diff options
author | 2018-02-07 15:41:52 -0500 | |
---|---|---|
committer | 2018-02-07 17:35:50 -0500 | |
commit | 8b644f1f0f654f00dcb486abffc05c6a73065aaf (patch) | |
tree | 569666b604cad56dc64c31419f54c14d9a08f2af /src/test/java/org | |
parent | a23ea1abfc73e3baca3bbf982de1caffbb2f94cf (diff) |
Adding more sparky junit coverage
Issue-ID: AAI-741
Change-Id: Id4137e7ef61e0066a39d98bcd8b9c0ec5b034d1e
Signed-off-by: dave.adams (da490c) <dave.adams@amdocs.com>
Diffstat (limited to 'src/test/java/org')
4 files changed, 1734 insertions, 0 deletions
diff --git a/src/test/java/org/onap/aai/sparky/autosuggestion/sync/AutosuggestionSynchronizerTest.java b/src/test/java/org/onap/aai/sparky/autosuggestion/sync/AutosuggestionSynchronizerTest.java new file mode 100644 index 0000000..038fe4b --- /dev/null +++ b/src/test/java/org/onap/aai/sparky/autosuggestion/sync/AutosuggestionSynchronizerTest.java @@ -0,0 +1,387 @@ +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.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.config.oxm.SuggestionEntityLookup; +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 AutosuggestionSynchronizerTest { + + private static ObjectMapper mapper = new ObjectMapper(); + + private AutosuggestionSynchronizer suggestionSynchronizer; + + private ElasticSearchSchemaConfig esSchemaConfig; + private NetworkStatisticsConfig aaiStatConfig; + private NetworkStatisticsConfig esStatConfig; + private OxmEntityLookup oxmEntityLookup; + private SuggestionEntityLookup suggestionEntityLookup; + 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); + + + + 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); + + + Map<String, SuggestionEntityDescriptor> suggestionEntityDescriptors = + new HashMap<String, SuggestionEntityDescriptor>(); + + SuggestionEntityDescriptor genericVnfSuggestionDescriptor = new SuggestionEntityDescriptor(); + genericVnfSuggestionDescriptor.setEntityName("generic-vnf"); + genericVnfSuggestionDescriptor.setPrimaryKeyAttributeNames(pkeyNames); + + filtersConfig = new FiltersConfig(null, null); + + 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); + + /* + * SuggestionSearchEntity sse = new SuggestionSearchEntity(filtersConfig); + * + * sse.setEntityType("generic-vnf"); sse.setSuggestionPropertyTypes( Arrays.asList("vnf-name")); + * + * genericVnfSuggestionDescriptor.setSuggestionSearchEntity(sse); + * + * suggestionEntityDescriptors.put("generic-vnf", genericVnfSuggestionDescriptor); + */ + + suggestionEntityLookup = new SuggestionEntityLookup(filtersConfig); + + processors.add(suggestionEntityLookup); + + OxmModelLoader oxmModelLoader = new OxmModelLoader(-1, processors); + oxmModelLoader.loadLatestOxmModel(); + + // suggestionEntityLookup.setSuggestionSearchEntityDescriptors(suggestionEntityDescriptors); + } + + @Test + public void validateBasicConstruction() throws Exception { + + suggestionSynchronizer = new AutosuggestionSynchronizer(esSchemaConfig, 5, 5, 5, aaiStatConfig, + esStatConfig, oxmEntityLookup, suggestionEntityLookup, filtersConfig); + + suggestionSynchronizer.setAaiAdapter(aaiAdapter); + suggestionSynchronizer.setElasticSearchAdapter(esAdapter); + + assertNotNull(suggestionSynchronizer.getAaiAdapter()); + assertNotNull(suggestionSynchronizer.getElasticSearchAdapter()); + + } + + @Test + public void validateSmallSync() throws Exception { + + suggestionSynchronizer = new AutosuggestionSynchronizer(esSchemaConfig, 5, 5, 5, aaiStatConfig, + esStatConfig, oxmEntityLookup, suggestionEntityLookup, filtersConfig); + + + suggestionSynchronizer.setAaiAdapter(aaiAdapter); + suggestionSynchronizer.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 = suggestionSynchronizer.doSync(); + assertEquals(OperationState.OK, syncState); + + assertNotNull(suggestionSynchronizer.getStatReport(false)); + assertNotNull(suggestionSynchronizer.getStatReport(true)); + + suggestionSynchronizer.clearCache(); + suggestionSynchronizer.shutdown(); + + + } + + @Test + public void validateSmallSyncWithRetries() throws Exception { + + suggestionSynchronizer = new AutosuggestionSynchronizer(esSchemaConfig, 5, 5, 5, aaiStatConfig, + esStatConfig, oxmEntityLookup, suggestionEntityLookup, filtersConfig); + + + suggestionSynchronizer.setAaiAdapter(aaiAdapter); + suggestionSynchronizer.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 = suggestionSynchronizer.doSync(); + assertEquals(OperationState.OK, syncState); + + assertNotNull(suggestionSynchronizer.getStatReport(false)); + assertNotNull(suggestionSynchronizer.getStatReport(true)); + + suggestionSynchronizer.clearCache(); + suggestionSynchronizer.shutdown(); + + + } +} diff --git a/src/test/java/org/onap/aai/sparky/crossentityreference/sync/CrossEntityReferenceSynchronizerTest.java b/src/test/java/org/onap/aai/sparky/crossentityreference/sync/CrossEntityReferenceSynchronizerTest.java new file mode 100644 index 0000000..c6c999a --- /dev/null +++ b/src/test/java/org/onap/aai/sparky/crossentityreference/sync/CrossEntityReferenceSynchronizerTest.java @@ -0,0 +1,1035 @@ +package org.onap.aai.sparky.crossentityreference.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.hamcrest.Matcher; +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.CrossEntityReferenceLookup; +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.dal.ActiveInventoryAdapter; +import org.onap.aai.sparky.dal.ElasticSearchAdapter; +import org.onap.aai.sparky.dal.rest.config.RestEndpointConfig; +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.StringCollectionContainsMatcher; +import org.onap.aai.sparky.util.TestResourceLoader; + +import com.fasterxml.jackson.databind.ObjectMapper; + +public class CrossEntityReferenceSynchronizerTest { + + private static ObjectMapper mapper = new ObjectMapper(); + + private CrossEntityReferenceSynchronizer cerSynchronizer; + + private ElasticSearchSchemaConfig esSchemaConfig; + private NetworkStatisticsConfig aaiStatConfig; + private NetworkStatisticsConfig esStatConfig; + private OxmEntityLookup oxmEntityLookup; + private SearchableEntityLookup searchableEntityLookup; + private ElasticSearchAdapter esAdapter; + private ActiveInventoryAdapter aaiAdapter; + private CrossEntityReferenceLookup cerLookup; + private RestEndpointConfig aaiRestEndPointConfig; + + @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); + + cerLookup = new CrossEntityReferenceLookup(); + processors.add(cerLookup); + + searchableEntityLookup = new SearchableEntityLookup(); + processors.add(searchableEntityLookup); + + OxmModelLoader oxmModelLoader = new OxmModelLoader(-1, processors); + oxmModelLoader.loadLatestOxmModel(); + + aaiRestEndPointConfig = new RestEndpointConfig(); + aaiRestEndPointConfig.setNumRequestRetries(5); + + Mockito.when(aaiAdapter.getEndpointConfig()).thenReturn(aaiRestEndPointConfig); + + } + + @Test + public void validateBasicConstruction() throws Exception { + + cerSynchronizer = new CrossEntityReferenceSynchronizer(esSchemaConfig, 5, 5, 5, aaiStatConfig, + esStatConfig, cerLookup, oxmEntityLookup, searchableEntityLookup); + + cerSynchronizer.setAaiAdapter(aaiAdapter); + cerSynchronizer.setElasticSearchAdapter(esAdapter); + + assertNotNull(cerSynchronizer.getAaiAdapter()); + assertNotNull(cerSynchronizer.getElasticSearchAdapter()); + + } + + private Matcher<List<String>> listContainsValue(String expectedValue) { + return new StringCollectionContainsMatcher(expectedValue); + } + + @Test + public void validateSmallSync() throws Exception { + + cerSynchronizer = new CrossEntityReferenceSynchronizer(esSchemaConfig, 5, 5, 5, aaiStatConfig, + esStatConfig, cerLookup, oxmEntityLookup, searchableEntityLookup); + + cerSynchronizer.setAaiAdapter(aaiAdapter); + cerSynchronizer.setElasticSearchAdapter(esAdapter); + + String nodesQueryResponse = TestResourceLoader + .getTestResourceDataJson("/sync/aai/activeInventory_service-subscription_nodesQuery_response.json"); + + OperationResult entitySelfLinks = new OperationResult(); + + entitySelfLinks.setResultCode(200); + entitySelfLinks.setResult(nodesQueryResponse); + + Mockito.when(aaiAdapter.getSelfLinksByEntityType("service-subscription")) + .thenReturn(entitySelfLinks); + + Mockito + .when(aaiAdapter.repairSelfLink(Matchers.contains("service-subscription-1"), + Mockito.anyString())) + .thenReturn( + "https://server.proxy:8443/aai/v11/business/customers/customer/customer-1/service-subscriptions/service-subscription/service-subscription-1"); + + Mockito + .when(aaiAdapter.repairSelfLink(Matchers.contains("service-subscription-2"), + Mockito.anyString())) + .thenReturn( + "https://server.proxy:8443/aai/v11/business/customers/customer/customer-2/service-subscriptions/service-subscription/service-subscription-2"); + + Mockito + .when( + aaiAdapter.repairSelfLink(Matchers.contains("service-subscription-3"), Mockito.anyString())) + .thenReturn( + "https://server.proxy:8443/aai/v11/business/customers/customer/customer-3/service-subscriptions/service-subscription/service-subscription-3"); + + Mockito + .when(aaiAdapter.queryActiveInventoryWithRetries( + Matchers.contains("service-subscription-2"), Mockito.anyString(), + Mockito.anyInt())) + .thenReturn(new OperationResult(200, TestResourceLoader.getTestResourceDataJson( + "/sync/aai/service-subscription-service-subscription-2.json"))); + + Mockito + .when(aaiAdapter.queryActiveInventoryWithRetries( + Matchers.contains("service-subscription-1"), Mockito.anyString(), + Mockito.anyInt())) + .thenReturn(new OperationResult(200, TestResourceLoader.getTestResourceDataJson( + "/sync/aai/service-subscription-service-subscription-1.json"))); + + Mockito + .when(aaiAdapter.queryActiveInventoryWithRetries(Matchers.contains("service-subscription-3"), + Mockito.anyString(), Mockito.anyInt())) + .thenReturn(new OperationResult(200, TestResourceLoader + .getTestResourceDataJson("/sync/aai/service-subscription-service-subscription-3.json"))); + + Mockito + .when(aaiAdapter.getGenericQueryForSelfLink(Matchers.contains("service-instance"), + Matchers.argThat(listContainsValue("service-instance-59")))) + .thenReturn("https://server.proxy:8443/aai/v11/search/generic-query/service-instance-59"); + + Mockito + .when(aaiAdapter.getGenericQueryForSelfLink(Matchers.contains("service-instance"), + Matchers.argThat(listContainsValue("service-instance-54")))) + .thenReturn( + "https://server.proxy:8443/aai/v11/search/generic-query/service-instance-54"); + + Mockito + .when(aaiAdapter.getGenericQueryForSelfLink(Matchers.contains("service-instance"), + Matchers.argThat(listContainsValue("service-instance-55")))) + .thenReturn( + "https://server.proxy:8443/aai/v11/search/generic-query/service-instance-55"); + + Mockito + .when(aaiAdapter.getGenericQueryForSelfLink(Matchers.contains("service-instance"), + Matchers.argThat(listContainsValue("service-instance-50")))) + .thenReturn( + "https://server.proxy:8443/aai/v11/search/generic-query/service-instance-50"); + + Mockito + .when(aaiAdapter.getGenericQueryForSelfLink(Matchers.contains("service-instance"), + Matchers.argThat(listContainsValue("service-instance-52")))) + .thenReturn( + "https://server.proxy:8443/aai/v11/search/generic-query/service-instance-52"); + + Mockito + .when(aaiAdapter.getGenericQueryForSelfLink(Matchers.contains("service-instance"), + Matchers.argThat(listContainsValue("service-instance-57")))) + .thenReturn( + "https://server.proxy:8443/aai/v11/search/generic-query/service-instance-57"); + + Mockito + .when(aaiAdapter.getGenericQueryForSelfLink(Matchers.contains("service-instance"), + Matchers.argThat(listContainsValue("service-instance-53")))) + .thenReturn( + "https://server.proxy:8443/aai/v11/search/generic-query/service-instance-53"); + + Mockito + .when(aaiAdapter.getGenericQueryForSelfLink(Matchers.contains("service-instance"), + Matchers.argThat(listContainsValue("service-instance-58")))) + .thenReturn( + "https://server.proxy:8443/aai/v11/search/generic-query/service-instance-58"); + + Mockito + .when(aaiAdapter.getGenericQueryForSelfLink(Matchers.contains("service-instance"), + Matchers.argThat(listContainsValue("service-instance-51")))) + .thenReturn( + "https://server.proxy:8443/aai/v11/search/generic-query/service-instance-51"); + + Mockito + .when(aaiAdapter.getGenericQueryForSelfLink(Matchers.contains("service-instance"), + Matchers.argThat(listContainsValue("service-instance-56")))) + .thenReturn( + "https://server.proxy:8443/aai/v11/search/generic-query/service-instance-56"); + + + + + Mockito + .when(aaiAdapter.queryActiveInventoryWithRetries( + Matchers.contains("generic-query/service-instance-59"), Mockito.anyString(), + Mockito.anyInt())) + .thenReturn(new OperationResult(200, TestResourceLoader.getTestResourceDataJson( + "/sync/aai/aai-traversal/generic-query/service-instance-59.json"))); + + Mockito + .when(aaiAdapter.queryActiveInventoryWithRetries( + Matchers.contains("generic-query/service-instance-54"), Mockito.anyString(), + Mockito.anyInt())) + .thenReturn(new OperationResult(200, TestResourceLoader.getTestResourceDataJson( + "/sync/aai/aai-traversal/generic-query/service-instance-54.json"))); + + Mockito + .when(aaiAdapter.queryActiveInventoryWithRetries( + Matchers.contains("generic-query/service-instance-55"), Mockito.anyString(), + Mockito.anyInt())) + .thenReturn(new OperationResult(200, TestResourceLoader.getTestResourceDataJson( + "/sync/aai/aai-traversal/generic-query/service-instance-55.json"))); + + Mockito + .when(aaiAdapter.queryActiveInventoryWithRetries( + Matchers.contains("generic-query/service-instance-50"), Mockito.anyString(), + Mockito.anyInt())) + .thenReturn(new OperationResult(200, TestResourceLoader.getTestResourceDataJson( + "/sync/aai/aai-traversal/generic-query/service-instance-50.json"))); + + Mockito + .when(aaiAdapter.queryActiveInventoryWithRetries( + Matchers.contains("generic-query/service-instance-52"), Mockito.anyString(), + Mockito.anyInt())) + .thenReturn(new OperationResult(200, TestResourceLoader.getTestResourceDataJson( + "/sync/aai/aai-traversal/generic-query/service-instance-52.json"))); + + Mockito + .when(aaiAdapter.queryActiveInventoryWithRetries( + Matchers.contains("generic-query/service-instance-57"), Mockito.anyString(), + Mockito.anyInt())) + .thenReturn(new OperationResult(200, TestResourceLoader.getTestResourceDataJson( + "/sync/aai/aai-traversal/generic-query/service-instance-57.json"))); + + Mockito + .when(aaiAdapter.queryActiveInventoryWithRetries( + Matchers.contains("generic-query/service-instance-53"), Mockito.anyString(), + Mockito.anyInt())) + .thenReturn(new OperationResult(200, TestResourceLoader.getTestResourceDataJson( + "/sync/aai/aai-traversal/generic-query/service-instance-53.json"))); + + Mockito + .when(aaiAdapter.queryActiveInventoryWithRetries( + Matchers.contains("generic-query/service-instance-58"), Mockito.anyString(), + Mockito.anyInt())) + .thenReturn(new OperationResult(200, TestResourceLoader.getTestResourceDataJson( + "/sync/aai/aai-traversal/generic-query/service-instance-58.json"))); + + Mockito + .when(aaiAdapter.queryActiveInventoryWithRetries( + Matchers.contains("generic-query/service-instance-51"), Mockito.anyString(), + Mockito.anyInt())) + .thenReturn(new OperationResult(200, TestResourceLoader.getTestResourceDataJson( + "/sync/aai/aai-traversal/generic-query/service-instance-51.json"))); + + Mockito + .when(aaiAdapter.queryActiveInventoryWithRetries( + Matchers.contains("generic-query/service-instance-56"), Mockito.anyString(), + Mockito.anyInt())) + .thenReturn(new OperationResult(200, TestResourceLoader.getTestResourceDataJson( + "/sync/aai/aai-traversal/generic-query/service-instance-56.json"))); + + + + + + + /* + + Mockito + .when(aaiAdapter.queryActiveInventoryWithRetries( + Matchers.contains("service-instance-59"), Mockito.anyString(), + Mockito.anyInt())) + .thenReturn(new OperationResult(200, TestResourceLoader.getTestResourceDataJson( + "/sync/aai/aai-resources/service-instance/service-instance-59.json"))); + + Mockito + .when(aaiAdapter.queryActiveInventoryWithRetries( + Matchers.contains("service-instance-54"), Mockito.anyString(), + Mockito.anyInt())) + .thenReturn(new OperationResult(200, TestResourceLoader.getTestResourceDataJson( + "/sync/aai/aai-resources/service-instance/service-instance-54.json"))); + + Mockito + .when(aaiAdapter.queryActiveInventoryWithRetries( + Matchers.contains("service-instance-55"), Mockito.anyString(), + Mockito.anyInt())) + .thenReturn(new OperationResult(200, TestResourceLoader.getTestResourceDataJson( + "/sync/aai/aai-resources/service-instance/service-instance-55.json"))); + + Mockito + .when(aaiAdapter.queryActiveInventoryWithRetries( + Matchers.contains("service-instance-50"), Mockito.anyString(), + Mockito.anyInt())) + .thenReturn(new OperationResult(200, TestResourceLoader.getTestResourceDataJson( + "/sync/aai/aai-resources/service-instance/service-instance-50.json"))); + + Mockito + .when(aaiAdapter.queryActiveInventoryWithRetries( + Matchers.contains("service-instance-52"), Mockito.anyString(), + Mockito.anyInt())) + .thenReturn(new OperationResult(200, TestResourceLoader.getTestResourceDataJson( + "/sync/aai/aai-resources/service-instance/service-instance-52.json"))); + + Mockito + .when(aaiAdapter.queryActiveInventoryWithRetries( + Matchers.contains("service-instance-57"), Mockito.anyString(), + Mockito.anyInt())) + .thenReturn(new OperationResult(200, TestResourceLoader.getTestResourceDataJson( + "/sync/aai/aai-resources/service-instance/service-instance-57.json"))); + + Mockito + .when(aaiAdapter.queryActiveInventoryWithRetries( + Matchers.contains("service-instance-53"), Mockito.anyString(), + Mockito.anyInt())) + .thenReturn(new OperationResult(200, TestResourceLoader.getTestResourceDataJson( + "/sync/aai/aai-resources/service-instance/service-instance-53.json"))); + + Mockito + .when(aaiAdapter.queryActiveInventoryWithRetries( + Matchers.contains("service-instance-58"), Mockito.anyString(), + Mockito.anyInt())) + .thenReturn(new OperationResult(200, TestResourceLoader.getTestResourceDataJson( + "/sync/aai/aai-resources/service-instance/service-instance-58.json"))); + + Mockito + .when(aaiAdapter.queryActiveInventoryWithRetries( + Matchers.contains("service-instance-51"), Mockito.anyString(), + Mockito.anyInt())) + .thenReturn(new OperationResult(200, TestResourceLoader.getTestResourceDataJson( + "/sync/aai/aai-resources/service-instance/service-instance-51.json"))); + + Mockito + .when(aaiAdapter.queryActiveInventoryWithRetries( + Matchers.contains("service-instance-56"), Mockito.anyString(), + Mockito.anyInt())) + .thenReturn(new OperationResult(200, TestResourceLoader.getTestResourceDataJson( + "/sync/aai/aai-resources/service-instance/service-instance-56.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 = cerSynchronizer.doSync(); + assertEquals(OperationState.OK, syncState); + + assertNotNull(cerSynchronizer.getStatReport(false)); + assertNotNull(cerSynchronizer.getStatReport(true)); + + cerSynchronizer.clearCache(); + cerSynchronizer.shutdown(); + + + } + + @Test + public void validateSmallSyncWithRetries() throws Exception { + + cerSynchronizer = new CrossEntityReferenceSynchronizer(esSchemaConfig, 5, 5, 5, aaiStatConfig, + esStatConfig, cerLookup, oxmEntityLookup, searchableEntityLookup); + + cerSynchronizer.setAaiAdapter(aaiAdapter); + cerSynchronizer.setElasticSearchAdapter(esAdapter); + + String nodesQueryResponse = TestResourceLoader + .getTestResourceDataJson("/sync/aai/activeInventory_service-subscription_nodesQuery_response.json"); + + OperationResult entitySelfLinks = new OperationResult(); + + entitySelfLinks.setResultCode(200); + entitySelfLinks.setResult(nodesQueryResponse); + + Mockito.when(aaiAdapter.getSelfLinksByEntityType("service-subscription")) + .thenReturn(entitySelfLinks); + + Mockito + .when(aaiAdapter.repairSelfLink(Matchers.contains("service-subscription-1"), + Mockito.anyString())) + .thenReturn( + "https://server.proxy:8443/aai/v11/business/customers/customer/customer-1/service-subscriptions/service-subscription/service-subscription-1"); + + Mockito + .when(aaiAdapter.repairSelfLink(Matchers.contains("service-subscription-2"), + Mockito.anyString())) + .thenReturn( + "https://server.proxy:8443/aai/v11/business/customers/customer/customer-2/service-subscriptions/service-subscription/service-subscription-2"); + + Mockito + .when( + aaiAdapter.repairSelfLink(Matchers.contains("service-subscription-3"), Mockito.anyString())) + .thenReturn( + "https://server.proxy:8443/aai/v11/business/customers/customer/customer-3/service-subscriptions/service-subscription/service-subscription-3"); + + Mockito + .when(aaiAdapter.queryActiveInventoryWithRetries( + Matchers.contains("service-subscription-2"), Mockito.anyString(), + Mockito.anyInt())) + .thenReturn(new OperationResult(200, TestResourceLoader.getTestResourceDataJson( + "/sync/aai/service-subscription-service-subscription-2.json"))); + + Mockito + .when(aaiAdapter.queryActiveInventoryWithRetries( + Matchers.contains("service-subscription-1"), Mockito.anyString(), + Mockito.anyInt())) + .thenReturn(new OperationResult(200, TestResourceLoader.getTestResourceDataJson( + "/sync/aai/service-subscription-service-subscription-1.json"))); + + Mockito + .when(aaiAdapter.queryActiveInventoryWithRetries(Matchers.contains("service-subscription-3"), + Mockito.anyString(), Mockito.anyInt())) + .thenReturn(new OperationResult(200, TestResourceLoader + .getTestResourceDataJson("/sync/aai/service-subscription-service-subscription-3.json"))); + + Mockito + .when(aaiAdapter.getGenericQueryForSelfLink(Matchers.contains("service-instance"), + Matchers.argThat(listContainsValue("service-instance-59")))) + .thenReturn("https://server.proxy:8443/aai/v11/search/generic-query/service-instance-59"); + + Mockito + .when(aaiAdapter.getGenericQueryForSelfLink(Matchers.contains("service-instance"), + Matchers.argThat(listContainsValue("service-instance-54")))) + .thenReturn( + "https://server.proxy:8443/aai/v11/search/generic-query/service-instance-54"); + + Mockito + .when(aaiAdapter.getGenericQueryForSelfLink(Matchers.contains("service-instance"), + Matchers.argThat(listContainsValue("service-instance-55")))) + .thenReturn( + "https://server.proxy:8443/aai/v11/search/generic-query/service-instance-55"); + + Mockito + .when(aaiAdapter.getGenericQueryForSelfLink(Matchers.contains("service-instance"), + Matchers.argThat(listContainsValue("service-instance-50")))) + .thenReturn( + "https://server.proxy:8443/aai/v11/search/generic-query/service-instance-50"); + + Mockito + .when(aaiAdapter.getGenericQueryForSelfLink(Matchers.contains("service-instance"), + Matchers.argThat(listContainsValue("service-instance-52")))) + .thenReturn( + "https://server.proxy:8443/aai/v11/search/generic-query/service-instance-52"); + + Mockito + .when(aaiAdapter.getGenericQueryForSelfLink(Matchers.contains("service-instance"), + Matchers.argThat(listContainsValue("service-instance-57")))) + .thenReturn( + "https://server.proxy:8443/aai/v11/search/generic-query/service-instance-57"); + + Mockito + .when(aaiAdapter.getGenericQueryForSelfLink(Matchers.contains("service-instance"), + Matchers.argThat(listContainsValue("service-instance-53")))) + .thenReturn( + "https://server.proxy:8443/aai/v11/search/generic-query/service-instance-53"); + + Mockito + .when(aaiAdapter.getGenericQueryForSelfLink(Matchers.contains("service-instance"), + Matchers.argThat(listContainsValue("service-instance-58")))) + .thenReturn( + "https://server.proxy:8443/aai/v11/search/generic-query/service-instance-58"); + + Mockito + .when(aaiAdapter.getGenericQueryForSelfLink(Matchers.contains("service-instance"), + Matchers.argThat(listContainsValue("service-instance-51")))) + .thenReturn( + "https://server.proxy:8443/aai/v11/search/generic-query/service-instance-51"); + + Mockito + .when(aaiAdapter.getGenericQueryForSelfLink(Matchers.contains("service-instance"), + Matchers.argThat(listContainsValue("service-instance-56")))) + .thenReturn( + "https://server.proxy:8443/aai/v11/search/generic-query/service-instance-56"); + + + + + Mockito + .when(aaiAdapter.queryActiveInventoryWithRetries( + Matchers.contains("generic-query/service-instance-59"), Mockito.anyString(), + Mockito.anyInt())) + .thenReturn(new OperationResult(200, TestResourceLoader.getTestResourceDataJson( + "/sync/aai/aai-traversal/generic-query/service-instance-59.json"))); + + Mockito + .when(aaiAdapter.queryActiveInventoryWithRetries( + Matchers.contains("generic-query/service-instance-54"), Mockito.anyString(), + Mockito.anyInt())) + .thenReturn(new OperationResult(200, TestResourceLoader.getTestResourceDataJson( + "/sync/aai/aai-traversal/generic-query/service-instance-54.json"))); + + Mockito + .when(aaiAdapter.queryActiveInventoryWithRetries( + Matchers.contains("generic-query/service-instance-55"), Mockito.anyString(), + Mockito.anyInt())) + .thenReturn(new OperationResult(200, TestResourceLoader.getTestResourceDataJson( + "/sync/aai/aai-traversal/generic-query/service-instance-55.json"))); + + Mockito + .when(aaiAdapter.queryActiveInventoryWithRetries( + Matchers.contains("generic-query/service-instance-50"), Mockito.anyString(), + Mockito.anyInt())) + .thenReturn(new OperationResult(200, TestResourceLoader.getTestResourceDataJson( + "/sync/aai/aai-traversal/generic-query/service-instance-50.json"))); + + Mockito + .when(aaiAdapter.queryActiveInventoryWithRetries( + Matchers.contains("generic-query/service-instance-52"), Mockito.anyString(), + Mockito.anyInt())) + .thenReturn(new OperationResult(200, TestResourceLoader.getTestResourceDataJson( + "/sync/aai/aai-traversal/generic-query/service-instance-52.json"))); + + Mockito + .when(aaiAdapter.queryActiveInventoryWithRetries( + Matchers.contains("generic-query/service-instance-57"), Mockito.anyString(), + Mockito.anyInt())) + .thenReturn(new OperationResult(200, TestResourceLoader.getTestResourceDataJson( + "/sync/aai/aai-traversal/generic-query/service-instance-57.json"))); + + Mockito + .when(aaiAdapter.queryActiveInventoryWithRetries( + Matchers.contains("generic-query/service-instance-53"), Mockito.anyString(), + Mockito.anyInt())) + .thenReturn(new OperationResult(200, TestResourceLoader.getTestResourceDataJson( + "/sync/aai/aai-traversal/generic-query/service-instance-53.json"))); + + Mockito + .when(aaiAdapter.queryActiveInventoryWithRetries( + Matchers.contains("generic-query/service-instance-58"), Mockito.anyString(), + Mockito.anyInt())) + .thenReturn(new OperationResult(200, TestResourceLoader.getTestResourceDataJson( + "/sync/aai/aai-traversal/generic-query/service-instance-58.json"))); + + Mockito + .when(aaiAdapter.queryActiveInventoryWithRetries( + Matchers.contains("generic-query/service-instance-51"), Mockito.anyString(), + Mockito.anyInt())) + .thenReturn(new OperationResult(200, TestResourceLoader.getTestResourceDataJson( + "/sync/aai/aai-traversal/generic-query/service-instance-51.json"))); + + Mockito + .when(aaiAdapter.queryActiveInventoryWithRetries( + Matchers.contains("generic-query/service-instance-56"), Mockito.anyString(), + Mockito.anyInt())) + .thenReturn(new OperationResult(200, TestResourceLoader.getTestResourceDataJson( + "/sync/aai/aai-traversal/generic-query/service-instance-56.json"))); + + + + + + + /* + + Mockito + .when(aaiAdapter.queryActiveInventoryWithRetries( + Matchers.contains("service-instance-59"), Mockito.anyString(), + Mockito.anyInt())) + .thenReturn(new OperationResult(200, TestResourceLoader.getTestResourceDataJson( + "/sync/aai/aai-resources/service-instance/service-instance-59.json"))); + + Mockito + .when(aaiAdapter.queryActiveInventoryWithRetries( + Matchers.contains("service-instance-54"), Mockito.anyString(), + Mockito.anyInt())) + .thenReturn(new OperationResult(200, TestResourceLoader.getTestResourceDataJson( + "/sync/aai/aai-resources/service-instance/service-instance-54.json"))); + + Mockito + .when(aaiAdapter.queryActiveInventoryWithRetries( + Matchers.contains("service-instance-55"), Mockito.anyString(), + Mockito.anyInt())) + .thenReturn(new OperationResult(200, TestResourceLoader.getTestResourceDataJson( + "/sync/aai/aai-resources/service-instance/service-instance-55.json"))); + + Mockito + .when(aaiAdapter.queryActiveInventoryWithRetries( + Matchers.contains("service-instance-50"), Mockito.anyString(), + Mockito.anyInt())) + .thenReturn(new OperationResult(200, TestResourceLoader.getTestResourceDataJson( + "/sync/aai/aai-resources/service-instance/service-instance-50.json"))); + + Mockito + .when(aaiAdapter.queryActiveInventoryWithRetries( + Matchers.contains("service-instance-52"), Mockito.anyString(), + Mockito.anyInt())) + .thenReturn(new OperationResult(200, TestResourceLoader.getTestResourceDataJson( + "/sync/aai/aai-resources/service-instance/service-instance-52.json"))); + + Mockito + .when(aaiAdapter.queryActiveInventoryWithRetries( + Matchers.contains("service-instance-57"), Mockito.anyString(), + Mockito.anyInt())) + .thenReturn(new OperationResult(200, TestResourceLoader.getTestResourceDataJson( + "/sync/aai/aai-resources/service-instance/service-instance-57.json"))); + + Mockito + .when(aaiAdapter.queryActiveInventoryWithRetries( + Matchers.contains("service-instance-53"), Mockito.anyString(), + Mockito.anyInt())) + .thenReturn(new OperationResult(200, TestResourceLoader.getTestResourceDataJson( + "/sync/aai/aai-resources/service-instance/service-instance-53.json"))); + + Mockito + .when(aaiAdapter.queryActiveInventoryWithRetries( + Matchers.contains("service-instance-58"), Mockito.anyString(), + Mockito.anyInt())) + .thenReturn(new OperationResult(200, TestResourceLoader.getTestResourceDataJson( + "/sync/aai/aai-resources/service-instance/service-instance-58.json"))); + + Mockito + .when(aaiAdapter.queryActiveInventoryWithRetries( + Matchers.contains("service-instance-51"), Mockito.anyString(), + Mockito.anyInt())) + .thenReturn(new OperationResult(200, TestResourceLoader.getTestResourceDataJson( + "/sync/aai/aai-resources/service-instance/service-instance-51.json"))); + + Mockito + .when(aaiAdapter.queryActiveInventoryWithRetries( + Matchers.contains("service-instance-56"), Mockito.anyString(), + Mockito.anyInt())) + .thenReturn(new OperationResult(200, TestResourceLoader.getTestResourceDataJson( + "/sync/aai/aai-resources/service-instance/service-instance-56.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)); + + + /* + * Cause version conflict errors on every put to test retry flow + */ + + Mockito.when(esAdapter.doPut(Matchers.contains("doc"), Mockito.any(), Mockito.any())) + .thenReturn(new OperationResult(409, null)); + + OperationState syncState = cerSynchronizer.doSync(); + assertEquals(OperationState.OK, syncState); + + assertNotNull(cerSynchronizer.getStatReport(false)); + assertNotNull(cerSynchronizer.getStatReport(true)); + + cerSynchronizer.clearCache(); + cerSynchronizer.shutdown(); + + + + + } + + + + @Test + public void validateSmallSyncWithEntityMerges() throws Exception { + + cerSynchronizer = new CrossEntityReferenceSynchronizer(esSchemaConfig, 5, 5, 5, aaiStatConfig, + esStatConfig, cerLookup, oxmEntityLookup, searchableEntityLookup); + + cerSynchronizer.setAaiAdapter(aaiAdapter); + cerSynchronizer.setElasticSearchAdapter(esAdapter); + + String nodesQueryResponse = TestResourceLoader + .getTestResourceDataJson("/sync/aai/activeInventory_service-subscription_nodesQuery_response.json"); + + OperationResult entitySelfLinks = new OperationResult(); + + entitySelfLinks.setResultCode(200); + entitySelfLinks.setResult(nodesQueryResponse); + + Mockito.when(aaiAdapter.getSelfLinksByEntityType("service-subscription")) + .thenReturn(entitySelfLinks); + + Mockito + .when(aaiAdapter.repairSelfLink(Matchers.contains("service-subscription-1"), + Mockito.anyString())) + .thenReturn( + "https://server.proxy:8443/aai/v11/business/customers/customer/customer-1/service-subscriptions/service-subscription/service-subscription-1"); + + Mockito + .when(aaiAdapter.repairSelfLink(Matchers.contains("service-subscription-2"), + Mockito.anyString())) + .thenReturn( + "https://server.proxy:8443/aai/v11/business/customers/customer/customer-2/service-subscriptions/service-subscription/service-subscription-2"); + + Mockito + .when( + aaiAdapter.repairSelfLink(Matchers.contains("service-subscription-3"), Mockito.anyString())) + .thenReturn( + "https://server.proxy:8443/aai/v11/business/customers/customer/customer-3/service-subscriptions/service-subscription/service-subscription-3"); + + Mockito + .when(aaiAdapter.queryActiveInventoryWithRetries( + Matchers.contains("service-subscription-2"), Mockito.anyString(), + Mockito.anyInt())) + .thenReturn(new OperationResult(200, TestResourceLoader.getTestResourceDataJson( + "/sync/aai/service-subscription-service-subscription-2.json"))); + + Mockito + .when(aaiAdapter.queryActiveInventoryWithRetries( + Matchers.contains("service-subscription-1"), Mockito.anyString(), + Mockito.anyInt())) + .thenReturn(new OperationResult(200, TestResourceLoader.getTestResourceDataJson( + "/sync/aai/service-subscription-service-subscription-1.json"))); + + Mockito + .when(aaiAdapter.queryActiveInventoryWithRetries(Matchers.contains("service-subscription-3"), + Mockito.anyString(), Mockito.anyInt())) + .thenReturn(new OperationResult(200, TestResourceLoader + .getTestResourceDataJson("/sync/aai/service-subscription-service-subscription-3.json"))); + + Mockito + .when(aaiAdapter.getGenericQueryForSelfLink(Matchers.contains("service-instance"), + Matchers.argThat(listContainsValue("service-instance-59")))) + .thenReturn("https://server.proxy:8443/aai/v11/search/generic-query/service-instance-59"); + + Mockito + .when(aaiAdapter.getGenericQueryForSelfLink(Matchers.contains("service-instance"), + Matchers.argThat(listContainsValue("service-instance-54")))) + .thenReturn( + "https://server.proxy:8443/aai/v11/search/generic-query/service-instance-54"); + + Mockito + .when(aaiAdapter.getGenericQueryForSelfLink(Matchers.contains("service-instance"), + Matchers.argThat(listContainsValue("service-instance-55")))) + .thenReturn( + "https://server.proxy:8443/aai/v11/search/generic-query/service-instance-55"); + + Mockito + .when(aaiAdapter.getGenericQueryForSelfLink(Matchers.contains("service-instance"), + Matchers.argThat(listContainsValue("service-instance-50")))) + .thenReturn( + "https://server.proxy:8443/aai/v11/search/generic-query/service-instance-50"); + + Mockito + .when(aaiAdapter.getGenericQueryForSelfLink(Matchers.contains("service-instance"), + Matchers.argThat(listContainsValue("service-instance-52")))) + .thenReturn( + "https://server.proxy:8443/aai/v11/search/generic-query/service-instance-52"); + + Mockito + .when(aaiAdapter.getGenericQueryForSelfLink(Matchers.contains("service-instance"), + Matchers.argThat(listContainsValue("service-instance-57")))) + .thenReturn( + "https://server.proxy:8443/aai/v11/search/generic-query/service-instance-57"); + + Mockito + .when(aaiAdapter.getGenericQueryForSelfLink(Matchers.contains("service-instance"), + Matchers.argThat(listContainsValue("service-instance-53")))) + .thenReturn( + "https://server.proxy:8443/aai/v11/search/generic-query/service-instance-53"); + + Mockito + .when(aaiAdapter.getGenericQueryForSelfLink(Matchers.contains("service-instance"), + Matchers.argThat(listContainsValue("service-instance-58")))) + .thenReturn( + "https://server.proxy:8443/aai/v11/search/generic-query/service-instance-58"); + + Mockito + .when(aaiAdapter.getGenericQueryForSelfLink(Matchers.contains("service-instance"), + Matchers.argThat(listContainsValue("service-instance-51")))) + .thenReturn( + "https://server.proxy:8443/aai/v11/search/generic-query/service-instance-51"); + + Mockito + .when(aaiAdapter.getGenericQueryForSelfLink(Matchers.contains("service-instance"), + Matchers.argThat(listContainsValue("service-instance-56")))) + .thenReturn( + "https://server.proxy:8443/aai/v11/search/generic-query/service-instance-56"); + + + + + Mockito + .when(aaiAdapter.queryActiveInventoryWithRetries( + Matchers.contains("generic-query/service-instance-59"), Mockito.anyString(), + Mockito.anyInt())) + .thenReturn(new OperationResult(200, TestResourceLoader.getTestResourceDataJson( + "/sync/aai/aai-traversal/generic-query/service-instance-59.json"))); + + Mockito + .when(aaiAdapter.queryActiveInventoryWithRetries( + Matchers.contains("generic-query/service-instance-54"), Mockito.anyString(), + Mockito.anyInt())) + .thenReturn(new OperationResult(200, TestResourceLoader.getTestResourceDataJson( + "/sync/aai/aai-traversal/generic-query/service-instance-54.json"))); + + Mockito + .when(aaiAdapter.queryActiveInventoryWithRetries( + Matchers.contains("generic-query/service-instance-55"), Mockito.anyString(), + Mockito.anyInt())) + .thenReturn(new OperationResult(200, TestResourceLoader.getTestResourceDataJson( + "/sync/aai/aai-traversal/generic-query/service-instance-55.json"))); + + Mockito + .when(aaiAdapter.queryActiveInventoryWithRetries( + Matchers.contains("generic-query/service-instance-50"), Mockito.anyString(), + Mockito.anyInt())) + .thenReturn(new OperationResult(200, TestResourceLoader.getTestResourceDataJson( + "/sync/aai/aai-traversal/generic-query/service-instance-50.json"))); + + Mockito + .when(aaiAdapter.queryActiveInventoryWithRetries( + Matchers.contains("generic-query/service-instance-52"), Mockito.anyString(), + Mockito.anyInt())) + .thenReturn(new OperationResult(200, TestResourceLoader.getTestResourceDataJson( + "/sync/aai/aai-traversal/generic-query/service-instance-52.json"))); + + Mockito + .when(aaiAdapter.queryActiveInventoryWithRetries( + Matchers.contains("generic-query/service-instance-57"), Mockito.anyString(), + Mockito.anyInt())) + .thenReturn(new OperationResult(200, TestResourceLoader.getTestResourceDataJson( + "/sync/aai/aai-traversal/generic-query/service-instance-57.json"))); + + Mockito + .when(aaiAdapter.queryActiveInventoryWithRetries( + Matchers.contains("generic-query/service-instance-53"), Mockito.anyString(), + Mockito.anyInt())) + .thenReturn(new OperationResult(200, TestResourceLoader.getTestResourceDataJson( + "/sync/aai/aai-traversal/generic-query/service-instance-53.json"))); + + Mockito + .when(aaiAdapter.queryActiveInventoryWithRetries( + Matchers.contains("generic-query/service-instance-58"), Mockito.anyString(), + Mockito.anyInt())) + .thenReturn(new OperationResult(200, TestResourceLoader.getTestResourceDataJson( + "/sync/aai/aai-traversal/generic-query/service-instance-58.json"))); + + Mockito + .when(aaiAdapter.queryActiveInventoryWithRetries( + Matchers.contains("generic-query/service-instance-51"), Mockito.anyString(), + Mockito.anyInt())) + .thenReturn(new OperationResult(200, TestResourceLoader.getTestResourceDataJson( + "/sync/aai/aai-traversal/generic-query/service-instance-51.json"))); + + Mockito + .when(aaiAdapter.queryActiveInventoryWithRetries( + Matchers.contains("generic-query/service-instance-56"), Mockito.anyString(), + Mockito.anyInt())) + .thenReturn(new OperationResult(200, TestResourceLoader.getTestResourceDataJson( + "/sync/aai/aai-traversal/generic-query/service-instance-56.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 return 200 ok with a found entity document requiring a doc update + */ + Mockito.when(esAdapter.doGet(Matchers.contains("doc1"), Mockito.any())).thenReturn(new OperationResult(200, + TestResourceLoader.getTestResourceDataJson("/sync/ElasticSearch/docEntityFromElasticSearch1.json"))); + + Mockito.when(esAdapter.doGet(Matchers.contains("doc2"), Mockito.any())).thenReturn(new OperationResult(200, + TestResourceLoader.getTestResourceDataJson("/sync/ElasticSearch/docEntityFromElasticSearch2.json"))); + + Mockito.when(esAdapter.doGet(Matchers.contains("doc3"), Mockito.any())).thenReturn(new OperationResult(200, + TestResourceLoader.getTestResourceDataJson("/sync/ElasticSearch/docEntityFromElasticSearch3.json"))); + + Mockito.when(esAdapter.doGet(Matchers.contains("doc4"), Mockito.any())).thenReturn(new OperationResult(200, + TestResourceLoader.getTestResourceDataJson("/sync/ElasticSearch/docEntityFromElasticSearch4.json"))); + + Mockito.when(esAdapter.doGet(Matchers.contains("doc5"), Mockito.any())).thenReturn(new OperationResult(200, + TestResourceLoader.getTestResourceDataJson("/sync/ElasticSearch/docEntityFromElasticSearch5.json"))); + + Mockito.when(esAdapter.doPut(Matchers.contains("doc"), Mockito.any(), Mockito.any())) + .thenReturn(new OperationResult(200, null)); + + + + Mockito.when(esAdapter.doPut(Matchers.contains("doc"), Mockito.any(), Mockito.any())) + .thenReturn(new OperationResult(200, null)); + + OperationState syncState = cerSynchronizer.doSync(); + assertEquals(OperationState.OK, syncState); + + assertNotNull(cerSynchronizer.getStatReport(false)); + assertNotNull(cerSynchronizer.getStatReport(true)); + + cerSynchronizer.clearCache(); + cerSynchronizer.shutdown(); + + + + + } + + + + +} diff --git a/src/test/java/org/onap/aai/sparky/util/StringCollectionContainsMatcher.java b/src/test/java/org/onap/aai/sparky/util/StringCollectionContainsMatcher.java new file mode 100644 index 0000000..e8b3258 --- /dev/null +++ b/src/test/java/org/onap/aai/sparky/util/StringCollectionContainsMatcher.java @@ -0,0 +1,39 @@ +package org.onap.aai.sparky.util; + +import java.util.List; + +import org.hamcrest.BaseMatcher; +import org.hamcrest.Description; + +public class StringCollectionContainsMatcher extends BaseMatcher<List<String>> { + + private String valueToCheck; + + @SuppressWarnings({"unused", "unchecked"}) + public StringCollectionContainsMatcher(String valToCheck) { + this.valueToCheck = valToCheck; + } + + @Override + public boolean matches(Object arg0) { + + @SuppressWarnings("unchecked") + List<String> argumentList = (List<String>) arg0; + + for ( String listItem : argumentList ) { + + if ( listItem.contains(valueToCheck)) { + return true; + } + } + + return false; + } + + @Override + public void describeTo(Description arg0) { + // TODO Auto-generated method stub + + } + +} diff --git a/src/test/java/org/onap/aai/sparky/viewandinspect/services/BaseVisualizationContextTest.java b/src/test/java/org/onap/aai/sparky/viewandinspect/services/BaseVisualizationContextTest.java new file mode 100644 index 0000000..09ca3a3 --- /dev/null +++ b/src/test/java/org/onap/aai/sparky/viewandinspect/services/BaseVisualizationContextTest.java @@ -0,0 +1,273 @@ +package org.onap.aai.sparky.viewandinspect.services; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import java.security.SecureRandom; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.ExecutorService; + +import org.hamcrest.Matcher; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Matchers; +import org.mockito.Mockito; +import org.onap.aai.cl.api.Logger; +import org.onap.aai.cl.eelf.LoggerFactory; +import org.onap.aai.cl.mdc.MdcContext; +import org.onap.aai.restclient.client.OperationResult; +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.dal.ActiveInventoryAdapter; +import org.onap.aai.sparky.dal.rest.config.RestEndpointConfig; +import org.onap.aai.sparky.sync.entity.SearchableEntity; +import org.onap.aai.sparky.util.NodeUtils; +import org.onap.aai.sparky.util.StringCollectionContainsMatcher; +import org.onap.aai.sparky.util.TestResourceLoader; +import org.onap.aai.sparky.viewandinspect.config.VisualizationConfigs; +import org.onap.aai.sparky.viewandinspect.entity.ActiveInventoryNode; +import org.onap.aai.sparky.viewandinspect.entity.QueryParams; +import org.onap.aai.sparky.viewandinspect.enumeration.NodeProcessingState; + + +public class BaseVisualizationContextTest { + + private static SecureRandom secureRandom = new SecureRandom(); + private static Logger LOG = LoggerFactory.getInstance().getLogger(BaseVisualizationContextTest.class); + + private BaseVisualizationContext baseVisualizationContext; + private ExecutorService aaiExecutorService; + private VisualizationConfigs visualizationConfig; + + private OxmEntityLookup oxmEntityLookup; + + private ActiveInventoryAdapter aaiAdapter; + private RestEndpointConfig aaiRestEndPointConfig; + + @Before + public void init() throws Exception { + + aaiExecutorService = NodeUtils.createNamedExecutor("SLNC-WORKER", 5, LOG); + visualizationConfig = new VisualizationConfigs(); + + ArrayList<String> shallowEntities = new ArrayList<String>(); + shallowEntities.add("cloud-region"); + + visualizationConfig.setShallowEntities(shallowEntities); + visualizationConfig.setMaxSelfLinkTraversalDepth(2); + + oxmEntityLookup = new OxmEntityLookup(); + + aaiAdapter = Mockito.mock(ActiveInventoryAdapter.class); + + + Set<OxmModelProcessor> processors = new HashSet<OxmModelProcessor>(); + + processors.add(oxmEntityLookup); + + + OxmModelLoader oxmModelLoader = new OxmModelLoader(-1, processors); + oxmModelLoader.loadLatestOxmModel(); + + aaiRestEndPointConfig = new RestEndpointConfig(); + aaiRestEndPointConfig.setNumRequestRetries(5); + + Mockito.when(aaiAdapter.getEndpointConfig()).thenReturn(aaiRestEndPointConfig); + + MdcContext.initialize("" + secureRandom.nextLong(), "AAI-UI", "", "partner-name", + "localhost:4242"); + + // all our resources are prefixed already, so the repairSelfLink shouldn't do anything to the link + Mockito.when(aaiAdapter.repairSelfLink(Matchers.contains(""))).thenReturn(""); + + + } + + private Matcher<List<String>> listContainsValue(String expectedValue) { + return new StringCollectionContainsMatcher(expectedValue); + } + + + @Test + public void validateBasicConstruction() throws Exception { + + long contextId = secureRandom.nextLong(); + + baseVisualizationContext = new BaseVisualizationContext(contextId, aaiAdapter, + aaiExecutorService, visualizationConfig, oxmEntityLookup); + + assertEquals(contextId, baseVisualizationContext.getContextId()); + + } + + @Test + public void validateSmallGraphAssembly() throws Exception { + + /** + * We have a tiny graph that we will validate assembly of: + * + * <li>customer -> tenant + * <li>customer -> service-subscription + * <li>service-subscription -> service-instance-1 + * <li>service-subscription -> service-instance-2 + * + * At the end of this success path, we should have 5 nodes in the node cache. Once we have this + * flow we can experiment with error paths involving resource download failures to ensure graph + * nodes are in the correct state and that expected nodes are successfully represented in the + * cache. + */ + + long contextId = secureRandom.nextLong(); + + baseVisualizationContext = new BaseVisualizationContext(contextId, aaiAdapter, + aaiExecutorService, visualizationConfig, oxmEntityLookup); + + SearchableEntity searchableEntity = new SearchableEntity(); + String customerSelfLink = + "https://server.proxy:8443/aai/v11/business/customers/customer/customer-4"; + String customerNodeId = NodeUtils.generateUniqueShaDigest(customerSelfLink); + + searchableEntity.setId(customerNodeId); + searchableEntity.setEntityType("customer"); + searchableEntity.setEntityPrimaryKeyValue("customer-4"); + searchableEntity.setLink(customerSelfLink); + + QueryParams queryParams = new QueryParams(); + queryParams.setSearchTargetNodeId(customerNodeId); + queryParams.setSearchTargetPrimaryKeyValues("customer-4"); + + // aai customer resource dip + + Mockito + .when(aaiAdapter.queryActiveInventoryWithRetries( + Matchers.contains("customer-4"), Mockito.anyString(), + Mockito.anyInt())) + .thenReturn(new OperationResult(200, TestResourceLoader.getTestResourceDataJson( + "/sync/aai/aai-resources/customer/customer-4.json"))); + + // aai tenant resource dip + + Mockito + .when(aaiAdapter.queryActiveInventoryWithRetries( + Matchers.contains("tenant/tenant-1"), Mockito.anyString(), + Mockito.anyInt())) + .thenReturn(new OperationResult(200, TestResourceLoader.getTestResourceDataJson( + "/sync/aai/aai-resources/tenant/tenant-1.json"))); + + // generic-queries for service-subscription + + Mockito + .when(aaiAdapter.getGenericQueryForSelfLink(Matchers.contains("service-subscription"), + Matchers.argThat(listContainsValue("service-subscription.service-type:service-subscription-2")))) + .thenReturn( + "https://server.proxy:8443/aai/v11/search/generic-query/service-subscription-2"); + + Mockito + .when(aaiAdapter.queryActiveInventoryWithRetries( + Matchers.contains("generic-query/service-subscription-2"), Mockito.anyString(), Mockito.anyInt())) + .thenReturn(new OperationResult(200, TestResourceLoader + .getTestResourceDataJson("/sync/aai/aai-traversal/generic-query/service-subscription/service-subscription-2.json"))); + + // generic-queries for service-instance-1 + + Mockito + .when(aaiAdapter.getGenericQueryForSelfLink(Matchers.contains("service-instance"), + Matchers.argThat( + listContainsValue("service-instance-id:service-instance-54")))) + .thenReturn( + "https://server.proxy:8443/aai/v11/search/generic-query/service-instance-id/service-instance-54"); + + Mockito + .when(aaiAdapter.queryActiveInventoryWithRetries( + Matchers + .contains("generic-query/service-instance-id/service-instance-54"), + Mockito.anyString(), Mockito.anyInt())) + .thenReturn(new OperationResult(200, TestResourceLoader.getTestResourceDataJson( + "/sync/aai/aai-traversal/generic-query/service-instance/service-instance-54.json"))); + + // generic-queries for service-instance-2 + + Mockito + .when(aaiAdapter.getGenericQueryForSelfLink(Matchers.contains("service-instance"), + Matchers.argThat( + listContainsValue("service-instance-id:service-instance-55")))) + .thenReturn( + "https://server.proxy:8443/aai/v11/search/generic-query/service-instance-id/service-instance-55"); + + Mockito + .when(aaiAdapter.queryActiveInventoryWithRetries( + Matchers + .contains("generic-query/service-instance-id/service-instance-55"), + Mockito.anyString(), Mockito.anyInt())) + .thenReturn(new OperationResult(200, TestResourceLoader.getTestResourceDataJson( + "/sync/aai/aai-traversal/generic-query/service-instance/service-instance-55.json"))); + + + + // start the test + + baseVisualizationContext.processSelfLinks(searchableEntity, queryParams); + + /* + * validation can be in the form of validating nodes + relationships from the node cache + * baseVisualizationContext.getNodeCache(); + */ + + Map<String, ActiveInventoryNode> nodeCache = baseVisualizationContext.getNodeCache(); + + assertEquals(5, nodeCache.size()); + assertNotNull(nodeCache.get(customerNodeId)); + assertEquals("customer", nodeCache.get(customerNodeId).getEntityType()); + + // verify node collection nodes + + ActiveInventoryNode customerNode = nodeCache.get("da4101ad19b3c380a1c12ffeda8ab390e1489fb4a22a392c9a1939db63c3dec5"); + ActiveInventoryNode ssNode = nodeCache.get("f4ceaf19459993c4fc9438a7579dd20d786109f4455e38682c579045b7ae615e"); + ActiveInventoryNode tenantNode = nodeCache.get("4735439b29e446b339535668238076e4b392eaa3eec218936e12f735179bc55e"); + ActiveInventoryNode s1 = nodeCache.get("f975ab453b142197af5d0173e0a9cf2aa22d10502f8ad655c8d17de81b066e8f"); + ActiveInventoryNode s2 = nodeCache.get("de77ef8f76dd6f19662b163527ff839891b9596cac655e3143fdd7ad39e2e4e3"); + + assertNotNull( customerNode ); + assertNotNull( ssNode ); + assertNotNull( tenantNode ); + assertNotNull( s1 ); + assertNotNull( s2 ); + + // verify node depths + + assertEquals( 0, customerNode.getNodeDepth() ); + assertEquals( 1, ssNode.getNodeDepth() ); + + /* + * I think there is a bug in the way the node depth is represented due to the enforcement of + * bidirectional links being disabled. We may have to circle back to this behavior at some point + * and re-verify that the behavior works properly. + */ + + assertEquals( 2, tenantNode.getNodeDepth() ); + assertEquals( 2, s1.getNodeDepth() ); + assertEquals( 2, s2.getNodeDepth() ); + + // verify node states + + assertEquals( NodeProcessingState.READY, customerNode.getState() ); + assertEquals( NodeProcessingState.READY, ssNode.getState() ); + + /* + * these nodes have a NEIGHBORS_UNPROCESSED state because the max traversal depth was hit before + * processing all the nested relationships. I think what we should look at is advancing the state + * to READY if in fact there are no relationships to process, which I think could be the case + * sometimes. + */ + assertEquals( NodeProcessingState.NEIGHBORS_UNPROCESSED, tenantNode.getState() ); + assertEquals( NodeProcessingState.NEIGHBORS_UNPROCESSED, s1.getState() ); + assertEquals( NodeProcessingState.NEIGHBORS_UNPROCESSED, s2.getState() ); + + } + +} |