### Question:
SimpleCsvFileLookupService extends AbstractControllerService implements StringLookupService { @Override public Optional<String> lookup(final Map<String, Object> coordinates) throws LookupFailureException { if (coordinates == null) { return Optional.empty(); } final String key = coordinates.get(KEY).toString(); if (StringUtils.isBlank(key)) { return Optional.empty(); } try { if (watcher != null && watcher.checkAndReset()) { loadCache(); } } catch (final IllegalStateException | IOException e) { throw new LookupFailureException(e.getMessage(), e); } return Optional.ofNullable(cache.get(key)); }  @OnEnabled void onEnabled(final ConfigurationContext context); @Override Optional<String> lookup(final Map<String, Object> coordinates); @Override Set<String> getRequiredKeys(); static final PropertyDescriptor CSV_FILE; static final PropertyDescriptor CHARSET; static final PropertyDescriptor LOOKUP_KEY_COLUMN; static final PropertyDescriptor LOOKUP_VALUE_COLUMN; static final PropertyDescriptor IGNORE_DUPLICATES; }### Answer:
@Test public void testSimpleCsvFileLookupService() throws InitializationException, IOException, LookupFailureException { final TestRunner runner = TestRunners.newTestRunner(TestProcessor.class); final SimpleCsvFileLookupService service = new SimpleCsvFileLookupService(); runner.addControllerService("csv-file-lookup-service", service); runner.setProperty(service, SimpleCsvFileLookupService.CSV_FILE, "src/test/resources/test.csv"); runner.setProperty(service, SimpleCsvFileLookupService.CSV_FORMAT, "RFC4180"); runner.setProperty(service, SimpleCsvFileLookupService.LOOKUP_KEY_COLUMN, "key"); runner.setProperty(service, SimpleCsvFileLookupService.LOOKUP_VALUE_COLUMN, "value"); runner.enableControllerService(service); runner.assertValid(service); final SimpleCsvFileLookupService lookupService = (SimpleCsvFileLookupService) runner.getProcessContext() .getControllerServiceLookup() .getControllerService("csv-file-lookup-service"); assertThat(lookupService, instanceOf(LookupService.class)); final Optional<String> property1 = lookupService.lookup(Collections.singletonMap("key", "property.1")); assertEquals(Optional.of("this is property 1"), property1); final Optional<String> property2 = lookupService.lookup(Collections.singletonMap("key", "property.2")); assertEquals(Optional.of("this is property 2"), property2); final Optional<String> property3 = lookupService.lookup(Collections.singletonMap("key", "property.3")); assertEquals(EMPTY_STRING, property3); }
@Test public void testSimpleCsvFileLookupServiceWithCharset() throws InitializationException, IOException, LookupFailureException { final TestRunner runner = TestRunners.newTestRunner(TestProcessor.class); final SimpleCsvFileLookupService service = new SimpleCsvFileLookupService(); runner.addControllerService("csv-file-lookup-service", service); runner.setProperty(service, SimpleCsvFileLookupService.CSV_FILE, "src/test/resources/test_Windows-31J.csv"); runner.setProperty(service, SimpleCsvFileLookupService.CSV_FORMAT, "RFC4180"); runner.setProperty(service, SimpleCsvFileLookupService.CHARSET, "Windows-31J"); runner.setProperty(service, SimpleCsvFileLookupService.LOOKUP_KEY_COLUMN, "key"); runner.setProperty(service, SimpleCsvFileLookupService.LOOKUP_VALUE_COLUMN, "value"); runner.enableControllerService(service); runner.assertValid(service); final Optional<String> property1 = service.lookup(Collections.singletonMap("key", "property.1")); assertThat(property1.isPresent(), is(true)); assertThat(property1.get(), is("this is property \uff11")); }