@Test(expected = PathNotFound404Exception.class) public void findSingleEndpointForExecution_throws_PathNotFound404Exception_if_no_matching_path() { // given doReturn(Optional.empty()).when(matcherMock).matchesPath(any(RequestInfo.class)); // expect handlerSpy.findSingleEndpointForExecution(requestInfoMock); }
@Test(expected = MethodNotAllowed405Exception.class) public void findSingleEndpointForExecution_throws_MethodNotAllowed405Exception_if_path_matches_but_method_does_not() { // given doReturn(Optional.of(defaultPath)).when(matcherMock).matchesPath(any(RequestInfo.class)); doReturn(false).when(matcherMock).matchesMethod(any(RequestInfo.class)); // expect handlerSpy.findSingleEndpointForExecution(requestInfoMock); }
@Test(expected = MultipleMatchingEndpointsException.class) public void findSingleEndpointForExecution_throws_MultipleMatchingEndpointsException_if_multiple_endpoints_fully_match() { // given doReturn(Optional.of(defaultPath)).when(matcherMock).matchesPath(any(RequestInfo.class)); doReturn(true).when(matcherMock).matchesMethod(any(RequestInfo.class)); Endpoint<?> alsoMatchingEndpointMock = mock(Endpoint.class); doReturn(matcherMock).when(alsoMatchingEndpointMock).requestMatcher(); endpoints.add(alsoMatchingEndpointMock); // when handlerSpy.findSingleEndpointForExecution(requestInfoMock); }
@Before public void beforeMethod() { stateMock = mock(HttpProcessingState.class); ctxMock = mock(ChannelHandlerContext.class); channelMock = mock(Channel.class); stateAttrMock = mock(Attribute.class); requestInfoMock = mock(RequestInfo.class); endpointMock = mock(StandardEndpoint.class); matcherMock = mock(Matcher.class); endpoints = new ArrayList<>(Collections.singleton(endpointMock)); httpHeaders = new DefaultHttpHeaders(); maxRequestSizeInBytes = 10; msg = mock(HttpRequest.class); doReturn(channelMock).when(ctxMock).channel(); doReturn(stateAttrMock).when(channelMock).attr(ChannelAttributes.HTTP_PROCESSING_STATE_ATTRIBUTE_KEY); doReturn(stateMock).when(stateAttrMock).get(); doReturn(endpointMock).when(stateMock).getEndpointForExecution(); doReturn(matcherMock).when(endpointMock).requestMatcher(); doReturn(Optional.of(defaultPath)).when(matcherMock).matchesPath(any(RequestInfo.class)); doReturn(true).when(matcherMock).matchesMethod(any(RequestInfo.class)); doReturn(requestInfoMock).when(stateMock).getRequestInfo(); doReturn(httpHeaders).when(msg).headers(); handlerSpy = spy(new RoutingHandler(endpoints, maxRequestSizeInBytes)); }
@Test public void findSingleEndpointForExecution_returns_matching_endpoint() { // given doReturn(Optional.of(defaultPath)).when(matcherMock).matchesPath(any(RequestInfo.class)); doReturn(true).when(matcherMock).matchesMethod(any(RequestInfo.class)); // when Pair<Endpoint<?>, String> result = handlerSpy.findSingleEndpointForExecution(requestInfoMock); // then assertThat(result.getKey()).isSameAs(endpointMock); assertThat(result.getValue()).isSameAs(defaultPath); }
Optional<String> pattern = endpoint.requestMatcher().matchesPath(requestInfo); if (pattern.isPresent()) { hasPathMatch = true;
Optional<String> pattern = endpoint.requestMatcher().matchesPath(requestInfo); if (pattern.isPresent()) { hasPathMatch = true;
doReturn(HttpVersion.HTTP_1_1).when(msgMock).protocolVersion(); RequestInfo<?> requestInfoAlreadyOnState = (requestInfoAlreadySetOnState) ? requestInfoMock : null; doReturn(Optional.of(uri)).when(matcherMock).matchesPath(any(RequestInfo.class)); doReturn(requestInfoAlreadyOnState).when(stateMock).getRequestInfo();