diff options
author | 2019-02-28 10:46:08 +0000 | |
---|---|---|
committer | 2019-02-28 14:48:31 +0000 | |
commit | f3b94a73f7693b95164f970eca1d2ec283f85499 (patch) | |
tree | 15d37eae789035a0f0805a77d1bee2e3ae01ede4 /appc-provider/appc-provider-bundle/src/test/java/org/onap | |
parent | ac73fdb6edf67652785aa58b5b205b2e61c1e417 (diff) |
Test coverage in TopologyService
Increased coverage from 80% to 97%
Fix Sonar major issue for branch coverage
Issue-ID: APPC-1509
Change-Id: I2f5af194b44e5871fc00c9cc12123fa6d6c1fd5d
Signed-off-by: Joss Armstrong <joss.armstrong@ericsson.com>
Diffstat (limited to 'appc-provider/appc-provider-bundle/src/test/java/org/onap')
-rw-r--r-- | appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/topology/TopologyServiceTest.java | 119 |
1 files changed, 118 insertions, 1 deletions
diff --git a/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/topology/TopologyServiceTest.java b/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/topology/TopologyServiceTest.java index a4aed5048..d3d4a9b36 100644 --- a/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/topology/TopologyServiceTest.java +++ b/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/topology/TopologyServiceTest.java @@ -34,12 +34,17 @@ import org.opendaylight.yang.gen.v1.org.onap.appc.provider.rev160104.UUID; import org.opendaylight.yang.gen.v1.org.onap.appc.provider.rev160104.common.request.header.CommonRequestHeader; import org.opendaylight.yang.gen.v1.org.onap.appc.provider.rev160104.config.payload.ConfigPayload; import org.opendaylight.yang.gen.v1.org.onap.appc.provider.rev160104.vnf.resource.VnfResource; +import org.onap.appc.Constants; import org.onap.appc.configuration.Configuration; import org.onap.appc.configuration.ConfigurationFactory; import org.onap.appc.provider.AppcProvider; +import org.onap.appc.provider.AppcProviderClient; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; - +import org.powermock.reflect.Whitebox; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.internal.verification.VerificationModeFactory.times; @@ -148,4 +153,116 @@ public class TopologyServiceTest { Mockito.verify(topologyService, times(1)).callGraph(Mockito.any(Properties.class)); } + @Test + public void testCallGraphSuccess() throws SvcLogicException { + Properties properties = new Properties(); + properties.setProperty(Constants.PROPERTY_MODULE_NAME, "test_module_name"); + properties.setProperty(Constants.PROPERTY_TOPOLOGY_METHOD, "test_topology_method"); + properties.setProperty(Constants.PROPERTY_TOPOLOGY_VERSION, "test_topology_version"); + AppcProviderClient client = Mockito.mock(AppcProviderClient.class); + Mockito.when(client.hasGraph(Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) + .thenReturn(true); + Properties respProps = new Properties(); + respProps.setProperty(Constants.ATTRIBUTE_ERROR_CODE, "200"); + Mockito.when(client.execute(Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), + Mockito.any(Properties.class))).thenReturn(respProps); + AppcProvider provider = Mockito.mock(AppcProvider.class); + Mockito.when(provider.getClient()).thenReturn(client); + Whitebox.setInternalState(topologyService, "provider", provider); + assertTrue(topologyService.callGraph(properties)); + } + + @Test + public void testCallGraphNoGraph() throws SvcLogicException { + Properties properties = new Properties(); + properties.setProperty(Constants.PROPERTY_MODULE_NAME, "test_module_name"); + properties.setProperty(Constants.PROPERTY_TOPOLOGY_METHOD, "test_topology_method"); + properties.setProperty(Constants.PROPERTY_TOPOLOGY_VERSION, "test_topology_version"); + AppcProviderClient client = Mockito.mock(AppcProviderClient.class); + Mockito.when(client.hasGraph(Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) + .thenReturn(false); + Properties respProps = new Properties(); + respProps.setProperty(Constants.ATTRIBUTE_ERROR_CODE, "200"); + Mockito.when(client.execute(Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), + Mockito.any(Properties.class))).thenReturn(respProps); + AppcProvider provider = Mockito.mock(AppcProvider.class); + Mockito.when(provider.getClient()).thenReturn(client); + Whitebox.setInternalState(topologyService, "provider", provider); + assertFalse(topologyService.callGraph(properties)); + } + + @Test + public void testCallGraphException() throws SvcLogicException { + Properties properties = new Properties(); + properties.setProperty(Constants.PROPERTY_MODULE_NAME, "test_module_name"); + properties.setProperty(Constants.PROPERTY_TOPOLOGY_METHOD, "test_topology_method"); + properties.setProperty(Constants.PROPERTY_TOPOLOGY_VERSION, "test_topology_version"); + AppcProviderClient client = Mockito.mock(AppcProviderClient.class); + Mockito.when(client.hasGraph(Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) + .thenReturn(true); + Properties respProps = new Properties(); + respProps.setProperty(Constants.ATTRIBUTE_ERROR_CODE, "200"); + Mockito.when(client.execute(Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), + Mockito.any(Properties.class))).thenThrow(new SvcLogicException()); + AppcProvider provider = Mockito.mock(AppcProvider.class); + Mockito.when(provider.getClient()).thenReturn(client); + Whitebox.setInternalState(topologyService, "provider", provider); + assertFalse(topologyService.callGraph(properties)); + } + + @Test + public void testCallGraphNoAttributeErrorCode() throws SvcLogicException { + Properties properties = new Properties(); + properties.setProperty(Constants.PROPERTY_MODULE_NAME, "test_module_name"); + properties.setProperty(Constants.PROPERTY_TOPOLOGY_METHOD, "test_topology_method"); + properties.setProperty(Constants.PROPERTY_TOPOLOGY_VERSION, "test_topology_version"); + AppcProviderClient client = Mockito.mock(AppcProviderClient.class); + Mockito.when(client.hasGraph(Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) + .thenReturn(true); + Properties respProps = new Properties(); + Mockito.when(client.execute(Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), + Mockito.any(Properties.class))).thenReturn(respProps); + AppcProvider provider = Mockito.mock(AppcProvider.class); + Mockito.when(provider.getClient()).thenReturn(client); + Whitebox.setInternalState(topologyService, "provider", provider); + assertFalse(topologyService.callGraph(properties)); + } + + @Test + public void testCallGraphErrorCodeGreaterThan300() throws SvcLogicException { + Properties properties = new Properties(); + properties.setProperty(Constants.PROPERTY_MODULE_NAME, "test_module_name"); + properties.setProperty(Constants.PROPERTY_TOPOLOGY_METHOD, "test_topology_method"); + properties.setProperty(Constants.PROPERTY_TOPOLOGY_VERSION, "test_topology_version"); + AppcProviderClient client = Mockito.mock(AppcProviderClient.class); + Mockito.when(client.hasGraph(Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) + .thenReturn(true); + Properties respProps = new Properties(); + respProps.setProperty(Constants.ATTRIBUTE_ERROR_CODE, "400"); + Mockito.when(client.execute(Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), + Mockito.any(Properties.class))).thenReturn(respProps); + AppcProvider provider = Mockito.mock(AppcProvider.class); + Mockito.when(provider.getClient()).thenReturn(client); + Whitebox.setInternalState(topologyService, "provider", provider); + assertFalse(topologyService.callGraph(properties)); + } + + @Test + public void testCallGraphNumberFormatException() throws SvcLogicException { + Properties properties = new Properties(); + properties.setProperty(Constants.PROPERTY_MODULE_NAME, "test_module_name"); + properties.setProperty(Constants.PROPERTY_TOPOLOGY_METHOD, "test_topology_method"); + properties.setProperty(Constants.PROPERTY_TOPOLOGY_VERSION, "test_topology_version"); + AppcProviderClient client = Mockito.mock(AppcProviderClient.class); + Mockito.when(client.hasGraph(Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) + .thenReturn(true); + Properties respProps = new Properties(); + respProps.setProperty(Constants.ATTRIBUTE_ERROR_CODE, "NaN"); + Mockito.when(client.execute(Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), + Mockito.any(Properties.class))).thenReturn(respProps); + AppcProvider provider = Mockito.mock(AppcProvider.class); + Mockito.when(provider.getClient()).thenReturn(client); + Whitebox.setInternalState(topologyService, "provider", provider); + assertFalse(topologyService.callGraph(properties)); + } }
\ No newline at end of file |