ExternalStubConfigUploadServlet extends HttpServlet { @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!"); } } @Autowired  ExternalStubConfigUploadServlet(UrlAccessLogMessageAssembler urlAccessLogMessageAssembler, StubDescriptorJsonFactory stubDescriptorJsonFactory,
                                           RoutingService routingService, SequenceDescriptorHolder sequenceDescriptorHolder, ServiceMap serviceMap);   }
@Test public void testDoGetShouldCallStubDescriptorConstructor() throws ServletException, IOException, ClassNotFoundException { given(request.getContentLength()).willReturn(1); underTest.doGet(request, response); verify(routingService).performModification(Mockito.any(NewStubDescriptorCommand.class)); }
@Test public void testDoGetWhenRequestBodyIsEmptyNotShouldCallStubDescriptorConstructor() throws ServletException, IOException { given(request.getContentLength()).willReturn(0); underTest.doGet(request, response); verify(writer).write("Please provide a non-empty stub configuration!"); }
@Test public void testDoGetWhenExceptionShouldWriteErrorToResponse() throws ServletException, IOException, ClassNotFoundException { given(request.getContentLength()).willReturn(1); willThrow(new DescriptorCannotBeParsedException(EXCEPTION_MESSAGE, new Throwable())).given(routingService).performModification( Mockito.any(NewStubDescriptorCommand.class)); underTest.doGet(request, response); verify(writer).write(Mockito.anyString()); }