summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authoraditya <ag282f@att.com>2017-10-12 08:09:20 -0500
committeraditya <ag282f@att.com>2017-10-12 08:13:48 -0500
commitaec86f150d536f5b37be0fc6fea02e0df49c3c26 (patch)
treeab95c6f421aff12668d970f228215a6adbd242f1 /src
parent57ebc748b30fc61ea3bee40abf0fd8b41b785088 (diff)
Add unit test cases.
Add unit test cases. Issue-ID: AAI-429 Change-Id: I3efdaf3b5f477442c691b6095681f34c4e35b53c Signed-off-by: Aditya Gajulapalli <ag282f@att.com>
Diffstat (limited to 'src')
-rw-r--r--src/test/java/org/onap/aai/sparky/analytics/AbstractStatisticsTest.java46
-rw-r--r--src/test/java/org/onap/aai/sparky/analytics/HistoricalCounterTest.java52
-rw-r--r--src/test/java/org/onap/aai/sparky/config/oxm/CrossEntityReferenceTest.java27
-rw-r--r--src/test/java/org/onap/aai/sparky/config/oxm/OxmModelLoaderFilterTest.java55
-rw-r--r--src/test/java/org/onap/aai/sparky/dal/NetworkTransactionTest.java36
-rw-r--r--src/test/java/org/onap/aai/sparky/dal/aai/ActiveInventoryEntityStatisticsTest.java75
-rw-r--r--src/test/java/org/onap/aai/sparky/dal/aai/ActiveInventoryProcessingExceptionStatisticsTest.java60
-rw-r--r--src/test/java/org/onap/aai/sparky/dal/cache/InMemoryEntityCacheTest.java26
8 files changed, 377 insertions, 0 deletions
diff --git a/src/test/java/org/onap/aai/sparky/analytics/AbstractStatisticsTest.java b/src/test/java/org/onap/aai/sparky/analytics/AbstractStatisticsTest.java
new file mode 100644
index 0000000..a420e1d
--- /dev/null
+++ b/src/test/java/org/onap/aai/sparky/analytics/AbstractStatisticsTest.java
@@ -0,0 +1,46 @@
+package org.onap.aai.sparky.analytics;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class AbstractStatisticsTest {
+
+ @Test
+ public void testAllMethods() {
+ AbstractStatistics abs = new AbstractStatistics();
+
+ int counterValue1 = abs.getCounterValue("key");
+ Assert.assertEquals(-1, counterValue1);
+
+ abs.addCounter("key");
+ int counterValue2 = abs.getCounterValue("key");
+ Assert.assertEquals(0, counterValue2);
+
+ abs.pegCounter("key");
+ int counterValue3 = abs.getCounterValue("key");
+ Assert.assertEquals(1, counterValue3);
+
+ abs.incrementCounter("key", 2);
+ int counterValue4 = abs.getCounterValue("key");
+ Assert.assertEquals(3, counterValue4);
+
+ String histStat1 = abs.getHistogramStats("key", false, " ");
+ Assert.assertNull(histStat1);
+
+ abs.addHistogram("key", "hist1", 10, 1, 2);
+ String histStat2 = abs.getHistogramStats("key", false, " ");
+ Assert.assertEquals(" hist1,-1,0,0,0,1,10.00,0",histStat2);
+
+ abs.updateHistogram("key", 3);
+ String histStat3 = abs.getHistogramStats("key", false, " ");
+ Assert.assertEquals(" hist1,3,3,3,1,1,10.00,1",histStat3);
+
+ abs.reset();
+ int counterValue5 = abs.getCounterValue("key");
+ String histStat4 = abs.getHistogramStats("key", false, " ");
+ Assert.assertEquals(0, counterValue5);
+ Assert.assertEquals(" hist1,-1,0,0,0,1,10.00,0",histStat4);
+
+
+ }
+}
diff --git a/src/test/java/org/onap/aai/sparky/analytics/HistoricalCounterTest.java b/src/test/java/org/onap/aai/sparky/analytics/HistoricalCounterTest.java
new file mode 100644
index 0000000..9816fff
--- /dev/null
+++ b/src/test/java/org/onap/aai/sparky/analytics/HistoricalCounterTest.java
@@ -0,0 +1,52 @@
+package org.onap.aai.sparky.analytics;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class HistoricalCounterTest {
+
+
+ @Test
+ public void testAllMethods() {
+ HistoricalCounter hc = new HistoricalCounter(true);
+
+ boolean maintainSingleValue = hc.isSingleValue();
+ Assert.assertTrue(maintainSingleValue);
+
+ hc.update(1.0);
+ double value = hc.getValue();
+ Assert.assertEquals(1.0, value, 0.1);
+
+ double min = hc.getMin();
+ Assert.assertEquals(-1, min, 0.1);
+
+ double max = hc.getMax();
+ Assert.assertEquals(0, max, 0.1);
+
+ long numOfSamples = hc.getNumSamples();
+ Assert.assertEquals(0, numOfSamples, 0.1);
+
+ double avg = hc.getAvg();
+ Assert.assertEquals(0, avg, 0.1);
+
+ String stringValue = hc.toString();
+ Assert.assertNotNull(stringValue);
+
+ hc.reset();
+
+ double valueReset = hc.getValue();
+ Assert.assertEquals(0.0, valueReset, 0.1);
+
+ double minReset = hc.getMin();
+ Assert.assertEquals(-1, minReset, 0.1);
+
+ double maxReset = hc.getMax();
+ Assert.assertEquals(0, maxReset, 0.1);
+
+ long numOfSamplesReset = hc.getNumSamples();
+ Assert.assertEquals(0, numOfSamplesReset, 0.1);
+
+ double avgReset = hc.getAvg();
+ Assert.assertEquals(0, avgReset, 0.1);
+ }
+}
diff --git a/src/test/java/org/onap/aai/sparky/config/oxm/CrossEntityReferenceTest.java b/src/test/java/org/onap/aai/sparky/config/oxm/CrossEntityReferenceTest.java
new file mode 100644
index 0000000..205cefd
--- /dev/null
+++ b/src/test/java/org/onap/aai/sparky/config/oxm/CrossEntityReferenceTest.java
@@ -0,0 +1,27 @@
+package org.onap.aai.sparky.config.oxm;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.onap.aai.sparky.config.oxm.CrossEntityReference;
+
+public class CrossEntityReferenceTest {
+
+
+ @Test
+ public void testCrossEntityReferenceAllMethods() {
+ CrossEntityReference cer = new CrossEntityReference();
+
+ Assert.assertNull(cer.getTargetEntityType());
+
+ cer.setTargetEntityType("TET");
+ Assert.assertEquals(cer.getTargetEntityType(), "TET");
+
+ Assert.assertEquals(cer.getReferenceAttributes().size(), 0);
+
+ cer.addReferenceAttribute("AT");
+
+ Assert.assertEquals(cer.getReferenceAttributes().size(), 1);
+
+ Assert.assertNotNull(cer.toString());
+ }
+}
diff --git a/src/test/java/org/onap/aai/sparky/config/oxm/OxmModelLoaderFilterTest.java b/src/test/java/org/onap/aai/sparky/config/oxm/OxmModelLoaderFilterTest.java
new file mode 100644
index 0000000..0c21c03
--- /dev/null
+++ b/src/test/java/org/onap/aai/sparky/config/oxm/OxmModelLoaderFilterTest.java
@@ -0,0 +1,55 @@
+package org.onap.aai.sparky.config.oxm;
+
+import java.io.IOException;
+
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.onap.aai.sparky.config.oxm.OxmModelLoaderFilter;
+
+public class OxmModelLoaderFilterTest {
+
+ @Mock
+ ServletRequest servletRequest;
+
+ @Mock
+ ServletResponse servletResponse;
+
+ @Mock
+ FilterChain filterChain;
+
+ @Mock
+ FilterConfig filterConfig;
+
+ @InjectMocks
+ OxmModelLoaderFilter oxmModelLoaderFilter;
+
+ @Before
+ public void init() {
+ MockitoAnnotations.initMocks(this);
+ }
+
+ @Test
+ public void testDoFilter() throws IOException, ServletException{
+ Mockito.doNothing().when(filterChain).doFilter(Mockito.any(ServletRequest.class), Mockito.any(ServletResponse.class));
+ oxmModelLoaderFilter.doFilter(servletRequest, servletResponse, filterChain);
+ Mockito.verify(filterChain, Mockito.times(1)).doFilter(Mockito.any(ServletRequest.class), Mockito.any(ServletResponse.class));
+ }
+
+ /*This test is taking more than 5 secs. Commented out
+ @Test
+ public void testInit() throws ServletException {
+ OxmModelLoaderFilter oxmFilter = new OxmModelLoaderFilter();
+ oxmFilter.init(filterConfig);
+ }*/
+
+}
diff --git a/src/test/java/org/onap/aai/sparky/dal/NetworkTransactionTest.java b/src/test/java/org/onap/aai/sparky/dal/NetworkTransactionTest.java
new file mode 100644
index 0000000..0e3c398
--- /dev/null
+++ b/src/test/java/org/onap/aai/sparky/dal/NetworkTransactionTest.java
@@ -0,0 +1,36 @@
+package org.onap.aai.sparky.dal;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.onap.aai.sparky.config.oxm.OxmEntityDescriptor;
+import org.onap.aai.sparky.dal.rest.HttpMethod;
+import org.onap.aai.sparky.dal.rest.OperationResult;
+
+public class NetworkTransactionTest {
+
+ @Test
+ public void testAllMethods() {
+ NetworkTransaction ntt = new NetworkTransaction();
+ ntt.setOperationType(HttpMethod.GET);
+ Assert.assertEquals(HttpMethod.GET, ntt.getOperationType());
+
+ ntt.setTaskAgeInMs();
+ Assert.assertNotNull(ntt.getTaskAgeInMs());
+
+ ntt.setOperationResult(new OperationResult());
+ Assert.assertNotNull(ntt.getOperationResult());
+
+ ntt.setEntityType("entity");
+ Assert.assertEquals(ntt.getEntityType(), "entity");
+
+ ntt.setLink("link");
+ Assert.assertEquals(ntt.getLink(), "link");
+
+ ntt.setDescriptor(new OxmEntityDescriptor());
+ Assert.assertNotNull(ntt.getDescriptor());
+
+ Assert.assertNotNull(ntt.toString());
+ }
+
+
+}
diff --git a/src/test/java/org/onap/aai/sparky/dal/aai/ActiveInventoryEntityStatisticsTest.java b/src/test/java/org/onap/aai/sparky/dal/aai/ActiveInventoryEntityStatisticsTest.java
new file mode 100644
index 0000000..b1357c4
--- /dev/null
+++ b/src/test/java/org/onap/aai/sparky/dal/aai/ActiveInventoryEntityStatisticsTest.java
@@ -0,0 +1,75 @@
+package org.onap.aai.sparky.dal.aai;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.aai.sparky.config.oxm.OxmEntityDescriptor;
+import org.onap.aai.sparky.config.oxm.OxmModelLoader;
+import org.onap.aai.sparky.dal.NetworkTransaction;
+import org.onap.aai.sparky.dal.rest.HttpMethod;
+import org.onap.aai.sparky.dal.rest.OperationResult;
+
+public class ActiveInventoryEntityStatisticsTest {
+
+ OxmModelLoader oxmModelLoader;
+
+ @Before
+ public void init() {
+ oxmModelLoader = OxmModelLoader.getInstance();
+ }
+
+ @Test
+ public void testInitializeCountersFromOxmEntityDescriptors_NotNullDescriptors() {
+ ActiveInventoryEntityStatistics aies = new ActiveInventoryEntityStatistics(oxmModelLoader);
+
+ Map<String, OxmEntityDescriptor> descriptors = new HashMap<>();
+
+ OxmEntityDescriptor oxmEd = new OxmEntityDescriptor();
+ oxmEd.setEntityName("entity-1");
+ oxmEd.setGeoLatName("geoLatName-1");
+
+ descriptors.put("entity-1", oxmEd);
+
+ aies.initializeCountersFromOxmEntityDescriptors(descriptors);
+
+ aies.reset();
+
+ }
+
+ @Test
+ public void testInitializeCountersFromOxmEntityDescriptors_NullDescriptors() {
+ ActiveInventoryEntityStatistics aies = new ActiveInventoryEntityStatistics(oxmModelLoader);
+
+ Map<String, OxmEntityDescriptor> descriptors = null;
+
+ aies.initializeCountersFromOxmEntityDescriptors(descriptors);
+
+ }
+
+ @Test
+ public void testUpdateCounters() {
+
+ ActiveInventoryEntityStatistics aies = new ActiveInventoryEntityStatistics(oxmModelLoader);
+ Map<String, OxmEntityDescriptor> descriptors = new HashMap<>();
+ OxmEntityDescriptor oxmEd = new OxmEntityDescriptor();
+ oxmEd.setEntityName("entity-1");
+ oxmEd.setGeoLatName("geoLatName-1");
+ descriptors.put("entity-1", oxmEd);
+ aies.initializeCountersFromOxmEntityDescriptors(descriptors);
+
+ OperationResult result = new OperationResult();
+ result.setResultCode(200);
+ result.setResult("result-1");
+ result.setNumRequestRetries(1);
+ NetworkTransaction ntwTxn = new NetworkTransaction(HttpMethod.GET, "entity-1", result);
+
+ aies.updateCounters(ntwTxn);
+
+ String statistics = aies.getStatisticsReport();
+ Assert.assertNotNull(statistics);
+
+ }
+}
diff --git a/src/test/java/org/onap/aai/sparky/dal/aai/ActiveInventoryProcessingExceptionStatisticsTest.java b/src/test/java/org/onap/aai/sparky/dal/aai/ActiveInventoryProcessingExceptionStatisticsTest.java
new file mode 100644
index 0000000..5677f4c
--- /dev/null
+++ b/src/test/java/org/onap/aai/sparky/dal/aai/ActiveInventoryProcessingExceptionStatisticsTest.java
@@ -0,0 +1,60 @@
+package org.onap.aai.sparky.dal.aai;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.onap.aai.sparky.dal.NetworkTransaction;
+import org.onap.aai.sparky.dal.rest.HttpMethod;
+import org.onap.aai.sparky.dal.rest.OperationResult;
+
+public class ActiveInventoryProcessingExceptionStatisticsTest {
+
+
+ @Test
+ public void testUpdateCounters() {
+ ActiveInventoryProcessingExceptionStatistics aipes = new ActiveInventoryProcessingExceptionStatistics();
+
+ aipes.incrementCounter("NativeSocketConnectException", 1);
+ aipes.incrementCounter("NativeSocketConnectionReset", 1);
+ aipes.incrementCounter("NativeSocketConnectionRefused", 1);
+ aipes.incrementCounter("JerseyClientTimoutException", 1);
+ aipes.incrementCounter("UnknownException", 1);
+
+ OperationResult result = new OperationResult();
+ result.setResultCode(310);
+ result.setResult("java.net.SocketTimeoutException: connect timed out");
+ result.setNumRequestRetries(1);
+ NetworkTransaction ntwTxn1 = new NetworkTransaction(HttpMethod.GET, "entity-1", result);
+ aipes.updateCounters(ntwTxn1);
+
+ result.setResult("result-1");
+ NetworkTransaction ntwTxn2 = new NetworkTransaction(HttpMethod.GET, "entity-1", result);
+ aipes.updateCounters(ntwTxn2);
+
+ result.setResult("java.net.ConnectException: Connection timed out: connect");
+ NetworkTransaction ntwTxn3 = new NetworkTransaction(HttpMethod.GET, "entity-1", result);
+ aipes.updateCounters(ntwTxn3);
+
+ result.setResult("java.net.ConnectException: Connection refused: connect");
+ NetworkTransaction ntwTxn4 = new NetworkTransaction(HttpMethod.GET, "entity-1", result);
+ aipes.updateCounters(ntwTxn4);
+
+ result.setResult("java.net.SocketException: Connection reset");
+ NetworkTransaction ntwTxn5 = new NetworkTransaction(HttpMethod.GET, "entity-1", result);
+ aipes.updateCounters(ntwTxn5);
+
+ }
+
+ @Test
+ public void testGetStatisticsReport() {
+ ActiveInventoryProcessingExceptionStatistics aipes = new ActiveInventoryProcessingExceptionStatistics();
+
+ aipes.incrementCounter("NativeSocketConnectException", 1);
+ aipes.incrementCounter("NativeSocketConnectionReset", 1);
+ aipes.incrementCounter("NativeSocketConnectionRefused", 1);
+ aipes.incrementCounter("JerseyClientTimoutException", 1);
+ aipes.incrementCounter("UnknownException", 1);
+
+ String statReport = aipes.getStatisticsReport();
+ Assert.assertNotNull(statReport);
+ }
+}
diff --git a/src/test/java/org/onap/aai/sparky/dal/cache/InMemoryEntityCacheTest.java b/src/test/java/org/onap/aai/sparky/dal/cache/InMemoryEntityCacheTest.java
new file mode 100644
index 0000000..45481ce
--- /dev/null
+++ b/src/test/java/org/onap/aai/sparky/dal/cache/InMemoryEntityCacheTest.java
@@ -0,0 +1,26 @@
+package org.onap.aai.sparky.dal.cache;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.onap.aai.sparky.dal.rest.OperationResult;
+
+public class InMemoryEntityCacheTest {
+
+ @Test
+ public void testInMemoryEntityCache_AllMethods() {
+
+ InMemoryEntityCache imec = new InMemoryEntityCache();
+
+ imec.put("key-1", null);
+ Assert.assertNull(imec.get("entity-1", "key-1"));
+ Assert.assertNull(imec.get("entity-1", null));
+
+ OperationResult result = new OperationResult();
+ result.setResultCode(200);
+ result.setResult("result-1");
+ result.setNumRequestRetries(1);
+
+ imec.put("key-1", result);
+ Assert.assertNotNull(imec.get("entity-1", "key-1"));
+ }
+}