Added some tools for DCAE CBS removal
[holmes/common.git] / holmes-actions / src / test / java / org / onap / holmes / common / ConfigFileScannerTest.java
1 /**
2  * Copyright 2021 ZTE Corporation.
3  * <p>
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  * <p>
8  * http://www.apache.org/licenses/LICENSE-2.0
9  * <p>
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package org.onap.holmes.common;
18
19 import org.junit.Rule;
20 import org.junit.Test;
21 import org.junit.rules.ExpectedException;
22 import org.junit.runner.RunWith;
23 import org.powermock.modules.junit4.PowerMockRunner;
24
25 import java.util.Map;
26
27 import static org.hamcrest.core.Is.is;
28 import static org.hamcrest.core.IsEqual.equalTo;
29 import static org.junit.Assert.assertThat;
30
31 @RunWith(PowerMockRunner.class)
32 public class ConfigFileScannerTest {
33
34     @Rule
35     ExpectedException thrown = ExpectedException.none();
36
37     @Test
38     public void testScan_file_normal() {
39         ConfigFileScanner scanner = new ConfigFileScanner();
40         String file = ConfigFileScannerTest.class.getResource("/ConfigFileScannerTestData.txt").getFile();
41         Map<String, String> files = scanner.scan(file);
42         assertThat(files.values().iterator().next(), equalTo("isTest=true"));
43     }
44
45     @Test
46     public void testScan_file_empty() {
47         ConfigFileScanner scanner = new ConfigFileScanner();
48         String file = ConfigFileScannerTest.class.getResource("/ConfigFileScannerEmpty.txt").getFile();
49         Map<String, String> files = scanner.scan(file);
50         assertThat(files.size(), is(0));
51     }
52
53     @Test
54     public void testScan_directory_normal() {
55         ConfigFileScanner scanner = new ConfigFileScanner();
56         String file = ConfigFileScannerTest.class.getResource("/").getFile();
57         Map<String, String> files = scanner.scan(file);
58         assertThat(files.size(), is(5));
59     }
60 }