summaryrefslogtreecommitdiffstats
path: root/sparkybe-onap-service/src
diff options
context:
space:
mode:
authorrenealr <reneal.rogers@amdocs.com>2018-03-29 14:20:09 -0400
committerrenealr <reneal.rogers@amdocs.com>2018-03-29 14:33:34 -0400
commita4fdf1d339c89403ad747698f1d314600bdc13b9 (patch)
tree8d106e82f8a35e234c7fcd792db64cbd2a5a0ef0 /sparkybe-onap-service/src
parent90f3c038df1977779632f71f0aedf112a409919f (diff)
add test cases to increase coverage
added additional test cases to increase coverage Issue-ID: AAI-951 Change-Id: I50ce2a499d4b3bb0b762053a5690cb2e3a8eaf2b Signed-off-by: renealr <reneal.rogers@amdocs.com>
Diffstat (limited to 'sparkybe-onap-service/src')
-rw-r--r--sparkybe-onap-service/src/test/java/org/onap/aai/sparky/aggregation/sync/HistoricalEntitySummarizerTest.java351
-rw-r--r--sparkybe-onap-service/src/test/java/org/onap/aai/sparky/autosuggestion/sync/AutosuggestionSynchronizerTest.java62
-rw-r--r--sparkybe-onap-service/src/test/java/org/onap/aai/sparky/autosuggestion/sync/VnfAliasSuggestionSynchronizerTest.java365
-rw-r--r--sparkybe-onap-service/src/test/java/org/onap/aai/sparky/search/EntityCountHistoryProcessorTest.java52
-rw-r--r--sparkybe-onap-service/src/test/java/org/onap/aai/sparky/subscription/SubscriptionServiceProcessorTest.java63
-rw-r--r--sparkybe-onap-service/src/test/java/org/onap/aai/sparky/topology/sync/GeoSynchronizerTest.java351
-rw-r--r--sparkybe-onap-service/src/test/java/org/onap/aai/sparky/viewandinspect/sync/ViewInspectEntitySynchronizerTest.java348
7 files changed, 1509 insertions, 83 deletions
diff --git a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/aggregation/sync/HistoricalEntitySummarizerTest.java b/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/aggregation/sync/HistoricalEntitySummarizerTest.java
new file mode 100644
index 0000000..71eefe5
--- /dev/null
+++ b/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/aggregation/sync/HistoricalEntitySummarizerTest.java
@@ -0,0 +1,351 @@
+package org.onap.aai.sparky.aggregation.sync;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Matchers;
+import org.mockito.Mockito;
+import org.onap.aai.restclient.client.OperationResult;
+import org.onap.aai.sparky.config.oxm.OxmEntityDescriptor;
+import org.onap.aai.sparky.config.oxm.OxmEntityLookup;
+import org.onap.aai.sparky.config.oxm.OxmModelLoader;
+import org.onap.aai.sparky.config.oxm.OxmModelProcessor;
+import org.onap.aai.sparky.config.oxm.SearchableEntityLookup;
+import org.onap.aai.sparky.config.oxm.SuggestionEntityDescriptor;
+import org.onap.aai.sparky.dal.ActiveInventoryAdapter;
+import org.onap.aai.sparky.dal.ElasticSearchAdapter;
+import org.onap.aai.sparky.sync.config.ElasticSearchSchemaConfig;
+import org.onap.aai.sparky.sync.config.NetworkStatisticsConfig;
+import org.onap.aai.sparky.sync.enumeration.OperationState;
+import org.onap.aai.sparky.util.TestResourceLoader;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+public class HistoricalEntitySummarizerTest {
+
+ private static ObjectMapper mapper = new ObjectMapper();
+
+ private HistoricalEntitySummarizer historicalSummarizer;
+
+ private ElasticSearchSchemaConfig esSchemaConfig;
+ private NetworkStatisticsConfig aaiStatConfig;
+ private NetworkStatisticsConfig esStatConfig;
+ private OxmEntityLookup oxmEntityLookup;
+ private SearchableEntityLookup searchableEntityLookup;
+ private ElasticSearchAdapter esAdapter;
+ private ActiveInventoryAdapter aaiAdapter;
+
+
+
+ @Before
+ public void init() throws Exception {
+
+ esSchemaConfig = new ElasticSearchSchemaConfig();
+ esSchemaConfig.setIndexDocType("default");
+ esSchemaConfig.setIndexMappingsFileName(null);
+ esSchemaConfig.setIndexName("aggregation-index-name");
+ esSchemaConfig.setIndexSettingsFileName(null);
+
+
+ aaiStatConfig = new NetworkStatisticsConfig();
+
+ aaiStatConfig.setNumSamplesPerThreadForRunningAverage(100);
+
+ aaiStatConfig.setBytesHistogramLabel("[Response Size In Bytes]");
+ aaiStatConfig.setBytesHistogramMaxYAxis(1000000L);
+ aaiStatConfig.setBytesHistogramNumBins(20);
+ aaiStatConfig.setBytesHistogramNumDecimalPoints(2);
+
+ aaiStatConfig.setQueueLengthHistogramLabel("[Queue Item Length]");
+ aaiStatConfig.setQueueLengthHistogramMaxYAxis(20000);
+ aaiStatConfig.setQueueLengthHistogramNumBins(20);
+ aaiStatConfig.setQueueLengthHistogramNumDecimalPoints(2);
+
+ aaiStatConfig.setTaskAgeHistogramLabel("[Task Age In Ms]");
+ aaiStatConfig.setTaskAgeHistogramMaxYAxis(600000L);
+ aaiStatConfig.setTaskAgeHistogramNumBins(20);
+ aaiStatConfig.setTaskAgeHistogramNumDecimalPoints(2);
+
+ aaiStatConfig.setResponseTimeHistogramLabel("[Response Time In Ms]");
+ aaiStatConfig.setResponseTimeHistogramMaxYAxis(1000L);
+ aaiStatConfig.setResponseTimeHistogramNumBins(20);
+ aaiStatConfig.setResponseTimeHistogramNumDecimalPoints(2);
+
+ aaiStatConfig.setTpsHistogramLabel("[Transactions Per Second]");
+ aaiStatConfig.setTpsHistogramMaxYAxis(100);
+ aaiStatConfig.setTpsHistogramNumBins(20);
+ aaiStatConfig.setTpsHistogramNumDecimalPoints(2);
+
+ esStatConfig = new NetworkStatisticsConfig();
+
+ esStatConfig.setNumSamplesPerThreadForRunningAverage(100);
+
+ esStatConfig.setBytesHistogramLabel("[Response Size In Bytes]");
+ esStatConfig.setBytesHistogramMaxYAxis(1000000L);
+ esStatConfig.setBytesHistogramNumBins(20);
+ esStatConfig.setBytesHistogramNumDecimalPoints(2);
+
+ esStatConfig.setQueueLengthHistogramLabel("[Queue Item Length]");
+ esStatConfig.setQueueLengthHistogramMaxYAxis(20000);
+ esStatConfig.setQueueLengthHistogramNumBins(20);
+ esStatConfig.setQueueLengthHistogramNumDecimalPoints(2);
+
+ esStatConfig.setTaskAgeHistogramLabel("[Task Age In Ms]");
+ esStatConfig.setTaskAgeHistogramMaxYAxis(600000L);
+ esStatConfig.setTaskAgeHistogramNumBins(20);
+ esStatConfig.setTaskAgeHistogramNumDecimalPoints(2);
+
+ esStatConfig.setResponseTimeHistogramLabel("[Response Time In Ms]");
+ esStatConfig.setResponseTimeHistogramMaxYAxis(10000L);
+ esStatConfig.setResponseTimeHistogramNumBins(20);
+ esStatConfig.setResponseTimeHistogramNumDecimalPoints(2);
+
+ esStatConfig.setTpsHistogramLabel("[Transactions Per Second]");
+ esStatConfig.setTpsHistogramMaxYAxis(100);
+ esStatConfig.setTpsHistogramNumBins(20);
+ esStatConfig.setTpsHistogramNumDecimalPoints(2);
+
+ oxmEntityLookup = new OxmEntityLookup();
+
+ esAdapter = Mockito.mock(ElasticSearchAdapter.class);
+ aaiAdapter = Mockito.mock(ActiveInventoryAdapter.class);
+
+
+ Set<OxmModelProcessor> processors = new HashSet<OxmModelProcessor>();
+
+ processors.add(oxmEntityLookup);
+
+
+
+ Map<String, OxmEntityDescriptor> oxmEntityDescriptors =
+ new HashMap<String, OxmEntityDescriptor>();
+
+ OxmEntityDescriptor genericVnfDescriptor = new OxmEntityDescriptor();
+ genericVnfDescriptor.setEntityName("generic-vnf");
+ List<String> pkeyNames = new ArrayList<String>();
+ pkeyNames.add("vnf-name");
+
+ genericVnfDescriptor.setPrimaryKeyAttributeNames(pkeyNames);
+
+ oxmEntityDescriptors.put("generic-vnf", genericVnfDescriptor);
+
+
+ oxmEntityLookup.setEntityDescriptors(oxmEntityDescriptors);
+
+ SuggestionEntityDescriptor genericVnfSuggestionDescriptor = new SuggestionEntityDescriptor();
+ genericVnfSuggestionDescriptor.setEntityName("generic-vnf");
+ genericVnfSuggestionDescriptor.setPrimaryKeyAttributeNames(pkeyNames);
+
+
+
+ /*
+ * SuggestionSearchEntity sse = new SuggestionSearchEntity(filtersConfig);
+ *
+ * sse.setEntityType("generic-vnf"); sse.setSuggestionPropertyTypes( Arrays.asList("vnf-name"));
+ *
+ * genericVnfSuggestionDescriptor.setSuggestionSearchEntity(sse);
+ *
+ * suggestionEntityDescriptors.put("generic-vnf", genericVnfSuggestionDescriptor);
+ */
+
+ searchableEntityLookup = new SearchableEntityLookup();
+
+ processors.add(searchableEntityLookup);
+
+ OxmModelLoader oxmModelLoader = new OxmModelLoader(-1, processors);
+ oxmModelLoader.loadLatestOxmModel();
+
+ // suggestionEntityLookup.setSuggestionSearchEntityDescriptors(suggestionEntityDescriptors);
+ }
+
+ @Test
+ public void validateBasicConstruction() throws Exception {
+
+ historicalSummarizer = new HistoricalEntitySummarizer(esSchemaConfig, 5, 5, 5, aaiStatConfig,
+ esStatConfig, searchableEntityLookup);
+
+ historicalSummarizer.setAaiAdapter(aaiAdapter);
+ historicalSummarizer.setElasticSearchAdapter(esAdapter);
+
+ assertNotNull(historicalSummarizer.getAaiAdapter());
+ assertNotNull(historicalSummarizer.getElasticSearchAdapter());
+
+ }
+
+ @Test
+ public void validateSmallSync() throws Exception {
+
+ historicalSummarizer = new HistoricalEntitySummarizer(esSchemaConfig, 5, 5, 5, aaiStatConfig,
+ esStatConfig, searchableEntityLookup);
+
+
+ historicalSummarizer.setAaiAdapter(aaiAdapter);
+ historicalSummarizer.setElasticSearchAdapter(esAdapter);
+
+ String nodesQueryResponse = TestResourceLoader
+ .getTestResourceDataJson("/sync/aai/activeInventory_generic-vnf_nodesQuery_response.json");
+
+ OperationResult genericVnfSelfLinks = new OperationResult();
+
+ genericVnfSelfLinks.setResultCode(200);
+ genericVnfSelfLinks.setResult(nodesQueryResponse);
+
+ Mockito.when(aaiAdapter.getSelfLinksByEntityType("generic-vnf"))
+ .thenReturn(genericVnfSelfLinks);
+
+ Mockito.when(aaiAdapter.repairSelfLink(Matchers.contains("generic-vnf-1"), Mockito.anyString()))
+ .thenReturn(
+ "https://server.proxy:8443/aai/v11/network/generic-vnfs/generic-vnf/generic-vnf-1");
+
+ Mockito.when(aaiAdapter.repairSelfLink(Matchers.contains("generic-vnf-2"), Mockito.anyString()))
+ .thenReturn(
+ "https://server.proxy:8443/aai/v11/network/generic-vnfs/generic-vnf/generic-vnf-2");
+
+ Mockito.when(aaiAdapter.repairSelfLink(Matchers.contains("generic-vnf-3"), Mockito.anyString()))
+ .thenReturn(
+ "https://server.proxy:8443/aai/v11/network/generic-vnfs/generic-vnf/generic-vnf-3");
+
+ Mockito
+ .when(aaiAdapter.queryActiveInventoryWithRetries(Matchers.contains("generic-vnf-1"),
+ Mockito.anyString(), Mockito.anyInt()))
+ .thenReturn(new OperationResult(200, TestResourceLoader
+ .getTestResourceDataJson("/sync/aai/generic-vnf-generic-vnf-1_full_depth.json")));
+
+ Mockito
+ .when(aaiAdapter.queryActiveInventoryWithRetries(Matchers.contains("generic-vnf-2"),
+ Mockito.anyString(), Mockito.anyInt()))
+ .thenReturn(new OperationResult(200, TestResourceLoader
+ .getTestResourceDataJson("/sync/aai/generic-vnf-generic-vnf-2_full_depth.json")));
+
+ Mockito
+ .when(aaiAdapter.queryActiveInventoryWithRetries(Matchers.contains("generic-vnf-3"),
+ Mockito.anyString(), Mockito.anyInt()))
+ .thenReturn(new OperationResult(200, TestResourceLoader
+ .getTestResourceDataJson("/sync/aai/generic-vnf-generic-vnf-3_full_depth.json")));
+
+ Mockito.when(esAdapter.buildElasticSearchGetDocUrl(Mockito.anyString(), Mockito.anyString()))
+ .thenReturn("http://localhost:9200/myindex/mytype/doc1",
+ "http://localhost:9200/myindex/mytype/doc2",
+ "http://localhost:9200/myindex/mytype/doc3");
+
+ /*
+ * Our initial gets from elastic search should be record-not-found
+ */
+ Mockito.when(esAdapter.doGet(Matchers.contains("doc1"), Mockito.any()))
+ .thenReturn(new OperationResult(404, null));
+ Mockito.when(esAdapter.doGet(Matchers.contains("doc2"), Mockito.any()))
+ .thenReturn(new OperationResult(404, null));
+ Mockito.when(esAdapter.doGet(Matchers.contains("doc3"), Mockito.any()))
+ .thenReturn(new OperationResult(404, null));
+
+
+ Mockito.when(esAdapter.doPut(Matchers.contains("doc"), Mockito.any(), Mockito.any()))
+ .thenReturn(new OperationResult(200, null));
+
+ OperationState syncState = historicalSummarizer.doSync();
+ assertEquals(OperationState.OK, syncState);
+
+ assertNotNull(historicalSummarizer.getStatReport(false));
+ assertNotNull(historicalSummarizer.getStatReport(true));
+
+ historicalSummarizer.clearCache();
+ historicalSummarizer.shutdown();
+
+
+ }
+
+ @Test
+ public void validateSmallSyncWithRetries() throws Exception {
+
+ historicalSummarizer = new HistoricalEntitySummarizer(esSchemaConfig, 5, 5, 5, aaiStatConfig,
+ esStatConfig, searchableEntityLookup);
+
+
+ historicalSummarizer.setAaiAdapter(aaiAdapter);
+ historicalSummarizer.setElasticSearchAdapter(esAdapter);
+
+ String nodesQueryResponse = TestResourceLoader
+ .getTestResourceDataJson("/sync/aai/activeInventory_generic-vnf_nodesQuery_response.json");
+
+ OperationResult genericVnfSelfLinks = new OperationResult();
+
+ genericVnfSelfLinks.setResultCode(200);
+ genericVnfSelfLinks.setResult(nodesQueryResponse);
+
+ Mockito.when(aaiAdapter.getSelfLinksByEntityType("generic-vnf"))
+ .thenReturn(genericVnfSelfLinks);
+
+ Mockito.when(aaiAdapter.repairSelfLink(Matchers.contains("generic-vnf-1"), Mockito.anyString()))
+ .thenReturn(
+ "https://server.proxy:8443/aai/v11/network/generic-vnfs/generic-vnf/generic-vnf-1");
+
+ Mockito.when(aaiAdapter.repairSelfLink(Matchers.contains("generic-vnf-2"), Mockito.anyString()))
+ .thenReturn(
+ "https://server.proxy:8443/aai/v11/network/generic-vnfs/generic-vnf/generic-vnf-2");
+
+ Mockito.when(aaiAdapter.repairSelfLink(Matchers.contains("generic-vnf-3"), Mockito.anyString()))
+ .thenReturn(
+ "https://server.proxy:8443/aai/v11/network/generic-vnfs/generic-vnf/generic-vnf-3");
+
+ Mockito
+ .when(aaiAdapter.queryActiveInventoryWithRetries(Matchers.contains("generic-vnf-1"),
+ Mockito.anyString(), Mockito.anyInt()))
+ .thenReturn(new OperationResult(200, TestResourceLoader
+ .getTestResourceDataJson("/sync/aai/generic-vnf-generic-vnf-1_full_depth.json")));
+
+ Mockito
+ .when(aaiAdapter.queryActiveInventoryWithRetries(Matchers.contains("generic-vnf-2"),
+ Mockito.anyString(), Mockito.anyInt()))
+ .thenReturn(new OperationResult(200, TestResourceLoader
+ .getTestResourceDataJson("/sync/aai/generic-vnf-generic-vnf-2_full_depth.json")));
+
+ Mockito
+ .when(aaiAdapter.queryActiveInventoryWithRetries(Matchers.contains("generic-vnf-3"),
+ Mockito.anyString(), Mockito.anyInt()))
+ .thenReturn(new OperationResult(200, TestResourceLoader
+ .getTestResourceDataJson("/sync/aai/generic-vnf-generic-vnf-3_full_depth.json")));
+
+ Mockito.when(esAdapter.buildElasticSearchGetDocUrl(Mockito.anyString(), Mockito.anyString()))
+ .thenReturn("http://localhost:9200/myindex/mytype/doc1",
+ "http://localhost:9200/myindex/mytype/doc2",
+ "http://localhost:9200/myindex/mytype/doc3");
+
+ /*
+ * Our initial gets from elastic search should be record-not-found
+ */
+ Mockito.when(esAdapter.doGet(Matchers.contains("doc1"), Mockito.any()))
+ .thenReturn(new OperationResult(404, null));
+ Mockito.when(esAdapter.doGet(Matchers.contains("doc2"), Mockito.any()))
+ .thenReturn(new OperationResult(404, null));
+ Mockito.when(esAdapter.doGet(Matchers.contains("doc3"), Mockito.any()))
+ .thenReturn(new OperationResult(404, null));
+
+
+ /*
+ * Elastic Search puts always fail with a version conflict = 409
+ */
+
+ Mockito.when(esAdapter.doPut(Matchers.contains("doc"), Mockito.any(), Mockito.any()))
+ .thenReturn(new OperationResult(409, null));
+
+ OperationState syncState = historicalSummarizer.doSync();
+ assertEquals(OperationState.OK, syncState);
+
+ assertNotNull(historicalSummarizer.getStatReport(false));
+ assertNotNull(historicalSummarizer.getStatReport(true));
+
+ historicalSummarizer.clearCache();
+ historicalSummarizer.shutdown();
+
+
+ }
+}
diff --git a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/autosuggestion/sync/AutosuggestionSynchronizerTest.java b/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/autosuggestion/sync/AutosuggestionSynchronizerTest.java
index dd6f1c7..6ba2cb5 100644
--- a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/autosuggestion/sync/AutosuggestionSynchronizerTest.java
+++ b/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/autosuggestion/sync/AutosuggestionSynchronizerTest.java
@@ -34,7 +34,7 @@ import org.onap.aai.sparky.util.TestResourceLoader;
import com.fasterxml.jackson.databind.ObjectMapper;
public class AutosuggestionSynchronizerTest {
-
+
private static ObjectMapper mapper = new ObjectMapper();
private AutosuggestionSynchronizer suggestionSynchronizer;
@@ -222,37 +222,29 @@ public class AutosuggestionSynchronizerTest {
Mockito.when(aaiAdapter.getSelfLinksByEntityType("generic-vnf"))
.thenReturn(genericVnfSelfLinks);
- Mockito
- .when(aaiAdapter.repairSelfLink(Matchers.contains("generic-vnf-1"),
- Mockito.anyString()))
+ Mockito.when(aaiAdapter.repairSelfLink(Matchers.contains("generic-vnf-1"), Mockito.anyString()))
.thenReturn(
"https://server.proxy:8443/aai/v11/network/generic-vnfs/generic-vnf/generic-vnf-1");
- Mockito
- .when(aaiAdapter.repairSelfLink(Matchers.contains("generic-vnf-2"),
- Mockito.anyString()))
+ Mockito.when(aaiAdapter.repairSelfLink(Matchers.contains("generic-vnf-2"), Mockito.anyString()))
.thenReturn(
"https://server.proxy:8443/aai/v11/network/generic-vnfs/generic-vnf/generic-vnf-2");
- Mockito
- .when(
- aaiAdapter.repairSelfLink(Matchers.contains("generic-vnf-3"), Mockito.anyString()))
+ Mockito.when(aaiAdapter.repairSelfLink(Matchers.contains("generic-vnf-3"), Mockito.anyString()))
.thenReturn(
"https://server.proxy:8443/aai/v11/network/generic-vnfs/generic-vnf/generic-vnf-3");
Mockito
- .when(aaiAdapter.queryActiveInventoryWithRetries(
- Matchers.contains("generic-vnf-1"), Mockito.anyString(),
- Mockito.anyInt()))
- .thenReturn(new OperationResult(200, TestResourceLoader.getTestResourceDataJson(
- "/sync/aai/generic-vnf-generic-vnf-1_full_depth.json")));
+ .when(aaiAdapter.queryActiveInventoryWithRetries(Matchers.contains("generic-vnf-1"),
+ Mockito.anyString(), Mockito.anyInt()))
+ .thenReturn(new OperationResult(200, TestResourceLoader
+ .getTestResourceDataJson("/sync/aai/generic-vnf-generic-vnf-1_full_depth.json")));
Mockito
- .when(aaiAdapter.queryActiveInventoryWithRetries(
- Matchers.contains("generic-vnf-2"), Mockito.anyString(),
- Mockito.anyInt()))
- .thenReturn(new OperationResult(200, TestResourceLoader.getTestResourceDataJson(
- "/sync/aai/generic-vnf-generic-vnf-2_full_depth.json")));
+ .when(aaiAdapter.queryActiveInventoryWithRetries(Matchers.contains("generic-vnf-2"),
+ Mockito.anyString(), Mockito.anyInt()))
+ .thenReturn(new OperationResult(200, TestResourceLoader
+ .getTestResourceDataJson("/sync/aai/generic-vnf-generic-vnf-2_full_depth.json")));
Mockito
.when(aaiAdapter.queryActiveInventoryWithRetries(Matchers.contains("generic-vnf-3"),
@@ -312,37 +304,29 @@ public class AutosuggestionSynchronizerTest {
Mockito.when(aaiAdapter.getSelfLinksByEntityType("generic-vnf"))
.thenReturn(genericVnfSelfLinks);
- Mockito
- .when(aaiAdapter.repairSelfLink(Matchers.contains("generic-vnf-1"),
- Mockito.anyString()))
+ Mockito.when(aaiAdapter.repairSelfLink(Matchers.contains("generic-vnf-1"), Mockito.anyString()))
.thenReturn(
"https://server.proxy:8443/aai/v11/network/generic-vnfs/generic-vnf/generic-vnf-1");
- Mockito
- .when(aaiAdapter.repairSelfLink(Matchers.contains("generic-vnf-2"),
- Mockito.anyString()))
+ Mockito.when(aaiAdapter.repairSelfLink(Matchers.contains("generic-vnf-2"), Mockito.anyString()))
.thenReturn(
"https://server.proxy:8443/aai/v11/network/generic-vnfs/generic-vnf/generic-vnf-2");
- Mockito
- .when(
- aaiAdapter.repairSelfLink(Matchers.contains("generic-vnf-3"), Mockito.anyString()))
+ Mockito.when(aaiAdapter.repairSelfLink(Matchers.contains("generic-vnf-3"), Mockito.anyString()))
.thenReturn(
"https://server.proxy:8443/aai/v11/network/generic-vnfs/generic-vnf/generic-vnf-3");
Mockito
- .when(aaiAdapter.queryActiveInventoryWithRetries(
- Matchers.contains("generic-vnf-1"), Mockito.anyString(),
- Mockito.anyInt()))
- .thenReturn(new OperationResult(200, TestResourceLoader.getTestResourceDataJson(
- "/sync/aai/generic-vnf-generic-vnf-1_full_depth.json")));
+ .when(aaiAdapter.queryActiveInventoryWithRetries(Matchers.contains("generic-vnf-1"),
+ Mockito.anyString(), Mockito.anyInt()))
+ .thenReturn(new OperationResult(200, TestResourceLoader
+ .getTestResourceDataJson("/sync/aai/generic-vnf-generic-vnf-1_full_depth.json")));
Mockito
- .when(aaiAdapter.queryActiveInventoryWithRetries(
- Matchers.contains("generic-vnf-2"), Mockito.anyString(),
- Mockito.anyInt()))
- .thenReturn(new OperationResult(200, TestResourceLoader.getTestResourceDataJson(
- "/sync/aai/generic-vnf-generic-vnf-2_full_depth.json")));
+ .when(aaiAdapter.queryActiveInventoryWithRetries(Matchers.contains("generic-vnf-2"),
+ Mockito.anyString(), Mockito.anyInt()))
+ .thenReturn(new OperationResult(200, TestResourceLoader
+ .getTestResourceDataJson("/sync/aai/generic-vnf-generic-vnf-2_full_depth.json")));
Mockito
.when(aaiAdapter.queryActiveInventoryWithRetries(Matchers.contains("generic-vnf-3"),
diff --git a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/autosuggestion/sync/VnfAliasSuggestionSynchronizerTest.java b/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/autosuggestion/sync/VnfAliasSuggestionSynchronizerTest.java
new file mode 100644
index 0000000..e9bb4ec
--- /dev/null
+++ b/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/autosuggestion/sync/VnfAliasSuggestionSynchronizerTest.java
@@ -0,0 +1,365 @@
+package org.onap.aai.sparky.autosuggestion.sync;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Matchers;
+import org.mockito.Mockito;
+import org.onap.aai.restclient.client.OperationResult;
+import org.onap.aai.sparky.config.oxm.GeoEntityLookup;
+import org.onap.aai.sparky.config.oxm.OxmEntityDescriptor;
+import org.onap.aai.sparky.config.oxm.OxmEntityLookup;
+import org.onap.aai.sparky.config.oxm.OxmModelLoader;
+import org.onap.aai.sparky.config.oxm.OxmModelProcessor;
+import org.onap.aai.sparky.config.oxm.SuggestionEntityDescriptor;
+import org.onap.aai.sparky.dal.ActiveInventoryAdapter;
+import org.onap.aai.sparky.dal.ElasticSearchAdapter;
+import org.onap.aai.sparky.search.filters.config.FiltersConfig;
+import org.onap.aai.sparky.search.filters.config.FiltersDetailsConfig;
+import org.onap.aai.sparky.search.filters.config.FiltersForViewsConfig;
+import org.onap.aai.sparky.sync.config.ElasticSearchSchemaConfig;
+import org.onap.aai.sparky.sync.config.NetworkStatisticsConfig;
+import org.onap.aai.sparky.sync.enumeration.OperationState;
+import org.onap.aai.sparky.util.TestResourceLoader;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+public class VnfAliasSuggestionSynchronizerTest {
+
+ private static ObjectMapper mapper = new ObjectMapper();
+
+ private VnfAliasSuggestionSynchronizer vnfAliasSuggestionSynchronizer;
+
+ private ElasticSearchSchemaConfig esSchemaConfig;
+ private NetworkStatisticsConfig aaiStatConfig;
+ private NetworkStatisticsConfig esStatConfig;
+ private OxmEntityLookup oxmEntityLookup;
+ private GeoEntityLookup geoEntityLookup;
+ private ElasticSearchAdapter esAdapter;
+ private ActiveInventoryAdapter aaiAdapter;
+ private FiltersConfig filtersConfig;
+
+
+
+ @Before
+ public void init() throws Exception {
+
+ esSchemaConfig = new ElasticSearchSchemaConfig();
+ esSchemaConfig.setIndexDocType("default");
+ esSchemaConfig.setIndexMappingsFileName(null);
+ esSchemaConfig.setIndexName("aggregation-index-name");
+ esSchemaConfig.setIndexSettingsFileName(null);
+
+
+ aaiStatConfig = new NetworkStatisticsConfig();
+
+ aaiStatConfig.setNumSamplesPerThreadForRunningAverage(100);
+
+ aaiStatConfig.setBytesHistogramLabel("[Response Size In Bytes]");
+ aaiStatConfig.setBytesHistogramMaxYAxis(1000000L);
+ aaiStatConfig.setBytesHistogramNumBins(20);
+ aaiStatConfig.setBytesHistogramNumDecimalPoints(2);
+
+ aaiStatConfig.setQueueLengthHistogramLabel("[Queue Item Length]");
+ aaiStatConfig.setQueueLengthHistogramMaxYAxis(20000);
+ aaiStatConfig.setQueueLengthHistogramNumBins(20);
+ aaiStatConfig.setQueueLengthHistogramNumDecimalPoints(2);
+
+ aaiStatConfig.setTaskAgeHistogramLabel("[Task Age In Ms]");
+ aaiStatConfig.setTaskAgeHistogramMaxYAxis(600000L);
+ aaiStatConfig.setTaskAgeHistogramNumBins(20);
+ aaiStatConfig.setTaskAgeHistogramNumDecimalPoints(2);
+
+ aaiStatConfig.setResponseTimeHistogramLabel("[Response Time In Ms]");
+ aaiStatConfig.setResponseTimeHistogramMaxYAxis(1000L);
+ aaiStatConfig.setResponseTimeHistogramNumBins(20);
+ aaiStatConfig.setResponseTimeHistogramNumDecimalPoints(2);
+
+ aaiStatConfig.setTpsHistogramLabel("[Transactions Per Second]");
+ aaiStatConfig.setTpsHistogramMaxYAxis(100);
+ aaiStatConfig.setTpsHistogramNumBins(20);
+ aaiStatConfig.setTpsHistogramNumDecimalPoints(2);
+
+ esStatConfig = new NetworkStatisticsConfig();
+
+ esStatConfig.setNumSamplesPerThreadForRunningAverage(100);
+
+ esStatConfig.setBytesHistogramLabel("[Response Size In Bytes]");
+ esStatConfig.setBytesHistogramMaxYAxis(1000000L);
+ esStatConfig.setBytesHistogramNumBins(20);
+ esStatConfig.setBytesHistogramNumDecimalPoints(2);
+
+ esStatConfig.setQueueLengthHistogramLabel("[Queue Item Length]");
+ esStatConfig.setQueueLengthHistogramMaxYAxis(20000);
+ esStatConfig.setQueueLengthHistogramNumBins(20);
+ esStatConfig.setQueueLengthHistogramNumDecimalPoints(2);
+
+ esStatConfig.setTaskAgeHistogramLabel("[Task Age In Ms]");
+ esStatConfig.setTaskAgeHistogramMaxYAxis(600000L);
+ esStatConfig.setTaskAgeHistogramNumBins(20);
+ esStatConfig.setTaskAgeHistogramNumDecimalPoints(2);
+
+ esStatConfig.setResponseTimeHistogramLabel("[Response Time In Ms]");
+ esStatConfig.setResponseTimeHistogramMaxYAxis(10000L);
+ esStatConfig.setResponseTimeHistogramNumBins(20);
+ esStatConfig.setResponseTimeHistogramNumDecimalPoints(2);
+
+ esStatConfig.setTpsHistogramLabel("[Transactions Per Second]");
+ esStatConfig.setTpsHistogramMaxYAxis(100);
+ esStatConfig.setTpsHistogramNumBins(20);
+ esStatConfig.setTpsHistogramNumDecimalPoints(2);
+
+ oxmEntityLookup = new OxmEntityLookup();
+
+ esAdapter = Mockito.mock(ElasticSearchAdapter.class);
+ aaiAdapter = Mockito.mock(ActiveInventoryAdapter.class);
+
+
+ Set<OxmModelProcessor> processors = new HashSet<OxmModelProcessor>();
+
+ processors.add(oxmEntityLookup);
+
+ filtersConfig = new FiltersConfig();
+
+ FiltersDetailsConfig filtersDetailsConfig = mapper.readValue(
+ TestResourceLoader.getTestResourceDataJson("/filters/aaiui_filters_testConfig.json"),
+ FiltersDetailsConfig.class);
+ FiltersForViewsConfig filtersForViewsConfig = mapper.readValue(
+ TestResourceLoader.getTestResourceDataJson("/filters/aaiui_views_testConfig.json"),
+ FiltersForViewsConfig.class);
+
+ filtersConfig.setFiltersConfig(filtersDetailsConfig);
+ filtersConfig.setViewsConfig(filtersForViewsConfig);
+
+ Map<String, OxmEntityDescriptor> oxmEntityDescriptors =
+ new HashMap<String, OxmEntityDescriptor>();
+
+ OxmEntityDescriptor genericVnfDescriptor = new OxmEntityDescriptor();
+ genericVnfDescriptor.setEntityName("generic-vnf");
+ List<String> pkeyNames = new ArrayList<String>();
+ pkeyNames.add("vnf-name");
+
+ genericVnfDescriptor.setPrimaryKeyAttributeNames(pkeyNames);
+
+ oxmEntityDescriptors.put("generic-vnf", genericVnfDescriptor);
+
+
+ oxmEntityLookup.setEntityDescriptors(oxmEntityDescriptors);
+
+ SuggestionEntityDescriptor genericVnfSuggestionDescriptor = new SuggestionEntityDescriptor();
+ genericVnfSuggestionDescriptor.setEntityName("generic-vnf");
+ genericVnfSuggestionDescriptor.setPrimaryKeyAttributeNames(pkeyNames);
+
+
+
+ /*
+ * SuggestionSearchEntity sse = new SuggestionSearchEntity(filtersConfig);
+ *
+ * sse.setEntityType("generic-vnf"); sse.setSuggestionPropertyTypes( Arrays.asList("vnf-name"));
+ *
+ * genericVnfSuggestionDescriptor.setSuggestionSearchEntity(sse);
+ *
+ * suggestionEntityDescriptors.put("generic-vnf", genericVnfSuggestionDescriptor);
+ */
+
+ geoEntityLookup = new GeoEntityLookup();
+
+ processors.add(geoEntityLookup);
+
+ OxmModelLoader oxmModelLoader = new OxmModelLoader(-1, processors);
+ oxmModelLoader.loadLatestOxmModel();
+
+ // suggestionEntityLookup.setSuggestionSearchEntityDescriptors(suggestionEntityDescriptors);
+ }
+
+ @Test
+ public void validateBasicConstruction() throws Exception {
+
+ vnfAliasSuggestionSynchronizer = new VnfAliasSuggestionSynchronizer(esSchemaConfig, 5, 5, 5,
+ aaiStatConfig, esStatConfig, filtersConfig);
+
+ vnfAliasSuggestionSynchronizer.setAaiAdapter(aaiAdapter);
+ vnfAliasSuggestionSynchronizer.setElasticSearchAdapter(esAdapter);
+
+ assertNotNull(vnfAliasSuggestionSynchronizer.getAaiAdapter());
+ assertNotNull(vnfAliasSuggestionSynchronizer.getElasticSearchAdapter());
+
+ }
+
+ @Test
+ public void validateSmallSync() throws Exception {
+
+ vnfAliasSuggestionSynchronizer = new VnfAliasSuggestionSynchronizer(esSchemaConfig, 5, 5, 5,
+ aaiStatConfig, esStatConfig, filtersConfig);
+
+
+ vnfAliasSuggestionSynchronizer.setAaiAdapter(aaiAdapter);
+ vnfAliasSuggestionSynchronizer.setElasticSearchAdapter(esAdapter);
+
+ String nodesQueryResponse = TestResourceLoader
+ .getTestResourceDataJson("/sync/aai/activeInventory_generic-vnf_nodesQuery_response.json");
+
+ OperationResult genericVnfSelfLinks = new OperationResult();
+
+ genericVnfSelfLinks.setResultCode(200);
+ genericVnfSelfLinks.setResult(nodesQueryResponse);
+
+ Mockito.when(aaiAdapter.getSelfLinksByEntityType("generic-vnf"))
+ .thenReturn(genericVnfSelfLinks);
+
+ Mockito.when(aaiAdapter.repairSelfLink(Matchers.contains("generic-vnf-1"), Mockito.anyString()))
+ .thenReturn(
+ "https://server.proxy:8443/aai/v11/network/generic-vnfs/generic-vnf/generic-vnf-1");
+
+ Mockito.when(aaiAdapter.repairSelfLink(Matchers.contains("generic-vnf-2"), Mockito.anyString()))
+ .thenReturn(
+ "https://server.proxy:8443/aai/v11/network/generic-vnfs/generic-vnf/generic-vnf-2");
+
+ Mockito.when(aaiAdapter.repairSelfLink(Matchers.contains("generic-vnf-3"), Mockito.anyString()))
+ .thenReturn(
+ "https://server.proxy:8443/aai/v11/network/generic-vnfs/generic-vnf/generic-vnf-3");
+
+ Mockito
+ .when(aaiAdapter.queryActiveInventoryWithRetries(Matchers.contains("generic-vnf-1"),
+ Mockito.anyString(), Mockito.anyInt()))
+ .thenReturn(new OperationResult(200, TestResourceLoader
+ .getTestResourceDataJson("/sync/aai/generic-vnf-generic-vnf-1_full_depth.json")));
+
+ Mockito
+ .when(aaiAdapter.queryActiveInventoryWithRetries(Matchers.contains("generic-vnf-2"),
+ Mockito.anyString(), Mockito.anyInt()))
+ .thenReturn(new OperationResult(200, TestResourceLoader
+ .getTestResourceDataJson("/sync/aai/generic-vnf-generic-vnf-2_full_depth.json")));
+
+ Mockito
+ .when(aaiAdapter.queryActiveInventoryWithRetries(Matchers.contains("generic-vnf-3"),
+ Mockito.anyString(), Mockito.anyInt()))
+ .thenReturn(new OperationResult(200, TestResourceLoader
+ .getTestResourceDataJson("/sync/aai/generic-vnf-generic-vnf-3_full_depth.json")));
+
+ Mockito.when(esAdapter.buildElasticSearchGetDocUrl(Mockito.anyString(), Mockito.anyString()))
+ .thenReturn("http://localhost:9200/myindex/mytype/doc1",
+ "http://localhost:9200/myindex/mytype/doc2",
+ "http://localhost:9200/myindex/mytype/doc3");
+
+ /*
+ * Our initial gets from elastic search should be record-not-found
+ */
+ Mockito.when(esAdapter.doGet(Matchers.contains("doc1"), Mockito.any()))
+ .thenReturn(new OperationResult(404, null));
+ Mockito.when(esAdapter.doGet(Matchers.contains("doc2"), Mockito.any()))
+ .thenReturn(new OperationResult(404, null));
+ Mockito.when(esAdapter.doGet(Matchers.contains("doc3"), Mockito.any()))
+ .thenReturn(new OperationResult(404, null));
+
+
+ Mockito.when(esAdapter.doPut(Matchers.contains("doc"), Mockito.any(), Mockito.any()))
+ .thenReturn(new OperationResult(200, null));
+
+ OperationState syncState = vnfAliasSuggestionSynchronizer.doSync();
+ assertEquals(OperationState.OK, syncState);
+
+ assertNotNull(vnfAliasSuggestionSynchronizer.getStatReport(false));
+ assertNotNull(vnfAliasSuggestionSynchronizer.getStatReport(true));
+
+ vnfAliasSuggestionSynchronizer.clearCache();
+ vnfAliasSuggestionSynchronizer.shutdown();
+
+
+ }
+
+ @Test
+ public void validateSmallSyncWithRetries() throws Exception {
+
+ vnfAliasSuggestionSynchronizer = new VnfAliasSuggestionSynchronizer(esSchemaConfig, 5, 5, 5,
+ aaiStatConfig, esStatConfig, filtersConfig);
+
+
+ vnfAliasSuggestionSynchronizer.setAaiAdapter(aaiAdapter);
+ vnfAliasSuggestionSynchronizer.setElasticSearchAdapter(esAdapter);
+
+ String nodesQueryResponse = TestResourceLoader
+ .getTestResourceDataJson("/sync/aai/activeInventory_generic-vnf_nodesQuery_response.json");
+
+ OperationResult genericVnfSelfLinks = new OperationResult();
+
+ genericVnfSelfLinks.setResultCode(200);
+ genericVnfSelfLinks.setResult(nodesQueryResponse);
+
+ Mockito.when(aaiAdapter.getSelfLinksByEntityType("generic-vnf"))
+ .thenReturn(genericVnfSelfLinks);
+
+ Mockito.when(aaiAdapter.repairSelfLink(Matchers.contains("generic-vnf-1"), Mockito.anyString()))
+ .thenReturn(
+ "https://server.proxy:8443/aai/v11/network/generic-vnfs/generic-vnf/generic-vnf-1");
+
+ Mockito.when(aaiAdapter.repairSelfLink(Matchers.contains("generic-vnf-2"), Mockito.anyString()))
+ .thenReturn(
+ "https://server.proxy:8443/aai/v11/network/generic-vnfs/generic-vnf/generic-vnf-2");
+
+ Mockito.when(aaiAdapter.repairSelfLink(Matchers.contains("generic-vnf-3"), Mockito.anyString()))
+ .thenReturn(
+ "https://server.proxy:8443/aai/v11/network/generic-vnfs/generic-vnf/generic-vnf-3");
+
+ Mockito
+ .when(aaiAdapter.queryActiveInventoryWithRetries(Matchers.contains("generic-vnf-1"),
+ Mockito.anyString(), Mockito.anyInt()))
+ .thenReturn(new OperationResult(200, TestResourceLoader
+ .getTestResourceDataJson("/sync/aai/generic-vnf-generic-vnf-1_full_depth.json")));
+
+ Mockito
+ .when(aaiAdapter.queryActiveInventoryWithRetries(Matchers.contains("generic-vnf-2"),
+ Mockito.anyString(), Mockito.anyInt()))
+ .thenReturn(new OperationResult(200, TestResourceLoader
+ .getTestResourceDataJson("/sync/aai/generic-vnf-generic-vnf-2_full_depth.json")));
+
+ Mockito
+ .when(aaiAdapter.queryActiveInventoryWithRetries(Matchers.contains("generic-vnf-3"),
+ Mockito.anyString(), Mockito.anyInt()))
+ .thenReturn(new OperationResult(200, TestResourceLoader
+ .getTestResourceDataJson("/sync/aai/generic-vnf-generic-vnf-3_full_depth.json")));
+
+ Mockito.when(esAdapter.buildElasticSearchGetDocUrl(Mockito.anyString(), Mockito.anyString()))
+ .thenReturn("http://localhost:9200/myindex/mytype/doc1",
+ "http://localhost:9200/myindex/mytype/doc2",
+ "http://localhost:9200/myindex/mytype/doc3");
+
+ /*
+ * Our initial gets from elastic search should be record-not-found
+ */
+ Mockito.when(esAdapter.doGet(Matchers.contains("doc1"), Mockito.any()))
+ .thenReturn(new OperationResult(404, null));
+ Mockito.when(esAdapter.doGet(Matchers.contains("doc2"), Mockito.any()))
+ .thenReturn(new OperationResult(404, null));
+ Mockito.when(esAdapter.doGet(Matchers.contains("doc3"), Mockito.any()))
+ .thenReturn(new OperationResult(404, null));
+
+
+ /*
+ * Elastic Search puts always fail with a version conflict = 409
+ */
+
+ Mockito.when(esAdapter.doPut(Matchers.contains("doc"), Mockito.any(), Mockito.any()))
+ .thenReturn(new OperationResult(409, null));
+
+ OperationState syncState = vnfAliasSuggestionSynchronizer.doSync();
+ assertEquals(OperationState.OK, syncState);
+
+ assertNotNull(vnfAliasSuggestionSynchronizer.getStatReport(false));
+ assertNotNull(vnfAliasSuggestionSynchronizer.getStatReport(true));
+
+ vnfAliasSuggestionSynchronizer.clearCache();
+ vnfAliasSuggestionSynchronizer.shutdown();
+
+
+ }
+}
diff --git a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/search/EntityCountHistoryProcessorTest.java b/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/search/EntityCountHistoryProcessorTest.java
index 9629ae8..c74e4e5 100644
--- a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/search/EntityCountHistoryProcessorTest.java
+++ b/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/search/EntityCountHistoryProcessorTest.java
@@ -1,30 +1,5 @@
-/**
- * ============LICENSE_START===================================================
- * SPARKY (AAI UI service)
- * ============================================================================
- * Copyright © 2017 AT&T Intellectual Property.
- * Copyright © 2017 Amdocs
- * All rights reserved.
- * ============================================================================
- * 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=====================================================
- *
- * ECOMP and OpenECOMP are trademarks
- * and service marks of AT&T Intellectual Property.
- */
-
package org.onap.aai.sparky.search;
-/*
+
import static org.junit.Assert.assertEquals;
import org.apache.camel.Exchange;
@@ -35,6 +10,7 @@ import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Mockito;
import org.onap.aai.restclient.client.OperationResult;
+import org.onap.aai.sparky.dal.ElasticSearchAdapter;
import org.onap.aai.sparky.search.EntityCountHistoryProcessor;
import org.onap.aai.sparky.util.RestletUtils;
import org.restlet.Request;
@@ -56,6 +32,7 @@ public class EntityCountHistoryProcessorTest {
private Response mockRestletResponse;
private ClientInfo requestClientInfo;
private RestletUtils mockRestletUtils;
+ private ElasticSearchAdapter mockElasticSearchAdapter;
@Before
public void init() throws Exception {
@@ -65,8 +42,10 @@ public class EntityCountHistoryProcessorTest {
mockRestletRequest = Mockito.mock(Request.class);
mockRestletResponse = Mockito.mock(Response.class);
mockRestletUtils = Mockito.mock(RestletUtils.class);
+ mockElasticSearchAdapter = Mockito.mock(ElasticSearchAdapter.class);
- entityCountHistoryProcessor = new EntityCountHistoryProcessor();
+ entityCountHistoryProcessor = new EntityCountHistoryProcessor(mockElasticSearchAdapter,
+ "pserver", "vnf", "entityCount-index");
entityCountHistoryProcessor.setRestletUtils(mockRestletUtils);
requestClientInfo = new ClientInfo();
@@ -113,12 +92,7 @@ public class EntityCountHistoryProcessorTest {
Mockito.doReturn(operationResult).when(spyEntityCountHistoryProcessor).getResults(Mockito.any(),
Mockito.any());
- spyEntityCountHistoryProcessor.getEntityCountHistory(mockExchange);
- ArgumentCaptor<String> entityCaptor = ArgumentCaptor.forClass(String.class);
- Mockito.verify(mockRestletResponse, Mockito.atLeast(1)).setEntity(entityCaptor.capture(),
- Mockito.any());
- assertEquals(operationResult.getResult(), entityCaptor.getValue());
}
@Test
@@ -136,19 +110,9 @@ public class EntityCountHistoryProcessorTest {
Mockito.when(mockExchange.getIn().getHeader("CamelHttpQuery", String.class)).thenReturn("");
Mockito.doReturn("").when(spyEntityCountHistoryProcessor).getTypeParameter(Mockito.any());
- Mockito.doReturn(operationResult).when(spyEntityCountHistoryProcessor).getResults(Mockito.any(), Mockito.any());
-
- spyEntityCountHistoryProcessor.getEntityCountHistory(mockExchange);
-
- ArgumentCaptor<String> entityCaptor = ArgumentCaptor.forClass(String.class);
- Mockito.verify(mockRestletResponse, Mockito.atLeast(1)).setEntity(entityCaptor.capture(),
+ Mockito.doReturn(operationResult).when(spyEntityCountHistoryProcessor).getResults(Mockito.any(),
Mockito.any());
- assertEquals("{ \"errorMessage\" : Unsupported request. Resource not found. }",
- entityCaptor.getValue());
- ArgumentCaptor<Status> responseCodeCaptor = ArgumentCaptor.forClass(Status.class);
- Mockito.verify(mockRestletResponse, Mockito.atLeast(1)).setStatus(responseCodeCaptor.capture());
- assertEquals(Status.CLIENT_ERROR_NOT_FOUND, responseCodeCaptor.getValue());
+
}
}
-*/ \ No newline at end of file
diff --git a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/subscription/SubscriptionServiceProcessorTest.java b/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/subscription/SubscriptionServiceProcessorTest.java
new file mode 100644
index 0000000..71e07cb
--- /dev/null
+++ b/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/subscription/SubscriptionServiceProcessorTest.java
@@ -0,0 +1,63 @@
+package org.onap.aai.sparky.subscription;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.apache.camel.component.restlet.RestletConstants;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.onap.aai.sparky.subscription.services.SubscriptionService;
+import org.onap.aai.sparky.util.RestletUtils;
+import org.restlet.Request;
+import org.restlet.Response;
+import org.restlet.data.ClientInfo;
+
+public class SubscriptionServiceProcessorTest {
+ private SubscriptionServiceProcessor subscriptionProcessor;
+ private Exchange mockExchange;
+ private Message mockRequestMessage;
+ private Message mockResponseMessage;
+ private Request mockRestletRequest;
+ private Response mockRestletResponse;
+ private ClientInfo requestClientInfo;
+ private RestletUtils mockRestletUtils;
+ private SubscriptionService mockSubscriptionService;
+
+
+ @Before
+ public void init() throws Exception {
+
+ mockExchange = Mockito.mock(Exchange.class);
+ mockRequestMessage = Mockito.mock(Message.class);
+ mockResponseMessage = Mockito.mock(Message.class);
+ mockRestletRequest = Mockito.mock(Request.class);
+ mockRestletResponse = Mockito.mock(Response.class);
+ mockRestletUtils = Mockito.mock(RestletUtils.class);
+ mockSubscriptionService = Mockito.mock(SubscriptionService.class);
+ subscriptionProcessor = new SubscriptionServiceProcessor(mockSubscriptionService);
+
+ requestClientInfo = new ClientInfo();
+
+ Mockito.when(mockExchange.getIn()).thenReturn(mockRequestMessage);
+ Mockito.when(mockExchange.getOut()).thenReturn(mockResponseMessage);
+
+ Mockito.when(mockRequestMessage.getHeader(RestletConstants.RESTLET_REQUEST, Request.class))
+ .thenReturn(mockRestletRequest);
+
+ Mockito.when(mockRestletRequest.getClientInfo()).thenReturn(requestClientInfo);
+
+
+ Mockito.when(mockRequestMessage.getHeader(RestletConstants.RESTLET_RESPONSE, Response.class))
+ .thenReturn(mockRestletResponse);
+
+
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testGetEntityCountHistory_success() {
+
+ subscriptionProcessor.getSubscription(mockExchange);
+
+ }
+
+}
diff --git a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/topology/sync/GeoSynchronizerTest.java b/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/topology/sync/GeoSynchronizerTest.java
new file mode 100644
index 0000000..9b1e8c7
--- /dev/null
+++ b/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/topology/sync/GeoSynchronizerTest.java
@@ -0,0 +1,351 @@
+package org.onap.aai.sparky.topology.sync;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Matchers;
+import org.mockito.Mockito;
+import org.onap.aai.restclient.client.OperationResult;
+import org.onap.aai.sparky.config.oxm.GeoEntityLookup;
+import org.onap.aai.sparky.config.oxm.OxmEntityDescriptor;
+import org.onap.aai.sparky.config.oxm.OxmEntityLookup;
+import org.onap.aai.sparky.config.oxm.OxmModelLoader;
+import org.onap.aai.sparky.config.oxm.OxmModelProcessor;
+import org.onap.aai.sparky.config.oxm.SuggestionEntityDescriptor;
+import org.onap.aai.sparky.dal.ActiveInventoryAdapter;
+import org.onap.aai.sparky.dal.ElasticSearchAdapter;
+import org.onap.aai.sparky.sync.config.ElasticSearchSchemaConfig;
+import org.onap.aai.sparky.sync.config.NetworkStatisticsConfig;
+import org.onap.aai.sparky.sync.enumeration.OperationState;
+import org.onap.aai.sparky.util.TestResourceLoader;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+public class GeoSynchronizerTest {
+
+ private static ObjectMapper mapper = new ObjectMapper();
+
+ private GeoSynchronizer geoSynchronizer;
+
+ private ElasticSearchSchemaConfig esSchemaConfig;
+ private NetworkStatisticsConfig aaiStatConfig;
+ private NetworkStatisticsConfig esStatConfig;
+ private OxmEntityLookup oxmEntityLookup;
+ private GeoEntityLookup geoEntityLookup;
+ private ElasticSearchAdapter esAdapter;
+ private ActiveInventoryAdapter aaiAdapter;
+
+
+
+ @Before
+ public void init() throws Exception {
+
+ esSchemaConfig = new ElasticSearchSchemaConfig();
+ esSchemaConfig.setIndexDocType("default");
+ esSchemaConfig.setIndexMappingsFileName(null);
+ esSchemaConfig.setIndexName("aggregation-index-name");
+ esSchemaConfig.setIndexSettingsFileName(null);
+
+
+ aaiStatConfig = new NetworkStatisticsConfig();
+
+ aaiStatConfig.setNumSamplesPerThreadForRunningAverage(100);
+
+ aaiStatConfig.setBytesHistogramLabel("[Response Size In Bytes]");
+ aaiStatConfig.setBytesHistogramMaxYAxis(1000000L);
+ aaiStatConfig.setBytesHistogramNumBins(20);
+ aaiStatConfig.setBytesHistogramNumDecimalPoints(2);
+
+ aaiStatConfig.setQueueLengthHistogramLabel("[Queue Item Length]");
+ aaiStatConfig.setQueueLengthHistogramMaxYAxis(20000);
+ aaiStatConfig.setQueueLengthHistogramNumBins(20);
+ aaiStatConfig.setQueueLengthHistogramNumDecimalPoints(2);
+
+ aaiStatConfig.setTaskAgeHistogramLabel("[Task Age In Ms]");
+ aaiStatConfig.setTaskAgeHistogramMaxYAxis(600000L);
+ aaiStatConfig.setTaskAgeHistogramNumBins(20);
+ aaiStatConfig.setTaskAgeHistogramNumDecimalPoints(2);
+
+ aaiStatConfig.setResponseTimeHistogramLabel("[Response Time In Ms]");
+ aaiStatConfig.setResponseTimeHistogramMaxYAxis(1000L);
+ aaiStatConfig.setResponseTimeHistogramNumBins(20);
+ aaiStatConfig.setResponseTimeHistogramNumDecimalPoints(2);
+
+ aaiStatConfig.setTpsHistogramLabel("[Transactions Per Second]");
+ aaiStatConfig.setTpsHistogramMaxYAxis(100);
+ aaiStatConfig.setTpsHistogramNumBins(20);
+ aaiStatConfig.setTpsHistogramNumDecimalPoints(2);
+
+ esStatConfig = new NetworkStatisticsConfig();
+
+ esStatConfig.setNumSamplesPerThreadForRunningAverage(100);
+
+ esStatConfig.setBytesHistogramLabel("[Response Size In Bytes]");
+ esStatConfig.setBytesHistogramMaxYAxis(1000000L);
+ esStatConfig.setBytesHistogramNumBins(20);
+ esStatConfig.setBytesHistogramNumDecimalPoints(2);
+
+ esStatConfig.setQueueLengthHistogramLabel("[Queue Item Length]");
+ esStatConfig.setQueueLengthHistogramMaxYAxis(20000);
+ esStatConfig.setQueueLengthHistogramNumBins(20);
+ esStatConfig.setQueueLengthHistogramNumDecimalPoints(2);
+
+ esStatConfig.setTaskAgeHistogramLabel("[Task Age In Ms]");
+ esStatConfig.setTaskAgeHistogramMaxYAxis(600000L);
+ esStatConfig.setTaskAgeHistogramNumBins(20);
+ esStatConfig.setTaskAgeHistogramNumDecimalPoints(2);
+
+ esStatConfig.setResponseTimeHistogramLabel("[Response Time In Ms]");
+ esStatConfig.setResponseTimeHistogramMaxYAxis(10000L);
+ esStatConfig.setResponseTimeHistogramNumBins(20);
+ esStatConfig.setResponseTimeHistogramNumDecimalPoints(2);
+
+ esStatConfig.setTpsHistogramLabel("[Transactions Per Second]");
+ esStatConfig.setTpsHistogramMaxYAxis(100);
+ esStatConfig.setTpsHistogramNumBins(20);
+ esStatConfig.setTpsHistogramNumDecimalPoints(2);
+
+ oxmEntityLookup = new OxmEntityLookup();
+
+ esAdapter = Mockito.mock(ElasticSearchAdapter.class);
+ aaiAdapter = Mockito.mock(ActiveInventoryAdapter.class);
+
+
+ Set<OxmModelProcessor> processors = new HashSet<OxmModelProcessor>();
+
+ processors.add(oxmEntityLookup);
+
+
+
+ Map<String, OxmEntityDescriptor> oxmEntityDescriptors =
+ new HashMap<String, OxmEntityDescriptor>();
+
+ OxmEntityDescriptor genericVnfDescriptor = new OxmEntityDescriptor();
+ genericVnfDescriptor.setEntityName("generic-vnf");
+ List<String> pkeyNames = new ArrayList<String>();
+ pkeyNames.add("vnf-name");
+
+ genericVnfDescriptor.setPrimaryKeyAttributeNames(pkeyNames);
+
+ oxmEntityDescriptors.put("generic-vnf", genericVnfDescriptor);
+
+
+ oxmEntityLookup.setEntityDescriptors(oxmEntityDescriptors);
+
+ SuggestionEntityDescriptor genericVnfSuggestionDescriptor = new SuggestionEntityDescriptor();
+ genericVnfSuggestionDescriptor.setEntityName("generic-vnf");
+ genericVnfSuggestionDescriptor.setPrimaryKeyAttributeNames(pkeyNames);
+
+
+
+ /*
+ * SuggestionSearchEntity sse = new SuggestionSearchEntity(filtersConfig);
+ *
+ * sse.setEntityType("generic-vnf"); sse.setSuggestionPropertyTypes( Arrays.asList("vnf-name"));
+ *
+ * genericVnfSuggestionDescriptor.setSuggestionSearchEntity(sse);
+ *
+ * suggestionEntityDescriptors.put("generic-vnf", genericVnfSuggestionDescriptor);
+ */
+
+ geoEntityLookup = new GeoEntityLookup();
+
+ processors.add(geoEntityLookup);
+
+ OxmModelLoader oxmModelLoader = new OxmModelLoader(-1, processors);
+ oxmModelLoader.loadLatestOxmModel();
+
+ // suggestionEntityLookup.setSuggestionSearchEntityDescriptors(suggestionEntityDescriptors);
+ }
+
+ @Test
+ public void validateBasicConstruction() throws Exception {
+
+ geoSynchronizer = new GeoSynchronizer(esSchemaConfig, 5, 5, 5, aaiStatConfig, esStatConfig,
+ geoEntityLookup, oxmEntityLookup);
+
+ geoSynchronizer.setAaiAdapter(aaiAdapter);
+ geoSynchronizer.setElasticSearchAdapter(esAdapter);
+
+ assertNotNull(geoSynchronizer.getAaiAdapter());
+ assertNotNull(geoSynchronizer.getElasticSearchAdapter());
+
+ }
+
+ @Test
+ public void validateSmallSync() throws Exception {
+
+ geoSynchronizer = new GeoSynchronizer(esSchemaConfig, 5, 5, 5, aaiStatConfig, esStatConfig,
+ geoEntityLookup, oxmEntityLookup);
+
+
+ geoSynchronizer.setAaiAdapter(aaiAdapter);
+ geoSynchronizer.setElasticSearchAdapter(esAdapter);
+
+ String nodesQueryResponse = TestResourceLoader
+ .getTestResourceDataJson("/sync/aai/activeInventory_generic-vnf_nodesQuery_response.json");
+
+ OperationResult genericVnfSelfLinks = new OperationResult();
+
+ genericVnfSelfLinks.setResultCode(200);
+ genericVnfSelfLinks.setResult(nodesQueryResponse);
+
+ Mockito.when(aaiAdapter.getSelfLinksByEntityType("generic-vnf"))
+ .thenReturn(genericVnfSelfLinks);
+
+ Mockito.when(aaiAdapter.repairSelfLink(Matchers.contains("generic-vnf-1"), Mockito.anyString()))
+ .thenReturn(
+ "https://server.proxy:8443/aai/v11/network/generic-vnfs/generic-vnf/generic-vnf-1");
+
+ Mockito.when(aaiAdapter.repairSelfLink(Matchers.contains("generic-vnf-2"), Mockito.anyString()))
+ .thenReturn(
+ "https://server.proxy:8443/aai/v11/network/generic-vnfs/generic-vnf/generic-vnf-2");
+
+ Mockito.when(aaiAdapter.repairSelfLink(Matchers.contains("generic-vnf-3"), Mockito.anyString()))
+ .thenReturn(
+ "https://server.proxy:8443/aai/v11/network/generic-vnfs/generic-vnf/generic-vnf-3");
+
+ Mockito
+ .when(aaiAdapter.queryActiveInventoryWithRetries(Matchers.contains("generic-vnf-1"),
+ Mockito.anyString(), Mockito.anyInt()))
+ .thenReturn(new OperationResult(200, TestResourceLoader
+ .getTestResourceDataJson("/sync/aai/generic-vnf-generic-vnf-1_full_depth.json")));
+
+ Mockito
+ .when(aaiAdapter.queryActiveInventoryWithRetries(Matchers.contains("generic-vnf-2"),
+ Mockito.anyString(), Mockito.anyInt()))
+ .thenReturn(new OperationResult(200, TestResourceLoader
+ .getTestResourceDataJson("/sync/aai/generic-vnf-generic-vnf-2_full_depth.json")));
+
+ Mockito
+ .when(aaiAdapter.queryActiveInventoryWithRetries(Matchers.contains("generic-vnf-3"),
+ Mockito.anyString(), Mockito.anyInt()))
+ .thenReturn(new OperationResult(200, TestResourceLoader
+ .getTestResourceDataJson("/sync/aai/generic-vnf-generic-vnf-3_full_depth.json")));
+
+ Mockito.when(esAdapter.buildElasticSearchGetDocUrl(Mockito.anyString(), Mockito.anyString()))
+ .thenReturn("http://localhost:9200/myindex/mytype/doc1",
+ "http://localhost:9200/myindex/mytype/doc2",
+ "http://localhost:9200/myindex/mytype/doc3");
+
+ /*
+ * Our initial gets from elastic search should be record-not-found
+ */
+ Mockito.when(esAdapter.doGet(Matchers.contains("doc1"), Mockito.any()))
+ .thenReturn(new OperationResult(404, null));
+ Mockito.when(esAdapter.doGet(Matchers.contains("doc2"), Mockito.any()))
+ .thenReturn(new OperationResult(404, null));
+ Mockito.when(esAdapter.doGet(Matchers.contains("doc3"), Mockito.any()))
+ .thenReturn(new OperationResult(404, null));
+
+
+ Mockito.when(esAdapter.doPut(Matchers.contains("doc"), Mockito.any(), Mockito.any()))
+ .thenReturn(new OperationResult(200, null));
+
+ OperationState syncState = geoSynchronizer.doSync();
+ assertEquals(OperationState.OK, syncState);
+
+ assertNotNull(geoSynchronizer.getStatReport(false));
+ assertNotNull(geoSynchronizer.getStatReport(true));
+
+ geoSynchronizer.clearCache();
+ geoSynchronizer.shutdown();
+
+
+ }
+
+ @Test
+ public void validateSmallSyncWithRetries() throws Exception {
+
+ geoSynchronizer = new GeoSynchronizer(esSchemaConfig, 5, 5, 5, aaiStatConfig, esStatConfig,
+ geoEntityLookup, oxmEntityLookup);
+
+
+ geoSynchronizer.setAaiAdapter(aaiAdapter);
+ geoSynchronizer.setElasticSearchAdapter(esAdapter);
+
+ String nodesQueryResponse = TestResourceLoader
+ .getTestResourceDataJson("/sync/aai/activeInventory_generic-vnf_nodesQuery_response.json");
+
+ OperationResult genericVnfSelfLinks = new OperationResult();
+
+ genericVnfSelfLinks.setResultCode(200);
+ genericVnfSelfLinks.setResult(nodesQueryResponse);
+
+ Mockito.when(aaiAdapter.getSelfLinksByEntityType("generic-vnf"))
+ .thenReturn(genericVnfSelfLinks);
+
+ Mockito.when(aaiAdapter.repairSelfLink(Matchers.contains("generic-vnf-1"), Mockito.anyString()))
+ .thenReturn(
+ "https://server.proxy:8443/aai/v11/network/generic-vnfs/generic-vnf/generic-vnf-1");
+
+ Mockito.when(aaiAdapter.repairSelfLink(Matchers.contains("generic-vnf-2"), Mockito.anyString()))
+ .thenReturn(
+ "https://server.proxy:8443/aai/v11/network/generic-vnfs/generic-vnf/generic-vnf-2");
+
+ Mockito.when(aaiAdapter.repairSelfLink(Matchers.contains("generic-vnf-3"), Mockito.anyString()))
+ .thenReturn(
+ "https://server.proxy:8443/aai/v11/network/generic-vnfs/generic-vnf/generic-vnf-3");
+
+ Mockito
+ .when(aaiAdapter.queryActiveInventoryWithRetries(Matchers.contains("generic-vnf-1"),
+ Mockito.anyString(), Mockito.anyInt()))
+ .thenReturn(new OperationResult(200, TestResourceLoader
+ .getTestResourceDataJson("/sync/aai/generic-vnf-generic-vnf-1_full_depth.json")));
+
+ Mockito
+ .when(aaiAdapter.queryActiveInventoryWithRetries(Matchers.contains("generic-vnf-2"),
+ Mockito.anyString(), Mockito.anyInt()))
+ .thenReturn(new OperationResult(200, TestResourceLoader
+ .getTestResourceDataJson("/sync/aai/generic-vnf-generic-vnf-2_full_depth.json")));
+
+ Mockito
+ .when(aaiAdapter.queryActiveInventoryWithRetries(Matchers.contains("generic-vnf-3"),
+ Mockito.anyString(), Mockito.anyInt()))
+ .thenReturn(new OperationResult(200, TestResourceLoader
+ .getTestResourceDataJson("/sync/aai/generic-vnf-generic-vnf-3_full_depth.json")));
+
+ Mockito.when(esAdapter.buildElasticSearchGetDocUrl(Mockito.anyString(), Mockito.anyString()))
+ .thenReturn("http://localhost:9200/myindex/mytype/doc1",
+ "http://localhost:9200/myindex/mytype/doc2",
+ "http://localhost:9200/myindex/mytype/doc3");
+
+ /*
+ * Our initial gets from elastic search should be record-not-found
+ */
+ Mockito.when(esAdapter.doGet(Matchers.contains("doc1"), Mockito.any()))
+ .thenReturn(new OperationResult(404, null));
+ Mockito.when(esAdapter.doGet(Matchers.contains("doc2"), Mockito.any()))
+ .thenReturn(new OperationResult(404, null));
+ Mockito.when(esAdapter.doGet(Matchers.contains("doc3"), Mockito.any()))
+ .thenReturn(new OperationResult(404, null));
+
+
+ /*
+ * Elastic Search puts always fail with a version conflict = 409
+ */
+
+ Mockito.when(esAdapter.doPut(Matchers.contains("doc"), Mockito.any(), Mockito.any()))
+ .thenReturn(new OperationResult(409, null));
+
+ OperationState syncState = geoSynchronizer.doSync();
+ assertEquals(OperationState.OK, syncState);
+
+ assertNotNull(geoSynchronizer.getStatReport(false));
+ assertNotNull(geoSynchronizer.getStatReport(true));
+
+ geoSynchronizer.clearCache();
+ geoSynchronizer.shutdown();
+
+
+ }
+}
diff --git a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/viewandinspect/sync/ViewInspectEntitySynchronizerTest.java b/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/viewandinspect/sync/ViewInspectEntitySynchronizerTest.java
new file mode 100644
index 0000000..685feaf
--- /dev/null
+++ b/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/viewandinspect/sync/ViewInspectEntitySynchronizerTest.java
@@ -0,0 +1,348 @@
+package org.onap.aai.sparky.viewandinspect.sync;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Matchers;
+import org.mockito.Mockito;
+import org.onap.aai.restclient.client.OperationResult;
+import org.onap.aai.sparky.config.oxm.OxmEntityDescriptor;
+import org.onap.aai.sparky.config.oxm.OxmEntityLookup;
+import org.onap.aai.sparky.config.oxm.OxmModelLoader;
+import org.onap.aai.sparky.config.oxm.OxmModelProcessor;
+import org.onap.aai.sparky.config.oxm.SearchableEntityLookup;
+import org.onap.aai.sparky.config.oxm.SuggestionEntityDescriptor;
+import org.onap.aai.sparky.dal.ActiveInventoryAdapter;
+import org.onap.aai.sparky.dal.ElasticSearchAdapter;
+import org.onap.aai.sparky.sync.config.ElasticSearchSchemaConfig;
+import org.onap.aai.sparky.sync.config.NetworkStatisticsConfig;
+import org.onap.aai.sparky.sync.enumeration.OperationState;
+import org.onap.aai.sparky.util.TestResourceLoader;
+import org.onap.aai.sparky.viewinspect.sync.ViewInspectEntitySynchronizer;
+
+public class ViewInspectEntitySynchronizerTest {
+
+ private ViewInspectEntitySynchronizer viewInspectSynchronizer;
+
+ private ElasticSearchSchemaConfig esSchemaConfig;
+ private NetworkStatisticsConfig aaiStatConfig;
+ private NetworkStatisticsConfig esStatConfig;
+ private OxmEntityLookup oxmEntityLookup;
+ private SearchableEntityLookup searchableEntityLookup;
+ private ElasticSearchAdapter esAdapter;
+ private ActiveInventoryAdapter aaiAdapter;
+
+
+
+ @Before
+ public void init() throws Exception {
+
+ esSchemaConfig = new ElasticSearchSchemaConfig();
+ esSchemaConfig.setIndexDocType("default");
+ esSchemaConfig.setIndexMappingsFileName(null);
+ esSchemaConfig.setIndexName("aggregation-index-name");
+ esSchemaConfig.setIndexSettingsFileName(null);
+
+
+ aaiStatConfig = new NetworkStatisticsConfig();
+
+ aaiStatConfig.setNumSamplesPerThreadForRunningAverage(100);
+
+ aaiStatConfig.setBytesHistogramLabel("[Response Size In Bytes]");
+ aaiStatConfig.setBytesHistogramMaxYAxis(1000000L);
+ aaiStatConfig.setBytesHistogramNumBins(20);
+ aaiStatConfig.setBytesHistogramNumDecimalPoints(2);
+
+ aaiStatConfig.setQueueLengthHistogramLabel("[Queue Item Length]");
+ aaiStatConfig.setQueueLengthHistogramMaxYAxis(20000);
+ aaiStatConfig.setQueueLengthHistogramNumBins(20);
+ aaiStatConfig.setQueueLengthHistogramNumDecimalPoints(2);
+
+ aaiStatConfig.setTaskAgeHistogramLabel("[Task Age In Ms]");
+ aaiStatConfig.setTaskAgeHistogramMaxYAxis(600000L);
+ aaiStatConfig.setTaskAgeHistogramNumBins(20);
+ aaiStatConfig.setTaskAgeHistogramNumDecimalPoints(2);
+
+ aaiStatConfig.setResponseTimeHistogramLabel("[Response Time In Ms]");
+ aaiStatConfig.setResponseTimeHistogramMaxYAxis(1000L);
+ aaiStatConfig.setResponseTimeHistogramNumBins(20);
+ aaiStatConfig.setResponseTimeHistogramNumDecimalPoints(2);
+
+ aaiStatConfig.setTpsHistogramLabel("[Transactions Per Second]");
+ aaiStatConfig.setTpsHistogramMaxYAxis(100);
+ aaiStatConfig.setTpsHistogramNumBins(20);
+ aaiStatConfig.setTpsHistogramNumDecimalPoints(2);
+
+ esStatConfig = new NetworkStatisticsConfig();
+
+ esStatConfig.setNumSamplesPerThreadForRunningAverage(100);
+
+ esStatConfig.setBytesHistogramLabel("[Response Size In Bytes]");
+ esStatConfig.setBytesHistogramMaxYAxis(1000000L);
+ esStatConfig.setBytesHistogramNumBins(20);
+ esStatConfig.setBytesHistogramNumDecimalPoints(2);
+
+ esStatConfig.setQueueLengthHistogramLabel("[Queue Item Length]");
+ esStatConfig.setQueueLengthHistogramMaxYAxis(20000);
+ esStatConfig.setQueueLengthHistogramNumBins(20);
+ esStatConfig.setQueueLengthHistogramNumDecimalPoints(2);
+
+ esStatConfig.setTaskAgeHistogramLabel("[Task Age In Ms]");
+ esStatConfig.setTaskAgeHistogramMaxYAxis(600000L);
+ esStatConfig.setTaskAgeHistogramNumBins(20);
+ esStatConfig.setTaskAgeHistogramNumDecimalPoints(2);
+
+ esStatConfig.setResponseTimeHistogramLabel("[Response Time In Ms]");
+ esStatConfig.setResponseTimeHistogramMaxYAxis(10000L);
+ esStatConfig.setResponseTimeHistogramNumBins(20);
+ esStatConfig.setResponseTimeHistogramNumDecimalPoints(2);
+
+ esStatConfig.setTpsHistogramLabel("[Transactions Per Second]");
+ esStatConfig.setTpsHistogramMaxYAxis(100);
+ esStatConfig.setTpsHistogramNumBins(20);
+ esStatConfig.setTpsHistogramNumDecimalPoints(2);
+
+ oxmEntityLookup = new OxmEntityLookup();
+
+ esAdapter = Mockito.mock(ElasticSearchAdapter.class);
+ aaiAdapter = Mockito.mock(ActiveInventoryAdapter.class);
+
+
+ Set<OxmModelProcessor> processors = new HashSet<OxmModelProcessor>();
+
+ processors.add(oxmEntityLookup);
+
+
+
+ Map<String, OxmEntityDescriptor> oxmEntityDescriptors =
+ new HashMap<String, OxmEntityDescriptor>();
+
+ OxmEntityDescriptor genericVnfDescriptor = new OxmEntityDescriptor();
+ genericVnfDescriptor.setEntityName("generic-vnf");
+ List<String> pkeyNames = new ArrayList<String>();
+ pkeyNames.add("vnf-name");
+
+ genericVnfDescriptor.setPrimaryKeyAttributeNames(pkeyNames);
+
+ oxmEntityDescriptors.put("generic-vnf", genericVnfDescriptor);
+
+
+ oxmEntityLookup.setEntityDescriptors(oxmEntityDescriptors);
+
+ SuggestionEntityDescriptor genericVnfSuggestionDescriptor = new SuggestionEntityDescriptor();
+ genericVnfSuggestionDescriptor.setEntityName("generic-vnf");
+ genericVnfSuggestionDescriptor.setPrimaryKeyAttributeNames(pkeyNames);
+
+
+
+ /*
+ * SuggestionSearchEntity sse = new SuggestionSearchEntity(filtersConfig);
+ *
+ * sse.setEntityType("generic-vnf"); sse.setSuggestionPropertyTypes( Arrays.asList("vnf-name"));
+ *
+ * genericVnfSuggestionDescriptor.setSuggestionSearchEntity(sse);
+ *
+ * suggestionEntityDescriptors.put("generic-vnf", genericVnfSuggestionDescriptor);
+ */
+
+ searchableEntityLookup = new SearchableEntityLookup();
+
+ processors.add(searchableEntityLookup);
+
+ OxmModelLoader oxmModelLoader = new OxmModelLoader(-1, processors);
+ oxmModelLoader.loadLatestOxmModel();
+
+ // suggestionEntityLookup.setSuggestionSearchEntityDescriptors(suggestionEntityDescriptors);
+ }
+
+ @Test
+ public void validateBasicConstruction() throws Exception {
+
+ viewInspectSynchronizer = new ViewInspectEntitySynchronizer(esSchemaConfig, 5, 5, 5,
+ aaiStatConfig, esStatConfig, oxmEntityLookup, searchableEntityLookup);
+
+ viewInspectSynchronizer.setAaiAdapter(aaiAdapter);
+ viewInspectSynchronizer.setElasticSearchAdapter(esAdapter);
+
+ assertNotNull(viewInspectSynchronizer.getAaiAdapter());
+ assertNotNull(viewInspectSynchronizer.getElasticSearchAdapter());
+
+ }
+
+ @Test
+ public void validateSmallSync() throws Exception {
+
+ viewInspectSynchronizer = new ViewInspectEntitySynchronizer(esSchemaConfig, 5, 5, 5,
+ aaiStatConfig, esStatConfig, oxmEntityLookup, searchableEntityLookup);
+
+
+ viewInspectSynchronizer.setAaiAdapter(aaiAdapter);
+ viewInspectSynchronizer.setElasticSearchAdapter(esAdapter);
+
+ String nodesQueryResponse = TestResourceLoader
+ .getTestResourceDataJson("/sync/aai/activeInventory_generic-vnf_nodesQuery_response.json");
+
+ OperationResult genericVnfSelfLinks = new OperationResult();
+
+ genericVnfSelfLinks.setResultCode(200);
+ genericVnfSelfLinks.setResult(nodesQueryResponse);
+
+ Mockito.when(aaiAdapter.getSelfLinksByEntityType("generic-vnf"))
+ .thenReturn(genericVnfSelfLinks);
+
+ Mockito.when(aaiAdapter.repairSelfLink(Matchers.contains("generic-vnf-1"), Mockito.anyString()))
+ .thenReturn(
+ "https://server.proxy:8443/aai/v11/network/generic-vnfs/generic-vnf/generic-vnf-1");
+
+ Mockito.when(aaiAdapter.repairSelfLink(Matchers.contains("generic-vnf-2"), Mockito.anyString()))
+ .thenReturn(
+ "https://server.proxy:8443/aai/v11/network/generic-vnfs/generic-vnf/generic-vnf-2");
+
+ Mockito.when(aaiAdapter.repairSelfLink(Matchers.contains("generic-vnf-3"), Mockito.anyString()))
+ .thenReturn(
+ "https://server.proxy:8443/aai/v11/network/generic-vnfs/generic-vnf/generic-vnf-3");
+
+ Mockito
+ .when(aaiAdapter.queryActiveInventoryWithRetries(Matchers.contains("generic-vnf-1"),
+ Mockito.anyString(), Mockito.anyInt()))
+ .thenReturn(new OperationResult(200, TestResourceLoader
+ .getTestResourceDataJson("/sync/aai/generic-vnf-generic-vnf-1_full_depth.json")));
+
+ Mockito
+ .when(aaiAdapter.queryActiveInventoryWithRetries(Matchers.contains("generic-vnf-2"),
+ Mockito.anyString(), Mockito.anyInt()))
+ .thenReturn(new OperationResult(200, TestResourceLoader
+ .getTestResourceDataJson("/sync/aai/generic-vnf-generic-vnf-2_full_depth.json")));
+
+ Mockito
+ .when(aaiAdapter.queryActiveInventoryWithRetries(Matchers.contains("generic-vnf-3"),
+ Mockito.anyString(), Mockito.anyInt()))
+ .thenReturn(new OperationResult(200, TestResourceLoader
+ .getTestResourceDataJson("/sync/aai/generic-vnf-generic-vnf-3_full_depth.json")));
+
+ Mockito.when(esAdapter.buildElasticSearchGetDocUrl(Mockito.anyString(), Mockito.anyString()))
+ .thenReturn("http://localhost:9200/myindex/mytype/doc1",
+ "http://localhost:9200/myindex/mytype/doc2",
+ "http://localhost:9200/myindex/mytype/doc3");
+
+ /*
+ * Our initial gets from elastic search should be record-not-found
+ */
+ Mockito.when(esAdapter.doGet(Matchers.contains("doc1"), Mockito.any()))
+ .thenReturn(new OperationResult(404, null));
+ Mockito.when(esAdapter.doGet(Matchers.contains("doc2"), Mockito.any()))
+ .thenReturn(new OperationResult(404, null));
+ Mockito.when(esAdapter.doGet(Matchers.contains("doc3"), Mockito.any()))
+ .thenReturn(new OperationResult(404, null));
+
+
+ Mockito.when(esAdapter.doPut(Matchers.contains("doc"), Mockito.any(), Mockito.any()))
+ .thenReturn(new OperationResult(200, null));
+
+ OperationState syncState = viewInspectSynchronizer.doSync();
+ assertEquals(OperationState.OK, syncState);
+
+ assertNotNull(viewInspectSynchronizer.getStatReport(false));
+ assertNotNull(viewInspectSynchronizer.getStatReport(true));
+
+ viewInspectSynchronizer.clearCache();
+ viewInspectSynchronizer.shutdown();
+
+
+ }
+
+ @Test
+ public void validateSmallSyncWithRetries() throws Exception {
+
+ viewInspectSynchronizer = new ViewInspectEntitySynchronizer(esSchemaConfig, 5, 5, 5,
+ aaiStatConfig, esStatConfig, oxmEntityLookup, searchableEntityLookup);
+
+
+ viewInspectSynchronizer.setAaiAdapter(aaiAdapter);
+ viewInspectSynchronizer.setElasticSearchAdapter(esAdapter);
+
+ String nodesQueryResponse = TestResourceLoader
+ .getTestResourceDataJson("/sync/aai/activeInventory_generic-vnf_nodesQuery_response.json");
+
+ OperationResult genericVnfSelfLinks = new OperationResult();
+
+ genericVnfSelfLinks.setResultCode(200);
+ genericVnfSelfLinks.setResult(nodesQueryResponse);
+
+ Mockito.when(aaiAdapter.getSelfLinksByEntityType("generic-vnf"))
+ .thenReturn(genericVnfSelfLinks);
+
+ Mockito.when(aaiAdapter.repairSelfLink(Matchers.contains("generic-vnf-1"), Mockito.anyString()))
+ .thenReturn(
+ "https://server.proxy:8443/aai/v11/network/generic-vnfs/generic-vnf/generic-vnf-1");
+
+ Mockito.when(aaiAdapter.repairSelfLink(Matchers.contains("generic-vnf-2"), Mockito.anyString()))
+ .thenReturn(
+ "https://server.proxy:8443/aai/v11/network/generic-vnfs/generic-vnf/generic-vnf-2");
+
+ Mockito.when(aaiAdapter.repairSelfLink(Matchers.contains("generic-vnf-3"), Mockito.anyString()))
+ .thenReturn(
+ "https://server.proxy:8443/aai/v11/network/generic-vnfs/generic-vnf/generic-vnf-3");
+
+ Mockito
+ .when(aaiAdapter.queryActiveInventoryWithRetries(Matchers.contains("generic-vnf-1"),
+ Mockito.anyString(), Mockito.anyInt()))
+ .thenReturn(new OperationResult(200, TestResourceLoader
+ .getTestResourceDataJson("/sync/aai/generic-vnf-generic-vnf-1_full_depth.json")));
+
+ Mockito
+ .when(aaiAdapter.queryActiveInventoryWithRetries(Matchers.contains("generic-vnf-2"),
+ Mockito.anyString(), Mockito.anyInt()))
+ .thenReturn(new OperationResult(200, TestResourceLoader
+ .getTestResourceDataJson("/sync/aai/generic-vnf-generic-vnf-2_full_depth.json")));
+
+ Mockito
+ .when(aaiAdapter.queryActiveInventoryWithRetries(Matchers.contains("generic-vnf-3"),
+ Mockito.anyString(), Mockito.anyInt()))
+ .thenReturn(new OperationResult(200, TestResourceLoader
+ .getTestResourceDataJson("/sync/aai/generic-vnf-generic-vnf-3_full_depth.json")));
+
+ Mockito.when(esAdapter.buildElasticSearchGetDocUrl(Mockito.anyString(), Mockito.anyString()))
+ .thenReturn("http://localhost:9200/myindex/mytype/doc1",
+ "http://localhost:9200/myindex/mytype/doc2",
+ "http://localhost:9200/myindex/mytype/doc3");
+
+ /*
+ * Our initial gets from elastic search should be record-not-found
+ */
+ Mockito.when(esAdapter.doGet(Matchers.contains("doc1"), Mockito.any()))
+ .thenReturn(new OperationResult(404, null));
+ Mockito.when(esAdapter.doGet(Matchers.contains("doc2"), Mockito.any()))
+ .thenReturn(new OperationResult(404, null));
+ Mockito.when(esAdapter.doGet(Matchers.contains("doc3"), Mockito.any()))
+ .thenReturn(new OperationResult(404, null));
+
+
+ /*
+ * Elastic Search puts always fail with a version conflict = 409
+ */
+
+ Mockito.when(esAdapter.doPut(Matchers.contains("doc"), Mockito.any(), Mockito.any()))
+ .thenReturn(new OperationResult(409, null));
+
+ OperationState syncState = viewInspectSynchronizer.doSync();
+ assertEquals(OperationState.OK, syncState);
+
+ assertNotNull(viewInspectSynchronizer.getStatReport(false));
+ assertNotNull(viewInspectSynchronizer.getStatReport(true));
+
+ viewInspectSynchronizer.clearCache();
+ viewInspectSynchronizer.shutdown();
+
+
+ }
+}