[DCAEGEN2] Release SDK libraries version 1.9.5
[dcaegen2/services/sdk.git] / rest-services / cbs-client / src / test / java / org / onap / dcaegen2 / services / sdk / rest / services / cbs / client / api / streams / MixedDmaapStreamsIT.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 io.vavr.collection.List;
27 import java.io.IOException;
28 import org.junit.jupiter.api.Test;
29 import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.impl.streams.gson.GsonUtils;
30 import org.onap.dcaegen2.services.sdk.model.streams.DataStreamDirection;
31 import org.onap.dcaegen2.services.sdk.model.streams.RawDataStream;
32 import org.onap.dcaegen2.services.sdk.model.streams.StreamType;
33 import org.onap.dcaegen2.services.sdk.model.streams.dmaap.DataRouterSink;
34 import org.onap.dcaegen2.services.sdk.model.streams.dmaap.DataRouterSource;
35 import org.onap.dcaegen2.services.sdk.model.streams.dmaap.MessageRouterSource;
36
37 /**
38  * @author <a href="mailto:piotr.jaszczyk@nokia.com">Piotr Jaszczyk</a>
39  * @since March 2019
40  */
41 class MixedDmaapStreamsIT {
42
43     final JsonObject json = GsonUtils.readObjectFromResource("/streams/integration_mixed_dmaap.json");
44     final List<RawDataStream<JsonObject>> sources = DataStreams.namedSources(json).toList();
45     final List<RawDataStream<JsonObject>> sinks = DataStreams.namedSinks(json).toList();
46
47     MixedDmaapStreamsIT() throws IOException {
48     }
49
50     @Test
51     void thereShouldBeSomeSinksDefined() {
52         assertThat(sinks).isNotEmpty();
53         assertThat(sinks).hasSize(3);
54     }
55
56     @Test
57     void thereShouldBeSomeSourcesDefined() {
58         assertThat(sources).isNotEmpty();
59         assertThat(sources).hasSize(3);
60     }
61
62     @Test
63     void allStreamsShouldBeOfProperType() {
64         assertThat(sources.map(RawDataStream::type).distinct()).containsExactly(StreamType.DATA_ROUTER, StreamType.MESSAGE_ROUTER);
65         assertThat(sinks.map(RawDataStream::type).distinct()).containsExactly(StreamType.DATA_ROUTER);
66     }
67
68     @Test
69     void sinksShouldHaveProperDirection() {
70         assertThat(sinks.map(RawDataStream::direction).distinct())
71                 .containsExactly(DataStreamDirection.SINK);
72     }
73
74     @Test
75     void sourcesShouldHaveProperDirection() {
76         assertThat(sources.map(RawDataStream::direction).distinct())
77                 .containsExactly(DataStreamDirection.SOURCE);
78     }
79
80     @Test
81     void verifyDcaeGuestOsSource() {
82         // given
83         final String streamName = "DCAE_GUEST_OS";
84         final RawDataStream<JsonObject> source = sources.find(streamWithName(streamName)).get();
85
86         // when
87         final DataRouterSource parsedSource = StreamFromGsonParsers.dataRouterSourceParser().unsafeParse(source);
88
89         // then
90         assertThat(parsedSource.name()).describedAs("name").isEqualTo(streamName);
91         assertThat(parsedSource.location()).describedAs("location").isEqualTo("mtn23");
92         assertThat(parsedSource.username()).describedAs("user name").isEqualTo("xyz");
93         assertThat(parsedSource.password()).describedAs("password").isEqualTo("abc");
94         assertThat(parsedSource.deliveryUrl()).describedAs("delivery url")
95                 .isEqualTo("https://dr.global:8666/DCAE_SAM_GUEST_OS");
96         assertThat(parsedSource.subscriberId()).describedAs("subscriber id").isEqualTo("811");
97     }
98
99     @Test
100     void verifyDcaeRawDataSource() {
101         // given
102         final String streamName = "DCAE_RAW_DATA";
103         final RawDataStream<JsonObject> source = sources.find(streamWithName(streamName)).get();
104
105         // when
106         final DataRouterSource parsedSource = StreamFromGsonParsers.dataRouterSourceParser().unsafeParse(source);
107
108         // then
109         assertThat(parsedSource.name()).describedAs("name").isEqualTo(streamName);
110         assertThat(parsedSource.location()).describedAs("location").isEqualTo("mtn23");
111         assertThat(parsedSource.username()).describedAs("user name").isEqualTo("abc");
112         assertThat(parsedSource.password()).describedAs("password").isEqualTo("xyz");
113         assertThat(parsedSource.deliveryUrl()).describedAs("delivery url")
114                 .isEqualTo("https://dr.global:8666/DCAE_CEILOMETER_RAW_DATA");
115         assertThat(parsedSource.subscriberId()).describedAs("subscriber id").isEqualTo("812");
116     }
117
118     @Test
119     void verifySecMeasurementOutputSource() {
120         // given
121         final String streamName = "sec-measurement-output";
122         final RawDataStream<JsonObject> source = sources.find(streamWithName(streamName))
123                 .get();
124
125         // when
126         final MessageRouterSource parsedSource = StreamFromGsonParsers.messageRouterSourceParser().unsafeParse(source);
127
128         // then
129         assertThat(parsedSource.name()).describedAs("name").isEqualTo(streamName);
130         assertThat(parsedSource.aafCredentials()).describedAs("aaf credentials").isNotNull();
131         assertThat(parsedSource.aafCredentials().username()).describedAs("aaf user name").isEqualTo("aaf_username");
132         assertThat(parsedSource.aafCredentials().password()).describedAs("aaf password").isEqualTo("aaf_password");
133         assertThat(parsedSource.location()).describedAs("location").isEqualTo("mtn23");
134         assertThat(parsedSource.clientId()).describedAs("client id").isEqualTo("1111");
135         assertThat(parsedSource.clientRole()).describedAs("client role").isEqualTo("com.att.dcae.member");
136         assertThat(parsedSource.topicUrl()).describedAs("topic url")
137                 .isEqualTo("https://mr.hostname:3905/events/com.att.dcae.dmaap.SEC-MEASUREMENT-OUTPUT-v1");
138     }
139
140     @Test
141     void verifyDcaeVoipPmDataSink() {
142         // given
143         final String streamName = "DCAE_VOIP_PM_DATA";
144         final RawDataStream<JsonObject> sink = sinks.find(streamWithName(streamName)).get();
145
146         // when
147         final DataRouterSink parsedSink = StreamFromGsonParsers.dataRouterSinkParser().unsafeParse(sink);
148
149         // then
150         assertThat(parsedSink.name()).describedAs("name").isEqualTo(streamName);
151         assertThat(parsedSink.location()).describedAs("location").isEqualTo("mtn23");
152         assertThat(parsedSink.username()).describedAs("user name").isEqualTo("abc");
153         assertThat(parsedSink.password()).describedAs("password").isEqualTo("xyz");
154         assertThat(parsedSink.logUrl()).describedAs("log url")
155                 .isEqualTo("https://dcae-drps/feedlog/206");
156         assertThat(parsedSink.publishUrl()).describedAs("publish url")
157                 .isEqualTo("https://dcae-drps/publish/206");
158         assertThat(parsedSink.publisherId()).describedAs("publisher id").isEqualTo("206.518hu");
159     }
160
161     @Test
162     void verifyDcaeGuestOsOSink() {
163         // given
164         final String streamName = "DCAE_GUEST_OS_O";
165         final RawDataStream<JsonObject> sink = sinks.find(streamWithName(streamName)).get();
166
167         // when
168         final DataRouterSink parsedSink = StreamFromGsonParsers.dataRouterSinkParser().unsafeParse(sink);
169
170         // then
171         assertThat(parsedSink.name()).describedAs("name").isEqualTo(streamName);
172         assertThat(parsedSink.location()).describedAs("location").isEqualTo("mtn23");
173         assertThat(parsedSink.username()).describedAs("user name").isEqualTo("axyz");
174         assertThat(parsedSink.password()).describedAs("password").isEqualTo("abc");
175         assertThat(parsedSink.logUrl()).describedAs("log url")
176                 .isEqualTo("https://dcae-drps/feedlog/203");
177         assertThat(parsedSink.publishUrl()).describedAs("publish url")
178                 .isEqualTo("https://dcae-drps/publish/203");
179         assertThat(parsedSink.publisherId()).describedAs("publisher id").isEqualTo("203.2od8s");
180     }
181
182
183     @Test
184     void verifyDcaePmDataSink() {
185         // given
186         final String streamName = "DCAE_PM_DATA";
187         final RawDataStream<JsonObject> sink = sinks.find(streamWithName(streamName)).get();
188
189         // when
190         final DataRouterSink parsedSink = StreamFromGsonParsers.dataRouterSinkParser().unsafeParse(sink);
191
192         // then
193         assertThat(parsedSink.name()).describedAs("name").isEqualTo(streamName);
194         assertThat(parsedSink.location()).describedAs("location").isEqualTo("mtn23bdce2");
195         assertThat(parsedSink.username()).describedAs("user name").isEqualTo("xyz");
196         assertThat(parsedSink.password()).describedAs("password").isEqualTo("abc");
197         assertThat(parsedSink.logUrl()).describedAs("log url")
198                 .isEqualTo("https://dcae-drps/feedlog/493");
199         assertThat(parsedSink.publishUrl()).describedAs("publish url")
200                 .isEqualTo("https://dcae-drps/publish/493");
201         assertThat(parsedSink.publisherId()).describedAs("publisher id").isEqualTo("493.eacqs");
202     }
203
204 }