From 49f43c856c8ca793bc6972d9d4b47c2d0d4c0816 Mon Sep 17 00:00:00 2001 From: kjaniak Date: Wed, 3 Apr 2019 15:48:28 +0200 Subject: Creation of server module Issue-ID: DCAEGEN2-1390 Change-Id: I07410b16ed6566b933d5f1efa35bddb965225794 Signed-off-by: kjaniak Signed-off-by: Filip Krzywka --- .../veshv/domain/logging/ClientContextTest.kt | 94 ++++++++++++++++++++++ .../veshv/domain/logging/ServiceContextTest.kt | 66 +++++++++++++++ .../src/test/resources/logback-test.xml | 35 ++++++++ .../org.mockito.plugins.MockMaker | 1 + 4 files changed, 196 insertions(+) create mode 100644 sources/hv-collector-domain/src/test/kotlin/org/onap/dcae/collectors/veshv/domain/logging/ClientContextTest.kt create mode 100644 sources/hv-collector-domain/src/test/kotlin/org/onap/dcae/collectors/veshv/domain/logging/ServiceContextTest.kt create mode 100644 sources/hv-collector-domain/src/test/resources/logback-test.xml create mode 100644 sources/hv-collector-domain/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker (limited to 'sources/hv-collector-domain/src/test') 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 + * @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 + * @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 @@ + + + + + + + + + %d{yyyy-MM-dd'T'HH:mm:ss.SSSXXX,UTC} %highlight(%-5level) [%-40.40logger{10}] - %msg%n + + + + + + + ${FILE_LOG_PATTERN} + + ${LOG_FILE} + + ${LOG_FILE}.%d{yyyy-MM-dd}.log + 50MB + 30 + 10GB + + + + + + + + + + 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 -- cgit 1.2.3-korg