Refactor LiveTest
This commit is contained in:
parent
d0a376e622
commit
bfddf3344d
|
@ -9,7 +9,6 @@ import org.apache.http.client.methods.HttpGet;
|
||||||
import org.apache.http.impl.client.BasicCredentialsProvider;
|
import org.apache.http.impl.client.BasicCredentialsProvider;
|
||||||
import org.apache.http.impl.client.CloseableHttpClient;
|
import org.apache.http.impl.client.CloseableHttpClient;
|
||||||
import org.apache.http.impl.client.HttpClientBuilder;
|
import org.apache.http.impl.client.HttpClientBuilder;
|
||||||
import org.junit.After;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -17,15 +16,18 @@ import java.io.InputStream;
|
||||||
|
|
||||||
public class HttpClientSandboxLiveTest {
|
public class HttpClientSandboxLiveTest {
|
||||||
|
|
||||||
private CloseableHttpClient client;
|
@Test
|
||||||
|
public final void givenGetRequestExecuted_whenAnalyzingTheResponse_thenCorrectStatusCode() throws IOException {
|
||||||
|
final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
|
||||||
|
final AuthScope authscp = new AuthScope("localhost", 8080);
|
||||||
|
credentialsProvider.setCredentials(authscp, new UsernamePasswordCredentials("user1", "user1Pass"));
|
||||||
|
|
||||||
private CloseableHttpResponse response;
|
CloseableHttpClient client = HttpClientBuilder.create().setDefaultCredentialsProvider(credentialsProvider).build();
|
||||||
|
|
||||||
@After
|
final HttpGet httpGet = new HttpGet("http://localhost:8080/spring-security-rest-basic-auth/api/foos/1");
|
||||||
public final void after() throws IllegalStateException, IOException {
|
CloseableHttpResponse response = client.execute(httpGet);
|
||||||
if (response == null) {
|
|
||||||
return;
|
System.out.println(response.getStatusLine());
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final HttpEntity entity = response.getEntity();
|
final HttpEntity entity = response.getEntity();
|
||||||
|
@ -38,22 +40,4 @@ public class HttpClientSandboxLiveTest {
|
||||||
response.close();
|
response.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// tests
|
|
||||||
|
|
||||||
// simple request - response
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public final void givenGetRequestExecuted_whenAnalyzingTheResponse_thenCorrectStatusCode() throws IOException {
|
|
||||||
final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
|
|
||||||
final AuthScope authscp = new AuthScope("localhost", 8080);
|
|
||||||
credentialsProvider.setCredentials(authscp, new UsernamePasswordCredentials("user1", "user1Pass"));
|
|
||||||
|
|
||||||
client = HttpClientBuilder.create().setDefaultCredentialsProvider(credentialsProvider).build();
|
|
||||||
|
|
||||||
final HttpGet httpGet = new HttpGet("http://localhost:8080/spring-security-rest-basic-auth/api/foos/1");
|
|
||||||
response = client.execute(httpGet);
|
|
||||||
|
|
||||||
System.out.println(response.getStatusLine());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue