aboutsummaryrefslogtreecommitdiffstats
path: root/sources/hv-collector-domain
diff options
context:
space:
mode:
authorkjaniak <kornel.janiak@nokia.com>2019-04-03 15:48:28 +0200
committerFilip Krzywka <filip.krzywka@nokia.com>2019-04-12 09:56:50 +0200
commit49f43c856c8ca793bc6972d9d4b47c2d0d4c0816 (patch)
tree1e2c7d124898e053d5a3d42f9dcb329d24050d0e /sources/hv-collector-domain
parent8b8385d323754903ade492a659548d54b56bd7ad (diff)
Creation of server module
Issue-ID: DCAEGEN2-1390 Change-Id: I07410b16ed6566b933d5f1efa35bddb965225794 Signed-off-by: kjaniak <kornel.janiak@nokia.com> Signed-off-by: Filip Krzywka <filip.krzywka@nokia.com>
Diffstat (limited to 'sources/hv-collector-domain')
-rw-r--r--sources/hv-collector-domain/pom.xml14
-rw-r--r--sources/hv-collector-domain/src/main/kotlin/org/onap/dcae/collectors/veshv/domain/logging/ClientContext.kt60
-rw-r--r--sources/hv-collector-domain/src/main/kotlin/org/onap/dcae/collectors/veshv/domain/logging/ClientContextLogging.kt46
-rw-r--r--sources/hv-collector-domain/src/main/kotlin/org/onap/dcae/collectors/veshv/domain/logging/Marker.kt46
-rw-r--r--sources/hv-collector-domain/src/main/kotlin/org/onap/dcae/collectors/veshv/domain/logging/MarkerLogging.kt63
-rw-r--r--sources/hv-collector-domain/src/main/kotlin/org/onap/dcae/collectors/veshv/domain/logging/OnapMdc.kt35
-rw-r--r--sources/hv-collector-domain/src/main/kotlin/org/onap/dcae/collectors/veshv/domain/logging/ServiceContext.kt44
-rw-r--r--sources/hv-collector-domain/src/test/kotlin/org/onap/dcae/collectors/veshv/domain/logging/ClientContextTest.kt94
-rw-r--r--sources/hv-collector-domain/src/test/kotlin/org/onap/dcae/collectors/veshv/domain/logging/ServiceContextTest.kt66
-rw-r--r--sources/hv-collector-domain/src/test/resources/logback-test.xml35
-rw-r--r--sources/hv-collector-domain/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker1
11 files changed, 503 insertions, 1 deletions
diff --git a/sources/hv-collector-domain/pom.xml b/sources/hv-collector-domain/pom.xml
index 40e7c936..d68fa65b 100644
--- a/sources/hv-collector-domain/pom.xml
+++ b/sources/hv-collector-domain/pom.xml
@@ -58,6 +58,11 @@
<dependencies>
<dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>hv-collector-utils</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
<groupId>org.onap.dcaegen2.services.sdk</groupId>
<artifactId>hvvesclient-protobuf</artifactId>
</dependency>
@@ -66,6 +71,10 @@
<artifactId>kotlin-stdlib-jdk8</artifactId>
</dependency>
<dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ </dependency>
+ <dependency>
<groupId>io.projectreactor.netty</groupId>
<artifactId>reactor-netty</artifactId>
</dependency>
@@ -80,7 +89,6 @@
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-test</artifactId>
- <scope>test</scope>
</dependency>
<dependency>
<groupId>org.jetbrains.spek</groupId>
@@ -90,6 +98,10 @@
<groupId>org.jetbrains.spek</groupId>
<artifactId>spek-junit-platform-engine</artifactId>
</dependency>
+ <dependency>
+ <groupId>com.nhaarman.mockitokotlin2</groupId>
+ <artifactId>mockito-kotlin</artifactId>
+ </dependency>
</dependencies>
</project>
diff --git a/sources/hv-collector-domain/src/main/kotlin/org/onap/dcae/collectors/veshv/domain/logging/ClientContext.kt b/sources/hv-collector-domain/src/main/kotlin/org/onap/dcae/collectors/veshv/domain/logging/ClientContext.kt
new file mode 100644
index 00000000..6a47f44d
--- /dev/null
+++ b/sources/hv-collector-domain/src/main/kotlin/org/onap/dcae/collectors/veshv/domain/logging/ClientContext.kt
@@ -0,0 +1,60 @@
+/*
+ * ============LICENSE_START=======================================================
+ * dcaegen2-collectors-veshv
+ * ================================================================================
+ * Copyright (C) 2018-2019 NOKIA
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.dcae.collectors.veshv.domain.logging
+
+import arrow.core.None
+import arrow.core.Option
+import arrow.core.getOrElse
+import io.netty.buffer.ByteBufAllocator
+import java.net.InetAddress
+import java.security.cert.X509Certificate
+import java.util.*
+
+/**
+ * @author Piotr Jaszczyk <piotr.jaszczyk@nokia.com>
+ * @since December 2018
+ */
+data class ClientContext(
+ val alloc: ByteBufAllocator = ByteBufAllocator.DEFAULT,
+ var clientAddress: Option<InetAddress> = None,
+ var clientCert: Option<X509Certificate> = None,
+ val requestId: String = UUID.randomUUID().toString(), // Should be somehow propagated to DMAAP
+ val invocationId: String = UUID.randomUUID().toString()) {
+
+ val mdc: Map<String, String>
+ get() = mapOf(
+ OnapMdc.REQUEST_ID to requestId,
+ OnapMdc.INVOCATION_ID to invocationId,
+ OnapMdc.STATUS_CODE to DEFAULT_STATUS_CODE,
+ OnapMdc.CLIENT_NAME to clientDn().getOrElse { DEFAULT_VALUE },
+ OnapMdc.CLIENT_IP to clientIp().getOrElse { DEFAULT_VALUE }
+ )
+
+ val fullMdc: Map<String, String>
+ get() = mdc + ServiceContext.mdc
+
+ private fun clientDn(): Option<String> = clientCert.map { it.subjectX500Principal.toString() }
+ private fun clientIp(): Option<String> = clientAddress.map(InetAddress::getHostAddress)
+
+ companion object {
+ const val DEFAULT_STATUS_CODE = "INPROGRESS"
+ const val DEFAULT_VALUE = ""
+ }
+}
diff --git a/sources/hv-collector-domain/src/main/kotlin/org/onap/dcae/collectors/veshv/domain/logging/ClientContextLogging.kt b/sources/hv-collector-domain/src/main/kotlin/org/onap/dcae/collectors/veshv/domain/logging/ClientContextLogging.kt
new file mode 100644
index 00000000..fc45ea9d
--- /dev/null
+++ b/sources/hv-collector-domain/src/main/kotlin/org/onap/dcae/collectors/veshv/domain/logging/ClientContextLogging.kt
@@ -0,0 +1,46 @@
+/*
+ * ============LICENSE_START=======================================================
+ * dcaegen2-collectors-veshv
+ * ================================================================================
+ * Copyright (C) 2018-2019 NOKIA
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.dcae.collectors.veshv.domain.logging
+
+import org.onap.dcae.collectors.veshv.utils.logging.AtLevelLogger
+import org.onap.dcae.collectors.veshv.utils.logging.Logger
+import org.onap.dcae.collectors.veshv.utils.logging.handleReactiveStreamError
+import reactor.core.publisher.Flux
+
+@Suppress("TooManyFunctions")
+object ClientContextLogging {
+ fun Logger.withError(ctx: ClientContext, block: AtLevelLogger.() -> Unit) = withError(ctx::fullMdc, block)
+ fun Logger.withWarn(ctx: ClientContext, block: AtLevelLogger.() -> Unit) = withWarn(ctx::fullMdc, block)
+ fun Logger.withInfo(ctx: ClientContext, block: AtLevelLogger.() -> Unit) = withInfo(ctx::fullMdc, block)
+ fun Logger.withDebug(ctx: ClientContext, block: AtLevelLogger.() -> Unit) = withDebug(ctx::fullMdc, block)
+ fun Logger.withTrace(ctx: ClientContext, block: AtLevelLogger.() -> Unit) = withTrace(ctx::fullMdc, block)
+
+ fun Logger.error(ctx: ClientContext, message: () -> String) = error(ctx::fullMdc, message)
+ fun Logger.warn(ctx: ClientContext, message: () -> String) = warn(ctx::fullMdc, message)
+ fun Logger.info(ctx: ClientContext, message: () -> String) = info(ctx::fullMdc, message)
+ fun Logger.debug(ctx: ClientContext, message: () -> String) = debug(ctx::fullMdc, message)
+ fun Logger.trace(ctx: ClientContext, message: () -> String) = trace(ctx::fullMdc, message)
+
+ fun <T> Logger.handleReactiveStreamError(context: ClientContext, ex: Throwable,
+ returnFlux: Flux<T> = Flux.empty()): Flux<T> {
+ return this.handleReactiveStreamError({ context.fullMdc }, ex, returnFlux)
+ }
+}
+
diff --git a/sources/hv-collector-domain/src/main/kotlin/org/onap/dcae/collectors/veshv/domain/logging/Marker.kt b/sources/hv-collector-domain/src/main/kotlin/org/onap/dcae/collectors/veshv/domain/logging/Marker.kt
new file mode 100644
index 00000000..b9463c96
--- /dev/null
+++ b/sources/hv-collector-domain/src/main/kotlin/org/onap/dcae/collectors/veshv/domain/logging/Marker.kt
@@ -0,0 +1,46 @@
+/*
+ * ============LICENSE_START=======================================================
+ * dcaegen2-collectors-veshv
+ * ================================================================================
+ * Copyright (C) 2018-2019 NOKIA
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.dcae.collectors.veshv.domain.logging
+
+import org.slf4j.MarkerFactory
+import java.time.Instant
+import java.util.*
+
+sealed class Marker(internal val slf4jMarker: org.slf4j.Marker, val mdc: Map<String, String> = emptyMap()) {
+
+ object Entry : Marker(ENTRY)
+ object Exit : Marker(EXIT)
+
+ class Invoke(id: UUID = UUID.randomUUID(), timestamp: Instant = Instant.now()) :
+ Marker(INVOKE, mdc(id, timestamp)) {
+ companion object {
+ private fun mdc(id: UUID, timestamp: Instant) = mapOf(
+ OnapMdc.INVOCATION_ID to id.toString(),
+ OnapMdc.INVOCATION_TIMESTAMP to timestamp.toString()
+ )
+ }
+ }
+
+ companion object {
+ private val ENTRY = MarkerFactory.getMarker("ENTRY")
+ private val EXIT = MarkerFactory.getMarker("EXIT")
+ private val INVOKE = MarkerFactory.getMarker("INVOKE")
+ }
+}
diff --git a/sources/hv-collector-domain/src/main/kotlin/org/onap/dcae/collectors/veshv/domain/logging/MarkerLogging.kt b/sources/hv-collector-domain/src/main/kotlin/org/onap/dcae/collectors/veshv/domain/logging/MarkerLogging.kt
new file mode 100644
index 00000000..2959f98c
--- /dev/null
+++ b/sources/hv-collector-domain/src/main/kotlin/org/onap/dcae/collectors/veshv/domain/logging/MarkerLogging.kt
@@ -0,0 +1,63 @@
+/*
+ * ============LICENSE_START=======================================================
+ * dcaegen2-collectors-veshv
+ * ================================================================================
+ * Copyright (C) 2019 NOKIA
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.dcae.collectors.veshv.domain.logging
+
+import org.onap.dcae.collectors.veshv.utils.logging.Logger
+import org.onap.dcae.collectors.veshv.utils.logging.MappedDiagnosticContext
+import org.slf4j.MDC
+
+
+@Suppress("TooManyFunctions")
+object MarkerLogging {
+ fun Logger.error(mdc: MappedDiagnosticContext, marker: Marker, message: () -> String) =
+ withError(mdc) { withAdditionalMdc(marker.mdc) { log(marker.slf4jMarker, message()) } }
+
+ fun Logger.error(mdc: MappedDiagnosticContext, marker: Marker, message: () -> String, t: Throwable) =
+ withError(mdc) { withAdditionalMdc(marker.mdc) { log(marker.slf4jMarker, message(), t) } }
+
+ fun Logger.warn(mdc: MappedDiagnosticContext, marker: Marker, message: () -> String) =
+ withWarn(mdc) { withAdditionalMdc(marker.mdc) { log(marker.slf4jMarker, message()) } }
+
+ fun Logger.warn(mdc: MappedDiagnosticContext, marker: Marker, message: () -> String, t: Throwable) =
+ withWarn(mdc) { withAdditionalMdc(marker.mdc) { log(marker.slf4jMarker, message(), t) } }
+
+ fun Logger.info(mdc: MappedDiagnosticContext, marker: Marker, message: () -> String) =
+ withInfo(mdc) { withAdditionalMdc(marker.mdc) { log(marker.slf4jMarker, message()) } }
+
+ fun Logger.debug(mdc: MappedDiagnosticContext, marker: Marker, message: () -> String) =
+ withDebug(mdc) { withAdditionalMdc(marker.mdc) { log(marker.slf4jMarker, message()) } }
+
+ fun Logger.trace(mdc: MappedDiagnosticContext, marker: Marker, message: () -> String) =
+ withTrace(mdc) { withAdditionalMdc(marker.mdc) { log(marker.slf4jMarker, message()) } }
+
+
+ private inline fun withAdditionalMdc(mdc: Map<String, String>, block: () -> Unit) {
+ if (mdc.isEmpty()) {
+ block()
+ } else {
+ try {
+ mdc.forEach(MDC::put)
+ block()
+ } finally {
+ mdc.keys.forEach(MDC::remove)
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/sources/hv-collector-domain/src/main/kotlin/org/onap/dcae/collectors/veshv/domain/logging/OnapMdc.kt b/sources/hv-collector-domain/src/main/kotlin/org/onap/dcae/collectors/veshv/domain/logging/OnapMdc.kt
new file mode 100644
index 00000000..8c7feced
--- /dev/null
+++ b/sources/hv-collector-domain/src/main/kotlin/org/onap/dcae/collectors/veshv/domain/logging/OnapMdc.kt
@@ -0,0 +1,35 @@
+/*
+ * ============LICENSE_START=======================================================
+ * dcaegen2-collectors-veshv
+ * ================================================================================
+ * Copyright (C) 2018-2019 NOKIA
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.dcae.collectors.veshv.domain.logging
+
+/**
+ * @author Piotr Jaszczyk <piotr.jaszczyk@nokia.com>
+ * @since December 2018
+ */
+object OnapMdc {
+ const val REQUEST_ID = "RequestID"
+ const val CLIENT_NAME = "PartnerName"
+ const val CLIENT_IP = "ClientIPAddress"
+ const val INVOCATION_ID = "InvocationID"
+ const val INVOCATION_TIMESTAMP = "InvokeTimestamp"
+ const val STATUS_CODE = "StatusCode"
+ const val INSTANCE_ID = "InstanceID"
+ const val SERVER_FQDN = "ServerFQDN"
+}
diff --git a/sources/hv-collector-domain/src/main/kotlin/org/onap/dcae/collectors/veshv/domain/logging/ServiceContext.kt b/sources/hv-collector-domain/src/main/kotlin/org/onap/dcae/collectors/veshv/domain/logging/ServiceContext.kt
new file mode 100644
index 00000000..c3c64d92
--- /dev/null
+++ b/sources/hv-collector-domain/src/main/kotlin/org/onap/dcae/collectors/veshv/domain/logging/ServiceContext.kt
@@ -0,0 +1,44 @@
+/*
+ * ============LICENSE_START=======================================================
+ * dcaegen2-collectors-veshv
+ * ================================================================================
+ * Copyright (C) 2018-2019 NOKIA
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.dcae.collectors.veshv.domain.logging
+
+import java.net.InetAddress
+import java.net.UnknownHostException
+import java.util.*
+
+/**
+ * @author Piotr Jaszczyk <piotr.jaszczyk@nokia.com>
+ * @since December 2018
+ */
+object ServiceContext {
+ val instanceId = UUID.randomUUID().toString()
+ val serverFqdn = getHost().hostName!!
+
+ val mdc = mapOf(
+ OnapMdc.INSTANCE_ID to instanceId,
+ OnapMdc.SERVER_FQDN to serverFqdn
+ )
+
+ private fun getHost() = try {
+ InetAddress.getLocalHost()
+ } catch (ex: UnknownHostException) {
+ InetAddress.getLoopbackAddress()
+ }
+}
diff --git a/sources/hv-collector-domain/src/test/kotlin/org/onap/dcae/collectors/veshv/domain/logging/ClientContextTest.kt b/sources/hv-collector-domain/src/test/kotlin/org/onap/dcae/collectors/veshv/domain/logging/ClientContextTest.kt
new file mode 100644
index 00000000..ea1a2e90
--- /dev/null
+++ b/sources/hv-collector-domain/src/test/kotlin/org/onap/dcae/collectors/veshv/domain/logging/ClientContextTest.kt
@@ -0,0 +1,94 @@
+/*
+ * ============LICENSE_START=======================================================
+ * dcaegen2-collectors-veshv
+ * ================================================================================
+ * Copyright (C) 2018 NOKIA
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.dcae.collectors.veshv.domain.logging
+
+import arrow.core.Some
+import com.nhaarman.mockitokotlin2.mock
+import com.nhaarman.mockitokotlin2.whenever
+import org.assertj.core.api.Assertions.assertThat
+import org.jetbrains.spek.api.Spek
+import org.jetbrains.spek.api.dsl.describe
+import org.jetbrains.spek.api.dsl.given
+import org.jetbrains.spek.api.dsl.it
+import org.jetbrains.spek.api.dsl.on
+import java.net.InetAddress
+import java.security.cert.X509Certificate
+import javax.security.auth.x500.X500Principal
+
+/**
+ * @author Piotr Jaszczyk <piotr.jaszczyk@nokia.com>
+ * @since December 2018
+ */
+internal object ClientContextTest : Spek({
+ describe("ClientContext") {
+ given("default instance") {
+ val cut = ClientContext()
+
+ on("mapped diagnostic context") {
+ val mdc = cut.mdc
+
+ it("should contain ${OnapMdc.REQUEST_ID}") {
+ assertThat(mdc[OnapMdc.REQUEST_ID]).isEqualTo(cut.requestId)
+ }
+
+ it("should contain ${OnapMdc.INVOCATION_ID}") {
+ assertThat(mdc[OnapMdc.INVOCATION_ID]).isEqualTo(cut.invocationId)
+ }
+
+ it("should contain ${OnapMdc.STATUS_CODE}") {
+ assertThat(mdc[OnapMdc.STATUS_CODE]).isEqualTo("INPROGRESS")
+ }
+
+ it("should contain ${OnapMdc.CLIENT_NAME}") {
+ assertThat(mdc[OnapMdc.CLIENT_NAME]).isBlank()
+ }
+
+ it("should contain ${OnapMdc.CLIENT_IP}") {
+ assertThat(mdc[OnapMdc.CLIENT_IP]).isBlank()
+ }
+ }
+ }
+
+ given("instance with client data") {
+ val clientDn = "C=PL, O=Nokia, CN=NokiaBTS"
+ val clientIp = "192.168.52.34"
+ val cert: X509Certificate = mock()
+ val principal: X500Principal = mock()
+ val cut = ClientContext(
+ clientAddress = Some(InetAddress.getByName(clientIp)),
+ clientCert = Some(cert))
+
+ whenever(cert.subjectX500Principal).thenReturn(principal)
+ whenever(principal.toString()).thenReturn(clientDn)
+
+ on("mapped diagnostic context") {
+ val mdc = cut.mdc
+
+ it("should contain ${OnapMdc.CLIENT_NAME}") {
+ assertThat(mdc[OnapMdc.CLIENT_NAME]).isEqualTo(clientDn)
+ }
+
+ it("should contain ${OnapMdc.CLIENT_IP}") {
+ assertThat(mdc[OnapMdc.CLIENT_IP]).isEqualTo(clientIp)
+ }
+ }
+ }
+ }
+})
diff --git a/sources/hv-collector-domain/src/test/kotlin/org/onap/dcae/collectors/veshv/domain/logging/ServiceContextTest.kt b/sources/hv-collector-domain/src/test/kotlin/org/onap/dcae/collectors/veshv/domain/logging/ServiceContextTest.kt
new file mode 100644
index 00000000..85ced42a
--- /dev/null
+++ b/sources/hv-collector-domain/src/test/kotlin/org/onap/dcae/collectors/veshv/domain/logging/ServiceContextTest.kt
@@ -0,0 +1,66 @@
+/*
+ * ============LICENSE_START=======================================================
+ * dcaegen2-collectors-veshv
+ * ================================================================================
+ * Copyright (C) 2018 NOKIA
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.dcae.collectors.veshv.domain.logging
+
+import org.assertj.core.api.Assertions.assertThat
+import org.jetbrains.spek.api.Spek
+import org.jetbrains.spek.api.dsl.describe
+import org.jetbrains.spek.api.dsl.given
+import org.jetbrains.spek.api.dsl.it
+import org.jetbrains.spek.api.dsl.on
+import java.util.*
+
+/**
+ * @author Piotr Jaszczyk <piotr.jaszczyk@nokia.com>
+ * @since December 2018
+ */
+internal object ServiceContextTest : Spek({
+ describe("ServiceContext") {
+ given("singleton instance") {
+ val cut = ServiceContext
+
+ on("instanceId") {
+ val instanceId = cut.instanceId
+ it("should be valid UUID") {
+ UUID.fromString(instanceId) // should not throw
+ }
+ }
+
+ on("serverFqdn") {
+ val serverFqdn = cut.serverFqdn
+ it("should be non empty") {
+ assertThat(serverFqdn).isNotBlank()
+ }
+ }
+
+ on("mapped diagnostic context") {
+ val mdc = cut.mdc
+
+ it("should contain ${OnapMdc.INSTANCE_ID}") {
+ assertThat(mdc[OnapMdc.INSTANCE_ID]).isEqualTo(cut.instanceId)
+ }
+
+ it("should contain ${OnapMdc.SERVER_FQDN}") {
+ assertThat(mdc[OnapMdc.SERVER_FQDN]).isEqualTo(cut.serverFqdn)
+ }
+ }
+ }
+ }
+})
diff --git a/sources/hv-collector-domain/src/test/resources/logback-test.xml b/sources/hv-collector-domain/src/test/resources/logback-test.xml
new file mode 100644
index 00000000..9a4eacfe
--- /dev/null
+++ b/sources/hv-collector-domain/src/test/resources/logback-test.xml
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<configuration>
+ <property name="LOG_FILE"
+ value="${LOG_FILE:-${LOG_PATH:-${LOG_TEMP:-${java.io.tmpdir:-/tmp}}/}ves-hv.log}"/>
+ <property name="FILE_LOG_PATTERN" value="%d{yyyy-MM-dd'T'HH:mm:ss.SSSXXX,UTC} %-5level [%-40.40logger{10}] - %msg%n"/>
+
+ <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
+ <encoder>
+ <pattern>
+ %d{yyyy-MM-dd'T'HH:mm:ss.SSSXXX,UTC} %highlight(%-5level) [%-40.40logger{10}] - %msg%n
+ </pattern>
+ </encoder>
+ </appender>
+
+ <appender name="ROLLING-FILE"
+ class="ch.qos.logback.core.rolling.RollingFileAppender">
+ <encoder>
+ <pattern>${FILE_LOG_PATTERN}</pattern>
+ </encoder>
+ <file>${LOG_FILE}</file>
+ <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
+ <fileNamePattern>${LOG_FILE}.%d{yyyy-MM-dd}.log</fileNamePattern>
+ <maxFileSize>50MB</maxFileSize>
+ <maxHistory>30</maxHistory>
+ <totalSizeCap>10GB</totalSizeCap>
+ </rollingPolicy>
+ </appender>
+
+ <logger name="org.onap.dcae.collectors.veshv" level="TRACE"/>
+
+ <root level="INFO">
+ <appender-ref ref="CONSOLE"/>
+ <appender-ref ref="ROLLING-FILE"/>
+ </root>
+</configuration>
diff --git a/sources/hv-collector-domain/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker b/sources/hv-collector-domain/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker
new file mode 100644
index 00000000..ca6ee9ce
--- /dev/null
+++ b/sources/hv-collector-domain/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker
@@ -0,0 +1 @@
+mock-maker-inline \ No newline at end of file