Skip to content

Commit eccfc15

Browse files
authored
Merge pull request #53 from ligangty/master
Use http-testserver 2.2.1
2 parents c49dcba + 06cb5e2 commit eccfc15

File tree

5 files changed

+28
-35
lines changed

5 files changed

+28
-35
lines changed

pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@
109109
</dependency>
110110
<dependency>
111111
<groupId>org.commonjava.util</groupId>
112-
<artifactId>http-testserver</artifactId>
113-
<version>1.4</version>
112+
<artifactId>http-testserver-junit4</artifactId>
113+
<version>2.2.1</version>
114114
</dependency>
115115
</dependencies>
116116
</dependencyManagement>
@@ -158,7 +158,7 @@
158158
<!-- Test deps -->
159159
<dependency>
160160
<groupId>org.commonjava.util</groupId>
161-
<artifactId>http-testserver</artifactId>
161+
<artifactId>http-testserver-junit4</artifactId>
162162
<scope>test</scope>
163163
</dependency>
164164
<dependency>

src/test/java/org/commonjava/util/jhttpc/it/AbstractIT.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,18 @@
3737

3838
import java.io.File;
3939
import java.io.FileOutputStream;
40+
import java.nio.charset.Charset;
4041
import java.util.Arrays;
4142
import java.util.List;
4243

4344
import static org.hamcrest.CoreMatchers.equalTo;
4445
import static org.hamcrest.CoreMatchers.notNullValue;
45-
import static org.junit.Assert.assertThat;
46+
import static org.hamcrest.MatcherAssert.assertThat;
4647

