*
* @param watchPath Path to watch
*/
- @SuppressWarnings("unchecked")
public void main(String watchPath) throws IOException {
try (final WatchService watcher = FileSystems.getDefault().newWatchService()) {
final Path dir = Paths.get(watchPath);
key = watcher.take();
for (final WatchEvent<?> event : key.pollEvents()) {
- final WatchEvent.Kind<?> kind = event.kind();
final WatchEvent<Path> ev = (WatchEvent<Path>) event;
final Path fileName = ev.context();
LOGGER.debug("new CSAR found: " + fileName);
import com.google.gson.GsonBuilder;
import java.io.File;
+import java.io.FileReader;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.junit.runner.RunWith;
-import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.runners.MockitoJUnitRunner;
import org.onap.policy.common.logging.flexlogger.FlexLogger;
import org.onap.policy.common.logging.flexlogger.Logger;
import org.onap.policy.common.parameters.ParameterService;
-import org.onap.policy.distribution.forwarding.PolicyForwarder;
import org.onap.policy.distribution.reception.decoding.PolicyDecodingException;
import org.onap.policy.distribution.reception.statistics.DistributionStatisticsManager;
public class TestFileSystemReceptionHandler {
private static final Logger LOGGER = FlexLogger.getLogger(TestFileSystemReceptionHandler.class);
- private static final String DUMMY_SERVICE_CSAR = "dummyService.csar";
@Rule
public TemporaryFolder tempFolder = new TemporaryFolder();
DistributionStatisticsManager.resetAllStatistics();
final Gson gson = new GsonBuilder().create();
- String json = "{ \"name\": \"parameterConfig9\", \"watchPath\": \"";
- json += tempFolder.getRoot().getAbsolutePath() + "\"}";
- pssdConfigParameters = gson.fromJson(json,
+ pssdConfigParameters = gson.fromJson(new FileReader("src/test/resources/handling-filesystem.json"),
FileSystemReceptionHandlerConfigurationParameterGroup.class);
ParameterService.register(pssdConfigParameters);
fileSystemHandler = new FileSystemReceptionHandler();
Processed cond = new Processed();
final FileSystemReceptionHandler sypHandler = Mockito.spy(fileSystemHandler);
- Mockito.doAnswer(new Answer() {
+ Mockito.doAnswer(new Answer<Object>() {
public Object answer(InvocationOnMock invocation) {
synchronized (lock) {
cond.processed = true;
import java.io.FileReader;
import java.io.IOException;
-import java.util.Arrays;
import org.junit.Rule;
import org.junit.Test;
@Test
public void testFileSystemConfiguration() throws IOException {
FileSystemReceptionHandlerConfigurationParameterGroup configParameters = null;
+ String validPath = null;
try {
- final Gson gson = new GsonBuilder().create();
- configParameters = gson.fromJson(new FileReader("src/test/resources/handling-filesystem.json"),
- FileSystemReceptionHandlerConfigurationParameterGroup.class);
+ validPath = tempFolder.getRoot().getAbsolutePath();
+
+ final FileSystemReceptionHandlerConfigurationParameterBuilder builder =
+ new FileSystemReceptionHandlerConfigurationParameterBuilder().setWatchPath(validPath);
+ configParameters = new FileSystemReceptionHandlerConfigurationParameterGroup(builder);
} catch (final Exception e) {
fail("test should not thrown an exception here: " + e.getMessage());
}
final GroupValidationResult validationResult = configParameters.validate();
assertTrue(validationResult.isValid());
- assertEquals("/tmp", configParameters.getWatchPath());
+ assertEquals(validPath, configParameters.getWatchPath());
}
@Test