2 * ============LICENSE_START=======================================================
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
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.
19 * ============LICENSE_END=========================================================
22 package org.onap.appc.design.xinterface;
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;
31 public class XInterfaceServiceTest {
34 public ExpectedException expectedEx = ExpectedException.none();
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, "{}"));
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, "{}");
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);
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", "{}");