Example usage for org.springframework.mock.http.client MockClientHttpResponse MockClientHttpResponse

List of usage examples for org.springframework.mock.http.client MockClientHttpResponse MockClientHttpResponse

Introduction

In this page you can find the example usage for org.springframework.mock.http.client MockClientHttpResponse MockClientHttpResponse.

Prototype

public MockClientHttpResponse(InputStream body, HttpStatus statusCode) 

Source Link

Document

Constructor with response body as InputStream.

Usage

From source file:org.zalando.riptide.PassThroughResponseErrorHandlerTest.java

@Test
public void isNoErrorForClientError() throws IOException {
    assertThat(unit.hasError(new MockClientHttpResponse(new byte[] {}, HttpStatus.BAD_REQUEST)), is(false));
}

From source file:org.zalando.riptide.PassThroughResponseErrorHandlerTest.java

@Test
public void isNoErrorForServerError() throws IOException {

    assertThat(unit.hasError(new MockClientHttpResponse(new byte[] {}, HttpStatus.INTERNAL_SERVER_ERROR)),
            is(false));// w  w w  .j a v  a  2s .c o  m
}

From source file:org.zalando.riptide.OAuth2CompatibilityResponseErrorHandlerTest.java

@Test
public void isNoErrorForClientError() throws IOException {
    final ClientHttpResponse response = new MockClientHttpResponse(new byte[] {}, HttpStatus.BAD_REQUEST);
    assertThat(unit.hasError(response), is(false));
}

From source file:com.gopivotal.cla.github.RateLimitingClientHttpRequestInterceptorTest.java

@Test
public void noBlock() throws IOException {
    MockClientHttpRequest request = new MockClientHttpRequest();
    MockClientHttpResponse response = new MockClientHttpResponse(new byte[0], HttpStatus.OK);
    ClientHttpRequestExecution execution = mock(ClientHttpRequestExecution.class);

    when(execution.execute(request, new byte[0])).thenReturn(response);

    this.interceptor.intercept(request, new byte[0], execution);
}

From source file:org.zalando.riptide.OAuth2CompatibilityResponseErrorHandlerTest.java

@Test
public void isNoErrorForServerError() throws IOException {
    final ClientHttpResponse response = new MockClientHttpResponse(new byte[] {},
            HttpStatus.INTERNAL_SERVER_ERROR);
    assertThat(unit.hasError(response), is(false));
}

From source file:org.zalando.riptide.RouterTest.java

@Test
public void shouldRejectDuplicateWildcards() {
    exception.expect(IllegalStateException.class);
    exception.expectMessage("Duplicate any conditions");

    unit.route(new MockClientHttpResponse((byte[]) null, OK), emptyList(), status(),
            asList(anyStatus().capture(), anyStatus().call(response -> {
                throw new IllegalStateException();
            })));/*from  w  ww  . ja  v  a2 s . c  o  m*/
}

From source file:guru.nidi.ramltester.spring.RamlRequestInterceptor.java

@Override
public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution)
        throws IOException {
    reportStore.storeReport(null);/*from ww w . j a  v  a2s  . c  o  m*/
    final SpringHttpRequestRamlRequest ramlRequest = new SpringHttpRequestRamlRequest(request, body);
    final RamlReport report;
    final ClientHttpResponse response;
    if (notSending) {
        response = new MockClientHttpResponse((byte[]) null, HttpStatus.NO_CONTENT);
        report = checker.check(ramlRequest);
    } else {
        response = execution.execute(request, body);
        final SpringClientHttpResponseRamlResponse ramlResponse = new SpringClientHttpResponseRamlResponse(
                response);
        report = checker.check(ramlRequest, ramlResponse);
    }
    reportStore.storeReport(report);
    return response;
}

From source file:org.zalando.riptide.OAuth2CompatibilityResponseErrorHandlerTest.java

@Test
public void throwsResponseWrappedInException() throws IOException {
    final ClientHttpResponse expectedResponse = new MockClientHttpResponse(new byte[] { 0x13, 0x37 },
            HttpStatus.INTERNAL_SERVER_ERROR);

    exception.expect(AlreadyConsumedResponseException.class);
    exception.expect(hasFeature("response", AlreadyConsumedResponseException::getResponse,
            statusCode(HttpStatus.INTERNAL_SERVER_ERROR)));

    unit.handleError(expectedResponse);/*from ww  w  .jav a  2  s. c  o m*/
}

From source file:com.gopivotal.cla.github.RateLimitingClientHttpRequestInterceptorTest.java

@Test
public void block() throws InterruptedException, IOException {
    CountDownLatch latch = new CountDownLatch(1);

    MockClientHttpRequest request = new MockClientHttpRequest();
    MockClientHttpResponse response = new MockClientHttpResponse(new byte[0], HttpStatus.OK);
    ClientHttpRequestExecution execution = mock(ClientHttpRequestExecution.class);

    request.setMethod(HttpMethod.GET);/*from  w ww .  jav  a2s  .  c  om*/
    request.setURI(URI.create("http://localhost"));

    when(execution.execute(request, new byte[0])).thenReturn(response);

    new Thread(new Trigger(this.interceptor, latch)).start();
    latch.await();

    this.interceptor.intercept(request, new byte[0], execution);
}

From source file:org.zalando.riptide.RouterTest.java

@Test
public void shouldRejectDuplicateAttributes() {
    exception.expect(IllegalStateException.class);
    exception.expectMessage("Duplicate condition attribute: 200");

    unit.route(new MockClientHttpResponse((byte[]) null, OK), emptyList(), status(),
            asList(on(OK).capture(), on(OK).call(response -> {
                throw new IllegalStateException();
            })));/*from   w w w  .  j  av a  2s.c o m*/
}