Bump checkstyle version
[dcaegen2/collectors/hv-ves.git] / sources / hv-collector-test-utils / src / main / kotlin / org / onap / dcae / collectors / veshv / tests / utils / vesEvents.kt
1 /*
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
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.dcae.collectors.veshv.tests.utils
21
22
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.VesEventDomain
27 import org.onap.dcae.collectors.veshv.domain.VesEventDomain.PERF3GPP
28 import org.onap.ves.VesEventOuterClass
29 import org.onap.ves.VesEventOuterClass.CommonEventHeader
30 import org.onap.ves.VesEventOuterClass.CommonEventHeader.Priority
31 import java.util.UUID.randomUUID
32
33 fun vesEvent(domain: VesEventDomain = PERF3GPP,
34              id: String = randomUUID().toString(),
35              eventFields: ByteString = ByteString.EMPTY
36 ): VesEventOuterClass.VesEvent = vesEvent(commonHeader(domain, id), eventFields)
37
38 fun vesEvent(commonEventHeader: CommonEventHeader,
39              eventFields: ByteString = ByteString.EMPTY): VesEventOuterClass.VesEvent =
40         VesEventOuterClass.VesEvent.newBuilder()
41                 .setCommonEventHeader(commonEventHeader)
42                 .setEventFields(eventFields)
43                 .build()
44
45 fun commonHeader(domain: VesEventDomain = PERF3GPP,
46                  id: String = randomUUID().toString(),
47                  priority: Priority = Priority.NORMAL,
48                  vesEventListenerVersion: String = "7.0.2"): CommonEventHeader =
49         CommonEventHeader.newBuilder()
50                 .setVersion("sample-version")
51                 .setDomain(domain.domainName)
52                 .setSequence(1)
53                 .setPriority(priority)
54                 .setEventId(id)
55                 .setEventName("sample-event-name")
56                 .setEventType("sample-event-type")
57                 .setStartEpochMicrosec(120034455)
58                 .setLastEpochMicrosec(120034455)
59                 .setNfNamingCode("sample-nf-naming-code")
60                 .setNfcNamingCode("sample-nfc-naming-code")
61                 .setNfVendorName("vendor-name")
62                 .setReportingEntityId(ByteString.copyFromUtf8("sample-reporting-entity-id"))
63                 .setReportingEntityName("sample-reporting-entity-name")
64                 .setSourceId(ByteString.copyFromUtf8("sample-source-id"))
65                 .setSourceName("sample-source-name")
66                 .setTimeZoneOffset("+1")
67                 .setVesEventListenerVersion(vesEventListenerVersion)
68                 .build()
69
70 fun vesEventBytes(commonHeader: CommonEventHeader, byteString: ByteString = ByteString.EMPTY): ByteData =
71         vesEvent(commonHeader, byteString).toByteData()
72
73 fun MessageLite.toByteData(): ByteData = ByteData(toByteArray())