Browse Source
Merge commit '469af0b96cffa3f5a42b2a1bb28bdc2a15028e19' into HEAD
feature-create-new-vault
Merge commit '469af0b96cffa3f5a42b2a1bb28bdc2a15028e19' into HEAD
feature-create-new-vault
jenkins
3 years ago
4 changed files with 140 additions and 0 deletions
-
28src/main/java/HttpApi.java
-
66src/main/java/PasswordValidator.java
-
19src/test/java/HttpApiTest.java
-
27src/test/java/PasswordValidatorTest.java
@ -0,0 +1,28 @@ |
|||
import java.io.BufferedReader; |
|||
import java.io.IOException; |
|||
import java.io.InputStreamReader; |
|||
import java.net.HttpURLConnection; |
|||
import java.net.URL; |
|||
|
|||
public class HttpApi { |
|||
public static String sendHttpGETRequest(String url) throws IOException { |
|||
URL obj = new URL(url); |
|||
HttpURLConnection httpURLConnection = (HttpURLConnection) obj.openConnection(); |
|||
httpURLConnection.setRequestMethod("GET"); |
|||
int responseCode = httpURLConnection.getResponseCode(); |
|||
|
|||
if (responseCode == HttpURLConnection.HTTP_OK) { |
|||
BufferedReader in = new BufferedReader(new InputStreamReader(httpURLConnection.getInputStream())); |
|||
String inputLine; |
|||
StringBuffer response = new StringBuffer(); |
|||
|
|||
while ((inputLine = in.readLine()) != null) { |
|||
response.append(inputLine + "\n"); |
|||
} |
|||
in.close(); |
|||
|
|||
return response.toString(); |
|||
} |
|||
return null; |
|||
} |
|||
} |
@ -0,0 +1,19 @@ |
|||
import org.junit.jupiter.api.Test; |
|||
|
|||
import java.io.IOException; |
|||
import java.util.Objects; |
|||
|
|||
import static org.junit.jupiter.api.Assertions.*; |
|||
|
|||
class HttpApiTest { |
|||
|
|||
@Test |
|||
void sendHttpGETRequest() { |
|||
assertDoesNotThrow(() -> HttpApi.sendHttpGETRequest("https://httpbin.org/get")); |
|||
try { |
|||
assertTrue(Objects.requireNonNull(HttpApi.sendHttpGETRequest("https://httpbin.org/get")).contains("args")); |
|||
} catch (IOException e) { |
|||
e.printStackTrace(); |
|||
} |
|||
} |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue