From e72b52437992610d38939700d38c42336cade235 Mon Sep 17 00:00:00 2001 From: Shawn Severin Date: Fri, 8 Dec 2017 12:53:42 -0500 Subject: Adding back-end support for UI filters Issue-ID: AAI-543 Change-Id: I5cec6f340ab6c531f073e10e7902a84036c961d5 Signed-off-by: Shawn Severin --- .../onap/aai/sparky/FilterByContainsClassName.java | 4 +- .../java/org/onap/aai/sparky/SparkyPojoTest.java | 324 +++++++++-------- .../sparky/analytics/AbstractStatisticsTest.java | 76 ++-- .../sparky/analytics/AveragingRingBufferTest.java | 2 +- .../aai/sparky/analytics/HistogramSamplerTest.java | 2 +- .../sparky/analytics/HistoricalCounterTest.java | 88 ++--- .../config/oxm/CrossEntityReferenceTest.java | 36 +- .../config/oxm/OxmModelLoaderFilterTest.java | 70 ++-- .../aai/sparky/config/oxm/OxmModelLoaderTest.java | 24 +- .../aai/sparky/dal/NetworkTransactionTest.java | 50 +-- .../sparky/dal/aai/ActiveInventoryAdapterTest.java | 126 +++---- .../aai/ActiveInventoryEntityStatisticsTest.java | 116 +++--- ...InventoryProcessingExceptionStatisticsTest.java | 100 +++--- .../dal/aai/config/ActiveInventoryConfigTest.java | 155 ++++---- .../aai/config/ActiveInventorySslConfigTest.java | 43 +-- .../sparky/dal/cache/InMemoryEntityCacheTest.java | 34 +- .../dal/elasticsearch/ElasticSearchConfigTest.java | 68 ++-- .../ElasticSearchEntityStatisticsTest.java | 126 +++---- .../entity/AutoSuggestDocumentEntity.java | 6 +- .../entity/AutoSuggestDocumentEntityFields.java | 6 +- .../entity/AutoSuggestElasticHitsEntity.java | 6 +- .../entity/AutoSuggestElasticSearchResponse.java | 20 +- .../dal/elasticsearch/entity/BucketEntity.java | 14 +- .../elasticsearch/entity/ElasticHitsEntity.java | 12 +- .../entity/ElasticSearchAggegrationResponse.java | 4 +- .../entity/ElasticSearchAggregation.java | 10 +- .../entity/ElasticSearchCountResponse.java | 6 +- .../dal/elasticsearch/entity/PayloadEntity.java | 5 +- .../dal/rest/RestOperationalStatisticsTest.java | 358 +++++++++--------- .../sparky/dal/rest/RestfulDataAccessorTest.java | 6 +- .../aai/sparky/dal/sas/entity/DocumentEntity.java | 12 +- .../sparky/dal/sas/entity/EntityCountResponse.java | 10 +- .../dal/sas/entity/GroupByAggregationEntity.java | 2 +- .../entity/GroupByAggregationResponseEntity.java | 10 +- .../onap/aai/sparky/dal/sas/entity/HitEntity.java | 2 +- .../sas/entity/SearchAbstractionEntityBuilder.java | 210 ++++++----- .../dal/sas/entity/SearchAbstractionResponse.java | 4 +- .../aai/sparky/dal/sas/entity/SearchResult.java | 13 +- .../sparky/search/VnfSearchQueryBuilderTest.java | 78 ++-- .../aai/sparky/search/VnfSearchServiceTest.java | 91 ++--- .../search/filters/FilteredSearchHelperTest.java | 2 +- .../filters/entity/DiscoverFiltersRequest.java | 2 +- .../portal/TestPortalRestAPIServiceImpl.java | 22 +- .../sparky/security/portal/TestUserManager.java | 36 +- .../AggregationSuggestionSynchronizerTest.java | 81 +++-- .../aai/sparky/synchronizer/IndexDocumentTest.java | 2 +- .../sparky/synchronizer/SyncControllerBuilder.java | 26 +- .../sparky/synchronizer/SyncControllerTest.java | 89 ++--- .../aai/sparky/synchronizer/SyncHelperTest.java | 148 ++++---- .../config/SynchronizerConfigurationTest.java | 299 ++++++++------- .../entity/AggregationSuggestionEntityTest.java | 4 +- .../aai/sparky/util/CaptureLoggerAppender.java | 52 ++- .../aai/sparky/util/ElasticEntitySummarizer.java | 7 +- .../aai/sparky/util/ElasticGarbageInjector.java | 4 +- .../org/onap/aai/sparky/util/ExceptionHelper.java | 2 +- .../onap/aai/sparky/util/HttpServletHelper.java | 16 +- .../onap/aai/sparky/util/KeystoreBuilderTest.java | 85 ++--- .../org/onap/aai/sparky/util/NodeUtilsTest.java | 41 ++- .../sparky/util/SuggestionsPermutationsTest.java | 10 +- .../org/onap/aai/sparky/util/TreeWalkerTest.java | 400 ++++++++++----------- .../viewandinspect/ActiveInventoryNodeTester.java | 3 +- .../sparky/viewandinspect/SearchAdapterTest.java | 2 +- .../sparky/viewandinspect/SearchResponseTest.java | 20 +- .../sparky/viewandinspect/SearchServletTest.java | 397 ++++++++++---------- .../viewandinspect/SearchableGroupsTest.java | 66 ++-- .../ViewAndInspectSearchRequestTest.java | 2 +- .../viewandinspect/entity/EntityEntryTest.java | 2 +- .../services/VisualizationContextTest.java | 146 ++++---- .../services/VisualizationServiceTest.java | 133 +++---- 69 files changed, 2282 insertions(+), 2146 deletions(-) (limited to 'src/test/java') diff --git a/src/test/java/org/onap/aai/sparky/FilterByContainsClassName.java b/src/test/java/org/onap/aai/sparky/FilterByContainsClassName.java index 1f55628..bfcc1c7 100644 --- a/src/test/java/org/onap/aai/sparky/FilterByContainsClassName.java +++ b/src/test/java/org/onap/aai/sparky/FilterByContainsClassName.java @@ -4,7 +4,7 @@ import com.openpojo.reflection.PojoClass; import com.openpojo.reflection.PojoClassFilter; public class FilterByContainsClassName implements PojoClassFilter { - //Since Pattern doesn't implement equals, relying on String for equals & hashCode instead. + // Since Pattern doesn't implement equals, relying on String for equals & hashCode instead. private final String className; public FilterByContainsClassName(String regex) { @@ -19,4 +19,4 @@ public class FilterByContainsClassName implements PojoClassFilter { public int hashCode() { return className.hashCode(); } -} \ No newline at end of file +} diff --git a/src/test/java/org/onap/aai/sparky/SparkyPojoTest.java b/src/test/java/org/onap/aai/sparky/SparkyPojoTest.java index ce50718..bc56223 100644 --- a/src/test/java/org/onap/aai/sparky/SparkyPojoTest.java +++ b/src/test/java/org/onap/aai/sparky/SparkyPojoTest.java @@ -16,178 +16,206 @@ import com.openpojo.validation.test.impl.GetterTester; import com.openpojo.validation.test.impl.SetterTester; public class SparkyPojoTest { -//The package to be tested + // The package to be tested private String packageName = "org.onap.aai.sparky"; private List pojoClasses; -@Test + @Test public void validateAnalytics() { - - String packageName = "org.onap.aai.sparky.analytics"; - List analyticsPojoClasses; - - FilterChain filterChainByClassNameForAnalytics = new FilterChain(new FilterByContainsClassName("AveragingRingBuffer"), - new FilterByContainsClassName("AbstractStatistics"), new FilterByContainsClassName("HistogramSampler"), - new FilterByContainsClassName("Test")); - analyticsPojoClasses = PojoClassFactory.getPojoClassesRecursively(packageName,filterChainByClassNameForAnalytics); - validateAll(analyticsPojoClasses); - + + String packageName = "org.onap.aai.sparky.analytics"; + List analyticsPojoClasses; + + FilterChain filterChainByClassNameForAnalytics = new FilterChain( + new FilterByContainsClassName("AveragingRingBuffer"), + new FilterByContainsClassName("AbstractStatistics"), + new FilterByContainsClassName("HistogramSampler"), new FilterByContainsClassName("Test")); + analyticsPojoClasses = + PojoClassFactory.getPojoClassesRecursively(packageName, filterChainByClassNameForAnalytics); + validateAll(analyticsPojoClasses); + } -@Test -public void validateAAIConfig() { - - String packageName = "org.onap.aai.sparky.dal.aai.config"; - List aaiConfigPojoClasses; - // activeinventory config mught come back - FilterChain filterChainByClassNameForConfig = new FilterChain(new FilterByContainsClassName("ActiveInventoryConfig"), - new FilterByContainsClassName("Test")); - aaiConfigPojoClasses = PojoClassFactory.getPojoClassesRecursively(packageName,filterChainByClassNameForConfig); - validateAll(aaiConfigPojoClasses); - - - -} + @Test + public void validateAAIConfig() { + String packageName = "org.onap.aai.sparky.dal.aai.config"; + List aaiConfigPojoClasses; + // activeinventory config mught come back + FilterChain filterChainByClassNameForConfig = + new FilterChain(new FilterByContainsClassName("ActiveInventoryConfig"), + new FilterByContainsClassName("Test")); + aaiConfigPojoClasses = + PojoClassFactory.getPojoClassesRecursively(packageName, filterChainByClassNameForConfig); + validateAll(aaiConfigPojoClasses); -@Test -public void validateElasticSearch(){ - - String packageName = "org.onap.aai.sparky.dal.elasticsearch"; - List elasticSearchPojoClasses; - - FilterChain filterChainByClassNameForElasticSearch = new FilterChain(new FilterByContainsClassName("ElasticSearchEntityStatistics"), - new FilterByContainsClassName("Test")); - elasticSearchPojoClasses = PojoClassFactory.getPojoClassesRecursively(packageName,filterChainByClassNameForElasticSearch); - validateAll(elasticSearchPojoClasses); - - -} -@Test -public void validateElasticSearchEntity(){ - - String packageName = "org.onap.aai.sparky.dal.elasticsearch.entity"; - List elasticSearchConfigPojoClasses; - - //FilterChain filterChainByClassNameForElasticSearchConfig = new FilterChain(new FilterByContainsClassName("ElasticSearchEntityStatistics"), - // new FilterByContainsClassName("Test")); - elasticSearchConfigPojoClasses = PojoClassFactory.getPojoClassesRecursively(packageName,null); - validateAll(elasticSearchConfigPojoClasses); - -} + } -@Test -public void validateRest(){ - - String packageName = "org.onap.aai.sparky.dal.rest"; - List restPojoClasses; - - FilterChain filterChainByClassNameForRest = new FilterChain(new FilterByContainsClassName("RestfulDataAccessor"), - new FilterByContainsClassName("Test"),new FilterByContainsClassName("RestOperationalStatistics"), - new FilterByContainsClassName("RestClientBuilder")); - restPojoClasses = PojoClassFactory.getPojoClassesRecursively(packageName,filterChainByClassNameForRest); - validateAll(restPojoClasses); -} + @Test + public void validateElasticSearch() { + String packageName = "org.onap.aai.sparky.dal.elasticsearch"; + List elasticSearchPojoClasses; -@Test -public void validateSASEntity(){ + FilterChain filterChainByClassNameForElasticSearch = + new FilterChain(new FilterByContainsClassName("ElasticSearchEntityStatistics"), + new FilterByContainsClassName("Test")); + elasticSearchPojoClasses = PojoClassFactory.getPojoClassesRecursively(packageName, + filterChainByClassNameForElasticSearch); + validateAll(elasticSearchPojoClasses); - String packageName = "org.onap.aai.sparky.dal.sas.entity"; - List sasEntityPojoClasses; - - sasEntityPojoClasses = PojoClassFactory.getPojoClassesRecursively(packageName,null); - validateAll(sasEntityPojoClasses); - -} + } -@Test -public void validateSecurity(){ - String packageName = "org.onap.aai.sparky.security"; - List securityPojoClasses; - - FilterChain filterChainByClassNameForSecurity = new FilterChain(new FilterByContainsClassName("SecurityContextFactoryImpl"), - new FilterByContainsClassName("Test"), new FilterByContainsClassName("UserManager"), - new FilterByContainsClassName("RolesConfig"),new FilterByContainsClassName("PortalAuthenticationConfig")); - securityPojoClasses = PojoClassFactory.getPojoClassesRecursively(packageName,filterChainByClassNameForSecurity); - validateAll(securityPojoClasses); -} + @Test + public void validateElasticSearchEntity() { + String packageName = "org.onap.aai.sparky.dal.elasticsearch.entity"; + List elasticSearchConfigPojoClasses; -@Test -public void validateSecurityPortal(){ + // FilterChain filterChainByClassNameForElasticSearchConfig = new FilterChain(new + // FilterByContainsClassName("ElasticSearchEntityStatistics"), + // new FilterByContainsClassName("Test")); + elasticSearchConfigPojoClasses = PojoClassFactory.getPojoClassesRecursively(packageName, null); + validateAll(elasticSearchConfigPojoClasses); - String packageName = "org.onap.aai.sparky.security.portal"; - List securityPortalPojoClasses; - - FilterChain filterChainByClassNameForSecurityPortal = new FilterChain(new FilterByContainsClassName("Test"), - new FilterByContainsClassName("UserManager"),new FilterByContainsClassName("RolesConfig"), - new FilterByContainsClassName("PortalAuthenticationConfig")); - securityPortalPojoClasses = PojoClassFactory.getPojoClassesRecursively(packageName,filterChainByClassNameForSecurityPortal); - validateAll(securityPortalPojoClasses); -} + } -@Test -public void validateSynchronizer(){ - - String packageName = "org.onap.aai.sparky.synchronizer"; - List synchronizerPojoClasses; - - FilterChain filterChainByClassNameForSynchronizer = new FilterChain(new FilterByContainsClassName("Test"), - new FilterByContainsClassName("AggregationSynchronizer"),new FilterByContainsClassName("SearchableEntitySynchronizer"), - new FilterByContainsClassName("AutosuggestionSynchronizer"),new FilterByContainsClassName("CrossEntityReferenceSynchronizer"), - new FilterByContainsClassName("SyncController"),new FilterByContainsClassName("SyncHelper"), - new FilterByContainsClassName("TransactionRateController"),new FilterByContainsClassName("AggregationSuggestionSynchronizer"), - new FilterByContainsClassName("AbstractEntitySynchronizer"),new FilterByContainsClassName("SynchronizerConfiguration")); - synchronizerPojoClasses = PojoClassFactory.getPojoClassesRecursively(packageName,filterChainByClassNameForSynchronizer); - validateAll(synchronizerPojoClasses); -} + @Test + public void validateRest() { -@Test -public void validateUtil(){ - - String packageName = "org.onap.aai.sparky.util"; - List utilPojoClasses; - - FilterChain filterChainByClassNameForUtil = new FilterChain(new FilterByContainsClassName("KeystoreBuilder"), - new FilterByContainsClassName("Test"),new FilterByContainsClassName("HttpServletHelper"),new FilterByContainsClassName("NodeUtils"), - new FilterByContainsClassName("CaptureLoggerAppender"),new FilterByContainsClassName("ElasticEntitySummarizer"), - new FilterByContainsClassName("ElasticGarbageInjector"),new FilterByContainsClassName("SuggestionsPermutation"), - new FilterByContainsClassName("savingTrustManager")); - utilPojoClasses = PojoClassFactory.getPojoClassesRecursively(packageName,filterChainByClassNameForUtil); - validateAll(utilPojoClasses); -} + String packageName = "org.onap.aai.sparky.dal.rest"; + List restPojoClasses; -@Test -public void validateViewAndInspect(){ - - String packageName = "org.onap.aai.sparky.viewandinspect"; - List viewAndInspectPojoClasses; - - FilterChain filterChainByClassNameForViewAndInspect = new FilterChain(new FilterByContainsClassName("Test"), - new FilterByContainsClassName("PerformSelfLinkDetermination"),new FilterByContainsClassName("PerformNodeSelfLinkProcessingTask"), - new FilterByContainsClassName("ActiveInventoryNode"),new FilterByContainsClassName("NodeProcessingTransaction"), - new FilterByContainsClassName("VisualizationServlet"),new FilterByContainsClassName("VisualizationService"), - new FilterByContainsClassName("VisualizationContext")); - viewAndInspectPojoClasses = PojoClassFactory.getPojoClassesRecursively(packageName,filterChainByClassNameForViewAndInspect); - validateAll(viewAndInspectPojoClasses); -} + FilterChain filterChainByClassNameForRest = new FilterChain( + new FilterByContainsClassName("RestfulDataAccessor"), new FilterByContainsClassName("Test"), + new FilterByContainsClassName("RestOperationalStatistics"), + new FilterByContainsClassName("RestClientBuilder")); + restPojoClasses = + PojoClassFactory.getPojoClassesRecursively(packageName, filterChainByClassNameForRest); + validateAll(restPojoClasses); + } -public void validateAll(List pojoClasses){ - - Validator validator = ValidatorBuilder.create() - .with(new SetterMustExistRule(), - new GetterMustExistRule()) - .with(new SetterTester(), - new GetterTester()) - .build(); -validator.validate(pojoClasses); -} -} \ No newline at end of file + @Test + public void validateSASEntity() { + + String packageName = "org.onap.aai.sparky.dal.sas.entity"; + List sasEntityPojoClasses; + + sasEntityPojoClasses = PojoClassFactory.getPojoClassesRecursively(packageName, null); + validateAll(sasEntityPojoClasses); + + } + + + @Test + public void validateSecurity() { + + String packageName = "org.onap.aai.sparky.security"; + List securityPojoClasses; + + FilterChain filterChainByClassNameForSecurity = + new FilterChain(new FilterByContainsClassName("SecurityContextFactoryImpl"), + new FilterByContainsClassName("Test"), new FilterByContainsClassName("UserManager"), + new FilterByContainsClassName("RolesConfig"), + new FilterByContainsClassName("PortalAuthenticationConfig")); + securityPojoClasses = + PojoClassFactory.getPojoClassesRecursively(packageName, filterChainByClassNameForSecurity); + validateAll(securityPojoClasses); + } + + + @Test + public void validateSecurityPortal() { + + String packageName = "org.onap.aai.sparky.security.portal"; + List securityPortalPojoClasses; + + FilterChain filterChainByClassNameForSecurityPortal = new FilterChain( + new FilterByContainsClassName("Test"), new FilterByContainsClassName("UserManager"), + new FilterByContainsClassName("RolesConfig"), + new FilterByContainsClassName("PortalAuthenticationConfig")); + securityPortalPojoClasses = PojoClassFactory.getPojoClassesRecursively(packageName, + filterChainByClassNameForSecurityPortal); + validateAll(securityPortalPojoClasses); + } + + + @Test + public void validateSynchronizer() { + + String packageName = "org.onap.aai.sparky.synchronizer"; + List synchronizerPojoClasses; + + FilterChain filterChainByClassNameForSynchronizer = + new FilterChain(new FilterByContainsClassName("Test"), + new FilterByContainsClassName("AggregationSynchronizer"), + new FilterByContainsClassName("SearchableEntitySynchronizer"), + new FilterByContainsClassName("AutosuggestionSynchronizer"), + new FilterByContainsClassName("CrossEntityReferenceSynchronizer"), + new FilterByContainsClassName("SyncController"), + new FilterByContainsClassName("SyncHelper"), + new FilterByContainsClassName("TransactionRateController"), + new FilterByContainsClassName("AggregationSuggestionSynchronizer"), + new FilterByContainsClassName("AbstractEntitySynchronizer"), + new FilterByContainsClassName("SynchronizerConfiguration")); + synchronizerPojoClasses = PojoClassFactory.getPojoClassesRecursively(packageName, + filterChainByClassNameForSynchronizer); + validateAll(synchronizerPojoClasses); + } + + @Test + public void validateUtil() { + + String packageName = "org.onap.aai.sparky.util"; + List utilPojoClasses; + + FilterChain filterChainByClassNameForUtil = new FilterChain( + new FilterByContainsClassName("KeystoreBuilder"), new FilterByContainsClassName("Test"), + new FilterByContainsClassName("HttpServletHelper"), + new FilterByContainsClassName("NodeUtils"), + new FilterByContainsClassName("CaptureLoggerAppender"), + new FilterByContainsClassName("ElasticEntitySummarizer"), + new FilterByContainsClassName("ElasticGarbageInjector"), + new FilterByContainsClassName("SuggestionsPermutation"), + new FilterByContainsClassName("savingTrustManager")); + utilPojoClasses = + PojoClassFactory.getPojoClassesRecursively(packageName, filterChainByClassNameForUtil); + validateAll(utilPojoClasses); + } + + @Test + public void validateViewAndInspect() { + + String packageName = "org.onap.aai.sparky.viewandinspect"; + List viewAndInspectPojoClasses; + + FilterChain filterChainByClassNameForViewAndInspect = + new FilterChain(new FilterByContainsClassName("Test"), + new FilterByContainsClassName("PerformSelfLinkDetermination"), + new FilterByContainsClassName("PerformNodeSelfLinkProcessingTask"), + new FilterByContainsClassName("ActiveInventoryNode"), + new FilterByContainsClassName("NodeProcessingTransaction"), + new FilterByContainsClassName("VisualizationServlet"), + new FilterByContainsClassName("VisualizationService"), + new FilterByContainsClassName("VisualizationContext")); + viewAndInspectPojoClasses = PojoClassFactory.getPojoClassesRecursively(packageName, + filterChainByClassNameForViewAndInspect); + validateAll(viewAndInspectPojoClasses); + } + + public void validateAll(List pojoClasses) { + + Validator validator = + ValidatorBuilder.create().with(new SetterMustExistRule(), new GetterMustExistRule()) + .with(new SetterTester(), new GetterTester()).build(); + validator.validate(pojoClasses); + } + +} diff --git a/src/test/java/org/onap/aai/sparky/analytics/AbstractStatisticsTest.java b/src/test/java/org/onap/aai/sparky/analytics/AbstractStatisticsTest.java index a420e1d..c2ab18f 100644 --- a/src/test/java/org/onap/aai/sparky/analytics/AbstractStatisticsTest.java +++ b/src/test/java/org/onap/aai/sparky/analytics/AbstractStatisticsTest.java @@ -5,42 +5,42 @@ import org.junit.Test; public class AbstractStatisticsTest { - @Test - public void testAllMethods() { - AbstractStatistics abs = new AbstractStatistics(); - - int counterValue1 = abs.getCounterValue("key"); - Assert.assertEquals(-1, counterValue1); - - abs.addCounter("key"); - int counterValue2 = abs.getCounterValue("key"); - Assert.assertEquals(0, counterValue2); - - abs.pegCounter("key"); - int counterValue3 = abs.getCounterValue("key"); - Assert.assertEquals(1, counterValue3); - - abs.incrementCounter("key", 2); - int counterValue4 = abs.getCounterValue("key"); - Assert.assertEquals(3, counterValue4); - - String histStat1 = abs.getHistogramStats("key", false, " "); - Assert.assertNull(histStat1); - - abs.addHistogram("key", "hist1", 10, 1, 2); - String histStat2 = abs.getHistogramStats("key", false, " "); - Assert.assertEquals(" hist1,-1,0,0,0,1,10.00,0",histStat2); - - abs.updateHistogram("key", 3); - String histStat3 = abs.getHistogramStats("key", false, " "); - Assert.assertEquals(" hist1,3,3,3,1,1,10.00,1",histStat3); - - abs.reset(); - int counterValue5 = abs.getCounterValue("key"); - String histStat4 = abs.getHistogramStats("key", false, " "); - Assert.assertEquals(0, counterValue5); - Assert.assertEquals(" hist1,-1,0,0,0,1,10.00,0",histStat4); - - - } + @Test + public void testAllMethods() { + AbstractStatistics abs = new AbstractStatistics(); + + int counterValue1 = abs.getCounterValue("key"); + Assert.assertEquals(-1, counterValue1); + + abs.addCounter("key"); + int counterValue2 = abs.getCounterValue("key"); + Assert.assertEquals(0, counterValue2); + + abs.pegCounter("key"); + int counterValue3 = abs.getCounterValue("key"); + Assert.assertEquals(1, counterValue3); + + abs.incrementCounter("key", 2); + int counterValue4 = abs.getCounterValue("key"); + Assert.assertEquals(3, counterValue4); + + String histStat1 = abs.getHistogramStats("key", false, " "); + Assert.assertNull(histStat1); + + abs.addHistogram("key", "hist1", 10, 1, 2); + String histStat2 = abs.getHistogramStats("key", false, " "); + Assert.assertEquals(" hist1,-1,0,0,0,1,10.00,0", histStat2); + + abs.updateHistogram("key", 3); + String histStat3 = abs.getHistogramStats("key", false, " "); + Assert.assertEquals(" hist1,3,3,3,1,1,10.00,1", histStat3); + + abs.reset(); + int counterValue5 = abs.getCounterValue("key"); + String histStat4 = abs.getHistogramStats("key", false, " "); + Assert.assertEquals(0, counterValue5); + Assert.assertEquals(" hist1,-1,0,0,0,1,10.00,0", histStat4); + + + } } diff --git a/src/test/java/org/onap/aai/sparky/analytics/AveragingRingBufferTest.java b/src/test/java/org/onap/aai/sparky/analytics/AveragingRingBufferTest.java index 4c37c08..89d32ef 100644 --- a/src/test/java/org/onap/aai/sparky/analytics/AveragingRingBufferTest.java +++ b/src/test/java/org/onap/aai/sparky/analytics/AveragingRingBufferTest.java @@ -38,7 +38,7 @@ import org.mockito.runners.MockitoJUnitRunner; /** * The Class AveragingRingBufferTest. */ -@RunWith(MockitoJUnitRunner.class) +@RunWith(MockitoJUnitRunner.class) public class AveragingRingBufferTest { protected SecureRandom random = new SecureRandom(); diff --git a/src/test/java/org/onap/aai/sparky/analytics/HistogramSamplerTest.java b/src/test/java/org/onap/aai/sparky/analytics/HistogramSamplerTest.java index 60a67d5..63d24a6 100644 --- a/src/test/java/org/onap/aai/sparky/analytics/HistogramSamplerTest.java +++ b/src/test/java/org/onap/aai/sparky/analytics/HistogramSamplerTest.java @@ -36,7 +36,7 @@ import org.mockito.runners.MockitoJUnitRunner; /** * The Class HistogramSamplerTest. */ -@RunWith(MockitoJUnitRunner.class) +@RunWith(MockitoJUnitRunner.class) public class HistogramSamplerTest { protected SecureRandom random = new SecureRandom(); diff --git a/src/test/java/org/onap/aai/sparky/analytics/HistoricalCounterTest.java b/src/test/java/org/onap/aai/sparky/analytics/HistoricalCounterTest.java index 9816fff..f8f4b99 100644 --- a/src/test/java/org/onap/aai/sparky/analytics/HistoricalCounterTest.java +++ b/src/test/java/org/onap/aai/sparky/analytics/HistoricalCounterTest.java @@ -5,48 +5,48 @@ import org.junit.Test; public class HistoricalCounterTest { - - @Test - public void testAllMethods() { - HistoricalCounter hc = new HistoricalCounter(true); - - boolean maintainSingleValue = hc.isSingleValue(); - Assert.assertTrue(maintainSingleValue); - - hc.update(1.0); - double value = hc.getValue(); - Assert.assertEquals(1.0, value, 0.1); - - double min = hc.getMin(); - Assert.assertEquals(-1, min, 0.1); - - double max = hc.getMax(); - Assert.assertEquals(0, max, 0.1); - - long numOfSamples = hc.getNumSamples(); - Assert.assertEquals(0, numOfSamples, 0.1); - - double avg = hc.getAvg(); - Assert.assertEquals(0, avg, 0.1); - - String stringValue = hc.toString(); - Assert.assertNotNull(stringValue); - - hc.reset(); - - double valueReset = hc.getValue(); - Assert.assertEquals(0.0, valueReset, 0.1); - - double minReset = hc.getMin(); - Assert.assertEquals(-1, minReset, 0.1); - - double maxReset = hc.getMax(); - Assert.assertEquals(0, maxReset, 0.1); - - long numOfSamplesReset = hc.getNumSamples(); - Assert.assertEquals(0, numOfSamplesReset, 0.1); - - double avgReset = hc.getAvg(); - Assert.assertEquals(0, avgReset, 0.1); - } + + @Test + public void testAllMethods() { + HistoricalCounter hc = new HistoricalCounter(true); + + boolean maintainSingleValue = hc.isSingleValue(); + Assert.assertTrue(maintainSingleValue); + + hc.update(1.0); + double value = hc.getValue(); + Assert.assertEquals(1.0, value, 0.1); + + double min = hc.getMin(); + Assert.assertEquals(-1, min, 0.1); + + double max = hc.getMax(); + Assert.assertEquals(0, max, 0.1); + + long numOfSamples = hc.getNumSamples(); + Assert.assertEquals(0, numOfSamples, 0.1); + + double avg = hc.getAvg(); + Assert.assertEquals(0, avg, 0.1); + + String stringValue = hc.toString(); + Assert.assertNotNull(stringValue); + + hc.reset(); + + double valueReset = hc.getValue(); + Assert.assertEquals(0.0, valueReset, 0.1); + + double minReset = hc.getMin(); + Assert.assertEquals(-1, minReset, 0.1); + + double maxReset = hc.getMax(); + Assert.assertEquals(0, maxReset, 0.1); + + long numOfSamplesReset = hc.getNumSamples(); + Assert.assertEquals(0, numOfSamplesReset, 0.1); + + double avgReset = hc.getAvg(); + Assert.assertEquals(0, avgReset, 0.1); + } } diff --git a/src/test/java/org/onap/aai/sparky/config/oxm/CrossEntityReferenceTest.java b/src/test/java/org/onap/aai/sparky/config/oxm/CrossEntityReferenceTest.java index 205cefd..0ef0458 100644 --- a/src/test/java/org/onap/aai/sparky/config/oxm/CrossEntityReferenceTest.java +++ b/src/test/java/org/onap/aai/sparky/config/oxm/CrossEntityReferenceTest.java @@ -6,22 +6,22 @@ import org.onap.aai.sparky.config.oxm.CrossEntityReference; public class CrossEntityReferenceTest { - - @Test - public void testCrossEntityReferenceAllMethods() { - CrossEntityReference cer = new CrossEntityReference(); - - Assert.assertNull(cer.getTargetEntityType()); - - cer.setTargetEntityType("TET"); - Assert.assertEquals(cer.getTargetEntityType(), "TET"); - - Assert.assertEquals(cer.getReferenceAttributes().size(), 0); - - cer.addReferenceAttribute("AT"); - - Assert.assertEquals(cer.getReferenceAttributes().size(), 1); - - Assert.assertNotNull(cer.toString()); - } + + @Test + public void testCrossEntityReferenceAllMethods() { + CrossEntityReference cer = new CrossEntityReference(); + + Assert.assertNull(cer.getTargetEntityType()); + + cer.setTargetEntityType("TET"); + Assert.assertEquals(cer.getTargetEntityType(), "TET"); + + Assert.assertEquals(cer.getReferenceAttributes().size(), 0); + + cer.addReferenceAttribute("AT"); + + Assert.assertEquals(cer.getReferenceAttributes().size(), 1); + + Assert.assertNotNull(cer.toString()); + } } diff --git a/src/test/java/org/onap/aai/sparky/config/oxm/OxmModelLoaderFilterTest.java b/src/test/java/org/onap/aai/sparky/config/oxm/OxmModelLoaderFilterTest.java index 0c21c03..d971084 100644 --- a/src/test/java/org/onap/aai/sparky/config/oxm/OxmModelLoaderFilterTest.java +++ b/src/test/java/org/onap/aai/sparky/config/oxm/OxmModelLoaderFilterTest.java @@ -18,38 +18,40 @@ import org.onap.aai.sparky.config.oxm.OxmModelLoaderFilter; public class OxmModelLoaderFilterTest { - @Mock - ServletRequest servletRequest; - - @Mock - ServletResponse servletResponse; - - @Mock - FilterChain filterChain; - - @Mock - FilterConfig filterConfig; - - @InjectMocks - OxmModelLoaderFilter oxmModelLoaderFilter; - - @Before - public void init() { - MockitoAnnotations.initMocks(this); - } - - @Test - public void testDoFilter() throws IOException, ServletException{ - Mockito.doNothing().when(filterChain).doFilter(Mockito.any(ServletRequest.class), Mockito.any(ServletResponse.class)); - oxmModelLoaderFilter.doFilter(servletRequest, servletResponse, filterChain); - Mockito.verify(filterChain, Mockito.times(1)).doFilter(Mockito.any(ServletRequest.class), Mockito.any(ServletResponse.class)); - } - - /*This test is taking more than 5 secs. Commented out - @Test - public void testInit() throws ServletException { - OxmModelLoaderFilter oxmFilter = new OxmModelLoaderFilter(); - oxmFilter.init(filterConfig); - }*/ - + @Mock + ServletRequest servletRequest; + + @Mock + ServletResponse servletResponse; + + @Mock + FilterChain filterChain; + + @Mock + FilterConfig filterConfig; + + @InjectMocks + OxmModelLoaderFilter oxmModelLoaderFilter; + + @Before + public void init() { + MockitoAnnotations.initMocks(this); + } + + @Test + public void testDoFilter() throws IOException, ServletException { + Mockito.doNothing().when(filterChain).doFilter(Mockito.any(ServletRequest.class), + Mockito.any(ServletResponse.class)); + oxmModelLoaderFilter.doFilter(servletRequest, servletResponse, filterChain); + Mockito.verify(filterChain, Mockito.times(1)).doFilter(Mockito.any(ServletRequest.class), + Mockito.any(ServletResponse.class)); + } + + /* + * This test is taking more than 5 secs. Commented out + * + * @Test public void testInit() throws ServletException { OxmModelLoaderFilter oxmFilter = new + * OxmModelLoaderFilter(); oxmFilter.init(filterConfig); } + */ + } diff --git a/src/test/java/org/onap/aai/sparky/config/oxm/OxmModelLoaderTest.java b/src/test/java/org/onap/aai/sparky/config/oxm/OxmModelLoaderTest.java index 3ef571e..5ff9e85 100644 --- a/src/test/java/org/onap/aai/sparky/config/oxm/OxmModelLoaderTest.java +++ b/src/test/java/org/onap/aai/sparky/config/oxm/OxmModelLoaderTest.java @@ -32,19 +32,19 @@ import org.mockito.Mockito; public class OxmModelLoaderTest { - OxmModelLoader loader; - - @Test - public void testLoadModel_ShouldSucceed() throws IOException { - String version = "v11"; - System.setProperty("AJSC_HOME", new File(".").getCanonicalPath().replace('\\', '/')); + OxmModelLoader loader; - loader = Mockito.spy(new OxmModelLoader()); - Mockito.when(loader.loadOxmFileName(version)).thenReturn( - System.getProperty("AJSC_HOME") + "/bundleconfig-local/oxm/aai_oxm_" + version + ".xml"); + @Test + public void testLoadModel_ShouldSucceed() throws IOException { + String version = "v11"; + System.setProperty("AJSC_HOME", new File(".").getCanonicalPath().replace('\\', '/')); - loader.loadModel(version); + loader = Mockito.spy(new OxmModelLoader()); + Mockito.when(loader.loadOxmFileName(version)).thenReturn( + System.getProperty("AJSC_HOME") + "/bundleconfig-local/oxm/aai_oxm_" + version + ".xml"); - assertNotEquals(null, loader.getOxmModel()); - } + loader.loadModel(version); + + assertNotEquals(null, loader.getOxmModel()); + } } diff --git a/src/test/java/org/onap/aai/sparky/dal/NetworkTransactionTest.java b/src/test/java/org/onap/aai/sparky/dal/NetworkTransactionTest.java index 0e3c398..f2098fb 100644 --- a/src/test/java/org/onap/aai/sparky/dal/NetworkTransactionTest.java +++ b/src/test/java/org/onap/aai/sparky/dal/NetworkTransactionTest.java @@ -8,29 +8,29 @@ import org.onap.aai.sparky.dal.rest.OperationResult; public class NetworkTransactionTest { - @Test - public void testAllMethods() { - NetworkTransaction ntt = new NetworkTransaction(); - ntt.setOperationType(HttpMethod.GET); - Assert.assertEquals(HttpMethod.GET, ntt.getOperationType()); - - ntt.setTaskAgeInMs(); - Assert.assertNotNull(ntt.getTaskAgeInMs()); - - ntt.setOperationResult(new OperationResult()); - Assert.assertNotNull(ntt.getOperationResult()); - - ntt.setEntityType("entity"); - Assert.assertEquals(ntt.getEntityType(), "entity"); - - ntt.setLink("link"); - Assert.assertEquals(ntt.getLink(), "link"); - - ntt.setDescriptor(new OxmEntityDescriptor()); - Assert.assertNotNull(ntt.getDescriptor()); - - Assert.assertNotNull(ntt.toString()); - } - - + @Test + public void testAllMethods() { + NetworkTransaction ntt = new NetworkTransaction(); + ntt.setOperationType(HttpMethod.GET); + Assert.assertEquals(HttpMethod.GET, ntt.getOperationType()); + + ntt.setTaskAgeInMs(); + Assert.assertNotNull(ntt.getTaskAgeInMs()); + + ntt.setOperationResult(new OperationResult()); + Assert.assertNotNull(ntt.getOperationResult()); + + ntt.setEntityType("entity"); + Assert.assertEquals(ntt.getEntityType(), "entity"); + + ntt.setLink("link"); + Assert.assertEquals(ntt.getLink(), "link"); + + ntt.setDescriptor(new OxmEntityDescriptor()); + Assert.assertNotNull(ntt.getDescriptor()); + + Assert.assertNotNull(ntt.toString()); + } + + } diff --git a/src/test/java/org/onap/aai/sparky/dal/aai/ActiveInventoryAdapterTest.java b/src/test/java/org/onap/aai/sparky/dal/aai/ActiveInventoryAdapterTest.java index 9f18ab2..936bc72 100644 --- a/src/test/java/org/onap/aai/sparky/dal/aai/ActiveInventoryAdapterTest.java +++ b/src/test/java/org/onap/aai/sparky/dal/aai/ActiveInventoryAdapterTest.java @@ -35,68 +35,70 @@ import org.onap.aai.sparky.dal.rest.RestClientBuilder; import org.onap.aai.sparky.viewandinspect.config.TierSupportUiConstants; public class ActiveInventoryAdapterTest { - - OxmModelLoader oxmModelLoader; - ActiveInventoryAdapter adapter; - - @Before - public void init() throws IOException, ElasticSearchOperationException { - String version = "v11"; - System.setProperty("AJSC_HOME", new File(".").getCanonicalPath().replace('\\', '/')); - TierSupportUiConstants.DYNAMIC_CONFIG_APP_LOCATION = System.getProperty("AJSC_HOME")+"/src/test/resources/appconfig/"; - oxmModelLoader = Mockito.spy(new OxmModelLoader()); - Mockito.when(oxmModelLoader.loadOxmFileName(version)).thenReturn( + + OxmModelLoader oxmModelLoader; + ActiveInventoryAdapter adapter; + + @Before + public void init() throws IOException, ElasticSearchOperationException { + String version = "v11"; + System.setProperty("AJSC_HOME", new File(".").getCanonicalPath().replace('\\', '/')); + TierSupportUiConstants.DYNAMIC_CONFIG_APP_LOCATION = + System.getProperty("AJSC_HOME") + "/src/test/resources/appconfig/"; + oxmModelLoader = Mockito.spy(new OxmModelLoader()); + Mockito.when(oxmModelLoader.loadOxmFileName(version)).thenReturn( System.getProperty("AJSC_HOME") + "/bundleconfig-local/oxm/aai_oxm_" + version + ".xml"); - - adapter = new ActiveInventoryAdapter(new RestClientBuilder()); - } - - @Test - public void testQueryActiveInventoryWithRetries() { - - adapter.queryActiveInventoryWithRetries("https://localhost:9517/model/aai/webapp/index.html", "response-type-1", 1); - } - - @Test(expected=NullPointerException.class) - public void testGetSelfLinkForEntity_NullEntityType() throws Exception { - - adapter.getSelfLinkForEntity(null, "key", "value"); - } - - @Test(expected=NullPointerException.class) - public void testGetSelfLinkForEntity_NullKeyName() throws Exception { - - adapter.getSelfLinkForEntity("entity", null, "value"); - } - - @Test(expected=NullPointerException.class) - public void testGetSelfLinkForEntity_NullKeyValue() throws Exception { - - adapter.getSelfLinkForEntity("entity", "key", null); - } - - @Test - public void testGetSelfLinkForEntity_ServiceInstance() throws Exception { - - adapter.getSelfLinkForEntity("service-instance", "key", "value"); - } - - @Test - public void testGetSelfLinkForEntity_NotServiceInstance() throws Exception { - - adapter.getSelfLinkForEntity("service", "key", "value"); - } - - @Test(expected=NullPointerException.class) - public void testGetSelfLinkByEntityType_NullEntity() throws Exception { - - adapter.getSelfLinksByEntityType(null); - } - - @Test(expected=NoSuchElementException.class) - public void testGetSelfLinkByEntityType_NullEntityDescriptor() throws Exception { - - adapter.getSelfLinksByEntityType("entity-1"); - } + + adapter = new ActiveInventoryAdapter(new RestClientBuilder()); + } + + @Test + public void testQueryActiveInventoryWithRetries() { + + adapter.queryActiveInventoryWithRetries("https://localhost:9517/model/aai/webapp/index.html", + "response-type-1", 1); + } + + @Test(expected = NullPointerException.class) + public void testGetSelfLinkForEntity_NullEntityType() throws Exception { + + adapter.getSelfLinkForEntity(null, "key", "value"); + } + + @Test(expected = NullPointerException.class) + public void testGetSelfLinkForEntity_NullKeyName() throws Exception { + + adapter.getSelfLinkForEntity("entity", null, "value"); + } + + @Test(expected = NullPointerException.class) + public void testGetSelfLinkForEntity_NullKeyValue() throws Exception { + + adapter.getSelfLinkForEntity("entity", "key", null); + } + + @Test + public void testGetSelfLinkForEntity_ServiceInstance() throws Exception { + + adapter.getSelfLinkForEntity("service-instance", "key", "value"); + } + + @Test + public void testGetSelfLinkForEntity_NotServiceInstance() throws Exception { + + adapter.getSelfLinkForEntity("service", "key", "value"); + } + + @Test(expected = NullPointerException.class) + public void testGetSelfLinkByEntityType_NullEntity() throws Exception { + + adapter.getSelfLinksByEntityType(null); + } + + @Test(expected = NoSuchElementException.class) + public void testGetSelfLinkByEntityType_NullEntityDescriptor() throws Exception { + + adapter.getSelfLinksByEntityType("entity-1"); + } } diff --git a/src/test/java/org/onap/aai/sparky/dal/aai/ActiveInventoryEntityStatisticsTest.java b/src/test/java/org/onap/aai/sparky/dal/aai/ActiveInventoryEntityStatisticsTest.java index b1357c4..f861a68 100644 --- a/src/test/java/org/onap/aai/sparky/dal/aai/ActiveInventoryEntityStatisticsTest.java +++ b/src/test/java/org/onap/aai/sparky/dal/aai/ActiveInventoryEntityStatisticsTest.java @@ -14,62 +14,62 @@ import org.onap.aai.sparky.dal.rest.OperationResult; public class ActiveInventoryEntityStatisticsTest { - OxmModelLoader oxmModelLoader; - - @Before - public void init() { - oxmModelLoader = OxmModelLoader.getInstance(); - } - - @Test - public void testInitializeCountersFromOxmEntityDescriptors_NotNullDescriptors() { - ActiveInventoryEntityStatistics aies = new ActiveInventoryEntityStatistics(oxmModelLoader); - - Map descriptors = new HashMap<>(); - - OxmEntityDescriptor oxmEd = new OxmEntityDescriptor(); - oxmEd.setEntityName("entity-1"); - oxmEd.setGeoLatName("geoLatName-1"); - - descriptors.put("entity-1", oxmEd); - - aies.initializeCountersFromOxmEntityDescriptors(descriptors); - - aies.reset(); - - } - - @Test - public void testInitializeCountersFromOxmEntityDescriptors_NullDescriptors() { - ActiveInventoryEntityStatistics aies = new ActiveInventoryEntityStatistics(oxmModelLoader); - - Map descriptors = null; - - aies.initializeCountersFromOxmEntityDescriptors(descriptors); - - } - - @Test - public void testUpdateCounters() { - - ActiveInventoryEntityStatistics aies = new ActiveInventoryEntityStatistics(oxmModelLoader); - Map descriptors = new HashMap<>(); - OxmEntityDescriptor oxmEd = new OxmEntityDescriptor(); - oxmEd.setEntityName("entity-1"); - oxmEd.setGeoLatName("geoLatName-1"); - descriptors.put("entity-1", oxmEd); - aies.initializeCountersFromOxmEntityDescriptors(descriptors); - - OperationResult result = new OperationResult(); - result.setResultCode(200); - result.setResult("result-1"); - result.setNumRequestRetries(1); - NetworkTransaction ntwTxn = new NetworkTransaction(HttpMethod.GET, "entity-1", result); - - aies.updateCounters(ntwTxn); - - String statistics = aies.getStatisticsReport(); - Assert.assertNotNull(statistics); - - } + OxmModelLoader oxmModelLoader; + + @Before + public void init() { + oxmModelLoader = OxmModelLoader.getInstance(); + } + + @Test + public void testInitializeCountersFromOxmEntityDescriptors_NotNullDescriptors() { + ActiveInventoryEntityStatistics aies = new ActiveInventoryEntityStatistics(oxmModelLoader); + + Map descriptors = new HashMap<>(); + + OxmEntityDescriptor oxmEd = new OxmEntityDescriptor(); + oxmEd.setEntityName("entity-1"); + oxmEd.setGeoLatName("geoLatName-1"); + + descriptors.put("entity-1", oxmEd); + + aies.initializeCountersFromOxmEntityDescriptors(descriptors); + + aies.reset(); + + } + + @Test + public void testInitializeCountersFromOxmEntityDescriptors_NullDescriptors() { + ActiveInventoryEntityStatistics aies = new ActiveInventoryEntityStatistics(oxmModelLoader); + + Map descriptors = null; + + aies.initializeCountersFromOxmEntityDescriptors(descriptors); + + } + + @Test + public void testUpdateCounters() { + + ActiveInventoryEntityStatistics aies = new ActiveInventoryEntityStatistics(oxmModelLoader); + Map descriptors = new HashMap<>(); + OxmEntityDescriptor oxmEd = new OxmEntityDescriptor(); + oxmEd.setEntityName("entity-1"); + oxmEd.setGeoLatName("geoLatName-1"); + descriptors.put("entity-1", oxmEd); + aies.initializeCountersFromOxmEntityDescriptors(descriptors); + + OperationResult result = new OperationResult(); + result.setResultCode(200); + result.setResult("result-1"); + result.setNumRequestRetries(1); + NetworkTransaction ntwTxn = new NetworkTransaction(HttpMethod.GET, "entity-1", result); + + aies.updateCounters(ntwTxn); + + String statistics = aies.getStatisticsReport(); + Assert.assertNotNull(statistics); + + } } diff --git a/src/test/java/org/onap/aai/sparky/dal/aai/ActiveInventoryProcessingExceptionStatisticsTest.java b/src/test/java/org/onap/aai/sparky/dal/aai/ActiveInventoryProcessingExceptionStatisticsTest.java index 5677f4c..2b65655 100644 --- a/src/test/java/org/onap/aai/sparky/dal/aai/ActiveInventoryProcessingExceptionStatisticsTest.java +++ b/src/test/java/org/onap/aai/sparky/dal/aai/ActiveInventoryProcessingExceptionStatisticsTest.java @@ -8,53 +8,55 @@ import org.onap.aai.sparky.dal.rest.OperationResult; public class ActiveInventoryProcessingExceptionStatisticsTest { - - @Test - public void testUpdateCounters() { - ActiveInventoryProcessingExceptionStatistics aipes = new ActiveInventoryProcessingExceptionStatistics(); - - aipes.incrementCounter("NativeSocketConnectException", 1); - aipes.incrementCounter("NativeSocketConnectionReset", 1); - aipes.incrementCounter("NativeSocketConnectionRefused", 1); - aipes.incrementCounter("JerseyClientTimoutException", 1); - aipes.incrementCounter("UnknownException", 1); - - OperationResult result = new OperationResult(); - result.setResultCode(310); - result.setResult("java.net.SocketTimeoutException: connect timed out"); - result.setNumRequestRetries(1); - NetworkTransaction ntwTxn1 = new NetworkTransaction(HttpMethod.GET, "entity-1", result); - aipes.updateCounters(ntwTxn1); - - result.setResult("result-1"); - NetworkTransaction ntwTxn2 = new NetworkTransaction(HttpMethod.GET, "entity-1", result); - aipes.updateCounters(ntwTxn2); - - result.setResult("java.net.ConnectException: Connection timed out: connect"); - NetworkTransaction ntwTxn3 = new NetworkTransaction(HttpMethod.GET, "entity-1", result); - aipes.updateCounters(ntwTxn3); - - result.setResult("java.net.ConnectException: Connection refused: connect"); - NetworkTransaction ntwTxn4 = new NetworkTransaction(HttpMethod.GET, "entity-1", result); - aipes.updateCounters(ntwTxn4); - - result.setResult("java.net.SocketException: Connection reset"); - NetworkTransaction ntwTxn5 = new NetworkTransaction(HttpMethod.GET, "entity-1", result); - aipes.updateCounters(ntwTxn5); - - } - - @Test - public void testGetStatisticsReport() { - ActiveInventoryProcessingExceptionStatistics aipes = new ActiveInventoryProcessingExceptionStatistics(); - - aipes.incrementCounter("NativeSocketConnectException", 1); - aipes.incrementCounter("NativeSocketConnectionReset", 1); - aipes.incrementCounter("NativeSocketConnectionRefused", 1); - aipes.incrementCounter("JerseyClientTimoutException", 1); - aipes.incrementCounter("UnknownException", 1); - - String statReport = aipes.getStatisticsReport(); - Assert.assertNotNull(statReport); - } + + @Test + public void testUpdateCounters() { + ActiveInventoryProcessingExceptionStatistics aipes = + new ActiveInventoryProcessingExceptionStatistics(); + + aipes.incrementCounter("NativeSocketConnectException", 1); + aipes.incrementCounter("NativeSocketConnectionReset", 1); + aipes.incrementCounter("NativeSocketConnectionRefused", 1); + aipes.incrementCounter("JerseyClientTimoutException", 1); + aipes.incrementCounter("UnknownException", 1); + + OperationResult result = new OperationResult(); + result.setResultCode(310); + result.setResult("java.net.SocketTimeoutException: connect timed out"); + result.setNumRequestRetries(1); + NetworkTransaction ntwTxn1 = new NetworkTransaction(HttpMethod.GET, "entity-1", result); + aipes.updateCounters(ntwTxn1); + + result.setResult("result-1"); + NetworkTransaction ntwTxn2 = new NetworkTransaction(HttpMethod.GET, "entity-1", result); + aipes.updateCounters(ntwTxn2); + + result.setResult("java.net.ConnectException: Connection timed out: connect"); + NetworkTransaction ntwTxn3 = new NetworkTransaction(HttpMethod.GET, "entity-1", result); + aipes.updateCounters(ntwTxn3); + + result.setResult("java.net.ConnectException: Connection refused: connect"); + NetworkTransaction ntwTxn4 = new NetworkTransaction(HttpMethod.GET, "entity-1", result); + aipes.updateCounters(ntwTxn4); + + result.setResult("java.net.SocketException: Connection reset"); + NetworkTransaction ntwTxn5 = new NetworkTransaction(HttpMethod.GET, "entity-1", result); + aipes.updateCounters(ntwTxn5); + + } + + @Test + public void testGetStatisticsReport() { + ActiveInventoryProcessingExceptionStatistics aipes = + new ActiveInventoryProcessingExceptionStatistics(); + + aipes.incrementCounter("NativeSocketConnectException", 1); + aipes.incrementCounter("NativeSocketConnectionReset", 1); + aipes.incrementCounter("NativeSocketConnectionRefused", 1); + aipes.incrementCounter("JerseyClientTimoutException", 1); + aipes.incrementCounter("UnknownException", 1); + + String statReport = aipes.getStatisticsReport(); + Assert.assertNotNull(statReport); + } } diff --git a/src/test/java/org/onap/aai/sparky/dal/aai/config/ActiveInventoryConfigTest.java b/src/test/java/org/onap/aai/sparky/dal/aai/config/ActiveInventoryConfigTest.java index 0166550..9a590b8 100644 --- a/src/test/java/org/onap/aai/sparky/dal/aai/config/ActiveInventoryConfigTest.java +++ b/src/test/java/org/onap/aai/sparky/dal/aai/config/ActiveInventoryConfigTest.java @@ -42,83 +42,83 @@ public class ActiveInventoryConfigTest { assertNotNull(config); } - + private Properties getTestProperties() { - + Properties props = new Properties(); - - props.put("aai.rest.host","aai-host"); - props.put("aai.rest.port","8443"); - props.put("aai.rest.resourceBasePath","/aai/v10"); - props.put("aai.rest.connectTimeoutInMs","30000"); - props.put("aai.rest.readTimeoutInMs","60000"); - props.put("aai.rest.numRequestRetries","5"); - props.put("aai.rest.numResolverWorkers","15"); - - props.put("aai.rest.cache.enabled","false"); - props.put("aai.rest.cache.numWorkers","10"); - props.put("aai.rest.cache.cacheFailures","false"); - props.put("aai.rest.cache.useCacheOnly","false"); - props.put("aai.rest.cache.storageFolderOverride",""); - props.put("aai.rest.cache.maxTimeToLiveInMs","-1"); - - props.put("aai.rest.shallowEntities","cloud-region,complex,vnf-image,image"); - - props.put("aai.ssl.truststore.filename","synchronizer.jks"); - props.put("aai.ssl.truststore.type","jks"); - - props.put("aai.ssl.keystore.filename","aai-client-cert.p12"); - props.put("aai.ssl.keystore.pass","70c87528c88dcd9f9c2558d30e817868"); - props.put("aai.ssl.keystore.type","pkcs12"); - - props.put("aai.ssl.enableDebug","false"); - props.put("aai.ssl.validateServerHostName","false"); - props.put("aai.ssl.validateServerCertificateChain","false"); - - props.put("aai.rest.authenticationMode","SSL_CERT"); - props.put("aai.ssl.basicAuth.username",""); - props.put("aai.ssl.basicAuth.password",""); - - props.put("aai.taskProcessor.maxConcurrentWorkers","5"); - - props.put("aai.taskProcessor.transactionRateControllerEnabled","false"); - props.put("aai.taskProcessor.numSamplesPerThreadForRunningAverage","100"); - props.put("aai.taskProcessor.targetTPS","100"); - - props.put("aai.taskProcessor.bytesHistogramLabel","[Response Size In Bytes]"); - props.put("aai.taskProcessor.bytesHistogramMaxYAxis","1000000"); - props.put("aai.taskProcessor.bytesHistogramNumBins","20"); - props.put("aai.taskProcessor.bytesHistogramNumDecimalPoints","2"); - - props.put("aai.taskProcessor.queueLengthHistogramLabel","[Queue Item Length]"); - props.put("aai.taskProcessor.queueLengthHistogramMaxYAxis","20000"); - props.put("aai.taskProcessor.queueLengthHistogramNumBins","20"); - props.put("aai.taskProcessor.queueLengthHistogramNumDecimalPoints","2"); - - props.put("aai.taskProcessor.taskAgeHistogramLabel","[Task Age In Ms]"); - props.put("aai.taskProcessor.taskAgeHistogramMaxYAxis","600000"); - props.put("aai.taskProcessor.taskAgeHistogramNumBins","20"); - props.put("aai.taskProcessor.taskAgeHistogramNumDecimalPoints","2"); - - props.put("aai.taskProcessor.responseTimeHistogramLabel","[Response Time In Ms]"); - props.put("aai.taskProcessor.responseTimeHistogramMaxYAxis","10000"); - props.put("aai.taskProcessor.responseTimeHistogramNumBins","20"); - props.put("aai.taskProcessor.responseTimeHistogramNumDecimalPoints","2"); - - props.put("aai.taskProcessor.tpsHistogramLabel","[Transactions Per Second]"); - props.put("aai.taskProcessor.tpsHistogramMaxYAxis","100"); - props.put("aai.taskProcessor.tpsHistogramNumBins","20"); - props.put("aai.taskProcessor.tpsHistogramNumDecimalPoints","2"); - - + + props.put("aai.rest.host", "aai-host"); + props.put("aai.rest.port", "8443"); + props.put("aai.rest.resourceBasePath", "/aai/v10"); + props.put("aai.rest.connectTimeoutInMs", "30000"); + props.put("aai.rest.readTimeoutInMs", "60000"); + props.put("aai.rest.numRequestRetries", "5"); + props.put("aai.rest.numResolverWorkers", "15"); + + props.put("aai.rest.cache.enabled", "false"); + props.put("aai.rest.cache.numWorkers", "10"); + props.put("aai.rest.cache.cacheFailures", "false"); + props.put("aai.rest.cache.useCacheOnly", "false"); + props.put("aai.rest.cache.storageFolderOverride", ""); + props.put("aai.rest.cache.maxTimeToLiveInMs", "-1"); + + props.put("aai.rest.shallowEntities", "cloud-region,complex,vnf-image,image"); + + props.put("aai.ssl.truststore.filename", "synchronizer.jks"); + props.put("aai.ssl.truststore.type", "jks"); + + props.put("aai.ssl.keystore.filename", "aai-client-cert.p12"); + props.put("aai.ssl.keystore.pass", "70c87528c88dcd9f9c2558d30e817868"); + props.put("aai.ssl.keystore.type", "pkcs12"); + + props.put("aai.ssl.enableDebug", "false"); + props.put("aai.ssl.validateServerHostName", "false"); + props.put("aai.ssl.validateServerCertificateChain", "false"); + + props.put("aai.rest.authenticationMode", "SSL_CERT"); + props.put("aai.ssl.basicAuth.username", ""); + props.put("aai.ssl.basicAuth.password", ""); + + props.put("aai.taskProcessor.maxConcurrentWorkers", "5"); + + props.put("aai.taskProcessor.transactionRateControllerEnabled", "false"); + props.put("aai.taskProcessor.numSamplesPerThreadForRunningAverage", "100"); + props.put("aai.taskProcessor.targetTPS", "100"); + + props.put("aai.taskProcessor.bytesHistogramLabel", "[Response Size In Bytes]"); + props.put("aai.taskProcessor.bytesHistogramMaxYAxis", "1000000"); + props.put("aai.taskProcessor.bytesHistogramNumBins", "20"); + props.put("aai.taskProcessor.bytesHistogramNumDecimalPoints", "2"); + + props.put("aai.taskProcessor.queueLengthHistogramLabel", "[Queue Item Length]"); + props.put("aai.taskProcessor.queueLengthHistogramMaxYAxis", "20000"); + props.put("aai.taskProcessor.queueLengthHistogramNumBins", "20"); + props.put("aai.taskProcessor.queueLengthHistogramNumDecimalPoints", "2"); + + props.put("aai.taskProcessor.taskAgeHistogramLabel", "[Task Age In Ms]"); + props.put("aai.taskProcessor.taskAgeHistogramMaxYAxis", "600000"); + props.put("aai.taskProcessor.taskAgeHistogramNumBins", "20"); + props.put("aai.taskProcessor.taskAgeHistogramNumDecimalPoints", "2"); + + props.put("aai.taskProcessor.responseTimeHistogramLabel", "[Response Time In Ms]"); + props.put("aai.taskProcessor.responseTimeHistogramMaxYAxis", "10000"); + props.put("aai.taskProcessor.responseTimeHistogramNumBins", "20"); + props.put("aai.taskProcessor.responseTimeHistogramNumDecimalPoints", "2"); + + props.put("aai.taskProcessor.tpsHistogramLabel", "[Transactions Per Second]"); + props.put("aai.taskProcessor.tpsHistogramMaxYAxis", "100"); + props.put("aai.taskProcessor.tpsHistogramNumBins", "20"); + props.put("aai.taskProcessor.tpsHistogramNumDecimalPoints", "2"); + + return props; - - + + } @Test public void validateAccessors() throws Exception { - + ActiveInventoryConfig config = new ActiveInventoryConfig(getTestProperties()); ActiveInventoryRestConfig airc = config.getAaiRestConfig(); @@ -190,7 +190,7 @@ public class ActiveInventoryConfigTest { assertEquals("https://aai-host:9191/aai/v10/business/customers/customer/1234", config.repairSelfLink("/aai/v10/business/customers/customer/1234")); } - + @Test public void validateResourcePathExtraction() throws Exception { // https with API version @@ -210,15 +210,14 @@ public class ActiveInventoryConfigTest { .extractResourcePath("http://aai-host:9191/business/customers/customer/1234")); // no scheme, host, or port - assertEquals("business/customers/customer/1234", ActiveInventoryConfig - .extractResourcePath("business/customers/customer/1234")); + assertEquals("business/customers/customer/1234", + ActiveInventoryConfig.extractResourcePath("business/customers/customer/1234")); // no scheme, host, or port with API version - assertEquals("/aai/v10/business/customers/customer/1234", ActiveInventoryConfig - .extractResourcePath("/aai/v10/business/customers/customer/1234")); + assertEquals("/aai/v10/business/customers/customer/1234", + ActiveInventoryConfig.extractResourcePath("/aai/v10/business/customers/customer/1234")); // no scheme, host, or port with API version - assertEquals("", ActiveInventoryConfig - .extractResourcePath("")); + assertEquals("", ActiveInventoryConfig.extractResourcePath("")); } -} \ No newline at end of file +} diff --git a/src/test/java/org/onap/aai/sparky/dal/aai/config/ActiveInventorySslConfigTest.java b/src/test/java/org/onap/aai/sparky/dal/aai/config/ActiveInventorySslConfigTest.java index e02a6a7..d6bcf99 100644 --- a/src/test/java/org/onap/aai/sparky/dal/aai/config/ActiveInventorySslConfigTest.java +++ b/src/test/java/org/onap/aai/sparky/dal/aai/config/ActiveInventorySslConfigTest.java @@ -65,8 +65,11 @@ public class ActiveInventorySslConfigTest { props.put("aai.ssl.validateServiceCertificateChain", "false"); props.put("aai.ssl.keystore.type", "pkcs12"); props.put("aai.ssl.keystore.filename", "/opt/app/applocal/etc/cert.crt"); - /*props.put("aai.ssl.keystore.pass", encryptor.decryptValue(value)EncryptedConfiguration.encryptToTriple("AES", - Long.toString(123456789 % 10000), "aa1admin", "password"));*/ + /* + * props.put("aai.ssl.keystore.pass", + * encryptor.decryptValue(value)EncryptedConfiguration.encryptToTriple("AES", + * Long.toString(123456789 % 10000), "aa1admin", "password")); + */ props.put("aai.ssl.truststore.type", "jks"); props.put("aai.ssl.truststore.filename", "/opt/app/applocal/etc/cert.crt"); props.put("aai.ssl.basicAuth.username", "username"); @@ -196,15 +199,15 @@ public class ActiveInventorySslConfigTest { assertFalse(config.isValidateServerHostName()); assertFalse(config.isValidateServerCertificateChain()); - assertEquals(config.getKeystoreType(),"invalid"); + assertEquals(config.getKeystoreType(), "invalid"); assertTrue(config.getKeystoreFilename().contains("null")); - assertEquals(config.getKeystorePassword(),""); + assertEquals(config.getKeystorePassword(), ""); - assertEquals(config.getTruststoreType(),"invalid"); + assertEquals(config.getTruststoreType(), "invalid"); assertTrue(config.getTruststoreFilename().contains("null")); - assertEquals(config.getBasicAuthUsername(),"invalid"); - assertEquals(config.getBasicAuthPassword(),"invalid"); + assertEquals(config.getBasicAuthUsername(), "invalid"); + assertEquals(config.getBasicAuthPassword(), "invalid"); assertEquals(config.getBasicAuthenticationCredentials(), generateAuthorizationHeaderValue("invalid", "invalid")); @@ -240,30 +243,30 @@ public class ActiveInventorySslConfigTest { config.setEncryptor(encryptorMock); config.setValidateServerCertificateChain(true); config.setValidateServerHostName(true); - + assertEquals(System.getProperty("javax.net.debug"), "ssl"); assertTrue(config.isValidateServerHostName()); assertTrue(config.isValidateServerCertificateChain()); - assertEquals(config.getKeystoreType(),"test"); + assertEquals(config.getKeystoreType(), "test"); assertTrue(config.getKeystoreFilename().contains("test")); - assertEquals(config.getKeystorePassword(),"test"); + assertEquals(config.getKeystorePassword(), "test"); - assertEquals(config.getTruststoreType(),"test"); + assertEquals(config.getTruststoreType(), "test"); assertTrue(config.getTruststoreFilename().contains("test")); - assertEquals(config.getBasicAuthUsername(),"test"); - assertEquals(config.getBasicAuthPassword(),"test"); + assertEquals(config.getBasicAuthUsername(), "test"); + assertEquals(config.getBasicAuthPassword(), "test"); assertEquals(config.getBasicAuthenticationCredentials(), generateAuthorizationHeaderValue("test", "test")); - + assertNotNull(config.getEncryptor()); - + assertTrue(config.toString().contains("ActiveInventorySslConfig")); - - + + } - - - + + + } diff --git a/src/test/java/org/onap/aai/sparky/dal/cache/InMemoryEntityCacheTest.java b/src/test/java/org/onap/aai/sparky/dal/cache/InMemoryEntityCacheTest.java index 45481ce..2beb36b 100644 --- a/src/test/java/org/onap/aai/sparky/dal/cache/InMemoryEntityCacheTest.java +++ b/src/test/java/org/onap/aai/sparky/dal/cache/InMemoryEntityCacheTest.java @@ -6,21 +6,21 @@ import org.onap.aai.sparky.dal.rest.OperationResult; public class InMemoryEntityCacheTest { - @Test - public void testInMemoryEntityCache_AllMethods() { - - InMemoryEntityCache imec = new InMemoryEntityCache(); - - imec.put("key-1", null); - Assert.assertNull(imec.get("entity-1", "key-1")); - Assert.assertNull(imec.get("entity-1", null)); - - OperationResult result = new OperationResult(); - result.setResultCode(200); - result.setResult("result-1"); - result.setNumRequestRetries(1); - - imec.put("key-1", result); - Assert.assertNotNull(imec.get("entity-1", "key-1")); - } + @Test + public void testInMemoryEntityCache_AllMethods() { + + InMemoryEntityCache imec = new InMemoryEntityCache(); + + imec.put("key-1", null); + Assert.assertNull(imec.get("entity-1", "key-1")); + Assert.assertNull(imec.get("entity-1", null)); + + OperationResult result = new OperationResult(); + result.setResultCode(200); + result.setResult("result-1"); + result.setNumRequestRetries(1); + + imec.put("key-1", result); + Assert.assertNotNull(imec.get("entity-1", "key-1")); + } } diff --git a/src/test/java/org/onap/aai/sparky/dal/elasticsearch/ElasticSearchConfigTest.java b/src/test/java/org/onap/aai/sparky/dal/elasticsearch/ElasticSearchConfigTest.java index 5de9e2f..01a5bb0 100644 --- a/src/test/java/org/onap/aai/sparky/dal/elasticsearch/ElasticSearchConfigTest.java +++ b/src/test/java/org/onap/aai/sparky/dal/elasticsearch/ElasticSearchConfigTest.java @@ -48,30 +48,30 @@ import ch.qos.logback.classic.Level; public class ElasticSearchConfigTest { private static final String GOOD_MAPPINGS_FILE = - "{" + "\"properties\": {" + "\"entityType\": {" + "\"type\": \"string\"" + "}," - + "\"edgeTagQueryEntityFieldName\": {" + "\"type\": \"string\"," + "\"index\": \"no\"" - + "}," + "\"edgeTagQueryEntityFieldValue\": {" + "\"type\": \"string\"," - + "\"index\": \"no\"" + "}," + "\"searchTagIDs\" : {" + "\"type\" : \"string\"" + "}," - + "\"searchTags\": {" + "\"type\": \"string\"," + "\"analyzer\": \"nGram_analyzer\"," - + "\"search_analyzer\": \"whitespace_analyzer\"}" + "}" + "}"; + "{" + "\"properties\": {" + "\"entityType\": {" + "\"type\": \"string\"" + "}," + + "\"edgeTagQueryEntityFieldName\": {" + "\"type\": \"string\"," + "\"index\": \"no\"" + + "}," + "\"edgeTagQueryEntityFieldValue\": {" + "\"type\": \"string\"," + + "\"index\": \"no\"" + "}," + "\"searchTagIDs\" : {" + "\"type\" : \"string\"" + "}," + + "\"searchTags\": {" + "\"type\": \"string\"," + "\"analyzer\": \"nGram_analyzer\"," + + "\"search_analyzer\": \"whitespace_analyzer\"}" + "}" + "}"; private static final String GOOD_SETTINGS_FILE = "{\"analysis\": {" + "\"filter\": {" - + "\"nGram_filter\": {" + "\"type\": \"nGram\"," + "\"min_gram\": 1," + "\"max_gram\": 50," - + "\"token_chars\": [" + "\"letter\"," + "\"digit\"," + "\"punctuation\"," + "\"symbol\"" - + "]}}," + "\"analyzer\": {" + "\"nGram_analyzer\": {" + "\"type\": \"custom\"," - + "\"tokenizer\": \"whitespace\"," + "\"filter\": [" + "\"lowercase\"," + "\"asciifolding\"," - + "\"nGram_filter\"]}," + "\"whitespace_analyzer\": {" + "\"type\": \"custom\"," - + "\"tokenizer\": \"whitespace\"," + "\"filter\": [" + "\"lowercase\"," - + "\"asciifolding\"]}}}}"; + + "\"nGram_filter\": {" + "\"type\": \"nGram\"," + "\"min_gram\": 1," + "\"max_gram\": 50," + + "\"token_chars\": [" + "\"letter\"," + "\"digit\"," + "\"punctuation\"," + "\"symbol\"" + + "]}}," + "\"analyzer\": {" + "\"nGram_analyzer\": {" + "\"type\": \"custom\"," + + "\"tokenizer\": \"whitespace\"," + "\"filter\": [" + "\"lowercase\"," + "\"asciifolding\"," + + "\"nGram_filter\"]}," + "\"whitespace_analyzer\": {" + "\"type\": \"custom\"," + + "\"tokenizer\": \"whitespace\"," + "\"filter\": [" + "\"lowercase\"," + + "\"asciifolding\"]}}}}"; private static final String BAD_SETTINGS_FILE = "{\"analysis\": {" + "\"filter\": {" - + "\"nGram_filter\": {" + "\"type\": \"nGram\"," + "\"min_gram\": 1," + "\"max_gram\": 50," - + "\"token_chars\": [" + "\"letter\"," + "\"digit\"," + "\"punctuation\"," + "\"symbol\"" - + "]}}," + "\"analyzer\": {" + "\"nGram_analyzer\": {" + "\"type\": \"custom\"," - + "\"tokenizer\": \"whitespace\"," + "\"filter\": [" + "\"lowercase\"," + "\"asciifolding\"," - + "\"nGram_filter\"]}," + "\"whitespace_analyzer\": {" + "\"type\": \"custom\"," - + "\"tokenizer\": \"whitespace\"," + "\"filter\": [" + "\"lowercase\"," - + "\"asciifolding\"]}}"; + + "\"nGram_filter\": {" + "\"type\": \"nGram\"," + "\"min_gram\": 1," + "\"max_gram\": 50," + + "\"token_chars\": [" + "\"letter\"," + "\"digit\"," + "\"punctuation\"," + "\"symbol\"" + + "]}}," + "\"analyzer\": {" + "\"nGram_analyzer\": {" + "\"type\": \"custom\"," + + "\"tokenizer\": \"whitespace\"," + "\"filter\": [" + "\"lowercase\"," + "\"asciifolding\"," + + "\"nGram_filter\"]}," + "\"whitespace_analyzer\": {" + "\"type\": \"custom\"," + + "\"tokenizer\": \"whitespace\"," + "\"filter\": [" + "\"lowercase\"," + + "\"asciifolding\"]}}"; ElasticSearchConfig elasticSearchConfig; @@ -130,12 +130,12 @@ public class ElasticSearchConfigTest { * * @return the elastic search settings expect valid config * @throws IOException Signals that an I/O exception has occurred. - * @throws ElasticSearchOperationException the elastic search operation exception - * Need to revisit this test case and change the way this class works + * @throws ElasticSearchOperationException the elastic search operation exception Need to revisit + * this test case and change the way this class works */ @Ignore public void getElasticSearchSettings_expectValidConfig() - throws IOException, ElasticSearchOperationException { + throws IOException, ElasticSearchOperationException { System.setProperty("AJSC_HOME", new File(".").getCanonicalPath().replace('\\', '/')); ElasticSearchConfig esConfig = new ElasticSearchConfig(); @@ -152,11 +152,11 @@ public class ElasticSearchConfigTest { * @throws IOException Signals that an I/O exception has occurred. * @throws ElasticSearchOperationException the elastic search operation exception * - * Need to revisit this test case and change the way this class works + * Need to revisit this test case and change the way this class works */ @Ignore public void getElasticSearchSettings_expectFileNotFoundException() - throws IOException, ElasticSearchOperationException { + throws IOException, ElasticSearchOperationException { System.setProperty("AJSC_HOME", new File(".").getCanonicalPath().replace('\\', '/')); ElasticSearchConfig esConfig = new ElasticSearchConfig(); @@ -174,11 +174,11 @@ public class ElasticSearchConfigTest { * @throws IOException Signals that an I/O exception has occurred. * @throws ElasticSearchOperationException the elastic search operation exception * - * Need to revisit this test case and change the way this class works + * Need to revisit this test case and change the way this class works */ @Ignore public void getElasticSearchMappings_expectValidConfig() - throws IOException, ElasticSearchOperationException { + throws IOException, ElasticSearchOperationException { System.setProperty("AJSC_HOME", new File(".").getCanonicalPath().replace('\\', '/')); ElasticSearchConfig esConfig = new ElasticSearchConfig(); @@ -197,7 +197,7 @@ public class ElasticSearchConfigTest { */ @Test(expected = ElasticSearchOperationException.class) public void getElasticSearchMappings_expectFileNotFoundException() - throws IOException, ElasticSearchOperationException { + throws IOException, ElasticSearchOperationException { System.setProperty("AJSC_HOME", new File(".").getCanonicalPath().replace('\\', '/')); ElasticSearchConfig esConfig = new ElasticSearchConfig(); @@ -216,7 +216,7 @@ public class ElasticSearchConfigTest { */ @Test public void buildElasticSearchTableConfig_expectValidResult() - throws ElasticSearchOperationException, IOException { + throws ElasticSearchOperationException, IOException { ElasticSearchConfig spyEsConfig = Mockito.spy(new ElasticSearchConfig()); Mockito.doReturn(GOOD_MAPPINGS_FILE).when(spyEsConfig).getElasticSearchMappings(); Mockito.doReturn(GOOD_SETTINGS_FILE).when(spyEsConfig).getElasticSearchSettings(); @@ -233,7 +233,7 @@ public class ElasticSearchConfigTest { */ @Test(expected = ElasticSearchOperationException.class) public void buildElasticSearchTableConfig_expectException() - throws ElasticSearchOperationException, IOException { + throws ElasticSearchOperationException, IOException { ElasticSearchConfig spyEsConfig = Mockito.spy(new ElasticSearchConfig()); Mockito.doReturn(GOOD_MAPPINGS_FILE).when(spyEsConfig).getElasticSearchMappings(); Mockito.doReturn(BAD_SETTINGS_FILE).when(spyEsConfig).getElasticSearchSettings(); @@ -246,7 +246,8 @@ public class ElasticSearchConfigTest { public void testGetFullUrl_ThreeParams() throws Exception { Mockito.when(elasticSearchConfig.getIpAddress()).thenReturn("http://localhost"); Mockito.when(elasticSearchConfig.getHttpPort()).thenReturn("5443"); - String fullUrl = elasticSearchConfig.getElasticFullUrl("http://localhost:5443/aai/model/index", "entity-index", "entity"); + String fullUrl = elasticSearchConfig.getElasticFullUrl("http://localhost:5443/aai/model/index", + "entity-index", "entity"); Assert.assertNotNull(fullUrl); } @@ -260,7 +261,7 @@ public class ElasticSearchConfigTest { } @Test - public void testGetBulkUrl() throws Exception { + public void testGetBulkUrl() throws Exception { Mockito.when(elasticSearchConfig.getIpAddress()).thenReturn("http://localhost"); Mockito.when(elasticSearchConfig.getHttpPort()).thenReturn("5443"); String fullUrl = elasticSearchConfig.getBulkUrl(); @@ -270,7 +271,8 @@ public class ElasticSearchConfigTest { @Test public void testGetConfigAsString() throws IOException, ElasticSearchOperationException { System.setProperty("AJSC_HOME", new File(".").getCanonicalPath().replace('\\', '/')); - String retStr = elasticSearchConfig.getConfigAsString("item-1", System.getProperty("AJSC_HOME")+"/src/test/resources/appconfig/roles.config"); + String retStr = elasticSearchConfig.getConfigAsString("item-1", + System.getProperty("AJSC_HOME") + "/src/test/resources/appconfig/roles.config"); Assert.assertNotNull(retStr); } diff --git a/src/test/java/org/onap/aai/sparky/dal/elasticsearch/ElasticSearchEntityStatisticsTest.java b/src/test/java/org/onap/aai/sparky/dal/elasticsearch/ElasticSearchEntityStatisticsTest.java index 6e4cf8a..92360c7 100644 --- a/src/test/java/org/onap/aai/sparky/dal/elasticsearch/ElasticSearchEntityStatisticsTest.java +++ b/src/test/java/org/onap/aai/sparky/dal/elasticsearch/ElasticSearchEntityStatisticsTest.java @@ -35,67 +35,67 @@ import org.onap.aai.sparky.dal.rest.OperationResult; public class ElasticSearchEntityStatisticsTest { - @Test - public void testInitializeCountersFromOxmEntityDescriptors_NotNullDescriptors() { - - ElasticSearchEntityStatistics eses = new ElasticSearchEntityStatistics(new OxmModelLoader()); - Map descriptors = new HashMap<>(); - - OxmEntityDescriptor oxmEd = new OxmEntityDescriptor(); - oxmEd.setEntityName("entity-1"); - oxmEd.setGeoLatName("geoLatName-1"); - - descriptors.put("entity-1", oxmEd); - - eses.initializeCountersFromOxmEntityDescriptors(descriptors); - eses.reset(); - } - - @Test - public void testInitializeCountersFromOxmEntityDescriptors_NullDescriptors() { - - ElasticSearchEntityStatistics eses = new ElasticSearchEntityStatistics(new OxmModelLoader()); - Map descriptors = null; - eses.initializeCountersFromOxmEntityDescriptors(descriptors); - } - - @Test - public void testUpdateCounters() { - - ElasticSearchEntityStatistics eses = new ElasticSearchEntityStatistics(new OxmModelLoader()); - Map descriptors = new HashMap<>(); - - OxmEntityDescriptor oxmEd = new OxmEntityDescriptor(); - oxmEd.setEntityName("entity-1"); - oxmEd.setGeoLatName("geoLatName-1"); - descriptors.put("entity-1", oxmEd); - - eses.initializeCountersFromOxmEntityDescriptors(descriptors); - - OperationResult result = new OperationResult(); - result.setResultCode(200); - result.setResult("result-1"); - result.setNumRequestRetries(1); - NetworkTransaction ntwTxn = new NetworkTransaction(HttpMethod.PUT, "entity-1", result); - eses.updateCounters(ntwTxn); - - result.setResultCode(201); - NetworkTransaction ntwTxn1 = new NetworkTransaction(HttpMethod.PUT, "entity-1", result); - eses.updateCounters(ntwTxn1); - - result.setResultCode(202); - NetworkTransaction ntwTxn2 = new NetworkTransaction(HttpMethod.PUT, "entity-1", result); - eses.updateCounters(ntwTxn2); - NetworkTransaction ntwTxn3 = new NetworkTransaction(HttpMethod.DELETE, "entity-1", result); - eses.updateCounters(ntwTxn3); - - result.setResultCode(101); - NetworkTransaction ntwTxn4 = new NetworkTransaction(HttpMethod.PUT, "entity-1", result); - eses.updateCounters(ntwTxn4); - NetworkTransaction ntwTxn5 = new NetworkTransaction(HttpMethod.DELETE, "entity-1", result); - eses.updateCounters(ntwTxn5); - - String statistics = eses.getStatisticsReport(); - Assert.assertNotNull(statistics); - } + @Test + public void testInitializeCountersFromOxmEntityDescriptors_NotNullDescriptors() { + + ElasticSearchEntityStatistics eses = new ElasticSearchEntityStatistics(new OxmModelLoader()); + Map descriptors = new HashMap<>(); + + OxmEntityDescriptor oxmEd = new OxmEntityDescriptor(); + oxmEd.setEntityName("entity-1"); + oxmEd.setGeoLatName("geoLatName-1"); + + descriptors.put("entity-1", oxmEd); + + eses.initializeCountersFromOxmEntityDescriptors(descriptors); + eses.reset(); + } + + @Test + public void testInitializeCountersFromOxmEntityDescriptors_NullDescriptors() { + + ElasticSearchEntityStatistics eses = new ElasticSearchEntityStatistics(new OxmModelLoader()); + Map descriptors = null; + eses.initializeCountersFromOxmEntityDescriptors(descriptors); + } + + @Test + public void testUpdateCounters() { + + ElasticSearchEntityStatistics eses = new ElasticSearchEntityStatistics(new OxmModelLoader()); + Map descriptors = new HashMap<>(); + + OxmEntityDescriptor oxmEd = new OxmEntityDescriptor(); + oxmEd.setEntityName("entity-1"); + oxmEd.setGeoLatName("geoLatName-1"); + descriptors.put("entity-1", oxmEd); + + eses.initializeCountersFromOxmEntityDescriptors(descriptors); + + OperationResult result = new OperationResult(); + result.setResultCode(200); + result.setResult("result-1"); + result.setNumRequestRetries(1); + NetworkTransaction ntwTxn = new NetworkTransaction(HttpMethod.PUT, "entity-1", result); + eses.updateCounters(ntwTxn); + + result.setResultCode(201); + NetworkTransaction ntwTxn1 = new NetworkTransaction(HttpMethod.PUT, "entity-1", result); + eses.updateCounters(ntwTxn1); + + result.setResultCode(202); + NetworkTransaction ntwTxn2 = new NetworkTransaction(HttpMethod.PUT, "entity-1", result); + eses.updateCounters(ntwTxn2); + NetworkTransaction ntwTxn3 = new NetworkTransaction(HttpMethod.DELETE, "entity-1", result); + eses.updateCounters(ntwTxn3); + + result.setResultCode(101); + NetworkTransaction ntwTxn4 = new NetworkTransaction(HttpMethod.PUT, "entity-1", result); + eses.updateCounters(ntwTxn4); + NetworkTransaction ntwTxn5 = new NetworkTransaction(HttpMethod.DELETE, "entity-1", result); + eses.updateCounters(ntwTxn5); + + String statistics = eses.getStatisticsReport(); + Assert.assertNotNull(statistics); + } } diff --git a/src/test/java/org/onap/aai/sparky/dal/elasticsearch/entity/AutoSuggestDocumentEntity.java b/src/test/java/org/onap/aai/sparky/dal/elasticsearch/entity/AutoSuggestDocumentEntity.java index dd04248..bab190c 100644 --- a/src/test/java/org/onap/aai/sparky/dal/elasticsearch/entity/AutoSuggestDocumentEntity.java +++ b/src/test/java/org/onap/aai/sparky/dal/elasticsearch/entity/AutoSuggestDocumentEntity.java @@ -38,7 +38,7 @@ public class AutoSuggestDocumentEntity { public void setFields(AutoSuggestDocumentEntityFields fields) { this.fields = fields; } - - - + + + } diff --git a/src/test/java/org/onap/aai/sparky/dal/elasticsearch/entity/AutoSuggestDocumentEntityFields.java b/src/test/java/org/onap/aai/sparky/dal/elasticsearch/entity/AutoSuggestDocumentEntityFields.java index eafef21..7c4c2db 100644 --- a/src/test/java/org/onap/aai/sparky/dal/elasticsearch/entity/AutoSuggestDocumentEntityFields.java +++ b/src/test/java/org/onap/aai/sparky/dal/elasticsearch/entity/AutoSuggestDocumentEntityFields.java @@ -37,7 +37,7 @@ public class AutoSuggestDocumentEntityFields { private List input; private PayloadEntity payload; private int weight; - + public AutoSuggestDocumentEntityFields() { input = new ArrayList(); } @@ -73,9 +73,9 @@ public class AutoSuggestDocumentEntityFields { public void setWeight(int weight) { this.weight = weight; } - + public void addInput(String input) { this.input.add(input); } - + } diff --git a/src/test/java/org/onap/aai/sparky/dal/elasticsearch/entity/AutoSuggestElasticHitsEntity.java b/src/test/java/org/onap/aai/sparky/dal/elasticsearch/entity/AutoSuggestElasticHitsEntity.java index 18dfdc4..13326ab 100644 --- a/src/test/java/org/onap/aai/sparky/dal/elasticsearch/entity/AutoSuggestElasticHitsEntity.java +++ b/src/test/java/org/onap/aai/sparky/dal/elasticsearch/entity/AutoSuggestElasticHitsEntity.java @@ -28,9 +28,9 @@ import java.util.ArrayList; import java.util.List; public class AutoSuggestElasticHitsEntity { - + private List hits; - + public AutoSuggestElasticHitsEntity() { hits = new ArrayList(); } @@ -42,7 +42,7 @@ public class AutoSuggestElasticHitsEntity { public void setHits(List hits) { this.hits = hits; } - + public void addHit(AutoSuggestElasticHitEntity hit) { this.hits.add(hit); } diff --git a/src/test/java/org/onap/aai/sparky/dal/elasticsearch/entity/AutoSuggestElasticSearchResponse.java b/src/test/java/org/onap/aai/sparky/dal/elasticsearch/entity/AutoSuggestElasticSearchResponse.java index 40c9b6d..9dc9709 100644 --- a/src/test/java/org/onap/aai/sparky/dal/elasticsearch/entity/AutoSuggestElasticSearchResponse.java +++ b/src/test/java/org/onap/aai/sparky/dal/elasticsearch/entity/AutoSuggestElasticSearchResponse.java @@ -30,19 +30,19 @@ import java.util.Map; import com.fasterxml.jackson.annotation.JsonProperty; public class AutoSuggestElasticSearchResponse { - + private int took; - + @JsonProperty("timed_out") private boolean timedOut; - + @JsonProperty("_shards") - private Map shards; - + private Map shards; + private AutoSuggestElasticHitsEntity hits; - public AutoSuggestElasticSearchResponse(){ - this.shards = new HashMap(); + public AutoSuggestElasticSearchResponse() { + this.shards = new HashMap(); } public int getTook() { @@ -68,7 +68,7 @@ public class AutoSuggestElasticSearchResponse { public void setShards(Map shards) { this.shards = shards; } - + public void addShard(String name, String value) { shards.put(name, value); } @@ -80,6 +80,6 @@ public class AutoSuggestElasticSearchResponse { public void setHits(AutoSuggestElasticHitsEntity hits) { this.hits = hits; } - - + + } diff --git a/src/test/java/org/onap/aai/sparky/dal/elasticsearch/entity/BucketEntity.java b/src/test/java/org/onap/aai/sparky/dal/elasticsearch/entity/BucketEntity.java index 5a578aa..9b5d27e 100644 --- a/src/test/java/org/onap/aai/sparky/dal/elasticsearch/entity/BucketEntity.java +++ b/src/test/java/org/onap/aai/sparky/dal/elasticsearch/entity/BucketEntity.java @@ -28,19 +28,19 @@ import com.fasterxml.jackson.annotation.JsonProperty; public class BucketEntity { private String key; - + @JsonProperty("doc_count") private int docCount; public BucketEntity() { - + } - + public BucketEntity(String name, int value) { this.key = name; this.docCount = value; } - + public String getKey() { return key; } @@ -56,6 +56,6 @@ public class BucketEntity { public void setDocCount(int docCount) { this.docCount = docCount; } - - -} + + +} diff --git a/src/test/java/org/onap/aai/sparky/dal/elasticsearch/entity/ElasticHitsEntity.java b/src/test/java/org/onap/aai/sparky/dal/elasticsearch/entity/ElasticHitsEntity.java index 4158903..dcd5b98 100644 --- a/src/test/java/org/onap/aai/sparky/dal/elasticsearch/entity/ElasticHitsEntity.java +++ b/src/test/java/org/onap/aai/sparky/dal/elasticsearch/entity/ElasticHitsEntity.java @@ -30,17 +30,17 @@ import java.util.List; import com.fasterxml.jackson.annotation.JsonProperty; public class ElasticHitsEntity { - + private int total; @JsonProperty("max_score") private int maxScore; - + private List hits; - + public ElasticHitsEntity() { this.hits = new ArrayList(); } - + public void addHit(ElasticHit hit) { this.hits.add(hit); } @@ -68,7 +68,7 @@ public class ElasticHitsEntity { public void setHits(List hits) { this.hits = hits; } - - + + } diff --git a/src/test/java/org/onap/aai/sparky/dal/elasticsearch/entity/ElasticSearchAggegrationResponse.java b/src/test/java/org/onap/aai/sparky/dal/elasticsearch/entity/ElasticSearchAggegrationResponse.java index 6dd2d11..4306f6b 100644 --- a/src/test/java/org/onap/aai/sparky/dal/elasticsearch/entity/ElasticSearchAggegrationResponse.java +++ b/src/test/java/org/onap/aai/sparky/dal/elasticsearch/entity/ElasticSearchAggegrationResponse.java @@ -45,7 +45,7 @@ public class ElasticSearchAggegrationResponse { public ElasticSearchAggegrationResponse() { this.shards = new HashMap(); - this.aggregations = new HashMap(); + this.aggregations = new HashMap(); } @@ -89,7 +89,7 @@ public class ElasticSearchAggegrationResponse { } public void addShard(String key, String value) { - this.shards.put(key,value); + this.shards.put(key, value); } diff --git a/src/test/java/org/onap/aai/sparky/dal/elasticsearch/entity/ElasticSearchAggregation.java b/src/test/java/org/onap/aai/sparky/dal/elasticsearch/entity/ElasticSearchAggregation.java index 7bcd318..44794cd 100644 --- a/src/test/java/org/onap/aai/sparky/dal/elasticsearch/entity/ElasticSearchAggregation.java +++ b/src/test/java/org/onap/aai/sparky/dal/elasticsearch/entity/ElasticSearchAggregation.java @@ -30,15 +30,15 @@ import java.util.List; import com.fasterxml.jackson.annotation.JsonProperty; public class ElasticSearchAggregation { - + @JsonProperty("doc_count_error_upper_bound") private int docCountErrorUpperBound; - + @JsonProperty("sum_other_doc_count") private int sumOtherDocCount; - + private List buckets; - + public ElasticSearchAggregation() { buckets = new ArrayList(); } @@ -66,7 +66,7 @@ public class ElasticSearchAggregation { public void setBuckets(List buckets) { this.buckets = buckets; } - + public void addBucket(BucketEntity bucket) { buckets.add(bucket); } diff --git a/src/test/java/org/onap/aai/sparky/dal/elasticsearch/entity/ElasticSearchCountResponse.java b/src/test/java/org/onap/aai/sparky/dal/elasticsearch/entity/ElasticSearchCountResponse.java index 5aec440..e02e353 100644 --- a/src/test/java/org/onap/aai/sparky/dal/elasticsearch/entity/ElasticSearchCountResponse.java +++ b/src/test/java/org/onap/aai/sparky/dal/elasticsearch/entity/ElasticSearchCountResponse.java @@ -33,9 +33,9 @@ public class ElasticSearchCountResponse { private Map shards; public ElasticSearchCountResponse() { - this.shards = new HashMap(); + this.shards = new HashMap(); } - + public int getCount() { return count; } @@ -51,7 +51,7 @@ public class ElasticSearchCountResponse { public void setShards(Map shards) { this.shards = shards; } - + public void addShard(String key, String value) { this.shards.put(key, value); } diff --git a/src/test/java/org/onap/aai/sparky/dal/elasticsearch/entity/PayloadEntity.java b/src/test/java/org/onap/aai/sparky/dal/elasticsearch/entity/PayloadEntity.java index 5f5e333..da84dd7 100644 --- a/src/test/java/org/onap/aai/sparky/dal/elasticsearch/entity/PayloadEntity.java +++ b/src/test/java/org/onap/aai/sparky/dal/elasticsearch/entity/PayloadEntity.java @@ -26,7 +26,6 @@ package org.onap.aai.sparky.dal.elasticsearch.entity; public class PayloadEntity { - public PayloadEntity() { - } - + public PayloadEntity() {} + } diff --git a/src/test/java/org/onap/aai/sparky/dal/rest/RestOperationalStatisticsTest.java b/src/test/java/org/onap/aai/sparky/dal/rest/RestOperationalStatisticsTest.java index 415cbe7..2e0c90e 100644 --- a/src/test/java/org/onap/aai/sparky/dal/rest/RestOperationalStatisticsTest.java +++ b/src/test/java/org/onap/aai/sparky/dal/rest/RestOperationalStatisticsTest.java @@ -28,183 +28,183 @@ import org.onap.aai.sparky.dal.NetworkTransaction; public class RestOperationalStatisticsTest { - @Test - public void testUpdateCounters_Get() { - RestOperationalStatistics ros = new RestOperationalStatistics(); - - OperationResult result = new OperationResult(); - result.setResultCode(101); - result.setResult("result-1"); - result.setNumRequestRetries(1); - NetworkTransaction ntwTxn1 = new NetworkTransaction(HttpMethod.GET, "entity-1", result); - ros.updateCounters(ntwTxn1); - - result.setResultCode(201); - result.setResult("result-1"); - result.setNumRequestRetries(1); - NetworkTransaction ntwTxn2 = new NetworkTransaction(HttpMethod.GET, "entity-1", result); - ros.updateCounters(ntwTxn2); - - result.setResultCode(301); - result.setResult("result-1"); - result.setNumRequestRetries(1); - NetworkTransaction ntwTxn3 = new NetworkTransaction(HttpMethod.GET, "entity-1", result); - ros.updateCounters(ntwTxn3); - - result.setResultCode(401); - result.setResult("result-1"); - result.setNumRequestRetries(1); - NetworkTransaction ntwTxn4 = new NetworkTransaction(HttpMethod.GET, "entity-1", result); - ros.updateCounters(ntwTxn4); - - result.setResultCode(501); - result.setResult("result-1"); - result.setNumRequestRetries(1); - NetworkTransaction ntwTxn5 = new NetworkTransaction(HttpMethod.GET, "entity-1", result); - ros.updateCounters(ntwTxn5); - - result.setResultCode(601); - result.setResult("result-1"); - result.setNumRequestRetries(1); - NetworkTransaction ntwTxn6 = new NetworkTransaction(HttpMethod.GET, "entity-1", result); - ros.updateCounters(ntwTxn6); - - String statistics = ros.getStatisticsReport(); - Assert.assertNotNull(statistics); - } - - @Test - public void testUpdateCounters_Put() { - RestOperationalStatistics ros = new RestOperationalStatistics(); - - OperationResult result = new OperationResult(); - result.setResultCode(101); - result.setResult("result-1"); - result.setNumRequestRetries(1); - NetworkTransaction ntwTxn1 = new NetworkTransaction(HttpMethod.PUT, "entity-1", result); - ros.updateCounters(ntwTxn1); - - result.setResultCode(201); - result.setResult("result-1"); - result.setNumRequestRetries(1); - NetworkTransaction ntwTxn2 = new NetworkTransaction(HttpMethod.PUT, "entity-1", result); - ros.updateCounters(ntwTxn2); - - result.setResultCode(301); - result.setResult("result-1"); - result.setNumRequestRetries(1); - NetworkTransaction ntwTxn3 = new NetworkTransaction(HttpMethod.PUT, "entity-1", result); - ros.updateCounters(ntwTxn3); - - result.setResultCode(401); - result.setResult("result-1"); - result.setNumRequestRetries(1); - NetworkTransaction ntwTxn4 = new NetworkTransaction(HttpMethod.PUT, "entity-1", result); - ros.updateCounters(ntwTxn4); - - result.setResultCode(501); - result.setResult("result-1"); - result.setNumRequestRetries(1); - NetworkTransaction ntwTxn5 = new NetworkTransaction(HttpMethod.PUT, "entity-1", result); - ros.updateCounters(ntwTxn5); - - result.setResultCode(601); - result.setResult("result-1"); - result.setNumRequestRetries(1); - NetworkTransaction ntwTxn6 = new NetworkTransaction(HttpMethod.PUT, "entity-1", result); - ros.updateCounters(ntwTxn6); - - String statistics = ros.getStatisticsReport(); - Assert.assertNotNull(statistics); - } - - @Test - public void testUpdateCounters_Post() { - RestOperationalStatistics ros = new RestOperationalStatistics(); - - OperationResult result = new OperationResult(); - result.setResultCode(101); - result.setResult("result-1"); - result.setNumRequestRetries(1); - NetworkTransaction ntwTxn1 = new NetworkTransaction(HttpMethod.POST, "entity-1", result); - ros.updateCounters(ntwTxn1); - - result.setResultCode(201); - result.setResult("result-1"); - result.setNumRequestRetries(1); - NetworkTransaction ntwTxn2 = new NetworkTransaction(HttpMethod.POST, "entity-1", result); - ros.updateCounters(ntwTxn2); - - result.setResultCode(301); - result.setResult("result-1"); - result.setNumRequestRetries(1); - NetworkTransaction ntwTxn3 = new NetworkTransaction(HttpMethod.POST, "entity-1", result); - ros.updateCounters(ntwTxn3); - - result.setResultCode(401); - result.setResult("result-1"); - result.setNumRequestRetries(1); - NetworkTransaction ntwTxn4 = new NetworkTransaction(HttpMethod.POST, "entity-1", result); - ros.updateCounters(ntwTxn4); - - result.setResultCode(501); - result.setResult("result-1"); - result.setNumRequestRetries(1); - NetworkTransaction ntwTxn5 = new NetworkTransaction(HttpMethod.POST, "entity-1", result); - ros.updateCounters(ntwTxn5); - - result.setResultCode(601); - result.setResult("result-1"); - result.setNumRequestRetries(1); - NetworkTransaction ntwTxn6 = new NetworkTransaction(HttpMethod.POST, "entity-1", result); - ros.updateCounters(ntwTxn6); - - String statistics = ros.getStatisticsReport(); - Assert.assertNotNull(statistics); - } - - @Test - public void testUpdateCounters_Delete() { - RestOperationalStatistics ros = new RestOperationalStatistics(); - - OperationResult result = new OperationResult(); - result.setResultCode(101); - result.setResult("result-1"); - result.setNumRequestRetries(1); - NetworkTransaction ntwTxn1 = new NetworkTransaction(HttpMethod.DELETE, "entity-1", result); - ros.updateCounters(ntwTxn1); - - result.setResultCode(201); - result.setResult("result-1"); - result.setNumRequestRetries(1); - NetworkTransaction ntwTxn2 = new NetworkTransaction(HttpMethod.DELETE, "entity-1", result); - ros.updateCounters(ntwTxn2); - - result.setResultCode(301); - result.setResult("result-1"); - result.setNumRequestRetries(1); - NetworkTransaction ntwTxn3 = new NetworkTransaction(HttpMethod.DELETE, "entity-1", result); - ros.updateCounters(ntwTxn3); - - result.setResultCode(401); - result.setResult("result-1"); - result.setNumRequestRetries(1); - NetworkTransaction ntwTxn4 = new NetworkTransaction(HttpMethod.DELETE, "entity-1", result); - ros.updateCounters(ntwTxn4); - - result.setResultCode(501); - result.setResult("result-1"); - result.setNumRequestRetries(1); - NetworkTransaction ntwTxn5 = new NetworkTransaction(HttpMethod.DELETE, "entity-1", result); - ros.updateCounters(ntwTxn5); - - result.setResultCode(601); - result.setResult("result-1"); - result.setNumRequestRetries(1); - NetworkTransaction ntwTxn6 = new NetworkTransaction(HttpMethod.DELETE, "entity-1", result); - ros.updateCounters(ntwTxn6); - - String statistics = ros.getStatisticsReport(); - Assert.assertNotNull(statistics); - } + @Test + public void testUpdateCounters_Get() { + RestOperationalStatistics ros = new RestOperationalStatistics(); + + OperationResult result = new OperationResult(); + result.setResultCode(101); + result.setResult("result-1"); + result.setNumRequestRetries(1); + NetworkTransaction ntwTxn1 = new NetworkTransaction(HttpMethod.GET, "entity-1", result); + ros.updateCounters(ntwTxn1); + + result.setResultCode(201); + result.setResult("result-1"); + result.setNumRequestRetries(1); + NetworkTransaction ntwTxn2 = new NetworkTransaction(HttpMethod.GET, "entity-1", result); + ros.updateCounters(ntwTxn2); + + result.setResultCode(301); + result.setResult("result-1"); + result.setNumRequestRetries(1); + NetworkTransaction ntwTxn3 = new NetworkTransaction(HttpMethod.GET, "entity-1", result); + ros.updateCounters(ntwTxn3); + + result.setResultCode(401); + result.setResult("result-1"); + result.setNumRequestRetries(1); + NetworkTransaction ntwTxn4 = new NetworkTransaction(HttpMethod.GET, "entity-1", result); + ros.updateCounters(ntwTxn4); + + result.setResultCode(501); + result.setResult("result-1"); + result.setNumRequestRetries(1); + NetworkTransaction ntwTxn5 = new NetworkTransaction(HttpMethod.GET, "entity-1", result); + ros.updateCounters(ntwTxn5); + + result.setResultCode(601); + result.setResult("result-1"); + result.setNumRequestRetries(1); + NetworkTransaction ntwTxn6 = new NetworkTransaction(HttpMethod.GET, "entity-1", result); + ros.updateCounters(ntwTxn6); + + String statistics = ros.getStatisticsReport(); + Assert.assertNotNull(statistics); + } + + @Test + public void testUpdateCounters_Put() { + RestOperationalStatistics ros = new RestOperationalStatistics(); + + OperationResult result = new OperationResult(); + result.setResultCode(101); + result.setResult("result-1"); + result.setNumRequestRetries(1); + NetworkTransaction ntwTxn1 = new NetworkTransaction(HttpMethod.PUT, "entity-1", result); + ros.updateCounters(ntwTxn1); + + result.setResultCode(201); + result.setResult("result-1"); + result.setNumRequestRetries(1); + NetworkTransaction ntwTxn2 = new NetworkTransaction(HttpMethod.PUT, "entity-1", result); + ros.updateCounters(ntwTxn2); + + result.setResultCode(301); + result.setResult("result-1"); + result.setNumRequestRetries(1); + NetworkTransaction ntwTxn3 = new NetworkTransaction(HttpMethod.PUT, "entity-1", result); + ros.updateCounters(ntwTxn3); + + result.setResultCode(401); + result.setResult("result-1"); + result.setNumRequestRetries(1); + NetworkTransaction ntwTxn4 = new NetworkTransaction(HttpMethod.PUT, "entity-1", result); + ros.updateCounters(ntwTxn4); + + result.setResultCode(501); + result.setResult("result-1"); + result.setNumRequestRetries(1); + NetworkTransaction ntwTxn5 = new NetworkTransaction(HttpMethod.PUT, "entity-1", result); + ros.updateCounters(ntwTxn5); + + result.setResultCode(601); + result.setResult("result-1"); + result.setNumRequestRetries(1); + NetworkTransaction ntwTxn6 = new NetworkTransaction(HttpMethod.PUT, "entity-1", result); + ros.updateCounters(ntwTxn6); + + String statistics = ros.getStatisticsReport(); + Assert.assertNotNull(statistics); + } + + @Test + public void testUpdateCounters_Post() { + RestOperationalStatistics ros = new RestOperationalStatistics(); + + OperationResult result = new OperationResult(); + result.setResultCode(101); + result.setResult("result-1"); + result.setNumRequestRetries(1); + NetworkTransaction ntwTxn1 = new NetworkTransaction(HttpMethod.POST, "entity-1", result); + ros.updateCounters(ntwTxn1); + + result.setResultCode(201); + result.setResult("result-1"); + result.setNumRequestRetries(1); + NetworkTransaction ntwTxn2 = new NetworkTransaction(HttpMethod.POST, "entity-1", result); + ros.updateCounters(ntwTxn2); + + result.setResultCode(301); + result.setResult("result-1"); + result.setNumRequestRetries(1); + NetworkTransaction ntwTxn3 = new NetworkTransaction(HttpMethod.POST, "entity-1", result); + ros.updateCounters(ntwTxn3); + + result.setResultCode(401); + result.setResult("result-1"); + result.setNumRequestRetries(1); + NetworkTransaction ntwTxn4 = new NetworkTransaction(HttpMethod.POST, "entity-1", result); + ros.updateCounters(ntwTxn4); + + result.setResultCode(501); + result.setResult("result-1"); + result.setNumRequestRetries(1); + NetworkTransaction ntwTxn5 = new NetworkTransaction(HttpMethod.POST, "entity-1", result); + ros.updateCounters(ntwTxn5); + + result.setResultCode(601); + result.setResult("result-1"); + result.setNumRequestRetries(1); + NetworkTransaction ntwTxn6 = new NetworkTransaction(HttpMethod.POST, "entity-1", result); + ros.updateCounters(ntwTxn6); + + String statistics = ros.getStatisticsReport(); + Assert.assertNotNull(statistics); + } + + @Test + public void testUpdateCounters_Delete() { + RestOperationalStatistics ros = new RestOperationalStatistics(); + + OperationResult result = new OperationResult(); + result.setResultCode(101); + result.setResult("result-1"); + result.setNumRequestRetries(1); + NetworkTransaction ntwTxn1 = new NetworkTransaction(HttpMethod.DELETE, "entity-1", result); + ros.updateCounters(ntwTxn1); + + result.setResultCode(201); + result.setResult("result-1"); + result.setNumRequestRetries(1); + NetworkTransaction ntwTxn2 = new NetworkTransaction(HttpMethod.DELETE, "entity-1", result); + ros.updateCounters(ntwTxn2); + + result.setResultCode(301); + result.setResult("result-1"); + result.setNumRequestRetries(1); + NetworkTransaction ntwTxn3 = new NetworkTransaction(HttpMethod.DELETE, "entity-1", result); + ros.updateCounters(ntwTxn3); + + result.setResultCode(401); + result.setResult("result-1"); + result.setNumRequestRetries(1); + NetworkTransaction ntwTxn4 = new NetworkTransaction(HttpMethod.DELETE, "entity-1", result); + ros.updateCounters(ntwTxn4); + + result.setResultCode(501); + result.setResult("result-1"); + result.setNumRequestRetries(1); + NetworkTransaction ntwTxn5 = new NetworkTransaction(HttpMethod.DELETE, "entity-1", result); + ros.updateCounters(ntwTxn5); + + result.setResultCode(601); + result.setResult("result-1"); + result.setNumRequestRetries(1); + NetworkTransaction ntwTxn6 = new NetworkTransaction(HttpMethod.DELETE, "entity-1", result); + ros.updateCounters(ntwTxn6); + + String statistics = ros.getStatisticsReport(); + Assert.assertNotNull(statistics); + } } diff --git a/src/test/java/org/onap/aai/sparky/dal/rest/RestfulDataAccessorTest.java b/src/test/java/org/onap/aai/sparky/dal/rest/RestfulDataAccessorTest.java index fe6fa56..fabc32b 100644 --- a/src/test/java/org/onap/aai/sparky/dal/rest/RestfulDataAccessorTest.java +++ b/src/test/java/org/onap/aai/sparky/dal/rest/RestfulDataAccessorTest.java @@ -46,7 +46,7 @@ import com.sun.jersey.api.client.WebResource.Builder; /** * The Class RestfulDataAccessorTest. */ -@RunWith(MockitoJUnitRunner.class) +@RunWith(MockitoJUnitRunner.class) public class RestfulDataAccessorTest { private RestClientBuilder clientBuilderMock; @@ -54,7 +54,7 @@ public class RestfulDataAccessorTest { private ClientResponse mockClientResponse; private WebResource mockWebResource; private Builder mockBuilder; - + /** * Inits the. @@ -63,7 +63,7 @@ public class RestfulDataAccessorTest { */ @Before public void init() throws Exception { - + /* * common collaborator mocking setup */ diff --git a/src/test/java/org/onap/aai/sparky/dal/sas/entity/DocumentEntity.java b/src/test/java/org/onap/aai/sparky/dal/sas/entity/DocumentEntity.java index 4d85bd6..3aaef43 100644 --- a/src/test/java/org/onap/aai/sparky/dal/sas/entity/DocumentEntity.java +++ b/src/test/java/org/onap/aai/sparky/dal/sas/entity/DocumentEntity.java @@ -30,14 +30,14 @@ import java.util.Map; public class DocumentEntity { private String etag; private String url; - private Map content; + private Map content; public DocumentEntity() { - content = new HashMap(); + content = new HashMap(); } - - - public String getEtag() { + + + public String getEtag() { return etag; } @@ -60,7 +60,7 @@ public class DocumentEntity { public void setContent(Map content) { this.content = content; } - + public void addContent(String key, String value) { content.put(key, value); } diff --git a/src/test/java/org/onap/aai/sparky/dal/sas/entity/EntityCountResponse.java b/src/test/java/org/onap/aai/sparky/dal/sas/entity/EntityCountResponse.java index d6e9971..fe69f81 100644 --- a/src/test/java/org/onap/aai/sparky/dal/sas/entity/EntityCountResponse.java +++ b/src/test/java/org/onap/aai/sparky/dal/sas/entity/EntityCountResponse.java @@ -28,12 +28,12 @@ import java.util.HashMap; import java.util.Map; public class EntityCountResponse { - - private Map shards; + + private Map shards; private int count; - + public EntityCountResponse() { - this.shards = new HashMap(); + this.shards = new HashMap(); } public Map getShards() { @@ -51,5 +51,5 @@ public class EntityCountResponse { public void setCount(int count) { this.count = count; } - + } diff --git a/src/test/java/org/onap/aai/sparky/dal/sas/entity/GroupByAggregationEntity.java b/src/test/java/org/onap/aai/sparky/dal/sas/entity/GroupByAggregationEntity.java index 0f1609b..9418cf5 100644 --- a/src/test/java/org/onap/aai/sparky/dal/sas/entity/GroupByAggregationEntity.java +++ b/src/test/java/org/onap/aai/sparky/dal/sas/entity/GroupByAggregationEntity.java @@ -32,7 +32,7 @@ import org.onap.aai.sparky.dal.elasticsearch.entity.BucketEntity; public class GroupByAggregationEntity { private int totalChartHits; List buckets; - + public GroupByAggregationEntity() { this.buckets = new ArrayList(); } diff --git a/src/test/java/org/onap/aai/sparky/dal/sas/entity/GroupByAggregationResponseEntity.java b/src/test/java/org/onap/aai/sparky/dal/sas/entity/GroupByAggregationResponseEntity.java index 0af4600..3f8cb69 100644 --- a/src/test/java/org/onap/aai/sparky/dal/sas/entity/GroupByAggregationResponseEntity.java +++ b/src/test/java/org/onap/aai/sparky/dal/sas/entity/GroupByAggregationResponseEntity.java @@ -30,9 +30,9 @@ public class GroupByAggregationResponseEntity { @JsonProperty("groupby_aggregation") private GroupByAggregationEntity aggEntity; - + public GroupByAggregationResponseEntity() { - + } public GroupByAggregationEntity getAggEntity() { @@ -42,7 +42,7 @@ public class GroupByAggregationResponseEntity { public void setAggEntity(GroupByAggregationEntity aggEntity) { this.aggEntity = aggEntity; } - - - + + + } diff --git a/src/test/java/org/onap/aai/sparky/dal/sas/entity/HitEntity.java b/src/test/java/org/onap/aai/sparky/dal/sas/entity/HitEntity.java index 755e903..2340c0d 100644 --- a/src/test/java/org/onap/aai/sparky/dal/sas/entity/HitEntity.java +++ b/src/test/java/org/onap/aai/sparky/dal/sas/entity/HitEntity.java @@ -30,7 +30,7 @@ public class HitEntity { private DocumentEntity document; public String getScore() { - return score; + return score; } public void setScore(String score) { diff --git a/src/test/java/org/onap/aai/sparky/dal/sas/entity/SearchAbstractionEntityBuilder.java b/src/test/java/org/onap/aai/sparky/dal/sas/entity/SearchAbstractionEntityBuilder.java index e815e0b..08bf76c 100644 --- a/src/test/java/org/onap/aai/sparky/dal/sas/entity/SearchAbstractionEntityBuilder.java +++ b/src/test/java/org/onap/aai/sparky/dal/sas/entity/SearchAbstractionEntityBuilder.java @@ -30,9 +30,9 @@ import java.util.Map; public class SearchAbstractionEntityBuilder { - + public static HitEntity getHitSample1() { - + HitEntity hitEntity = new HitEntity(); DocumentEntity doc = new DocumentEntity(); @@ -40,20 +40,23 @@ public class SearchAbstractionEntityBuilder { hitEntity.setScore("17.073963"); doc.addContent("entityPrimaryKeyValue", "example-vnf-id-val-4394"); - doc.addContent("entityType", "vpe"); - doc.addContent("searchTags", "example-vnf-id-val-4394;example-vnf-name-val-4394;example-vnf-name2-val-4394"); - doc.addContent("link", "https://aai-hostname:8443/aai/v9/network/vpes/vpe/example-vnf-id-val-4394"); - doc.addContent("searchTagIDs", "0;1;2"); - doc.addContent("lastmodTimestamp", "2017-04-18T17:20:48.072-0400"); - - doc.setUrl("services/search-data-service/v1/search/indexes/entitysearchindex-localhost-ist-apr18/documents/e317a35256717f10e88d1b2c995efcdddfc911bf350c73e37e8afca6dfb11553"); + doc.addContent("entityType", "vpe"); + doc.addContent("searchTags", + "example-vnf-id-val-4394;example-vnf-name-val-4394;example-vnf-name2-val-4394"); + doc.addContent("link", + "https://aai-hostname:8443/aai/v9/network/vpes/vpe/example-vnf-id-val-4394"); + doc.addContent("searchTagIDs", "0;1;2"); + doc.addContent("lastmodTimestamp", "2017-04-18T17:20:48.072-0400"); + + doc.setUrl( + "services/search-data-service/v1/search/indexes/entitysearchindex-localhost-ist-apr18/documents/e317a35256717f10e88d1b2c995efcdddfc911bf350c73e37e8afca6dfb11553"); doc.setEtag("1"); return hitEntity; } - + public static HitEntity getHitSample2() { HitEntity hitEntity = new HitEntity(); @@ -63,20 +66,22 @@ public class SearchAbstractionEntityBuilder { hitEntity.setScore("17.073963"); doc.addContent("entityPrimaryKeyValue", "vpe-vnf-id-team4-11"); - doc.addContent("entityType", "vpe"); - doc.addContent("searchTags", "vpe-vnf-id-team4-11;example-vnf-name-val-9512;example-vnf-name2-val-9512"); - doc.addContent("link", "https://aai-hostname:8443/aai/v9/network/vpes/vpe/vpe-vnf-id-team4-11"); - doc.addContent("searchTagIDs", "0;1;2"); - doc.addContent("lastmodTimestamp", "2017-04-18T17:20:48.175-0400"); - - doc.setUrl("services/search-data-service/v1/search/indexes/entitysearchindex-localhost-ist-apr18/documents/80f6d1a252e047e50e0adbeb90ad30876bb5b63cf70c9dd53f3fe46aeb50c74b"); + doc.addContent("entityType", "vpe"); + doc.addContent("searchTags", + "vpe-vnf-id-team4-11;example-vnf-name-val-9512;example-vnf-name2-val-9512"); + doc.addContent("link", "https://aai-hostname:8443/aai/v9/network/vpes/vpe/vpe-vnf-id-team4-11"); + doc.addContent("searchTagIDs", "0;1;2"); + doc.addContent("lastmodTimestamp", "2017-04-18T17:20:48.175-0400"); + + doc.setUrl( + "services/search-data-service/v1/search/indexes/entitysearchindex-localhost-ist-apr18/documents/80f6d1a252e047e50e0adbeb90ad30876bb5b63cf70c9dd53f3fe46aeb50c74b"); doc.setEtag("1"); return hitEntity; } - + public static HitEntity getHitSample3() { HitEntity hitEntity = new HitEntity(); @@ -86,20 +91,23 @@ public class SearchAbstractionEntityBuilder { hitEntity.setScore("17.030035"); doc.addContent("entityPrimaryKeyValue", "example-vnf-id-val-6176"); - doc.addContent("entityType", "generic-vnf"); - doc.addContent("searchTags", "example-vnf-id-val-6176;example-vnf-name-val-6176;example-vnf-name2-val-6176"); - doc.addContent("link", "https://aai-hostname:8443/aai/v9/network/generic-vnfs/generic-vnf/example-vnf-id-val-6176"); - doc.addContent("searchTagIDs", "0;1;2"); - doc.addContent("lastmodTimestamp", "2017-04-18T17:29:39.889-0400"); - - doc.setUrl("services/search-data-service/v1/search/indexes/entitysearchindex-localhost-ist-apr18/documents/8dfd1136f943296508fee11efcda35a0719aa490aa60e9abffecce0b220d8c94"); + doc.addContent("entityType", "generic-vnf"); + doc.addContent("searchTags", + "example-vnf-id-val-6176;example-vnf-name-val-6176;example-vnf-name2-val-6176"); + doc.addContent("link", + "https://aai-hostname:8443/aai/v9/network/generic-vnfs/generic-vnf/example-vnf-id-val-6176"); + doc.addContent("searchTagIDs", "0;1;2"); + doc.addContent("lastmodTimestamp", "2017-04-18T17:29:39.889-0400"); + + doc.setUrl( + "services/search-data-service/v1/search/indexes/entitysearchindex-localhost-ist-apr18/documents/8dfd1136f943296508fee11efcda35a0719aa490aa60e9abffecce0b220d8c94"); doc.setEtag("1"); return hitEntity; } - + public static HitEntity getHitSample4() { HitEntity hitEntity = new HitEntity(); @@ -109,20 +117,23 @@ public class SearchAbstractionEntityBuilder { hitEntity.setScore("17.01174"); doc.addContent("entityPrimaryKeyValue", "vnf-id-team4-11"); - doc.addContent("entityType", "newvce"); - doc.addContent("searchTags", "vnf-id-team4-11;example-vnf-name-val-5313;example-vnf-name2-val-5313"); - doc.addContent("link", "https://aai-hostname:8443/aai/v9/network/newvces/newvce/vnf-id-team4-11"); - doc.addContent("searchTagIDs", "0;1;2"); - doc.addContent("lastmodTimestamp", "2017-04-18T17:21:08.142-0400"); - - doc.setUrl("services/search-data-service/v1/search/indexes/entitysearchindex-localhost-ist-apr18/documents/83dcab92d75b20eb94578039c8cec5e7b6b4717791e3c367d8af5069ce76dc90"); + doc.addContent("entityType", "newvce"); + doc.addContent("searchTags", + "vnf-id-team4-11;example-vnf-name-val-5313;example-vnf-name2-val-5313"); + doc.addContent("link", + "https://aai-hostname:8443/aai/v9/network/newvces/newvce/vnf-id-team4-11"); + doc.addContent("searchTagIDs", "0;1;2"); + doc.addContent("lastmodTimestamp", "2017-04-18T17:21:08.142-0400"); + + doc.setUrl( + "services/search-data-service/v1/search/indexes/entitysearchindex-localhost-ist-apr18/documents/83dcab92d75b20eb94578039c8cec5e7b6b4717791e3c367d8af5069ce76dc90"); doc.setEtag("1"); return hitEntity; } - + public static HitEntity getHitSample5() { HitEntity hitEntity = new HitEntity(); @@ -132,20 +143,23 @@ public class SearchAbstractionEntityBuilder { hitEntity.setScore("17.01174"); doc.addContent("entityPrimaryKeyValue", "example-vnf-id2-val-9501"); - doc.addContent("entityType", "newvce"); - doc.addContent("searchTags", "example-vnf-id2-val-9501;example-vnf-name-val-9501;example-vnf-name2-val-9501"); - doc.addContent("link", "https://aai-hostname:8443/aai/v9/network/newvces/newvce/example-vnf-id2-val-9501"); - doc.addContent("searchTagIDs", "0;1;2"); - doc.addContent("lastmodTimestamp", "2017-04-18T17:21:23.323-0400"); - - doc.setUrl("services/search-data-service/v1/search/indexes/entitysearchindex-localhost-ist-apr18/documents/461816ba8aa94d01f2c978999b843dbaf10e0509db58d1945d6f5999d6db8f5e"); + doc.addContent("entityType", "newvce"); + doc.addContent("searchTags", + "example-vnf-id2-val-9501;example-vnf-name-val-9501;example-vnf-name2-val-9501"); + doc.addContent("link", + "https://aai-hostname:8443/aai/v9/network/newvces/newvce/example-vnf-id2-val-9501"); + doc.addContent("searchTagIDs", "0;1;2"); + doc.addContent("lastmodTimestamp", "2017-04-18T17:21:23.323-0400"); + + doc.setUrl( + "services/search-data-service/v1/search/indexes/entitysearchindex-localhost-ist-apr18/documents/461816ba8aa94d01f2c978999b843dbaf10e0509db58d1945d6f5999d6db8f5e"); doc.setEtag("1"); return hitEntity; } - + public static HitEntity getHitSample6() { HitEntity hitEntity = new HitEntity(); @@ -155,20 +169,22 @@ public class SearchAbstractionEntityBuilder { hitEntity.setScore("17.01174"); doc.addContent("entityPrimaryKeyValue", "vnf-id-dm-auto-10"); - doc.addContent("entityType", "vce"); - doc.addContent("searchTags", "vpe-id-dm-auto-10;vnf-id-dm-auto-10;vnf-name-dm-auto-10;vnf-name2-dm-auto-10"); - doc.addContent("link", "https://aai-hostname:8443/aai/v9/network/vces/vce/vnf-id-dm-auto-10"); - doc.addContent("searchTagIDs", "0;1;2;3"); - doc.addContent("lastmodTimestamp", "2017-04-18T17:24:57.209-0400"); - - doc.setUrl("services/search-data-service/v1/search/indexes/entitysearchindex-localhost-ist-apr18/documents/1ead4512e65ee0eafb24e0156cc1abdf97368f08dfe065f02580aa09661bbcd8"); + doc.addContent("entityType", "vce"); + doc.addContent("searchTags", + "vpe-id-dm-auto-10;vnf-id-dm-auto-10;vnf-name-dm-auto-10;vnf-name2-dm-auto-10"); + doc.addContent("link", "https://aai-hostname:8443/aai/v9/network/vces/vce/vnf-id-dm-auto-10"); + doc.addContent("searchTagIDs", "0;1;2;3"); + doc.addContent("lastmodTimestamp", "2017-04-18T17:24:57.209-0400"); + + doc.setUrl( + "services/search-data-service/v1/search/indexes/entitysearchindex-localhost-ist-apr18/documents/1ead4512e65ee0eafb24e0156cc1abdf97368f08dfe065f02580aa09661bbcd8"); doc.setEtag("1"); return hitEntity; } - + public static HitEntity getHitSample7() { HitEntity hitEntity = new HitEntity(); @@ -178,20 +194,22 @@ public class SearchAbstractionEntityBuilder { hitEntity.setScore("13.940832"); doc.addContent("entityPrimaryKeyValue", "e3e59c5b-ad48-44d0-b3e4-80eacdcee4c7"); - doc.addContent("entityType", "generic-vnf"); - doc.addContent("searchTags", "e3e59c5b-ad48-44d0-b3e4-80eacdcee4c7;VNF_Test_vNF_modules_01"); - doc.addContent("link", "https://aai-hostname:8443/aai/v9/network/generic-vnfs/generic-vnf/e3e59c5b-ad48-44d0-b3e4-80eacdcee4c7"); - doc.addContent("searchTagIDs", "0;1"); - doc.addContent("lastmodTimestamp", "2017-04-18T17:26:34.603-0400"); - - doc.setUrl("services/search-data-service/v1/search/indexes/entitysearchindex-localhost-ist-apr18/documents/1462582e8fd7786f72f26548e4247b72ab6cd101cca0bbb68a60dd3ad16500d0"); + doc.addContent("entityType", "generic-vnf"); + doc.addContent("searchTags", "e3e59c5b-ad48-44d0-b3e4-80eacdcee4c7;VNF_Test_vNF_modules_01"); + doc.addContent("link", + "https://aai-hostname:8443/aai/v9/network/generic-vnfs/generic-vnf/e3e59c5b-ad48-44d0-b3e4-80eacdcee4c7"); + doc.addContent("searchTagIDs", "0;1"); + doc.addContent("lastmodTimestamp", "2017-04-18T17:26:34.603-0400"); + + doc.setUrl( + "services/search-data-service/v1/search/indexes/entitysearchindex-localhost-ist-apr18/documents/1462582e8fd7786f72f26548e4247b72ab6cd101cca0bbb68a60dd3ad16500d0"); doc.setEtag("1"); return hitEntity; } - + public static HitEntity getHitSample8() { HitEntity hitEntity = new HitEntity(); @@ -201,20 +219,22 @@ public class SearchAbstractionEntityBuilder { hitEntity.setScore("13.940832"); doc.addContent("entityPrimaryKeyValue", "fusion-jitsi-vnf-001"); - doc.addContent("entityType", "generic-vnf"); - doc.addContent("searchTags", "fusion-jitsi-vnf-001;fusion-jitsi-vnf"); - doc.addContent("link", "https://aai-hostname:8443/aai/v9/network/generic-vnfs/generic-vnf/fusion-jitsi-vnf-001"); - doc.addContent("searchTagIDs", "0;1"); - doc.addContent("lastmodTimestamp", "2017-04-18T17:28:14.293-0400"); - - doc.setUrl("services/search-data-service/v1/search/indexes/entitysearchindex-localhost-ist-apr18/documents/b79ddfec9a00184445174c91e7490a0d407f351983bba4ae53bfec0584f73ee3"); + doc.addContent("entityType", "generic-vnf"); + doc.addContent("searchTags", "fusion-jitsi-vnf-001;fusion-jitsi-vnf"); + doc.addContent("link", + "https://aai-hostname:8443/aai/v9/network/generic-vnfs/generic-vnf/fusion-jitsi-vnf-001"); + doc.addContent("searchTagIDs", "0;1"); + doc.addContent("lastmodTimestamp", "2017-04-18T17:28:14.293-0400"); + + doc.setUrl( + "services/search-data-service/v1/search/indexes/entitysearchindex-localhost-ist-apr18/documents/b79ddfec9a00184445174c91e7490a0d407f351983bba4ae53bfec0584f73ee3"); doc.setEtag("1"); return hitEntity; } - + public static HitEntity getHitSample9() { HitEntity hitEntity = new HitEntity(); @@ -224,20 +244,22 @@ public class SearchAbstractionEntityBuilder { hitEntity.setScore("13.940832"); doc.addContent("entityPrimaryKeyValue", "vnfm0003v"); - doc.addContent("entityType", "generic-vnf"); - doc.addContent("searchTags", "vnfm0003v;vnfm0003v"); - doc.addContent("link", "https://aai-hostname:8443/aai/v9/network/generic-vnfs/generic-vnf/vnfm0003v"); - doc.addContent("searchTagIDs", "0;1"); - doc.addContent("lastmodTimestamp", "2017-04-18T17:29:39.594-0400"); - - doc.setUrl("services/search-data-service/v1/search/indexes/entitysearchindex-localhost-ist-apr18/documents/52ae232ea5506d6de8ef35c4f46a1ceafe35f3717ff578b83531bc7615870b12"); + doc.addContent("entityType", "generic-vnf"); + doc.addContent("searchTags", "vnfm0003v;vnfm0003v"); + doc.addContent("link", + "https://aai-hostname:8443/aai/v9/network/generic-vnfs/generic-vnf/vnfm0003v"); + doc.addContent("searchTagIDs", "0;1"); + doc.addContent("lastmodTimestamp", "2017-04-18T17:29:39.594-0400"); + + doc.setUrl( + "services/search-data-service/v1/search/indexes/entitysearchindex-localhost-ist-apr18/documents/52ae232ea5506d6de8ef35c4f46a1ceafe35f3717ff578b83531bc7615870b12"); doc.setEtag("1"); return hitEntity; } - + public static HitEntity getHitSample10() { HitEntity hitEntity = new HitEntity(); @@ -247,33 +269,35 @@ public class SearchAbstractionEntityBuilder { hitEntity.setScore("13.928098"); doc.addContent("entityPrimaryKeyValue", "amist456vnf"); - doc.addContent("entityType", "generic-vnf"); - doc.addContent("searchTags", "amist456vnf;amist456vnf"); - doc.addContent("link", "https://aai-hostname:8443/aai/v9/network/generic-vnfs/generic-vnf/amist456vnf"); - doc.addContent("searchTagIDs", "0;1"); - doc.addContent("lastmodTimestamp", "2017-04-18T17:28:28.163-0400"); - - doc.setUrl("services/search-data-service/v1/search/indexes/entitysearchindex-localhost-ist-apr18/documents/3424afea5963696380a0fdc78ee5320cf5fa9bc0459f1f9376db208d31196434"); + doc.addContent("entityType", "generic-vnf"); + doc.addContent("searchTags", "amist456vnf;amist456vnf"); + doc.addContent("link", + "https://aai-hostname:8443/aai/v9/network/generic-vnfs/generic-vnf/amist456vnf"); + doc.addContent("searchTagIDs", "0;1"); + doc.addContent("lastmodTimestamp", "2017-04-18T17:28:28.163-0400"); + + doc.setUrl( + "services/search-data-service/v1/search/indexes/entitysearchindex-localhost-ist-apr18/documents/3424afea5963696380a0fdc78ee5320cf5fa9bc0459f1f9376db208d31196434"); doc.setEtag("1"); return hitEntity; } - - - + + + public static SearchAbstractionResponse getSuccessfulEntitySearchResponse() { - + SearchAbstractionResponse sasResponse = new SearchAbstractionResponse(); - + SearchResult searchResult = new SearchResult(); sasResponse.setSearchResult(searchResult); - + searchResult.setTotalHits(3257); - + List hits = new ArrayList(); - + hits.add(getHitSample1()); hits.add(getHitSample2()); hits.add(getHitSample3()); @@ -284,12 +308,12 @@ public class SearchAbstractionEntityBuilder { hits.add(getHitSample8()); hits.add(getHitSample9()); hits.add(getHitSample10()); - + searchResult.setHits(hits); - + return sasResponse; - + } - + } diff --git a/src/test/java/org/onap/aai/sparky/dal/sas/entity/SearchAbstractionResponse.java b/src/test/java/org/onap/aai/sparky/dal/sas/entity/SearchAbstractionResponse.java index d3d4a4c..547b61e 100644 --- a/src/test/java/org/onap/aai/sparky/dal/sas/entity/SearchAbstractionResponse.java +++ b/src/test/java/org/onap/aai/sparky/dal/sas/entity/SearchAbstractionResponse.java @@ -25,13 +25,13 @@ package org.onap.aai.sparky.dal.sas.entity; public class SearchAbstractionResponse { - + private SearchResult searchResult; public SearchResult getSearchResult() { return searchResult; } - + public void setSearchResult(SearchResult searchResult) { this.searchResult = searchResult; } diff --git a/src/test/java/org/onap/aai/sparky/dal/sas/entity/SearchResult.java b/src/test/java/org/onap/aai/sparky/dal/sas/entity/SearchResult.java index e484fa6..255413d 100644 --- a/src/test/java/org/onap/aai/sparky/dal/sas/entity/SearchResult.java +++ b/src/test/java/org/onap/aai/sparky/dal/sas/entity/SearchResult.java @@ -30,20 +30,23 @@ public class SearchResult { private int totalHits; private List hits; - - public int getTotalHits() { + + public int getTotalHits() { return totalHits; } + public void setTotalHits(int totalHits) { this.totalHits = totalHits; } + public List getHits() { return hits; } + public void setHits(List hits) { this.hits = hits; } - - - + + + } diff --git a/src/test/java/org/onap/aai/sparky/search/VnfSearchQueryBuilderTest.java b/src/test/java/org/onap/aai/sparky/search/VnfSearchQueryBuilderTest.java index 19a0a3a..99b20c1 100644 --- a/src/test/java/org/onap/aai/sparky/search/VnfSearchQueryBuilderTest.java +++ b/src/test/java/org/onap/aai/sparky/search/VnfSearchQueryBuilderTest.java @@ -34,42 +34,44 @@ import org.onap.aai.sparky.search.VnfSearchQueryBuilder; public class VnfSearchQueryBuilderTest { - @Test - public void testCreateSuggestionsQuery() { - String maxResults = "maxResults-1"; - String queryStr = "queryStr-1"; - JsonObject object = VnfSearchQueryBuilder.createSuggestionsQuery(maxResults, queryStr); - Assert.assertNotNull(object); - } - - @Test - public void testSortCriteria() { - JsonArray array = VnfSearchQueryBuilder.getSortCriteria("field-1", "sortOrder-1"); - Assert.assertNotNull(array); - } - - @Test - public void testCreateEntityCountsQuery_SingleAttribute() { - Map attributes = new HashMap<>(); - attributes.put("key-1", "value-1"); - JsonObject object = VnfSearchQueryBuilder.createEntityCountsQuery(attributes); - Assert.assertNotNull(object); - } - - @Test - public void testCreateSummaryByEntityTypeQuery_Single() { - Map attributes = new HashMap<>(); - attributes.put("key-1", "value-1"); - JsonObject object = VnfSearchQueryBuilder.createSummaryByEntityTypeQuery(attributes, "groupkey-1"); - Assert.assertNotNull(object); - } - - @Test - public void testCreateSummaryByEntityTypeQuery_Multiple() { - Map attributes = new HashMap<>(); - attributes.put("key-1", "value-1"); - attributes.put("key-2", "value-2"); - JsonObject object = VnfSearchQueryBuilder.createSummaryByEntityTypeQuery(attributes, "groupkey-1"); - Assert.assertNotNull(object); - } + @Test + public void testCreateSuggestionsQuery() { + String maxResults = "maxResults-1"; + String queryStr = "queryStr-1"; + JsonObject object = VnfSearchQueryBuilder.createSuggestionsQuery(maxResults, queryStr); + Assert.assertNotNull(object); + } + + @Test + public void testSortCriteria() { + JsonArray array = VnfSearchQueryBuilder.getSortCriteria("field-1", "sortOrder-1"); + Assert.assertNotNull(array); + } + + @Test + public void testCreateEntityCountsQuery_SingleAttribute() { + Map attributes = new HashMap<>(); + attributes.put("key-1", "value-1"); + JsonObject object = VnfSearchQueryBuilder.createEntityCountsQuery(attributes); + Assert.assertNotNull(object); + } + + @Test + public void testCreateSummaryByEntityTypeQuery_Single() { + Map attributes = new HashMap<>(); + attributes.put("key-1", "value-1"); + JsonObject object = + VnfSearchQueryBuilder.createSummaryByEntityTypeQuery(attributes, "groupkey-1"); + Assert.assertNotNull(object); + } + + @Test + public void testCreateSummaryByEntityTypeQuery_Multiple() { + Map attributes = new HashMap<>(); + attributes.put("key-1", "value-1"); + attributes.put("key-2", "value-2"); + JsonObject object = + VnfSearchQueryBuilder.createSummaryByEntityTypeQuery(attributes, "groupkey-1"); + Assert.assertNotNull(object); + } } diff --git a/src/test/java/org/onap/aai/sparky/search/VnfSearchServiceTest.java b/src/test/java/org/onap/aai/sparky/search/VnfSearchServiceTest.java index 8c4d59d..ed77e25 100644 --- a/src/test/java/org/onap/aai/sparky/search/VnfSearchServiceTest.java +++ b/src/test/java/org/onap/aai/sparky/search/VnfSearchServiceTest.java @@ -41,49 +41,54 @@ import org.onap.aai.sparky.viewandinspect.entity.QuerySearchEntity; public class VnfSearchServiceTest { - VnfSearchService searchService; - - @Before - public void init() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException, IOException { - System.setProperty("AJSC_HOME", new File(".").getCanonicalPath().replace('\\', '/')); - TierSupportUiConstants.DYNAMIC_CONFIG_APP_LOCATION = System.getProperty("AJSC_HOME")+"/src/test/resources/appconfig/"; - ElasticSearchConfig.setConfig(null); - setFinalStatic(); - searchService = new VnfSearchService(); - } - @Test - public void testSetZeroCountResponse() throws IOException { - HttpServletResponse response = Mockito.mock(HttpServletResponse.class); - Mockito.doNothing().when(response).setStatus(1); - Mockito.doNothing().when(response).setContentType(Mockito.anyString()); - PrintWriter writer = Mockito.mock(PrintWriter.class); - Mockito.doNothing().when(writer).println(Mockito.anyString()); - Mockito.doNothing().when(writer).close(); - Mockito.when(response.getWriter()).thenReturn(writer); - searchService.setZeroCountResponse(response); - } - - @Test - public void testSetEmptyAggResponse() throws IOException { - HttpServletResponse response = Mockito.mock(HttpServletResponse.class); - Mockito.doNothing().when(response).setStatus(1); - Mockito.doNothing().when(response).setContentType(Mockito.anyString()); - PrintWriter writer = Mockito.mock(PrintWriter.class); - Mockito.doNothing().when(writer).println(Mockito.anyString()); - Mockito.doNothing().when(writer).close(); - Mockito.when(response.getWriter()).thenReturn(writer); - searchService.setEmptyAggResponse(response); - } - - - static void setFinalStatic() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { - Field configField = ElasticSearchConfig.class.getDeclaredField("CONFIG_FILE"); - configField.setAccessible(true); + VnfSearchService searchService; - Field modifiersField = Field.class.getDeclaredField( "modifiers" ); - modifiersField.setAccessible( true ); - modifiersField.setInt( configField, configField.getModifiers() & ~Modifier.FINAL ); + @Before + public void init() throws NoSuchFieldException, SecurityException, IllegalArgumentException, + IllegalAccessException, IOException { + System.setProperty("AJSC_HOME", new File(".").getCanonicalPath().replace('\\', '/')); + TierSupportUiConstants.DYNAMIC_CONFIG_APP_LOCATION = + System.getProperty("AJSC_HOME") + "/src/test/resources/appconfig/"; + ElasticSearchConfig.setConfig(null); + setFinalStatic(); + searchService = new VnfSearchService(); + } - configField.set(null, System.getProperty("AJSC_HOME")+"/src/test/resources/appconfig/elasticsearch.properties"); - } + @Test + public void testSetZeroCountResponse() throws IOException { + HttpServletResponse response = Mockito.mock(HttpServletResponse.class); + Mockito.doNothing().when(response).setStatus(1); + Mockito.doNothing().when(response).setContentType(Mockito.anyString()); + PrintWriter writer = Mockito.mock(PrintWriter.class); + Mockito.doNothing().when(writer).println(Mockito.anyString()); + Mockito.doNothing().when(writer).close(); + Mockito.when(response.getWriter()).thenReturn(writer); + searchService.setZeroCountResponse(response); + } + + @Test + public void testSetEmptyAggResponse() throws IOException { + HttpServletResponse response = Mockito.mock(HttpServletResponse.class); + Mockito.doNothing().when(response).setStatus(1); + Mockito.doNothing().when(response).setContentType(Mockito.anyString()); + PrintWriter writer = Mockito.mock(PrintWriter.class); + Mockito.doNothing().when(writer).println(Mockito.anyString()); + Mockito.doNothing().when(writer).close(); + Mockito.when(response.getWriter()).thenReturn(writer); + searchService.setEmptyAggResponse(response); + } + + + static void setFinalStatic() throws NoSuchFieldException, SecurityException, + IllegalArgumentException, IllegalAccessException { + Field configField = ElasticSearchConfig.class.getDeclaredField("CONFIG_FILE"); + configField.setAccessible(true); + + Field modifiersField = Field.class.getDeclaredField("modifiers"); + modifiersField.setAccessible(true); + modifiersField.setInt(configField, configField.getModifiers() & ~Modifier.FINAL); + + configField.set(null, + System.getProperty("AJSC_HOME") + "/src/test/resources/appconfig/elasticsearch.properties"); + } } diff --git a/src/test/java/org/onap/aai/sparky/search/filters/FilteredSearchHelperTest.java b/src/test/java/org/onap/aai/sparky/search/filters/FilteredSearchHelperTest.java index aa37d42..062aa04 100644 --- a/src/test/java/org/onap/aai/sparky/search/filters/FilteredSearchHelperTest.java +++ b/src/test/java/org/onap/aai/sparky/search/filters/FilteredSearchHelperTest.java @@ -47,7 +47,7 @@ public class FilteredSearchHelperTest { config.setViewsConfig(config.readUiViewsConfig()); System.out.println("SETTING UIFILTERSCONFIG"); config.setFiltersConfig(config.readUiFiltersConfig()); - + filteredSearchHelper = new FilteredSearchHelper(config); } diff --git a/src/test/java/org/onap/aai/sparky/search/filters/entity/DiscoverFiltersRequest.java b/src/test/java/org/onap/aai/sparky/search/filters/entity/DiscoverFiltersRequest.java index 336e3b1..f836821 100644 --- a/src/test/java/org/onap/aai/sparky/search/filters/entity/DiscoverFiltersRequest.java +++ b/src/test/java/org/onap/aai/sparky/search/filters/entity/DiscoverFiltersRequest.java @@ -36,5 +36,5 @@ public class DiscoverFiltersRequest { public void setViewName(String viewName) { this.viewName = viewName; } - + } diff --git a/src/test/java/org/onap/aai/sparky/security/portal/TestPortalRestAPIServiceImpl.java b/src/test/java/org/onap/aai/sparky/security/portal/TestPortalRestAPIServiceImpl.java index 815199f..a84748b 100644 --- a/src/test/java/org/onap/aai/sparky/security/portal/TestPortalRestAPIServiceImpl.java +++ b/src/test/java/org/onap/aai/sparky/security/portal/TestPortalRestAPIServiceImpl.java @@ -63,9 +63,9 @@ import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; import org.powermock.reflect.Whitebox; -@PowerMockIgnore({ "javax.crypto.*" }) +@PowerMockIgnore({"javax.crypto.*"}) @RunWith(PowerMockRunner.class) -@PrepareForTest({ PortalAuthenticationConfig.class, RolesConfig.class }) +@PrepareForTest({PortalAuthenticationConfig.class, RolesConfig.class}) public class TestPortalRestAPIServiceImpl { private static File testUsersFile; @@ -75,13 +75,19 @@ public class TestPortalRestAPIServiceImpl { enum TestData { // @formatter:off - TEST_USERS ("src/test/resources/portal/test-users.config"), - PORTAL_AUTHENTICATION_PROPERTIES ("src/test/resources/portal/portal-authentication.properties"), - ROLES_CONFIG_FILE ("src/test/resources/portal/roles.config"); + TEST_USERS("src/test/resources/portal/test-users.config"), PORTAL_AUTHENTICATION_PROPERTIES( + "src/test/resources/portal/portal-authentication.properties"), ROLES_CONFIG_FILE( + "src/test/resources/portal/roles.config"); private String filename; - TestData(String filename) {this.filename = filename;} - public String getFilename() {return this.filename;} + + TestData(String filename) { + this.filename = filename; + } + + public String getFilename() { + return this.filename; + } // @formatter:on } @@ -268,4 +274,4 @@ public class TestPortalRestAPIServiceImpl { assertThat(userWithNoRoles.getRoles(), empty()); } -} \ No newline at end of file +} diff --git a/src/test/java/org/onap/aai/sparky/security/portal/TestUserManager.java b/src/test/java/org/onap/aai/sparky/security/portal/TestUserManager.java index 16669fd..2bc06ef 100644 --- a/src/test/java/org/onap/aai/sparky/security/portal/TestUserManager.java +++ b/src/test/java/org/onap/aai/sparky/security/portal/TestUserManager.java @@ -54,7 +54,7 @@ import org.powermock.modules.junit4.PowerMockRunner; import com.google.gson.Gson; @RunWith(PowerMockRunner.class) -//@PrepareForTest(RolesConfig.class) +// @PrepareForTest(RolesConfig.class) public class TestUserManager { private static final String LOGINID_3 = "3"; @@ -68,14 +68,20 @@ public class TestUserManager { enum TestData { // @formatter:off - NO_FILE ("src/test/resources/portal/no-users.config"), - CONCURRENT_USERS ("src/test/resources/portal/concurrent-users.config"), - CONCURRENT_EDIT_USERS ("src/test/resources/portal/concurrent-edit-users.config"); -// ROLES_CONFIG_FILE ("src/test/resources/portal/roles.config"); + NO_FILE("src/test/resources/portal/no-users.config"), CONCURRENT_USERS( + "src/test/resources/portal/concurrent-users.config"), CONCURRENT_EDIT_USERS( + "src/test/resources/portal/concurrent-edit-users.config"); + // ROLES_CONFIG_FILE ("src/test/resources/portal/roles.config"); private String filename; - TestData(String filename) {this.filename = filename;} - public String getFilename() {return this.filename;} + + TestData(String filename) { + this.filename = filename; + } + + public String getFilename() { + return this.filename; + } // @formatter:on } @@ -103,8 +109,8 @@ public class TestUserManager { List users = Arrays.asList(user1, user2); Files.write(concurrentEditUsers.toPath(), GSON.toJson(users).getBytes()); -// Whitebox.setInternalState(RolesConfig.class, "ROLES_CONFIG_FILE", -// TestData.ROLES_CONFIG_FILE.getFilename()); + // Whitebox.setInternalState(RolesConfig.class, "ROLES_CONFIG_FILE", + // TestData.ROLES_CONFIG_FILE.getFilename()); } @After @@ -127,8 +133,8 @@ public class TestUserManager { return pushTask(concurrentUsers, String.valueOf(NodeUtils.getRandomTxnId())); }; - List> callables = Arrays.asList(pushTask, pushTask, pushTask, pushTask, - pushTask); + List> callables = + Arrays.asList(pushTask, pushTask, pushTask, pushTask, pushTask); ExecutorService executor = Executors.newWorkStealingPool(); executor.invokeAll(callables).stream().map(future -> { @@ -165,9 +171,9 @@ public class TestUserManager { return editTask(LOGINID_3, "Amy"); }; - List> callables = Arrays.asList(pushTaskRandomId, pushTaskRandomId, - pushTaskId3, editTaskId1, pushTaskRandomId, pushTaskRandomId, editTaskId3, editTaskId2, - pushTaskRandomId); + List> callables = + Arrays.asList(pushTaskRandomId, pushTaskRandomId, pushTaskId3, editTaskId1, + pushTaskRandomId, pushTaskRandomId, editTaskId3, editTaskId2, pushTaskRandomId); ExecutorService executor = Executors.newWorkStealingPool(); List userTasks = executor.invokeAll(callables).stream().map(future -> { @@ -203,4 +209,4 @@ public class TestUserManager { userManager.editUser(loginId, user); return user; } -} \ No newline at end of file +} diff --git a/src/test/java/org/onap/aai/sparky/synchronizer/AggregationSuggestionSynchronizerTest.java b/src/test/java/org/onap/aai/sparky/synchronizer/AggregationSuggestionSynchronizerTest.java index e590af6..b903851 100644 --- a/src/test/java/org/onap/aai/sparky/synchronizer/AggregationSuggestionSynchronizerTest.java +++ b/src/test/java/org/onap/aai/sparky/synchronizer/AggregationSuggestionSynchronizerTest.java @@ -40,47 +40,52 @@ import org.onap.aai.sparky.viewandinspect.config.TierSupportUiConstants; public class AggregationSuggestionSynchronizerTest { - @Before - public void init() throws IOException { - System.setProperty("AJSC_HOME", new File(".").getCanonicalPath().replace('\\', '/')); - TierSupportUiConstants.DYNAMIC_CONFIG_APP_LOCATION = System.getProperty("AJSC_HOME")+"/src/test/resources/appconfig/"; - // TierSupportUiConstants.CONFIG_OXM_LOCATION = System.getProperty("AJSC_HOME")+"/bundleconfig-local/oxm/"; - } - - @Test - public void testDoSync() throws Exception { - ElasticSearchConfig.setConfig(null); - setFinalStatic(); - AggregationSuggestionSynchronizer ass = new AggregationSuggestionSynchronizer("entity-search-index"); - Assert.assertNotNull(ass); - OperationState state = ass.doSync(); - Assert.assertEquals(OperationState.OK, state); + @Before + public void init() throws IOException { + System.setProperty("AJSC_HOME", new File(".").getCanonicalPath().replace('\\', '/')); + TierSupportUiConstants.DYNAMIC_CONFIG_APP_LOCATION = + System.getProperty("AJSC_HOME") + "/src/test/resources/appconfig/"; + // TierSupportUiConstants.CONFIG_OXM_LOCATION = + // System.getProperty("AJSC_HOME")+"/bundleconfig-local/oxm/"; + } - OperationResult result = new OperationResult(); - result.setResultCode(200); - result.setResult("result-1"); - result.setNumRequestRetries(1); - NetworkTransaction ntwTxn = new NetworkTransaction(HttpMethod.GET, "entity-1", result); - ass.updateElasticSearchCounters(ntwTxn); + @Test + public void testDoSync() throws Exception { + ElasticSearchConfig.setConfig(null); + setFinalStatic(); + AggregationSuggestionSynchronizer ass = + new AggregationSuggestionSynchronizer("entity-search-index"); + Assert.assertNotNull(ass); + OperationState state = ass.doSync(); + Assert.assertEquals(OperationState.OK, state); - SynchronizerState syncState = ass.getState(); - Assert.assertEquals(SynchronizerState.IDLE, syncState); - - String statReport = ass.getStatReport(true); - Assert.assertNotNull(statReport); - Assert.assertTrue(statReport.contains("Aggregation Suggestion Synchronizer")); - - ass.shutdown(); - } + OperationResult result = new OperationResult(); + result.setResultCode(200); + result.setResult("result-1"); + result.setNumRequestRetries(1); + NetworkTransaction ntwTxn = new NetworkTransaction(HttpMethod.GET, "entity-1", result); + ass.updateElasticSearchCounters(ntwTxn); - static void setFinalStatic() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { - Field configField = ElasticSearchConfig.class.getDeclaredField("CONFIG_FILE"); - configField.setAccessible(true); + SynchronizerState syncState = ass.getState(); + Assert.assertEquals(SynchronizerState.IDLE, syncState); - Field modifiersField = Field.class.getDeclaredField( "modifiers" ); - modifiersField.setAccessible( true ); - modifiersField.setInt( configField, configField.getModifiers() & ~Modifier.FINAL ); + String statReport = ass.getStatReport(true); + Assert.assertNotNull(statReport); + Assert.assertTrue(statReport.contains("Aggregation Suggestion Synchronizer")); - configField.set(null, System.getProperty("AJSC_HOME")+"/src/test/resources/appconfig/elasticsearch.properties"); - } + ass.shutdown(); + } + + static void setFinalStatic() throws NoSuchFieldException, SecurityException, + IllegalArgumentException, IllegalAccessException { + Field configField = ElasticSearchConfig.class.getDeclaredField("CONFIG_FILE"); + configField.setAccessible(true); + + Field modifiersField = Field.class.getDeclaredField("modifiers"); + modifiersField.setAccessible(true); + modifiersField.setInt(configField, configField.getModifiers() & ~Modifier.FINAL); + + configField.set(null, + System.getProperty("AJSC_HOME") + "/src/test/resources/appconfig/elasticsearch.properties"); + } } diff --git a/src/test/java/org/onap/aai/sparky/synchronizer/IndexDocumentTest.java b/src/test/java/org/onap/aai/sparky/synchronizer/IndexDocumentTest.java index 822e927..1e14d38 100644 --- a/src/test/java/org/onap/aai/sparky/synchronizer/IndexDocumentTest.java +++ b/src/test/java/org/onap/aai/sparky/synchronizer/IndexDocumentTest.java @@ -42,7 +42,7 @@ import ch.qos.logback.classic.Level; /** * The Class IndexDocumentTest. */ -@RunWith(MockitoJUnitRunner.class) +@RunWith(MockitoJUnitRunner.class) public class IndexDocumentTest { private LogValidator logValidator; diff --git a/src/test/java/org/onap/aai/sparky/synchronizer/SyncControllerBuilder.java b/src/test/java/org/onap/aai/sparky/synchronizer/SyncControllerBuilder.java index e97da4f..907ff23 100644 --- a/src/test/java/org/onap/aai/sparky/synchronizer/SyncControllerBuilder.java +++ b/src/test/java/org/onap/aai/sparky/synchronizer/SyncControllerBuilder.java @@ -130,7 +130,7 @@ public class SyncControllerBuilder { ElasticSearchConfig esConfig = ElasticSearchConfig.getConfig(); - ElasticSearchAdapter esAdapter = new ElasticSearchAdapter(nonCachingRestProvider,esConfig); + ElasticSearchAdapter esAdapter = new ElasticSearchAdapter(nonCachingRestProvider, esConfig); IndexIntegrityValidator entityCounterHistoryValidator = @@ -211,7 +211,7 @@ public class SyncControllerBuilder { RestfulDataAccessor nonCachingRestProvider = new RestfulDataAccessor(clientBuilder); ElasticSearchConfig esConfig = ElasticSearchConfig.getConfig(); - ElasticSearchAdapter esAdapter = new ElasticSearchAdapter(nonCachingRestProvider,esConfig); + ElasticSearchAdapter esAdapter = new ElasticSearchAdapter(nonCachingRestProvider, esConfig); IndexIntegrityValidator entitySearchIndexValidator = new IndexIntegrityValidator(nonCachingRestProvider, esConfig.getIndexName(), @@ -266,7 +266,7 @@ public class SyncControllerBuilder { */ public void doSearchableEntitysync() { try { - + ActiveInventoryAdapter aaiAdapter = new ActiveInventoryAdapter(new RestClientBuilder()); @@ -286,10 +286,10 @@ public class SyncControllerBuilder { RestfulDataAccessor nonCachingRestProvider = new RestfulDataAccessor(clientBuilder); ElasticSearchConfig esConfig = ElasticSearchConfig.getConfig(); - ElasticSearchAdapter esAdapter = new ElasticSearchAdapter(nonCachingRestProvider,esConfig); + ElasticSearchAdapter esAdapter = new ElasticSearchAdapter(nonCachingRestProvider, esConfig); ////// - + SyncController syncController = new SyncController("searchtableEntityTestController"); SearchableEntitySynchronizer ses = @@ -340,7 +340,7 @@ public class SyncControllerBuilder { */ public void doCrossEntityReferenceSync() { try { - + ActiveInventoryAdapter aaiAdapter = new ActiveInventoryAdapter(new RestClientBuilder()); @@ -360,12 +360,12 @@ public class SyncControllerBuilder { RestfulDataAccessor nonCachingRestProvider = new RestfulDataAccessor(clientBuilder); ElasticSearchConfig esConfig = ElasticSearchConfig.getConfig(); - ElasticSearchAdapter esAdapter = new ElasticSearchAdapter(nonCachingRestProvider,esConfig); + ElasticSearchAdapter esAdapter = new ElasticSearchAdapter(nonCachingRestProvider, esConfig); SyncController syncController = new SyncController("crossEntityRefSyncController"); - CrossEntityReferenceSynchronizer cers = - new CrossEntityReferenceSynchronizer("entitysearchindex-localhost", ActiveInventoryConfig.getConfig()); + CrossEntityReferenceSynchronizer cers = new CrossEntityReferenceSynchronizer( + "entitysearchindex-localhost", ActiveInventoryConfig.getConfig()); cers.setAaiDataProvider(aaiAdapter); cers.setEsDataProvider(esAdapter); syncController.registerEntitySynchronizer(cers); @@ -413,7 +413,7 @@ public class SyncControllerBuilder { */ public void doSuggestionEntitySync() { try { - + ActiveInventoryAdapter aaiAdapter = new ActiveInventoryAdapter(new RestClientBuilder()); @@ -433,8 +433,8 @@ public class SyncControllerBuilder { RestfulDataAccessor nonCachingRestProvider = new RestfulDataAccessor(clientBuilder); ElasticSearchConfig esConfig = ElasticSearchConfig.getConfig(); - ElasticSearchAdapter esAdapter = new ElasticSearchAdapter(nonCachingRestProvider,esConfig); - + ElasticSearchAdapter esAdapter = new ElasticSearchAdapter(nonCachingRestProvider, esConfig); + SyncController syncController = new SyncController("suggestionEntityTestController"); AutosuggestionSynchronizer ses = @@ -456,7 +456,7 @@ public class SyncControllerBuilder { System.out.println("Error: failed to sync with message = " + exc.getMessage()); } } - + /* * Do no op sync. */ diff --git a/src/test/java/org/onap/aai/sparky/synchronizer/SyncControllerTest.java b/src/test/java/org/onap/aai/sparky/synchronizer/SyncControllerTest.java index c7464d3..bc268df 100644 --- a/src/test/java/org/onap/aai/sparky/synchronizer/SyncControllerTest.java +++ b/src/test/java/org/onap/aai/sparky/synchronizer/SyncControllerTest.java @@ -29,53 +29,58 @@ import org.onap.aai.sparky.synchronizer.SyncController.SyncActions; public class SyncControllerTest { - SyncController controller; + SyncController controller; - @Before - public void init() throws Exception { - controller = new SyncController("name-1"); - } - @Test - public void testPerformAction_PreSync() { - controller.performAction(SyncActions.SYNCHRONIZE); - controller.shutdown(); - } + @Before + public void init() throws Exception { + controller = new SyncController("name-1"); + } - @Test - public void testRegisterIndexCleaner_NullIndexName() { - IndexCleaner cleaner = new ElasticSearchIndexCleaner(null, null, "index_type-1", "host-1", "port-1", 1, 1); - controller.registerIndexCleaner(cleaner); - } + @Test + public void testPerformAction_PreSync() { + controller.performAction(SyncActions.SYNCHRONIZE); + controller.shutdown(); + } - @Test - public void testRegisterIndexCleaner_NotNullIndexName() { - IndexCleaner cleaner = new ElasticSearchIndexCleaner(null, "index-1", "index_type-1", "host-1", "port-1", 1, 1); - controller.registerIndexCleaner(cleaner); - } + @Test + public void testRegisterIndexCleaner_NullIndexName() { + IndexCleaner cleaner = + new ElasticSearchIndexCleaner(null, null, "index_type-1", "host-1", "port-1", 1, 1); + controller.registerIndexCleaner(cleaner); + } - @Test - public void testRegisterIndexValidator_NullIndexValidator() { - IndexValidator validator = new IndexIntegrityValidator(null, null, "index_type-1", "host-1", "port-1", "json-1"); - controller.registerIndexValidator(validator); - } + @Test + public void testRegisterIndexCleaner_NotNullIndexName() { + IndexCleaner cleaner = + new ElasticSearchIndexCleaner(null, "index-1", "index_type-1", "host-1", "port-1", 1, 1); + controller.registerIndexCleaner(cleaner); + } - @Test - public void testRegisterIndexValidator_NotNullIndexValidator() { - IndexValidator validator = new IndexIntegrityValidator(null, "index-1", "index_type-1", "host-1", "port-1", "json-1"); - controller.registerIndexValidator(validator); - } + @Test + public void testRegisterIndexValidator_NullIndexValidator() { + IndexValidator validator = + new IndexIntegrityValidator(null, null, "index_type-1", "host-1", "port-1", "json-1"); + controller.registerIndexValidator(validator); + } - @Test - public void testRegisterEntitySynchronizer_NullEntitySynchronizer() throws Exception { - IndexSynchronizer synchroniser = Mockito.mock(SearchableEntitySynchronizer.class); - Mockito.when(synchroniser.getIndexName()).thenReturn(null); - controller.registerEntitySynchronizer(synchroniser); - } + @Test + public void testRegisterIndexValidator_NotNullIndexValidator() { + IndexValidator validator = + new IndexIntegrityValidator(null, "index-1", "index_type-1", "host-1", "port-1", "json-1"); + controller.registerIndexValidator(validator); + } - @Test - public void testRegisterEntitySynchronizer_NotNullEntitySynchronizer() throws Exception { - IndexSynchronizer synchroniser = Mockito.mock(SearchableEntitySynchronizer.class); - Mockito.when(synchroniser.getIndexName()).thenReturn("entity-1"); - controller.registerEntitySynchronizer(synchroniser); - } + @Test + public void testRegisterEntitySynchronizer_NullEntitySynchronizer() throws Exception { + IndexSynchronizer synchroniser = Mockito.mock(SearchableEntitySynchronizer.class); + Mockito.when(synchroniser.getIndexName()).thenReturn(null); + controller.registerEntitySynchronizer(synchroniser); + } + + @Test + public void testRegisterEntitySynchronizer_NotNullEntitySynchronizer() throws Exception { + IndexSynchronizer synchroniser = Mockito.mock(SearchableEntitySynchronizer.class); + Mockito.when(synchroniser.getIndexName()).thenReturn("entity-1"); + controller.registerEntitySynchronizer(synchroniser); + } } diff --git a/src/test/java/org/onap/aai/sparky/synchronizer/SyncHelperTest.java b/src/test/java/org/onap/aai/sparky/synchronizer/SyncHelperTest.java index 5a2584f..46e6350 100644 --- a/src/test/java/org/onap/aai/sparky/synchronizer/SyncHelperTest.java +++ b/src/test/java/org/onap/aai/sparky/synchronizer/SyncHelperTest.java @@ -45,74 +45,82 @@ import org.onap.aai.sparky.viewandinspect.config.TierSupportUiConstants; @RunWith(MockitoJUnitRunner.class) public class SyncHelperTest { - private SyncHelper syncHelper; - - @BeforeClass - public static void initBeforeClass() throws IOException, NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { - String configHomePath = - (new File(".").getCanonicalPath() + "/src/test/resources/appconfig/").replace('\\', '/'); - TierSupportUiConstants.AJSC_HOME = configHomePath; - TierSupportUiConstants.CONFIG_HOME = configHomePath; - TierSupportUiConstants.DYNAMIC_CONFIG_APP_LOCATION = configHomePath; - ElasticSearchConfig.setConfig(null); - SynchronizerConfiguration.setInstance(null); - setFinalStatic(); - System.setProperty("AJSC_HOME", new File(".").getCanonicalPath().replace('\\', '/')); - TierSupportUiConstants.DYNAMIC_CONFIG_APP_LOCATION = System.getProperty("AJSC_HOME")+"/src/test/resources/appconfig/"; - } - - - @Test - public void testGetOxmModelLoader() throws Exception { - syncHelper = new SyncHelper(new OxmModelLoader()); - OxmModelLoader oxmLoader = new OxmModelLoader(); - syncHelper.setOxmModelLoader(oxmLoader); - assertEquals(oxmLoader, syncHelper.getOxmModelLoader()); - } - - @Test - public void testGetFirstSyncTime(){ - SyncHelper syncHelper = new SyncHelper(new OxmModelLoader()); - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z"); - TimeZone tz = TimeZone.getTimeZone("05:00:00 GMT+00:00"); - Calendar calendar = Calendar.getInstance(tz); - sdf.setTimeZone(tz); - - calendar.set(Calendar.HOUR_OF_DAY, 1); - calendar.set(Calendar.MINUTE, 1); - calendar.set(Calendar.SECOND, 1); - - long timeCurrent = calendar.getTimeInMillis(); - int taskFrequencyInDay = 2; - - assertEquals(calendar.getTimeInMillis(), syncHelper.getFirstSyncTime(calendar, timeCurrent, taskFrequencyInDay)); - taskFrequencyInDay = 0; - assertEquals(SynchronizerConstants.DELAY_NO_PERIODIC_SYNC_IN_MS, syncHelper.getFirstSyncTime(calendar, timeCurrent, taskFrequencyInDay)); - timeCurrent = timeCurrent + 100; - taskFrequencyInDay = 2; - Calendar expCalendar = calendar; - expCalendar.add(Calendar.DAY_OF_MONTH, taskFrequencyInDay); - //assertEquals(expCalendar.getTimeInMillis(), syncHelper.getFirstSyncTime(calendar, calendar.getTimeInMillis() + 100, taskFrequencyInDay)); - - } - - static void setFinalStatic() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { - Field configField = ElasticSearchConfig.class.getDeclaredField("CONFIG_FILE"); - configField.setAccessible(true); - - Field modifiersField = Field.class.getDeclaredField( "modifiers" ); - modifiersField.setAccessible( true ); - modifiersField.setInt( configField, configField.getModifiers() & ~Modifier.FINAL ); - - configField.set(null, System.getProperty("AJSC_HOME")+"/src/test/resources/appconfig/elasticsearch.properties"); - - Field syncField = SynchronizerConfiguration.class.getDeclaredField("CONFIG_FILE"); - syncField.setAccessible(true); - - Field syncModifiersField = Field.class.getDeclaredField( "modifiers" ); - syncModifiersField.setAccessible( true ); - syncModifiersField.setInt( syncField, syncField.getModifiers() & ~Modifier.FINAL ); - - syncField.set(null, System.getProperty("AJSC_HOME")+"/src/test/resources/appconfig/synchronizer.properties"); - } + private SyncHelper syncHelper; + + @BeforeClass + public static void initBeforeClass() throws IOException, NoSuchFieldException, SecurityException, + IllegalArgumentException, IllegalAccessException { + String configHomePath = + (new File(".").getCanonicalPath() + "/src/test/resources/appconfig/").replace('\\', '/'); + TierSupportUiConstants.AJSC_HOME = configHomePath; + TierSupportUiConstants.CONFIG_HOME = configHomePath; + TierSupportUiConstants.DYNAMIC_CONFIG_APP_LOCATION = configHomePath; + ElasticSearchConfig.setConfig(null); + SynchronizerConfiguration.setInstance(null); + setFinalStatic(); + System.setProperty("AJSC_HOME", new File(".").getCanonicalPath().replace('\\', '/')); + TierSupportUiConstants.DYNAMIC_CONFIG_APP_LOCATION = + System.getProperty("AJSC_HOME") + "/src/test/resources/appconfig/"; + } + + + @Test + public void testGetOxmModelLoader() throws Exception { + syncHelper = new SyncHelper(new OxmModelLoader()); + OxmModelLoader oxmLoader = new OxmModelLoader(); + syncHelper.setOxmModelLoader(oxmLoader); + assertEquals(oxmLoader, syncHelper.getOxmModelLoader()); + } + + @Test + public void testGetFirstSyncTime() { + SyncHelper syncHelper = new SyncHelper(new OxmModelLoader()); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z"); + TimeZone tz = TimeZone.getTimeZone("05:00:00 GMT+00:00"); + Calendar calendar = Calendar.getInstance(tz); + sdf.setTimeZone(tz); + + calendar.set(Calendar.HOUR_OF_DAY, 1); + calendar.set(Calendar.MINUTE, 1); + calendar.set(Calendar.SECOND, 1); + + long timeCurrent = calendar.getTimeInMillis(); + int taskFrequencyInDay = 2; + + assertEquals(calendar.getTimeInMillis(), + syncHelper.getFirstSyncTime(calendar, timeCurrent, taskFrequencyInDay)); + taskFrequencyInDay = 0; + assertEquals(SynchronizerConstants.DELAY_NO_PERIODIC_SYNC_IN_MS, + syncHelper.getFirstSyncTime(calendar, timeCurrent, taskFrequencyInDay)); + timeCurrent = timeCurrent + 100; + taskFrequencyInDay = 2; + Calendar expCalendar = calendar; + expCalendar.add(Calendar.DAY_OF_MONTH, taskFrequencyInDay); + // assertEquals(expCalendar.getTimeInMillis(), syncHelper.getFirstSyncTime(calendar, + // calendar.getTimeInMillis() + 100, taskFrequencyInDay)); + + } + + static void setFinalStatic() throws NoSuchFieldException, SecurityException, + IllegalArgumentException, IllegalAccessException { + Field configField = ElasticSearchConfig.class.getDeclaredField("CONFIG_FILE"); + configField.setAccessible(true); + + Field modifiersField = Field.class.getDeclaredField("modifiers"); + modifiersField.setAccessible(true); + modifiersField.setInt(configField, configField.getModifiers() & ~Modifier.FINAL); + + configField.set(null, + System.getProperty("AJSC_HOME") + "/src/test/resources/appconfig/elasticsearch.properties"); + + Field syncField = SynchronizerConfiguration.class.getDeclaredField("CONFIG_FILE"); + syncField.setAccessible(true); + + Field syncModifiersField = Field.class.getDeclaredField("modifiers"); + syncModifiersField.setAccessible(true); + syncModifiersField.setInt(syncField, syncField.getModifiers() & ~Modifier.FINAL); + + syncField.set(null, + System.getProperty("AJSC_HOME") + "/src/test/resources/appconfig/synchronizer.properties"); + } } diff --git a/src/test/java/org/onap/aai/sparky/synchronizer/config/SynchronizerConfigurationTest.java b/src/test/java/org/onap/aai/sparky/synchronizer/config/SynchronizerConfigurationTest.java index b61eebd..228b048 100644 --- a/src/test/java/org/onap/aai/sparky/synchronizer/config/SynchronizerConfigurationTest.java +++ b/src/test/java/org/onap/aai/sparky/synchronizer/config/SynchronizerConfigurationTest.java @@ -14,11 +14,11 @@ import org.junit.Test; public class SynchronizerConfigurationTest { private SynchronizerConfiguration config; - + private Properties generateTestProperties() { - + Properties props = new Properties(); - + props.put("synchronizer.syncTask.initialDelayInMs", "60000"); props.put("synchronizer.syncTask.taskFrequencyInDay", "2"); props.put("synchronizer.syncTask.startTimestamp", "05:00:00 UTC+00:00"); @@ -35,21 +35,21 @@ public class SynchronizerConfigurationTest { props.put("synchronizer.suppressResourceNotFoundErrors", "true"); props.put("synchronizer.applyNodesOnlyModifier", "false"); props.put("synchronizer.autosuggestSynchronizationEnabled", "true"); - + return props; } - - + + @Before public void init() throws Exception { - + config = new SynchronizerConfiguration(generateTestProperties()); } @Test public void validateAccessors() { - + assertEquals(60000, config.getSyncTaskInitialDelayInMs()); assertEquals(2, config.getSyncTaskFrequencyInDay()); assertEquals("05:00:00 UTC+00:00", config.getSyncTaskStartTime()); @@ -57,7 +57,7 @@ public class SynchronizerConfigurationTest { assertEquals(0, config.getSyncTaskStartTimeMin()); assertEquals(0, config.getSyncTaskStartTimeSec()); assertEquals(true, config.isAutosuggestSynchronizationEnabled()); - assertEquals(false, config.isConfigDisabledForInitialSync() ); + assertEquals(false, config.isConfigDisabledForInitialSync()); assertEquals(true, config.isConfigOkForPeriodicSync()); assertEquals(true, config.isConfigOkForStartupSync()); assertEquals(false, config.isDisplayVerboseQueueManagerStats()); @@ -72,177 +72,176 @@ public class SynchronizerConfigurationTest { assertEquals(1000, config.getResolverQueueMonitorFrequencyInMs()); assertEquals(3600000, config.getIndexIntegrityValidatorFrequencyInMs()); assertTrue(config.toString().startsWith("SynchronizerConfiguration")); - - + + config.setSyncTaskInitialDelayInMs(1234); assertEquals(1234, config.getSyncTaskInitialDelayInMs()); - + config.setSyncTaskFrequencyInDay(5); assertEquals(5, config.getSyncTaskFrequencyInDay()); config.setSyncTaskStartTime("06:10:22 UTC+00:00"); assertEquals("06:10:22 UTC+00:00", config.getSyncTaskStartTime()); - + config.setSyncTaskStartTimeHr(6); assertEquals(6, config.getSyncTaskStartTimeHr()); - + config.setSyncTaskStartTimeMin(10); assertEquals(10, config.getSyncTaskStartTimeMin()); config.setSyncTaskStartTimeSec(22); assertEquals(22, config.getSyncTaskStartTimeSec()); - + config.setAutosuggestSynchronizationEnabled(false); assertEquals(false, config.isAutosuggestSynchronizationEnabled()); - + config.setDisplayVerboseQueueManagerStats(true); assertEquals(true, config.isDisplayVerboseQueueManagerStats()); - - + + config.setIndexIntegrityValidatorEnabled(true); assertEquals(true, config.isIndexIntegrityValidatorEnabled()); - + config.setNodesOnlyModifierEnabled(true); assertEquals(true, config.isNodesOnlyModifierEnabled()); config.setResourceNotFoundErrorsSupressed(false); assertEquals(false, config.isResourceNotFoundErrorsSupressed()); - + config.setNumScrollContextItemsToRetrievePerRequest(1234); assertEquals(1234, config.getNumScrollContextItemsToRetrievePerRequest()); - + config.setScrollContextTimeToLiveInMinutes(11); assertEquals(11, config.getScrollContextTimeToLiveInMinutes()); - - + + config.setSyncTaskStartTimeTimeZone("EST"); assertEquals("EST", config.getSyncTaskStartTimeTimeZone()); - + config.setSyncTaskFrequencyInMs(1221); assertEquals(1221, config.getSyncTaskFrequencyInMs()); - + config.setResolverProgressLogFrequencyInMs(1111); assertEquals(1111, config.getResolverProgressLogFrequencyInMs()); - + config.setResolverQueueMonitorFrequencyInMs(1111); assertEquals(1111, config.getResolverQueueMonitorFrequencyInMs()); - + config.setIndexIntegrityValidatorFrequencyInMs(5555); assertEquals(5555, config.getIndexIntegrityValidatorFrequencyInMs()); - + config.setConfigOkForPeriodicSync(false); assertEquals(false, config.isConfigOkForPeriodicSync()); - + config.setConfigOkForStartupSync(false); assertEquals(false, config.isConfigOkForStartupSync()); - + } - + @Test public void validateFirstSyncTimeCalculation_taskFrequencyZeroDays() { - - Calendar syncThresholdTime = Calendar.getInstance(TimeZone.getTimeZone("EST"),Locale.CANADA); + + Calendar syncThresholdTime = Calendar.getInstance(TimeZone.getTimeZone("EST"), Locale.CANADA); // set year, month, day, hour, minute, second - syncThresholdTime.set(2017,2,1,0,0,0); // 00:00 on 1-Feb-2017 - - - Calendar timeNow = Calendar.getInstance(TimeZone.getTimeZone("EST"),Locale.CANADA); + syncThresholdTime.set(2017, 2, 1, 0, 0, 0); // 00:00 on 1-Feb-2017 + + + Calendar timeNow = Calendar.getInstance(TimeZone.getTimeZone("EST"), Locale.CANADA); // set year, month, day, hour, minute, second - timeNow.set(2017,2,1,0,0,0); // 00:00 on 1-Feb-2017 + timeNow.set(2017, 2, 1, 0, 0, 0); // 00:00 on 1-Feb-2017 + + assertEquals(0, config.getNextSyncTime(syncThresholdTime, timeNow.getTimeInMillis(), 0)); - assertEquals( 0, config.getNextSyncTime(syncThresholdTime, timeNow.getTimeInMillis(), 0)); - } - + @Test public void validateFirstSyncTimeCalculation_timeNowLessThanSyncTimeBoundary() { - - Calendar syncThresholdTime = Calendar.getInstance(TimeZone.getTimeZone("EST"),Locale.CANADA); + + Calendar syncThresholdTime = Calendar.getInstance(TimeZone.getTimeZone("EST"), Locale.CANADA); // 06:00 on 1-Feb-2017 - syncThresholdTime.set(2017,2,1,6,0,0); - - Calendar timeNow = Calendar.getInstance(TimeZone.getTimeZone("EST"),Locale.CANADA); + syncThresholdTime.set(2017, 2, 1, 6, 0, 0); + + Calendar timeNow = Calendar.getInstance(TimeZone.getTimeZone("EST"), Locale.CANADA); // set year, month, day, hour, minute, second - timeNow.set(2017,2,1,0,0,0); // 00:00 on 1-Feb-2017 - + timeNow.set(2017, 2, 1, 0, 0, 0); // 00:00 on 1-Feb-2017 + // First sync time is the 06:00 am threshold time - assertEquals( syncThresholdTime.getTimeInMillis(), config.getNextSyncTime(syncThresholdTime, timeNow.getTimeInMillis(), 1*86400)); - + assertEquals(syncThresholdTime.getTimeInMillis(), + config.getNextSyncTime(syncThresholdTime, timeNow.getTimeInMillis(), 1 * 86400)); + } - + @Test public void validateFirstSyncTimeCalculation_timeNowEqualsSyncTimeBoundary() { - - Calendar syncThresholdTime = Calendar.getInstance(TimeZone.getTimeZone("EST"),Locale.CANADA); + + Calendar syncThresholdTime = Calendar.getInstance(TimeZone.getTimeZone("EST"), Locale.CANADA); // 06:00 on 1-Feb-2017 - syncThresholdTime.set(2017,2,1,6,0,0); - - Calendar timeNow = Calendar.getInstance(TimeZone.getTimeZone("EST"),Locale.CANADA); + syncThresholdTime.set(2017, 2, 1, 6, 0, 0); + + Calendar timeNow = Calendar.getInstance(TimeZone.getTimeZone("EST"), Locale.CANADA); // set year, month, day, hour, minute, second - timeNow.set(2017,2,1,6,0,0); // 00:00 on 1-Feb-2017 - + timeNow.set(2017, 2, 1, 6, 0, 0); // 00:00 on 1-Feb-2017 + // First sync time is the 06:00 am threshold time - //assertEquals( (syncThresholdTime.getTimeInMillis()/1000), (config.getNextSyncTime(syncThresholdTime, timeNow.getTimeInMillis(), 1*86400)/1000)); - + // assertEquals( (syncThresholdTime.getTimeInMillis()/1000), + // (config.getNextSyncTime(syncThresholdTime, timeNow.getTimeInMillis(), 1*86400)/1000)); + } - + @Test public void validateFirstSyncTimeCalculation_timeNowGreaterThanSyncTimeBoundary() { - - Calendar syncThresholdTime = Calendar.getInstance(TimeZone.getTimeZone("EST"),Locale.CANADA); + + Calendar syncThresholdTime = Calendar.getInstance(TimeZone.getTimeZone("EST"), Locale.CANADA); // 06:00 on 1-Feb-2017 - syncThresholdTime.set(2017,2,1,6,0,0); - - Calendar timeNow = Calendar.getInstance(TimeZone.getTimeZone("EST"),Locale.CANADA); + syncThresholdTime.set(2017, 2, 1, 6, 0, 0); + + Calendar timeNow = Calendar.getInstance(TimeZone.getTimeZone("EST"), Locale.CANADA); // set year, month, day, hour, minute, second - timeNow.set(2017,2,1,8,0,0); // 00:00 on 1-Feb-2017 - + timeNow.set(2017, 2, 1, 8, 0, 0); // 00:00 on 1-Feb-2017 + // First sync time is 1 full sync period past the sync threshold time - assertEquals( 86400000 + syncThresholdTime.getTimeInMillis(), config.getNextSyncTime(syncThresholdTime, timeNow.getTimeInMillis(), 1*86400)); - + assertEquals(86400000 + syncThresholdTime.getTimeInMillis(), + config.getNextSyncTime(syncThresholdTime, timeNow.getTimeInMillis(), 1 * 86400)); + } - -/* @Test - public void validateDefaultPeriodicInitialSyncDelay_dailySync_timeNowAtMidnight() { - - config.setSyncTaskStartTimeTimeZone("EST"); - config.setSyncTaskStartTimeHr(6); - config.setSyncTaskStartTimeMin(0); - config.setSyncTaskStartTimeSec(0); - config.setSyncTaskFrequencyInDay(1); - config.setSyncTaskInitialDelayInMs(60000); - - Calendar timeNow = Calendar.getInstance(TimeZone.getTimeZone("EST")); - // set year, month, day, hour, minute, second - timeNow.set(Calendar.AM_PM, Calendar.AM); - timeNow.set(Calendar.HOUR, 0); - timeNow.set(Calendar.MINUTE, 0); - timeNow.set(Calendar.SECOND, 0); - - // First sync time is 6 hours from midnight - assertEquals( 6*3600*1000, config.getDefaultInitialSyncDelayInMs(timeNow)); - - }*/ - + /* + * @Test public void validateDefaultPeriodicInitialSyncDelay_dailySync_timeNowAtMidnight() { + * + * config.setSyncTaskStartTimeTimeZone("EST"); config.setSyncTaskStartTimeHr(6); + * config.setSyncTaskStartTimeMin(0); config.setSyncTaskStartTimeSec(0); + * config.setSyncTaskFrequencyInDay(1); config.setSyncTaskInitialDelayInMs(60000); + * + * Calendar timeNow = Calendar.getInstance(TimeZone.getTimeZone("EST")); + * + * // set year, month, day, hour, minute, second timeNow.set(Calendar.AM_PM, Calendar.AM); + * timeNow.set(Calendar.HOUR, 0); timeNow.set(Calendar.MINUTE, 0); timeNow.set(Calendar.SECOND, + * 0); + * + * // First sync time is 6 hours from midnight assertEquals( 6*3600*1000, + * config.getDefaultInitialSyncDelayInMs(timeNow)); + * + * } + */ + @Test public void validateDefaultPeriodicInitialSyncDelay_dailySync_timeNowAt4AM() { - + config.setSyncTaskStartTimeTimeZone("EST"); config.setSyncTaskStartTimeHr(6); config.setSyncTaskStartTimeMin(0); config.setSyncTaskStartTimeSec(0); config.setSyncTaskFrequencyInDay(1); config.setSyncTaskInitialDelayInMs(60000); - + Calendar timeNow = Calendar.getInstance(TimeZone.getTimeZone("EST")); // set year, month, day, hour, minute, second @@ -250,22 +249,22 @@ public class SynchronizerConfigurationTest { timeNow.set(Calendar.HOUR, 4); timeNow.set(Calendar.MINUTE, 0); timeNow.set(Calendar.SECOND, 0); - + // round time to minutes to avoid millisecond alignment variance assertEquals(2 * 3600, (config.getDefaultInitialSyncDelayInMs(timeNow)) / 1000); } - + @Test public void validateDefaultPeriodicInitialSyncDelay_dailySync_timeNowAt6AM() { - + config.setSyncTaskStartTimeTimeZone("EST"); config.setSyncTaskStartTimeHr(6); config.setSyncTaskStartTimeMin(0); config.setSyncTaskStartTimeSec(0); config.setSyncTaskFrequencyInDay(1); config.setSyncTaskInitialDelayInMs(60000); - + Calendar timeNow = Calendar.getInstance(TimeZone.getTimeZone("EST")); // set year, month, day, hour, minute, second @@ -273,22 +272,22 @@ public class SynchronizerConfigurationTest { timeNow.set(Calendar.HOUR, 6); timeNow.set(Calendar.MINUTE, 0); timeNow.set(Calendar.SECOND, 0); - - // First sync time is now with 60 seconds from now - assertEquals( 60000, config.getDefaultInitialSyncDelayInMs(timeNow)); - + + // First sync time is now with 60 seconds from now + assertEquals(60000, config.getDefaultInitialSyncDelayInMs(timeNow)); + } - + @Test public void validateDefaultPeriodicInitialSyncDelay_dailySync_timeNowAt10PM() { - + config.setSyncTaskStartTimeTimeZone("EST"); config.setSyncTaskStartTimeHr(6); config.setSyncTaskStartTimeMin(0); config.setSyncTaskStartTimeSec(0); config.setSyncTaskFrequencyInDay(1); config.setSyncTaskInitialDelayInMs(60000); - + Calendar timeNow = Calendar.getInstance(TimeZone.getTimeZone("EST")); // set year, month, day, hour, minute, second @@ -296,46 +295,42 @@ public class SynchronizerConfigurationTest { timeNow.set(Calendar.HOUR, 10); timeNow.set(Calendar.MINUTE, 0); timeNow.set(Calendar.SECOND, 0); - - // First sync time is now 1 sync period delayed. The time delay before + + // First sync time is now 1 sync period delayed. The time delay before // the initial sync should now be 8 hours, assuming 10PM is the current time. - assertEquals( 8*3600, (config.getDefaultInitialSyncDelayInMs(timeNow)/1000)); - + assertEquals(8 * 3600, (config.getDefaultInitialSyncDelayInMs(timeNow) / 1000)); + } - -/* @Test - public void validateDefaultPeriodicInitialSyncDelay_weeklySync_timeNowAtMidnight() { - - config.setSyncTaskStartTimeTimeZone("EST"); - config.setSyncTaskStartTimeHr(6); - config.setSyncTaskStartTimeMin(0); - config.setSyncTaskStartTimeSec(0); - config.setSyncTaskFrequencyInDay(7); - config.setSyncTaskInitialDelayInMs(60000); - - Calendar timeNow = Calendar.getInstance(TimeZone.getTimeZone("EST")); - // set year, month, day, hour, minute, second - timeNow.set(Calendar.AM_PM, Calendar.AM); - timeNow.set(Calendar.HOUR, 0); - timeNow.set(Calendar.MINUTE, 0); - timeNow.set(Calendar.SECOND, 0); - - // First sync time is 6 hours from midnight - assertTrue(6*3600*1000 >= config.getDefaultInitialSyncDelayInMs(timeNow)); - - }*/ - + /* + * @Test public void validateDefaultPeriodicInitialSyncDelay_weeklySync_timeNowAtMidnight() { + * + * config.setSyncTaskStartTimeTimeZone("EST"); config.setSyncTaskStartTimeHr(6); + * config.setSyncTaskStartTimeMin(0); config.setSyncTaskStartTimeSec(0); + * config.setSyncTaskFrequencyInDay(7); config.setSyncTaskInitialDelayInMs(60000); + * + * Calendar timeNow = Calendar.getInstance(TimeZone.getTimeZone("EST")); + * + * // set year, month, day, hour, minute, second timeNow.set(Calendar.AM_PM, Calendar.AM); + * timeNow.set(Calendar.HOUR, 0); timeNow.set(Calendar.MINUTE, 0); timeNow.set(Calendar.SECOND, + * 0); + * + * // First sync time is 6 hours from midnight assertTrue(6*3600*1000 >= + * config.getDefaultInitialSyncDelayInMs(timeNow)); + * + * } + */ + @Test public void validateDefaultPeriodicInitialSyncDelay_weeklySync_timeNowAt4AM() { - + config.setSyncTaskStartTimeTimeZone("EST"); config.setSyncTaskStartTimeHr(6); config.setSyncTaskStartTimeMin(0); config.setSyncTaskStartTimeSec(0); config.setSyncTaskFrequencyInDay(7); config.setSyncTaskInitialDelayInMs(60000); - + Calendar timeNow = Calendar.getInstance(TimeZone.getTimeZone("EST")); // set year, month, day, hour, minute, second @@ -343,22 +338,22 @@ public class SynchronizerConfigurationTest { timeNow.set(Calendar.HOUR, 4); timeNow.set(Calendar.MINUTE, 0); timeNow.set(Calendar.SECOND, 0); - + // round time to minutes to avoid millisecond alignment variance assertEquals(2 * 3600, (config.getDefaultInitialSyncDelayInMs(timeNow)) / 1000); } - + @Test public void validateDefaultPeriodicInitialSyncDelay_weeklySync_timeNowAt6AM() { - + config.setSyncTaskStartTimeTimeZone("EST"); config.setSyncTaskStartTimeHr(6); config.setSyncTaskStartTimeMin(0); config.setSyncTaskStartTimeSec(0); config.setSyncTaskFrequencyInDay(7); config.setSyncTaskInitialDelayInMs(60000); - + Calendar timeNow = Calendar.getInstance(TimeZone.getTimeZone("EST")); // set year, month, day, hour, minute, second @@ -366,22 +361,22 @@ public class SynchronizerConfigurationTest { timeNow.set(Calendar.HOUR, 6); timeNow.set(Calendar.MINUTE, 0); timeNow.set(Calendar.SECOND, 0); - - // First sync time is now with 60 seconds from now - assertEquals( 60000, config.getDefaultInitialSyncDelayInMs(timeNow)); - + + // First sync time is now with 60 seconds from now + assertEquals(60000, config.getDefaultInitialSyncDelayInMs(timeNow)); + } - + @Test public void validateDefaultPeriodicInitialSyncDelay_weeklySync_timeNowAt10PM() { - + config.setSyncTaskStartTimeTimeZone("EST"); config.setSyncTaskStartTimeHr(6); config.setSyncTaskStartTimeMin(0); config.setSyncTaskStartTimeSec(0); config.setSyncTaskFrequencyInDay(7); config.setSyncTaskInitialDelayInMs(60000); - + Calendar timeNow = Calendar.getInstance(TimeZone.getTimeZone("EST")); // set year, month, day, hour, minute, second @@ -389,12 +384,12 @@ public class SynchronizerConfigurationTest { timeNow.set(Calendar.HOUR, 10); timeNow.set(Calendar.MINUTE, 0); timeNow.set(Calendar.SECOND, 0); - - // First sync time is now 1 sync period delayed. The time delay before + + // First sync time is now 1 sync period delayed. The time delay before // the initial sync should now be 8 hours + 24*6 days, assuming 10PM is the current time. - assertEquals( (8+(6*24))*3600, (config.getDefaultInitialSyncDelayInMs(timeNow)/1000)); - + assertEquals((8 + (6 * 24)) * 3600, (config.getDefaultInitialSyncDelayInMs(timeNow) / 1000)); + } - - + + } diff --git a/src/test/java/org/onap/aai/sparky/synchronizer/entity/AggregationSuggestionEntityTest.java b/src/test/java/org/onap/aai/sparky/synchronizer/entity/AggregationSuggestionEntityTest.java index 5b945cf..5aab75d 100644 --- a/src/test/java/org/onap/aai/sparky/synchronizer/entity/AggregationSuggestionEntityTest.java +++ b/src/test/java/org/onap/aai/sparky/synchronizer/entity/AggregationSuggestionEntityTest.java @@ -63,7 +63,7 @@ public class AggregationSuggestionEntityTest { String expectedFilterListPayload = getResourceFileContents( "sync/entity/AggregationSuggestionEntity_getIndexDocumentJson_expected.json"); - assertTrue( - aggregationSuggestionEntity.getIndexDocumentJson().contains(expectedFilterListPayload.trim())); + assertTrue(aggregationSuggestionEntity.getIndexDocumentJson() + .contains(expectedFilterListPayload.trim())); } } diff --git a/src/test/java/org/onap/aai/sparky/util/CaptureLoggerAppender.java b/src/test/java/org/onap/aai/sparky/util/CaptureLoggerAppender.java index 31b425a..3a36f7d 100644 --- a/src/test/java/org/onap/aai/sparky/util/CaptureLoggerAppender.java +++ b/src/test/java/org/onap/aai/sparky/util/CaptureLoggerAppender.java @@ -90,13 +90,17 @@ public class CaptureLoggerAppender implements Appender { - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see ch.qos.logback.core.spi.LifeCycle#start() */ @Override public void start() {} - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see ch.qos.logback.core.spi.LifeCycle#stop() */ @Override @@ -123,7 +127,9 @@ public class CaptureLoggerAppender implements Appender { return null; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see ch.qos.logback.core.spi.ContextAware#addStatus(ch.qos.logback.core.status.Status) */ @Override @@ -132,7 +138,9 @@ public class CaptureLoggerAppender implements Appender { System.out.println("addStatus"); } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see ch.qos.logback.core.spi.ContextAware#addInfo(java.lang.String) */ @Override @@ -141,7 +149,9 @@ public class CaptureLoggerAppender implements Appender { } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see ch.qos.logback.core.spi.ContextAware#addInfo(java.lang.String, java.lang.Throwable) */ @Override @@ -150,7 +160,9 @@ public class CaptureLoggerAppender implements Appender { } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see ch.qos.logback.core.spi.ContextAware#addWarn(java.lang.String) */ @Override @@ -159,7 +171,9 @@ public class CaptureLoggerAppender implements Appender { } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see ch.qos.logback.core.spi.ContextAware#addWarn(java.lang.String, java.lang.Throwable) */ @Override @@ -168,7 +182,9 @@ public class CaptureLoggerAppender implements Appender { } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see ch.qos.logback.core.spi.ContextAware#addError(java.lang.String) */ @Override @@ -177,7 +193,9 @@ public class CaptureLoggerAppender implements Appender { } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see ch.qos.logback.core.spi.ContextAware#addError(java.lang.String, java.lang.Throwable) */ @Override @@ -186,7 +204,9 @@ public class CaptureLoggerAppender implements Appender { } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see ch.qos.logback.core.spi.FilterAttachable#addFilter(ch.qos.logback.core.filter.Filter) */ @Override @@ -195,7 +215,9 @@ public class CaptureLoggerAppender implements Appender { } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see ch.qos.logback.core.spi.FilterAttachable#clearAllFilters() */ @Override @@ -210,7 +232,9 @@ public class CaptureLoggerAppender implements Appender { return null; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see ch.qos.logback.core.spi.FilterAttachable#getFilterChainDecision(java.lang.Object) */ @Override @@ -226,7 +250,9 @@ public class CaptureLoggerAppender implements Appender { return "MOCK"; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see ch.qos.logback.core.Appender#doAppend(java.lang.Object) */ @Override diff --git a/src/test/java/org/onap/aai/sparky/util/ElasticEntitySummarizer.java b/src/test/java/org/onap/aai/sparky/util/ElasticEntitySummarizer.java index 7538c1b..5f98e0b 100644 --- a/src/test/java/org/onap/aai/sparky/util/ElasticEntitySummarizer.java +++ b/src/test/java/org/onap/aai/sparky/util/ElasticEntitySummarizer.java @@ -44,6 +44,7 @@ import org.onap.aai.sparky.synchronizer.config.TaskProcessorConfig; public class ElasticEntitySummarizer { private RestDataProvider syncAdapter; + /** * @return the syncAdapter */ @@ -185,10 +186,8 @@ public class ElasticEntitySummarizer { System.out.println(String.format("\n%-30s %-12d", "Total", totalEntities)); } catch (Exception exc) { - System.out.println( - "An error occurred while attempting to collect pre-sync elastic" - + " search document ids with an error cause = " - + exc.getLocalizedMessage()); + System.out.println("An error occurred while attempting to collect pre-sync elastic" + + " search document ids with an error cause = " + exc.getLocalizedMessage()); } diff --git a/src/test/java/org/onap/aai/sparky/util/ElasticGarbageInjector.java b/src/test/java/org/onap/aai/sparky/util/ElasticGarbageInjector.java index 5e47942..92ccd28 100644 --- a/src/test/java/org/onap/aai/sparky/util/ElasticGarbageInjector.java +++ b/src/test/java/org/onap/aai/sparky/util/ElasticGarbageInjector.java @@ -47,8 +47,8 @@ public class ElasticGarbageInjector { private enum ActiveInventoryEntities { COMPLEX("complex"), CUSTOMER("customer"), GENERIC_VNF("generic-vnf"), NEWVCE("newvce"), PSERVER( - "pserver"), SERVICE_INSTANCE("service-instance"), VCE("vce"), VPE("vpe"), VSERVER( - "vserver"); + "pserver"), SERVICE_INSTANCE( + "service-instance"), VCE("vce"), VPE("vpe"), VSERVER("vserver"); private final String entityName; diff --git a/src/test/java/org/onap/aai/sparky/util/ExceptionHelper.java b/src/test/java/org/onap/aai/sparky/util/ExceptionHelper.java index 6acb1bf..3b56a6e 100644 --- a/src/test/java/org/onap/aai/sparky/util/ExceptionHelper.java +++ b/src/test/java/org/onap/aai/sparky/util/ExceptionHelper.java @@ -29,7 +29,7 @@ package org.onap.aai.sparky.util; * The Class ExceptionHelper. */ public class ExceptionHelper { - + /** * Extract stack trace elements. * diff --git a/src/test/java/org/onap/aai/sparky/util/HttpServletHelper.java b/src/test/java/org/onap/aai/sparky/util/HttpServletHelper.java index de90f85..d06a1c1 100644 --- a/src/test/java/org/onap/aai/sparky/util/HttpServletHelper.java +++ b/src/test/java/org/onap/aai/sparky/util/HttpServletHelper.java @@ -64,8 +64,8 @@ public class HttpServletHelper { try { Mockito.when(request.getContentType()).thenReturn(mimeType); - - + + final ByteArrayInputStream bais = new ByteArrayInputStream(payloadContent.getBytes(StandardCharsets.UTF_8)); @@ -94,8 +94,9 @@ public class HttpServletHelper { }; Mockito.when(request.getInputStream()).thenReturn(servletInputStream); - Mockito.when(request.getReader()).thenReturn(new BufferedReader(new StringReader(payloadContent))); - + Mockito.when(request.getReader()) + .thenReturn(new BufferedReader(new StringReader(payloadContent))); + } catch (IOException ioe) { fail(ExceptionHelper.extractStackTraceElements(5, ioe)); } @@ -150,11 +151,12 @@ public class HttpServletHelper { for (String key : paramNameValueMap.keySet()) { Mockito.when(req.getParameter(key)).thenReturn(paramNameValueMap.get(key)); } - + } } - - public static void assignRequestHeader(HttpServletRequest req, String headerName, String headerValue) { + + public static void assignRequestHeader(HttpServletRequest req, String headerName, + String headerValue) { Mockito.when(req.getHeader(headerName)).thenReturn(headerValue); } diff --git a/src/test/java/org/onap/aai/sparky/util/KeystoreBuilderTest.java b/src/test/java/org/onap/aai/sparky/util/KeystoreBuilderTest.java index aadaff9..b719381 100644 --- a/src/test/java/org/onap/aai/sparky/util/KeystoreBuilderTest.java +++ b/src/test/java/org/onap/aai/sparky/util/KeystoreBuilderTest.java @@ -49,52 +49,57 @@ import org.mockito.Mockito; public class KeystoreBuilderTest { - @Rule - public TemporaryFolder folder = new TemporaryFolder(); + @Rule + public TemporaryFolder folder = new TemporaryFolder(); - KeystoreBuilder ksb; - org.onap.aai.sparky.util.test.KeystoreBuilder ksb1; + KeystoreBuilder ksb; + org.onap.aai.sparky.util.test.KeystoreBuilder ksb1; - @Before - public void setUp() throws IOException, NoSuchAlgorithmException { - System.setProperty("AJSC_HOME", new File(".").getCanonicalPath().replace('\\', '/')); + @Before + public void setUp() throws IOException, NoSuchAlgorithmException { + System.setProperty("AJSC_HOME", new File(".").getCanonicalPath().replace('\\', '/')); - folder.newFile("file1.xml"); - folder.newFile("file2.xml"); + folder.newFile("file1.xml"); + folder.newFile("file2.xml"); - String endPointList = "https://localhost:9517;https://localhost:8443"; - ksb = new KeystoreBuilder(endPointList); - ksb1 = new org.onap.aai.sparky.util.test.KeystoreBuilder(endPointList); - } + String endPointList = "https://localhost:9517;https://localhost:8443"; + ksb = new KeystoreBuilder(endPointList); + ksb1 = new org.onap.aai.sparky.util.test.KeystoreBuilder(endPointList); + } - @Test(expected=IOException.class) - public void testUpdateKeyStore() throws KeyManagementException, KeyStoreException, CertificateException, IOException, NoSuchAlgorithmException { - ksb.updateKeystore(folder.getRoot().getAbsolutePath(), "password-1"); - ksb1.updateKeystore(folder.getRoot().getAbsolutePath(), "password-1"); - } + @Test(expected = IOException.class) + public void testUpdateKeyStore() throws KeyManagementException, KeyStoreException, + CertificateException, IOException, NoSuchAlgorithmException { + ksb.updateKeystore(folder.getRoot().getAbsolutePath(), "password-1"); + ksb1.updateKeystore(folder.getRoot().getAbsolutePath(), "password-1"); + } - @Test(expected=InvocationTargetException.class) - public void testCertificateChainMethods() throws NoSuchMethodException, SecurityException, - IllegalAccessException, IllegalArgumentException, InvocationTargetException, UnknownHostException, IOException { - SSLSocketFactory factory = Mockito.mock(SSLSocketFactory.class); - SSLSocket socket = Mockito.mock(SSLSocket.class); - Mockito.when(factory.createSocket("localhost",9517)).thenReturn(socket); - Method method = KeystoreBuilder.class.getDeclaredMethod("getCertificateChainForRemoteEndpoint", String.class, int.class); - method.setAccessible(true); - X509Certificate[] certChain = (X509Certificate[])method.invoke(ksb, "localhost",9517); - Assert.assertNotNull(certChain); - } + @Test(expected = InvocationTargetException.class) + public void testCertificateChainMethods() + throws NoSuchMethodException, SecurityException, IllegalAccessException, + IllegalArgumentException, InvocationTargetException, UnknownHostException, IOException { + SSLSocketFactory factory = Mockito.mock(SSLSocketFactory.class); + SSLSocket socket = Mockito.mock(SSLSocket.class); + Mockito.when(factory.createSocket("localhost", 9517)).thenReturn(socket); + Method method = KeystoreBuilder.class.getDeclaredMethod("getCertificateChainForRemoteEndpoint", + String.class, int.class); + method.setAccessible(true); + X509Certificate[] certChain = (X509Certificate[]) method.invoke(ksb, "localhost", 9517); + Assert.assertNotNull(certChain); + } - @Test(expected=InvocationTargetException.class) - public void testCertificateChainMethods1() throws NoSuchMethodException, SecurityException, - IllegalAccessException, IllegalArgumentException, InvocationTargetException, UnknownHostException, IOException { - SSLSocketFactory factory = Mockito.mock(SSLSocketFactory.class); - SSLSocket socket = Mockito.mock(SSLSocket.class); - Mockito.when(factory.createSocket("localhost",9517)).thenReturn(socket); - Method method = org.onap.aai.sparky.util.test.KeystoreBuilder.class.getDeclaredMethod("getCertificateChainForRemoteEndpoint", String.class, int.class); - method.setAccessible(true); - X509Certificate[] certChain = (X509Certificate[])method.invoke(ksb1, "localhost",9517); - Assert.assertNotNull(certChain); - } + @Test(expected = InvocationTargetException.class) + public void testCertificateChainMethods1() + throws NoSuchMethodException, SecurityException, IllegalAccessException, + IllegalArgumentException, InvocationTargetException, UnknownHostException, IOException { + SSLSocketFactory factory = Mockito.mock(SSLSocketFactory.class); + SSLSocket socket = Mockito.mock(SSLSocket.class); + Mockito.when(factory.createSocket("localhost", 9517)).thenReturn(socket); + Method method = org.onap.aai.sparky.util.test.KeystoreBuilder.class + .getDeclaredMethod("getCertificateChainForRemoteEndpoint", String.class, int.class); + method.setAccessible(true); + X509Certificate[] certChain = (X509Certificate[]) method.invoke(ksb1, "localhost", 9517); + Assert.assertNotNull(certChain); + } } diff --git a/src/test/java/org/onap/aai/sparky/util/NodeUtilsTest.java b/src/test/java/org/onap/aai/sparky/util/NodeUtilsTest.java index 9329d9a..b2c19df 100644 --- a/src/test/java/org/onap/aai/sparky/util/NodeUtilsTest.java +++ b/src/test/java/org/onap/aai/sparky/util/NodeUtilsTest.java @@ -448,7 +448,7 @@ public class NodeUtilsTest { String result = NodeUtils.concatArray(numberList); assertEquals("1 2 3", result); } - + /** * Test format timestamp expect valid result. */ @@ -470,37 +470,46 @@ public class NodeUtilsTest { assertEquals(validTimeStamp, result); } - + /** * Test isNumeric expect true */ @Test - public void test_isNumeric_expectFalse(){ - String invalidNumber="number"; - assertFalse(NodeUtils.isNumeric(invalidNumber)); + public void test_isNumeric_expectFalse() { + String invalidNumber = "number"; + assertFalse(NodeUtils.isNumeric(invalidNumber)); } - + /** * Test isNumeric expect true */ @Test - public void test_isNumeric_expectTrue(){ - String validNumber="123"; - assertTrue(NodeUtils.isNumeric(validNumber)); + public void test_isNumeric_expectTrue() { + String validNumber = "123"; + assertTrue(NodeUtils.isNumeric(validNumber)); } + /** * test calculate edit attributes urls */ @Test public void validateCalculateEditAttributeLogic() { - - assertEquals(NodeUtils.calculateEditAttributeUri("https://localhost:9000/aai/v7/pservers/pserver/12345"),"pservers/pserver/12345"); - assertEquals(NodeUtils.calculateEditAttributeUri("https://localhost:9000/aai/v1/pservers/pserver/12345"),"pservers/pserver/12345"); - assertEquals(NodeUtils.calculateEditAttributeUri("https://localhost:9000/aai/v21/pservers/pserver/12345"),"pservers/pserver/12345"); - assertEquals(NodeUtils.calculateEditAttributeUri("https://localhost:9000/aai/v211/pservers/pserver/12345"),"pservers/pserver/12345"); - assertEquals(NodeUtils.calculateEditAttributeUri("https://localhost:9000/aai/v5252/pservers/pserver/12345"),"pservers/pserver/12345"); + + assertEquals( + NodeUtils.calculateEditAttributeUri("https://localhost:9000/aai/v7/pservers/pserver/12345"), + "pservers/pserver/12345"); + assertEquals( + NodeUtils.calculateEditAttributeUri("https://localhost:9000/aai/v1/pservers/pserver/12345"), + "pservers/pserver/12345"); + assertEquals(NodeUtils.calculateEditAttributeUri( + "https://localhost:9000/aai/v21/pservers/pserver/12345"), "pservers/pserver/12345"); + assertEquals(NodeUtils.calculateEditAttributeUri( + "https://localhost:9000/aai/v211/pservers/pserver/12345"), "pservers/pserver/12345"); + assertEquals(NodeUtils.calculateEditAttributeUri( + "https://localhost:9000/aai/v5252/pservers/pserver/12345"), "pservers/pserver/12345"); assertNull(NodeUtils.calculateEditAttributeUri(null)); - assertNull(NodeUtils.calculateEditAttributeUri("https://localhost:9000/aai/noVersionTag/pservers/pserver/12345")); + assertNull(NodeUtils.calculateEditAttributeUri( + "https://localhost:9000/aai/noVersionTag/pservers/pserver/12345")); } diff --git a/src/test/java/org/onap/aai/sparky/util/SuggestionsPermutationsTest.java b/src/test/java/org/onap/aai/sparky/util/SuggestionsPermutationsTest.java index 2d277bd..53905d4 100644 --- a/src/test/java/org/onap/aai/sparky/util/SuggestionsPermutationsTest.java +++ b/src/test/java/org/onap/aai/sparky/util/SuggestionsPermutationsTest.java @@ -14,13 +14,13 @@ public class SuggestionsPermutationsTest { @Test public void isValidSuggestionPermutation_successPath() { - + List x = new ArrayList<>(Arrays.asList("A", "B", "C", "D")); SuggestionsPermutation suggPermutation = new SuggestionsPermutation(); - + ArrayList> uniqueLists = suggPermutation.getSuggestionsPermutation(x); - - assertTrue(uniqueLists.get(0).toString().equals("[A]")); + + assertTrue(uniqueLists.get(0).toString().equals("[A]")); assertTrue(uniqueLists.get(1).toString().equals("[A, B, C, D]")); assertTrue(uniqueLists.get(2).toString().equals("[A, C, D]")); assertTrue(uniqueLists.get(3).toString().equals("[A, D]")); @@ -31,6 +31,6 @@ public class SuggestionsPermutationsTest { assertTrue(uniqueLists.get(8).toString().equals("[C, D]")); assertTrue(uniqueLists.get(9).toString().equals("[D]")); assertTrue(uniqueLists.size() == 10); - + } } diff --git a/src/test/java/org/onap/aai/sparky/util/TreeWalkerTest.java b/src/test/java/org/onap/aai/sparky/util/TreeWalkerTest.java index 36b11ed..198a0eb 100644 --- a/src/test/java/org/onap/aai/sparky/util/TreeWalkerTest.java +++ b/src/test/java/org/onap/aai/sparky/util/TreeWalkerTest.java @@ -57,8 +57,7 @@ public class TreeWalkerTest { * @throws Exception the exception */ @Before - public void init() throws Exception { - } + public void init() throws Exception {} /** * Validate json node conversion null input. @@ -184,8 +183,7 @@ public class TreeWalkerTest { public void validateWalkTreeOneParentNodeWithObjectArray() { try { - String jsonStr = - "{\"Employee\":[{\"id\":\"101\",\"name\":\"Pushkar\",\"salary\":\"5000\"}," + String jsonStr = "{\"Employee\":[{\"id\":\"101\",\"name\":\"Pushkar\",\"salary\":\"5000\"}," + "{\"id\":\"102\",\"name\":\"Rahul\",\"salary\":\"4000\"}," + "{\"id\":\"103\",\"name\":\"tanveer\",\"salary\":\"56678\"}]}"; TreeWalker walker = new TreeWalker(); @@ -230,68 +228,68 @@ public class TreeWalkerTest { try { String jsonStr = "{ \"generalNodeClass\": { \"class\": \"aai-entity-node general-node\"," - + " \"visualElements\": [ { \"type\": \"circle\"," - + " \"class\": \"outer\", \"svgAttributes\": {" - + " \"r\": \"20\" } }, {" - + " \"type\": \"circle\", \"class\": \"inner\", " - + " \"svgAttributes\": { \"r\": \"10\" " - + "} }, { \"type\": \"text\", " - + "\"class\": \"id-type-label\", \"displayKey\": \"itemType\", " - + " \"shapeAttributes\": { \"offset\": { " - + " \"x\": \"0\", \"y\": \"30\" } " - + " } }, { \"type\": \"text\", " - + " \"class\": \"id-value-label\", \"displayKey\":" - + " \"itemNameValue\", \"shapeAttributes\": { " - + " \"offset\": { \"x\": \"0\", " - + " \"y\": \"40\" } } } ] " - + " }, \"searchedNodeClass\": { \"class\": \"aai-entity-node search-node\"," - + " \"visualElements\": [ { \"type\": \"circle\"," - + " \"class\": \"outer\", \"svgAttributes\": { " - + " \"r\": \"20\" } }, { " - + " \"type\": \"circle\", \"class\": \"inner\", " - + " \"svgAttributes\": { \"r\": \"10\" }" - + " }, { \"type\": \"text\", " - + "\"class\": \"id-type-label\", \"displayKey\": \"itemType\", " - + " \"shapeAttributes\": { \"offset\": { " - + " \"x\": \"0\", \"y\": \"30\" }" - + " } }, { \"type\": \"text\", " - + " \"class\": \"id-value-label\", " - + "\"displayKey\": \"itemNameValue\", \"shapeAttributes\": {" - + " \"offset\": { \"x\": \"0\"," - + " \"y\": \"40\" } }" - + " } ] }, \"selectedSearchedNodeClass\": { " - + "\"class\": \"aai-entity-node selected-search-node\", \"visualElements\": [" - + " { \"type\": \"circle\", " - + "\"class\": \"outer\", \"svgAttributes\": {" - + " \"r\": \"20\" } }, {" - + " \"type\": \"circle\", \"class\": \"inner\"," - + " \"svgAttributes\": { \"r\": \"10\" " - + " } }, { \"type\": \"text\", " - + " \"class\": \"id-type-label\", \"displayKey\": \"itemType\"," - + " \"shapeAttributes\": { \"offset\": {" - + " \"x\": \"0\", \"y\": \"30\"" - + " } } }, { " - + " \"type\": \"text\", \"class\": \"id-value-label\", " - + " \"displayKey\": \"itemNameValue\", \"shapeAttributes\": {" - + " \"offset\": { \"x\": \"0\", " - + " \"y\": \"40\" } } } ]" - + " }, \"selectedNodeClass\": { \"class\":" - + " \"aai-entity-node selected-node\"," - + " \"visualElements\": [ { \"type\": \"circle\"," - + " \"class\": \"outer\", \"svgAttributes\": {" - + " \"r\": \"20\" } }, {" - + " \"type\": \"circle\", \"class\": \"inner\"," - + " \"svgAttributes\": { \"r\": \"10\" " - + " } }, { \"type\": \"text\", " - + " \"class\": \"id-type-label\", \"displayKey\": \"itemType\"," - + " \"shapeAttributes\": { \"offset\": " - + "{ " - + " \"x\": \"0\", \"y\": \"30\" } " - + " } }, { \"type\": \"text\"," - + " \"class\": \"id-value-label\", \"displayKey\":" - + " \"itemNameValue\", \"shapeAttributes\": { " - + "\"offset\": { \"x\": \"0\", " - + "\"y\": \"40\" } } } ] }}"; + + " \"visualElements\": [ { \"type\": \"circle\"," + + " \"class\": \"outer\", \"svgAttributes\": {" + + " \"r\": \"20\" } }, {" + + " \"type\": \"circle\", \"class\": \"inner\", " + + " \"svgAttributes\": { \"r\": \"10\" " + + "} }, { \"type\": \"text\", " + + "\"class\": \"id-type-label\", \"displayKey\": \"itemType\", " + + " \"shapeAttributes\": { \"offset\": { " + + " \"x\": \"0\", \"y\": \"30\" } " + + " } }, { \"type\": \"text\", " + + " \"class\": \"id-value-label\", \"displayKey\":" + + " \"itemNameValue\", \"shapeAttributes\": { " + + " \"offset\": { \"x\": \"0\", " + + " \"y\": \"40\" } } } ] " + + " }, \"searchedNodeClass\": { \"class\": \"aai-entity-node search-node\"," + + " \"visualElements\": [ { \"type\": \"circle\"," + + " \"class\": \"outer\", \"svgAttributes\": { " + + " \"r\": \"20\" } }, { " + + " \"type\": \"circle\", \"class\": \"inner\", " + + " \"svgAttributes\": { \"r\": \"10\" }" + + " }, { \"type\": \"text\", " + + "\"class\": \"id-type-label\", \"displayKey\": \"itemType\", " + + " \"shapeAttributes\": { \"offset\": { " + + " \"x\": \"0\", \"y\": \"30\" }" + + " } }, { \"type\": \"text\", " + + " \"class\": \"id-value-label\", " + + "\"displayKey\": \"itemNameValue\", \"shapeAttributes\": {" + + " \"offset\": { \"x\": \"0\"," + + " \"y\": \"40\" } }" + + " } ] }, \"selectedSearchedNodeClass\": { " + + "\"class\": \"aai-entity-node selected-search-node\", \"visualElements\": [" + + " { \"type\": \"circle\", " + + "\"class\": \"outer\", \"svgAttributes\": {" + + " \"r\": \"20\" } }, {" + + " \"type\": \"circle\", \"class\": \"inner\"," + + " \"svgAttributes\": { \"r\": \"10\" " + + " } }, { \"type\": \"text\", " + + " \"class\": \"id-type-label\", \"displayKey\": \"itemType\"," + + " \"shapeAttributes\": { \"offset\": {" + + " \"x\": \"0\", \"y\": \"30\"" + + " } } }, { " + + " \"type\": \"text\", \"class\": \"id-value-label\", " + + " \"displayKey\": \"itemNameValue\", \"shapeAttributes\": {" + + " \"offset\": { \"x\": \"0\", " + + " \"y\": \"40\" } } } ]" + + " }, \"selectedNodeClass\": { \"class\":" + + " \"aai-entity-node selected-node\"," + + " \"visualElements\": [ { \"type\": \"circle\"," + + " \"class\": \"outer\", \"svgAttributes\": {" + + " \"r\": \"20\" } }, {" + + " \"type\": \"circle\", \"class\": \"inner\"," + + " \"svgAttributes\": { \"r\": \"10\" " + + " } }, { \"type\": \"text\", " + + " \"class\": \"id-type-label\", \"displayKey\": \"itemType\"," + + " \"shapeAttributes\": { \"offset\": " + + "{ " + + " \"x\": \"0\", \"y\": \"30\" } " + + " } }, { \"type\": \"text\"," + + " \"class\": \"id-value-label\", \"displayKey\":" + + " \"itemNameValue\", \"shapeAttributes\": { " + + "\"offset\": { \"x\": \"0\", " + + "\"y\": \"40\" } } } ] }}"; TreeWalker walker = new TreeWalker(); List paths = new ArrayList(); walker.walkTree(paths, walker.convertJsonToNode(jsonStr)); @@ -400,143 +398,143 @@ public class TreeWalkerTest { try { String n1Str = "{ \"generalNodeClass\": { \"class\": \"aai-entity-node general-node\"," - + " \"visualElements\": [ { \"type\": \"circle\"," - + " \"class\": \"outer\", \"svgAttributes\": {" - + " \"r\": \"20\" } }, {" - + " \"type\": \"circle\", \"class\": \"inner\"," - + " \"svgAttributes\": { \"r\": \"10\"" - + " } }, { \"type\": \"text\"," - + " \"class\": \"id-type-label\", \"displayKey\":" - + " \"itemType\", \"shapeAttributes\": { \"offset\":" - + " { \"x\": \"0\", \"y\": \"30\"" - + " } } }, {" - + " \"type\": \"text\", \"class\": \"id-value-label\"," - + " \"displayKey\": \"itemNameValue\"," - + " \"shapeAttributes\": { \"offset\":" - + " { \"x\": \"0\", \"y\": \"40\"" - + " } } } ] }," - + " \"searchedNodeClass\": { \"class\": \"aai-entity-node search-node\"," - + " \"visualElements\": [ { \"type\": \"circle\"," - + " \"class\": \"outer\", \"svgAttributes\": {" - + " \"r\": \"20\" } }, {" - + " \"type\": \"circle\", \"class\": \"inner\"," - + " \"svgAttributes\": { \"r\": \"10\"" - + " } }, { \"type\": \"text\"," - + " \"class\": \"id-type-label\", \"displayKey\":" - + " \"itemType\", \"shapeAttributes\": { \"offset\": {" - + " \"x\": \"0\", \"y\": \"30\"" - + " } } }, {" - + " \"type\": \"text\", \"class\": \"id-value-label\"," - + " \"displayKey\": \"itemNameValue\"," - + " \"shapeAttributes\": { \"offset\": {" - + " \"x\": \"0\", \"y\": \"40\"" - + " } } } ] }," - + " \"selectedSearchedNodeClass\": { \"class\":" - + " \"aai-entity-node selected-search-node\", \"visualElements\": [" - + " { \"type\": \"circle\", \"class\":" - + " \"outer\", \"svgAttributes\": { \"r\": \"20\"" - + " } }, { \"type\": \"circle\"," - + " \"class\": \"inner\", \"svgAttributes\": {" - + " \"r\": \"10\" } }, {" - + " \"type\": \"text\", \"class\": \"id-type-label\"," - + " \"displayKey\": \"itemType\", \"shapeAttributes\": {" - + " \"offset\": { \"x\": \"0\"," - + " \"y\": \"30\" } }" - + " }, { \"type\": \"text\"," - + " \"class\": \"id-value-label\"," - + " \"displayKey\": \"itemNameValue\"," - + " \"shapeAttributes\": { \"offset\": {" - + " \"x\": \"0\", \"y\": \"40\"" - + " } } } ] }," - + " \"selectedNodeClass\": { \"class\": \"aai-entity-node selected-node\"," - + " \"visualElements\": [ { \"type\": \"circle\"," - + " \"class\": \"outer\", \"svgAttributes\": {" - + " \"r\": \"20\" } }, {" - + " \"type\": \"circle\", \"class\": \"inner\"," - + " \"svgAttributes\": { \"r\": \"10\"" - + " } }, { \"type\": \"text\"," - + " \"class\": \"id-type-label\", \"displayKey\":" - + " \"itemType\", \"shapeAttributes\": {" - + " \"offset\": { \"x\": \"0\"," - + " \"y\": \"30\" }" - + " } }, { \"type\": \"text\"," - + " \"class\": \"id-value-label\", \"displayKey\":" - + " \"itemNameValue\", \"shapeAttributes\": {" - + " \"offset\": { \"x\": \"0\"," - + " \"y\": \"40\" } }" - + " } ] }}"; + + " \"visualElements\": [ { \"type\": \"circle\"," + + " \"class\": \"outer\", \"svgAttributes\": {" + + " \"r\": \"20\" } }, {" + + " \"type\": \"circle\", \"class\": \"inner\"," + + " \"svgAttributes\": { \"r\": \"10\"" + + " } }, { \"type\": \"text\"," + + " \"class\": \"id-type-label\", \"displayKey\":" + + " \"itemType\", \"shapeAttributes\": { \"offset\":" + + " { \"x\": \"0\", \"y\": \"30\"" + + " } } }, {" + + " \"type\": \"text\", \"class\": \"id-value-label\"," + + " \"displayKey\": \"itemNameValue\"," + + " \"shapeAttributes\": { \"offset\":" + + " { \"x\": \"0\", \"y\": \"40\"" + + " } } } ] }," + + " \"searchedNodeClass\": { \"class\": \"aai-entity-node search-node\"," + + " \"visualElements\": [ { \"type\": \"circle\"," + + " \"class\": \"outer\", \"svgAttributes\": {" + + " \"r\": \"20\" } }, {" + + " \"type\": \"circle\", \"class\": \"inner\"," + + " \"svgAttributes\": { \"r\": \"10\"" + + " } }, { \"type\": \"text\"," + + " \"class\": \"id-type-label\", \"displayKey\":" + + " \"itemType\", \"shapeAttributes\": { \"offset\": {" + + " \"x\": \"0\", \"y\": \"30\"" + + " } } }, {" + + " \"type\": \"text\", \"class\": \"id-value-label\"," + + " \"displayKey\": \"itemNameValue\"," + + " \"shapeAttributes\": { \"offset\": {" + + " \"x\": \"0\", \"y\": \"40\"" + + " } } } ] }," + + " \"selectedSearchedNodeClass\": { \"class\":" + + " \"aai-entity-node selected-search-node\", \"visualElements\": [" + + " { \"type\": \"circle\", \"class\":" + + " \"outer\", \"svgAttributes\": { \"r\": \"20\"" + + " } }, { \"type\": \"circle\"," + + " \"class\": \"inner\", \"svgAttributes\": {" + + " \"r\": \"10\" } }, {" + + " \"type\": \"text\", \"class\": \"id-type-label\"," + + " \"displayKey\": \"itemType\", \"shapeAttributes\": {" + + " \"offset\": { \"x\": \"0\"," + + " \"y\": \"30\" } }" + + " }, { \"type\": \"text\"," + + " \"class\": \"id-value-label\"," + + " \"displayKey\": \"itemNameValue\"," + + " \"shapeAttributes\": { \"offset\": {" + + " \"x\": \"0\", \"y\": \"40\"" + + " } } } ] }," + + " \"selectedNodeClass\": { \"class\": \"aai-entity-node selected-node\"," + + " \"visualElements\": [ { \"type\": \"circle\"," + + " \"class\": \"outer\", \"svgAttributes\": {" + + " \"r\": \"20\" } }, {" + + " \"type\": \"circle\", \"class\": \"inner\"," + + " \"svgAttributes\": { \"r\": \"10\"" + + " } }, { \"type\": \"text\"," + + " \"class\": \"id-type-label\", \"displayKey\":" + + " \"itemType\", \"shapeAttributes\": {" + + " \"offset\": { \"x\": \"0\"," + + " \"y\": \"30\" }" + + " } }, { \"type\": \"text\"," + + " \"class\": \"id-value-label\", \"displayKey\":" + + " \"itemNameValue\", \"shapeAttributes\": {" + + " \"offset\": { \"x\": \"0\"," + + " \"y\": \"40\" } }" + + " } ] }}"; String n2Str = "{ \"searchedNodeClass\": { \"class\": \"aai-entity-node search-node\"," - + " \"visualElements\": [ { \"type\": \"circle\"," - + " \"class\": \"outer\", \"svgAttributes\": {" - + " \"r\": \"20\" } }," - + " { \"type\": \"circle\"," - + " \"class\": \"inner\", \"svgAttributes\": {" - + " \"r\": \"10\" } }, {" - + " \"type\": \"text\", \"class\": \"id-type-label\"," - + " \"displayKey\": \"itemType\", \"shapeAttributes\": {" - + " \"offset\": { \"y\": \"30\"," - + " \"x\": \"0\" } }" - + " }, { \"type\": \"text\"," - + " \"class\": \"id-value-label\"," - + " \"displayKey\": \"itemNameValue\"," - + " \"shapeAttributes\": { \"offset\": {" - + " \"y\": \"40\", \"x\": \"0\"" - + " } } } ] }," - + " \"selectedSearchedNodeClass\": { \"class\":" - + " \"aai-entity-node selected-search-node\", \"visualElements\": [" - + " { \"type\": \"circle\", \"class\":" - + " \"outer\", \"svgAttributes\": { \"r\": \"20\"" - + " } }, { \"type\": \"circle\"," - + " \"class\": \"inner\", \"svgAttributes\": {" - + " \"r\": \"10\" } }, {" - + " \"type\": \"text\", \"class\": \"id-type-label\"," - + " \"displayKey\": \"itemType\", \"shapeAttributes\": {" - + " \"offset\": { \"y\": \"30\"," - + " \"x\": \"0\" } }" - + " }, { \"type\": \"text\"," - + " \"class\": \"id-value-label\"," - + " \"displayKey\": \"itemNameValue\"," - + " \"shapeAttributes\": { \"offset\": {" - + " \"y\": \"40\", \"x\": \"0\"" - + " } } } ] }," - + " \"selectedNodeClass\": { \"class\": \"aai-entity-node selected-node\"," - + " \"visualElements\": [ { \"type\": \"circle\"," - + " \"class\": \"outer\", \"svgAttributes\": {" - + " \"r\": \"20\" } }, {" - + " \"type\": \"circle\", \"class\": \"inner\"," - + " \"svgAttributes\": { \"r\": \"10\"" - + " } }, { \"type\": \"text\"," - + " \"class\": \"id-type-label\"," - + " \"displayKey\": \"itemType\", \"shapeAttributes\": {" - + " \"offset\": { \"y\": \"30\"," - + " \"x\": \"0\" } }" - + " }, { \"type\": \"text\"," - + " \"class\": \"id-value-label\"," - + " \"displayKey\": \"itemNameValue\"," - + " \"shapeAttributes\": { \"offset\": {" - + " \"y\": \"40\", \"x\": \"0\"" - + " } } } ] }," - + " \"generalNodeClass\": { \"class\":" - + " \"aai-entity-node general-node\", \"visualElements\": [" - + " { \"type\": \"circle\"," - + " \"class\": \"outer\", \"svgAttributes\": {" - + " \"r\": \"20\" } }," - + " { \"type\": \"circle\"," - + " \"class\": \"inner\", \"svgAttributes\": {" - + " \"r\": \"10\" } }," - + " { \"type\": \"text\"," - + " \"class\": \"id-type-label\", \"displayKey\":" - + " \"itemType\", \"shapeAttributes\": {" - + " \"offset\": { \"y\": \"30\"," - + " \"x\": \"0\" }" - + " } }, {" - + " \"type\": \"text\"," - + " \"class\": \"id-value-label\", \"displayKey\":" - + " \"itemNameValue\", \"shapeAttributes\": {" - + " \"offset\": { \"y\": \"40\"," - + " \"x\": \"0\" }" - + " } } ] }}"; + + " \"visualElements\": [ { \"type\": \"circle\"," + + " \"class\": \"outer\", \"svgAttributes\": {" + + " \"r\": \"20\" } }," + + " { \"type\": \"circle\"," + + " \"class\": \"inner\", \"svgAttributes\": {" + + " \"r\": \"10\" } }, {" + + " \"type\": \"text\", \"class\": \"id-type-label\"," + + " \"displayKey\": \"itemType\", \"shapeAttributes\": {" + + " \"offset\": { \"y\": \"30\"," + + " \"x\": \"0\" } }" + + " }, { \"type\": \"text\"," + + " \"class\": \"id-value-label\"," + + " \"displayKey\": \"itemNameValue\"," + + " \"shapeAttributes\": { \"offset\": {" + + " \"y\": \"40\", \"x\": \"0\"" + + " } } } ] }," + + " \"selectedSearchedNodeClass\": { \"class\":" + + " \"aai-entity-node selected-search-node\", \"visualElements\": [" + + " { \"type\": \"circle\", \"class\":" + + " \"outer\", \"svgAttributes\": { \"r\": \"20\"" + + " } }, { \"type\": \"circle\"," + + " \"class\": \"inner\", \"svgAttributes\": {" + + " \"r\": \"10\" } }, {" + + " \"type\": \"text\", \"class\": \"id-type-label\"," + + " \"displayKey\": \"itemType\", \"shapeAttributes\": {" + + " \"offset\": { \"y\": \"30\"," + + " \"x\": \"0\" } }" + + " }, { \"type\": \"text\"," + + " \"class\": \"id-value-label\"," + + " \"displayKey\": \"itemNameValue\"," + + " \"shapeAttributes\": { \"offset\": {" + + " \"y\": \"40\", \"x\": \"0\"" + + " } } } ] }," + + " \"selectedNodeClass\": { \"class\": \"aai-entity-node selected-node\"," + + " \"visualElements\": [ { \"type\": \"circle\"," + + " \"class\": \"outer\", \"svgAttributes\": {" + + " \"r\": \"20\" } }, {" + + " \"type\": \"circle\", \"class\": \"inner\"," + + " \"svgAttributes\": { \"r\": \"10\"" + + " } }, { \"type\": \"text\"," + + " \"class\": \"id-type-label\"," + + " \"displayKey\": \"itemType\", \"shapeAttributes\": {" + + " \"offset\": { \"y\": \"30\"," + + " \"x\": \"0\" } }" + + " }, { \"type\": \"text\"," + + " \"class\": \"id-value-label\"," + + " \"displayKey\": \"itemNameValue\"," + + " \"shapeAttributes\": { \"offset\": {" + + " \"y\": \"40\", \"x\": \"0\"" + + " } } } ] }," + + " \"generalNodeClass\": { \"class\":" + + " \"aai-entity-node general-node\", \"visualElements\": [" + + " { \"type\": \"circle\"," + + " \"class\": \"outer\", \"svgAttributes\": {" + + " \"r\": \"20\" } }," + + " { \"type\": \"circle\"," + + " \"class\": \"inner\", \"svgAttributes\": {" + + " \"r\": \"10\" } }," + + " { \"type\": \"text\"," + + " \"class\": \"id-type-label\", \"displayKey\":" + + " \"itemType\", \"shapeAttributes\": {" + + " \"offset\": { \"y\": \"30\"," + + " \"x\": \"0\" }" + + " } }, {" + + " \"type\": \"text\"," + + " \"class\": \"id-value-label\", \"displayKey\":" + + " \"itemNameValue\", \"shapeAttributes\": {" + + " \"offset\": { \"y\": \"40\"," + + " \"x\": \"0\" }" + + " } } ] }}"; TreeWalker walker = new TreeWalker(); List n1Paths = new ArrayList(); diff --git a/src/test/java/org/onap/aai/sparky/viewandinspect/ActiveInventoryNodeTester.java b/src/test/java/org/onap/aai/sparky/viewandinspect/ActiveInventoryNodeTester.java index 9dd23b5..df6bc2c 100644 --- a/src/test/java/org/onap/aai/sparky/viewandinspect/ActiveInventoryNodeTester.java +++ b/src/test/java/org/onap/aai/sparky/viewandinspect/ActiveInventoryNodeTester.java @@ -87,8 +87,7 @@ public class ActiveInventoryNodeTester { return nodeA; } - private String selfLinkFormat = - "https://aai-hostname:9292/aai/v7/network/generic-vnfs/%s/%s"; + private String selfLinkFormat = "https://aai-hostname:9292/aai/v7/network/generic-vnfs/%s/%s"; /** diff --git a/src/test/java/org/onap/aai/sparky/viewandinspect/SearchAdapterTest.java b/src/test/java/org/onap/aai/sparky/viewandinspect/SearchAdapterTest.java index bbee87c..1baf2e4 100644 --- a/src/test/java/org/onap/aai/sparky/viewandinspect/SearchAdapterTest.java +++ b/src/test/java/org/onap/aai/sparky/viewandinspect/SearchAdapterTest.java @@ -56,7 +56,7 @@ public class SearchAdapterTest { private WebResource mockWebResource; private Builder mockBuilder; - + /** * Inits the. diff --git a/src/test/java/org/onap/aai/sparky/viewandinspect/SearchResponseTest.java b/src/test/java/org/onap/aai/sparky/viewandinspect/SearchResponseTest.java index cae9290..3b2158b 100644 --- a/src/test/java/org/onap/aai/sparky/viewandinspect/SearchResponseTest.java +++ b/src/test/java/org/onap/aai/sparky/viewandinspect/SearchResponseTest.java @@ -57,19 +57,19 @@ public class SearchResponseTest { SearchResponse response = new SearchResponse(); - //response.setNumReturned(1); + // response.setNumReturned(1); response.setProcessingTimeInMs(512); - //response.setTotalFound(50); + // response.setTotalFound(50); List entities = new ArrayList(); - //response.setEntities(entities); + // response.setEntities(entities); EntityEntry e1 = new EntityEntry(); e1.setEntityPrimaryKeyValue("e1"); e1.setEntityType("e1"); e1.setSearchTags("e1"); - //response.addEntityEntry(e1); + // response.addEntityEntry(e1); EntityEntry e2 = new EntityEntry(); @@ -77,15 +77,15 @@ public class SearchResponseTest { e2.setEntityType("e2"); e2.setSearchTags("e2"); - //response.addEntityEntry(e2); + // response.addEntityEntry(e2); - //assertEquals(1, response.getNumReturned()); - //assertEquals(512, response.getProcessingTimeInMs()); - //assertEquals(50, response.getTotalFound()); + // assertEquals(1, response.getNumReturned()); + // assertEquals(512, response.getProcessingTimeInMs()); + // assertEquals(50, response.getTotalFound()); - //List responseEntities = response.getEntities(); + // List responseEntities = response.getEntities(); - //assertEquals(2, responseEntities.size()); + // assertEquals(2, responseEntities.size()); } diff --git a/src/test/java/org/onap/aai/sparky/viewandinspect/SearchServletTest.java b/src/test/java/org/onap/aai/sparky/viewandinspect/SearchServletTest.java index 198bbb3..6d682f4 100644 --- a/src/test/java/org/onap/aai/sparky/viewandinspect/SearchServletTest.java +++ b/src/test/java/org/onap/aai/sparky/viewandinspect/SearchServletTest.java @@ -97,7 +97,7 @@ public class SearchServletTest { private static final String VNF_ROUTE = "vnf"; private static final String VIEW_INSPECT_ROUTE = "viewInspect"; - + private HttpServletRequest commonRequest = null; private HttpServletResponse commonResponse = null; private PrintWriter printWriter = null; @@ -111,7 +111,7 @@ public class SearchServletTest { private Map descriptors = null; private SuggestionConfig suggestionConfig = null; private SearchServiceConfig esConfig = null; - + /** * Inits the. * @@ -128,21 +128,21 @@ public class SearchServletTest { // permit serialization of objects with no members mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false); - + rand = new SecureRandom(); - loader = Mockito.mock(OxmModelLoader.class); + loader = Mockito.mock(OxmModelLoader.class); descriptors = new HashMap(); esConfig = new SearchServiceConfig(); suggestionConfig = SuggestionConfig.getConfig(); - + // Use SearchServiceWrapper and VnfSearchService for suggestionConfig Map svcs = new HashMap(); svcs.put("autosuggestIndexname", "SearchServiceWrapper"); svcs.put("indexName", "VnfSearchService"); suggestionConfig.setSearchIndexToSearchService(svcs); - + esConfig.setIndexName("esi-localhost"); esConfig.setType("default"); @@ -150,7 +150,7 @@ public class SearchServletTest { vnfSearchService = Mockito.mock(VnfSearchService.class); initializeEntityDescriptors(); - + searchWrapper = new SearchServiceWrapper(); searchWrapper.setSasConfig(esConfig); searchWrapper.setSearch(searchAdapter); @@ -161,9 +161,9 @@ public class SearchServletTest { @Test public void validateAccessors() { - assertNotNull("Vnf Search Service should not be null", searchWrapper.getVnfSearch()); + assertNotNull("Vnf Search Service should not be null", searchWrapper.getVnfSearch()); } - + @Test public void validateInitializer() { @@ -173,7 +173,7 @@ public class SearchServletTest { assertNotNull("SearchAdapter should not be null", searchWrapper.getSearch()); assertNotNull("Suggestion Config should not be null", searchWrapper.getSuggestionConfig()); assertNotNull("VnfSearchService should not be null", searchWrapper.getVnfSearch()); - + searchWrapper.setOxmModelLoader(null); searchWrapper.setSasConfig(null); searchWrapper.setSearch(null); @@ -191,34 +191,34 @@ public class SearchServletTest { } } - + /** - * Test doGet() and doPost() for a non-existent end-point. A test objective would be - * to either return a 404 Not Found. + * Test doGet() and doPost() for a non-existent end-point. A test objective would be to either + * return a 404 Not Found. */ @Test public void validateMdcContextLoggingVariablesWhenExplicitlySet() { - + final String transactionId = "1234"; final String serviceName = "AAI_UI"; final String partnerName = "SparkyApp"; - + HttpServletHelper.assignRequestHeader(commonRequest, "X-TransactionId", transactionId); HttpServletHelper.assignRequestHeader(commonRequest, "X-FromAppId", partnerName); - + HttpServletHelper.assignRequestUri(commonRequest, "search/this/path/does/not/exist/"); - + try { - + /* * Testing the doGet() operation will hit the doPost() operation in the servlet as well */ OperationResult result = doEvaluationTestMDC(true, commonRequest, commonResponse); - - assertEquals(transactionId,MDC.get(MdcContext.MDC_REQUEST_ID)); - assertEquals(serviceName,MDC.get(MdcContext.MDC_SERVICE_NAME)); - assertEquals(partnerName,MDC.get(MdcContext.MDC_PARTNER_NAME)); + + assertEquals(transactionId, MDC.get(MdcContext.MDC_REQUEST_ID)); + assertEquals(serviceName, MDC.get(MdcContext.MDC_SERVICE_NAME)); + assertEquals(partnerName, MDC.get(MdcContext.MDC_PARTNER_NAME)); } catch (Exception exc) { exc.printStackTrace(); @@ -226,23 +226,24 @@ public class SearchServletTest { } } - + /** - * Test doGet() and doPost() for a non-existent end-point. A test objective would be - * to either return a 404 Not Found. + * Test doGet() and doPost() for a non-existent end-point. A test objective would be to either + * return a 404 Not Found. */ @Test public void validateMdcContextLoggingVariablesWhenNotExplicitlySet() { - - /*final String transactionId = "1234"; - final String serviceName = "AAI-UI"; - final String partnerName = "SparkyApp"; - - HttpServletHelper.assignRequestHeader(commonRequest, "X-TransactionId", transactionId); - HttpServletHelper.assignRequestHeader(commonRequest, "X-FromAppId", serviceName);*/ - + + /* + * final String transactionId = "1234"; final String serviceName = "AAI-UI"; final String + * partnerName = "SparkyApp"; + * + * HttpServletHelper.assignRequestHeader(commonRequest, "X-TransactionId", transactionId); + * HttpServletHelper.assignRequestHeader(commonRequest, "X-FromAppId", serviceName); + */ + HttpServletHelper.assignRequestUri(commonRequest, "search/this/path/does/not/exist/"); - + try { /* @@ -250,7 +251,7 @@ public class SearchServletTest { */ OperationResult result = doEvaluationTestMDC(true, commonRequest, commonResponse); - + assertNotNull(MDC.get(MdcContext.MDC_REQUEST_ID)); assertNotNull(MDC.get(MdcContext.MDC_SERVICE_NAME)); assertNotNull(MDC.get(MdcContext.MDC_PARTNER_NAME)); @@ -261,17 +262,17 @@ public class SearchServletTest { } } - - - + + + /** - * Test doGet() and doPost() for a non-existent end-point. + * Test doGet() and doPost() for a non-existent end-point. */ @Test public void validateViewAndInspectSearchError_invalidRequestUri() { - + HttpServletHelper.assignRequestUri(commonRequest, "search/this/path/does/not/exist/"); - + try { /* @@ -288,10 +289,10 @@ public class SearchServletTest { } } - - + + /** - * Test doGet() and doPost() for Unified Query Search success path + * Test doGet() and doPost() for Unified Query Search success path */ @Test public void validateQuerySearch_successPath() { @@ -302,12 +303,13 @@ public class SearchServletTest { searchEntity.setMaxResults("10"); searchEntity.setQueryStr("the quick brown fox"); - HttpServletHelper.assignRequestUri(commonRequest, "search/querysearch"); + HttpServletHelper.assignRequestUri(commonRequest, "search/querysearch"); HttpServletHelper.setRequestPayload(commonRequest, MediaType.JSON_UTF_8.toString(), NodeUtils.convertObjectToJson(searchEntity, false)); - - // set search-abstraction-response that we expect to get back from real system, but stubbed through a mock + + // set search-abstraction-response that we expect to get back from real system, but stubbed + // through a mock // to fulfill collaborator behavior OperationResult mockedEntitySearchResponse = new OperationResult(); @@ -315,22 +317,23 @@ public class SearchServletTest { mockedEntitySearchResponse.setResult(NodeUtils.convertObjectToJson( SearchAbstractionEntityBuilder.getSuccessfulEntitySearchResponse(), false)); - // TODO: make parameters expect certain values to lock in invocation attempt against a specific input sequence + // TODO: make parameters expect certain values to lock in invocation attempt against a + // specific input sequence Mockito.when(searchAdapter.doPost(anyString(), anyString(), anyString())) .thenReturn(mockedEntitySearchResponse); - + List autoSuggestions = new ArrayList(); - autoSuggestions.add(new SuggestionEntity("vnf","1234", "VNFs")); - autoSuggestions.add(new SuggestionEntity("vnf","1111", "Created VNFs")); - autoSuggestions.add(new SuggestionEntity("vnf","1122", "ACTIVE VNFs")); - autoSuggestions.add(new SuggestionEntity("vnf","2233", "ACTIVE and Error VNFs")); - autoSuggestions.add(new SuggestionEntity("vnf","3344", "ACTIVE and NOT ORCHESTRATED VNFs")); - autoSuggestions.add(new SuggestionEntity("vnf","4455", "ACTIVE and Running VNFs")); - autoSuggestions.add(new SuggestionEntity("vnf","5566", "Activated VNFs")); - autoSuggestions.add(new SuggestionEntity("vnf","6677", "CAPPED VNFs")); - autoSuggestions.add(new SuggestionEntity("vnf","7788", "CAPPED and Created VNFs")); - + autoSuggestions.add(new SuggestionEntity("vnf", "1234", "VNFs")); + autoSuggestions.add(new SuggestionEntity("vnf", "1111", "Created VNFs")); + autoSuggestions.add(new SuggestionEntity("vnf", "1122", "ACTIVE VNFs")); + autoSuggestions.add(new SuggestionEntity("vnf", "2233", "ACTIVE and Error VNFs")); + autoSuggestions.add(new SuggestionEntity("vnf", "3344", "ACTIVE and NOT ORCHESTRATED VNFs")); + autoSuggestions.add(new SuggestionEntity("vnf", "4455", "ACTIVE and Running VNFs")); + autoSuggestions.add(new SuggestionEntity("vnf", "5566", "Activated VNFs")); + autoSuggestions.add(new SuggestionEntity("vnf", "6677", "CAPPED VNFs")); + autoSuggestions.add(new SuggestionEntity("vnf", "7788", "CAPPED and Created VNFs")); + Mockito.when(vnfSearchService.getSuggestionsResults(Mockito.anyObject(), Mockito.anyInt())) .thenReturn(autoSuggestions); @@ -339,39 +342,39 @@ public class SearchServletTest { */ OperationResult result = doEvaluation(true, commonRequest, commonResponse); - - + + assertEquals(200, result.getResultCode()); - + SearchResponse searchResponse = mapper.readValue(result.getResult(), SearchResponse.class); - + assertEquals(10, searchResponse.getTotalFound()); - + int numVnf = 0; int numViewInspect = 0; - - for ( SuggestionEntity suggestion : searchResponse.getSuggestions()) { - - if ( VNF_ROUTE.equals(suggestion.getRoute())) { + + for (SuggestionEntity suggestion : searchResponse.getSuggestions()) { + + if (VNF_ROUTE.equals(suggestion.getRoute())) { numVnf++; - } else if ( VIEW_INSPECT_ROUTE.equals(suggestion.getRoute())) { + } else if (VIEW_INSPECT_ROUTE.equals(suggestion.getRoute())) { numViewInspect++; } } - + assertEquals(5, numVnf); assertEquals(5, numViewInspect); - - //assertTrue(result.getResult().contains("Ignored request-uri")); + + // assertTrue(result.getResult().contains("Ignored request-uri")); } catch (Exception exc) { fail("Unexpected exception = " + exc.getLocalizedMessage()); } } - + /** - * Test doGet() and doPost() for Unified Query Search success path + * Test doGet() and doPost() for Unified Query Search success path */ @Test public void validateSummaryByEntityTypeCount_successPath() { @@ -379,15 +382,17 @@ public class SearchServletTest { try { HttpServletHelper.assignRequestUri(commonRequest, "search/summarybyentitytype/count"); - - Map payloadFields = new HashMap(); - payloadFields.put("hashId", "662d1b57c31df70d7ef57ec53c0ace81578ec77b6bc5de055a57c7547ec122dd"); + + Map payloadFields = new HashMap(); + payloadFields.put("hashId", + "662d1b57c31df70d7ef57ec53c0ace81578ec77b6bc5de055a57c7547ec122dd"); payloadFields.put("groupby", "orchestration-status"); - - - HttpServletHelper.setRequestPayload(commonRequest, MediaType.JSON_UTF_8.toString(), NodeUtils.convertObjectToJson(payloadFields, false)); - - + + + HttpServletHelper.setRequestPayload(commonRequest, MediaType.JSON_UTF_8.toString(), + NodeUtils.convertObjectToJson(payloadFields, false)); + + /* * In this test we don't want to mock the vnf search service, only it's collaborator * interactions with a REST endpoint. @@ -397,55 +402,57 @@ public class SearchServletTest { searchWrapper.setVnfSearch(vnfSearchService); /* - * The first network response to mock is the one to elastic search to get the suggestion entity by hash id + * The first network response to mock is the one to elastic search to get the suggestion + * entity by hash id * - * http://localhost:9200/entityautosuggestindex-localhost/_search - * {"query":{"term":{"_id":"2172a3c25ae56e4995038ffbc1f055692bfc76c0b8ceda1205bc745a9f7a805d"}}} + * http://localhost:9200/entityautosuggestindex-localhost/_search + * {"query":{"term":{"_id":"2172a3c25ae56e4995038ffbc1f055692bfc76c0b8ceda1205bc745a9f7a805d"} + * }} */ - + AutoSuggestElasticSearchResponse elasticResponse = new AutoSuggestElasticSearchResponse(); - + elasticResponse.setTook(1); - + elasticResponse.setTimedOut(false); elasticResponse.addShard("total", "5"); elasticResponse.addShard("successful", "5"); elasticResponse.addShard("failed", "0"); - + AutoSuggestElasticHitEntity elasticHit = new AutoSuggestElasticHitEntity(); elasticHit.setIndex("entityautosuggestindex-localhost"); elasticHit.setType("default"); elasticHit.setId("2172a3c25ae56e4995038ffbc1f055692bfc76c0b8ceda1205bc745a9f7a805d"); elasticHit.setScore("1"); - + AutoSuggestDocumentEntityFields suggestDocFields = new AutoSuggestDocumentEntityFields(); suggestDocFields.addInput("VNFs"); suggestDocFields.addInput("generic-vnfs"); suggestDocFields.setOutput("VNFs"); suggestDocFields.setPayload(new PayloadEntity()); suggestDocFields.setWeight(100); - + AutoSuggestDocumentEntity autoSuggestDoc = new AutoSuggestDocumentEntity(); autoSuggestDoc.setFields(suggestDocFields); - + elasticHit.setSource(autoSuggestDoc); - + AutoSuggestElasticHitsEntity hits = new AutoSuggestElasticHitsEntity(); hits.addHit(elasticHit); - + elasticResponse.setHits(hits); - - + + OperationResult mockedSearchResponse = new OperationResult(); mockedSearchResponse.setResultCode(200); - + mockedSearchResponse.setResult(NodeUtils.convertObjectToJson(elasticResponse, false)); - + /* * The second response is the count API dip to elastic search */ - + ElasticSearchCountResponse countResponse = new ElasticSearchCountResponse(); countResponse.setCount(3170); countResponse.addShard("total", "5"); @@ -454,39 +461,41 @@ public class SearchServletTest { OperationResult searchResponseForCount = new OperationResult(); searchResponseForCount.setResultCode(200); - + searchResponseForCount.setResult(NodeUtils.convertObjectToJson(countResponse, false)); - // TODO: make parameters expect certain values to lock in invocation attempt against a specific input sequence + // TODO: make parameters expect certain values to lock in invocation attempt against a + // specific input sequence Mockito.when(searchAdapter.doPost(anyString(), anyString(), anyString())) .thenReturn(mockedSearchResponse).thenReturn(searchResponseForCount); - - + + /* * Testing the doGet() operation will hit the doPost() operation in the servlet as well */ OperationResult result = doEvaluation(true, commonRequest, commonResponse); - - + + assertEquals(200, result.getResultCode()); - + // - //{"shards":{"total":"5","failed":"0","successful":"5"},"count":3170} - - EntityCountResponse entityCountResponse = mapper.readValue(result.getResult(), EntityCountResponse.class); - - assertEquals(3170, entityCountResponse.getCount()); + // {"shards":{"total":"5","failed":"0","successful":"5"},"count":3170} + + EntityCountResponse entityCountResponse = + mapper.readValue(result.getResult(), EntityCountResponse.class); + + assertEquals(3170, entityCountResponse.getCount()); } catch (Exception exc) { fail("Unexpected exception = " + exc.getLocalizedMessage()); } } - - + + /** - * Test doGet() and doPost() for Unified Query Search success path + * Test doGet() and doPost() for Unified Query Search success path */ @Test public void validateSummaryByEntityType_successPath() { @@ -494,13 +503,15 @@ public class SearchServletTest { try { HttpServletHelper.assignRequestUri(commonRequest, "search/summarybyentitytype"); - - Map payloadFields = new HashMap(); - payloadFields.put("hashId", "662d1b57c31df70d7ef57ec53c0ace81578ec77b6bc5de055a57c7547ec122dd"); + + Map payloadFields = new HashMap(); + payloadFields.put("hashId", + "662d1b57c31df70d7ef57ec53c0ace81578ec77b6bc5de055a57c7547ec122dd"); payloadFields.put("groupby", "orchestration-status"); - - HttpServletHelper.setRequestPayload(commonRequest, MediaType.JSON_UTF_8.toString(), NodeUtils.convertObjectToJson(payloadFields, false)); - + + HttpServletHelper.setRequestPayload(commonRequest, MediaType.JSON_UTF_8.toString(), + NodeUtils.convertObjectToJson(payloadFields, false)); + /* * In this test we don't want to mock the vnf search service, only it's collaborator * interactions with a REST endpoint. @@ -510,128 +521,132 @@ public class SearchServletTest { searchWrapper.setVnfSearch(vnfSearchService); /* - * The first network response to mock is the one to elastic search to get the suggestion entity by hash id + * The first network response to mock is the one to elastic search to get the suggestion + * entity by hash id * - * http://localhost:9200/entityautosuggestindex-localhost/_search - * {"query":{"term":{"_id":"2172a3c25ae56e4995038ffbc1f055692bfc76c0b8ceda1205bc745a9f7a805d"}}} + * http://localhost:9200/entityautosuggestindex-localhost/_search + * {"query":{"term":{"_id":"2172a3c25ae56e4995038ffbc1f055692bfc76c0b8ceda1205bc745a9f7a805d"} + * }} */ - + AutoSuggestElasticSearchResponse elasticResponse = new AutoSuggestElasticSearchResponse(); - + elasticResponse.setTook(1); - + elasticResponse.setTimedOut(false); elasticResponse.addShard("total", "5"); elasticResponse.addShard("successful", "5"); elasticResponse.addShard("failed", "0"); - + AutoSuggestElasticHitEntity elasticHit = new AutoSuggestElasticHitEntity(); elasticHit.setIndex("entityautosuggestindex-localhost"); elasticHit.setType("default"); elasticHit.setId("2172a3c25ae56e4995038ffbc1f055692bfc76c0b8ceda1205bc745a9f7a805d"); elasticHit.setScore("1"); - + AutoSuggestDocumentEntityFields suggestDocFields = new AutoSuggestDocumentEntityFields(); suggestDocFields.addInput("VNFs"); suggestDocFields.addInput("generic-vnfs"); suggestDocFields.setOutput("VNFs"); suggestDocFields.setPayload(new PayloadEntity()); suggestDocFields.setWeight(100); - + AutoSuggestDocumentEntity autoSuggestDoc = new AutoSuggestDocumentEntity(); autoSuggestDoc.setFields(suggestDocFields); - + elasticHit.setSource(autoSuggestDoc); - + AutoSuggestElasticHitsEntity hits = new AutoSuggestElasticHitsEntity(); hits.addHit(elasticHit); - + elasticResponse.setHits(hits); - - + + OperationResult mockedSearchResponse = new OperationResult(); mockedSearchResponse.setResultCode(200); - + mockedSearchResponse.setResult(NodeUtils.convertObjectToJson(elasticResponse, false)); - + /* * The second response is the aggregation API dip to elastic search */ - + ElasticSearchAggegrationResponse aggResponse = new ElasticSearchAggegrationResponse(); - + aggResponse.setTook(20); aggResponse.setTimedOut(false); - - aggResponse.addShard("total","5"); - aggResponse.addShard("successful","5"); - aggResponse.addShard("failed","0"); - + + aggResponse.addShard("total", "5"); + aggResponse.addShard("successful", "5"); + aggResponse.addShard("failed", "0"); + ElasticHitsEntity hitsEntity = new ElasticHitsEntity(); - + hitsEntity.setTotal(3170); hitsEntity.setMaxScore(0); aggResponse.setHits(hitsEntity); - + ElasticSearchAggregation defaultAggregation = new ElasticSearchAggregation(); - + defaultAggregation.setDocCountErrorUpperBound(0); defaultAggregation.setSumOtherDocCount(0); - defaultAggregation.addBucket(new BucketEntity("created",1876)); - defaultAggregation.addBucket(new BucketEntity("Created",649)); - defaultAggregation.addBucket(new BucketEntity("Activated",158)); - defaultAggregation.addBucket(new BucketEntity("active",59)); - defaultAggregation.addBucket(new BucketEntity("NOT ORCHESTRATED",42)); - defaultAggregation.addBucket(new BucketEntity("Pending-Create",10)); - defaultAggregation.addBucket(new BucketEntity("Running",9)); - defaultAggregation.addBucket(new BucketEntity("Configured",7)); - defaultAggregation.addBucket(new BucketEntity("pending-create",7)); - defaultAggregation.addBucket(new BucketEntity("Error",3)); - defaultAggregation.addBucket(new BucketEntity("planned",3)); - defaultAggregation.addBucket(new BucketEntity("PLANNED",2)); - defaultAggregation.addBucket(new BucketEntity("ERROR",1)); - defaultAggregation.addBucket(new BucketEntity("RUNNING",1)); - defaultAggregation.addBucket(new BucketEntity("example-orchestration-status-val-6176",1)); - + defaultAggregation.addBucket(new BucketEntity("created", 1876)); + defaultAggregation.addBucket(new BucketEntity("Created", 649)); + defaultAggregation.addBucket(new BucketEntity("Activated", 158)); + defaultAggregation.addBucket(new BucketEntity("active", 59)); + defaultAggregation.addBucket(new BucketEntity("NOT ORCHESTRATED", 42)); + defaultAggregation.addBucket(new BucketEntity("Pending-Create", 10)); + defaultAggregation.addBucket(new BucketEntity("Running", 9)); + defaultAggregation.addBucket(new BucketEntity("Configured", 7)); + defaultAggregation.addBucket(new BucketEntity("pending-create", 7)); + defaultAggregation.addBucket(new BucketEntity("Error", 3)); + defaultAggregation.addBucket(new BucketEntity("planned", 3)); + defaultAggregation.addBucket(new BucketEntity("PLANNED", 2)); + defaultAggregation.addBucket(new BucketEntity("ERROR", 1)); + defaultAggregation.addBucket(new BucketEntity("RUNNING", 1)); + defaultAggregation.addBucket(new BucketEntity("example-orchestration-status-val-6176", 1)); + aggResponse.addAggregation("default", defaultAggregation); - + OperationResult searchResponseForAggregation = new OperationResult(); searchResponseForAggregation.setResultCode(200); - + searchResponseForAggregation.setResult(NodeUtils.convertObjectToJson(aggResponse, false)); - // TODO: make parameters expect certain values to lock in invocation attempt against a specific input sequence + // TODO: make parameters expect certain values to lock in invocation attempt against a + // specific input sequence Mockito.when(searchAdapter.doPost(anyString(), anyString(), anyString())) .thenReturn(mockedSearchResponse).thenReturn(searchResponseForAggregation); - - + + /* * Testing the doGet() operation will hit the doPost() operation in the servlet as well */ OperationResult result = doEvaluation(true, commonRequest, commonResponse); - - + + assertEquals(200, result.getResultCode()); - + // - //{"shards":{"total":"5","failed":"0","successful":"5"},"count":3170} - - GroupByAggregationResponseEntity groupByResponse = mapper.readValue(result.getResult(), GroupByAggregationResponseEntity.class); - - assertEquals(2828, groupByResponse.getAggEntity().getTotalChartHits()); - assertEquals(15, groupByResponse.getAggEntity().getBuckets().size()); + // {"shards":{"total":"5","failed":"0","successful":"5"},"count":3170} + + GroupByAggregationResponseEntity groupByResponse = + mapper.readValue(result.getResult(), GroupByAggregationResponseEntity.class); + + assertEquals(2828, groupByResponse.getAggEntity().getTotalChartHits()); + assertEquals(15, groupByResponse.getAggEntity().getBuckets().size()); } catch (Exception exc) { fail("Unexpected exception = " + exc.getLocalizedMessage()); } } - - - + + + /** * Builds the resource entity descriptor. * @@ -664,7 +679,7 @@ public class SearchServletTest { descriptors.put("customer", buildResourceEntityDescriptor("customer", "service-instance-id", "f1,f2,f3")); } - + /** * Builds the view and inspect search request. * @@ -703,7 +718,8 @@ public class SearchServletTest { * @param res the res * @return the string */ - private OperationResult doEvaluationTestMDC(boolean doGet, HttpServletRequest req, HttpServletResponse res) { + private OperationResult doEvaluationTestMDC(boolean doGet, HttpServletRequest req, + HttpServletResponse res) { /* * Test method invocation @@ -717,7 +733,7 @@ public class SearchServletTest { e.printStackTrace(); } ArgumentCaptor responseCodeCaptor = ArgumentCaptor.forClass(Integer.class); - + try { if (doGet) { searchServlet.doGet(req, res); @@ -732,16 +748,16 @@ public class SearchServletTest { responseStringWriter.flush(); Mockito.verify(commonResponse, Mockito.atLeast(1)).setStatus(responseCodeCaptor.capture()); - + OperationResult result = new OperationResult(); - + result.setResultCode(responseCodeCaptor.getValue()); result.setResult(responseStringWriter.toString()); return result; } - + /** * Do evaluation. * @@ -750,13 +766,14 @@ public class SearchServletTest { * @param res the res * @return the string */ - private OperationResult doEvaluation(boolean doGet, HttpServletRequest req, HttpServletResponse res) { + private OperationResult doEvaluation(boolean doGet, HttpServletRequest req, + HttpServletResponse res) { /* * Test method invocation */ ArgumentCaptor responseCodeCaptor = ArgumentCaptor.forClass(Integer.class); - + try { if (doGet) { searchWrapper.doGet(req, res); @@ -771,9 +788,9 @@ public class SearchServletTest { responseStringWriter.flush(); Mockito.verify(commonResponse, Mockito.atLeast(1)).setStatus(responseCodeCaptor.capture()); - + OperationResult result = new OperationResult(); - + result.setResultCode(responseCodeCaptor.getValue()); result.setResult(responseStringWriter.toString()); @@ -781,6 +798,6 @@ public class SearchServletTest { } - + } diff --git a/src/test/java/org/onap/aai/sparky/viewandinspect/SearchableGroupsTest.java b/src/test/java/org/onap/aai/sparky/viewandinspect/SearchableGroupsTest.java index d378c3a..5d9fa3a 100644 --- a/src/test/java/org/onap/aai/sparky/viewandinspect/SearchableGroupsTest.java +++ b/src/test/java/org/onap/aai/sparky/viewandinspect/SearchableGroupsTest.java @@ -36,38 +36,36 @@ public class SearchableGroupsTest { + "\"search-paths\" : [\"cloud-infrastructure\", \"business\", \"network\"]" + "}," + "{" + "\"group-name\" : \"cloud-infrastructure\"," + "\"search-paths\" : [\"complexes\", \"cloud-regions\", \"pservers\"]" + "}" + "]" + "}"; - /* - * @Before public void init() throws NoSuchFieldException, SecurityException, - * IllegalArgumentException, IllegalAccessException { Field instance = - * SearchableGroups.class.getDeclaredField("instance"); instance.setAccessible(true); - * instance.set(null, null); } - * - * @Test public void test_FileNotFound() throws ElasticSearchOperationException { - * System.setProperty("AJSC_HOME", ""); SearchableGroups testGroups = - * SearchableGroups.getTestInstance(); assertTrue(testGroups.getGroups().isEmpty()); } - * - * @Test public void test_FileFoundWithProperlyFormatedConfig() throws - * ElasticSearchOperationException { ResolverUtils testUtils = - * Mockito.mock(ResolverUtils.class); - * Mockito.when(testUtils.getConfigSettings(anyString())).thenReturn(GOOD_TEST_CONFIG); - * SearchableGroups testGroups = SearchableGroups.getTestInstance(); - * - * testGroups.setUtils(testUtils); testGroups.initSearchableGroups(); - * - * assertFalse(testGroups.getGroups().isEmpty()); - * - * assertFalse(testGroups.getSearchableGroups("inventory").isEmpty()); } - * - * @Test public void test_FileFoundGroupDoesNotExist() throws - * ElasticSearchOperationException { - * ResolverUtils testUtils = Mockito.mock(ResolverUtils.class); - * Mockito.when(testUtils.getConfigSettings(anyString())).thenReturn(GOOD_TEST_CONFIG); - * SearchableGroups testGroups = SearchableGroups.getTestInstance(); - * - * testGroups.setUtils(testUtils); testGroups.initSearchableGroups(); - * - * assertFalse(testGroups.getGroups().isEmpty()); - * - * assertEquals(null, testGroups.getSearchableGroups("Test")); } - */ + /* + * @Before public void init() throws NoSuchFieldException, SecurityException, + * IllegalArgumentException, IllegalAccessException { Field instance = + * SearchableGroups.class.getDeclaredField("instance"); instance.setAccessible(true); + * instance.set(null, null); } + * + * @Test public void test_FileNotFound() throws ElasticSearchOperationException { + * System.setProperty("AJSC_HOME", ""); SearchableGroups testGroups = + * SearchableGroups.getTestInstance(); assertTrue(testGroups.getGroups().isEmpty()); } + * + * @Test public void test_FileFoundWithProperlyFormatedConfig() throws + * ElasticSearchOperationException { ResolverUtils testUtils = Mockito.mock(ResolverUtils.class); + * Mockito.when(testUtils.getConfigSettings(anyString())).thenReturn(GOOD_TEST_CONFIG); + * SearchableGroups testGroups = SearchableGroups.getTestInstance(); + * + * testGroups.setUtils(testUtils); testGroups.initSearchableGroups(); + * + * assertFalse(testGroups.getGroups().isEmpty()); + * + * assertFalse(testGroups.getSearchableGroups("inventory").isEmpty()); } + * + * @Test public void test_FileFoundGroupDoesNotExist() throws ElasticSearchOperationException { + * ResolverUtils testUtils = Mockito.mock(ResolverUtils.class); + * Mockito.when(testUtils.getConfigSettings(anyString())).thenReturn(GOOD_TEST_CONFIG); + * SearchableGroups testGroups = SearchableGroups.getTestInstance(); + * + * testGroups.setUtils(testUtils); testGroups.initSearchableGroups(); + * + * assertFalse(testGroups.getGroups().isEmpty()); + * + * assertEquals(null, testGroups.getSearchableGroups("Test")); } + */ } diff --git a/src/test/java/org/onap/aai/sparky/viewandinspect/ViewAndInspectSearchRequestTest.java b/src/test/java/org/onap/aai/sparky/viewandinspect/ViewAndInspectSearchRequestTest.java index 15d46dd..70dd762 100644 --- a/src/test/java/org/onap/aai/sparky/viewandinspect/ViewAndInspectSearchRequestTest.java +++ b/src/test/java/org/onap/aai/sparky/viewandinspect/ViewAndInspectSearchRequestTest.java @@ -38,7 +38,7 @@ import org.onap.aai.sparky.viewandinspect.entity.QuerySearchEntity; /** * The Class ViewAndInspectSearchRequestTest. */ -@RunWith(MockitoJUnitRunner.class) +@RunWith(MockitoJUnitRunner.class) public class ViewAndInspectSearchRequestTest { /** diff --git a/src/test/java/org/onap/aai/sparky/viewandinspect/entity/EntityEntryTest.java b/src/test/java/org/onap/aai/sparky/viewandinspect/entity/EntityEntryTest.java index 023855b..d5fe2ae 100644 --- a/src/test/java/org/onap/aai/sparky/viewandinspect/entity/EntityEntryTest.java +++ b/src/test/java/org/onap/aai/sparky/viewandinspect/entity/EntityEntryTest.java @@ -39,7 +39,7 @@ import org.mockito.runners.MockitoJUnitRunner; /** * The Class EntityEntryTest. */ -@RunWith(MockitoJUnitRunner.class) +@RunWith(MockitoJUnitRunner.class) public class EntityEntryTest { /** diff --git a/src/test/java/org/onap/aai/sparky/viewandinspect/services/VisualizationContextTest.java b/src/test/java/org/onap/aai/sparky/viewandinspect/services/VisualizationContextTest.java index 08ce29d..00c6267 100644 --- a/src/test/java/org/onap/aai/sparky/viewandinspect/services/VisualizationContextTest.java +++ b/src/test/java/org/onap/aai/sparky/viewandinspect/services/VisualizationContextTest.java @@ -56,84 +56,86 @@ import com.fasterxml.jackson.databind.node.ObjectNode; public class VisualizationContextTest { - VisualizationContext context; - ActiveInventoryDataProvider dataProvider; - long contextId; - OxmModelLoader oxmModelLoader; - ExecutorService service; + VisualizationContext context; + ActiveInventoryDataProvider dataProvider; + long contextId; + OxmModelLoader oxmModelLoader; + ExecutorService service; - @Before - public void init() throws Exception { - MockitoAnnotations.initMocks(this); - System.setProperty("AJSC_HOME", new File(".").getCanonicalPath().replace('\\', '/')); - TierSupportUiConstants.DYNAMIC_CONFIG_APP_LOCATION = System.getProperty("AJSC_HOME")+"/src/test/resources/appconfig/"; - TierSupportUiConstants.CONFIG_OXM_LOCATION = System.getProperty("AJSC_HOME")+"/bundleconfig-local/oxm/"; - oxmModelLoader = Mockito.spy(OxmModelLoader.getInstance()); - ActiveInventoryDataProvider dataProvider = new ActiveInventoryAdapter(new RestClientBuilder()); - SecureRandom random = new SecureRandom(); - long contextId = random.nextLong(); - ExecutorService service = NodeUtils.createNamedExecutor("SLNC-WORKER", - 2, LoggerFactory.getInstance().getLogger(VisualizationContextTest.class)); - context = new VisualizationContext(contextId, dataProvider, service, oxmModelLoader); - } + @Before + public void init() throws Exception { + MockitoAnnotations.initMocks(this); + System.setProperty("AJSC_HOME", new File(".").getCanonicalPath().replace('\\', '/')); + TierSupportUiConstants.DYNAMIC_CONFIG_APP_LOCATION = + System.getProperty("AJSC_HOME") + "/src/test/resources/appconfig/"; + TierSupportUiConstants.CONFIG_OXM_LOCATION = + System.getProperty("AJSC_HOME") + "/bundleconfig-local/oxm/"; + oxmModelLoader = Mockito.spy(OxmModelLoader.getInstance()); + ActiveInventoryDataProvider dataProvider = new ActiveInventoryAdapter(new RestClientBuilder()); + SecureRandom random = new SecureRandom(); + long contextId = random.nextLong(); + ExecutorService service = NodeUtils.createNamedExecutor("SLNC-WORKER", 2, + LoggerFactory.getInstance().getLogger(VisualizationContextTest.class)); + context = new VisualizationContext(contextId, dataProvider, service, oxmModelLoader); + } - @Test - public void testExtractQueryParamsFromSelfLink_NullLink() { - List queryParams = context.extractQueryParamsFromSelfLink(null); - Assert.assertEquals(queryParams.size(), 0); - } + @Test + public void testExtractQueryParamsFromSelfLink_NullLink() { + List queryParams = context.extractQueryParamsFromSelfLink(null); + Assert.assertEquals(queryParams.size(), 0); + } - @Test - public void testExtractQueryParamsFromSelfLink_NotNullLink() { - context.extractQueryParamsFromSelfLink("https://localhost:9517/model/aai/webapp/index.html"); - } + @Test + public void testExtractQueryParamsFromSelfLink_NotNullLink() { + context.extractQueryParamsFromSelfLink("https://localhost:9517/model/aai/webapp/index.html"); + } - @Test - public void testDecodeComplexAttributeGroup_NullAttributeGroup() { - ActiveInventoryNode ain = new ActiveInventoryNode(); - ObjectNode node = JsonNodeFactory.instance.objectNode(); - boolean retValue = context.decodeComplexAttributeGroup(ain, node); - Assert.assertFalse(retValue); - } + @Test + public void testDecodeComplexAttributeGroup_NullAttributeGroup() { + ActiveInventoryNode ain = new ActiveInventoryNode(); + ObjectNode node = JsonNodeFactory.instance.objectNode(); + boolean retValue = context.decodeComplexAttributeGroup(ain, node); + Assert.assertFalse(retValue); + } - @Test - public void testDecodeComplexAttributeGroup_NotNullAttributeGroup() { - ActiveInventoryNode ain = new ActiveInventoryNode(); - ObjectNode node1 = JsonNodeFactory.instance.objectNode(); - ObjectNode node2 = JsonNodeFactory.instance.objectNode(); - node1.set("model", node2); - ObjectNode modelNode = JsonNodeFactory.instance.objectNode(); - node2.set("model-1", modelNode); - modelNode.set("firstValue", JsonNodeFactory.instance.objectNode()); - modelNode.set("secondValue", JsonNodeFactory.instance.objectNode()); - modelNode.set("thirdValue", JsonNodeFactory.instance.objectNode()); - boolean retValue = context.decodeComplexAttributeGroup(ain, node1); - Assert.assertFalse(retValue); - } + @Test + public void testDecodeComplexAttributeGroup_NotNullAttributeGroup() { + ActiveInventoryNode ain = new ActiveInventoryNode(); + ObjectNode node1 = JsonNodeFactory.instance.objectNode(); + ObjectNode node2 = JsonNodeFactory.instance.objectNode(); + node1.set("model", node2); + ObjectNode modelNode = JsonNodeFactory.instance.objectNode(); + node2.set("model-1", modelNode); + modelNode.set("firstValue", JsonNodeFactory.instance.objectNode()); + modelNode.set("secondValue", JsonNodeFactory.instance.objectNode()); + modelNode.set("thirdValue", JsonNodeFactory.instance.objectNode()); + boolean retValue = context.decodeComplexAttributeGroup(ain, node1); + Assert.assertFalse(retValue); + } - @Test - public void testProcessSelfLinks() { - SearchableEntity entity = new SearchableEntity(); - entity.setId("id-1"); - entity.setEntityType("cloud-region"); - entity.setEntityPrimaryKeyValue("cloud-region-1"); - entity.setLink("https://localhost:9517/model/aai/webapp/index.html"); - QueryParams params = new QueryParams(); - params.setSearchTargetNodeId("id-1"); - Map nodeMap = context.getNodeCache(); - ActiveInventoryNode node = new ActiveInventoryNode(); - node.setEntityType("cloud-region"); - node.setNodeId("id-1"); - node.setPrimaryKeyName("cloud-region-1"); - node.setPrimaryKeyValue("cloud-region-1"); - node.addQueryParam( + @Test + public void testProcessSelfLinks() { + SearchableEntity entity = new SearchableEntity(); + entity.setId("id-1"); + entity.setEntityType("cloud-region"); + entity.setEntityPrimaryKeyValue("cloud-region-1"); + entity.setLink("https://localhost:9517/model/aai/webapp/index.html"); + QueryParams params = new QueryParams(); + params.setSearchTargetNodeId("id-1"); + Map nodeMap = context.getNodeCache(); + ActiveInventoryNode node = new ActiveInventoryNode(); + node.setEntityType("cloud-region"); + node.setNodeId("id-1"); + node.setPrimaryKeyName("cloud-region-1"); + node.setPrimaryKeyValue("cloud-region-1"); + node.addQueryParam( node.getEntityType() + "." + node.getPrimaryKeyName() + ":" + node.getPrimaryKeyValue()); - node.setNodeDepth(0); - node.setRootNode(true); - node.setSelfLink(entity.getLink()); - nodeMap.put("id-1", node); - node.setResolvedSelfLink(true); - context.processSelfLinks(entity, params); + node.setNodeDepth(0); + node.setRootNode(true); + node.setSelfLink(entity.getLink()); + nodeMap.put("id-1", node); + node.setResolvedSelfLink(true); + context.processSelfLinks(entity, params); - } + } } diff --git a/src/test/java/org/onap/aai/sparky/viewandinspect/services/VisualizationServiceTest.java b/src/test/java/org/onap/aai/sparky/viewandinspect/services/VisualizationServiceTest.java index 72ea1ed..fef0410 100644 --- a/src/test/java/org/onap/aai/sparky/viewandinspect/services/VisualizationServiceTest.java +++ b/src/test/java/org/onap/aai/sparky/viewandinspect/services/VisualizationServiceTest.java @@ -33,79 +33,64 @@ import org.onap.aai.sparky.viewandinspect.entity.QueryRequest; public class VisualizationServiceTest { - VisualizationService service; - - @Before - public void init() throws Exception { - System.setProperty("AJSC_HOME", new File(".").getCanonicalPath().replace('\\', '/')); - TierSupportUiConstants.DYNAMIC_CONFIG_APP_LOCATION = System.getProperty("AJSC_HOME")+"/src/test/resources/appconfig/"; - //TierSupportUiConstants.CONFIG_OXM_LOCATION = System.getProperty("AJSC_HOME")+"/bundleconfig-local/oxm/"; - TierSupportUiConstants.STATIC_CONFIG_APP_LOCATION = System.getProperty("AJSC_HOME")+"/bundleconfig-local/etc/appprops"; - OxmModelLoader loader = OxmModelLoader.getInstance(); - service = new VisualizationService(loader); - } - - @Test - public void testAnalyzeQueryRequestBody_InvalidQuery() { - QueryRequest request = service.analyzeQueryRequestBody("query-json-1"); - Assert.assertNull(request); - } - - @Test - public void testAnalyzeQueryRequestBody_ValidQuery() { - QueryRequest request = service.analyzeQueryRequestBody("{\"hashId\":\"hashid-1\"}"); - Assert.assertNotNull(request); - } - @Test - public void testBuildVisualizationUsingGenericQuery_UnsuccessfulOperationResult() { - QueryRequest queryRequest = new QueryRequest(); - queryRequest.setHashId("hash-id-1"); - service.buildVisualizationUsingGenericQuery(queryRequest); - } + VisualizationService service; - String queryRequest = "{\r\n" + - " \"variables\": [],\r\n" + - " \"info\": {\r\n" + - " \"name\": \"NamedQuery\",\r\n" + - " \"_postman_id\": \"8006823d-35ce-16ef-88e9-cd5b873c9e7b\",\r\n" + - " \"schema\": \"https://schema.getpostman.com/json/collection/v2.0.0/collection.json\"\r\n" + - " },\r\n" + - " \"item\": [\r\n" + - " {\r\n" + - " \"name\": \"https://127.0.0.1:8443/aai/v11/service-design-and-creation/named-queries/named-query/0367193e-c785-4d5f-9cb8-7bc89dc9ddb7\",\r\n" + - " \"request\": {\r\n" + - " \"url\": \"https://127.0.0.1:8443/aai/v11/service-design-and-creation/named-queries/named-query/0367193e-c785-4d5f-9cb8-7bc89dc9ddb7\",\r\n" + - " \"method\": \"POST\",\r\n" + - " \"header\": [\r\n" + - " {\r\n" + - " \"key\": \"Content-Type\",\r\n" + - " \"value\": \"application/json\",\r\n" + - " \"description\": \"\"\r\n" + - " },\r\n" + - " {\r\n" + - " \"key\": \"X-TransactionId\",\r\n" + - " \"value\": \"9999\",\r\n" + - " \"description\": \"\"\r\n" + - " },\r\n" + - " {\r\n" + - " \"key\": \"X-FromAppId\",\r\n" + - " \"value\": \"jimmy-postman\",\r\n" + - " \"description\": \"\"\r\n" + - " },\r\n" + - " {\r\n" + - " \"key\": \"Authorization\",\r\n" + - " \"value\": \"Basic QUFJOkFBSQ==\",\r\n" + - " \"description\": \"\"\r\n" + - " }\r\n" + - " ],\r\n" + - " \"body\": {\r\n" + - " \"mode\": \"raw\",\r\n" + - " \"raw\": \"{\\n \\\"named-query-uuid\\\" : \\\"0367193e-c785-4d5f-9cb8-7bc89dc9ddb7\\\",\\n \\\"named-query-name\\\" : \\\"get-component-list\\\",\\n \\\"named-query-version\\\" : \\\"1.1\\\",\\n \\\"description\\\" : \\\"Named Query - Get Component List\\\",\\n \\\"named-query-elements\\\" : {\\n \\\"named-query-element\\\" : [ {\\n \\\"property-collect-list\\\" : [ \\\"service-instance-id\\\", \\\"service-instance-name\\\" ],\\n \\\"named-query-elements\\\" : {\\n \\\"named-query-element\\\" : [ {\\n \\\"named-query-elements\\\" : {\\n \\\"named-query-element\\\" : [ {\\n \\\"relationship-list\\\" : {\\n \\\"relationship\\\" : [ {\\n \\\"related-to\\\" : \\\"model\\\",\\n \\\"relationship-data\\\" : [ {\\n \\\"relationship-key\\\" : \\\"model.model-invariant-id\\\",\\n \\\"relationship-value\\\" : \\\"1b2c9ba7-e449-4831-ba15-3073672f5ef2\\\"\\n } ]\\n } ]\\n }\\n } ]\\n },\\n \\\"relationship-list\\\" : {\\n \\\"relationship\\\" : [ {\\n \\\"related-to\\\" : \\\"model\\\",\\n \\\"relationship-data\\\" : [ {\\n \\\"relationship-key\\\" : \\\"model.model-invariant-id\\\",\\n \\\"relationship-value\\\" : \\\"3d560d81-57d0-438b-a2a1-5334dba0651a\\\"\\n } ]\\n } ]\\n }\\n }, {\\n \\\"named-query-elements\\\" : {\\n \\\"named-query-element\\\" : [ {\\n \\\"relationship-list\\\" : {\\n \\\"relationship\\\" : [ {\\n \\\"related-to\\\" : \\\"model\\\",\\n \\\"relationship-data\\\" : [ {\\n \\\"relationship-key\\\" : \\\"model.model-invariant-id\\\",\\n \\\"relationship-value\\\" : \\\"fcec1b02-b2d0-4834-aef8-d71be04717dd\\\"\\n } ]\\n } ]\\n }\\n }, {\\n \\\"named-query-elements\\\" : {\\n \\\"named-query-element\\\" : [ {\\n \\\"relationship-list\\\" : {\\n \\\"relationship\\\" : [ {\\n \\\"related-to\\\" : \\\"model\\\",\\n \\\"relationship-data\\\" : [ {\\n \\\"relationship-key\\\" : \\\"model.model-invariant-id\\\",\\n \\\"relationship-value\\\" : \\\"ff69d4e0-a8e8-4108-bdb0-dd63217e63c7\\\"\\n } ]\\n } ]\\n }\\n }, {\\n \\\"relationship-list\\\" : {\\n \\\"relationship\\\" : [ {\\n \\\"related-to\\\" : \\\"model\\\",\\n \\\"relationship-data\\\" : [ {\\n \\\"relationship-key\\\" : \\\"model.model-invariant-id\\\",\\n \\\"relationship-value\\\" : \\\"fcec1b02-b2d0-4834-aef8-d71be04717dd\\\"\\n } ]\\n } ]\\n }\\n }, {\\n \\\"named-query-elements\\\" : {\\n \\\"named-query-element\\\" : [ {\\n \\\"relationship-list\\\" : {\\n \\\"relationship\\\" : [ {\\n \\\"related-to\\\" : \\\"model\\\",\\n \\\"relationship-data\\\" : [ {\\n \\\"relationship-key\\\" : \\\"model.model-invariant-id\\\",\\n \\\"relationship-value\\\" : \\\"1b2c9ba7-e449-4831-ba15-3073672f5ef2\\\"\\n } ]\\n } ]\\n }\\n } ]\\n },\\n \\\"relationship-list\\\" : {\\n \\\"relationship\\\" : [ {\\n \\\"related-to\\\" : \\\"model\\\",\\n \\\"relationship-data\\\" : [ {\\n \\\"relationship-key\\\" : \\\"model.model-invariant-id\\\",\\n \\\"relationship-value\\\" : \\\"3d560d81-57d0-438b-a2a1-5334dba0651a\\\"\\n } ]\\n } ]\\n }\\n } ]\\n },\\n \\\"relationship-list\\\" : {\\n \\\"relationship\\\" : [ {\\n \\\"related-to\\\" : \\\"model\\\",\\n \\\"relationship-data\\\" : [ {\\n \\\"relationship-key\\\" : \\\"model.model-invariant-id\\\",\\n \\\"relationship-value\\\" : \\\"ef86f9c5-2165-44f3-8fc3-96018b609ea5\\\"\\n } ]\\n } ]\\n }\\n } ]\\n },\\n \\\"relationship-list\\\" : {\\n \\\"relationship\\\" : [ {\\n \\\"related-to\\\" : \\\"model\\\",\\n \\\"relationship-data\\\" : [ {\\n \\\"relationship-key\\\" : \\\"model.model-invariant-id\\\",\\n \\\"relationship-value\\\" : \\\"acc6edd8-a8d4-4b93-afaa-0994068be14c\\\"\\n } ]\\n } ]\\n }\\n } ]\\n },\\n \\\"relationship-list\\\" : {\\n \\\"relationship\\\" : [ {\\n \\\"related-to\\\" : \\\"model\\\",\\n \\\"relationship-data\\\" : [ {\\n \\\"relationship-key\\\" : \\\"model.model-invariant-id\\\",\\n \\\"relationship-value\\\" : \\\"82194af1-3c2c-485a-8f44-420e22a9eaa4\\\"\\n } ]\\n } ]\\n }\\n } ]\\n }\\n}\\n\"\r\n" + - " },\r\n" + - " \"description\": \"\"\r\n" + - " },\r\n" + - " \"response\": []\r\n" + - " }\r\n" + - " ]\r\n" + - "}"; + @Before + public void init() throws Exception { + System.setProperty("AJSC_HOME", new File(".").getCanonicalPath().replace('\\', '/')); + TierSupportUiConstants.DYNAMIC_CONFIG_APP_LOCATION = + System.getProperty("AJSC_HOME") + "/src/test/resources/appconfig/"; + // TierSupportUiConstants.CONFIG_OXM_LOCATION = + // System.getProperty("AJSC_HOME")+"/bundleconfig-local/oxm/"; + TierSupportUiConstants.STATIC_CONFIG_APP_LOCATION = + System.getProperty("AJSC_HOME") + "/bundleconfig-local/etc/appprops"; + OxmModelLoader loader = OxmModelLoader.getInstance(); + service = new VisualizationService(loader); + } + + @Test + public void testAnalyzeQueryRequestBody_InvalidQuery() { + QueryRequest request = service.analyzeQueryRequestBody("query-json-1"); + Assert.assertNull(request); + } + + @Test + public void testAnalyzeQueryRequestBody_ValidQuery() { + QueryRequest request = service.analyzeQueryRequestBody("{\"hashId\":\"hashid-1\"}"); + Assert.assertNotNull(request); + } + + @Test + public void testBuildVisualizationUsingGenericQuery_UnsuccessfulOperationResult() { + QueryRequest queryRequest = new QueryRequest(); + queryRequest.setHashId("hash-id-1"); + service.buildVisualizationUsingGenericQuery(queryRequest); + } + + String queryRequest = "{\r\n" + " \"variables\": [],\r\n" + " \"info\": {\r\n" + + " \"name\": \"NamedQuery\",\r\n" + + " \"_postman_id\": \"8006823d-35ce-16ef-88e9-cd5b873c9e7b\",\r\n" + + " \"schema\": \"https://schema.getpostman.com/json/collection/v2.0.0/collection.json\"\r\n" + + " },\r\n" + " \"item\": [\r\n" + " {\r\n" + + " \"name\": \"https://127.0.0.1:8443/aai/v11/service-design-and-creation/named-queries/named-query/0367193e-c785-4d5f-9cb8-7bc89dc9ddb7\",\r\n" + + " \"request\": {\r\n" + + " \"url\": \"https://127.0.0.1:8443/aai/v11/service-design-and-creation/named-queries/named-query/0367193e-c785-4d5f-9cb8-7bc89dc9ddb7\",\r\n" + + " \"method\": \"POST\",\r\n" + " \"header\": [\r\n" + + " {\r\n" + " \"key\": \"Content-Type\",\r\n" + + " \"value\": \"application/json\",\r\n" + + " \"description\": \"\"\r\n" + " },\r\n" + + " {\r\n" + " \"key\": \"X-TransactionId\",\r\n" + + " \"value\": \"9999\",\r\n" + + " \"description\": \"\"\r\n" + " },\r\n" + + " {\r\n" + " \"key\": \"X-FromAppId\",\r\n" + + " \"value\": \"jimmy-postman\",\r\n" + + " \"description\": \"\"\r\n" + " },\r\n" + + " {\r\n" + " \"key\": \"Authorization\",\r\n" + + " \"value\": \"Basic QUFJOkFBSQ==\",\r\n" + + " \"description\": \"\"\r\n" + " }\r\n" + + " ],\r\n" + " \"body\": {\r\n" + + " \"mode\": \"raw\",\r\n" + + " \"raw\": \"{\\n \\\"named-query-uuid\\\" : \\\"0367193e-c785-4d5f-9cb8-7bc89dc9ddb7\\\",\\n \\\"named-query-name\\\" : \\\"get-component-list\\\",\\n \\\"named-query-version\\\" : \\\"1.1\\\",\\n \\\"description\\\" : \\\"Named Query - Get Component List\\\",\\n \\\"named-query-elements\\\" : {\\n \\\"named-query-element\\\" : [ {\\n \\\"property-collect-list\\\" : [ \\\"service-instance-id\\\", \\\"service-instance-name\\\" ],\\n \\\"named-query-elements\\\" : {\\n \\\"named-query-element\\\" : [ {\\n \\\"named-query-elements\\\" : {\\n \\\"named-query-element\\\" : [ {\\n \\\"relationship-list\\\" : {\\n \\\"relationship\\\" : [ {\\n \\\"related-to\\\" : \\\"model\\\",\\n \\\"relationship-data\\\" : [ {\\n \\\"relationship-key\\\" : \\\"model.model-invariant-id\\\",\\n \\\"relationship-value\\\" : \\\"1b2c9ba7-e449-4831-ba15-3073672f5ef2\\\"\\n } ]\\n } ]\\n }\\n } ]\\n },\\n \\\"relationship-list\\\" : {\\n \\\"relationship\\\" : [ {\\n \\\"related-to\\\" : \\\"model\\\",\\n \\\"relationship-data\\\" : [ {\\n \\\"relationship-key\\\" : \\\"model.model-invariant-id\\\",\\n \\\"relationship-value\\\" : \\\"3d560d81-57d0-438b-a2a1-5334dba0651a\\\"\\n } ]\\n } ]\\n }\\n }, {\\n \\\"named-query-elements\\\" : {\\n \\\"named-query-element\\\" : [ {\\n \\\"relationship-list\\\" : {\\n \\\"relationship\\\" : [ {\\n \\\"related-to\\\" : \\\"model\\\",\\n \\\"relationship-data\\\" : [ {\\n \\\"relationship-key\\\" : \\\"model.model-invariant-id\\\",\\n \\\"relationship-value\\\" : \\\"fcec1b02-b2d0-4834-aef8-d71be04717dd\\\"\\n } ]\\n } ]\\n }\\n }, {\\n \\\"named-query-elements\\\" : {\\n \\\"named-query-element\\\" : [ {\\n \\\"relationship-list\\\" : {\\n \\\"relationship\\\" : [ {\\n \\\"related-to\\\" : \\\"model\\\",\\n \\\"relationship-data\\\" : [ {\\n \\\"relationship-key\\\" : \\\"model.model-invariant-id\\\",\\n \\\"relationship-value\\\" : \\\"ff69d4e0-a8e8-4108-bdb0-dd63217e63c7\\\"\\n } ]\\n } ]\\n }\\n }, {\\n \\\"relationship-list\\\" : {\\n \\\"relationship\\\" : [ {\\n \\\"related-to\\\" : \\\"model\\\",\\n \\\"relationship-data\\\" : [ {\\n \\\"relationship-key\\\" : \\\"model.model-invariant-id\\\",\\n \\\"relationship-value\\\" : \\\"fcec1b02-b2d0-4834-aef8-d71be04717dd\\\"\\n } ]\\n } ]\\n }\\n }, {\\n \\\"named-query-elements\\\" : {\\n \\\"named-query-element\\\" : [ {\\n \\\"relationship-list\\\" : {\\n \\\"relationship\\\" : [ {\\n \\\"related-to\\\" : \\\"model\\\",\\n \\\"relationship-data\\\" : [ {\\n \\\"relationship-key\\\" : \\\"model.model-invariant-id\\\",\\n \\\"relationship-value\\\" : \\\"1b2c9ba7-e449-4831-ba15-3073672f5ef2\\\"\\n } ]\\n } ]\\n }\\n } ]\\n },\\n \\\"relationship-list\\\" : {\\n \\\"relationship\\\" : [ {\\n \\\"related-to\\\" : \\\"model\\\",\\n \\\"relationship-data\\\" : [ {\\n \\\"relationship-key\\\" : \\\"model.model-invariant-id\\\",\\n \\\"relationship-value\\\" : \\\"3d560d81-57d0-438b-a2a1-5334dba0651a\\\"\\n } ]\\n } ]\\n }\\n } ]\\n },\\n \\\"relationship-list\\\" : {\\n \\\"relationship\\\" : [ {\\n \\\"related-to\\\" : \\\"model\\\",\\n \\\"relationship-data\\\" : [ {\\n \\\"relationship-key\\\" : \\\"model.model-invariant-id\\\",\\n \\\"relationship-value\\\" : \\\"ef86f9c5-2165-44f3-8fc3-96018b609ea5\\\"\\n } ]\\n } ]\\n }\\n } ]\\n },\\n \\\"relationship-list\\\" : {\\n \\\"relationship\\\" : [ {\\n \\\"related-to\\\" : \\\"model\\\",\\n \\\"relationship-data\\\" : [ {\\n \\\"relationship-key\\\" : \\\"model.model-invariant-id\\\",\\n \\\"relationship-value\\\" : \\\"acc6edd8-a8d4-4b93-afaa-0994068be14c\\\"\\n } ]\\n } ]\\n }\\n } ]\\n },\\n \\\"relationship-list\\\" : {\\n \\\"relationship\\\" : [ {\\n \\\"related-to\\\" : \\\"model\\\",\\n \\\"relationship-data\\\" : [ {\\n \\\"relationship-key\\\" : \\\"model.model-invariant-id\\\",\\n \\\"relationship-value\\\" : \\\"82194af1-3c2c-485a-8f44-420e22a9eaa4\\\"\\n } ]\\n } ]\\n }\\n } ]\\n }\\n}\\n\"\r\n" + + " },\r\n" + " \"description\": \"\"\r\n" + " },\r\n" + + " \"response\": []\r\n" + " }\r\n" + " ]\r\n" + "}"; } -- cgit 1.2.3-korg