2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018 Ericsson
6 * ================================================================================
7 * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * ============LICENSE_END=========================================================
24 package org.onap.appc.dg.common.impl;
26 import java.util.HashMap;
28 import org.junit.Assert;
29 import org.junit.Test;
30 import org.mockito.Mockito;
31 import org.onap.appc.srvcomm.messaging.MessagingConnector;
32 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
34 public class IntermediateMessageSenderImplTest {
36 private SvcLogicContext ctx;
37 private Map<String, String> params;
40 private IntermediateMessageSenderImpl intermediateMessageSenderImpl;
45 public void testSendEmptyMessage() {
46 intermediateMessageSenderImpl = new IntermediateMessageSenderImpl();
47 MessagingConnector msgConn = Mockito.mock(MessagingConnector.class);
48 Mockito.when(msgConn.publishMessage(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(false);
49 intermediateMessageSenderImpl.init(msgConn);
50 ctx = new SvcLogicContext();
51 params = new HashMap<>();
52 intermediateMessageSenderImpl.sendMessage(params, ctx);
53 Assert.assertEquals("FAILURE", ctx.getAttribute("STATUS"));
57 public void testSendMessage() {
58 intermediateMessageSenderImpl = new IntermediateMessageSenderImpl();
59 MessagingConnector msgConn = Mockito.mock(MessagingConnector.class);
60 Mockito.when(msgConn.publishMessage(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(true);
61 intermediateMessageSenderImpl.init(msgConn);
62 ctx = new SvcLogicContext();
63 ctx.setAttribute("input.common-header.request-id", "REQUEST-ID");
64 params = new HashMap<>();
65 params.put("message", "TEST MESSAGE");
66 params.put("code", "TEST CODE");
67 intermediateMessageSenderImpl.sendMessage(params, ctx);
68 Assert.assertEquals("SUCCESS", ctx.getAttribute("STATUS"));