2 * ============LICENSE_START=======================================================
3 * dcaegen2-collectors-veshv
4 * ================================================================================
5 * Copyright (C) 2018 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.VesEventDomain.PERF3GPP
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 = 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 = PERF3GPP,
54 id: String = randomUUID().toString(),
55 vesEventListenerVersion: String = "7.0.2",
56 priority: Priority = Priority.NORMAL,
57 lastEpochMicrosec: Long = 100000005
58 ): CommonEventHeader =
59 CommonEventHeader.newBuilder()
60 .setVersion("sample-version")
61 .setDomain(domain.domainName)
63 .setPriority(priority)
65 .setEventName("sample-event-name")
66 .setEventType("sample-event-type")
67 .setStartEpochMicrosec(100000000)
68 .setLastEpochMicrosec(lastEpochMicrosec)
69 .setNfNamingCode("sample-nf-naming-code")
70 .setNfcNamingCode("sample-nfc-naming-code")
71 .setNfVendorName("vendor-name")
72 .setReportingEntityId(ByteString.copyFromUtf8("sample-reporting-entity-id"))
73 .setReportingEntityName("sample-reporting-entity-name")
74 .setSourceId(ByteString.copyFromUtf8("sample-source-id"))
75 .setSourceName("sample-source-name")
76 .setTimeZoneOffset("+1")
77 .setVesEventListenerVersion(vesEventListenerVersion)
80 fun emptyWireProtocolFrame(): WireFrameMessage = wireProtocolFrameWithPayloadSize(0)
83 fun wireProtocolFrameWithPayloadSize(size: Int): WireFrameMessage = WireFrameMessage(
84 payload = ByteData(ByteArray(size)),
85 versionMajor = WireFrameMessage.SUPPORTED_VERSION_MAJOR,
86 versionMinor = WireFrameMessage.SUPPORTED_VERSION_MINOR,
88 payloadType = PayloadContentType.GOOGLE_PROTOCOL_BUFFER.hexValue
91 fun wireProtocolFrame(commonHeader: CommonEventHeader,
92 eventFields: ByteString = ByteString.EMPTY,
93 receivedAt: Temporal = Instant.now()): WireFrameMessage =
94 vesEventBytes(commonHeader, eventFields).let { payload ->
97 versionMajor = WireFrameMessage.SUPPORTED_VERSION_MAJOR,
98 versionMinor = WireFrameMessage.SUPPORTED_VERSION_MINOR,
99 payloadSize = payload.size(),
100 payloadType = PayloadContentType.GOOGLE_PROTOCOL_BUFFER.hexValue,
101 receivedAt = receivedAt
105 fun wireProtocolFrame(evt: VesEventOuterClass.VesEvent) =
107 payload = ByteData(evt.toByteArray()),
108 payloadSize = evt.serializedSize,
109 payloadType = PayloadContentType.GOOGLE_PROTOCOL_BUFFER.hexValue,
110 versionMajor = WireFrameMessage.SUPPORTED_VERSION_MAJOR,
111 versionMinor = WireFrameMessage.SUPPORTED_VERSION_MINOR
114 fun vesEventBytes(commonHeader: CommonEventHeader, eventFields: ByteString = ByteString.EMPTY): ByteData =
115 vesEvent(commonHeader, eventFields).toByteData()
117 fun MessageLite.toByteData(): ByteData = ByteData(toByteArray())