@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 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); } } }
/** * 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); }
@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) { RequestInterceptor interceptor = interceptorDescriptor.getRequestInterceptor(); callInterceptor(interceptor, entity, interceptorDescriptor); } } }
Map<String, StubDescriptor> descriptors = routingService.getStubDescriptors(); for (String key : descriptors.keySet()) { StubDescriptor stubDescriptor = descriptors.get(key);
@BeforeMethod public void setUp() { MockitoAnnotations.initMocks(this); given(routingService.getStubDescriptors()).willReturn(descriptors); }
@Test public void testProcessShouldCallAllResponseInterceptors() throws ApplicationException { //GIVEN Map<String, StubDescriptor> stubDescriptors = new LinkedHashMap<>(); stubDescriptors.put("test", createStubDescriptor()); given(routingService.getStubDescriptors()).willReturn(stubDescriptors); WilmaHttpEntity entity = new WilmaHttpResponse(isVolatile); //WHEN underTest.process(entity); //THEN BDDMockito.verify(responseInterceptor).onResponseReceive((WilmaHttpResponse) entity, PARAMS); }
@Test public void testProcessShouldCallAllResponseInterceptors() throws ApplicationException { //GIVEN Map<String, StubDescriptor> stubDescriptors = new LinkedHashMap<>(); stubDescriptors.put("test", createStubDescriptor()); given(routingService.getStubDescriptors()).willReturn(stubDescriptors); WilmaHttpEntity entity = new WilmaHttpRequest(); //WHEN underTest.process(entity); //THEN BDDMockito.verify(requestInterceptor).onRequestReceive((WilmaHttpRequest) entity, PARAMS); }
@Test public void testProcessWhenThereAreNoInterceptorsShouldDoNothing() throws ApplicationException { //GIVEN Map<String, StubDescriptor> stubDescriptors = new LinkedHashMap<>(); stubDescriptors.put("test", createStubDescriptorWithNoInterceptor()); given(routingService.getStubDescriptors()).willReturn(stubDescriptors); WilmaHttpEntity entity = new WilmaHttpResponse(isVolatile); //WHEN underTest.process(entity); //THEN BDDMockito.verify(responseInterceptor, BDDMockito.never()).onResponseReceive((WilmaHttpResponse) entity, PARAMS); }
@Test public void testProcessWhenThereAreNoInterceptorsShouldDoNothing() throws ApplicationException { //GIVEN Map<String, StubDescriptor> stubDescriptors = new LinkedHashMap<>(); stubDescriptors.put("test", createStubDescriptorWithNoInterceptor()); given(routingService.getStubDescriptors()).willReturn(stubDescriptors); WilmaHttpEntity entity = new WilmaHttpRequest(); //WHEN underTest.process(entity); //THEN BDDMockito.verify(requestInterceptor, BDDMockito.never()).onRequestReceive((WilmaHttpRequest) entity, PARAMS); }
@BeforeMethod public void setUp() throws IOException { MockitoAnnotations.initMocks(this); Whitebox.setInternalState(underTest, "routingService", routingService); Whitebox.setInternalState(underTest, "expirationTimeProvider", expirationTimeProvider); sequenceDescriptors = new ArrayList<>(); dialogDescriptors = new ArrayList<>(); interceptorDescriptors = new ArrayList<>(); Map<String, StubDescriptor> stubDescriptors = new LinkedHashMap<>(); stubDescriptors.put(TEST_GROUPNAME, stubDescriptor); Whitebox.setInternalState(routingService, "stubDescriptors", stubDescriptors); given(routingService.getStubDescriptors()).willReturn(stubDescriptors); given(stubDescriptor.getAttributes()).willReturn(stubDescriptorAttributes); given(stubDescriptor.getDialogDescriptors()).willReturn(dialogDescriptors); given(stubDescriptor.getSequenceDescriptors()).willReturn(sequenceDescriptors); given(stubDescriptor.getInterceptorDescriptors()).willReturn(interceptorDescriptors); given(response.getWriter()).willReturn(out); Whitebox.setInternalState(stubDescriptor, "attributes", stubDescriptorAttributes); }