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 * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
20 * SPDX-License-Identifier: Apache-2.0
21 * ============LICENSE_END=========================================================
24 package org.onap.policy.distribution.reception.handling.file;
26 import static org.assertj.core.api.Assertions.assertThat;
27 import static org.junit.Assert.assertEquals;
28 import static org.junit.Assert.assertFalse;
29 import static org.junit.Assert.assertTrue;
31 import com.google.gson.Gson;
32 import com.google.gson.GsonBuilder;
33 import java.io.FileReader;
34 import java.io.IOException;
35 import org.junit.Rule;
36 import org.junit.Test;
37 import org.junit.rules.TemporaryFolder;
38 import org.onap.policy.common.parameters.ValidationResult;
41 * Class to perform unit test of {@link FileSystemReceptionHandlerConfigurationParameterGroup}.
44 public class TestFileSystemReceptionHandlerConfigurationParameterGroup {
46 public TemporaryFolder tempFolder = new TemporaryFolder();
49 public void testFileSystemConfiguration() throws IOException {
50 FileSystemReceptionHandlerConfigurationParameterGroup configParameters = null;
51 String validPath = null;
53 validPath = tempFolder.getRoot().getAbsolutePath();
55 configParameters = new FileSystemReceptionHandlerConfigurationParameterGroup();
56 configParameters.setWatchPath(validPath);
57 configParameters.setMaxThread(2);
59 final ValidationResult validationResult = configParameters.validate();
60 assertTrue(validationResult.isValid());
61 assertEquals(validPath, configParameters.getWatchPath());
62 assertEquals(2, configParameters.getMaxThread());
66 public void testInvalidFileSystemConfiguration() throws IOException {
67 FileSystemReceptionHandlerConfigurationParameterGroup configParameters = null;
68 final Gson gson = new GsonBuilder().create();
69 configParameters = gson.fromJson(new FileReader("src/test/resources/handling-sdcInvalid.json"),
70 FileSystemReceptionHandlerConfigurationParameterGroup.class);
71 final ValidationResult validationResult = configParameters.validate();
72 assertFalse(validationResult.isValid());
77 public void testFileSystemReceptionHandlerConfigurationParameterBuilderWithInvalidPath() throws IOException {
78 final String invalidPath = tempFolder.newFile("foobar").getAbsolutePath();
80 final FileSystemReceptionHandlerConfigurationParameterGroup configParameters =
81 new FileSystemReceptionHandlerConfigurationParameterGroup();
82 configParameters.setWatchPath(invalidPath);
84 final ValidationResult validateResult = configParameters.validate();
85 assertFalse(validateResult.isValid());
86 assertThat(validateResult.getResult()).contains("is not a valid directory");