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
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.
19 * ============LICENSE_END=========================================================
22 package org.onap.dcae.configuration;
24 import io.vavr.collection.Map;
25 import io.vavr.control.Option;
26 import org.json.JSONObject;
27 import org.junit.Test;
29 import java.nio.file.Paths;
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;
36 public class ConfigParsingTest {
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);
46 Option<JSONObject> dMaaPConfig = ConfigParsing.getDMaaPConfig(root);
48 assertThat(dMaaPConfig.isEmpty()).isFalse();
49 assertJSONObjectsEqual(dMaaPConfig.get(), dMaaPConf);
53 public void shouldReturnEmptyIfDMaaPConfigIsInvalid() {
54 JSONObject root = new JSONObject();
55 root.put("streams_publishes", 1);
57 Option<JSONObject> dMaaPConfig = ConfigParsing.getDMaaPConfig(root);
59 assertThat(dMaaPConfig.isEmpty()).isTrue();
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);
70 Map<String, String> properties = ConfigParsing.getProperties(root);
71 assertThat(properties).isEqualTo(Map("key1", "someProperty", "key2", "someProperty"));