aboutsummaryrefslogtreecommitdiffstats
path: root/rest-services/cbs-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/api/streams/MessageRouterSinksIT.java
blob: c57ce0276c81e4b377469fddeca0cbf098c6cefb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/*
 * ============LICENSE_START====================================
 * DCAEGEN2-SERVICES-SDK
 * =========================================================
 * Copyright (C) 2019 Nokia. All rights reserved.
 * =========================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ============LICENSE_END=====================================
 */
package org.onap.dcaegen2.services.sdk.rest.services.cbs.client.api.streams;

import static org.assertj.core.api.Assertions.assertThat;
import static org.onap.dcaegen2.services.sdk.rest.services.cbs.client.api.streams.StreamPredicates.streamWithName;

import com.google.gson.JsonObject;
import java.io.IOException;
import org.junit.jupiter.api.Test;
import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.impl.streams.gson.GsonUtils;
import org.onap.dcaegen2.services.sdk.model.streams.DataStreamDirection;
import org.onap.dcaegen2.services.sdk.model.streams.RawDataStream;
import org.onap.dcaegen2.services.sdk.model.streams.StreamType;
import org.onap.dcaegen2.services.sdk.model.streams.dmaap.MessageRouterSink;

/**
 * @author <a href="mailto:piotr.jaszczyk@nokia.com">Piotr Jaszczyk</a>
 * @since March 2019
 */
class MessageRouterSinksIT {

    final JsonObject json = GsonUtils.readObjectFromResource("/streams/integration_message_router.json");

    MessageRouterSinksIT() throws IOException {
    }

    @Test
    void thereShouldBeNoDataSources() {
        assertThat(DataStreams.namedSources(json)).isEmpty();
    }

    @Test
    void thereShouldBeSomeSinksDefined() {
        assertThat(DataStreams.namedSinks(json)).isNotEmpty();
        assertThat(DataStreams.namedSinks(json)).hasSize(4);
    }

    @Test
    void allSinksShouldBeOfMessageRouterType() {
        assertThat(DataStreams.namedSinks(json).map(RawDataStream::type).distinct())
                .containsExactly(StreamType.MESSAGE_ROUTER);
    }

    @Test
    void sinksShouldHaveProperDirection() {
        assertThat(DataStreams.namedSinks(json).map(RawDataStream::direction).distinct())
                .containsExactly(DataStreamDirection.SINK);
    }

    @Test
    void verifySecMeasurementSink() {
        // given
        final String streamName = "sec_measurement";
        final RawDataStream<JsonObject> sink = DataStreams.namedSinks(json).find(streamWithName(streamName))
                .get();

        // when
        final MessageRouterSink parsedSink = StreamFromGsonParsers.messageRouterSinkParser().unsafeParse(sink);

        // then
        assertThat(parsedSink.name()).describedAs("name").isEqualTo(streamName);
        assertThat(parsedSink.aafCredentials()).describedAs("aaf credentials").isNotNull();
        assertThat(parsedSink.aafCredentials().username()).describedAs("aaf user name").isEqualTo("aaf_username");
        assertThat(parsedSink.aafCredentials().password()).describedAs("aaf password").isEqualTo("aaf_password");
        assertThat(parsedSink.location()).describedAs("location").isEqualTo("mtl5");
        assertThat(parsedSink.clientId()).describedAs("client id").isEqualTo("111111");
        assertThat(parsedSink.clientRole()).describedAs("client role").isEqualTo("com.att.dcae.member");
        assertThat(parsedSink.topicUrl()).describedAs("topic url")
                .isEqualTo("https://mrlocal:3905/events/com.att.dcae.dmaap.FTL2.SEC-MEASUREMENT-OUTPUT");
    }

    @Test
    void verifySecFaultUnsecureSink() {
        // given
        final String streamName = "sec_fault_unsecure";
        final RawDataStream<JsonObject> sink = DataStreams.namedSinks(json).find(streamWithName(streamName))
                .get();

        // when
        final MessageRouterSink parsedSink = StreamFromGsonParsers.messageRouterSinkParser().unsafeParse(sink);

        // then
        assertThat(parsedSink.name()).describedAs("name").isEqualTo(streamName);
        assertThat(parsedSink.aafCredentials()).describedAs("aaf credentials").isNull();
        assertThat(parsedSink.location()).describedAs("location").isEqualTo("mtl5");
        assertThat(parsedSink.clientId()).describedAs("client id").isNull();
        assertThat(parsedSink.clientRole()).describedAs("client role").isNull();
        assertThat(parsedSink.topicUrl()).describedAs("topic url")
                .isEqualTo("http://ueb.global:3904/events/DCAE-SE-COLLECTOR-EVENTS-DEV");
    }

    @Test
    void verifySecMeasurementUnsecureSink() {
        // given
        final String streamName = "sec_measurement_unsecure";
        final RawDataStream<JsonObject> sink = DataStreams.namedSinks(json).find(streamWithName(streamName))
                .get();

        // when
        final MessageRouterSink parsedSink = StreamFromGsonParsers.messageRouterSinkParser().unsafeParse(sink);

        // then
        assertThat(parsedSink.name()).describedAs("name").isEqualTo(streamName);
        assertThat(parsedSink.aafCredentials()).describedAs("aaf credentials").isNull();
        assertThat(parsedSink.location()).describedAs("location").isEqualTo("mtl5");
        assertThat(parsedSink.clientId()).describedAs("client id").isNull();
        assertThat(parsedSink.clientRole()).describedAs("client role").isNull();
        assertThat(parsedSink.topicUrl()).describedAs("topic url")
                .isEqualTo("http://ueb.global:3904/events/DCAE-SE-COLLECTOR-EVENTS-DEV");
    }

    @Test
    void verifySecFaultSink() {
        // given
        final String streamName = "sec_fault";
        final RawDataStream<JsonObject> sink = DataStreams.namedSinks(json).find(streamWithName(streamName))
                .get();

        // when
        final MessageRouterSink parsedSink = StreamFromGsonParsers.messageRouterSinkParser().unsafeParse(sink);

        // then
        assertThat(parsedSink.name()).describedAs("name").isEqualTo(streamName);
        assertThat(parsedSink.aafCredentials()).describedAs("aaf credentials").isNotNull();
        assertThat(parsedSink.aafCredentials().username()).describedAs("aaf user name").isEqualTo("aaf_username");
        assertThat(parsedSink.aafCredentials().password()).describedAs("aaf password").isEqualTo("aaf_password");
        assertThat(parsedSink.location()).describedAs("location").isEqualTo("mtl5");
        assertThat(parsedSink.clientId()).describedAs("client id").isEqualTo("222222");
        assertThat(parsedSink.clientRole()).describedAs("client role").isEqualTo("com.att.dcae.member");
        assertThat(parsedSink.topicUrl()).describedAs("topic url")
                .isEqualTo("https://mrlocal:3905/events/com.att.dcae.dmaap.FTL2.SEC-FAULT-OUTPUT");
    }
}