summaryrefslogtreecommitdiffstats
path: root/src/test/java
diff options
context:
space:
mode:
authoraditya <ag282f@att.com>2017-11-21 20:58:53 -0600
committeraditya <ag282f@att.com>2017-11-22 08:46:40 -0600
commit3edefce2bf67b6454a8bfbc6748a3577a213ff1d (patch)
treeab8474b9233c9813db60a4fbc7bacc90ffd368b0 /src/test/java
parent8330923db923414eef5413acb2ac977b39f7ca46 (diff)
Add unit test cases to increase sonar coverage
Add unit test cases to search, synchronizer packages to increase sonar coverage Issue-ID: AAI-503 Change-Id: Iff43c3b1e17699d183566f63ab25e45660ed1fdb Signed-off-by: Aditya Gajulapalli <ag282f@att.com>
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/org/onap/aai/sparky/dal/elasticsearch/ElasticSearchConfigTest.java520
-rw-r--r--src/test/java/org/onap/aai/sparky/search/VnfSearchQueryBuilderTest.java75
-rw-r--r--src/test/java/org/onap/aai/sparky/search/VnfSearchServiceTest.java89
-rw-r--r--src/test/java/org/onap/aai/sparky/synchronizer/AggregationSuggestionSynchronizerTest.java86
-rw-r--r--src/test/java/org/onap/aai/sparky/synchronizer/SyncControllerTest.java81
-rw-r--r--src/test/java/org/onap/aai/sparky/synchronizer/SyncHelperTest.java185
-rw-r--r--src/test/java/org/onap/aai/sparky/util/KeystoreBuilderTest.java100
-rw-r--r--src/test/java/org/onap/aai/sparky/viewandinspect/services/VisualizationServiceTest.java111
8 files changed, 937 insertions, 310 deletions
diff --git a/src/test/java/org/onap/aai/sparky/dal/elasticsearch/ElasticSearchConfigTest.java b/src/test/java/org/onap/aai/sparky/dal/elasticsearch/ElasticSearchConfigTest.java
index 946d570..5de9e2f 100644
--- a/src/test/java/org/onap/aai/sparky/dal/elasticsearch/ElasticSearchConfigTest.java
+++ b/src/test/java/org/onap/aai/sparky/dal/elasticsearch/ElasticSearchConfigTest.java
@@ -1,243 +1,277 @@
-/*
-* ============LICENSE_START=======================================================
-* SPARKY (AAI UI service)
-* ================================================================================
-* Copyright © 2017 AT&T Intellectual Property.
-* Copyright © 2017 Amdocs
-* All rights reserved.
-* ================================================================================
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-* ============LICENSE_END=========================================================
-*
-* ECOMP and OpenECOMP are trademarks
-* and service marks of AT&T Intellectual Property.
-*/
-
-package org.onap.aai.sparky.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.onap.aai.sparky.dal.elasticsearch.config.ElasticSearchConfig;
-import org.onap.aai.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 {
- }
-
- /**
- * 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();
- }
-
-}
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017 Amdocs
+ * ================================================================================
+ * 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 is a trademark and service mark of AT&T Intellectual Property.
+ */
+
+package org.onap.aai.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.Assert;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.onap.aai.sparky.dal.elasticsearch.config.ElasticSearchConfig;
+import org.onap.aai.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\"]}}";
+
+ ElasticSearchConfig elasticSearchConfig;
+
+ /**
+ * Inits the.
+ *
+ * @throws Exception the exception
+ */
+ @Before
+ public void init() throws Exception {
+ elasticSearchConfig = Mockito.spy(new ElasticSearchConfig());
+ }
+
+ /**
+ * 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();
+ }
+
+ @Test
+ public void testGetFullUrl_ThreeParams() throws Exception {
+ Mockito.when(elasticSearchConfig.getIpAddress()).thenReturn("http://localhost");
+ Mockito.when(elasticSearchConfig.getHttpPort()).thenReturn("5443");
+ String fullUrl = elasticSearchConfig.getElasticFullUrl("http://localhost:5443/aai/model/index", "entity-index", "entity");
+ Assert.assertNotNull(fullUrl);
+ }
+
+ @Test
+ public void testGetFullUrl_OneParam() throws Exception {
+ Mockito.when(elasticSearchConfig.getIpAddress()).thenReturn("http://localhost");
+ Mockito.when(elasticSearchConfig.getHttpPort()).thenReturn("5443");
+ Mockito.when(elasticSearchConfig.getIndexName()).thenReturn("entity");
+ String fullUrl = elasticSearchConfig.getElasticFullUrl("http://localhost:5443/aai/model/index");
+ Assert.assertNotNull(fullUrl);
+ }
+
+ @Test
+ public void testGetBulkUrl() throws Exception {
+ Mockito.when(elasticSearchConfig.getIpAddress()).thenReturn("http://localhost");
+ Mockito.when(elasticSearchConfig.getHttpPort()).thenReturn("5443");
+ String fullUrl = elasticSearchConfig.getBulkUrl();
+ Assert.assertNotNull(fullUrl);
+ }
+
+ @Test
+ public void testGetConfigAsString() throws IOException, ElasticSearchOperationException {
+ System.setProperty("AJSC_HOME", new File(".").getCanonicalPath().replace('\\', '/'));
+ String retStr = elasticSearchConfig.getConfigAsString("item-1", System.getProperty("AJSC_HOME")+"/src/test/resources/appconfig/roles.config");
+ Assert.assertNotNull(retStr);
+ }
+
+}
diff --git a/src/test/java/org/onap/aai/sparky/search/VnfSearchQueryBuilderTest.java b/src/test/java/org/onap/aai/sparky/search/VnfSearchQueryBuilderTest.java
new file mode 100644
index 0000000..19a0a3a
--- /dev/null
+++ b/src/test/java/org/onap/aai/sparky/search/VnfSearchQueryBuilderTest.java
@@ -0,0 +1,75 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017 Amdocs
+ * ================================================================================
+ * 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 is a trademark and service mark of AT&T Intellectual Property.
+ */
+package org.onap.aai.sparky.search;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.json.JsonArray;
+import javax.json.JsonObject;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.onap.aai.sparky.search.VnfSearchQueryBuilder;
+
+public class VnfSearchQueryBuilderTest {
+
+ @Test
+ public void testCreateSuggestionsQuery() {
+ String maxResults = "maxResults-1";
+ String queryStr = "queryStr-1";
+ JsonObject object = VnfSearchQueryBuilder.createSuggestionsQuery(maxResults, queryStr);
+ Assert.assertNotNull(object);
+ }
+
+ @Test
+ public void testSortCriteria() {
+ JsonArray array = VnfSearchQueryBuilder.getSortCriteria("field-1", "sortOrder-1");
+ Assert.assertNotNull(array);
+ }
+
+ @Test
+ public void testCreateEntityCountsQuery_SingleAttribute() {
+ Map<String, String> attributes = new HashMap<>();
+ attributes.put("key-1", "value-1");
+ JsonObject object = VnfSearchQueryBuilder.createEntityCountsQuery(attributes);
+ Assert.assertNotNull(object);
+ }
+
+ @Test
+ public void testCreateSummaryByEntityTypeQuery_Single() {
+ Map<String, String> attributes = new HashMap<>();
+ attributes.put("key-1", "value-1");
+ JsonObject object = VnfSearchQueryBuilder.createSummaryByEntityTypeQuery(attributes, "groupkey-1");
+ Assert.assertNotNull(object);
+ }
+
+ @Test
+ public void testCreateSummaryByEntityTypeQuery_Multiple() {
+ Map<String, String> attributes = new HashMap<>();
+ attributes.put("key-1", "value-1");
+ attributes.put("key-2", "value-2");
+ JsonObject object = VnfSearchQueryBuilder.createSummaryByEntityTypeQuery(attributes, "groupkey-1");
+ Assert.assertNotNull(object);
+ }
+}
diff --git a/src/test/java/org/onap/aai/sparky/search/VnfSearchServiceTest.java b/src/test/java/org/onap/aai/sparky/search/VnfSearchServiceTest.java
new file mode 100644
index 0000000..8c4d59d
--- /dev/null
+++ b/src/test/java/org/onap/aai/sparky/search/VnfSearchServiceTest.java
@@ -0,0 +1,89 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017 Amdocs
+ * ================================================================================
+ * 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 is a trademark and service mark of AT&T Intellectual Property.
+ */
+package org.onap.aai.sparky.search;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+
+import javax.servlet.http.HttpServletResponse;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.onap.aai.sparky.dal.elasticsearch.SearchAdapter;
+import org.onap.aai.sparky.dal.elasticsearch.config.ElasticSearchConfig;
+import org.onap.aai.sparky.dal.rest.OperationResult;
+import org.onap.aai.sparky.viewandinspect.config.TierSupportUiConstants;
+import org.onap.aai.sparky.viewandinspect.entity.QuerySearchEntity;
+
+public class VnfSearchServiceTest {
+
+ VnfSearchService searchService;
+
+ @Before
+ public void init() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException, IOException {
+ System.setProperty("AJSC_HOME", new File(".").getCanonicalPath().replace('\\', '/'));
+ TierSupportUiConstants.DYNAMIC_CONFIG_APP_LOCATION = System.getProperty("AJSC_HOME")+"/src/test/resources/appconfig/";
+ ElasticSearchConfig.setConfig(null);
+ setFinalStatic();
+ searchService = new VnfSearchService();
+ }
+ @Test
+ public void testSetZeroCountResponse() throws IOException {
+ HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
+ Mockito.doNothing().when(response).setStatus(1);
+ Mockito.doNothing().when(response).setContentType(Mockito.anyString());
+ PrintWriter writer = Mockito.mock(PrintWriter.class);
+ Mockito.doNothing().when(writer).println(Mockito.anyString());
+ Mockito.doNothing().when(writer).close();
+ Mockito.when(response.getWriter()).thenReturn(writer);
+ searchService.setZeroCountResponse(response);
+ }
+
+ @Test
+ public void testSetEmptyAggResponse() throws IOException {
+ HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
+ Mockito.doNothing().when(response).setStatus(1);
+ Mockito.doNothing().when(response).setContentType(Mockito.anyString());
+ PrintWriter writer = Mockito.mock(PrintWriter.class);
+ Mockito.doNothing().when(writer).println(Mockito.anyString());
+ Mockito.doNothing().when(writer).close();
+ Mockito.when(response.getWriter()).thenReturn(writer);
+ searchService.setEmptyAggResponse(response);
+ }
+
+
+ static void setFinalStatic() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
+ Field configField = ElasticSearchConfig.class.getDeclaredField("CONFIG_FILE");
+ configField.setAccessible(true);
+
+ Field modifiersField = Field.class.getDeclaredField( "modifiers" );
+ modifiersField.setAccessible( true );
+ modifiersField.setInt( configField, configField.getModifiers() & ~Modifier.FINAL );
+
+ configField.set(null, System.getProperty("AJSC_HOME")+"/src/test/resources/appconfig/elasticsearch.properties");
+ }
+}
diff --git a/src/test/java/org/onap/aai/sparky/synchronizer/AggregationSuggestionSynchronizerTest.java b/src/test/java/org/onap/aai/sparky/synchronizer/AggregationSuggestionSynchronizerTest.java
new file mode 100644
index 0000000..e590af6
--- /dev/null
+++ b/src/test/java/org/onap/aai/sparky/synchronizer/AggregationSuggestionSynchronizerTest.java
@@ -0,0 +1,86 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017 Amdocs
+ * ================================================================================
+ * 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 is a trademark and service mark of AT&T Intellectual Property.
+ */
+package org.onap.aai.sparky.synchronizer;
+
+import java.io.File;
+import java.io.IOException;
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.aai.sparky.dal.NetworkTransaction;
+import org.onap.aai.sparky.dal.elasticsearch.config.ElasticSearchConfig;
+import org.onap.aai.sparky.dal.rest.HttpMethod;
+import org.onap.aai.sparky.dal.rest.OperationResult;
+import org.onap.aai.sparky.synchronizer.enumeration.OperationState;
+import org.onap.aai.sparky.synchronizer.enumeration.SynchronizerState;
+import org.onap.aai.sparky.viewandinspect.config.TierSupportUiConstants;
+
+public class AggregationSuggestionSynchronizerTest {
+
+ @Before
+ public void init() throws IOException {
+ System.setProperty("AJSC_HOME", new File(".").getCanonicalPath().replace('\\', '/'));
+ TierSupportUiConstants.DYNAMIC_CONFIG_APP_LOCATION = System.getProperty("AJSC_HOME")+"/src/test/resources/appconfig/";
+ // TierSupportUiConstants.CONFIG_OXM_LOCATION = System.getProperty("AJSC_HOME")+"/bundleconfig-local/oxm/";
+ }
+
+ @Test
+ public void testDoSync() throws Exception {
+ ElasticSearchConfig.setConfig(null);
+ setFinalStatic();
+ AggregationSuggestionSynchronizer ass = new AggregationSuggestionSynchronizer("entity-search-index");
+ Assert.assertNotNull(ass);
+ OperationState state = ass.doSync();
+ Assert.assertEquals(OperationState.OK, state);
+
+ OperationResult result = new OperationResult();
+ result.setResultCode(200);
+ result.setResult("result-1");
+ result.setNumRequestRetries(1);
+ NetworkTransaction ntwTxn = new NetworkTransaction(HttpMethod.GET, "entity-1", result);
+ ass.updateElasticSearchCounters(ntwTxn);
+
+ SynchronizerState syncState = ass.getState();
+ Assert.assertEquals(SynchronizerState.IDLE, syncState);
+
+ String statReport = ass.getStatReport(true);
+ Assert.assertNotNull(statReport);
+ Assert.assertTrue(statReport.contains("Aggregation Suggestion Synchronizer"));
+
+ ass.shutdown();
+ }
+
+ static void setFinalStatic() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
+ Field configField = ElasticSearchConfig.class.getDeclaredField("CONFIG_FILE");
+ configField.setAccessible(true);
+
+ Field modifiersField = Field.class.getDeclaredField( "modifiers" );
+ modifiersField.setAccessible( true );
+ modifiersField.setInt( configField, configField.getModifiers() & ~Modifier.FINAL );
+
+ configField.set(null, System.getProperty("AJSC_HOME")+"/src/test/resources/appconfig/elasticsearch.properties");
+ }
+}
diff --git a/src/test/java/org/onap/aai/sparky/synchronizer/SyncControllerTest.java b/src/test/java/org/onap/aai/sparky/synchronizer/SyncControllerTest.java
new file mode 100644
index 0000000..c7464d3
--- /dev/null
+++ b/src/test/java/org/onap/aai/sparky/synchronizer/SyncControllerTest.java
@@ -0,0 +1,81 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017 Amdocs
+ * ================================================================================
+ * 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 is a trademark and service mark of AT&T Intellectual Property.
+ */
+package org.onap.aai.sparky.synchronizer;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.onap.aai.sparky.synchronizer.SyncController.SyncActions;
+
+public class SyncControllerTest {
+
+ SyncController controller;
+
+ @Before
+ public void init() throws Exception {
+ controller = new SyncController("name-1");
+ }
+ @Test
+ public void testPerformAction_PreSync() {
+ controller.performAction(SyncActions.SYNCHRONIZE);
+ controller.shutdown();
+ }
+
+ @Test
+ public void testRegisterIndexCleaner_NullIndexName() {
+ IndexCleaner cleaner = new ElasticSearchIndexCleaner(null, null, "index_type-1", "host-1", "port-1", 1, 1);
+ controller.registerIndexCleaner(cleaner);
+ }
+
+ @Test
+ public void testRegisterIndexCleaner_NotNullIndexName() {
+ IndexCleaner cleaner = new ElasticSearchIndexCleaner(null, "index-1", "index_type-1", "host-1", "port-1", 1, 1);
+ controller.registerIndexCleaner(cleaner);
+ }
+
+ @Test
+ public void testRegisterIndexValidator_NullIndexValidator() {
+ IndexValidator validator = new IndexIntegrityValidator(null, null, "index_type-1", "host-1", "port-1", "json-1");
+ controller.registerIndexValidator(validator);
+ }
+
+ @Test
+ public void testRegisterIndexValidator_NotNullIndexValidator() {
+ IndexValidator validator = new IndexIntegrityValidator(null, "index-1", "index_type-1", "host-1", "port-1", "json-1");
+ controller.registerIndexValidator(validator);
+ }
+
+ @Test
+ public void testRegisterEntitySynchronizer_NullEntitySynchronizer() throws Exception {
+ IndexSynchronizer synchroniser = Mockito.mock(SearchableEntitySynchronizer.class);
+ Mockito.when(synchroniser.getIndexName()).thenReturn(null);
+ controller.registerEntitySynchronizer(synchroniser);
+ }
+
+ @Test
+ public void testRegisterEntitySynchronizer_NotNullEntitySynchronizer() throws Exception {
+ IndexSynchronizer synchroniser = Mockito.mock(SearchableEntitySynchronizer.class);
+ Mockito.when(synchroniser.getIndexName()).thenReturn("entity-1");
+ controller.registerEntitySynchronizer(synchroniser);
+ }
+}
diff --git a/src/test/java/org/onap/aai/sparky/synchronizer/SyncHelperTest.java b/src/test/java/org/onap/aai/sparky/synchronizer/SyncHelperTest.java
index 460bdf0..5a2584f 100644
--- a/src/test/java/org/onap/aai/sparky/synchronizer/SyncHelperTest.java
+++ b/src/test/java/org/onap/aai/sparky/synchronizer/SyncHelperTest.java
@@ -1,67 +1,118 @@
-package org.onap.aai.sparky.synchronizer;
-
-import static org.junit.Assert.assertEquals;
-
-import java.io.File;
-import java.io.IOException;
-import java.text.SimpleDateFormat;
-import java.util.Calendar;
-import java.util.TimeZone;
-
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.runners.MockitoJUnitRunner;
-import org.onap.aai.sparky.config.oxm.OxmModelLoader;
-import org.onap.aai.sparky.synchronizer.config.SynchronizerConstants;
-import org.onap.aai.sparky.viewandinspect.config.TierSupportUiConstants;
-
-@RunWith(MockitoJUnitRunner.class)
-public class SyncHelperTest {
-
- private SyncHelper syncHelper;
-
- @BeforeClass
- public static void initBeforeClass() throws IOException {
- String configHomePath =
- (new File(".").getCanonicalPath() + "/src/test/resources/appconfig/").replace('\\', '/');
- TierSupportUiConstants.AJSC_HOME = configHomePath;
- TierSupportUiConstants.CONFIG_HOME = configHomePath;
- TierSupportUiConstants.DYNAMIC_CONFIG_APP_LOCATION = configHomePath;
- }
-
-
- @Test
- public void testGetOxmModelLoader() throws Exception {
- syncHelper = new SyncHelper(new OxmModelLoader());
- OxmModelLoader oxmLoader = new OxmModelLoader();
- syncHelper.setOxmModelLoader(oxmLoader);
- assertEquals(oxmLoader, syncHelper.getOxmModelLoader());
- }
-
- @Test
- public void testGetFirstSyncTime(){
- SyncHelper syncHelper = new SyncHelper(new OxmModelLoader());
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z");
- TimeZone tz = TimeZone.getTimeZone("05:00:00 GMT+00:00");
- Calendar calendar = Calendar.getInstance(tz);
- sdf.setTimeZone(tz);
-
- calendar.set(Calendar.HOUR_OF_DAY, 1);
- calendar.set(Calendar.MINUTE, 1);
- calendar.set(Calendar.SECOND, 1);
-
- long timeCurrent = calendar.getTimeInMillis();
- int taskFrequencyInDay = 2;
-
- assertEquals(calendar.getTimeInMillis(), syncHelper.getFirstSyncTime(calendar, timeCurrent, taskFrequencyInDay));
- taskFrequencyInDay = 0;
- assertEquals(SynchronizerConstants.DELAY_NO_PERIODIC_SYNC_IN_MS, syncHelper.getFirstSyncTime(calendar, timeCurrent, taskFrequencyInDay));
- timeCurrent = timeCurrent + 100;
- taskFrequencyInDay = 2;
- Calendar expCalendar = calendar;
- expCalendar.add(Calendar.DAY_OF_MONTH, taskFrequencyInDay);
- //assertEquals(expCalendar.getTimeInMillis(), syncHelper.getFirstSyncTime(calendar, calendar.getTimeInMillis() + 100, taskFrequencyInDay));
-
- }
-}
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017 Amdocs
+ * ================================================================================
+ * 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 is a trademark and service mark of AT&T Intellectual Property.
+ */
+package org.onap.aai.sparky.synchronizer;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.File;
+import java.io.IOException;
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.TimeZone;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.onap.aai.sparky.config.oxm.OxmModelLoader;
+import org.onap.aai.sparky.dal.elasticsearch.config.ElasticSearchConfig;
+import org.onap.aai.sparky.synchronizer.config.SynchronizerConfiguration;
+import org.onap.aai.sparky.synchronizer.config.SynchronizerConstants;
+import org.onap.aai.sparky.viewandinspect.config.TierSupportUiConstants;
+
+@RunWith(MockitoJUnitRunner.class)
+public class SyncHelperTest {
+
+ private SyncHelper syncHelper;
+
+ @BeforeClass
+ public static void initBeforeClass() throws IOException, NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
+ String configHomePath =
+ (new File(".").getCanonicalPath() + "/src/test/resources/appconfig/").replace('\\', '/');
+ TierSupportUiConstants.AJSC_HOME = configHomePath;
+ TierSupportUiConstants.CONFIG_HOME = configHomePath;
+ TierSupportUiConstants.DYNAMIC_CONFIG_APP_LOCATION = configHomePath;
+ ElasticSearchConfig.setConfig(null);
+ SynchronizerConfiguration.setInstance(null);
+ setFinalStatic();
+ System.setProperty("AJSC_HOME", new File(".").getCanonicalPath().replace('\\', '/'));
+ TierSupportUiConstants.DYNAMIC_CONFIG_APP_LOCATION = System.getProperty("AJSC_HOME")+"/src/test/resources/appconfig/";
+ }
+
+
+ @Test
+ public void testGetOxmModelLoader() throws Exception {
+ syncHelper = new SyncHelper(new OxmModelLoader());
+ OxmModelLoader oxmLoader = new OxmModelLoader();
+ syncHelper.setOxmModelLoader(oxmLoader);
+ assertEquals(oxmLoader, syncHelper.getOxmModelLoader());
+ }
+
+ @Test
+ public void testGetFirstSyncTime(){
+ SyncHelper syncHelper = new SyncHelper(new OxmModelLoader());
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z");
+ TimeZone tz = TimeZone.getTimeZone("05:00:00 GMT+00:00");
+ Calendar calendar = Calendar.getInstance(tz);
+ sdf.setTimeZone(tz);
+
+ calendar.set(Calendar.HOUR_OF_DAY, 1);
+ calendar.set(Calendar.MINUTE, 1);
+ calendar.set(Calendar.SECOND, 1);
+
+ long timeCurrent = calendar.getTimeInMillis();
+ int taskFrequencyInDay = 2;
+
+ assertEquals(calendar.getTimeInMillis(), syncHelper.getFirstSyncTime(calendar, timeCurrent, taskFrequencyInDay));
+ taskFrequencyInDay = 0;
+ assertEquals(SynchronizerConstants.DELAY_NO_PERIODIC_SYNC_IN_MS, syncHelper.getFirstSyncTime(calendar, timeCurrent, taskFrequencyInDay));
+ timeCurrent = timeCurrent + 100;
+ taskFrequencyInDay = 2;
+ Calendar expCalendar = calendar;
+ expCalendar.add(Calendar.DAY_OF_MONTH, taskFrequencyInDay);
+ //assertEquals(expCalendar.getTimeInMillis(), syncHelper.getFirstSyncTime(calendar, calendar.getTimeInMillis() + 100, taskFrequencyInDay));
+
+ }
+
+ static void setFinalStatic() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
+ Field configField = ElasticSearchConfig.class.getDeclaredField("CONFIG_FILE");
+ configField.setAccessible(true);
+
+ Field modifiersField = Field.class.getDeclaredField( "modifiers" );
+ modifiersField.setAccessible( true );
+ modifiersField.setInt( configField, configField.getModifiers() & ~Modifier.FINAL );
+
+ configField.set(null, System.getProperty("AJSC_HOME")+"/src/test/resources/appconfig/elasticsearch.properties");
+
+ Field syncField = SynchronizerConfiguration.class.getDeclaredField("CONFIG_FILE");
+ syncField.setAccessible(true);
+
+ Field syncModifiersField = Field.class.getDeclaredField( "modifiers" );
+ syncModifiersField.setAccessible( true );
+ syncModifiersField.setInt( syncField, syncField.getModifiers() & ~Modifier.FINAL );
+
+ syncField.set(null, System.getProperty("AJSC_HOME")+"/src/test/resources/appconfig/synchronizer.properties");
+ }
+}
diff --git a/src/test/java/org/onap/aai/sparky/util/KeystoreBuilderTest.java b/src/test/java/org/onap/aai/sparky/util/KeystoreBuilderTest.java
new file mode 100644
index 0000000..aadaff9
--- /dev/null
+++ b/src/test/java/org/onap/aai/sparky/util/KeystoreBuilderTest.java
@@ -0,0 +1,100 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017 Amdocs
+ * ================================================================================
+ * 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 is a trademark and service mark of AT&T Intellectual Property.
+ */
+package org.onap.aai.sparky.util;
+
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.net.UnknownHostException;
+import java.security.KeyManagementException;
+import java.security.KeyStoreException;
+import java.security.NoSuchAlgorithmException;
+import java.security.cert.CertificateException;
+import java.security.cert.CertificateFactory;
+import java.security.cert.X509Certificate;
+
+import javax.net.ssl.SSLSocket;
+import javax.net.ssl.SSLSocketFactory;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+import org.mockito.Matchers;
+import org.mockito.Mockito;
+
+public class KeystoreBuilderTest {
+
+ @Rule
+ public TemporaryFolder folder = new TemporaryFolder();
+
+ KeystoreBuilder ksb;
+ org.onap.aai.sparky.util.test.KeystoreBuilder ksb1;
+
+ @Before
+ public void setUp() throws IOException, NoSuchAlgorithmException {
+ System.setProperty("AJSC_HOME", new File(".").getCanonicalPath().replace('\\', '/'));
+
+ folder.newFile("file1.xml");
+ folder.newFile("file2.xml");
+
+ String endPointList = "https://localhost:9517;https://localhost:8443";
+ ksb = new KeystoreBuilder(endPointList);
+ ksb1 = new org.onap.aai.sparky.util.test.KeystoreBuilder(endPointList);
+ }
+
+ @Test(expected=IOException.class)
+ public void testUpdateKeyStore() throws KeyManagementException, KeyStoreException, CertificateException, IOException, NoSuchAlgorithmException {
+ ksb.updateKeystore(folder.getRoot().getAbsolutePath(), "password-1");
+ ksb1.updateKeystore(folder.getRoot().getAbsolutePath(), "password-1");
+ }
+
+ @Test(expected=InvocationTargetException.class)
+ public void testCertificateChainMethods() throws NoSuchMethodException, SecurityException,
+ IllegalAccessException, IllegalArgumentException, InvocationTargetException, UnknownHostException, IOException {
+ SSLSocketFactory factory = Mockito.mock(SSLSocketFactory.class);
+ SSLSocket socket = Mockito.mock(SSLSocket.class);
+ Mockito.when(factory.createSocket("localhost",9517)).thenReturn(socket);
+ Method method = KeystoreBuilder.class.getDeclaredMethod("getCertificateChainForRemoteEndpoint", String.class, int.class);
+ method.setAccessible(true);
+ X509Certificate[] certChain = (X509Certificate[])method.invoke(ksb, "localhost",9517);
+ Assert.assertNotNull(certChain);
+ }
+
+ @Test(expected=InvocationTargetException.class)
+ public void testCertificateChainMethods1() throws NoSuchMethodException, SecurityException,
+ IllegalAccessException, IllegalArgumentException, InvocationTargetException, UnknownHostException, IOException {
+ SSLSocketFactory factory = Mockito.mock(SSLSocketFactory.class);
+ SSLSocket socket = Mockito.mock(SSLSocket.class);
+ Mockito.when(factory.createSocket("localhost",9517)).thenReturn(socket);
+ Method method = org.onap.aai.sparky.util.test.KeystoreBuilder.class.getDeclaredMethod("getCertificateChainForRemoteEndpoint", String.class, int.class);
+ method.setAccessible(true);
+ X509Certificate[] certChain = (X509Certificate[])method.invoke(ksb1, "localhost",9517);
+ Assert.assertNotNull(certChain);
+ }
+
+}
diff --git a/src/test/java/org/onap/aai/sparky/viewandinspect/services/VisualizationServiceTest.java b/src/test/java/org/onap/aai/sparky/viewandinspect/services/VisualizationServiceTest.java
new file mode 100644
index 0000000..72ea1ed
--- /dev/null
+++ b/src/test/java/org/onap/aai/sparky/viewandinspect/services/VisualizationServiceTest.java
@@ -0,0 +1,111 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017 Amdocs
+ * ================================================================================
+ * 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 is a trademark and service mark of AT&T Intellectual Property.
+ */
+package org.onap.aai.sparky.viewandinspect.services;
+
+import java.io.File;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.aai.sparky.config.oxm.OxmModelLoader;
+import org.onap.aai.sparky.viewandinspect.config.TierSupportUiConstants;
+import org.onap.aai.sparky.viewandinspect.entity.QueryRequest;
+
+public class VisualizationServiceTest {
+
+ VisualizationService service;
+
+ @Before
+ public void init() throws Exception {
+ System.setProperty("AJSC_HOME", new File(".").getCanonicalPath().replace('\\', '/'));
+ TierSupportUiConstants.DYNAMIC_CONFIG_APP_LOCATION = System.getProperty("AJSC_HOME")+"/src/test/resources/appconfig/";
+ //TierSupportUiConstants.CONFIG_OXM_LOCATION = System.getProperty("AJSC_HOME")+"/bundleconfig-local/oxm/";
+ TierSupportUiConstants.STATIC_CONFIG_APP_LOCATION = System.getProperty("AJSC_HOME")+"/bundleconfig-local/etc/appprops";
+ OxmModelLoader loader = OxmModelLoader.getInstance();
+ service = new VisualizationService(loader);
+ }
+
+ @Test
+ public void testAnalyzeQueryRequestBody_InvalidQuery() {
+ QueryRequest request = service.analyzeQueryRequestBody("query-json-1");
+ Assert.assertNull(request);
+ }
+
+ @Test
+ public void testAnalyzeQueryRequestBody_ValidQuery() {
+ QueryRequest request = service.analyzeQueryRequestBody("{\"hashId\":\"hashid-1\"}");
+ Assert.assertNotNull(request);
+ }
+ @Test
+ public void testBuildVisualizationUsingGenericQuery_UnsuccessfulOperationResult() {
+ QueryRequest queryRequest = new QueryRequest();
+ queryRequest.setHashId("hash-id-1");
+ service.buildVisualizationUsingGenericQuery(queryRequest);
+ }
+
+ String queryRequest = "{\r\n" +
+ " \"variables\": [],\r\n" +
+ " \"info\": {\r\n" +
+ " \"name\": \"NamedQuery\",\r\n" +
+ " \"_postman_id\": \"8006823d-35ce-16ef-88e9-cd5b873c9e7b\",\r\n" +
+ " \"schema\": \"https://schema.getpostman.com/json/collection/v2.0.0/collection.json\"\r\n" +
+ " },\r\n" +
+ " \"item\": [\r\n" +
+ " {\r\n" +
+ " \"name\": \"https://127.0.0.1:8443/aai/v11/service-design-and-creation/named-queries/named-query/0367193e-c785-4d5f-9cb8-7bc89dc9ddb7\",\r\n" +
+ " \"request\": {\r\n" +
+ " \"url\": \"https://127.0.0.1:8443/aai/v11/service-design-and-creation/named-queries/named-query/0367193e-c785-4d5f-9cb8-7bc89dc9ddb7\",\r\n" +
+ " \"method\": \"POST\",\r\n" +
+ " \"header\": [\r\n" +
+ " {\r\n" +
+ " \"key\": \"Content-Type\",\r\n" +
+ " \"value\": \"application/json\",\r\n" +
+ " \"description\": \"\"\r\n" +
+ " },\r\n" +
+ " {\r\n" +
+ " \"key\": \"X-TransactionId\",\r\n" +
+ " \"value\": \"9999\",\r\n" +
+ " \"description\": \"\"\r\n" +
+ " },\r\n" +
+ " {\r\n" +
+ " \"key\": \"X-FromAppId\",\r\n" +
+ " \"value\": \"jimmy-postman\",\r\n" +
+ " \"description\": \"\"\r\n" +
+ " },\r\n" +
+ " {\r\n" +
+ " \"key\": \"Authorization\",\r\n" +
+ " \"value\": \"Basic QUFJOkFBSQ==\",\r\n" +
+ " \"description\": \"\"\r\n" +
+ " }\r\n" +
+ " ],\r\n" +
+ " \"body\": {\r\n" +
+ " \"mode\": \"raw\",\r\n" +
+ " \"raw\": \"{\\n \\\"named-query-uuid\\\" : \\\"0367193e-c785-4d5f-9cb8-7bc89dc9ddb7\\\",\\n \\\"named-query-name\\\" : \\\"get-component-list\\\",\\n \\\"named-query-version\\\" : \\\"1.1\\\",\\n \\\"description\\\" : \\\"Named Query - Get Component List\\\",\\n \\\"named-query-elements\\\" : {\\n \\\"named-query-element\\\" : [ {\\n \\\"property-collect-list\\\" : [ \\\"service-instance-id\\\", \\\"service-instance-name\\\" ],\\n \\\"named-query-elements\\\" : {\\n \\\"named-query-element\\\" : [ {\\n \\\"named-query-elements\\\" : {\\n \\\"named-query-element\\\" : [ {\\n \\\"relationship-list\\\" : {\\n \\\"relationship\\\" : [ {\\n \\\"related-to\\\" : \\\"model\\\",\\n \\\"relationship-data\\\" : [ {\\n \\\"relationship-key\\\" : \\\"model.model-invariant-id\\\",\\n \\\"relationship-value\\\" : \\\"1b2c9ba7-e449-4831-ba15-3073672f5ef2\\\"\\n } ]\\n } ]\\n }\\n } ]\\n },\\n \\\"relationship-list\\\" : {\\n \\\"relationship\\\" : [ {\\n \\\"related-to\\\" : \\\"model\\\",\\n \\\"relationship-data\\\" : [ {\\n \\\"relationship-key\\\" : \\\"model.model-invariant-id\\\",\\n \\\"relationship-value\\\" : \\\"3d560d81-57d0-438b-a2a1-5334dba0651a\\\"\\n } ]\\n } ]\\n }\\n }, {\\n \\\"named-query-elements\\\" : {\\n \\\"named-query-element\\\" : [ {\\n \\\"relationship-list\\\" : {\\n \\\"relationship\\\" : [ {\\n \\\"related-to\\\" : \\\"model\\\",\\n \\\"relationship-data\\\" : [ {\\n \\\"relationship-key\\\" : \\\"model.model-invariant-id\\\",\\n \\\"relationship-value\\\" : \\\"fcec1b02-b2d0-4834-aef8-d71be04717dd\\\"\\n } ]\\n } ]\\n }\\n }, {\\n \\\"named-query-elements\\\" : {\\n \\\"named-query-element\\\" : [ {\\n \\\"relationship-list\\\" : {\\n \\\"relationship\\\" : [ {\\n \\\"related-to\\\" : \\\"model\\\",\\n \\\"relationship-data\\\" : [ {\\n \\\"relationship-key\\\" : \\\"model.model-invariant-id\\\",\\n \\\"relationship-value\\\" : \\\"ff69d4e0-a8e8-4108-bdb0-dd63217e63c7\\\"\\n } ]\\n } ]\\n }\\n }, {\\n \\\"relationship-list\\\" : {\\n \\\"relationship\\\" : [ {\\n \\\"related-to\\\" : \\\"model\\\",\\n \\\"relationship-data\\\" : [ {\\n \\\"relationship-key\\\" : \\\"model.model-invariant-id\\\",\\n \\\"relationship-value\\\" : \\\"fcec1b02-b2d0-4834-aef8-d71be04717dd\\\"\\n } ]\\n } ]\\n }\\n }, {\\n \\\"named-query-elements\\\" : {\\n \\\"named-query-element\\\" : [ {\\n \\\"relationship-list\\\" : {\\n \\\"relationship\\\" : [ {\\n \\\"related-to\\\" : \\\"model\\\",\\n \\\"relationship-data\\\" : [ {\\n \\\"relationship-key\\\" : \\\"model.model-invariant-id\\\",\\n \\\"relationship-value\\\" : \\\"1b2c9ba7-e449-4831-ba15-3073672f5ef2\\\"\\n } ]\\n } ]\\n }\\n } ]\\n },\\n \\\"relationship-list\\\" : {\\n \\\"relationship\\\" : [ {\\n \\\"related-to\\\" : \\\"model\\\",\\n \\\"relationship-data\\\" : [ {\\n \\\"relationship-key\\\" : \\\"model.model-invariant-id\\\",\\n \\\"relationship-value\\\" : \\\"3d560d81-57d0-438b-a2a1-5334dba0651a\\\"\\n } ]\\n } ]\\n }\\n } ]\\n },\\n \\\"relationship-list\\\" : {\\n \\\"relationship\\\" : [ {\\n \\\"related-to\\\" : \\\"model\\\",\\n \\\"relationship-data\\\" : [ {\\n \\\"relationship-key\\\" : \\\"model.model-invariant-id\\\",\\n \\\"relationship-value\\\" : \\\"ef86f9c5-2165-44f3-8fc3-96018b609ea5\\\"\\n } ]\\n } ]\\n }\\n } ]\\n },\\n \\\"relationship-list\\\" : {\\n \\\"relationship\\\" : [ {\\n \\\"related-to\\\" : \\\"model\\\",\\n \\\"relationship-data\\\" : [ {\\n \\\"relationship-key\\\" : \\\"model.model-invariant-id\\\",\\n \\\"relationship-value\\\" : \\\"acc6edd8-a8d4-4b93-afaa-0994068be14c\\\"\\n } ]\\n } ]\\n }\\n } ]\\n },\\n \\\"relationship-list\\\" : {\\n \\\"relationship\\\" : [ {\\n \\\"related-to\\\" : \\\"model\\\",\\n \\\"relationship-data\\\" : [ {\\n \\\"relationship-key\\\" : \\\"model.model-invariant-id\\\",\\n \\\"relationship-value\\\" : \\\"82194af1-3c2c-485a-8f44-420e22a9eaa4\\\"\\n } ]\\n } ]\\n }\\n } ]\\n }\\n}\\n\"\r\n" +
+ " },\r\n" +
+ " \"description\": \"\"\r\n" +
+ " },\r\n" +
+ " \"response\": []\r\n" +
+ " }\r\n" +
+ " ]\r\n" +
+ "}";
+}