@Test public void testSimpleKeyValueLookupService() throws InitializationException { final SimpleKeyValueLookupService service = new SimpleKeyValueLookupService(); final TestRunner runner = TestRunners.newTestRunner(TestProcessor.class); runner.addControllerService("simple-key-value-lookup-service", service); runner.setProperty(service, "key1", "value1"); runner.setProperty(service, "key2", "value2"); runner.enableControllerService(service); runner.assertValid(service); assertThat(service, instanceOf(LookupService.class)); final Optional<String> get1 = service.lookup(Collections.singletonMap("key", "key1")); assertEquals(Optional.of("value1"), get1); final Optional<String> get2 = service.lookup(Collections.singletonMap("key", "key2")); assertEquals(Optional.of("value2"), get2); final Optional<String> get3 = service.lookup(Collections.singletonMap("key", "key3")); assertEquals(EMPTY_STRING, get3); }
@Override public Optional<String> lookup(final Map<String, Object> coordinates) { if (coordinates == null) { return Optional.empty(); } final String key = coordinates.get(KEY).toString(); if (key == null) { return Optional.empty(); } return Optional.ofNullable(lookupValues.get(key)); }
SimpleKeyValueLookupService extends AbstractControllerService implements StringLookupService { @Override public Optional<String> lookup(final Map<String, Object> coordinates) { if (coordinates == null) { return Optional.empty(); } final String key = coordinates.get(KEY).toString(); if (key == null) { return Optional.empty(); } return Optional.ofNullable(lookupValues.get(key)); } }
SimpleKeyValueLookupService extends AbstractControllerService implements StringLookupService { @Override public Optional<String> lookup(final Map<String, Object> coordinates) { if (coordinates == null) { return Optional.empty(); } final String key = coordinates.get(KEY).toString(); if (key == null) { return Optional.empty(); } return Optional.ofNullable(lookupValues.get(key)); }  }
SimpleKeyValueLookupService extends AbstractControllerService implements StringLookupService { @Override public Optional<String> lookup(final Map<String, Object> coordinates) { if (coordinates == null) { return Optional.empty(); } final String key = coordinates.get(KEY).toString(); if (key == null) { return Optional.empty(); } return Optional.ofNullable(lookupValues.get(key)); }  @OnEnabled void cacheConfiguredValues(final ConfigurationContext context); @Override Optional<String> lookup(final Map<String, Object> coordinates); @Override Set<String> getRequiredKeys(); }
SimpleKeyValueLookupService extends AbstractControllerService implements StringLookupService { @Override public Optional<String> lookup(final Map<String, Object> coordinates) { if (coordinates == null) { return Optional.empty(); } final String key = coordinates.get(KEY).toString(); if (key == null) { return Optional.empty(); } return Optional.ofNullable(lookupValues.get(key)); }  @OnEnabled void cacheConfiguredValues(final ConfigurationContext context); @Override Optional<String> lookup(final Map<String, Object> coordinates); @Override Set<String> getRequiredKeys();  }