From b4922d319d293894fddd512d29b5f0d1411915d9 Mon Sep 17 00:00:00 2001 From: ARULNA Date: Mon, 12 Jun 2017 16:41:12 -0400 Subject: Initial commit for AAI-UI(sparky-backend) Change-Id: I785397ed4197663cdf0c1351041d2f708ed08763 Signed-off-by: ARULNA --- .../dal/aai/config/ActiveInventoryConfigTest.java | 182 +++++++++++++ .../aai/config/ActiveInventoryRestConfigTest.java | 293 ++++++++++++++++++++ .../aai/config/ActiveInventorySslConfigTest.java | 268 +++++++++++++++++++ .../dal/elasticsearch/ElasticSearchConfigTest.java | 272 +++++++++++++++++++ .../entity/AutoSuggestDocumentEntity.java | 44 +++ .../entity/AutoSuggestDocumentEntityFields.java | 81 ++++++ .../entity/AutoSuggestElasticHitEntity.java | 87 ++++++ .../entity/AutoSuggestElasticHitsEntity.java | 50 ++++ .../entity/AutoSuggestElasticSearchResponse.java | 85 ++++++ .../dal/elasticsearch/entity/BucketEntity.java | 61 +++++ .../dal/elasticsearch/entity/ElasticHit.java | 29 ++ .../elasticsearch/entity/ElasticHitsEntity.java | 74 ++++++ .../entity/ElasticSearchAggegrationResponse.java | 109 ++++++++ .../entity/ElasticSearchAggregation.java | 74 ++++++ .../entity/ElasticSearchCountResponse.java | 60 +++++ .../dal/elasticsearch/entity/PayloadEntity.java | 32 +++ .../sparky/dal/rest/RestClientBuilderTest.java | 180 +++++++++++++ .../sparky/dal/rest/RestfulDataAccessorTest.java | 226 ++++++++++++++++ .../sparky/dal/sas/entity/DocumentEntity.java | 68 +++++ .../sparky/dal/sas/entity/EntityCountResponse.java | 55 ++++ .../dal/sas/entity/GroupByAggregationEntity.java | 60 +++++ .../entity/GroupByAggregationResponseEntity.java | 48 ++++ .../openecomp/sparky/dal/sas/entity/HitEntity.java | 48 ++++ .../sas/entity/SearchAbstractionEntityBuilder.java | 295 +++++++++++++++++++++ .../dal/sas/entity/SearchAbstractionResponse.java | 39 +++ .../sparky/dal/sas/entity/SearchResult.java | 49 ++++ 26 files changed, 2869 insertions(+) create mode 100644 src/test/java/org/openecomp/sparky/dal/aai/config/ActiveInventoryConfigTest.java create mode 100644 src/test/java/org/openecomp/sparky/dal/aai/config/ActiveInventoryRestConfigTest.java create mode 100644 src/test/java/org/openecomp/sparky/dal/aai/config/ActiveInventorySslConfigTest.java create mode 100644 src/test/java/org/openecomp/sparky/dal/elasticsearch/ElasticSearchConfigTest.java create mode 100644 src/test/java/org/openecomp/sparky/dal/elasticsearch/entity/AutoSuggestDocumentEntity.java create mode 100644 src/test/java/org/openecomp/sparky/dal/elasticsearch/entity/AutoSuggestDocumentEntityFields.java create mode 100644 src/test/java/org/openecomp/sparky/dal/elasticsearch/entity/AutoSuggestElasticHitEntity.java create mode 100644 src/test/java/org/openecomp/sparky/dal/elasticsearch/entity/AutoSuggestElasticHitsEntity.java create mode 100644 src/test/java/org/openecomp/sparky/dal/elasticsearch/entity/AutoSuggestElasticSearchResponse.java create mode 100644 src/test/java/org/openecomp/sparky/dal/elasticsearch/entity/BucketEntity.java create mode 100644 src/test/java/org/openecomp/sparky/dal/elasticsearch/entity/ElasticHit.java create mode 100644 src/test/java/org/openecomp/sparky/dal/elasticsearch/entity/ElasticHitsEntity.java create mode 100644 src/test/java/org/openecomp/sparky/dal/elasticsearch/entity/ElasticSearchAggegrationResponse.java create mode 100644 src/test/java/org/openecomp/sparky/dal/elasticsearch/entity/ElasticSearchAggregation.java create mode 100644 src/test/java/org/openecomp/sparky/dal/elasticsearch/entity/ElasticSearchCountResponse.java create mode 100644 src/test/java/org/openecomp/sparky/dal/elasticsearch/entity/PayloadEntity.java create mode 100644 src/test/java/org/openecomp/sparky/dal/rest/RestClientBuilderTest.java create mode 100644 src/test/java/org/openecomp/sparky/dal/rest/RestfulDataAccessorTest.java create mode 100644 src/test/java/org/openecomp/sparky/dal/sas/entity/DocumentEntity.java create mode 100644 src/test/java/org/openecomp/sparky/dal/sas/entity/EntityCountResponse.java create mode 100644 src/test/java/org/openecomp/sparky/dal/sas/entity/GroupByAggregationEntity.java create mode 100644 src/test/java/org/openecomp/sparky/dal/sas/entity/GroupByAggregationResponseEntity.java create mode 100644 src/test/java/org/openecomp/sparky/dal/sas/entity/HitEntity.java create mode 100644 src/test/java/org/openecomp/sparky/dal/sas/entity/SearchAbstractionEntityBuilder.java create mode 100644 src/test/java/org/openecomp/sparky/dal/sas/entity/SearchAbstractionResponse.java create mode 100644 src/test/java/org/openecomp/sparky/dal/sas/entity/SearchResult.java (limited to 'src/test/java/org/openecomp/sparky/dal') diff --git a/src/test/java/org/openecomp/sparky/dal/aai/config/ActiveInventoryConfigTest.java b/src/test/java/org/openecomp/sparky/dal/aai/config/ActiveInventoryConfigTest.java new file mode 100644 index 0000000..24cb405 --- /dev/null +++ b/src/test/java/org/openecomp/sparky/dal/aai/config/ActiveInventoryConfigTest.java @@ -0,0 +1,182 @@ +package org.openecomp.sparky.dal.aai.config; + + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import java.util.Properties; + +import org.junit.Before; +import org.junit.Test; +import org.openecomp.sparky.dal.aai.enums.RestAuthenticationMode; +import org.openecomp.sparky.synchronizer.config.TaskProcessorConfig; + +public class ActiveInventoryConfigTest { + + /** + * Test case initialization + * + * @throws Exception the exception + */ + @Before + public void init() throws Exception {} + + @Test + public void validateBasicConstruction_emptyProperties() throws Exception { + + ActiveInventoryConfig config = new ActiveInventoryConfig(getTestProperties()); + + 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,att-aic,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(); + ActiveInventorySslConfig sslConfig = config.getAaiSslConfig(); + TaskProcessorConfig tpc = config.getTaskProcessorConfig(); + + assertNotNull(airc); + assertNotNull(sslConfig); + assertNotNull(tpc); + + assertEquals("https://aai-host:8443/aai/v10", config.getBaseUri().toString()); + + assertTrue(config.toString().contains("ActiveInventoryConfig")); + + config.setAaiRestConfig(null); + config.setAaiSslConfig(null); + config.setTaskProcessorConfig(null); + + assertNull(config.getAaiRestConfig()); + assertNull(config.getAaiSslConfig()); + assertNull(config.getTaskProcessorConfig()); + + config.setAaiRestConfig(airc); + config.setAaiSslConfig(sslConfig); + config.setTaskProcessorConfig(tpc); + + + } + + @Test + public void validateRepairSelfLink_nullLink() throws Exception { + + ActiveInventoryConfig config = new ActiveInventoryConfig(getTestProperties()); + + ActiveInventoryRestConfig restConfig = config.getAaiRestConfig(); + + restConfig.setAuthenticationMode(RestAuthenticationMode.UNKNOWN_MODE); + restConfig.setHost("aai-host"); + restConfig.setPort("9191"); + + assertNull(config.repairSelfLink(null)); + } + + @Test + public void validateRepairSelfLink_emptyString() throws Exception { + + ActiveInventoryConfig config = new ActiveInventoryConfig(getTestProperties()); + + ActiveInventoryRestConfig restConfig = config.getAaiRestConfig(); + + restConfig.setAuthenticationMode(RestAuthenticationMode.UNKNOWN_MODE); + restConfig.setHost("aai-host"); + restConfig.setPort("9191"); + + assertEquals("http://aai-host:9191", config.repairSelfLink("")); + } + + @Test + public void validateRepairSelfLink_withResourceUrl() throws Exception { + + ActiveInventoryConfig config = new ActiveInventoryConfig(getTestProperties()); + + ActiveInventoryRestConfig restConfig = config.getAaiRestConfig(); + + restConfig.setAuthenticationMode(RestAuthenticationMode.SSL_CERT); + restConfig.setHost("aai-host"); + restConfig.setPort("9191"); + + assertEquals("https://aai-host:9191/aai/v10/business/customers/customer/1234", + config.repairSelfLink("/aai/v10/business/customers/customer/1234")); + } +} \ No newline at end of file diff --git a/src/test/java/org/openecomp/sparky/dal/aai/config/ActiveInventoryRestConfigTest.java b/src/test/java/org/openecomp/sparky/dal/aai/config/ActiveInventoryRestConfigTest.java new file mode 100644 index 0000000..e1421c4 --- /dev/null +++ b/src/test/java/org/openecomp/sparky/dal/aai/config/ActiveInventoryRestConfigTest.java @@ -0,0 +1,293 @@ +/* +* ============LICENSE_START======================================================= +* SPARKY (AAI UI service) +* ================================================================================ +* Copyright © 2017 AT&T Intellectual Property. +* Copyright © 2017 Amdocs +* All rights reserved. +* ================================================================================ +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* ============LICENSE_END========================================================= +* +* ECOMP and OpenECOMP are trademarks +* and service marks of AT&T Intellectual Property. +*/ + +package org.openecomp.sparky.dal.aai.config; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import java.util.ArrayList; +import java.util.List; +import java.util.Properties; + +import org.junit.Before; +import org.junit.Test; +import org.openecomp.sparky.dal.aai.enums.RestAuthenticationMode; + + +public class ActiveInventoryRestConfigTest { + + /** + * Test case initialization + * + * @throws Exception the exception + */ + @Before + public void init() throws Exception {} + + private Properties buildExpectedPropertyDefinition() throws Exception { + + Properties props = new Properties(); + + props.put("aai.rest.resourceBasePath", "/aai/v9"); + props.put("aai.rest.host", "1.2.3.4"); + props.put("aai.rest.port", "4321"); + props.put("aai.rest.numRequestRetries", "100"); + props.put("aai.rest.numResolverWorkers", "50"); + props.put("aai.rest.maxConcurrentWorkers", "50"); + props.put("aai.rest.connectTimeoutInMs", "1000"); + props.put("aai.rest.readTimeoutInMs", "1500"); + props.put("aai.rest.shallowEntities", "a,b,c,d"); + props.put("aai.rest.authenticationMode", "HTTP_NOAUTH"); + + props.put("aai.rest.cache.enabled", "true"); + props.put("aai.rest.cache.storageFolderOverride", "folderOverride"); + props.put("aai.rest.cache.cacheFailures", "true"); + props.put("aai.rest.cache.useCacheOnly", "true"); + props.put("aai.rest.cache.numWorkers", "50"); + props.put("aai.rest.cache.maxTimeToLiveInMs", "500"); + + + return props; + } + + /** + * Success path initialization and validation of accessors + * + * @throws Exception + */ + @Test + public void successfulInitialization() throws Exception { + + ActiveInventoryRestConfig config = + new ActiveInventoryRestConfig(buildExpectedPropertyDefinition()); + + /* + * Now verify that all the internal members have been set to default values + */ + + assertEquals(config.getResourceBasePath(), "/aai/v9"); + assertEquals(config.getHost(), "1.2.3.4"); + assertEquals(config.getPort(), "4321"); + assertEquals(config.getNumRequestRetries(), 100); + assertEquals(config.getNumResolverWorkers(), 50); + assertEquals(config.getConnectTimeoutInMs(), 1000); + assertEquals(config.getReadTimeoutInMs(), 1500); + + List expectedEntities = new ArrayList(); + expectedEntities.add("a"); + expectedEntities.add("b"); + expectedEntities.add("c"); + expectedEntities.add("d"); + + assertEquals(config.getShallowEntities().size(), 4); + assertTrue(config.getShallowEntities().containsAll(expectedEntities)); + assertEquals(config.getAuthenticationMode(), RestAuthenticationMode.HTTP_NOAUTH); + + assertTrue(config.isCacheEnabled()); + assertEquals(config.getStorageFolderOverride(), "folderOverride"); + assertTrue(config.shouldCacheFailures()); + assertTrue(config.isUseCacheOnly()); + assertEquals(config.getNumCacheWorkers(), 50); + assertEquals(config.getMaxTimeToLiveInMs(), 500); + + + } + + /** + * Failed path initialization + * + * @throws Exception + */ + @Test + public void validateInitializationWithNullProperties() throws Exception { + + /* + * Setup encryptor expectations + */ + + ActiveInventoryRestConfig config = new ActiveInventoryRestConfig(null); + + /* + * Now verify that all the internal members have been set to default values + */ + + assertNull(config.getResourceBasePath()); + assertNull(config.getHost()); + assertNull(config.getPort()); + assertEquals(config.getNumRequestRetries(), 0); + assertEquals(config.getNumResolverWorkers(), 0); + assertEquals(config.getConnectTimeoutInMs(), 0); + assertEquals(config.getReadTimeoutInMs(), 0); + + assertNull(config.getShallowEntities()); + assertNull(config.getAuthenticationMode()); + + assertFalse(config.isCacheEnabled()); + assertNull(config.getStorageFolderOverride()); + assertFalse(config.shouldCacheFailures()); + assertFalse(config.isUseCacheOnly()); + assertEquals(config.getNumCacheWorkers(), 0); + assertEquals(config.getMaxTimeToLiveInMs(), 0); + + } + + /** + * Failed path initialization + * + * @throws Exception + */ + @Test + public void validateInitializationWithInvalidProperties() throws Exception { + + /* + * Setup encryptor expectations + */ + + ActiveInventoryRestConfig config = new ActiveInventoryRestConfig(new Properties()); + + /* + * Now verify that all the internal members have been set to default values + */ + + assertEquals(config.getResourceBasePath(), "/aai/v7"); + assertEquals(config.getHost(), "localhost"); + assertEquals(config.getPort(), "8443"); + assertEquals(config.getNumRequestRetries(), 5); + assertEquals(config.getNumResolverWorkers(), 15); + assertEquals(config.getConnectTimeoutInMs(), 5000); + assertEquals(config.getReadTimeoutInMs(), 10000); + + assertEquals(config.getShallowEntities().size(), 1); + assertEquals(config.getAuthenticationMode(), RestAuthenticationMode.SSL_CERT); + + assertFalse(config.isCacheEnabled()); + assertNull(config.getStorageFolderOverride()); + assertFalse(config.shouldCacheFailures()); + assertFalse(config.isUseCacheOnly()); + assertEquals(config.getNumCacheWorkers(), 5); + assertEquals(config.getMaxTimeToLiveInMs(), -1); + + } + + /** + * Class accessor validator + * + * @throws Exception + */ + @Test + public void validateClassAccessors() throws Exception { + + /* + * Setup encryptor expectations + */ + + ActiveInventoryRestConfig config = + new ActiveInventoryRestConfig(buildExpectedPropertyDefinition()); + + /* + * Now verify that all the internal members have been set to default values + */ + + config.setAuthenticationMode(RestAuthenticationMode.SSL_BASIC); + config.setCacheEnabled(true); + config.setConnectTimeoutInMs(1000); + config.setHost("myhost"); + config.setMaxTimeToLiveInMs(1234); + config.setNumCacheWorkers(1000); + config.setNumRequestRetries(1500); + config.setNumResolverWorkers(150); + config.setPort("11223344"); + config.setReadTimeoutInMs(54321); + config.setResourceBasePath("/aai/v21"); + config.setStorageFolderOverride("override"); + config.setUseCacheOnly(true); + config.setShouldCacheFailures(true); + + assertEquals(config.getResourceBasePath(), "/aai/v21"); + assertEquals(config.getHost(), "myhost"); + assertEquals(config.getPort(), "11223344"); + assertEquals(config.getNumRequestRetries(), 1500); + assertEquals(config.getNumResolverWorkers(), 150); + assertEquals(config.getConnectTimeoutInMs(), 1000); + assertEquals(config.getReadTimeoutInMs(), 54321); + assertTrue(config.shouldCacheFailures()); + + List expectedEntities = new ArrayList(); + expectedEntities.add("a"); + expectedEntities.add("b"); + expectedEntities.add("c"); + expectedEntities.add("d"); + + assertEquals(config.getShallowEntities().size(), 4); + assertTrue(config.getShallowEntities().containsAll(expectedEntities)); + assertTrue(config.isShallowEntity("b")); + assertFalse(config.isShallowEntity("f")); + assertFalse(config.isShallowEntity(null)); + assertEquals(config.getAuthenticationMode(), RestAuthenticationMode.SSL_BASIC); + + assertTrue(config.isCacheEnabled()); + assertEquals(config.getStorageFolderOverride(), "override"); + assertTrue(config.shouldCacheFailures()); + assertTrue(config.isUseCacheOnly()); + assertEquals(config.getNumCacheWorkers(), 1000); + assertEquals(config.getMaxTimeToLiveInMs(), 1234); + + assertTrue(config.toString().contains("ActiveInventoryRestConfig")); + + } + + + /** + * Validate auth mode edge cases + * + * @throws Exception + */ + @Test + public void validateUnknownAuthModeDefaultsToSslCert() throws Exception { + + /* + * Setup encryptor expectations + */ + + Properties props = buildExpectedPropertyDefinition(); + props.setProperty("aai.rest.authenticationMode", "invalid mode"); + props.setProperty("aai.rest.storageFolderOverride", ""); + + ActiveInventoryRestConfig config = new ActiveInventoryRestConfig(props); + + /* + * Now verify that all the internal members have been set to default values + */ + + assertNotNull(config.getShallowEntities()); + assertEquals(RestAuthenticationMode.SSL_CERT, config.getAuthenticationMode()); + + } + +} diff --git a/src/test/java/org/openecomp/sparky/dal/aai/config/ActiveInventorySslConfigTest.java b/src/test/java/org/openecomp/sparky/dal/aai/config/ActiveInventorySslConfigTest.java new file mode 100644 index 0000000..834bbd1 --- /dev/null +++ b/src/test/java/org/openecomp/sparky/dal/aai/config/ActiveInventorySslConfigTest.java @@ -0,0 +1,268 @@ +/* +* ============LICENSE_START======================================================= +* SPARKY (inventory UI service) +* ================================================================================ +* Copyright © 2017 AT&T Intellectual Property. +* Copyright © 2017 Amdocs +* All rights reserved. +* ================================================================================ +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* ============LICENSE_END========================================================= +* +* ECOMP and OpenECOMP are trademarks +* and service marks of AT&T Intellectual Property. +*/ + +package org.openecomp.sparky.dal.aai.config; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import java.util.Properties; + +import org.eclipse.jetty.util.security.Password; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; +import org.openecomp.sparky.util.Encryptor; + +//import com.att.aai.util.EncryptedConfiguration; + +public class ActiveInventorySslConfigTest { + + private Encryptor encryptorMock = Mockito.mock(Encryptor.class); + + /** + * Test case initialization + * + * @throws Exception the exception + */ + @Before + public void init() throws Exception { + System.setProperty("javax.net.debug", "invalid"); + } + + private Properties buildExpectedPropertyDefinition() throws Exception { + Encryptor encryptor = new Encryptor(); + Properties props = new Properties(); + + props.put("aai.ssl.enableDebug", "false"); + props.put("aai.ssl.validateServerHostName", "false"); + 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.truststore.type", "jks"); + props.put("aai.ssl.truststore.filename", "/opt/app/applocal/etc/cert.crt"); + props.put("aai.ssl.basicAuth.username", "username"); + props.put("aai.ssl.basicAuth.password", Password.obfuscate("password")); + + return props; + } + + private Properties buildInvalidPropertyDefinition() { + Properties props = new Properties(); + + props.put("aai.ssl.enableDebug", "true"); + props.put("aai.ssl.validateServerHostName", "invalid"); + props.put("aai.ssl.validateServiceCertificateChain", "invalid"); + props.put("aai.ssl.keystore.type", "invalid"); + // props.put("aai.ssl.keystore.filename", ); + props.put("aai.ssl.keystore.pass", "invalid"); + props.put("aai.ssl.truststore.type", "invalid"); + // props.put("aai.ssl.truststore.filename", "/opt/app/applocal/etc/cert.crt"); + props.put("aai.ssl.basicAuth.username", "invalid"); + props.put("aai.ssl.basicAuth.password", "invalid"); + + return props; + } + + private String generateAuthorizationHeaderValue(String username, String password) { + String usernameAndPassword = username + ":" + password; + return "Basic " + java.util.Base64.getEncoder().encodeToString(usernameAndPassword.getBytes()); + } + + /** + * Success path initialization and validation of accessors + * + * @throws Exception + */ + @Test + public void successfulInitialization() throws Exception { + + /* + * Setup encryptor expectations + */ + Mockito.when(encryptorMock.decryptValue(Mockito.anyString())).thenReturn("password"); + + ActiveInventorySslConfig config = + new ActiveInventorySslConfig(buildExpectedPropertyDefinition(), encryptorMock); + + /* + * Now verify that all the internal members have been set to default values + */ + + assertEquals(System.getProperty("javax.net.debug"), ""); + assertFalse(config.isValidateServerHostName()); + assertFalse(config.isValidateServerCertificateChain()); + + assertEquals(config.getKeystoreType(), "pkcs12"); + assertTrue(config.getKeystoreFilename().contains("/opt/app/applocal/etc/cert.crt")); + assertEquals(config.getKeystorePassword(), "password"); + + assertEquals(config.getTruststoreType(), "jks"); + assertTrue(config.getTruststoreFilename().contains("/opt/app/applocal/etc/cert.crt")); + + assertEquals(config.getBasicAuthUsername(), "username"); + assertEquals(config.getBasicAuthPassword(), "password"); + assertEquals(config.getBasicAuthenticationCredentials(), + generateAuthorizationHeaderValue("username", "password")); + + } + + /** + * Failed path initialization + * + * @throws Exception + */ + @Test + public void validateInitializationWithNullProperties() throws Exception { + + /* + * Setup encryptor expectations + */ + Mockito.when(encryptorMock.decryptValue(Mockito.anyString())).thenReturn(""); + + ActiveInventorySslConfig config = new ActiveInventorySslConfig(null, encryptorMock); + + /* + * Now verify that all the internal members have been set to default values + */ + + assertEquals(System.getProperty("javax.net.debug"), "invalid"); + assertFalse(config.isValidateServerHostName()); + assertFalse(config.isValidateServerCertificateChain()); + + assertNull(config.getKeystoreType()); + assertNull(config.getKeystoreFilename()); + assertNull(config.getKeystorePassword()); + + assertNull(config.getTruststoreType()); + assertNull(config.getTruststoreFilename()); + + assertNull(config.getBasicAuthUsername()); + assertNull(config.getBasicAuthPassword()); + assertEquals(config.getBasicAuthenticationCredentials(), + generateAuthorizationHeaderValue("null", "null")); + + } + + /** + * Failed path initialization + * + * @throws Exception + */ + @Test + public void validateInitializationWithInvalidProperties() throws Exception { + + /* + * Setup encryptor expectations + */ + Mockito.when(encryptorMock.decryptValue(Mockito.anyString())).thenReturn(""); + + ActiveInventorySslConfig config = + new ActiveInventorySslConfig(buildInvalidPropertyDefinition(), encryptorMock); + + /* + * Now verify that all the internal members have been set to default values + */ + + assertEquals(System.getProperty("javax.net.debug"), "ssl"); + assertFalse(config.isValidateServerHostName()); + assertFalse(config.isValidateServerCertificateChain()); + + assertEquals(config.getKeystoreType(),"invalid"); + assertTrue(config.getKeystoreFilename().contains("null")); + assertEquals(config.getKeystorePassword(),""); + + assertEquals(config.getTruststoreType(),"invalid"); + assertTrue(config.getTruststoreFilename().contains("null")); + + assertEquals(config.getBasicAuthUsername(),"invalid"); + assertEquals(config.getBasicAuthPassword(),"invalid"); + assertEquals(config.getBasicAuthenticationCredentials(), + generateAuthorizationHeaderValue("invalid", "invalid")); + + } + + /** + * Class accessor validator + * + * @throws Exception + */ + @Test + public void validateClassAccessors() throws Exception { + + /* + * Setup encryptor expectations + */ + Mockito.when(encryptorMock.decryptValue(Mockito.anyString())).thenReturn("password"); + + ActiveInventorySslConfig config = + new ActiveInventorySslConfig(buildInvalidPropertyDefinition(), encryptorMock); + + /* + * Now verify that all the internal members have been set to default values + */ + + config.setBasicAuthPassword("test"); + config.setBasicAuthUsername("test"); + config.setKeystoreFilename("test"); + config.setKeystorePassword("test"); + config.setKeystoreType("test"); + config.setTruststoreFilename("test"); + config.setTruststoreType("test"); + 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"); + assertTrue(config.getKeystoreFilename().contains("test")); + assertEquals(config.getKeystorePassword(),"test"); + + assertEquals(config.getTruststoreType(),"test"); + assertTrue(config.getTruststoreFilename().contains("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/openecomp/sparky/dal/elasticsearch/ElasticSearchConfigTest.java b/src/test/java/org/openecomp/sparky/dal/elasticsearch/ElasticSearchConfigTest.java new file mode 100644 index 0000000..c9d071f --- /dev/null +++ b/src/test/java/org/openecomp/sparky/dal/elasticsearch/ElasticSearchConfigTest.java @@ -0,0 +1,272 @@ +/* +* ============LICENSE_START======================================================= +* SPARKY (AAI UI service) +* ================================================================================ +* Copyright © 2017 AT&T Intellectual Property. +* Copyright © 2017 Amdocs +* All rights reserved. +* ================================================================================ +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* ============LICENSE_END========================================================= +* +* ECOMP and OpenECOMP are trademarks +* and service marks of AT&T Intellectual Property. +*/ + +package org.openecomp.sparky.dal.elasticsearch; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; + +import java.io.File; +import java.io.IOException; + +import javax.servlet.ServletException; + +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; +import org.mockito.Mockito; +import org.openecomp.sparky.dal.elasticsearch.config.ElasticSearchConfig; +import org.openecomp.sparky.dal.exception.ElasticSearchOperationException; + + +import ch.qos.logback.classic.Level; + +/** + * The Class ElasticSearchConfigTest. + */ +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\"}" + "}" + "}"; + + 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\"]}}}}"; + + 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\"]}}"; + + /** + * Inits the. + * + * @throws Exception the exception + */ + @Before + public void init() throws Exception { + } + + /** + * Failure to initialize properties results in config defaults. + */ + @Test + public void failureToInitializePropertiesResultsInConfigDefaults() { + try { + ElasticSearchConfig config = ElasticSearchConfig.getConfig(); + + /* + * Now verify that all the internal members have been set to default values + */ + + assertEquals(config.getIpAddress(), "localhost"); + assertEquals(config.getHttpPort(), "" + 9200); + assertEquals(config.getJavaApiPort(), "" + 9300); + assertEquals(config.getIndexName(), "entitySearchIndex"); + assertEquals(config.getType(), "aaiEntities"); + assertEquals(config.getClusterName(), "elasticsearch"); + assertEquals(config.getMappingsFileName(), null); + assertEquals(config.getSettingsFileName(), null); + assertEquals(config.getAuditIndexName(), "auditdataindex"); + + } catch (Exception exc) { + assertEquals("null", exc.getLocalizedMessage()); + } + } + + + /** + * Validate accessors. + * + * @throws IOException Signals that an I/O exception has occurred. + * @throws ServletException the servlet exception + * @throws Exception the exception + */ + @Test + public void validateAccessors() throws IOException, ServletException, Exception { + + ElasticSearchConfig esConfig = new ElasticSearchConfig(); + + esConfig.setIpAddress("47.248.10.127"); + esConfig.setHttpPort("8123"); + esConfig.setJavaApiPort("9123"); + esConfig.setIndexName("myIndexName"); + esConfig.setType("myIndexTableType"); + esConfig.setClusterName("ES_AAI_DEV"); + esConfig.setMappingsFileName("d:\\1\\mappings.json"); + esConfig.setSettingsFileName("d:\\1\\settings.json"); + esConfig.setAuditIndexName("auditIndexName"); + + ElasticSearchConfig.setConfig(esConfig); + + assertEquals(esConfig.getIpAddress(), "47.248.10.127"); + assertEquals(esConfig.getHttpPort(), "8123"); + assertEquals(esConfig.getJavaApiPort(), "9123"); + assertEquals(esConfig.getIndexName(), "myIndexName"); + assertEquals(esConfig.getType(), "myIndexTableType"); + assertEquals(esConfig.getClusterName(), "ES_AAI_DEV"); + assertEquals(esConfig.getMappingsFileName(), "d:\\1\\mappings.json"); + assertEquals(esConfig.getSettingsFileName(), "d:\\1\\settings.json"); + assertEquals(esConfig.getAuditIndexName(), "auditIndexName"); + + String output = esConfig.toString(); + + assertNotEquals(output, null); + + } + + /** + * Gets the elastic search settings expect valid config. + * + * @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 + */ + @Ignore + public void getElasticSearchSettings_expectValidConfig() + throws IOException, ElasticSearchOperationException { + System.setProperty("AJSC_HOME", new File(".").getCanonicalPath().replace('\\', '/')); + + ElasticSearchConfig esConfig = new ElasticSearchConfig(); + + esConfig.setSettingsFileName("src/main/config/es_settings.json"); + + assertNotNull(esConfig.getElasticSearchSettings()); + } + + /** + * Gets the elastic search settings expect file not found exception. + * + * @return the elastic search settings expect file not found exception + * @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 + */ + @Ignore + public void getElasticSearchSettings_expectFileNotFoundException() + throws IOException, ElasticSearchOperationException { + System.setProperty("AJSC_HOME", new File(".").getCanonicalPath().replace('\\', '/')); + + ElasticSearchConfig esConfig = new ElasticSearchConfig(); + + esConfig.setSettingsFileName("src/main/config/es_setting.json"); + + esConfig.getElasticSearchSettings(); + + } + + /** + * Gets the elastic search mappings expect valid config. + * + * @return the elastic search mappings 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 + */ + @Ignore + public void getElasticSearchMappings_expectValidConfig() + throws IOException, ElasticSearchOperationException { + System.setProperty("AJSC_HOME", new File(".").getCanonicalPath().replace('\\', '/')); + + ElasticSearchConfig esConfig = new ElasticSearchConfig(); + + esConfig.setMappingsFileName("src/main/config/es_mappings.json"); + + assertNotNull(esConfig.getElasticSearchMappings()); + } + + /** + * Gets the elastic search mappings expect file not found exception. + * + * @return the elastic search mappings expect file not found exception + * @throws IOException Signals that an I/O exception has occurred. + * @throws ElasticSearchOperationException the elastic search operation exception + */ + @Test(expected = ElasticSearchOperationException.class) + public void getElasticSearchMappings_expectFileNotFoundException() + throws IOException, ElasticSearchOperationException { + System.setProperty("AJSC_HOME", new File(".").getCanonicalPath().replace('\\', '/')); + + ElasticSearchConfig esConfig = new ElasticSearchConfig(); + + esConfig.setSettingsFileName("src/main/config/es_setting.json"); + + esConfig.getElasticSearchMappings(); + + } + + /** + * Builds the elastic search table config expect valid result. + * + * @throws ElasticSearchOperationException the elastic search operation exception + * @throws IOException Signals that an I/O exception has occurred. + */ + @Test + public void buildElasticSearchTableConfig_expectValidResult() + 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(); + Mockito.doReturn("myIndexTableType").when(spyEsConfig).getType(); + + assertNotNull(spyEsConfig.buildElasticSearchTableConfig()); + } + + /** + * Builds the elastic search table config expect exception. + * + * @throws ElasticSearchOperationException the elastic search operation exception + * @throws IOException Signals that an I/O exception has occurred. + */ + @Test(expected = ElasticSearchOperationException.class) + public void buildElasticSearchTableConfig_expectException() + 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(); + Mockito.doReturn("myIndexTableType").when(spyEsConfig).getType(); + + spyEsConfig.buildElasticSearchTableConfig(); + } + +} diff --git a/src/test/java/org/openecomp/sparky/dal/elasticsearch/entity/AutoSuggestDocumentEntity.java b/src/test/java/org/openecomp/sparky/dal/elasticsearch/entity/AutoSuggestDocumentEntity.java new file mode 100644 index 0000000..b3abd14 --- /dev/null +++ b/src/test/java/org/openecomp/sparky/dal/elasticsearch/entity/AutoSuggestDocumentEntity.java @@ -0,0 +1,44 @@ +/* +* ============LICENSE_START======================================================= +* SPARKY (inventory UI service) +* ================================================================================ +* Copyright © 2017 AT&T Intellectual Property. +* Copyright © 2017 Amdocs +* All rights reserved. +* ================================================================================ +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* ============LICENSE_END========================================================= +* +* ECOMP and OpenECOMP are trademarks +* and service marks of AT&T Intellectual Property. +*/ +package org.openecomp.sparky.dal.elasticsearch.entity; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public class AutoSuggestDocumentEntity { + + @JsonProperty("entity_suggest") + AutoSuggestDocumentEntityFields fields; + + public AutoSuggestDocumentEntityFields getFields() { + return fields; + } + + public void setFields(AutoSuggestDocumentEntityFields fields) { + this.fields = fields; + } + + + +} diff --git a/src/test/java/org/openecomp/sparky/dal/elasticsearch/entity/AutoSuggestDocumentEntityFields.java b/src/test/java/org/openecomp/sparky/dal/elasticsearch/entity/AutoSuggestDocumentEntityFields.java new file mode 100644 index 0000000..db0dc8c --- /dev/null +++ b/src/test/java/org/openecomp/sparky/dal/elasticsearch/entity/AutoSuggestDocumentEntityFields.java @@ -0,0 +1,81 @@ +/* +* ============LICENSE_START======================================================= +* SPARKY (inventory UI service) +* ================================================================================ +* Copyright © 2017 AT&T Intellectual Property. +* Copyright © 2017 Amdocs +* All rights reserved. +* ================================================================================ +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* ============LICENSE_END========================================================= +* +* ECOMP and OpenECOMP are trademarks +* and service marks of AT&T Intellectual Property. +*/ +package org.openecomp.sparky.dal.elasticsearch.entity; + +import java.util.ArrayList; +import java.util.List; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonInclude.Include; + +@JsonInclude(Include.NON_NULL) +public class AutoSuggestDocumentEntityFields { + + private String output; + private List input; + private PayloadEntity payload; + private int weight; + + public AutoSuggestDocumentEntityFields() { + input = new ArrayList(); + } + + public String getOutput() { + return output; + } + + public void setOutput(String output) { + this.output = output; + } + + public List getInput() { + return input; + } + + public void setInput(List input) { + this.input = input; + } + + public PayloadEntity getPayload() { + return payload; + } + + public void setPayload(PayloadEntity payload) { + this.payload = payload; + } + + public int getWeight() { + return weight; + } + + public void setWeight(int weight) { + this.weight = weight; + } + + public void addInput(String input) { + this.input.add(input); + } + +} diff --git a/src/test/java/org/openecomp/sparky/dal/elasticsearch/entity/AutoSuggestElasticHitEntity.java b/src/test/java/org/openecomp/sparky/dal/elasticsearch/entity/AutoSuggestElasticHitEntity.java new file mode 100644 index 0000000..60ac538 --- /dev/null +++ b/src/test/java/org/openecomp/sparky/dal/elasticsearch/entity/AutoSuggestElasticHitEntity.java @@ -0,0 +1,87 @@ +/* +* ============LICENSE_START======================================================= +* SPARKY (inventory UI service) +* ================================================================================ +* Copyright © 2017 AT&T Intellectual Property. +* Copyright © 2017 Amdocs +* All rights reserved. +* ================================================================================ +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* ============LICENSE_END========================================================= +* +* ECOMP and OpenECOMP are trademarks +* and service marks of AT&T Intellectual Property. +*/ +package org.openecomp.sparky.dal.elasticsearch.entity; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public class AutoSuggestElasticHitEntity { + + @JsonProperty("_index") + private String index; + + @JsonProperty("_type") + private String type; + + @JsonProperty("_id") + private String id; + + @JsonProperty("_score") + private String score; + + @JsonProperty("_source") + private AutoSuggestDocumentEntity source; + + public String getIndex() { + return index; + } + + public void setIndex(String index) { + this.index = index; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getScore() { + return score; + } + + public void setScore(String score) { + this.score = score; + } + + public AutoSuggestDocumentEntity getSource() { + return source; + } + + public void setSource(AutoSuggestDocumentEntity source) { + this.source = source; + } + + +} diff --git a/src/test/java/org/openecomp/sparky/dal/elasticsearch/entity/AutoSuggestElasticHitsEntity.java b/src/test/java/org/openecomp/sparky/dal/elasticsearch/entity/AutoSuggestElasticHitsEntity.java new file mode 100644 index 0000000..af74485 --- /dev/null +++ b/src/test/java/org/openecomp/sparky/dal/elasticsearch/entity/AutoSuggestElasticHitsEntity.java @@ -0,0 +1,50 @@ +/* +* ============LICENSE_START======================================================= +* SPARKY (inventory UI service) +* ================================================================================ +* Copyright © 2017 AT&T Intellectual Property. +* Copyright © 2017 Amdocs +* All rights reserved. +* ================================================================================ +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* ============LICENSE_END========================================================= +* +* ECOMP and OpenECOMP are trademarks +* and service marks of AT&T Intellectual Property. +*/ +package org.openecomp.sparky.dal.elasticsearch.entity; + +import java.util.ArrayList; +import java.util.List; + +public class AutoSuggestElasticHitsEntity { + + private List hits; + + public AutoSuggestElasticHitsEntity() { + hits = new ArrayList(); + } + + public List getHits() { + return hits; + } + + public void setHits(List hits) { + this.hits = hits; + } + + public void addHit(AutoSuggestElasticHitEntity hit) { + this.hits.add(hit); + } + +} diff --git a/src/test/java/org/openecomp/sparky/dal/elasticsearch/entity/AutoSuggestElasticSearchResponse.java b/src/test/java/org/openecomp/sparky/dal/elasticsearch/entity/AutoSuggestElasticSearchResponse.java new file mode 100644 index 0000000..9b6c9f5 --- /dev/null +++ b/src/test/java/org/openecomp/sparky/dal/elasticsearch/entity/AutoSuggestElasticSearchResponse.java @@ -0,0 +1,85 @@ +/* +* ============LICENSE_START======================================================= +* SPARKY (inventory UI service) +* ================================================================================ +* Copyright © 2017 AT&T Intellectual Property. +* Copyright © 2017 Amdocs +* All rights reserved. +* ================================================================================ +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* ============LICENSE_END========================================================= +* +* ECOMP and OpenECOMP are trademarks +* and service marks of AT&T Intellectual Property. +*/ +package org.openecomp.sparky.dal.elasticsearch.entity; + +import java.util.HashMap; +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 AutoSuggestElasticHitsEntity hits; + + public AutoSuggestElasticSearchResponse(){ + this.shards = new HashMap(); + } + + public int getTook() { + return took; + } + + public void setTook(int took) { + this.took = took; + } + + public boolean isTimedOut() { + return timedOut; + } + + public void setTimedOut(boolean timedOut) { + this.timedOut = timedOut; + } + + public Map getShards() { + return shards; + } + + public void setShards(Map shards) { + this.shards = shards; + } + + public void addShard(String name, String value) { + shards.put(name, value); + } + + public AutoSuggestElasticHitsEntity getHits() { + return hits; + } + + public void setHits(AutoSuggestElasticHitsEntity hits) { + this.hits = hits; + } + + +} diff --git a/src/test/java/org/openecomp/sparky/dal/elasticsearch/entity/BucketEntity.java b/src/test/java/org/openecomp/sparky/dal/elasticsearch/entity/BucketEntity.java new file mode 100644 index 0000000..0a1a133 --- /dev/null +++ b/src/test/java/org/openecomp/sparky/dal/elasticsearch/entity/BucketEntity.java @@ -0,0 +1,61 @@ +/* +* ============LICENSE_START======================================================= +* SPARKY (inventory UI service) +* ================================================================================ +* Copyright © 2017 AT&T Intellectual Property. +* Copyright © 2017 Amdocs +* All rights reserved. +* ================================================================================ +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* ============LICENSE_END========================================================= +* +* ECOMP and OpenECOMP are trademarks +* and service marks of AT&T Intellectual Property. +*/ +package org.openecomp.sparky.dal.elasticsearch.entity; + +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; + } + + public void setKey(String key) { + this.key = key; + } + + public int getDocCount() { + return docCount; + } + + public void setDocCount(int docCount) { + this.docCount = docCount; + } + + +} diff --git a/src/test/java/org/openecomp/sparky/dal/elasticsearch/entity/ElasticHit.java b/src/test/java/org/openecomp/sparky/dal/elasticsearch/entity/ElasticHit.java new file mode 100644 index 0000000..32dc17a --- /dev/null +++ b/src/test/java/org/openecomp/sparky/dal/elasticsearch/entity/ElasticHit.java @@ -0,0 +1,29 @@ +/* +* ============LICENSE_START======================================================= +* SPARKY (inventory UI service) +* ================================================================================ +* Copyright © 2017 AT&T Intellectual Property. +* Copyright © 2017 Amdocs +* All rights reserved. +* ================================================================================ +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* ============LICENSE_END========================================================= +* +* ECOMP and OpenECOMP are trademarks +* and service marks of AT&T Intellectual Property. +*/ +package org.openecomp.sparky.dal.elasticsearch.entity; + +public class ElasticHit { + +} diff --git a/src/test/java/org/openecomp/sparky/dal/elasticsearch/entity/ElasticHitsEntity.java b/src/test/java/org/openecomp/sparky/dal/elasticsearch/entity/ElasticHitsEntity.java new file mode 100644 index 0000000..b10532e --- /dev/null +++ b/src/test/java/org/openecomp/sparky/dal/elasticsearch/entity/ElasticHitsEntity.java @@ -0,0 +1,74 @@ +/* +* ============LICENSE_START======================================================= +* SPARKY (inventory UI service) +* ================================================================================ +* Copyright © 2017 AT&T Intellectual Property. +* Copyright © 2017 Amdocs +* All rights reserved. +* ================================================================================ +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* ============LICENSE_END========================================================= +* +* ECOMP and OpenECOMP are trademarks +* and service marks of AT&T Intellectual Property. +*/ +package org.openecomp.sparky.dal.elasticsearch.entity; + +import java.util.ArrayList; +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); + } + + public int getTotal() { + return total; + } + + public void setTotal(int total) { + this.total = total; + } + + public int getMaxScore() { + return maxScore; + } + + public void setMaxScore(int maxScore) { + this.maxScore = maxScore; + } + + public List getHits() { + return hits; + } + + public void setHits(List hits) { + this.hits = hits; + } + + + +} diff --git a/src/test/java/org/openecomp/sparky/dal/elasticsearch/entity/ElasticSearchAggegrationResponse.java b/src/test/java/org/openecomp/sparky/dal/elasticsearch/entity/ElasticSearchAggegrationResponse.java new file mode 100644 index 0000000..54c9278 --- /dev/null +++ b/src/test/java/org/openecomp/sparky/dal/elasticsearch/entity/ElasticSearchAggegrationResponse.java @@ -0,0 +1,109 @@ +/* +* ============LICENSE_START======================================================= +* SPARKY (inventory UI service) +* ================================================================================ +* Copyright © 2017 AT&T Intellectual Property. +* Copyright © 2017 Amdocs +* All rights reserved. +* ================================================================================ +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* ============LICENSE_END========================================================= +* +* ECOMP and OpenECOMP are trademarks +* and service marks of AT&T Intellectual Property. +*/ +package org.openecomp.sparky.dal.elasticsearch.entity; + +import java.util.HashMap; +import java.util.Map; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public class ElasticSearchAggegrationResponse { + + private int took; + + @JsonProperty("timed_out") + private boolean timedOut; + + @JsonProperty("_shards") + private Map shards; + + private ElasticHitsEntity hits; + + private Map aggregations; + + public ElasticSearchAggegrationResponse() { + this.shards = new HashMap(); + this.aggregations = new HashMap(); + } + + + public int getTook() { + return took; + } + + + public void setTook(int took) { + this.took = took; + } + + + public boolean isTimedOut() { + return timedOut; + } + + + public void setTimedOut(boolean timedOut) { + this.timedOut = timedOut; + } + + + public Map getShards() { + return shards; + } + + + public void setShards(Map shards) { + this.shards = shards; + } + + + public ElasticHitsEntity getHits() { + return hits; + } + + + public void setHits(ElasticHitsEntity hits) { + this.hits = hits; + } + + public void addShard(String key, String value) { + this.shards.put(key,value); + } + + + public Map getAggregations() { + return aggregations; + } + + + public void setAggregations(Map aggregations) { + this.aggregations = aggregations; + } + + public void addAggregation(String key, ElasticSearchAggregation agg) { + this.aggregations.put(key, agg); + } + +} diff --git a/src/test/java/org/openecomp/sparky/dal/elasticsearch/entity/ElasticSearchAggregation.java b/src/test/java/org/openecomp/sparky/dal/elasticsearch/entity/ElasticSearchAggregation.java new file mode 100644 index 0000000..ea954d9 --- /dev/null +++ b/src/test/java/org/openecomp/sparky/dal/elasticsearch/entity/ElasticSearchAggregation.java @@ -0,0 +1,74 @@ +/* +* ============LICENSE_START======================================================= +* SPARKY (inventory UI service) +* ================================================================================ +* Copyright © 2017 AT&T Intellectual Property. +* Copyright © 2017 Amdocs +* All rights reserved. +* ================================================================================ +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* ============LICENSE_END========================================================= +* +* ECOMP and OpenECOMP are trademarks +* and service marks of AT&T Intellectual Property. +*/ +package org.openecomp.sparky.dal.elasticsearch.entity; + +import java.util.ArrayList; +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(); + } + + public int getDocCountErrorUpperBound() { + return docCountErrorUpperBound; + } + + public void setDocCountErrorUpperBound(int docCountErrorUpperBound) { + this.docCountErrorUpperBound = docCountErrorUpperBound; + } + + public int getSumOtherDocCount() { + return sumOtherDocCount; + } + + public void setSumOtherDocCount(int sumOtherDocCount) { + this.sumOtherDocCount = sumOtherDocCount; + } + + public List getBuckets() { + return buckets; + } + + public void setBuckets(List buckets) { + this.buckets = buckets; + } + + public void addBucket(BucketEntity bucket) { + buckets.add(bucket); + } + +} diff --git a/src/test/java/org/openecomp/sparky/dal/elasticsearch/entity/ElasticSearchCountResponse.java b/src/test/java/org/openecomp/sparky/dal/elasticsearch/entity/ElasticSearchCountResponse.java new file mode 100644 index 0000000..4b11f8c --- /dev/null +++ b/src/test/java/org/openecomp/sparky/dal/elasticsearch/entity/ElasticSearchCountResponse.java @@ -0,0 +1,60 @@ +/* +* ============LICENSE_START======================================================= +* SPARKY (inventory UI service) +* ================================================================================ +* Copyright © 2017 AT&T Intellectual Property. +* Copyright © 2017 Amdocs +* All rights reserved. +* ================================================================================ +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* ============LICENSE_END========================================================= +* +* ECOMP and OpenECOMP are trademarks +* and service marks of AT&T Intellectual Property. +*/ +package org.openecomp.sparky.dal.elasticsearch.entity; + +import java.util.HashMap; +import java.util.Map; + +public class ElasticSearchCountResponse { + + private int count; + private Map shards; + + public ElasticSearchCountResponse() { + this.shards = new HashMap(); + } + + public int getCount() { + return count; + } + + public void setCount(int count) { + this.count = count; + } + + public Map getShards() { + return shards; + } + + 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/openecomp/sparky/dal/elasticsearch/entity/PayloadEntity.java b/src/test/java/org/openecomp/sparky/dal/elasticsearch/entity/PayloadEntity.java new file mode 100644 index 0000000..360abdf --- /dev/null +++ b/src/test/java/org/openecomp/sparky/dal/elasticsearch/entity/PayloadEntity.java @@ -0,0 +1,32 @@ +/* +* ============LICENSE_START======================================================= +* SPARKY (inventory UI service) +* ================================================================================ +* Copyright © 2017 AT&T Intellectual Property. +* Copyright © 2017 Amdocs +* All rights reserved. +* ================================================================================ +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* ============LICENSE_END========================================================= +* +* ECOMP and OpenECOMP are trademarks +* and service marks of AT&T Intellectual Property. +*/ +package org.openecomp.sparky.dal.elasticsearch.entity; + +public class PayloadEntity { + + public PayloadEntity() { + } + +} diff --git a/src/test/java/org/openecomp/sparky/dal/rest/RestClientBuilderTest.java b/src/test/java/org/openecomp/sparky/dal/rest/RestClientBuilderTest.java new file mode 100644 index 0000000..80ee21f --- /dev/null +++ b/src/test/java/org/openecomp/sparky/dal/rest/RestClientBuilderTest.java @@ -0,0 +1,180 @@ +/* +* ============LICENSE_START======================================================= +* SPARKY (AAI UI service) +* ================================================================================ +* Copyright © 2017 AT&T Intellectual Property. +* Copyright © 2017 Amdocs +* All rights reserved. +* ================================================================================ +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* ============LICENSE_END========================================================= +* +* ECOMP and OpenECOMP are trademarks +* and service marks of AT&T Intellectual Property. +*/ + +package org.openecomp.sparky.dal.rest; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.doReturn; + +import com.sun.jersey.api.client.Client; +import com.sun.jersey.client.urlconnection.HTTPSProperties; + +import javax.net.ssl.SSLContext; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.openecomp.sparky.security.SecurityContextFactory; +import org.powermock.modules.junit4.PowerMockRunner; + +import ch.qos.logback.classic.Level; + +/** + * The Class RestClientBuilderTest. + */ +@RunWith(PowerMockRunner.class) +public class RestClientBuilderTest { + + + /** + * Inits the. + * + * @throws Exception the exception + */ + @Before + public void init() throws Exception { + } + + /** + * Basic construction test. + * + * @throws Exception the exception + */ + @Test + public void basicConstructionTest() throws Exception { + + RestClientBuilder clientBuilder = new RestClientBuilder(); + + // test constructor defaults + + assertFalse(clientBuilder.isValidateServerHostname()); + assertEquals(60000L, clientBuilder.getConnectTimeoutInMs()); + assertEquals(60000L, clientBuilder.getReadTimeoutInMs()); + assertTrue(clientBuilder.isUseHttps()); + + } + + /** + * Validate accessors. + * + * @throws Exception the exception + */ + @Test + public void validateAccessors() throws Exception { + + RestClientBuilder clientBuilder = new RestClientBuilder(); + + clientBuilder.setConnectTimeoutInMs(12345); + clientBuilder.setReadTimeoutInMs(54321); + clientBuilder.setUseHttps(true); + clientBuilder.setValidateServerHostname(true); + + assertEquals(12345, clientBuilder.getConnectTimeoutInMs()); + assertEquals(54321, clientBuilder.getReadTimeoutInMs()); + assertTrue(clientBuilder.isUseHttps()); + assertTrue(clientBuilder.isValidateServerHostname()); + + } + + /** + * Validate simple client construction. + * + * @throws Exception the exception + */ + @Test + public void validateSimpleClientConstruction() throws Exception { + + RestClientBuilder clientBuilder = new RestClientBuilder(); + clientBuilder.setUseHttps(false); + Client client = clientBuilder.getClient(); + + /* + * Simple client context should not contain HTTPS properties + */ + assertNull(client.getProperties().get(HTTPSProperties.PROPERTY_HTTPS_PROPERTIES)); + + } + + /** + * Validate secure client construction without host name validation. + * + * @throws Exception the exception + */ + @Test + public void validateSecureClientConstruction_WithoutHostNameValidation() throws Exception { + + RestClientBuilder clientBuilder = new RestClientBuilder(); + clientBuilder.setUseHttps(true); + + SecurityContextFactory sslContextFactory = Mockito.mock(SecurityContextFactory.class); + clientBuilder.setSslContextFactory(sslContextFactory); + + SSLContext sslContext = Mockito.mock(SSLContext.class); + doReturn(sslContext).when(sslContextFactory).getSecureContext(); + + Client client = clientBuilder.getClient(); + + /* + * Secure client context should contain HTTPS properties + */ + assertNotNull(client.getProperties().get(HTTPSProperties.PROPERTY_HTTPS_PROPERTIES)); + assertNotNull(clientBuilder.getSslContextFactory()); + + } + + /** + * Validate secure client construction with host name validation. + * + * @throws Exception the exception + */ + @Test + public void validateSecureClientConstruction_WithHostNameValidation() throws Exception { + + RestClientBuilder clientBuilder = new RestClientBuilder(); + clientBuilder.setUseHttps(true); + clientBuilder.setValidateServerHostname(true); + + SecurityContextFactory sslContextFactory = Mockito.mock(SecurityContextFactory.class); + clientBuilder.setSslContextFactory(sslContextFactory); + + SSLContext sslContext = Mockito.mock(SSLContext.class); + doReturn(sslContext).when(sslContextFactory).getSecureContext(); + + Client client = clientBuilder.getClient(); + + /* + * Secure client context should contain HTTPS properties + */ + assertNotNull(client.getProperties().get(HTTPSProperties.PROPERTY_HTTPS_PROPERTIES)); + assertNotNull(clientBuilder.getSslContextFactory()); + + } + +} diff --git a/src/test/java/org/openecomp/sparky/dal/rest/RestfulDataAccessorTest.java b/src/test/java/org/openecomp/sparky/dal/rest/RestfulDataAccessorTest.java new file mode 100644 index 0000000..b898d90 --- /dev/null +++ b/src/test/java/org/openecomp/sparky/dal/rest/RestfulDataAccessorTest.java @@ -0,0 +1,226 @@ +/* +* ============LICENSE_START======================================================= +* SPARKY (AAI UI service) +* ================================================================================ +* Copyright © 2017 AT&T Intellectual Property. +* Copyright © 2017 Amdocs +* All rights reserved. +* ================================================================================ +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* ============LICENSE_END========================================================= +* +* ECOMP and OpenECOMP are trademarks +* and service marks of AT&T Intellectual Property. +*/ + +package org.openecomp.sparky.dal.rest; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Matchers.anyObject; +import static org.mockito.Matchers.anyString; +import static org.mockito.Matchers.same; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.mock; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.powermock.modules.junit4.PowerMockRunner; + +import com.sun.jersey.api.client.Client; +import com.sun.jersey.api.client.ClientResponse; +import com.sun.jersey.api.client.WebResource; +import com.sun.jersey.api.client.WebResource.Builder; + +/** + * The Class RestfulDataAccessorTest. + */ +@RunWith(PowerMockRunner.class) +public class RestfulDataAccessorTest { + + private RestClientBuilder clientBuilderMock; + private Client mockClient; + private ClientResponse mockClientResponse; + private WebResource mockWebResource; + private Builder mockBuilder; + + + /** + * Inits the. + * + * @throws Exception the exception + */ + @Before + public void init() throws Exception { + + /* + * common collaborator mocking setup + */ + + clientBuilderMock = mock(RestClientBuilder.class); + mockClient = mock(Client.class); + mockClientResponse = mock(ClientResponse.class); + mockWebResource = mock(WebResource.class); + mockBuilder = mock(Builder.class); + + doReturn(mockClient).when(clientBuilderMock).getClient(); + doReturn(mockWebResource).when(mockClient).resource(anyString()); + doReturn(mockBuilder).when(mockWebResource).accept(anyString()); + doReturn(mockBuilder).when(mockBuilder).header(anyString(), anyObject()); + + doReturn(mockClientResponse).when(mockBuilder).get(same(ClientResponse.class)); + doReturn(mockClientResponse).when(mockBuilder).put(same(ClientResponse.class), anyObject()); + doReturn(mockClientResponse).when(mockBuilder).post(same(ClientResponse.class), anyObject()); + doReturn(mockClientResponse).when(mockBuilder).delete(same(ClientResponse.class)); + } + + /** + * Successful do put. + * + * @throws Exception the exception + */ + @Test + public void successfulDoPut() throws Exception { + + /* + * set test mocking expectations + */ + + doReturn(200).when(mockClientResponse).getStatus(); + doReturn("Success").when(mockClientResponse).getEntity(String.class); + + // test code + RestfulDataAccessor dataAccessor = new RestfulDataAccessor(clientBuilderMock); + OperationResult actualResult = dataAccessor.doPut("myUrl", "jsonPayload", "acceptContentType"); + + assertEquals("Unexpected result", 200, actualResult.getResultCode()); + } + + /** + * Successful do get. + * + * @throws Exception the exception + */ + @Test + public void successfulDoGet() throws Exception { + + /* + * set test mocking expectations + */ + + doReturn(200).when(mockClientResponse).getStatus(); + doReturn("Success").when(mockClientResponse).getEntity(String.class); + + // test code + RestfulDataAccessor dataAccessor = new RestfulDataAccessor(clientBuilderMock); + OperationResult actualResult = dataAccessor.doGet("myUrl", "anyContentType"); + + assertEquals("Unexpected result", 200, actualResult.getResultCode()); + + } + + /** + * Successful do post. + * + * @throws Exception the exception + */ + @Test + public void successfulDoPost() throws Exception { + + /* + * set test mocking expectations + */ + + doReturn(200).when(mockClientResponse).getStatus(); + doReturn("Success").when(mockClientResponse).getEntity(String.class); + + // test code + RestfulDataAccessor dataAccessor = new RestfulDataAccessor(clientBuilderMock); + OperationResult actualResult = dataAccessor.doPost("myUrl", "jsonPayload", "anyContentType"); + + assertEquals("Unexpected result", 200, actualResult.getResultCode()); + + } + + /** + * Successful do delete. + * + * @throws Exception the exception + */ + @Test + public void successfulDoDelete() throws Exception { + + /* + * set test mocking expectations + */ + + doReturn(200).when(mockClientResponse).getStatus(); + doReturn("Success").when(mockClientResponse).getEntity(String.class); + + // test code + RestfulDataAccessor dataAccessor = new RestfulDataAccessor(clientBuilderMock); + OperationResult actualResult = dataAccessor.doDelete("myUrl", "anyContentType"); + + assertEquals("Unexpected result", 200, actualResult.getResultCode()); + + } + + /** + * Operation results in null pointer exception. + * + * @throws Exception the exception + */ + @Test + public void operationResultsInNullPointerException() throws Exception { + + /* + * set test mocking expectations + */ + + + doThrow(new NullPointerException("Parameter can't be null")).when(clientBuilderMock) + .getClient(); + + // test code + RestfulDataAccessor dataAccessor = new RestfulDataAccessor(clientBuilderMock); + OperationResult actualResult = dataAccessor.doDelete("myUrl", "anyContentType"); + + assertEquals("Unexpected result", 500, actualResult.getResultCode()); + + } + + /** + * Operation results in null client response. + * + * @throws Exception the exception + */ + @Test + public void operationResultsInNullClientResponse() throws Exception { + + /* + * set test mocking expectations + */ + // return null client response + doReturn(null).when(mockBuilder).delete(same(ClientResponse.class)); + + // test code + RestfulDataAccessor dataAccessor = new RestfulDataAccessor(clientBuilderMock); + OperationResult actualResult = dataAccessor.doDelete("myUrl", "anyContentType"); + + assertEquals("Unexpected result", 500, actualResult.getResultCode()); + + } + + +} diff --git a/src/test/java/org/openecomp/sparky/dal/sas/entity/DocumentEntity.java b/src/test/java/org/openecomp/sparky/dal/sas/entity/DocumentEntity.java new file mode 100644 index 0000000..6285e9c --- /dev/null +++ b/src/test/java/org/openecomp/sparky/dal/sas/entity/DocumentEntity.java @@ -0,0 +1,68 @@ +/* +* ============LICENSE_START======================================================= +* SPARKY (inventory UI service) +* ================================================================================ +* Copyright © 2017 AT&T Intellectual Property. +* Copyright © 2017 Amdocs +* All rights reserved. +* ================================================================================ +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* ============LICENSE_END========================================================= +* +* ECOMP and OpenECOMP are trademarks +* and service marks of AT&T Intellectual Property. +*/ +package org.openecomp.sparky.dal.sas.entity; + +import java.util.HashMap; +import java.util.Map; + +public class DocumentEntity { + private String etag; + private String url; + private Map content; + + public DocumentEntity() { + content = new HashMap(); + } + + + public String getEtag() { + return etag; + } + + public void setEtag(String etag) { + this.etag = etag; + } + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + + public Map getContent() { + return content; + } + + 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/openecomp/sparky/dal/sas/entity/EntityCountResponse.java b/src/test/java/org/openecomp/sparky/dal/sas/entity/EntityCountResponse.java new file mode 100644 index 0000000..3940b28 --- /dev/null +++ b/src/test/java/org/openecomp/sparky/dal/sas/entity/EntityCountResponse.java @@ -0,0 +1,55 @@ +/* +* ============LICENSE_START======================================================= +* SPARKY (inventory UI service) +* ================================================================================ +* Copyright © 2017 AT&T Intellectual Property. +* Copyright © 2017 Amdocs +* All rights reserved. +* ================================================================================ +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* ============LICENSE_END========================================================= +* +* ECOMP and OpenECOMP are trademarks +* and service marks of AT&T Intellectual Property. +*/ +package org.openecomp.sparky.dal.sas.entity; + +import java.util.HashMap; +import java.util.Map; + +public class EntityCountResponse { + + private Map shards; + private int count; + + public EntityCountResponse() { + this.shards = new HashMap(); + } + + public Map getShards() { + return shards; + } + + public void setShards(Map shards) { + this.shards = shards; + } + + public int getCount() { + return count; + } + + public void setCount(int count) { + this.count = count; + } + +} diff --git a/src/test/java/org/openecomp/sparky/dal/sas/entity/GroupByAggregationEntity.java b/src/test/java/org/openecomp/sparky/dal/sas/entity/GroupByAggregationEntity.java new file mode 100644 index 0000000..3ab5e30 --- /dev/null +++ b/src/test/java/org/openecomp/sparky/dal/sas/entity/GroupByAggregationEntity.java @@ -0,0 +1,60 @@ +/* +* ============LICENSE_START======================================================= +* SPARKY (inventory UI service) +* ================================================================================ +* Copyright © 2017 AT&T Intellectual Property. +* Copyright © 2017 Amdocs +* All rights reserved. +* ================================================================================ +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* ============LICENSE_END========================================================= +* +* ECOMP and OpenECOMP are trademarks +* and service marks of AT&T Intellectual Property. +*/ +package org.openecomp.sparky.dal.sas.entity; + +import java.util.ArrayList; +import java.util.List; + +import org.openecomp.sparky.dal.elasticsearch.entity.BucketEntity; + +public class GroupByAggregationEntity { + private int totalChartHits; + List buckets; + + public GroupByAggregationEntity() { + this.buckets = new ArrayList(); + } + + public int getTotalChartHits() { + return totalChartHits; + } + + public void setTotalChartHits(int totalChartHits) { + this.totalChartHits = totalChartHits; + } + + public List getBuckets() { + return buckets; + } + + public void setBuckets(List buckets) { + this.buckets = buckets; + } + + public void addBucket(BucketEntity bucket) { + this.buckets.add(bucket); + } + +} diff --git a/src/test/java/org/openecomp/sparky/dal/sas/entity/GroupByAggregationResponseEntity.java b/src/test/java/org/openecomp/sparky/dal/sas/entity/GroupByAggregationResponseEntity.java new file mode 100644 index 0000000..4ef3be1 --- /dev/null +++ b/src/test/java/org/openecomp/sparky/dal/sas/entity/GroupByAggregationResponseEntity.java @@ -0,0 +1,48 @@ +/* +* ============LICENSE_START======================================================= +* SPARKY (inventory UI service) +* ================================================================================ +* Copyright © 2017 AT&T Intellectual Property. +* Copyright © 2017 Amdocs +* All rights reserved. +* ================================================================================ +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* ============LICENSE_END========================================================= +* +* ECOMP and OpenECOMP are trademarks +* and service marks of AT&T Intellectual Property. +*/ +package org.openecomp.sparky.dal.sas.entity; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public class GroupByAggregationResponseEntity { + + @JsonProperty("groupby_aggregation") + private GroupByAggregationEntity aggEntity; + + public GroupByAggregationResponseEntity() { + + } + + public GroupByAggregationEntity getAggEntity() { + return aggEntity; + } + + public void setAggEntity(GroupByAggregationEntity aggEntity) { + this.aggEntity = aggEntity; + } + + + +} diff --git a/src/test/java/org/openecomp/sparky/dal/sas/entity/HitEntity.java b/src/test/java/org/openecomp/sparky/dal/sas/entity/HitEntity.java new file mode 100644 index 0000000..f5036e7 --- /dev/null +++ b/src/test/java/org/openecomp/sparky/dal/sas/entity/HitEntity.java @@ -0,0 +1,48 @@ +/* +* ============LICENSE_START======================================================= +* SPARKY (inventory UI service) +* ================================================================================ +* Copyright © 2017 AT&T Intellectual Property. +* Copyright © 2017 Amdocs +* All rights reserved. +* ================================================================================ +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* ============LICENSE_END========================================================= +* +* ECOMP and OpenECOMP are trademarks +* and service marks of AT&T Intellectual Property. +*/ +package org.openecomp.sparky.dal.sas.entity; + +public class HitEntity { + + private String score; + private DocumentEntity document; + + public String getScore() { + return score; + } + + public void setScore(String score) { + this.score = score; + } + + public DocumentEntity getDocument() { + return document; + } + + public void setDocument(DocumentEntity document) { + this.document = document; + } + +} diff --git a/src/test/java/org/openecomp/sparky/dal/sas/entity/SearchAbstractionEntityBuilder.java b/src/test/java/org/openecomp/sparky/dal/sas/entity/SearchAbstractionEntityBuilder.java new file mode 100644 index 0000000..fa3d463 --- /dev/null +++ b/src/test/java/org/openecomp/sparky/dal/sas/entity/SearchAbstractionEntityBuilder.java @@ -0,0 +1,295 @@ +/* +* ============LICENSE_START======================================================= +* SPARKY (inventory UI service) +* ================================================================================ +* Copyright © 2017 AT&T Intellectual Property. +* Copyright © 2017 Amdocs +* All rights reserved. +* ================================================================================ +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* ============LICENSE_END========================================================= +* +* ECOMP and OpenECOMP are trademarks +* and service marks of AT&T Intellectual Property. +*/ +package org.openecomp.sparky.dal.sas.entity; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +public class SearchAbstractionEntityBuilder { + + + public static HitEntity getHitSample1() { + + HitEntity hitEntity = new HitEntity(); + DocumentEntity doc = new DocumentEntity(); + + hitEntity.setDocument(doc); + 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-ext1.test.att.com: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(); + DocumentEntity doc = new DocumentEntity(); + + hitEntity.setDocument(doc); + 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-ext1.test.att.com: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(); + DocumentEntity doc = new DocumentEntity(); + + hitEntity.setDocument(doc); + 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-ext1.test.att.com: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(); + DocumentEntity doc = new DocumentEntity(); + + hitEntity.setDocument(doc); + 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-ext1.test.att.com: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(); + DocumentEntity doc = new DocumentEntity(); + + hitEntity.setDocument(doc); + 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-ext1.test.att.com: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(); + DocumentEntity doc = new DocumentEntity(); + + hitEntity.setDocument(doc); + 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-ext1.test.att.com: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(); + DocumentEntity doc = new DocumentEntity(); + + hitEntity.setDocument(doc); + 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-ext1.test.att.com: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(); + DocumentEntity doc = new DocumentEntity(); + + hitEntity.setDocument(doc); + 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-ext1.test.att.com: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(); + DocumentEntity doc = new DocumentEntity(); + + hitEntity.setDocument(doc); + hitEntity.setScore("13.940832"); + + doc.addContent("entityPrimaryKeyValue", "vnfm0003v"); + doc.addContent("entityType", "generic-vnf"); + doc.addContent("searchTags", "vnfm0003v;vnfm0003v"); + doc.addContent("link", "https://aai-ext1.test.att.com: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(); + DocumentEntity doc = new DocumentEntity(); + + hitEntity.setDocument(doc); + hitEntity.setScore("13.928098"); + + doc.addContent("entityPrimaryKeyValue", "amist456vnf"); + doc.addContent("entityType", "generic-vnf"); + doc.addContent("searchTags", "amist456vnf;amist456vnf"); + doc.addContent("link", "https://aai-ext1.test.att.com: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()); + hits.add(getHitSample4()); + hits.add(getHitSample5()); + hits.add(getHitSample6()); + hits.add(getHitSample7()); + hits.add(getHitSample8()); + hits.add(getHitSample9()); + hits.add(getHitSample10()); + + searchResult.setHits(hits); + + return sasResponse; + + } + + +} diff --git a/src/test/java/org/openecomp/sparky/dal/sas/entity/SearchAbstractionResponse.java b/src/test/java/org/openecomp/sparky/dal/sas/entity/SearchAbstractionResponse.java new file mode 100644 index 0000000..0e6398f --- /dev/null +++ b/src/test/java/org/openecomp/sparky/dal/sas/entity/SearchAbstractionResponse.java @@ -0,0 +1,39 @@ +/* +* ============LICENSE_START======================================================= +* SPARKY (inventory UI service) +* ================================================================================ +* Copyright © 2017 AT&T Intellectual Property. +* Copyright © 2017 Amdocs +* All rights reserved. +* ================================================================================ +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* ============LICENSE_END========================================================= +* +* ECOMP and OpenECOMP are trademarks +* and service marks of AT&T Intellectual Property. +*/ +package org.openecomp.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/openecomp/sparky/dal/sas/entity/SearchResult.java b/src/test/java/org/openecomp/sparky/dal/sas/entity/SearchResult.java new file mode 100644 index 0000000..992d5b5 --- /dev/null +++ b/src/test/java/org/openecomp/sparky/dal/sas/entity/SearchResult.java @@ -0,0 +1,49 @@ +/* +* ============LICENSE_START======================================================= +* SPARKY (inventory UI service) +* ================================================================================ +* Copyright © 2017 AT&T Intellectual Property. +* Copyright © 2017 Amdocs +* All rights reserved. +* ================================================================================ +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* ============LICENSE_END========================================================= +* +* ECOMP and OpenECOMP are trademarks +* and service marks of AT&T Intellectual Property. +*/ +package org.openecomp.sparky.dal.sas.entity; + +import java.util.List; + +public class SearchResult { + + private int totalHits; + private List hits; + + 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; + } + + + +} -- cgit 1.2.3-korg