2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2018 Intel. All rights reserved.
4 * Copyright (C) 2019 Nordix Foundation.
5 * Modifications Copyright (C) 2020 Nordix Foundation
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
19 * SPDX-License-Identifier: Apache-2.0
20 * ============LICENSE_END=========================================================
23 package org.onap.policy.distribution.reception.handling.file;
25 import static org.junit.Assert.assertEquals;
26 import static org.junit.Assert.assertFalse;
27 import static org.junit.Assert.assertTrue;
29 import com.google.gson.Gson;
30 import com.google.gson.GsonBuilder;
31 import java.io.FileReader;
32 import java.io.IOException;
33 import org.junit.Rule;
34 import org.junit.Test;
35 import org.junit.rules.TemporaryFolder;
36 import org.onap.policy.common.parameters.GroupValidationResult;
39 * Class to perform unit test of {@link FileSystemReceptionHandlerConfigurationParameterGroup}.
42 public class TestFileSystemReceptionHandlerConfigurationParameterGroup {
44 public TemporaryFolder tempFolder = new TemporaryFolder();
47 public void testFileSystemConfiguration() throws IOException {
48 FileSystemReceptionHandlerConfigurationParameterGroup configParameters = null;
49 String validPath = null;
51 validPath = tempFolder.getRoot().getAbsolutePath();
53 configParameters = new FileSystemReceptionHandlerConfigurationParameterGroup();
54 configParameters.setWatchPath(validPath);
55 configParameters.setMaxThread(2);
57 final GroupValidationResult validationResult = configParameters.validate();
58 assertTrue(validationResult.isValid());
59 assertEquals(validPath, configParameters.getWatchPath());
60 assertEquals(2, configParameters.getMaxThread());
64 public void testInvalidFileSystemConfiguration() throws IOException {
65 FileSystemReceptionHandlerConfigurationParameterGroup configParameters = null;
66 final Gson gson = new GsonBuilder().create();
67 configParameters = gson.fromJson(new FileReader("src/test/resources/handling-sdcInvalid.json"),
68 FileSystemReceptionHandlerConfigurationParameterGroup.class);
69 final GroupValidationResult validationResult = configParameters.validate();
70 assertFalse(validationResult.isValid());
75 public void testFileSystemReceptionHandlerConfigurationParameterBuilderWithInvalidPath() throws IOException {
76 final String invalidPath = tempFolder.newFile("foobar").getAbsolutePath();
78 final FileSystemReceptionHandlerConfigurationParameterGroup configParameters =
79 new FileSystemReceptionHandlerConfigurationParameterGroup();
80 configParameters.setWatchPath(invalidPath);
82 final GroupValidationResult validateResult = configParameters.validate();
83 assertFalse(validateResult.isValid());
84 assertTrue(validateResult.getResult().contains("must be a valid directory"));