CheckMetadataValueService extends DuplicateMetadataValueService { @Override public void doService(AdaptrisMessage msg) throws ServiceException { try { loadPreviouslyReceivedValues(); String value = Args.notBlank(msg.getMetadataValue(getMetadataKey()), "required-metadata"); if (previousValuesStore.contains(value)) { log.warn("Value [{}] stored [{}] exists in list of previously stored values", value, getMetadataKey()); msg.setNextServiceId(getNextServiceIdIfDuplicate()); } else { log.debug("unique value [{}] received", value); msg.setNextServiceId(getNextServiceIdIfUnique()); } } catch (Exception e) { throw ExceptionHelper.wrapServiceException(e); } } CheckMetadataValueService(); @Override void doService(AdaptrisMessage msg); @Override boolean isBranching(); String getNextServiceIdIfDuplicate(); void setNextServiceIdIfDuplicate(String s); String getNextServiceIdIfUnique(); void setNextServiceIdIfUnique(String s);  }
@Test public void testService() throws Exception { seedStore("123", "123", "456"); CheckMetadataValueService service = createChecker(); try { LifecycleHelper.initAndStart(service); assertEquals(3, service.storeSize()); AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(); msg.addMetadata(DEFAULT_METADATA_KEY, "123"); service.doService(msg); assertEquals(DEFAULT_SERVICE_ID_DUPLICATE, msg.getNextServiceId()); msg.addMetadata(DEFAULT_METADATA_KEY, "789"); service.doService(msg); assertEquals(DEFAULT_SERVICE_ID_UNIQUE, msg.getNextServiceId()); msg.clearMetadata(); try { service.doService(msg); fail(); } catch (ServiceException e) { } } finally { LifecycleHelper.stopAndClose(service); } }