33761f9fd3c4df2d4978922af0bbac7f0e45096a
[appc.git] / appc-dg / appc-dg-shared / appc-dg-common / src / test / java / org / onap / appc / dg / common / impl / IntermediateMessageSenderImplTest.java
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
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
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
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.
20  *
21  * ============LICENSE_END=========================================================
22  */
23
24 package org.onap.appc.dg.common.impl;
25
26 import java.util.HashMap;
27 import java.util.Map;
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;
33
34 public class IntermediateMessageSenderImplTest {
35
36     private SvcLogicContext ctx;
37     private Map<String, String> params;
38
39
40     private IntermediateMessageSenderImpl intermediateMessageSenderImpl;
41
42
43
44     @Test
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"));
54     }
55
56     @Test
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"));
69     }
70 }