ChangeStatusCommand implements StubDescriptorModificationCommand { @Override public Map<String, StubDescriptor> modify(Map<String, StubDescriptor> stubDescriptors) { Map<String, StubDescriptor> updated = new LinkedHashMap<>(stubDescriptors); StubDescriptor selected = updated.get(groupName); if (selected != null) { StubDescriptorAttributes attributes = selected.getAttributes(); attributes.setActive(nextStatus); if (nextStatus) { logger.info(urlAccessLogMessageAssembler.assembleMessage(request, groupName + " stub configuration: Enabled")); } else { logger.info(urlAccessLogMessageAssembler.assembleMessage(request, groupName + " stub configuration: Disabled")); } } return updated; } ChangeStatusCommand(final boolean nextStatus, final String groupName, final HttpServletRequest request,
            final UrlAccessLogMessageAssembler urlAccessLogMessageAssembler); @Override Map<String, StubDescriptor> modify(Map<String, StubDescriptor> stubDescriptors); String getGroupName(); HttpServletRequest getRequest(); boolean isNextStatus();  }
@Test public void testSetStatusShouldDisableTheSelectedStubDescriptor() { normalStubDescriptors = new LinkedHashMap<>(); attributes = new StubDescriptorAttributes(GROUPNAME_FIRST, true); stubDescriptor = new StubDescriptor(attributes, new ArrayList<DialogDescriptor>(), new ArrayList<InterceptorDescriptor>(), null); normalStubDescriptors.put(GROUPNAME_FIRST, stubDescriptor); underTest = new ChangeStatusCommand(false, GROUPNAME_FIRST, request, urlAccessLogMessageAssembler); Map<String, StubDescriptor> result = underTest.modify(normalStubDescriptors); StubDescriptor resultDescriptor = result.get(GROUPNAME_FIRST); Assert.assertNotNull(resultDescriptor); boolean resultAttribute = resultDescriptor.getAttributes().isActive(); Assert.assertFalse(resultAttribute); }
@Test public void testSetStatusShouldEnableTheSelectedStubDescriptor() { normalStubDescriptors = new LinkedHashMap<>(); attributes = new StubDescriptorAttributes(GROUPNAME_FIRST, false); stubDescriptor = new StubDescriptor(attributes, new ArrayList<DialogDescriptor>(), new ArrayList<InterceptorDescriptor>(), null); normalStubDescriptors.put(GROUPNAME_FIRST, stubDescriptor); underTest = new ChangeStatusCommand(true, GROUPNAME_FIRST, request, urlAccessLogMessageAssembler); Map<String, StubDescriptor> result = underTest.modify(normalStubDescriptors); StubDescriptor resultDescriptor = result.get(GROUPNAME_FIRST); Assert.assertNotNull(resultDescriptor); boolean resultAttribute = resultDescriptor.getAttributes().isActive(); Assert.assertTrue(resultAttribute); }