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,2021 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();
60 public void testParseGen2() {
61 Path path = Paths.get("src/test/resources/testParseDMaaPGen2.json");
62 Try<Map<String, PublisherConfig>> publisherConfigs = parseToDomainMapping(path);
64 PublisherConfig withEventsSegment = publisherConfigs.get().get("event-segments-with-port").getOrNull();
65 assertThat(withEventsSegment.destinations()).isEqualTo(List("UEBHOST:3904"));
66 assertThat(withEventsSegment.topic()).isEqualTo("DCAE-SE-COLLECTOR-EVENTS-DEV");
68 PublisherConfig withOtherSegment = publisherConfigs.get().get("other-segments-without-ports").getOrNull();
69 assertThat(withOtherSegment.destinations()).isEqualTo(List("UEBHOST"));
70 assertThat(withOtherSegment.topic()).isEqualTo("DCAE-SE-COLLECTOR-EVENTS-DEV");