StubDescriptorStatusServlet extends HttpServlet { @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(); } @Autowired  StubDescriptorStatusServlet(RoutingService routingService, ExpirationTimeProvider expirationTimeProvider);   }
@Test public void testDoGetWhenThereAreNoSequenceDescriptorsWriteAnEmptyList() throws ServletException, IOException { underTest.doGet(request, response); InOrder order = Mockito.inOrder(out); order.verify(out).write("\"sequenceDescriptors\":["); order.verify(out).write("]"); order.verify(out).write(","); }
@Test public void testDoGetWhenThereAreNoInterceptorDescriptorsWriteAnEmptyList() throws ServletException, IOException { underTest.doGet(request, response); InOrder order = Mockito.inOrder(out); order.verify(out).write("\"interceptorDescriptors\":["); order.verify(out).write("]"); }
@Test public void testDoGetWhenThereIsOneSequenceDescriptors() throws ServletException, IOException { sequenceDescriptors.add(sequenceDescriptor); given(sequenceDescriptor.getName()).willReturn("SequenceDescriptor1"); underTest.doGet(request, response); InOrder order = Mockito.inOrder(out); order.verify(out).write("\"sequenceDescriptors\":["); order.verify(out).write("{\"Name\": \"SequenceDescriptor1\"}"); order.verify(out).write("]"); order.verify(out).write(","); }
@Test public void testDoGetWhenThereIsOneInterceptorDescriptors() throws ServletException, IOException { interceptorDescriptors.add(interceptorDescriptor); given(interceptorDescriptor.getName()).willReturn("InterceptorDescriptor1"); underTest.doGet(request, response); InOrder order = Mockito.inOrder(out); order.verify(out).write("\"interceptorDescriptors\":["); order.verify(out).write("{\"Name\": \"InterceptorDescriptor1\"}"); order.verify(out).write("]"); }
@Test public void testDoGetWhenThereAreNoDialogDescriptorsWriteAnEmptyList() throws ServletException, IOException { underTest.doGet(request, response); InOrder order = Mockito.inOrder(out); order.verify(out).write("\"dialogDescriptors\":["); order.verify(out).write("], \"groupname\": \"test\", \"active\": \"true\""); }
@Test public void testDoGetWhenThereIsSequenceDescriptorAndDialogDescriptorAndInterceptorDescriptorInStubDescriptor() throws ServletException, IOException { dialogDescriptors.add(dialogDescriptor); sequenceDescriptors.add(sequenceDescriptor); interceptorDescriptors.add(interceptorDescriptor); given(interceptorDescriptor.getName()).willReturn("InterceptorDescriptor1"); given(sequenceDescriptor.getName()).willReturn("SequenceDescriptor1"); given(dialogDescriptor.getAttributes().getName()).willReturn(NAME); given(dialogDescriptor.getAttributes().getUsage()).willReturn(DialogDescriptorUsage.ALWAYS); underTest.doGet(request, response); InOrder order = Mockito.inOrder(out); order.verify(out).write("\"dialogDescriptors\":["); order.verify(out).write("{\"Name\":\"" + NAME + "\", \"Usage\":\"" + DialogDescriptorUsage.ALWAYS); order.verify(out).write("\"}"); order.verify(out).write("], \"groupname\": \"test\", \"active\": \"true\""); order.verify(out).write(","); order.verify(out).write("\"sequenceDescriptors\":["); order.verify(out).write("{\"Name\": \"SequenceDescriptor1\"}"); order.verify(out).write("]"); order.verify(out).write(","); order.verify(out).write("\"interceptorDescriptors\":["); order.verify(out).write("{\"Name\": \"InterceptorDescriptor1\"}"); }
@Test public void testDoGetWhenUsageIsAlwaysShouldWriteAlwaysInResponse() throws ServletException, IOException { dialogDescriptors.add(dialogDescriptor); given(dialogDescriptor.getAttributes().getName()).willReturn(NAME); given(dialogDescriptor.getAttributes().getUsage()).willReturn(DialogDescriptorUsage.ALWAYS); underTest.doGet(request, response); InOrder order = Mockito.inOrder(out); order.verify(out).write("{\"Name\":\"" + NAME + "\", \"Usage\":\"" + DialogDescriptorUsage.ALWAYS); order.verify(out).write("\"}"); }
@Test public void testDoGetWhenUsageIsDisabledShouldWriteDisabledInResponse() throws ServletException, IOException { dialogDescriptors.add(dialogDescriptor); given(dialogDescriptor.getAttributes().getName()).willReturn(NAME); given(dialogDescriptor.getAttributes().getUsage()).willReturn(DialogDescriptorUsage.DISABLED); underTest.doGet(request, response); InOrder order = Mockito.inOrder(out); order.verify(out).write("{\"Name\":\"" + NAME + "\", \"Usage\":\"" + DialogDescriptorUsage.DISABLED); order.verify(out).write("\"}"); }
@Test public void testDoGetWhenUsageIsHitcountShouldWriteHitcountInResponse() throws ServletException, IOException { dialogDescriptors.add(dialogDescriptor); given(dialogDescriptor.getAttributes().getName()).willReturn(NAME); given(dialogDescriptor.getAttributes().getUsage()).willReturn(DialogDescriptorUsage.HITCOUNT); given(dialogDescriptor.getAttributes().getHitcount()).willReturn(VALIDITY_VALUE); underTest.doGet(request, response); InOrder order = Mockito.inOrder(out); order.verify(out).write("{\"Name\":\"" + NAME + "\", \"Usage\":\"" + DialogDescriptorUsage.HITCOUNT); order.verify(out).write(" -> " + VALIDITY_VALUE + " hit(s) left\"}"); }
@Test public void testDoGetWhenUsageIsTimeoutShouldWriteTimeoutInResponse() throws ServletException, IOException { long expirationMinutes = 2L; long expirationSeconds = 31L; dialogDescriptors.add(dialogDescriptor); given(dialogDescriptor.getAttributes().getName()).willReturn(NAME); given(dialogDescriptor.getAttributes().getUsage()).willReturn(DialogDescriptorUsage.TIMEOUT); given(dialogDescriptor.getAttributes().getTimeout()).willReturn(VALIDITY_VALUE); given(expirationTimeProvider.getExpirationMinutes(VALIDITY_VALUE)).willReturn(expirationMinutes); given(expirationTimeProvider.getExpirationSeconds(VALIDITY_VALUE)).willReturn(expirationSeconds); underTest.doGet(request, response); InOrder order = Mockito.inOrder(out); order.verify(out).write("{\"Name\":\"" + NAME + "\", \"Usage\":\"" + DialogDescriptorUsage.TIMEOUT); order.verify(out).write(" -> expires in " + expirationMinutes + ":" + expirationSeconds + " (min:sec)\"}"); }
@Test public void testDoGetWhenUsageIsTimeoutMinuteExpiredShouldWriteTimeoutInResponse() throws ServletException, IOException { long expirationMinutes = 0L; long expirationSeconds = 2L; dialogDescriptors.add(dialogDescriptor); given(dialogDescriptor.getAttributes().getName()).willReturn(NAME); given(dialogDescriptor.getAttributes().getUsage()).willReturn(DialogDescriptorUsage.TIMEOUT); given(dialogDescriptor.getAttributes().getTimeout()).willReturn(VALIDITY_VALUE); given(expirationTimeProvider.getExpirationMinutes(VALIDITY_VALUE)).willReturn(expirationMinutes); given(expirationTimeProvider.getExpirationSeconds(VALIDITY_VALUE)).willReturn(expirationSeconds); underTest.doGet(request, response); InOrder order = Mockito.inOrder(out); order.verify(out).write("{\"Name\":\"" + NAME + "\", \"Usage\":\"" + DialogDescriptorUsage.TIMEOUT); order.verify(out).write(" -> expires in " + expirationMinutes + ":" + expirationSeconds + " (min:sec)\"}"); }
@Test public void testDoGetWhenUsageIsTimeoutAndExpiredShouldWriteTimeoutInResponse() throws ServletException, IOException { long expirationMinutes = 0L; long expirationSeconds = -1L; dialogDescriptors.add(dialogDescriptor); given(dialogDescriptor.getAttributes().getName()).willReturn(NAME); given(dialogDescriptor.getAttributes().getUsage()).willReturn(DialogDescriptorUsage.TIMEOUT); given(dialogDescriptor.getAttributes().getTimeout()).willReturn(VALIDITY_VALUE); given(expirationTimeProvider.getExpirationMinutes(VALIDITY_VALUE)).willReturn(expirationMinutes); given(expirationTimeProvider.getExpirationSeconds(VALIDITY_VALUE)).willReturn(expirationSeconds); underTest.doGet(request, response); InOrder order = Mockito.inOrder(out); order.verify(out).write("{\"Name\":\"" + NAME + "\", \"Usage\":\"" + DialogDescriptorUsage.TIMEOUT); order.verify(out).write(" -> expired\"}"); }
@Test public void testDoGetWhenThereAreMultipleDDsShouldWriteAlwaysInResponse() throws ServletException, IOException { dialogDescriptors.add(dialogDescriptor); dialogDescriptors.add(dialogDescriptor); given(dialogDescriptor.getAttributes().getName()).willReturn(NAME); given(dialogDescriptor.getAttributes().getUsage()).willReturn(DialogDescriptorUsage.ALWAYS); underTest.doGet(request, response); InOrder order = Mockito.inOrder(out); order.verify(out).write("{\"Name\":\"" + NAME + "\", \"Usage\":\"" + DialogDescriptorUsage.ALWAYS); order.verify(out).write("\"}"); order.verify(out).write(","); order.verify(out).write("{\"Name\":\"" + NAME + "\", \"Usage\":\"" + DialogDescriptorUsage.ALWAYS); order.verify(out).write("\"}"); }