-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
modify url to not be public and add getter to retrieve it. add setter…
… that sets the url internally and also on the wrapped BoundRequestBuilder
- Loading branch information
Showing
2 changed files
with
203 additions
and
4 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
150 changes: 150 additions & 0 deletions
150
...lient/src/test/java/com/nike/riposte/client/asynchttp/ning/RequestBuilderWrapperTest.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,150 @@ | ||
package com.nike.riposte.client.asynchttp.ning; | ||
|
||
import com.nike.fastbreak.CircuitBreaker; | ||
import com.nike.fastbreak.CircuitBreakerImpl; | ||
import com.ning.http.client.AsyncHttpClient; | ||
import com.ning.http.client.Response; | ||
import io.netty.channel.ChannelHandlerContext; | ||
import io.netty.handler.codec.http.HttpMethod; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import java.util.Optional; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.verify; | ||
|
||
|
||
public class RequestBuilderWrapperTest { | ||
|
||
private RequestBuilderWrapper requestBuilderWrapper; | ||
private String url; | ||
private String httpMethod; | ||
private AsyncHttpClient.BoundRequestBuilder requestBuilder; | ||
private Optional<CircuitBreaker<Response>> customCircuitBreaker; | ||
private boolean disableCircuitBreaker; | ||
|
||
@Before | ||
public void setup() { | ||
url = "http://localhost.com"; | ||
httpMethod = HttpMethod.GET.name(); | ||
requestBuilder = mock(AsyncHttpClient.BoundRequestBuilder.class); | ||
customCircuitBreaker = Optional.of(new CircuitBreakerImpl<Response>()); | ||
disableCircuitBreaker = true; | ||
} | ||
|
||
@Test | ||
public void constructor_sets_values_as_expected() { | ||
// given | ||
requestBuilderWrapper = new RequestBuilderWrapper( | ||
url, | ||
httpMethod, | ||
requestBuilder, | ||
customCircuitBreaker, | ||
disableCircuitBreaker); | ||
|
||
// then | ||
assertThat(requestBuilderWrapper.url).isEqualTo(url); | ||
assertThat(requestBuilderWrapper.httpMethod).isEqualTo(httpMethod); | ||
assertThat(requestBuilderWrapper.customCircuitBreaker).isEqualTo(customCircuitBreaker); | ||
assertThat(requestBuilderWrapper.disableCircuitBreaker).isEqualTo(disableCircuitBreaker); | ||
} | ||
|
||
@Test | ||
public void get_set_ChannelHandlerContext_works_as_expected() { | ||
// given | ||
requestBuilderWrapper = new RequestBuilderWrapper( | ||
url, | ||
httpMethod, | ||
requestBuilder, | ||
customCircuitBreaker, | ||
disableCircuitBreaker); | ||
|
||
ChannelHandlerContext ctx = mock(ChannelHandlerContext.class); | ||
|
||
// when | ||
requestBuilderWrapper.setCtx(ctx); | ||
|
||
// then | ||
assertThat(ctx).isEqualTo(requestBuilderWrapper.getCtx()); | ||
} | ||
|
||
@Test | ||
public void get_set_Url_works_as_expected() { | ||
// given | ||
requestBuilderWrapper = new RequestBuilderWrapper( | ||
url, | ||
httpMethod, | ||
requestBuilder, | ||
customCircuitBreaker, | ||
disableCircuitBreaker); | ||
|
||
String alternateUrl = "http://alteredUrl.testing"; | ||
|
||
// when | ||
requestBuilderWrapper.setUrl(alternateUrl); | ||
|
||
// then | ||
assertThat(alternateUrl).isEqualTo(requestBuilderWrapper.getUrl()); | ||
verify(requestBuilder).setUrl(alternateUrl); | ||
} | ||
|
||
@Test | ||
public void get_set_HttpMethod_works_as_expected() { | ||
// given | ||
requestBuilderWrapper = new RequestBuilderWrapper( | ||
url, | ||
httpMethod, | ||
requestBuilder, | ||
customCircuitBreaker, | ||
disableCircuitBreaker); | ||
|
||
String alteredMethod = "POST"; | ||
|
||
// when | ||
requestBuilderWrapper.setHttpMethod(alteredMethod); | ||
|
||
// then | ||
assertThat(alteredMethod).isEqualTo(requestBuilderWrapper.getHttpMethod()); | ||
verify(requestBuilder).setMethod(alteredMethod); | ||
} | ||
|
||
@Test | ||
public void get_set_DisableCircuitBreaker_works_as_expected() { | ||
// given | ||
requestBuilderWrapper = new RequestBuilderWrapper( | ||
url, | ||
httpMethod, | ||
requestBuilder, | ||
customCircuitBreaker, | ||
disableCircuitBreaker); | ||
|
||
boolean alteredDisableCircuitBreaker = false; | ||
|
||
// when | ||
requestBuilderWrapper.setDisableCircuitBreaker(alteredDisableCircuitBreaker); | ||
|
||
// then | ||
assertThat(requestBuilderWrapper.isDisableCircuitBreaker()).isFalse(); | ||
} | ||
|
||
@Test | ||
public void get_set_CustomCircuitBreaker_works_as_expected() { | ||
// given | ||
requestBuilderWrapper = new RequestBuilderWrapper( | ||
url, | ||
httpMethod, | ||
requestBuilder, | ||
customCircuitBreaker, | ||
disableCircuitBreaker); | ||
|
||
Optional<CircuitBreaker<Response>> alteredCircuitBreaker = Optional.of(new CircuitBreakerImpl<>()); | ||
|
||
// when | ||
requestBuilderWrapper.setCustomCircuitBreaker(alteredCircuitBreaker); | ||
|
||
// then | ||
assertThat(requestBuilderWrapper.getCustomCircuitBreaker()).isEqualTo(alteredCircuitBreaker); | ||
} | ||
} |