From 19bb17c4b16ee955cdec6db9ddc2af25845df062 Mon Sep 17 00:00:00 2001 From: Joss Armstrong Date: Thu, 14 Feb 2019 13:38:23 +0000 Subject: Test coverage in XInterfaceService Increased coverage from 68% to 100% Issue-ID: APPC-1436 Change-Id: If9f1670ba9955325bf938d7edf3d7d67bb48088c Signed-off-by: Joss Armstrong --- .../design/xinterface/XInterfaceServiceTest.java | 76 ++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 appc-inbound/appc-design-services/provider/src/test/java/org/onap/appc/design/xinterface/XInterfaceServiceTest.java (limited to 'appc-inbound/appc-design-services/provider/src/test') diff --git a/appc-inbound/appc-design-services/provider/src/test/java/org/onap/appc/design/xinterface/XInterfaceServiceTest.java b/appc-inbound/appc-design-services/provider/src/test/java/org/onap/appc/design/xinterface/XInterfaceServiceTest.java new file mode 100644 index 000000000..4e3f83fa3 --- /dev/null +++ b/appc-inbound/appc-design-services/provider/src/test/java/org/onap/appc/design/xinterface/XInterfaceServiceTest.java @@ -0,0 +1,76 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2019 Ericsson + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.design.xinterface; + +import static org.junit.Assert.assertNull; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.mockito.Mockito; +import org.onap.appc.design.services.util.DesignServiceConstants; + +public class XInterfaceServiceTest { + + @Rule + public ExpectedException expectedEx = ExpectedException.none(); + + @Test + public void testExecute() throws Exception { + XInterfaceService service = Mockito.spy(new XInterfaceService()); + XResponseProcessor processor = Mockito.mock(XResponseProcessor.class); + Mockito.when(processor.parseResponse(Mockito.anyString(), Mockito.anyString())).thenReturn(null); + Mockito.when(service.getXResponseProcessor()).thenReturn(processor); + assertNull(service.execute(DesignServiceConstants.GETINSTARDATA, "{}")); + } + + @Test + public void testExecuteException() throws Exception { + XInterfaceService service = Mockito.spy(XInterfaceService.getInstance()); + XResponseProcessor processor = Mockito.mock(XResponseProcessor.class); + Mockito.when(processor.parseResponse(Mockito.anyString(), Mockito.anyString())).thenThrow(new RuntimeException()); + Mockito.when(service.getXResponseProcessor()).thenReturn(processor); + expectedEx.expect(RuntimeException.class); + service.execute(DesignServiceConstants.GETINSTARDATA, "{}"); + } + + @Test + public void testExecuteNullPayload() throws Exception { + XInterfaceService service = Mockito.spy(XInterfaceService.getInstance()); + XResponseProcessor processor = Mockito.mock(XResponseProcessor.class); + Mockito.when(processor.parseResponse(Mockito.anyString(), Mockito.anyString())).thenThrow(new RuntimeException()); + Mockito.when(service.getXResponseProcessor()).thenReturn(processor); + expectedEx.expect(Exception.class); + expectedEx.expectMessage("Payload is null or empty.."); + service.execute(DesignServiceConstants.GETINSTARDATA, null); + } + + @Test + public void testExecuteInvalidAction() throws Exception { + XInterfaceService service = Mockito.spy(XInterfaceService.getInstance()); + XResponseProcessor processor = Mockito.mock(XResponseProcessor.class); + Mockito.when(processor.parseResponse(Mockito.anyString(), Mockito.anyString())).thenThrow(new RuntimeException()); + Mockito.when(service.getXResponseProcessor()).thenReturn(processor); + expectedEx.expect(Exception.class); + expectedEx.expectMessage("No Such Action, Please enter valid Action"); + service.execute("TEST", "{}"); + } +} -- cgit 1.2.3-korg