SequenceManager implements SequenceDescriptorHolder { public void handleRequest(final WilmaHttpRequest request) { for (SequenceDescriptor descriptor : descriptors.values()) { if (descriptor.isActive()) { try { sequenceService.checkRequest(request, descriptor); } catch (SequenceHandlerKeyValidationException e) { logger.error(e.getMessage()); } } } }  void handleRequest(final WilmaHttpRequest request); void cleanUpDescriptors(); void addSequenceDescriptor(final String descriptorKey, final SequenceDescriptor descriptor); void removeSequenceDescriptors(final String groupName); void setStatusOfDescriptors(final String groupName, final boolean newStatus); void dropAllSequences(); void tryToSaveResponseIntoSequence(final WilmaHttpResponse response); Map<String, WilmaSequence> getSequences(final String sequenceDescriptorName); @Override void addAllSequenceDescriptors(final StubDescriptor stubDescriptor); Map<String, SequenceDescriptor> getDescriptors();  }
@Test public void testHandleRequestWhenSequenceDescriptorIsActive() { Map<String, SequenceDescriptor> descriptors = new ConcurrentHashMap<>(); descriptors.put("TestTeam-fistDescriptor-TestHandler", sequenceDescriptor); Whitebox.setInternalState(underTest, "descriptors", descriptors); given(sequenceDescriptor.isActive()).willReturn(true); underTest.handleRequest(request); verify(sequenceService).checkRequest(request, sequenceDescriptor); }
@Test public void testHandleRequestWhenSequenceDescriptorIsNotActive() { Map<String, SequenceDescriptor> descriptors = new ConcurrentHashMap<>(); descriptors.put("TestTeam-fistDescriptor-TestHandler", sequenceDescriptor); Whitebox.setInternalState(underTest, "descriptors", descriptors); given(sequenceDescriptor.isActive()).willReturn(false); underTest.handleRequest(request); verify(sequenceService, never()).checkRequest(request, sequenceDescriptor); }
@Test public void testHandleRequestWhenCheckRequestThrowValidationException() { Map<String, SequenceDescriptor> descriptors = new ConcurrentHashMap<>(); descriptors.put("TestTeam-fistDescriptor-TestHandler", sequenceDescriptor); Whitebox.setInternalState(underTest, "descriptors", descriptors); Whitebox.setInternalState(underTest, "logger", logger); given(sequenceDescriptor.isActive()).willReturn(true); Mockito.doThrow(new SequenceHandlerKeyValidationException("Test message")).when(sequenceService).checkRequest(request, sequenceDescriptor); underTest.handleRequest(request); verify(logger).error(Mockito.anyString()); }