34175577547c92bee8706b40d22c8bb239f69e06
[dcaegen2/services/sdk.git] /
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.services.hvves.client.producer.ct;
21
22 import static org.assertj.core.api.Assertions.assertThat;
23
24 import io.netty.buffer.ByteBuf;
25 import org.junit.jupiter.api.AfterEach;
26 import org.junit.jupiter.api.Test;
27 import org.onap.dcaegen2.services.sdk.services.hvves.client.producer.api.options.PayloadType;
28 import org.onap.ves.MeasDataCollectionOuterClass;
29 import org.onap.ves.VesEventOuterClass.CommonEventHeader;
30 import org.onap.ves.VesEventOuterClass.VesEvent;
31 import reactor.core.publisher.Flux;
32
33 import java.time.Duration;
34
35 /**
36  * @author <a href="mailto:piotr.jaszczyk@nokia.com">Piotr Jaszczyk</a>
37  */
38 class HvVesProducerIT {
39
40     private static final int INFO_ID = 17;
41     private static final long VALUE = 5l;
42     private static final int MEAS_TYPE = 3;
43     private static final int PERIOD = 1000;
44     private static final String OBJECT_INSTANCE_ID = "DH-1";
45
46     private final SystemUnderTestWrapper sut = new SystemUnderTestWrapper(Duration.ofSeconds(10));
47
48     @AfterEach
49     void tearDown() {
50         sut.stop();
51     }
52
53     @Test
54     void singleMessageTest_withUnsecureConnection() throws Exception {
55         // given
56         final VesEvent sampleEvent = createSimpleVesEvent();
57         final Flux<VesEvent> input = Flux.just(sampleEvent);
58
59         // when
60         sut.start();
61         final ByteBuf receivedData = sut.blockingSend(input);
62
63         // then
64         WireProtocolDecoder decoded = WireProtocolDecoder.decode(receivedData);
65         assertThat(decoded.type).isEqualTo(PayloadType.PROTOBUF.getPayloadTypeBytes().getShort());
66         assertThat(decoded.event).isEqualTo(sampleEvent);
67
68     }
69
70     @Test
71     void singleMessageTest_withSecureConnection() throws Exception {
72         // given
73         final VesEvent sampleEvent = createSimpleVesEvent();
74         final Flux<VesEvent> input = Flux.just(sampleEvent);
75
76         // when
77         sut.startSecure();
78         final ByteBuf receivedData = sut.blockingSend(input);
79
80         // then
81         WireProtocolDecoder decoded = WireProtocolDecoder.decode(receivedData);
82         assertThat(decoded.type).isEqualTo(PayloadType.PROTOBUF.getPayloadTypeBytes().getShort());
83         assertThat(decoded.event).isEqualTo(sampleEvent);
84
85     }
86
87     private VesEvent createSimpleVesEvent() {
88         final MeasDataCollectionOuterClass.MeasDataCollection content = MeasDataCollectionOuterClass.MeasDataCollection
89                 .newBuilder()
90                 .addMeasInfo(MeasDataCollectionOuterClass.MeasInfo.newBuilder()
91                         .addMeasValues(MeasDataCollectionOuterClass.MeasValue.newBuilder()
92                                 .addMeasResults(MeasDataCollectionOuterClass.MeasResult.newBuilder()
93                                         .setIValue(VALUE).build())
94                                 .build())
95                         .setIMeasInfoId(INFO_ID)
96                         .setIMeasTypes(MeasDataCollectionOuterClass.MeasInfo.IMeasTypes.newBuilder()
97                                 .addIMeasType(MEAS_TYPE))
98                         .build())
99                 .setGranularityPeriod(PERIOD)
100                 .addMeasObjInstIdList(OBJECT_INSTANCE_ID)
101                 .build();
102         return VesEvent.newBuilder()
103                 .setCommonEventHeader(CommonEventHeader.newBuilder()
104                         .setDomain("RTPM")
105                         .build())
106                 .setEventFields(content.toByteString())
107                 .build();
108     }
109 }