c8bcc7bdfc5bee39a39fc99f549dc0d8ffeb3c6a
[policy/distribution.git] /
1 /*-
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
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
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.
19  *
20  * SPDX-License-Identifier: Apache-2.0
21  * ============LICENSE_END=========================================================
22  */
23
24 package org.onap.policy.distribution.reception.handling.file;
25
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;
30
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;
39
40 /**
41  * Class to perform unit test of {@link FileSystemReceptionHandlerConfigurationParameterGroup}.
42  *
43  */
44 public class TestFileSystemReceptionHandlerConfigurationParameterGroup {
45     @Rule
46     public TemporaryFolder tempFolder = new TemporaryFolder();
47
48     @Test
49     public void testFileSystemConfiguration() throws IOException {
50         FileSystemReceptionHandlerConfigurationParameterGroup configParameters = null;
51         String validPath = null;
52
53         validPath = tempFolder.getRoot().getAbsolutePath();
54
55         configParameters = new FileSystemReceptionHandlerConfigurationParameterGroup();
56         configParameters.setWatchPath(validPath);
57         configParameters.setMaxThread(2);
58
59         final ValidationResult validationResult = configParameters.validate();
60         assertTrue(validationResult.isValid());
61         assertEquals(validPath, configParameters.getWatchPath());
62         assertEquals(2, configParameters.getMaxThread());
63     }
64
65     @Test
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());
73
74     }
75
76     @Test
77     public void testFileSystemReceptionHandlerConfigurationParameterBuilderWithInvalidPath() throws IOException {
78         final String invalidPath = tempFolder.newFile("foobar").getAbsolutePath();
79
80         final FileSystemReceptionHandlerConfigurationParameterGroup configParameters =
81                 new FileSystemReceptionHandlerConfigurationParameterGroup();
82         configParameters.setWatchPath(invalidPath);
83
84         final ValidationResult validateResult = configParameters.validate();
85         assertFalse(validateResult.isValid());
86         assertThat(validateResult.getResult()).contains("is not a valid directory");
87     }
88 }