cleanup work
This commit is contained in:
parent
6633f5b9a0
commit
cfafcc57b7
|
@ -10,7 +10,7 @@ import org.junit.Test;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
|
|
||||||
public class CoreJavaUnitTest {
|
public class CoreJavaCollectionsUnitTest {
|
||||||
|
|
||||||
// tests -
|
// tests -
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
package org.baeldung.java;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class CoreJavaIoUnitTest {
|
||||||
|
|
||||||
|
// tests -
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public final void whenIteratingAFile_thenCorrect() {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -12,7 +12,6 @@ import org.apache.http.HttpStatus;
|
||||||
import org.apache.http.client.ClientProtocolException;
|
import org.apache.http.client.ClientProtocolException;
|
||||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||||
import org.apache.http.client.methods.HttpGet;
|
import org.apache.http.client.methods.HttpGet;
|
||||||
import org.apache.http.client.methods.HttpPost;
|
|
||||||
import org.apache.http.entity.ContentType;
|
import org.apache.http.entity.ContentType;
|
||||||
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;
|
||||||
|
@ -63,7 +62,7 @@ public class HttpClientBasicLiveTest {
|
||||||
@Test
|
@Test
|
||||||
public final void givenGetRequestExecuted_whenAnalyzingTheResponse_thenCorrectStatusCode() throws ClientProtocolException, IOException {
|
public final void givenGetRequestExecuted_whenAnalyzingTheResponse_thenCorrectStatusCode() throws ClientProtocolException, IOException {
|
||||||
response = instance.execute(new HttpGet(SAMPLE_URL));
|
response = instance.execute(new HttpGet(SAMPLE_URL));
|
||||||
int statusCode = response.getStatusLine().getStatusCode();
|
final int statusCode = response.getStatusLine().getStatusCode();
|
||||||
assertThat(statusCode, equalTo(HttpStatus.SC_OK));
|
assertThat(statusCode, equalTo(HttpStatus.SC_OK));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,11 +82,4 @@ public class HttpClientBasicLiveTest {
|
||||||
assertThat(bodyAsString, notNullValue());
|
assertThat(bodyAsString, notNullValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
// tests - non-GET
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public final void whenExecutingBasicRequest_thenNoExceptions() throws ClientProtocolException, IOException {
|
|
||||||
instance.execute(new HttpPost(SAMPLE_URL));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,73 @@
|
||||||
|
package org.baeldung.httpclient;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
|
||||||
|
import org.apache.http.HttpEntity;
|
||||||
|
import org.apache.http.auth.AuthenticationException;
|
||||||
|
import org.apache.http.auth.UsernamePasswordCredentials;
|
||||||
|
import org.apache.http.client.ClientProtocolException;
|
||||||
|
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||||
|
import org.apache.http.client.methods.HttpPost;
|
||||||
|
import org.apache.http.entity.StringEntity;
|
||||||
|
import org.apache.http.impl.auth.BasicScheme;
|
||||||
|
import org.apache.http.impl.client.CloseableHttpClient;
|
||||||
|
import org.apache.http.impl.client.HttpClientBuilder;
|
||||||
|
import org.junit.After;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class HttpClientBasicPostLiveTest {
|
||||||
|
|
||||||
|
private static final String SAMPLE_URL = "http://www.github.com";
|
||||||
|
|
||||||
|
private CloseableHttpClient instance;
|
||||||
|
|
||||||
|
private CloseableHttpResponse response;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public final void before() {
|
||||||
|
instance = HttpClientBuilder.create().build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public final void after() throws IllegalStateException, IOException {
|
||||||
|
if (response == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
final HttpEntity entity = response.getEntity();
|
||||||
|
if (entity != null) {
|
||||||
|
final InputStream instream = entity.getContent();
|
||||||
|
instream.close();
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
response.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// tests - non-GET
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public final void whenExecutingPostRequest_thenNoExceptions() throws ClientProtocolException, IOException {
|
||||||
|
instance.execute(new HttpPost(SAMPLE_URL));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public final void whenExecutingPostRequestWithBody_thenNoExceptions() throws ClientProtocolException, IOException {
|
||||||
|
final HttpPost request = new HttpPost(SAMPLE_URL);
|
||||||
|
request.setEntity(new StringEntity("in the body of the POST"));
|
||||||
|
instance.execute(request);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public final void givenAuth_whenExecutingPostRequestWithBody_thenNoExceptions() throws ClientProtocolException, IOException, AuthenticationException {
|
||||||
|
final HttpPost request = new HttpPost(SAMPLE_URL);
|
||||||
|
request.setEntity(new StringEntity("in the body of the POST"));
|
||||||
|
final UsernamePasswordCredentials creds = new UsernamePasswordCredentials("username", "password");
|
||||||
|
request.addHeader(new BasicScheme().authenticate(creds, request, null));
|
||||||
|
instance.execute(request);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue