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.util.UUID.randomUUID
35 fun vesEvent(domain: VesEventDomain = PERF3GPP,
36 id: String = randomUUID().toString(),
37 eventFields: ByteString = ByteString.EMPTY,
38 vesEventListenerVersion: String = "7.0.2"
39 ): VesEventOuterClass.VesEvent = vesEvent(
40 commonHeader(domain, id, vesEventListenerVersion),
44 fun vesEvent(commonEventHeader: CommonEventHeader,
45 eventFields: ByteString = ByteString.EMPTY): VesEventOuterClass.VesEvent =
46 VesEventOuterClass.VesEvent.newBuilder()
47 .setCommonEventHeader(commonEventHeader)
48 .setEventFields(eventFields)
51 fun commonHeader(domain: VesEventDomain = PERF3GPP,
52 id: String = randomUUID().toString(),
53 vesEventListenerVersion: String = "7.0.2",
54 priority: Priority = Priority.NORMAL
55 ): CommonEventHeader =
56 CommonEventHeader.newBuilder()
57 .setVersion("sample-version")
58 .setDomain(domain.domainName)
60 .setPriority(priority)
62 .setEventName("sample-event-name")
63 .setEventType("sample-event-type")
64 .setStartEpochMicrosec(100000000)
65 .setLastEpochMicrosec(100000005)
66 .setNfNamingCode("sample-nf-naming-code")
67 .setNfcNamingCode("sample-nfc-naming-code")
68 .setNfVendorName("vendor-name")
69 .setReportingEntityId(ByteString.copyFromUtf8("sample-reporting-entity-id"))
70 .setReportingEntityName("sample-reporting-entity-name")
71 .setSourceId(ByteString.copyFromUtf8("sample-source-id"))
72 .setSourceName("sample-source-name")
73 .setTimeZoneOffset("+1")
74 .setVesEventListenerVersion(vesEventListenerVersion)
77 fun emptyWireProtocolFrame(): WireFrameMessage = wireProtocolFrameWithPayloadSize(0)
80 fun wireProtocolFrameWithPayloadSize(size: Int): WireFrameMessage = WireFrameMessage(
81 payload = ByteData(ByteArray(size)),
82 versionMajor = WireFrameMessage.SUPPORTED_VERSION_MAJOR,
83 versionMinor = WireFrameMessage.SUPPORTED_VERSION_MINOR,
85 payloadType = PayloadContentType.GOOGLE_PROTOCOL_BUFFER.hexValue
88 fun wireProtocolFrame(commonHeader: CommonEventHeader, eventFields: ByteString = ByteString.EMPTY): WireFrameMessage =
89 vesEventBytes(commonHeader, eventFields).let { payload ->
92 versionMajor = WireFrameMessage.SUPPORTED_VERSION_MAJOR,
93 versionMinor = WireFrameMessage.SUPPORTED_VERSION_MINOR,
94 payloadSize = payload.size(),
95 payloadType = PayloadContentType.GOOGLE_PROTOCOL_BUFFER.hexValue
99 fun wireProtocolFrame(evt: VesEventOuterClass.VesEvent) =
101 payload = ByteData(evt.toByteArray()),
102 payloadSize = evt.serializedSize,
103 payloadType = PayloadContentType.GOOGLE_PROTOCOL_BUFFER.hexValue,
104 versionMajor = WireFrameMessage.SUPPORTED_VERSION_MAJOR,
105 versionMinor = WireFrameMessage.SUPPORTED_VERSION_MINOR
108 fun vesEventBytes(commonHeader: CommonEventHeader, eventFields: ByteString = ByteString.EMPTY): ByteData =
109 vesEvent(commonHeader, eventFields).toByteData()
111 fun MessageLite.toByteData(): ByteData = ByteData(toByteArray())