-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
SP-734 Java - Investigate HTTPResponse
1 parent
90c7968
commit f42973e
Showing
4 changed files
with
100 additions
and
6 deletions.
There are no files selected for viewing
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
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
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 |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.bitpay.sdk.client; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
public class HttpResponseTest { | ||
|
||
private static final int CODE = 200; | ||
private static final String BODY = "anyBody"; | ||
private static final String LOCALE = "en_US"; | ||
private static final String HTTP_VERSION = "HTTP/1.1"; | ||
|
||
@Test | ||
public void it_should_returns_code() { | ||
Assertions.assertEquals(CODE, this.getTestedClass().getCode()); | ||
} | ||
|
||
@Test | ||
public void it_should_returns_body() { | ||
Assertions.assertSame(BODY, this.getTestedClass().getBody()); | ||
} | ||
|
||
@Test | ||
public void it_should_returns_headers() { | ||
Assertions.assertSame("application/json", this.getTestedClass().getHeaders().get("Content-Type")); | ||
} | ||
|
||
@Test | ||
public void it_should_returns_locale() { | ||
Assertions.assertSame(LOCALE, this.getTestedClass().getLocale()); | ||
} | ||
|
||
@Test | ||
public void it_should_returns_httpVersion() { | ||
Assertions.assertSame(HTTP_VERSION, this.getTestedClass().getHttpVersion()); | ||
} | ||
|
||
private HttpResponse getTestedClass() { | ||
Map<String, String> headers = new HashMap<>(); | ||
headers.put("Content-Type", "application/json"); | ||
|
||
return new HttpResponse(CODE, BODY, headers, LOCALE, HTTP_VERSION); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
src/test/java/com/bitpay/sdk/functional/client/HttpResponseProviderTest.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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.bitpay.sdk.functional.client; | ||
|
||
import com.bitpay.sdk.client.HttpResponse; | ||
import com.bitpay.sdk.client.HttpResponseProvider; | ||
import com.bitpay.sdk.exceptions.BitPayApiException; | ||
import java.io.IOException; | ||
import org.apache.http.client.HttpClient; | ||
import org.apache.http.client.methods.HttpGet; | ||
import org.apache.http.impl.client.HttpClientBuilder; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
public class HttpResponseProviderTest { | ||
|
||
@Test | ||
public void it_should_correct_transfer_apache_response_to_bitpay_response() throws IOException, BitPayApiException { | ||
|
||
HttpClient apacheClient = HttpClientBuilder.create().build(); | ||
HttpGet httpGet = new HttpGet("https://jsonplaceholder.typicode.com/posts/1"); | ||
org.apache.http.HttpResponse apacheResponse = apacheClient.execute(httpGet); | ||
|
||
HttpResponse httpResponse = HttpResponseProvider.fromApacheHttpResponse(apacheResponse); | ||
|
||
Assertions.assertEquals(20, httpResponse.getCode()); | ||
Assertions.assertEquals("{\n" + | ||
" \"userId\": 1,\n" + | ||
" \"id\": 1,\n" + | ||
" \"title\": \"sunt aut facere repellat provident occaecati excepturi optio reprehenderit\",\n" + | ||
" \"body\": \"quia et suscipit\\nsuscipit recusandae consequuntur expedita et cum\\nreprehenderit molestiae ut ut quas totam\\nnostrum rerum est autem sunt rem eveniet architecto\"\n" + | ||
"}", httpResponse.getBody()); | ||
} | ||
} |