From 7ba1265367a756ef3fcc98ca3babbf34674e0137 Mon Sep 17 00:00:00 2001 From: "m.kowalski3" Date: Wed, 8 May 2019 08:57:34 +0200 Subject: [PATCH] Add unit tests fot FlowLogOperation Change-Id: I499ca3ffe5d5f9a6fca4f5b92fc3c5da6a424d37 Issue-ID: CLAMP-355 Signed-off-by: Marcin Kowalski --- .../clamp/flow/FlowLogOperationTestItCase.java | 41 ++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/test/java/org/onap/clamp/flow/FlowLogOperationTestItCase.java 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 index 00000000..1abeb104 --- /dev/null +++ b/src/test/java/org/onap/clamp/flow/FlowLogOperationTestItCase.java @@ -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 -- 2.16.6