diff options
author | Joss Armstrong <joss.armstrong@ericsson.com> | 2019-02-14 13:38:23 +0000 |
---|---|---|
committer | Takamune Cho <takamune.cho@att.com> | 2019-02-14 16:29:22 +0000 |
commit | 19bb17c4b16ee955cdec6db9ddc2af25845df062 (patch) | |
tree | e4f15ad6e22940d1c7725e73ea7f4d5f6ef5a119 /appc-inbound/appc-design-services/provider/src/test | |
parent | 6d9bedf2ed048a7715f0b6927683d904db9524b1 (diff) |
Test coverage in XInterfaceService
Increased coverage from 68% to 100%
Issue-ID: APPC-1436
Change-Id: If9f1670ba9955325bf938d7edf3d7d67bb48088c
Signed-off-by: Joss Armstrong <joss.armstrong@ericsson.com>
Diffstat (limited to 'appc-inbound/appc-design-services/provider/src/test')
-rw-r--r-- | appc-inbound/appc-design-services/provider/src/test/java/org/onap/appc/design/xinterface/XInterfaceServiceTest.java | 76 |
1 files changed, 76 insertions, 0 deletions
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", "{}"); + } +} |