2 * ============LICENSE_START=======================================================
3 * dcaegen2-collectors-veshv
4 * ================================================================================
5 * Copyright (C) 2018-2021 NOKIA
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
20 package org.onap.dcae.collectors.veshv.tests.utils
23 import com.google.protobuf.ByteString
24 import com.google.protobuf.MessageLite
25 import org.onap.dcae.collectors.veshv.domain.ByteData
26 import org.onap.dcae.collectors.veshv.domain.PayloadContentType
27 import org.onap.dcae.collectors.veshv.domain.VesEventDomain
28 import org.onap.dcae.collectors.veshv.domain.VesEventStndDefinedNamespace
29 import org.onap.dcae.collectors.veshv.domain.WireFrameMessage
30 import org.onap.ves.VesEventOuterClass
31 import org.onap.ves.VesEventOuterClass.CommonEventHeader
32 import org.onap.ves.VesEventOuterClass.CommonEventHeader.Priority
33 import java.time.Instant
34 import java.time.temporal.Temporal
35 import java.util.UUID.randomUUID
37 fun vesEvent(domain: VesEventDomain = VesEventDomain.PERF3GPP,
38 id: String = randomUUID().toString(),
39 eventFields: ByteString = ByteString.EMPTY,
40 vesEventListenerVersion: String = "7.0.2"
41 ): VesEventOuterClass.VesEvent = vesEvent(
42 commonHeader(domain, id, vesEventListenerVersion, lastEpochMicrosec = 100000005),
46 fun vesEvent(commonEventHeader: CommonEventHeader,
47 eventFields: ByteString = ByteString.EMPTY): VesEventOuterClass.VesEvent =
48 VesEventOuterClass.VesEvent.newBuilder()
49 .setCommonEventHeader(commonEventHeader)
50 .setEventFields(eventFields)
53 fun commonHeader(domain: VesEventDomain = VesEventDomain.PERF3GPP,
54 id: String = randomUUID().toString(),
55 vesEventListenerVersion: String = "7.0.2",
56 priority: Priority = Priority.NORMAL,
57 lastEpochMicrosec: Long = 100000005,
58 stndDefinedNamespace: VesEventStndDefinedNamespace? = null): CommonEventHeader {
59 val builder = CommonEventHeader.newBuilder().setVersion("sample-version")
60 .setDomain(domain.domainName)
62 .setPriority(priority)
64 .setEventName("sample-event-name")
65 .setEventType("sample-event-type")
66 .setStartEpochMicrosec(100000000)
67 .setLastEpochMicrosec(lastEpochMicrosec)
68 .setNfNamingCode("sample-nf-naming-code")
69 .setNfcNamingCode("sample-nfc-naming-code")
70 .setNfVendorName("vendor-name")
71 .setReportingEntityId(ByteString.copyFromUtf8("sample-reporting-entity-id"))
72 .setReportingEntityName("sample-reporting-entity-name")
73 .setSourceId(ByteString.copyFromUtf8("sample-source-id"))
74 .setSourceName("sample-source-name")
75 .setTimeZoneOffset("+1")
76 .setVesEventListenerVersion(vesEventListenerVersion)
78 stndDefinedNamespace?.let {
79 builder.setStndDefinedNamespace(stndDefinedNamespace.stndDefinedNamespace)
81 return builder.build()
85 fun emptyWireProtocolFrame(): WireFrameMessage = wireProtocolFrameWithPayloadSize(0)
88 fun wireProtocolFrameWithPayloadSize(size: Int): WireFrameMessage = WireFrameMessage(
89 payload = ByteData(ByteArray(size)),
90 versionMajor = WireFrameMessage.SUPPORTED_VERSION_MAJOR,
91 versionMinor = WireFrameMessage.SUPPORTED_VERSION_MINOR,
93 payloadType = PayloadContentType.GOOGLE_PROTOCOL_BUFFER.hexValue
96 fun wireProtocolFrame(commonHeader: CommonEventHeader,
97 eventFields: ByteString = ByteString.EMPTY,
98 receivedAt: Temporal = Instant.now()): WireFrameMessage =
99 vesEventBytes(commonHeader, eventFields).let { payload ->
102 versionMajor = WireFrameMessage.SUPPORTED_VERSION_MAJOR,
103 versionMinor = WireFrameMessage.SUPPORTED_VERSION_MINOR,
104 payloadSize = payload.size(),
105 payloadType = PayloadContentType.GOOGLE_PROTOCOL_BUFFER.hexValue,
106 receivedAt = receivedAt
110 fun wireProtocolFrame(evt: VesEventOuterClass.VesEvent) =
112 payload = ByteData(evt.toByteArray()),
113 payloadSize = evt.serializedSize,
114 payloadType = PayloadContentType.GOOGLE_PROTOCOL_BUFFER.hexValue,
115 versionMajor = WireFrameMessage.SUPPORTED_VERSION_MAJOR,
116 versionMinor = WireFrameMessage.SUPPORTED_VERSION_MINOR
119 fun vesEventBytes(commonHeader: CommonEventHeader, eventFields: ByteString = ByteString.EMPTY): ByteData =
120 vesEvent(commonHeader, eventFields).toByteData()
122 fun MessageLite.toByteData(): ByteData = ByteData(toByteArray())