aboutsummaryrefslogtreecommitdiffstats
path: root/appc-provider
diff options
context:
space:
mode:
authorJoss Armstrong <joss.armstrong@ericsson.com>2019-02-28 10:46:08 +0000
committerTakamune Cho <takamune.cho@att.com>2019-02-28 14:48:31 +0000
commitf3b94a73f7693b95164f970eca1d2ec283f85499 (patch)
tree15d37eae789035a0f0805a77d1bee2e3ae01ede4 /appc-provider
parentac73fdb6edf67652785aa58b5b205b2e61c1e417 (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')
-rw-r--r--appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/topology/TopologyService.java6
-rw-r--r--appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/topology/TopologyServiceTest.java119
2 files changed, 118 insertions, 7 deletions
diff --git a/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/topology/TopologyService.java b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/topology/TopologyService.java
index 441aab624..1a95d24ab 100644
--- a/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/topology/TopologyService.java
+++ b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/topology/TopologyService.java
@@ -84,14 +84,10 @@ public class TopologyService {
private final EELFLogger auditLogger = EELFManager.getInstance().getAuditLogger();
private final EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger();
private final EELFLogger performanceLogger = EELFManager.getInstance().getPerformanceLogger();
- private final static String DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ssX";
- private final static String START_TIME_PARAM = "startTime";
private final static String RESTART_INITIATED_STR = "Metrics Logger: App-C Restart initiated. Start Time: [%s]. Request ID: [%s]";
private final static String TARGET_PARAM = "target";
private final static String SUCCESS_PARAM = "SUCCESS";
private final static String FAILURE_PARAM = "FAILURE";
- private final static String END_TIME_PARAM = "endTime";
- private final static String DURATION_PARAM = "duration";
private final static String ERROR_STR = "An error occurred";
/**
@@ -701,6 +697,4 @@ public class TopologyService {
Msg.DEBUG_GRAPH_RESPONSE_DETAIL, appName, graphName, key, (String) respProps.get(key)));
}
}
-
}
-
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