-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#17] Fix UsingWithHttpClientTest to pass in TravisCI.
- Loading branch information
Showing
1 changed file
with
25 additions
and
12 deletions.
There are no files selected for viewing
37 changes: 25 additions & 12 deletions
37
src/test/java/com/github/dzieciou/testing/curl/UsingWithHttpClientTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,55 @@ | ||
package com.github.dzieciou.testing.curl; | ||
|
||
|
||
import static org.hamcrest.CoreMatchers.equalTo; | ||
import static org.hamcrest.CoreMatchers.hasItem; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
|
||
import com.github.valfirst.slf4jtest.LoggingEvent; | ||
import com.github.valfirst.slf4jtest.TestLoggerFactory; | ||
import java.io.IOException; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
import org.apache.http.client.HttpClient; | ||
import org.apache.http.client.methods.HttpGet; | ||
import org.apache.http.impl.client.HttpClientBuilder; | ||
import org.testng.annotations.Test; | ||
|
||
public class UsingWithHttpClientTest { | ||
|
||
private static HttpClient createHttpClient() { | ||
return HttpClientBuilder.create() | ||
.addInterceptorFirst(new CurlLoggingInterceptor(Options.builder() | ||
.targetPlatform(Platform.UNIX) // TO ease verifying output curl | ||
.build())) | ||
.build(); | ||
} | ||
|
||
@Test(groups = "end-to-end-samples") | ||
public void testHttp() throws IOException { | ||
TestLoggerFactory.clearAll(); | ||
HttpGet getRequest = new HttpGet("http://google.com"); | ||
createHttpClient().execute(getRequest); | ||
assertThat(TestLoggerFactory.getAllLoggingEvents().get(0).getMessage(), | ||
equalTo("curl 'http://google.com/' --compressed --insecure --verbose")); | ||
assertThat(getAllLoggedMessages(), | ||
hasItem("curl 'http://google.com/' --compressed --insecure --verbose")); | ||
} | ||
|
||
|
||
|
||
@Test(groups = "end-to-end-samples") | ||
public void testHttps() throws IOException { | ||
TestLoggerFactory.clearAll(); | ||
HttpGet getRequest = new HttpGet("https://google.com"); | ||
createHttpClient().execute(getRequest); | ||
assertThat(TestLoggerFactory.getAllLoggingEvents().get(0).getMessage(), | ||
equalTo("curl 'https://google.com/' --compressed --insecure --verbose")); | ||
assertThat(getAllLoggedMessages(), | ||
hasItem("curl 'https://google.com/' --compressed --insecure --verbose")); | ||
} | ||
|
||
|
||
private static HttpClient createHttpClient() { | ||
return HttpClientBuilder.create() | ||
.addInterceptorFirst(new CurlLoggingInterceptor(Options.builder() | ||
.targetPlatform(Platform.UNIX) // TO ease verifying output curl | ||
.build())) | ||
.build(); | ||
} | ||
|
||
private static List<String> getAllLoggedMessages() { | ||
return TestLoggerFactory.getAllLoggingEvents().stream().map(LoggingEvent::getMessage).collect( | ||
Collectors.toList()); | ||
} | ||
|
||
|
||
} |