CheckUniqueMetadataValueService extends BranchingServiceImp { @Override public void doService(AdaptrisMessage msg) throws ServiceException { String value = msg.getMetadataValue(this.getMetadataKeyToCheck()); try { Args.notBlank(value, "metadataValue"); if (previousValuesStore.contains(value)) { this.handleDuplicate(msg, value); } else { this.handleNewValue(msg, value); } } catch (Exception e) { throw ExceptionHelper.wrapServiceException(e); } } CheckUniqueMetadataValueService(); @Override void doService(AdaptrisMessage msg); String getMetadataKeyToCheck(); void setMetadataKeyToCheck(String s); int getNumberOfPreviousValuesToStore(); void setNumberOfPreviousValuesToStore(int i); String getStoreFileUrl(); void setStoreFileUrl(String s); String getNextServiceIdIfDuplicate(); void setNextServiceIdIfDuplicate(String s); String getNextServiceIdIfUnique(); void setNextServiceIdIfUnique(String s); @Override void prepare(); static final String DEFAULT_SERVICE_ID_UNIQUE; static final String DEFAULT_SERVICE_ID_DUPLICATE; }
@Test public void testWithDuplicate() throws Exception { try { start(service); service.doService(msg1); service.doService(msg4); assertTrue(msg1.getNextServiceId().equals(CheckUniqueMetadataValueService.DEFAULT_SERVICE_ID_UNIQUE)); assertTrue(msg4.getNextServiceId().equals(CheckUniqueMetadataValueService.DEFAULT_SERVICE_ID_DUPLICATE)); } finally { stop(service); } }
@Test public void testPeristentStore() throws Exception { try { start(service); service.doService(msg1); service.doService(msg2); service.doService(msg3); stop(service); start(service); service.doService(msg4); assertTrue(msg4.getNextServiceId().equals(CheckUniqueMetadataValueService.DEFAULT_SERVICE_ID_DUPLICATE)); } finally { stop(service); } }