@Test public void testRouteTriathlon() throws Exception { Observable<Void> observable = Mockito.mock(Observable.class); when(this.triathlonEndpoint.postApps(any(), any())).thenReturn(observable); HttpRequestHeaders headers = Mockito.mock(HttpRequestHeaders.class); List<String> uris = Lists.newArrayList( "/v2/apps" ); while(uris.size()>0){ String uri = uris.remove(0); request = getRequest(uri, headers, HttpMethod.POST); response = getResponse(); this.triathlonRouter.handle(request, response); verify(this.triathlonEndpoint, times(1)).postApps(request, response); } request = getRequest("/someOtherUri", headers, HttpMethod.POST); response = getResponse(); this.triathlonRouter.handle(request, response); verify(this.triathlonEndpoint,times(0)).postApps(request, response); verify(response, times(1)).setStatus(argThat(matchResponseStatus(HttpResponseStatus.NOT_FOUND))); }
private HttpServerRequest getRequest(String path, HttpRequestHeaders headers, HttpMethod method){ HttpServerRequest request = Mockito.mock(HttpServerRequest.class); when(request.getHeaders()).thenReturn(headers); when(request.getHttpMethod()).thenReturn(method); when(request.getHttpVersion()).thenReturn(HttpVersion.HTTP_1_1); when(request.getPath()).thenReturn(path); when(request.getQueryString()).thenReturn(""); when(request.getUri()).thenReturn(path); when(request.getQueryParameters()).thenReturn(new HashMap<String, List<String>>()); when(request.getCookies()).thenReturn(new HashMap<String, Set<String>>()); when(request.getNettyChannel()).thenReturn(new LocalChannel()); return request; }
private JerseyRequestHeadersAdapter(HttpRequestHeaders requestHeaders) { this.requestHeaders = requestHeaders; }