/** * 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)); } }
/** * 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)); } }
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); } }
@Override protected void doGet(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException { PrintWriter writer = response.getWriter(); if (request.getContentLength() > 0) { ServletInputStream inputStream = request.getInputStream(); try { routingService.performModification(new NewStubDescriptorCommand(inputStream, stubDescriptorJsonFactory, sequenceDescriptorHolder)); serviceMap.detectServices(); LOGGER.info(urlAccessLogMessageAssembler.assembleMessage(request, "New stub configuration was uploaded to Wilma.")); } catch (ClassNotFoundException | NoClassDefFoundError | SystemException e) { response.setStatus(HttpServletResponse.SC_BAD_REQUEST); writer.write("Stub config uploading failed: " + e.getMessage()); LOGGER.warn(urlAccessLogMessageAssembler.assembleMessage(request, "Stub config uploading failed: " + e.getMessage()), e); } } else { response.setStatus(HttpServletResponse.SC_BAD_REQUEST); writer.write("Please provide a non-empty stub configuration!"); } }
/** * Call the changeStubConfigurationDropper drop method and then applies this changes. * @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 dropSelectedStubConfiguration(final String groupName, final HttpServletRequest request) throws ClassNotFoundException { sequenceManager.removeSequenceDescriptors(groupName); routingService.performModification(new DropCommand(groupName, request, urlAccessLogMessageAssembler)); serviceMap.detectServices(); } }
@Test public void testProcessUploadedFileShouldReturnWhenStubConfigIsValid() throws ClassNotFoundException { //GIVEN in setUp //WHEN String actual = underTest.processUploadedFile(resource, JSON_CONTENT_TYPE, "stub-configuration", FILE_PATH); //THEN verify(routingService).performModification(Mockito.any(NewStubDescriptorCommand.class)); assertEquals(actual, "New stub configuration was uploaded to Wilma."); }
@Test public void testChangeStatusShouldCallTheTwoMethod() throws ClassNotFoundException { //GIVEN in setUp //WHEN underTest.changeStatus(false, GROUPNAME_FIRST, request); //THEN ArgumentCaptor<ChangeStatusCommand> argument = ArgumentCaptor.forClass(ChangeStatusCommand.class); verify(routingService, times(1)).performModification(argument.capture()); Assert.assertEquals(argument.getValue().isNextStatus(), false); Assert.assertEquals(argument.getValue().getGroupName(), GROUPNAME_FIRST); Assert.assertEquals(argument.getValue().getRequest(), request); } }
@Test public void testDoChangeShouldCallTheTwoMethod() throws ClassNotFoundException { //GIVEN in setUp //WHEN underTest.doChange(1, GROUPNAME_FIRST, request); //THEN ArgumentCaptor<ChangeOrderCommand> argument = ArgumentCaptor.forClass(ChangeOrderCommand.class); verify(routingService, times(1)).performModification(argument.capture()); Assert.assertEquals(argument.getValue().getDirection(), 1); Assert.assertEquals(argument.getValue().getGroupName(), GROUPNAME_FIRST); Assert.assertEquals(argument.getValue().getRequest(), request); } }
@Test public void testDropSelectedStubConfigurationShouldCallTheTwoMethod() throws ClassNotFoundException { //GIVEN in setUp //WHEN underTest.dropSelectedStubConfiguration(GROUPNAME_FIRST, request); //THEN ArgumentCaptor<DropCommand> argument = ArgumentCaptor.forClass(DropCommand.class); verify(sequenceManager).removeSequenceDescriptors(GROUPNAME_FIRST); verify(routingService, times(1)).performModification(argument.capture()); Assert.assertEquals(argument.getValue().getGroupName(), GROUPNAME_FIRST); Assert.assertEquals(argument.getValue().getRequest(), request); } }
@Test public void testDoGetShouldCallStubDescriptorConstructor() throws ServletException, IOException, ClassNotFoundException { //GIVEN given(request.getContentLength()).willReturn(1); //WHEN underTest.doGet(request, response); //THEN verify(routingService).performModification(Mockito.any(NewStubDescriptorCommand.class)); }
@Test public void testDoPostShouldCallDoGet() throws ServletException, IOException, ClassNotFoundException { //GIVEN given(request.getContentLength()).willReturn(1); //WHEN underTest.doPost(request, response); //THEN verify(routingService).performModification(Mockito.any(NewStubDescriptorCommand.class)); } }
@Test public void testLoadSpecificStubDescriptors() throws FileNotFoundException, ClassNotFoundException { //GIVEN List<String> paths = new ArrayList<>(); paths.add("test"); given(newStubDescriptorJsonCommandFactory.create("test", stubConfigurationJsonBuilder, sequenceDescriptorHolder)).willReturn(command); //WHEN underTest.loadSpecificStubDescriptors(paths); //THEN verify(routingService, times(1)).performModification(command); } }
@Test public void testDoGetWhenExceptionShouldWriteErrorToResponse() throws ServletException, IOException, ClassNotFoundException { //GIVEN given(request.getContentLength()).willReturn(1); willThrow(new DescriptorCannotBeParsedException(EXCEPTION_MESSAGE, new Throwable())).given(routingService).performModification( Mockito.any(NewStubDescriptorCommand.class)); //WHEN underTest.doGet(request, response); //THEN verify(writer).write(Mockito.anyString()); }
if ("stub-configuration".equals(fieldName) && JSON_CONTENT_TYPE.equals(contentType)) { try { routingService.performModification(new NewStubDescriptorCommand(resource, stubConfigurationJsonBuilder, sequenceDescriptorHolder)); serviceMap.detectServices(); } catch (ClassNotFoundException e) {
@SuppressWarnings("unchecked") @Test public void testInitStubDescriptorWhenOperationModeIsStubShouldSwitchOnStubMode() throws ClassNotFoundException { //GIVEN operationMode = OperationMode.STUB; given(configurationAccess.getProperties()).willReturn(properties); given(properties.getOperationMode()).willReturn(operationMode); given(command.modify(stubDescriptors)).willReturn(stubDescriptors); //WHEN underTest.performModification(command); //THEN Map<String, StubDescriptor> actual = (Map<String, StubDescriptor>) Whitebox.getInternalState(underTest, "stubDescriptors"); assertEquals(actual, stubDescriptors); OperationMode result = (OperationMode) Whitebox.getInternalState(underTest, "operationMode"); Assert.assertEquals(result, operationMode); }
@SuppressWarnings("unchecked") @Test public void testInitStubDescriptorWhenOperationModeIsNotStubShouldDoNothing() throws ClassNotFoundException { //GIVEN operationMode = OperationMode.WILMA; given(configurationAccess.getProperties()).willReturn(properties); given(properties.getOperationMode()).willReturn(operationMode); given(command.modify(stubDescriptors)).willReturn(stubDescriptors); //WHEN underTest.performModification(command); //THEN Map<String, StubDescriptor> actual = (Map<String, StubDescriptor>) Whitebox.getInternalState(underTest, "stubDescriptors"); assertEquals(actual, stubDescriptors); OperationMode result = (OperationMode) Whitebox.getInternalState(underTest, "operationMode"); Assert.assertEquals(result, operationMode); }