Replace cambria with DmaaP client
[dcaegen2/collectors/ves.git] / src / test / java / org / onap / dcae / common / publishing / DMaaPConfigurationParserTest.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,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
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 package org.onap.dcae.common.publishing;
22
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;
26
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;
32
33 /**
34  * @author Pawel Szalapski (pawel.szalapski@nokia.com)
35  */
36 public class DMaaPConfigurationParserTest {
37
38     @Test
39     public void testParseCredentialsForGen2() {
40         Path path = Paths.get("src/test/resources/testParseDMaaPCredentialsGen2.json");
41         Try<Map<String, PublisherConfig>> publisherConfigs = parseToDomainMapping(path);
42
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();
47
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();
52
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();
57     }
58
59     @Test
60     public void testParseGen2() {
61         Path path = Paths.get("src/test/resources/testParseDMaaPGen2.json");
62         Try<Map<String, PublisherConfig>> publisherConfigs = parseToDomainMapping(path);
63
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");
67
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");
71     }
72
73 }