/** * Modify the ordering in the stubDescriptors of routingService. * @param direction is the way where we want to move the selected stub descriptor * @param groupName is the groupname of selected stub descriptor * @param request is only needed for {@link UrlAccessLogMessageAssembler} * @throws ClassNotFoundException in case of problem */ public void doChange(final int direction, final String groupName, final HttpServletRequest request) throws ClassNotFoundException { routingService.performModification(new ChangeOrderCommand(direction, groupName, request, urlAccessLogMessageAssembler)); } }
@Override protected void doGet(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException { response.setContentType("application/json"); PrintWriter out = response.getWriter(); Map<String, StubDescriptor> stubDescriptors = routingService.getStubDescriptors(); writeAllDialogDescriptors(out, stubDescriptors); out.flush(); out.close(); }
@Override public ResponseDescriptorDTO getResponseDescriptor(final String key) { return routingService.getResponseDescriptorDTOAndRemove(key); }
@Override protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { logger.info(urlAccessLogMessageAssembler.assembleMessage(req, "Set Operation Mode: STUB.")); proxyModeToggle.switchProxyModeOff(); routingService.setOperationMode(OperationMode.STUB); }
/** * Redirects requests by changing their URI. * @param request the request that is redirected */ public void reroute(final WilmaHttpRequest request) { if (routingService.redirectRequestToStub(request)) { try { request.setUri(getURI()); } catch (URISyntaxException e) { logger.error(e.getMessage()); } } }
@Override protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { resp.setContentType("application/json"); PrintWriter out = resp.getWriter(); boolean proxyModeOn = proxyModeToggle.isProxyModeOn(); boolean stubModeOn = routingService.isStubModeOn(); boolean wilmaModeOn = !proxyModeOn && !stubModeOn; out.write("{\"proxyMode\":" + proxyModeOn + ",\"stubMode\":" + stubModeOn + ",\"wilmaMode\":" + wilmaModeOn + "}"); out.flush(); out.close(); }
@Override protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { logger.info(urlAccessLogMessageAssembler.assembleMessage(req, "Set Operation Mode: PROXY.")); proxyModeToggle.switchProxyModeOn(); routingService.setOperationMode(OperationMode.PROXY); }
@Test public void testRerouteWhenUriNotCorrectShouldLogError() throws URISyntaxException { //GIVEN doThrow(new URISyntaxException("", "")).when(underTest).getURI(); given(routingService.redirectRequestToStub(request)).willReturn(true); //WHEN underTest.reroute(request); //THEN verify(logger).error(Mockito.anyString()); }
@Test public void testDoGetShouldWriteStatusToResponse() throws ServletException, IOException { //GIVEN given(proxyModeToggle.isProxyModeOn()).willReturn(true); given(routingService.isStubModeOn()).willReturn(false); //WHEN underTest.doGet(request, response); //THEN verify(printWriter).write("{\"proxyMode\":true,\"stubMode\":false,\"wilmaMode\":false}"); }
/** * Call the changeStubConfigurationStatus what set the enabled/disabled status at the selected stub descriptor and then applies the change at {@link RoutingService}. * @param nextStatus is the new status of the selected stub descriptor * @param groupName is the groupname of selected stub descriptor * @param request is only needed for {@link UrlAccessLogMessageAssembler} * @throws ClassNotFoundException in case of problem */ public void changeStatus(final boolean nextStatus, final String groupName, final HttpServletRequest request) throws ClassNotFoundException { routingService.performModification(new ChangeStatusCommand(nextStatus, groupName, request, urlAccessLogMessageAssembler)); } }
@Override public void process(final WilmaHttpEntity entity) throws ApplicationException { Map<String, StubDescriptor> stubDescriptors = routingService.getStubDescriptors(); for (String groupName : stubDescriptors.keySet()) { StubDescriptor stubDescriptor = stubDescriptors.get(groupName); List<InterceptorDescriptor> interceptorDescriptors = stubDescriptor.getInterceptorDescriptors(); for (InterceptorDescriptor interceptorDescriptor : interceptorDescriptors) { ResponseInterceptor interceptor = interceptorDescriptor.getResponseInterceptor(); callInterceptor(interceptor, entity, interceptorDescriptor); } } }
@Override protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { logger.info(urlAccessLogMessageAssembler.assembleMessage(req, "Set Operation Mode: WILMA (proxy+stub).")); proxyModeToggle.switchProxyModeOff(); routingService.setOperationMode(OperationMode.WILMA); }
@Test public void testGetResponseDescriptorDTOAndRemoveShouldReturnNullWhenKeyNotFound() { //GIVEN Map<String, ResponseDescriptor> responseDescriptorMap = new HashMap<>(); String key = "key"; Whitebox.setInternalState(underTest, "responseDescriptorMap", responseDescriptorMap); //WHEN ResponseDescriptorDTO actual = underTest.getResponseDescriptorDTOAndRemove(key); //THEN assertNull(actual); }
@Test public void testRerouteShouldNotSetNewUri() throws URISyntaxException { //GIVEN uri = new URI("http://127.0.0.1:" + internalPort + "/stub/"); given(routingService.redirectRequestToStub(request)).willReturn(false); //WHEN underTest.reroute(request); //TEST verify(request, times(0)).setUri(uri); }
@Test public void testDoPostShouldWriteStatusToResponse() throws ServletException, IOException { //GIVEN given(proxyModeToggle.isProxyModeOn()).willReturn(true); given(routingService.isStubModeOn()).willReturn(false); //WHEN underTest.doPost(request, response); //THEN verify(printWriter).write("{\"proxyMode\":true,\"stubMode\":false,\"wilmaMode\":false}"); } }
private void createStubDescriptor(final String jsonFilePath) { try { StubDescriptorModificationCommand command; command = newStubDescriptorJsonCommandFactory.create(jsonFilePath, stubConfigurationJsonBuilder, sequenceDescriptorHolder); routingService.performModification(command); } catch (ClassNotFoundException | FileNotFoundException e) { throw new DescriptorCannotBeParsedException("One of the stub descriptor files cannot be found!", e); } }
/** * This method deletes all old files from the cache folder. * Then it gets all stub descriptors from {@link RoutingService} and call {@link StubConfigurationSaver} to save all of the descriptors. * @throws JsonTransformationException is thrown when a document can not be written */ public void saveStubConfigurations() throws JsonTransformationException { cleaner.cleanCache(); Map<String, StubDescriptor> descriptors = routingService.getStubDescriptors(); saver.saveAllStubConfigurations(descriptors); }
@Test public void testDoGetShouldSetOpModeAndToggleInRoutingService() throws ServletException, IOException { //GIVEN OperationMode operationMode = OperationMode.STUB; //WHEN underTest.doGet(request, response); //THEN verify(routingService).setOperationMode(operationMode); }
@Test public void testGetResponseDescriptorShouldCallRoutingService() { //GIVEN String key = "key"; //WHEN underTest.getResponseDescriptor(key); //THEN verify(routingService).getResponseDescriptorDTOAndRemove(key); }
@Test public void testRerouteShouldSetNewUri() throws URISyntaxException { //GIVEN uri = new URI("http://127.0.0.1:" + internalPort + "/stub/"); given(routingService.redirectRequestToStub(request)).willReturn(true); //WHEN underTest.reroute(request); //TEST verify(request).setUri(uri); }