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, lastEpochMicrosec = 100000005),
 
  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                  lastEpochMicrosec: Long = 100000005
 
  56                  ): CommonEventHeader =
 
  57         CommonEventHeader.newBuilder()
 
  58                 .setVersion("sample-version")
 
  59                 .setDomain(domain.domainName)
 
  61                 .setPriority(priority)
 
  63                 .setEventName("sample-event-name")
 
  64                 .setEventType("sample-event-type")
 
  65                 .setStartEpochMicrosec(100000000)
 
  66                 .setLastEpochMicrosec(lastEpochMicrosec)
 
  67                 .setNfNamingCode("sample-nf-naming-code")
 
  68                 .setNfcNamingCode("sample-nfc-naming-code")
 
  69                 .setNfVendorName("vendor-name")
 
  70                 .setReportingEntityId(ByteString.copyFromUtf8("sample-reporting-entity-id"))
 
  71                 .setReportingEntityName("sample-reporting-entity-name")
 
  72                 .setSourceId(ByteString.copyFromUtf8("sample-source-id"))
 
  73                 .setSourceName("sample-source-name")
 
  74                 .setTimeZoneOffset("+1")
 
  75                 .setVesEventListenerVersion(vesEventListenerVersion)
 
  78 fun emptyWireProtocolFrame(): WireFrameMessage = wireProtocolFrameWithPayloadSize(0)
 
  81 fun wireProtocolFrameWithPayloadSize(size: Int): WireFrameMessage = WireFrameMessage(
 
  82         payload = ByteData(ByteArray(size)),
 
  83         versionMajor = WireFrameMessage.SUPPORTED_VERSION_MAJOR,
 
  84         versionMinor = WireFrameMessage.SUPPORTED_VERSION_MINOR,
 
  86         payloadType = PayloadContentType.GOOGLE_PROTOCOL_BUFFER.hexValue
 
  89 fun wireProtocolFrame(commonHeader: CommonEventHeader, eventFields: ByteString = ByteString.EMPTY): WireFrameMessage =
 
  90         vesEventBytes(commonHeader, eventFields).let { payload ->
 
  93                     versionMajor = WireFrameMessage.SUPPORTED_VERSION_MAJOR,
 
  94                     versionMinor = WireFrameMessage.SUPPORTED_VERSION_MINOR,
 
  95                     payloadSize = payload.size(),
 
  96                     payloadType = PayloadContentType.GOOGLE_PROTOCOL_BUFFER.hexValue
 
 100 fun wireProtocolFrame(evt: VesEventOuterClass.VesEvent) =
 
 102                 payload = ByteData(evt.toByteArray()),
 
 103                 payloadSize = evt.serializedSize,
 
 104                 payloadType = PayloadContentType.GOOGLE_PROTOCOL_BUFFER.hexValue,
 
 105                 versionMajor = WireFrameMessage.SUPPORTED_VERSION_MAJOR,
 
 106                 versionMinor = WireFrameMessage.SUPPORTED_VERSION_MINOR
 
 109 fun vesEventBytes(commonHeader: CommonEventHeader, eventFields: ByteString = ByteString.EMPTY): ByteData =
 
 110         vesEvent(commonHeader, eventFields).toByteData()
 
 112 fun MessageLite.toByteData(): ByteData = ByteData(toByteArray())