Test coverage in OAM and OAM message-adapter
[appc.git] / appc-oam / appc-oam-bundle / src / test / java / org / onap / appc / oam / messageadapter / ConverterTest.java
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
4  * ================================================================================
5  * Copyright (C) 2018 Ericsson
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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  *
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.appc.oam.messageadapter;
23
24 import static org.junit.Assert.assertTrue;
25 import org.junit.Before;
26 import org.junit.Test;
27 import org.mockito.Mockito;
28 import org.onap.appc.oam.AppcOam.RPC;
29 import org.opendaylight.yang.gen.v1.org.onap.appc.oam.rev170303.common.header.CommonHeader;
30 import com.fasterxml.jackson.core.JsonProcessingException;
31
32
33
34 public class ConverterTest {
35
36     private OAMContext oamContext = Mockito.spy(new OAMContext());
37
38     @Before
39     public void setup() {
40         org.opendaylight.yang.gen.v1.org.onap.appc.oam.rev170303.status.StatusBuilder statusBuilder = 
41                 new org.opendaylight.yang.gen.v1.org.onap.appc.oam.rev170303.status.StatusBuilder();
42         statusBuilder.setCode(1);
43         statusBuilder.setMessage("MESSAGE");
44         oamContext.setStatus(statusBuilder.build());
45         org.opendaylight.yang.gen.v1.org.onap.appc.oam.rev170303.common.header.CommonHeaderBuilder commonHeaderBuilder =
46                 new org.opendaylight.yang.gen.v1.org.onap.appc.oam.rev170303.common.header.CommonHeaderBuilder();
47         commonHeaderBuilder.setRequestId("REQUEST_ID");
48         CommonHeader commonHeader = commonHeaderBuilder.build();
49         oamContext.setCommonHeader(commonHeader);
50     }
51
52     @Test
53     public void testStop() throws JsonProcessingException {
54         oamContext.setRpcName(RPC.stop);
55         assertTrue(Converter.convAsyncResponseToUebOutgoingMessageJsonString(oamContext).contains("\"rpc-name\":\"stop\""));
56     }
57
58     @Test
59     public void testStart() throws JsonProcessingException {
60         oamContext.setRpcName(RPC.start);
61         assertTrue(Converter.convAsyncResponseToUebOutgoingMessageJsonString(oamContext).contains("\"rpc-name\":\"start\""));
62     }
63
64     @Test
65     public void testRestart() throws JsonProcessingException {
66         oamContext.setRpcName(RPC.restart);
67         assertTrue(Converter.convAsyncResponseToUebOutgoingMessageJsonString(oamContext).contains("\"rpc-name\":\"restart\""));
68     }
69
70     @Test
71     public void testMmode() throws JsonProcessingException {
72         oamContext.setRpcName(RPC.maintenance_mode);
73         assertTrue(Converter.convAsyncResponseToUebOutgoingMessageJsonString(oamContext).contains("\"rpc-name\":\"maintenance_mode\""));
74     }
75
76 }