Release 1.7.3 DCAEGEN2 VESCollector container
[dcaegen2/collectors/ves.git] / src / test / java / org / onap / dcae / configuration / ConfigParsingTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * org.onap.dcaegen2.collectors.ves
4  * ================================================================================
5  * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6  * Copyright (C) 2018,2020 Nokia. 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  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.dcae.configuration;
23
24 import io.vavr.collection.Map;
25 import io.vavr.control.Option;
26 import org.json.JSONObject;
27 import org.junit.Test;
28
29 import java.nio.file.Paths;
30
31 import static io.vavr.API.Map;
32 import static org.assertj.core.api.Assertions.assertThat;
33 import static org.onap.dcae.TestingUtilities.assertJSONObjectsEqual;
34 import static org.onap.dcae.TestingUtilities.readJSONFromFile;
35
36 public class ConfigParsingTest {
37
38     @Test
39     public void shouldReturnDMaaPConfig() {
40         JSONObject dMaaPConf = readJSONFromFile(Paths.get("src/test/resources/testParseDMaaPCredentialsGen2.json"));
41         JSONObject root = new JSONObject();
42         root.put("key1", "someProperty");
43         root.put("key2", "someProperty");
44         root.put("streams_publishes", dMaaPConf);
45
46         Option<JSONObject> dMaaPConfig = ConfigParsing.getDMaaPConfig(root);
47
48         assertThat(dMaaPConfig.isEmpty()).isFalse();
49         assertJSONObjectsEqual(dMaaPConfig.get(), dMaaPConf);
50     }
51
52     @Test
53     public void shouldReturnEmptyIfDMaaPConfigIsInvalid() {
54         JSONObject root = new JSONObject();
55         root.put("streams_publishes", 1);
56
57         Option<JSONObject> dMaaPConfig = ConfigParsing.getDMaaPConfig(root);
58
59         assertThat(dMaaPConfig.isEmpty()).isTrue();
60     }
61
62     @Test
63     public void getProperties() {
64         JSONObject dMaaPConf = readJSONFromFile(Paths.get("src/test/resources/testParseDMaaPCredentialsGen2.json"));
65         JSONObject root = new JSONObject();
66         root.put("key1", "someProperty");
67         root.put("key2", "someProperty");
68         root.put("streams_publishes", dMaaPConf);
69
70         Map<String, String> properties = ConfigParsing.getProperties(root);
71         assertThat(properties).isEqualTo(Map("key1", "someProperty", "key2", "someProperty"));
72     }
73 }