4748
/**
4849
* Created by jdcasey on 5/30/17.
4950
*/
51+
@SuppressWarnings( "ResultOfMethodCallIgnored" )
5052
public abstract class AbstractIT
5153
{
5254
protected static final String SSL_CONFIG_BASE = "/ssl-config";
@@ -106,7 +108,6 @@ protected SiteConfigBuilder getNormalSiteConfigBuilder()
106108

107109
@Before
108110
public void setup()
109-
throws Exception
110111
{
111112
System.out.println( "\n\n #### SETUP: " + name.getMethodName() + " #### \n\n" );
112113
passwordManager = new MemoryPasswordManager();
@@ -192,7 +193,7 @@ protected String getServerCertsPem()
192193
{
193194
CloseableHttpResponse response = client.execute( new HttpGet( formatUrl( path ) ) );
194195
assertThat( response.getStatusLine().getStatusCode(), equalTo( 200 ) );
195-
String result = IOUtils.toString( response.getEntity().getContent() );
196+
String result = IOUtils.toString( response.getEntity().getContent(), Charset.defaultCharset() );
196197

197198
System.out.println( result );
198199
assertThat( result, notNullValue() );
@@ -219,7 +220,7 @@ protected String getClientKeyCertPem()
219220
CloseableHttpResponse response =
220221
client.execute( new HttpGet( formatUrl( SSL_CONFIG_BASE, "client.pem" ) ) );
221222
assertThat( response.getStatusLine().getStatusCode(), equalTo( 200 ) );
222-
String result = IOUtils.toString( response.getEntity().getContent() );
223+
String result = IOUtils.toString( response.getEntity().getContent(), Charset.defaultCharset() );
223224

224225
System.out.println( result );
225226
assertThat( result, notNullValue() );
@@ -293,7 +294,7 @@ protected void putContent( String path, String content )
293294
String extra = "";
294295
if ( response.getEntity() != null )
295296
{
296-
String body = IOUtils.toString( response.getEntity().getContent() );
297+
String body = IOUtils.toString( response.getEntity().getContent(), Charset.defaultCharset() );
297298
extra = "\nBody:\n\n" + body;
298299
}
299300

@@ -325,7 +326,7 @@ protected void deleteContent( String path )
325326
String extra = "";
326327
if ( response.getEntity() != null )
327328
{
328-
String body = IOUtils.toString( response.getEntity().getContent() );
329+
String body = IOUtils.toString( response.getEntity().getContent(), Charset.defaultCharset() );
329330
extra = "\nBody:\n\n" + body;
330331
}
331332

src/test/java/org/commonjava/util/jhttpc/it/AbstractSSLTestsIT.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,13 @@
2424
import org.commonjava.util.jhttpc.model.SiteConfig;
2525
import org.junit.Test;
2626

27+
import java.nio.charset.Charset;
2728
import java.security.KeyStore;
2829
import java.util.Enumeration;
2930

3031
import static org.hamcrest.CoreMatchers.equalTo;
3132
import static org.hamcrest.CoreMatchers.notNullValue;
32-
import static org.junit.Assert.assertThat;
33+
import static org.hamcrest.MatcherAssert.assertThat;
3334

3435
public abstract class AbstractSSLTestsIT
3536
extends AbstractIT
@@ -53,7 +54,7 @@ public void clientSSLGet()
5354
client = factory.createClient( config );
5455
CloseableHttpResponse response = client.execute( new HttpGet( formatSSLUrl( path ) ) );
5556
assertThat( response.getStatusLine().getStatusCode(), equalTo( 200 ) );
56-
String result = IOUtils.toString( response.getEntity().getContent() );
57+
String result = IOUtils.toString( response.getEntity().getContent(), Charset.defaultCharset() );
5758

5859
assertThat( result, equalTo( content ) );
5960
}
@@ -79,7 +80,7 @@ public void simpleSSLGet()
7980
client = factory.createClient( config );
8081
CloseableHttpResponse response = client.execute( new HttpGet( formatSSLUrl( path ) ) );
8182
assertThat( response.getStatusLine().getStatusCode(), equalTo( 200 ) );
82-
String result = IOUtils.toString( response.getEntity().getContent() );
83+
String result = IOUtils.toString( response.getEntity().getContent(), Charset.defaultCharset() );
8384

8485
assertThat( result, equalTo( content ) );
8586
}
@@ -104,7 +105,7 @@ public void simpleSingleGet_NoSSL()
104105
client = factory.createClient();
105106
CloseableHttpResponse response = client.execute( new HttpGet( formatUrl( path ) ) );
106107
assertThat( response.getStatusLine().getStatusCode(), equalTo( 200 ) );
107-
String result = IOUtils.toString( response.getEntity().getContent() );
108+
String result = IOUtils.toString( response.getEntity().getContent(), Charset.defaultCharset() );
108109

109110
assertThat( result, equalTo( content ) );
110111
}
@@ -128,7 +129,7 @@ public void retrieveSiteCertificatePems()
128129
{
129130
CloseableHttpResponse response = client.execute( new HttpGet( formatUrl( path ) ) );
130131
assertThat( response.getStatusLine().getStatusCode(), equalTo( 200 ) );
131-
String result = IOUtils.toString( response.getEntity().getContent() );
132+
String result = IOUtils.toString( response.getEntity().getContent(), Charset.defaultCharset() );
132133

133134
System.out.println( result );
134135
assertThat( result, notNullValue() );

src/test/java/org/commonjava/util/jhttpc/unit/HttpFactoryTest.java

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@
1616
package org.commonjava.util.jhttpc.unit;
1717

1818
import org.apache.commons.io.IOUtils;
19-
import org.apache.http.HttpResponse;
20-
import org.apache.http.client.ClientProtocolException;
21-
import org.apache.http.client.ResponseHandler;
2219
import org.apache.http.client.methods.CloseableHttpResponse;
2320
import org.apache.http.client.methods.HttpGet;
2421
import org.apache.http.impl.client.CloseableHttpClient;
@@ -34,12 +31,12 @@
3431
import org.junit.Test;
3532

3633
import javax.crypto.Cipher;
37-
import java.io.IOException;
34+
import java.nio.charset.Charset;
3835
import java.security.NoSuchAlgorithmException;
3936

4037
import static org.hamcrest.CoreMatchers.equalTo;
4138
import static org.hamcrest.CoreMatchers.notNullValue;
42-
import static org.junit.Assert.assertThat;
39+
import static org.hamcrest.MatcherAssert.assertThat;
4340

4441
/**
4542
* Created by jdcasey on 10/28/15.
@@ -55,7 +52,6 @@ public class HttpFactoryTest
5552

5653
@Before
5754
public void setup()
58-
throws Exception
5955
{
6056
server = new ExpectationServer();
6157
server.start();
@@ -78,15 +74,9 @@ public void simpleSingleGet_NoSiteConfig()
7874
try
7975
{
8076
client = factory.createClient();
81-
String result = client.execute( new HttpGet( server.formatUrl( path ) ), new ResponseHandler<String>()
82-
{
83-
@Override
84-
public String handleResponse( HttpResponse response )
85-
throws ClientProtocolException, IOException
86-
{
87-
assertThat( response.getStatusLine().getStatusCode(), equalTo( 200 ) );
88-
return IOUtils.toString( response.getEntity().getContent() );
89-
}
77+
String result = client.execute( new HttpGet( server.formatUrl( path ) ), response -> {
78+
assertThat( response.getStatusLine().getStatusCode(), equalTo( 200 ) );
79+
return IOUtils.toString( response.getEntity().getContent(), Charset.defaultCharset() );
9080
} );
9181

9282
assertThat( result, equalTo( content ) );
@@ -129,14 +119,14 @@ public void simpleSSLGet_Manual()
129119
CloseableHttpResponse response = client.execute( get );
130120
if ( response.getStatusLine().getStatusCode() == 200 )
131121
{
132-
serverCertPem = IOUtils.toString( response.getEntity().getContent() );
122+
serverCertPem = IOUtils.toString( response.getEntity().getContent(), Charset.defaultCharset() );
133123
}
134124

135125
get = new HttpGet( clientDownloadUrl );
136126
response = client.execute( get );
137127
if ( response.getStatusLine().getStatusCode() == 200 )
138128
{
139-
clientCertPem = IOUtils.toString( response.getEntity().getContent() );
129+
clientCertPem = IOUtils.toString( response.getEntity().getContent(), Charset.defaultCharset() );
140130
}
141131
}
142132
finally

src/test/java/org/commonjava/util/jhttpc/unit/ResourceCleanupLoadTest.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import org.apache.http.conn.ConnectionPoolTimeoutException;
2222
import org.apache.http.impl.client.CloseableHttpClient;
2323
import org.commonjava.test.http.expect.ExpectationHandler;
24-
import org.commonjava.test.http.expect.ExpectationServer;
24+
import org.commonjava.test.http.junit4.expect.ExpectationServerWrapper;
2525
import org.commonjava.util.jhttpc.HttpFactory;
2626
import org.commonjava.util.jhttpc.auth.MemoryPasswordManager;
2727
import org.commonjava.util.jhttpc.model.SiteConfig;
@@ -37,14 +37,15 @@
3737
import javax.servlet.http.HttpServletRequest;
3838
import javax.servlet.http.HttpServletResponse;
3939
import java.io.IOException;
40+
import java.nio.charset.Charset;
4041
import java.util.concurrent.CountDownLatch;
4142
import java.util.concurrent.ExecutorService;
4243
import java.util.concurrent.Executors;
4344
import java.util.concurrent.atomic.AtomicBoolean;
4445
import java.util.concurrent.atomic.AtomicInteger;
4546

4647
import static org.hamcrest.CoreMatchers.equalTo;
47-
import static org.junit.Assert.assertThat;
48+
import static org.hamcrest.MatcherAssert.assertThat;
4849

4950
/**
5051
* Created by jdcasey on 5/30/17.
@@ -55,7 +56,7 @@ public class ResourceCleanupLoadTest
5556
private static final int THREAD_COUNT = 20;
5657

5758
@Rule
58-
public ExpectationServer server = new ExpectationServer();
59+
public ExpectationServerWrapper server = new ExpectationServerWrapper();
5960

6061
@Rule
6162
public TestName name = new TestName();
@@ -176,7 +177,7 @@ public void run(){
176177
logger.info( "Response: {}", response.getStatusLine() );
177178

178179
assertThat( response.getStatusLine().getStatusCode(), equalTo( 200 ) );
179-
String result = IOUtils.toString( response.getEntity().getContent() );
180+
String result = IOUtils.toString( response.getEntity().getContent(), Charset.defaultCharset() );
180181

181182
assertThat( result, equalTo( content ) );
182183
}

0 commit comments

Comments
 (0)