Enable UNDEFINED option in commonHeader GPB schema
Closes ONAP-655
Change-Id: I6fc830d2b8c7bdd726f306a6fbf7e979f39e03f0
Signed-off-by: kjaniak <kornel.janiak@nokia.com>
Issue-ID: DCAEGEN2-601
diff --git a/hv-collector-core/src/main/kotlin/org/onap/dcae/collectors/veshv/impl/MessageValidator.kt b/hv-collector-core/src/main/kotlin/org/onap/dcae/collectors/veshv/impl/MessageValidator.kt
index 4586d30..543d7dc 100644
--- a/hv-collector-core/src/main/kotlin/org/onap/dcae/collectors/veshv/impl/MessageValidator.kt
+++ b/hv-collector-core/src/main/kotlin/org/onap/dcae/collectors/veshv/impl/MessageValidator.kt
@@ -27,11 +27,11 @@
private val requiredFieldDescriptors = listOf(
"version",
"eventName",
- // "domain", TODO to be restored back when GPB schema will include default value
+ "domain",
"eventId",
"sourceName",
"reportingEntityName",
- // "priority", TODO to be restored back when GPB schema will include default value
+ "priority",
"startEpochMicrosec",
"lastEpochMicrosec",
"sequence")
diff --git a/hv-collector-core/src/test/kotlin/org/onap/dcae/collectors/veshv/impl/MessageValidatorTest.kt b/hv-collector-core/src/test/kotlin/org/onap/dcae/collectors/veshv/impl/MessageValidatorTest.kt
index a2a26b3..eb8971c 100644
--- a/hv-collector-core/src/test/kotlin/org/onap/dcae/collectors/veshv/impl/MessageValidatorTest.kt
+++ b/hv-collector-core/src/test/kotlin/org/onap/dcae/collectors/veshv/impl/MessageValidatorTest.kt
@@ -49,18 +49,7 @@
val cut = MessageValidator
on("ves hv message including header with fully initialized fields") {
- val commonHeader = newBuilder()
- .setVersion("1.9")
- .setEventName("Sample event name")
- .setDomain(Domain.HVRANMEAS)
- .setEventId("Sample event Id")
- .setSourceName("Sample Source")
- .setReportingEntityName(ByteString.copyFromUtf8("Sample byte String"))
- .setPriority(Priority.MEDIUM)
- .setStartEpochMicrosec(120034455)
- .setLastEpochMicrosec(120034459)
- .setSequence(2)
- .build()
+ val commonHeader = createInitializedHeaderBuilder().build()
it("should accept message with fully initialized message header") {
val vesMessage = VesMessage(commonHeader, vesMessageBytes(commonHeader))
@@ -68,9 +57,9 @@
}
Domain.values()
- .filter { it != Domain.UNRECOGNIZED }
- .forEach {domain ->
- it("should accept message with $domain domain"){
+ .filter { (it != Domain.UNRECOGNIZED && it != Domain.DOMAIN_UNDEFINED) }
+ .forEach { domain ->
+ it("should accept message with $domain domain") {
val header = newBuilder(commonHeader).setDomain(domain).build()
val vesMessage = VesMessage(header, vesMessageBytes(header))
assertThat(cut.isValid(vesMessage))
@@ -87,6 +76,45 @@
}
+ val domainTestCases = mapOf(
+ Domain.DOMAIN_UNDEFINED to false,
+ Domain.FAULT to true
+ )
+
+ domainTestCases.forEach { value, expectedResult ->
+ on("ves hv message including header with domain $value") {
+ val commonEventHeader = createInitializedHeaderBuilder()
+ .setDomain(value)
+ .build()
+ val vesMessage = VesMessage(commonEventHeader, vesMessageBytes(commonEventHeader))
+
+ it("should resolve validation result") {
+ assertThat(cut.isValid(vesMessage)).describedAs("message validation results")
+ .isEqualTo(expectedResult)
+ }
+ }
+ }
+
+ val priorityTestCases = mapOf(
+ Priority.PRIORITY_UNDEFINED to false,
+ Priority.HIGH to true
+ )
+
+ priorityTestCases.forEach { value, expectedResult ->
+ on("ves hv message including header with priority $value") {
+ val commonEventHeader = createInitializedHeaderBuilder()
+ .setPriority(value)
+ .build()
+ val vesMessage = VesMessage(commonEventHeader, vesMessageBytes(commonEventHeader))
+
+ it("should resolve validation result") {
+ assertThat(cut.isValid(vesMessage)).describedAs("message validation results")
+ .isEqualTo(expectedResult)
+ }
+ }
+ }
+
+
on("ves hv message including header with not initialized fields") {
val commonHeader = newBuilder()
.setVersion("1.9")
@@ -106,4 +134,17 @@
}
}
}
-})
\ No newline at end of file
+})
+
+private fun createInitializedHeaderBuilder(): CommonEventHeader.Builder =
+ newBuilder()
+ .setVersion("1.9")
+ .setEventName("Sample event name")
+ .setDomain(Domain.HVRANMEAS)
+ .setEventId("Sample event Id")
+ .setSourceName("Sample Source")
+ .setReportingEntityName(ByteString.copyFromUtf8("Sample byte String"))
+ .setPriority(Priority.MEDIUM)
+ .setStartEpochMicrosec(120034455)
+ .setLastEpochMicrosec(120034459)
+ .setSequence(2)
\ No newline at end of file
diff --git a/hv-collector-core/src/test/kotlin/org/onap/dcae/collectors/veshv/impl/adapters/ConsulConfigurationProviderTest.kt b/hv-collector-core/src/test/kotlin/org/onap/dcae/collectors/veshv/impl/adapters/ConsulConfigurationProviderTest.kt
index 808a6fc..f4c527a 100644
--- a/hv-collector-core/src/test/kotlin/org/onap/dcae/collectors/veshv/impl/adapters/ConsulConfigurationProviderTest.kt
+++ b/hv-collector-core/src/test/kotlin/org/onap/dcae/collectors/veshv/impl/adapters/ConsulConfigurationProviderTest.kt
@@ -68,11 +68,11 @@
assertEquals("kafka:9093", it.kafkaBootstrapServers)
val route1 = it.routing.routes[0]
- assertEquals(Domain.HEARTBEAT, route1.domain)
+ assertEquals(Domain.FAULT, route1.domain)
assertEquals("test-topic-1", route1.targetTopic)
val route2 = it.routing.routes[1]
- assertEquals(Domain.MEASUREMENTS_FOR_VF_SCALING, route2.domain)
+ assertEquals(Domain.HEARTBEAT, route2.domain)
assertEquals("test-topic-2", route2.targetTopic)
}.verifyComplete()
diff --git a/hv-collector-domain/src/main/proto/VesEvent-v5.proto b/hv-collector-domain/src/main/proto/VesEvent-v5.proto
index 022cce4..340133b 100644
--- a/hv-collector-domain/src/main/proto/VesEvent-v5.proto
+++ b/hv-collector-domain/src/main/proto/VesEvent-v5.proto
@@ -30,27 +30,29 @@
message CommonEventHeader {
string version = 1; // required, "version of the event header"
enum Domain {
- FAULT = 0;
- HEARTBEAT = 1;
- MEASUREMENTS_FOR_VF_SCALING = 2;
- MOBILE_FLOW = 3;
- SIP_SIGNALING = 4;
- STATE_CHANGE = 5;
- SYSLOG = 6;
- THRESHOLD_CROSSING_ALERT = 7;
- VOICE_QUALITY = 8;
- OTHER = 9;
- HVRANMEAS = 10;
+ DOMAIN_UNDEFINED = 0;
+ FAULT = 1;
+ HEARTBEAT = 2;
+ MEASUREMENTS_FOR_VF_SCALING = 3;
+ MOBILE_FLOW = 4;
+ SIP_SIGNALING = 5;
+ STATE_CHANGE = 6;
+ SYSLOG = 7;
+ THRESHOLD_CROSSING_ALERT = 8;
+ VOICE_QUALITY = 9;
+ OTHER = 10;
+ HVRANMEAS = 11;
}
Domain domain = 2; // required, "the eventing domain associated with the event" [map to string]
uint32 sequence = 3; // required, "ordering of events communicated by an event source instance or 0 if not needed"
enum Priority {
- HIGH = 0;
- MEDIUM = 1;
- NORMAL = 2;
- LOW = 3;
+ PRIORITY_UNDEFINED = 0;
+ HIGH = 1;
+ MEDIUM = 2;
+ NORMAL = 3;
+ LOW = 4;
}
Priority priority = 4; // required, "processing priority"