aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorm.kowalski3 <m.kowalski3@partner.samsung.com>2019-05-10 08:50:30 +0200
committerm.kowalski3 <m.kowalski3@partner.samsung.com>2019-06-04 12:00:03 +0200
commita0b3b5f6af6b4dd8db1c2b32658c013f0017ab3c (patch)
tree3c280fabd57b62af1a7359707f120c2154fcc9c9 /src
parent1b55edad8e4a3b6c28c4c8b066de4e6a38f63479 (diff)
Improve test coverage in FlowLogOperation
Change-Id: Ia76e2652ab99bf06def5fafca24de471d53e224e Issue-ID: CLAMP-355 Signed-off-by: Marcin Kowalski <m.kowalski3@partner.samsung.com>
Diffstat (limited to 'src')
-rw-r--r--src/test/java/org/onap/clamp/flow/FlowLogOperationTest.java99
-rw-r--r--src/test/java/org/onap/clamp/flow/FlowLogOperationTestItCase.java41
2 files changed, 99 insertions, 41 deletions
diff --git a/src/test/java/org/onap/clamp/flow/FlowLogOperationTest.java b/src/test/java/org/onap/clamp/flow/FlowLogOperationTest.java
new file mode 100644
index 000000000..16136ae2e
--- /dev/null
+++ b/src/test/java/org/onap/clamp/flow/FlowLogOperationTest.java
@@ -0,0 +1,99 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP CLAMP
+ * ================================================================================
+ * Copyright (C) 2019 Samsung. All rights reserved.
+ * ================================================================================
+ * 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.clamp.flow;
+
+import static junit.framework.Assert.assertEquals;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import org.apache.camel.CamelContext;
+import org.apache.camel.Exchange;
+import org.apache.camel.impl.DefaultExchange;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.onap.clamp.clds.util.LoggingUtils;
+import org.onap.clamp.clds.util.ONAPLogConstants;
+import org.onap.clamp.flow.log.FlowLogOperation;
+import org.slf4j.MDC;
+import org.slf4j.spi.MDCAdapter;
+import org.springframework.test.util.ReflectionTestUtils;
+
+public class FlowLogOperationTest {
+
+ private FlowLogOperation flowLogOperation = new FlowLogOperation();
+
+ @Test
+ public void testStratLog() {
+ //given
+ Exchange exchange = new DefaultExchange(mock(CamelContext.class));
+ LoggingUtils loggingUtils = mock(LoggingUtils.class);
+ ReflectionTestUtils.setField(flowLogOperation, "util", loggingUtils);
+
+ //when
+ Mockito.when(loggingUtils.getProperties(ONAPLogConstants.MDCs.REQUEST_ID)).thenReturn("MockRequestId");
+ Mockito.when(loggingUtils.getProperties(ONAPLogConstants.MDCs.INVOCATION_ID)).thenReturn("MockInvocationId");
+ Mockito.when(loggingUtils.getProperties(ONAPLogConstants.MDCs.PARTNER_NAME)).thenReturn("MockPartnerName");
+ flowLogOperation.startLog(exchange, "serviceName");
+
+ //then
+ assertThat(exchange.getProperty(ONAPLogConstants.Headers.REQUEST_ID)).isEqualTo("MockRequestId");
+ assertThat(exchange.getProperty(ONAPLogConstants.Headers.INVOCATION_ID)).isEqualTo("MockInvocationId");
+ assertThat(exchange.getProperty(ONAPLogConstants.Headers.PARTNER_NAME)).isEqualTo("MockPartnerName");
+ }
+
+ @Test
+ public void testInvokeLog() {
+ //given
+ final String mockEntity = "mockEntity";
+ final String mockServiceName = "mockSerivceName";
+ MDCAdapter mdcAdapter = MDC.getMDCAdapter();
+ //when
+ flowLogOperation.invokeLog(mockEntity, mockServiceName);
+ //then
+ String entity = mdcAdapter.get(ONAPLogConstants.MDCs.TARGET_ENTITY);
+ String serviceName = mdcAdapter.get(ONAPLogConstants.MDCs.TARGET_SERVICE_NAME);
+ assertEquals(entity,mockEntity);
+ assertEquals(serviceName,mockServiceName);
+ }
+
+ @Test
+ public void testEndLog() {
+ //given
+ MDC.put(ONAPLogConstants.MDCs.ENTRY_TIMESTAMP, "2019-05-19T00:00:00.007Z");
+ MDCAdapter mdcAdapter = MDC.getMDCAdapter();
+ ///when
+ flowLogOperation.endLog();
+ //then
+ assertThat(mdcAdapter.get(ONAPLogConstants.MDCs.ENTRY_TIMESTAMP)).isNull();
+ }
+
+ @Test
+ public void testErrorLog() {
+ //given
+ MDC.put(ONAPLogConstants.MDCs.ENTRY_TIMESTAMP, "2019-05-19T00:00:00.007Z");
+ MDCAdapter mdcAdapter = MDC.getMDCAdapter();
+ //when
+ flowLogOperation.errorLog();
+ //then
+ assertThat(mdcAdapter.get(ONAPLogConstants.MDCs.ENTRY_TIMESTAMP)).isNull();
+ }
+} \ No newline at end of file
diff --git a/src/test/java/org/onap/clamp/flow/FlowLogOperationTestItCase.java b/src/test/java/org/onap/clamp/flow/FlowLogOperationTestItCase.java
deleted file mode 100644
index 1abeb104c..000000000
--- a/src/test/java/org/onap/clamp/flow/FlowLogOperationTestItCase.java
+++ /dev/null
@@ -1,41 +0,0 @@
-package org.onap.clamp.flow;
-
-import org.apache.camel.CamelContext;
-import org.apache.camel.Exchange;
-import org.apache.camel.impl.DefaultExchange;
-import org.junit.Test;
-import org.mockito.Mockito;
-import org.onap.clamp.clds.util.LoggingUtils;
-import org.onap.clamp.clds.util.ONAPLogConstants;
-import org.onap.clamp.flow.log.FlowLogOperation;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.test.util.ReflectionTestUtils;
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.mock;
-
-
-public class FlowLogOperationTestItCase {
-
- @Autowired
- CamelContext camelContext;
-
- @Test
- public void testStratLog() {
- //given
- FlowLogOperation flowLogOperation = new FlowLogOperation();
- Exchange exchange = new DefaultExchange(camelContext);
- LoggingUtils loggingUtils = mock(LoggingUtils.class);
- ReflectionTestUtils.setField(flowLogOperation, "util", loggingUtils);
-
- //when
- Mockito.when(loggingUtils.getProperties(ONAPLogConstants.MDCs.REQUEST_ID)).thenReturn("MockRequestId");
- Mockito.when(loggingUtils.getProperties(ONAPLogConstants.MDCs.INVOCATION_ID)).thenReturn("MockInvocationId");
- Mockito.when(loggingUtils.getProperties(ONAPLogConstants.MDCs.PARTNER_NAME)).thenReturn("MockPartnerName");
- flowLogOperation.startLog(exchange, "serviceName");
-
- //then
- assertThat(exchange.getProperty(ONAPLogConstants.Headers.REQUEST_ID)).isEqualTo("MockRequestId");
- assertThat(exchange.getProperty(ONAPLogConstants.Headers.INVOCATION_ID)).isEqualTo("MockInvocationId");
- assertThat(exchange.getProperty(ONAPLogConstants.Headers.PARTNER_NAME)).isEqualTo("MockPartnerName");
- }
-} \ No newline at end of file