2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 Samsung. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END============================================
19 * ===================================================================
23 package org.onap.clamp.flow;
25 import static org.assertj.core.api.Assertions.assertThat;
26 import static org.mockito.Mockito.mock;
28 import org.apache.camel.CamelContext;
29 import org.apache.camel.Exchange;
30 import org.apache.camel.impl.DefaultExchange;
31 import org.junit.Test;
32 import org.mockito.Mockito;
33 import org.onap.clamp.clds.util.LoggingUtils;
34 import org.onap.clamp.clds.util.ONAPLogConstants;
35 import org.onap.clamp.flow.log.FlowLogOperation;
36 import org.springframework.beans.factory.annotation.Autowired;
37 import org.springframework.test.util.ReflectionTestUtils;
39 public class FlowLogOperationTestItCase {
42 CamelContext camelContext;
45 public void testStratLog() {
47 FlowLogOperation flowLogOperation = new FlowLogOperation();
48 Exchange exchange = new DefaultExchange(camelContext);
49 LoggingUtils loggingUtils = mock(LoggingUtils.class);
50 ReflectionTestUtils.setField(flowLogOperation, "util", loggingUtils);
53 Mockito.when(loggingUtils.getProperties(ONAPLogConstants.MDCs.REQUEST_ID)).thenReturn("MockRequestId");
54 Mockito.when(loggingUtils.getProperties(ONAPLogConstants.MDCs.INVOCATION_ID)).thenReturn("MockInvocationId");
55 Mockito.when(loggingUtils.getProperties(ONAPLogConstants.MDCs.PARTNER_NAME)).thenReturn("MockPartnerName");
56 flowLogOperation.startLog(exchange, "serviceName");
59 assertThat(exchange.getProperty(ONAPLogConstants.Headers.REQUEST_ID)).isEqualTo("MockRequestId");
60 assertThat(exchange.getProperty(ONAPLogConstants.Headers.INVOCATION_ID)).isEqualTo("MockInvocationId");
61 assertThat(exchange.getProperty(ONAPLogConstants.Headers.PARTNER_NAME)).isEqualTo("MockPartnerName");