Test coverage in XInterfaceService
[appc.git] / appc-inbound / appc-design-services / provider / src / test / java / org / onap / appc / design / xinterface / XInterfaceServiceTest.java
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
4  * ================================================================================
5  * Copyright (C) 2019 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.design.xinterface;
23
24 import static org.junit.Assert.assertNull;
25 import org.junit.Rule;
26 import org.junit.Test;
27 import org.junit.rules.ExpectedException;
28 import org.mockito.Mockito;
29 import org.onap.appc.design.services.util.DesignServiceConstants;
30
31 public class XInterfaceServiceTest {
32
33     @Rule
34     public ExpectedException expectedEx = ExpectedException.none();
35
36     @Test
37     public void testExecute() throws Exception {
38         XInterfaceService service = Mockito.spy(new XInterfaceService());
39         XResponseProcessor processor = Mockito.mock(XResponseProcessor.class);
40         Mockito.when(processor.parseResponse(Mockito.anyString(), Mockito.anyString())).thenReturn(null);
41         Mockito.when(service.getXResponseProcessor()).thenReturn(processor);
42         assertNull(service.execute(DesignServiceConstants.GETINSTARDATA, "{}"));
43     }
44
45     @Test
46     public void testExecuteException() throws Exception {
47         XInterfaceService service = Mockito.spy(XInterfaceService.getInstance());
48         XResponseProcessor processor = Mockito.mock(XResponseProcessor.class);
49         Mockito.when(processor.parseResponse(Mockito.anyString(), Mockito.anyString())).thenThrow(new RuntimeException());
50         Mockito.when(service.getXResponseProcessor()).thenReturn(processor);
51         expectedEx.expect(RuntimeException.class);
52         service.execute(DesignServiceConstants.GETINSTARDATA, "{}");
53     }
54
55     @Test
56     public void testExecuteNullPayload() throws Exception {
57         XInterfaceService service = Mockito.spy(XInterfaceService.getInstance());
58         XResponseProcessor processor = Mockito.mock(XResponseProcessor.class);
59         Mockito.when(processor.parseResponse(Mockito.anyString(), Mockito.anyString())).thenThrow(new RuntimeException());
60         Mockito.when(service.getXResponseProcessor()).thenReturn(processor);
61         expectedEx.expect(Exception.class);
62         expectedEx.expectMessage("Payload is null or empty..");
63         service.execute(DesignServiceConstants.GETINSTARDATA, null);
64     }
65
66     @Test
67     public void testExecuteInvalidAction() throws Exception {
68         XInterfaceService service = Mockito.spy(XInterfaceService.getInstance());
69         XResponseProcessor processor = Mockito.mock(XResponseProcessor.class);
70         Mockito.when(processor.parseResponse(Mockito.anyString(), Mockito.anyString())).thenThrow(new RuntimeException());
71         Mockito.when(service.getXResponseProcessor()).thenReturn(processor);
72         expectedEx.expect(Exception.class);
73         expectedEx.expectMessage("No Such Action, Please enter valid Action");
74         service.execute("TEST", "{}");
75     }
76 }