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