Add unit tests fot FlowLogOperation 15/87215/1
authorm.kowalski3 <m.kowalski3@partner.samsung.com>
Wed, 8 May 2019 06:57:34 +0000 (08:57 +0200)
committerm.kowalski3 <m.kowalski3@partner.samsung.com>
Wed, 8 May 2019 06:58:18 +0000 (08:58 +0200)
Change-Id: I499ca3ffe5d5f9a6fca4f5b92fc3c5da6a424d37
Issue-ID: CLAMP-355
Signed-off-by: Marcin Kowalski <m.kowalski3@partner.samsung.com>
src/test/java/org/onap/clamp/flow/FlowLogOperationTestItCase.java [new file with mode: 0644]

diff --git a/src/test/java/org/onap/clamp/flow/FlowLogOperationTestItCase.java b/src/test/java/org/onap/clamp/flow/FlowLogOperationTestItCase.java
new file mode 100644 (file)
index 0000000..1abeb10
--- /dev/null
@@ -0,0 +1,41 @@
+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