[DCAEGEN2] Release SDK libraries version 1.9.4
[dcaegen2/services/sdk.git] / rest-services / cbs-client / src / test / java / org / onap / dcaegen2 / services / sdk / rest / services / cbs / client / api / streams / MessageRouterSinksIT.java
1 /*
2  * ============LICENSE_START====================================
3  * DCAEGEN2-SERVICES-SDK
4  * =========================================================
5  * Copyright (C) 2019 Nokia. All rights reserved.
6  * =========================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *       http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=====================================
19  */
20 package org.onap.dcaegen2.services.sdk.rest.services.cbs.client.api.streams;
21
22 import static org.assertj.core.api.Assertions.assertThat;
23 import static org.onap.dcaegen2.services.sdk.rest.services.cbs.client.api.streams.StreamPredicates.streamWithName;
24
25 import com.google.gson.JsonObject;
26 import java.io.IOException;
27 import org.junit.jupiter.api.Test;
28 import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.impl.streams.gson.GsonUtils;
29 import org.onap.dcaegen2.services.sdk.model.streams.DataStreamDirection;
30 import org.onap.dcaegen2.services.sdk.model.streams.RawDataStream;
31 import org.onap.dcaegen2.services.sdk.model.streams.StreamType;
32 import org.onap.dcaegen2.services.sdk.model.streams.dmaap.MessageRouterSink;
33
34 /**
35  * @author <a href="mailto:piotr.jaszczyk@nokia.com">Piotr Jaszczyk</a>
36  * @since March 2019
37  */
38 class MessageRouterSinksIT {
39
40     final JsonObject json = GsonUtils.readObjectFromResource("/streams/integration_message_router.json");
41
42     MessageRouterSinksIT() throws IOException {
43     }
44
45     @Test
46     void thereShouldBeNoDataSources() {
47         assertThat(DataStreams.namedSources(json)).isEmpty();
48     }
49
50     @Test
51     void thereShouldBeSomeSinksDefined() {
52         assertThat(DataStreams.namedSinks(json)).isNotEmpty();
53         assertThat(DataStreams.namedSinks(json)).hasSize(4);
54     }
55
56     @Test
57     void allSinksShouldBeOfMessageRouterType() {
58         assertThat(DataStreams.namedSinks(json).map(RawDataStream::type).distinct())
59                 .containsExactly(StreamType.MESSAGE_ROUTER);
60     }
61
62     @Test
63     void sinksShouldHaveProperDirection() {
64         assertThat(DataStreams.namedSinks(json).map(RawDataStream::direction).distinct())
65                 .containsExactly(DataStreamDirection.SINK);
66     }
67
68     @Test
69     void verifySecMeasurementSink() {
70         // given
71         final String streamName = "sec_measurement";
72         final RawDataStream<JsonObject> sink = DataStreams.namedSinks(json).find(streamWithName(streamName))
73                 .get();
74
75         // when
76         final MessageRouterSink parsedSink = StreamFromGsonParsers.messageRouterSinkParser().unsafeParse(sink);
77
78         // then
79         assertThat(parsedSink.name()).describedAs("name").isEqualTo(streamName);
80         assertThat(parsedSink.aafCredentials()).describedAs("aaf credentials").isNotNull();
81         assertThat(parsedSink.aafCredentials().username()).describedAs("aaf user name").isEqualTo("aaf_username");
82         assertThat(parsedSink.aafCredentials().password()).describedAs("aaf password").isEqualTo("aaf_password");
83         assertThat(parsedSink.location()).describedAs("location").isEqualTo("mtl5");
84         assertThat(parsedSink.clientId()).describedAs("client id").isEqualTo("111111");
85         assertThat(parsedSink.clientRole()).describedAs("client role").isEqualTo("com.att.dcae.member");
86         assertThat(parsedSink.topicUrl()).describedAs("topic url")
87                 .isEqualTo("https://mrlocal:3905/events/com.att.dcae.dmaap.FTL2.SEC-MEASUREMENT-OUTPUT");
88     }
89
90     @Test
91     void verifySecFaultUnsecureSink() {
92         // given
93         final String streamName = "sec_fault_unsecure";
94         final RawDataStream<JsonObject> sink = DataStreams.namedSinks(json).find(streamWithName(streamName))
95                 .get();
96
97         // when
98         final MessageRouterSink parsedSink = StreamFromGsonParsers.messageRouterSinkParser().unsafeParse(sink);
99
100         // then
101         assertThat(parsedSink.name()).describedAs("name").isEqualTo(streamName);
102         assertThat(parsedSink.aafCredentials()).describedAs("aaf credentials").isNull();
103         assertThat(parsedSink.location()).describedAs("location").isEqualTo("mtl5");
104         assertThat(parsedSink.clientId()).describedAs("client id").isNull();
105         assertThat(parsedSink.clientRole()).describedAs("client role").isNull();
106         assertThat(parsedSink.topicUrl()).describedAs("topic url")
107                 .isEqualTo("http://ueb.global:3904/events/DCAE-SE-COLLECTOR-EVENTS-DEV");
108     }
109
110     @Test
111     void verifySecMeasurementUnsecureSink() {
112         // given
113         final String streamName = "sec_measurement_unsecure";
114         final RawDataStream<JsonObject> sink = DataStreams.namedSinks(json).find(streamWithName(streamName))
115                 .get();
116
117         // when
118         final MessageRouterSink parsedSink = StreamFromGsonParsers.messageRouterSinkParser().unsafeParse(sink);
119
120         // then
121         assertThat(parsedSink.name()).describedAs("name").isEqualTo(streamName);
122         assertThat(parsedSink.aafCredentials()).describedAs("aaf credentials").isNull();
123         assertThat(parsedSink.location()).describedAs("location").isEqualTo("mtl5");
124         assertThat(parsedSink.clientId()).describedAs("client id").isNull();
125         assertThat(parsedSink.clientRole()).describedAs("client role").isNull();
126         assertThat(parsedSink.topicUrl()).describedAs("topic url")
127                 .isEqualTo("http://ueb.global:3904/events/DCAE-SE-COLLECTOR-EVENTS-DEV");
128     }
129
130     @Test
131     void verifySecFaultSink() {
132         // given
133         final String streamName = "sec_fault";
134         final RawDataStream<JsonObject> sink = DataStreams.namedSinks(json).find(streamWithName(streamName))
135                 .get();
136
137         // when
138         final MessageRouterSink parsedSink = StreamFromGsonParsers.messageRouterSinkParser().unsafeParse(sink);
139
140         // then
141         assertThat(parsedSink.name()).describedAs("name").isEqualTo(streamName);
142         assertThat(parsedSink.aafCredentials()).describedAs("aaf credentials").isNotNull();
143         assertThat(parsedSink.aafCredentials().username()).describedAs("aaf user name").isEqualTo("aaf_username");
144         assertThat(parsedSink.aafCredentials().password()).describedAs("aaf password").isEqualTo("aaf_password");
145         assertThat(parsedSink.location()).describedAs("location").isEqualTo("mtl5");
146         assertThat(parsedSink.clientId()).describedAs("client id").isEqualTo("222222");
147         assertThat(parsedSink.clientRole()).describedAs("client role").isEqualTo("com.att.dcae.member");
148         assertThat(parsedSink.topicUrl()).describedAs("topic url")
149                 .isEqualTo("https://mrlocal:3905/events/com.att.dcae.dmaap.FTL2.SEC-FAULT-OUTPUT");
150     }
151 }