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 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=========================================================
21 package org.onap.dcae.common.publishing;
23 import static io.vavr.API.List;
24 import static org.assertj.core.api.Assertions.assertThat;
25 import static org.onap.dcae.common.publishing.DMaaPConfigurationParser.parseToDomainMapping;
27 import io.vavr.collection.Map;
28 import io.vavr.control.Try;
29 import java.nio.file.Path;
30 import java.nio.file.Paths;
31 import org.junit.Test;
34 * @author Pawel Szalapski (pawel.szalapski@nokia.com)
36 public class DMaaPConfigurationParserTest {
39 public void testParseCredentialsForGen2() {
40 Path path = Paths.get("src/test/resources/testParseDMaaPCredentialsGen2.json");
41 Try<Map<String, PublisherConfig>> publisherConfigs = parseToDomainMapping(path);
43 PublisherConfig authCredentialsNulls = publisherConfigs.get().get("auth-credentials-null").getOrNull();
44 assertThat(authCredentialsNulls.userName().isEmpty()).isTrue();
45 assertThat(authCredentialsNulls.password().isEmpty()).isTrue();
46 assertThat(authCredentialsNulls.isSecured()).isFalse();
48 PublisherConfig authCredentialsPresent = publisherConfigs.get().get("auth-credentials-present").getOrNull();
49 assertThat(authCredentialsPresent.userName().getOrNull()).isEqualTo("sampleUser");
50 assertThat(authCredentialsPresent.password().getOrNull()).isEqualTo("samplePassword");
51 assertThat(authCredentialsPresent.isSecured()).isTrue();
53 PublisherConfig authCredentialsKeysMissing = publisherConfigs.get().get("auth-credentials-missing").getOrNull();
54 assertThat(authCredentialsKeysMissing.userName().isEmpty()).isTrue();
55 assertThat(authCredentialsKeysMissing.password().isEmpty()).isTrue();
56 assertThat(authCredentialsKeysMissing.isSecured()).isFalse();
61 public void testParseCredentialsForLegacy() {
62 Path path = Paths.get("src/test/resources/testParseDMaaPCredentialsLegacy.json");
63 Try<Map<String, PublisherConfig>> publisherConfigs = parseToDomainMapping(path);
65 PublisherConfig authCredentialsNull = publisherConfigs.get().get("auth-credentials-null").getOrNull();
66 assertThat(authCredentialsNull.userName().isEmpty()).isTrue();
67 assertThat(authCredentialsNull.password().isEmpty()).isTrue();
68 assertThat(authCredentialsNull.isSecured()).isFalse();
70 PublisherConfig authCredentialsPresent = publisherConfigs.get().get("auth-credentials-present").getOrNull();
71 assertThat(authCredentialsPresent.userName().getOrNull()).isEqualTo("sampleUser");
72 assertThat(authCredentialsPresent.password().getOrNull()).isEqualTo("samplePassword");
73 assertThat(authCredentialsPresent.isSecured()).isTrue();
75 PublisherConfig authCredentialsMissing = publisherConfigs.get().get("auth-credentials-missing").getOrNull();
76 assertThat(authCredentialsMissing.userName().isEmpty()).isTrue();
77 assertThat(authCredentialsMissing.password().isEmpty()).isTrue();
78 assertThat(authCredentialsMissing.isSecured()).isFalse();
83 public void testParseGen2() {
84 Path path = Paths.get("src/test/resources/testParseDMaaPGen2.json");
85 Try<Map<String, PublisherConfig>> publisherConfigs = parseToDomainMapping(path);
87 PublisherConfig withEventsSegment = publisherConfigs.get().get("event-segments-with-port").getOrNull();
88 assertThat(withEventsSegment.destinations()).isEqualTo(List("UEBHOST:3904"));
89 assertThat(withEventsSegment.topic()).isEqualTo("DCAE-SE-COLLECTOR-EVENTS-DEV");
91 PublisherConfig withOtherSegment = publisherConfigs.get().get("other-segments-without-ports").getOrNull();
92 assertThat(withOtherSegment.destinations()).isEqualTo(List("UEBHOST"));
93 assertThat(withOtherSegment.topic()).isEqualTo("DCAE-SE-COLLECTOR-EVENTS-DEV");
97 public void testParseLegacy() {
98 Path exemplaryConfig = Paths.get("src/test/resources/testParseDMaaPLegacy.json");
99 Try<Map<String, PublisherConfig>> publisherConfigs = DMaaPConfigurationParser
100 .parseToDomainMapping(exemplaryConfig);
102 PublisherConfig urlFirstThenHosts = publisherConfigs.get().get("url-precedes-hosts").getOrNull();
103 assertThat(urlFirstThenHosts.destinations()).isEqualTo(List("127.0.0.1:3904"));
104 assertThat(urlFirstThenHosts.topic()).isEqualTo("DCAE-SE-COLLECTOR-EVENTS-DEV");
106 PublisherConfig urlKeyMissing = publisherConfigs.get().get("url-key-missing").getOrNull();
107 assertThat(urlKeyMissing.destinations()).isEqualTo(List("h1.att.com", "h2.att.com"));
108 assertThat(urlKeyMissing.topic()).isEqualTo("DCAE-SE-COLLECTOR-EVENTS-DEV");
110 PublisherConfig urlIsMissing = publisherConfigs.get().get("url-is-null").getOrNull();
111 assertThat(urlIsMissing.destinations()).isEqualTo(List("h1.att.com", "h2.att.com"));
112 assertThat(urlIsMissing.topic()).isEqualTo("DCAE-SE-COLLECTOR-EVENTS-DEV");