Add unit test cases to increase sonar coverage 29/24829/3
authoraditya <ag282f@att.com>
Wed, 22 Nov 2017 02:58:53 +0000 (20:58 -0600)
committeraditya <ag282f@att.com>
Wed, 22 Nov 2017 14:46:40 +0000 (08:46 -0600)
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>
src/test/java/org/onap/aai/sparky/dal/elasticsearch/ElasticSearchConfigTest.java
src/test/java/org/onap/aai/sparky/search/VnfSearchQueryBuilderTest.java [new file with mode: 0644]
src/test/java/org/onap/aai/sparky/search/VnfSearchServiceTest.java [new file with mode: 0644]
src/test/java/org/onap/aai/sparky/synchronizer/AggregationSuggestionSynchronizerTest.java [new file with mode: 0644]
src/test/java/org/onap/aai/sparky/synchronizer/SyncControllerTest.java [new file with mode: 0644]
src/test/java/org/onap/aai/sparky/synchronizer/SyncHelperTest.java
src/test/java/org/onap/aai/sparky/util/KeystoreBuilderTest.java [new file with mode: 0644]
src/test/java/org/onap/aai/sparky/viewandinspect/services/VisualizationServiceTest.java [new file with mode: 0644]

index 946d570..5de9e2f 100644 (file)
-/* 
-* ============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();
-  }
-
-}
+/**\r
+ * ============LICENSE_START=======================================================\r
+ * org.onap.aai\r
+ * ================================================================================\r
+ * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * Copyright © 2017 Amdocs\r
+ * ================================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *       http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END=========================================================\r
+ *\r
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ */\r
+\r
+package org.onap.aai.sparky.dal.elasticsearch;\r
+\r
+import static org.junit.Assert.assertEquals;\r
+import static org.junit.Assert.assertNotEquals;\r
+import static org.junit.Assert.assertNotNull;\r
+\r
+import java.io.File;\r
+import java.io.IOException;\r
+\r
+import javax.servlet.ServletException;\r
+\r
+import org.junit.Assert;\r
+import org.junit.Before;\r
+import org.junit.Ignore;\r
+import org.junit.Test;\r
+import org.mockito.Mockito;\r
+import org.onap.aai.sparky.dal.elasticsearch.config.ElasticSearchConfig;\r
+import org.onap.aai.sparky.dal.exception.ElasticSearchOperationException;\r
+\r
+import ch.qos.logback.classic.Level;\r
+\r
+/**\r
+ * The Class ElasticSearchConfigTest.\r
+ */\r
+public class ElasticSearchConfigTest {\r
+\r
+  private static final String GOOD_MAPPINGS_FILE =\r
+          "{" + "\"properties\": {" + "\"entityType\": {" + "\"type\": \"string\"" + "},"\r
+                  + "\"edgeTagQueryEntityFieldName\": {" + "\"type\": \"string\"," + "\"index\": \"no\""\r
+                  + "}," + "\"edgeTagQueryEntityFieldValue\": {" + "\"type\": \"string\","\r
+                  + "\"index\": \"no\"" + "}," + "\"searchTagIDs\" : {" + "\"type\" : \"string\"" + "},"\r
+                  + "\"searchTags\": {" + "\"type\": \"string\"," + "\"analyzer\": \"nGram_analyzer\","\r
+                  + "\"search_analyzer\": \"whitespace_analyzer\"}" + "}" + "}";\r
+\r
+  private static final String GOOD_SETTINGS_FILE = "{\"analysis\": {" + "\"filter\": {"\r
+          + "\"nGram_filter\": {" + "\"type\": \"nGram\"," + "\"min_gram\": 1," + "\"max_gram\": 50,"\r
+          + "\"token_chars\": [" + "\"letter\"," + "\"digit\"," + "\"punctuation\"," + "\"symbol\""\r
+          + "]}}," + "\"analyzer\": {" + "\"nGram_analyzer\": {" + "\"type\": \"custom\","\r
+          + "\"tokenizer\": \"whitespace\"," + "\"filter\": [" + "\"lowercase\"," + "\"asciifolding\","\r
+          + "\"nGram_filter\"]}," + "\"whitespace_analyzer\": {" + "\"type\": \"custom\","\r
+          + "\"tokenizer\": \"whitespace\"," + "\"filter\": [" + "\"lowercase\","\r
+          + "\"asciifolding\"]}}}}";\r
+\r
+  private static final String BAD_SETTINGS_FILE = "{\"analysis\": {" + "\"filter\": {"\r
+          + "\"nGram_filter\": {" + "\"type\": \"nGram\"," + "\"min_gram\": 1," + "\"max_gram\": 50,"\r
+          + "\"token_chars\": [" + "\"letter\"," + "\"digit\"," + "\"punctuation\"," + "\"symbol\""\r
+          + "]}}," + "\"analyzer\": {" + "\"nGram_analyzer\": {" + "\"type\": \"custom\","\r
+          + "\"tokenizer\": \"whitespace\"," + "\"filter\": [" + "\"lowercase\"," + "\"asciifolding\","\r
+          + "\"nGram_filter\"]}," + "\"whitespace_analyzer\": {" + "\"type\": \"custom\","\r
+          + "\"tokenizer\": \"whitespace\"," + "\"filter\": [" + "\"lowercase\","\r
+          + "\"asciifolding\"]}}";\r
+\r
+  ElasticSearchConfig elasticSearchConfig;\r
+\r
+  /**\r
+   * Inits the.\r
+   *\r
+   * @throws Exception the exception\r
+   */\r
+  @Before\r
+  public void init() throws Exception {\r
+    elasticSearchConfig = Mockito.spy(new ElasticSearchConfig());\r
+  }\r
+\r
+  /**\r
+   * Validate accessors.\r
+   *\r
+   * @throws IOException Signals that an I/O exception has occurred.\r
+   * @throws ServletException the servlet exception\r
+   * @throws Exception the exception\r
+   */\r
+  @Test\r
+  public void validateAccessors() throws IOException, ServletException, Exception {\r
+\r
+    ElasticSearchConfig esConfig = new ElasticSearchConfig();\r
+\r
+    esConfig.setIpAddress("47.248.10.127");\r
+    esConfig.setHttpPort("8123");\r
+    esConfig.setJavaApiPort("9123");\r
+    esConfig.setIndexName("myIndexName");\r
+    esConfig.setType("myIndexTableType");\r
+    esConfig.setClusterName("ES_AAI_DEV");\r
+    esConfig.setMappingsFileName("d:\\1\\mappings.json");\r
+    esConfig.setSettingsFileName("d:\\1\\settings.json");\r
+    esConfig.setAuditIndexName("auditIndexName");\r
+\r
+    ElasticSearchConfig.setConfig(esConfig);\r
+\r
+    assertEquals(esConfig.getIpAddress(), "47.248.10.127");\r
+    assertEquals(esConfig.getHttpPort(), "8123");\r
+    assertEquals(esConfig.getJavaApiPort(), "9123");\r
+    assertEquals(esConfig.getIndexName(), "myIndexName");\r
+    assertEquals(esConfig.getType(), "myIndexTableType");\r
+    assertEquals(esConfig.getClusterName(), "ES_AAI_DEV");\r
+    assertEquals(esConfig.getMappingsFileName(), "d:\\1\\mappings.json");\r
+    assertEquals(esConfig.getSettingsFileName(), "d:\\1\\settings.json");\r
+    assertEquals(esConfig.getAuditIndexName(), "auditIndexName");\r
+\r
+    String output = esConfig.toString();\r
+\r
+    assertNotEquals(output, null);\r
+\r
+  }\r
+\r
+  /**\r
+   * Gets the elastic search settings expect valid config.\r
+   *\r
+   * @return the elastic search settings expect valid config\r
+   * @throws IOException Signals that an I/O exception has occurred.\r
+   * @throws ElasticSearchOperationException the elastic search operation exception\r
+   * Need to revisit this test case and change the way this class works\r
+   */\r
+  @Ignore\r
+  public void getElasticSearchSettings_expectValidConfig()\r
+          throws IOException, ElasticSearchOperationException {\r
+    System.setProperty("AJSC_HOME", new File(".").getCanonicalPath().replace('\\', '/'));\r
+\r
+    ElasticSearchConfig esConfig = new ElasticSearchConfig();\r
+\r
+    esConfig.setSettingsFileName("src/main/config/es_settings.json");\r
+\r
+    assertNotNull(esConfig.getElasticSearchSettings());\r
+  }\r
+\r
+  /**\r
+   * Gets the elastic search settings expect file not found exception.\r
+   *\r
+   * @return the elastic search settings expect file not found exception\r
+   * @throws IOException Signals that an I/O exception has occurred.\r
+   * @throws ElasticSearchOperationException the elastic search operation exception\r
+   *\r
+   * Need to revisit this test case and change the way this class works\r
+   */\r
+  @Ignore\r
+  public void getElasticSearchSettings_expectFileNotFoundException()\r
+          throws IOException, ElasticSearchOperationException {\r
+    System.setProperty("AJSC_HOME", new File(".").getCanonicalPath().replace('\\', '/'));\r
+\r
+    ElasticSearchConfig esConfig = new ElasticSearchConfig();\r
+\r
+    esConfig.setSettingsFileName("src/main/config/es_setting.json");\r
+\r
+    esConfig.getElasticSearchSettings();\r
+\r
+  }\r
+\r
+  /**\r
+   * Gets the elastic search mappings expect valid config.\r
+   *\r
+   * @return the elastic search mappings expect valid config\r
+   * @throws IOException Signals that an I/O exception has occurred.\r
+   * @throws ElasticSearchOperationException the elastic search operation exception\r
+   *\r
+   * Need to revisit this test case and change the way this class works\r
+   */\r
+  @Ignore\r
+  public void getElasticSearchMappings_expectValidConfig()\r
+          throws IOException, ElasticSearchOperationException {\r
+    System.setProperty("AJSC_HOME", new File(".").getCanonicalPath().replace('\\', '/'));\r
+\r
+    ElasticSearchConfig esConfig = new ElasticSearchConfig();\r
+\r
+    esConfig.setMappingsFileName("src/main/config/es_mappings.json");\r
+\r
+    assertNotNull(esConfig.getElasticSearchMappings());\r
+  }\r
+\r
+  /**\r
+   * Gets the elastic search mappings expect file not found exception.\r
+   *\r
+   * @return the elastic search mappings expect file not found exception\r
+   * @throws IOException Signals that an I/O exception has occurred.\r
+   * @throws ElasticSearchOperationException the elastic search operation exception\r
+   */\r
+  @Test(expected = ElasticSearchOperationException.class)\r
+  public void getElasticSearchMappings_expectFileNotFoundException()\r
+          throws IOException, ElasticSearchOperationException {\r
+    System.setProperty("AJSC_HOME", new File(".").getCanonicalPath().replace('\\', '/'));\r
+\r
+    ElasticSearchConfig esConfig = new ElasticSearchConfig();\r
+\r
+    esConfig.setSettingsFileName("src/main/config/es_setting.json");\r
+\r
+    esConfig.getElasticSearchMappings();\r
+\r
+  }\r
+\r
+  /**\r
+   * Builds the elastic search table config expect valid result.\r
+   *\r
+   * @throws ElasticSearchOperationException the elastic search operation exception\r
+   * @throws IOException Signals that an I/O exception has occurred.\r
+   */\r
+  @Test\r
+  public void buildElasticSearchTableConfig_expectValidResult()\r
+          throws ElasticSearchOperationException, IOException {\r
+    ElasticSearchConfig spyEsConfig = Mockito.spy(new ElasticSearchConfig());\r
+    Mockito.doReturn(GOOD_MAPPINGS_FILE).when(spyEsConfig).getElasticSearchMappings();\r
+    Mockito.doReturn(GOOD_SETTINGS_FILE).when(spyEsConfig).getElasticSearchSettings();\r
+    Mockito.doReturn("myIndexTableType").when(spyEsConfig).getType();\r
+\r
+    assertNotNull(spyEsConfig.buildElasticSearchTableConfig());\r
+  }\r
+\r
+  /**\r
+   * Builds the elastic search table config expect exception.\r
+   *\r
+   * @throws ElasticSearchOperationException the elastic search operation exception\r
+   * @throws IOException Signals that an I/O exception has occurred.\r
+   */\r
+  @Test(expected = ElasticSearchOperationException.class)\r
+  public void buildElasticSearchTableConfig_expectException()\r
+          throws ElasticSearchOperationException, IOException {\r
+    ElasticSearchConfig spyEsConfig = Mockito.spy(new ElasticSearchConfig());\r
+    Mockito.doReturn(GOOD_MAPPINGS_FILE).when(spyEsConfig).getElasticSearchMappings();\r
+    Mockito.doReturn(BAD_SETTINGS_FILE).when(spyEsConfig).getElasticSearchSettings();\r
+    Mockito.doReturn("myIndexTableType").when(spyEsConfig).getType();\r
+\r
+    spyEsConfig.buildElasticSearchTableConfig();\r
+  }\r
+\r
+  @Test\r
+  public void testGetFullUrl_ThreeParams() throws Exception {\r
+    Mockito.when(elasticSearchConfig.getIpAddress()).thenReturn("http://localhost");\r
+    Mockito.when(elasticSearchConfig.getHttpPort()).thenReturn("5443");\r
+    String fullUrl = elasticSearchConfig.getElasticFullUrl("http://localhost:5443/aai/model/index", "entity-index", "entity");\r
+    Assert.assertNotNull(fullUrl);\r
+  }\r
+\r
+  @Test\r
+  public void testGetFullUrl_OneParam() throws Exception {\r
+    Mockito.when(elasticSearchConfig.getIpAddress()).thenReturn("http://localhost");\r
+    Mockito.when(elasticSearchConfig.getHttpPort()).thenReturn("5443");\r
+    Mockito.when(elasticSearchConfig.getIndexName()).thenReturn("entity");\r
+    String fullUrl = elasticSearchConfig.getElasticFullUrl("http://localhost:5443/aai/model/index");\r
+    Assert.assertNotNull(fullUrl);\r
+  }\r
+\r
+  @Test\r
+  public void testGetBulkUrl()  throws Exception {\r
+    Mockito.when(elasticSearchConfig.getIpAddress()).thenReturn("http://localhost");\r
+    Mockito.when(elasticSearchConfig.getHttpPort()).thenReturn("5443");\r
+    String fullUrl = elasticSearchConfig.getBulkUrl();\r
+    Assert.assertNotNull(fullUrl);\r
+  }\r
+\r
+  @Test\r
+  public void testGetConfigAsString() throws IOException, ElasticSearchOperationException {\r
+    System.setProperty("AJSC_HOME", new File(".").getCanonicalPath().replace('\\', '/'));\r
+    String retStr = elasticSearchConfig.getConfigAsString("item-1", System.getProperty("AJSC_HOME")+"/src/test/resources/appconfig/roles.config");\r
+    Assert.assertNotNull(retStr);\r
+  }\r
+\r
+}\r
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 (file)
index 0000000..19a0a3a
--- /dev/null
@@ -0,0 +1,75 @@
+/**\r
+ * ============LICENSE_START=======================================================\r
+ * org.onap.aai\r
+ * ================================================================================\r
+ * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * Copyright © 2017 Amdocs\r
+ * ================================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *       http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END=========================================================\r
+ *\r
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ */\r
+package org.onap.aai.sparky.search;\r
+\r
+import java.util.HashMap;\r
+import java.util.Map;\r
+\r
+import javax.json.JsonArray;\r
+import javax.json.JsonObject;\r
+\r
+import org.junit.Assert;\r
+import org.junit.Test;\r
+import org.onap.aai.sparky.search.VnfSearchQueryBuilder;\r
+\r
+public class VnfSearchQueryBuilderTest {\r
+\r
+       @Test\r
+       public void testCreateSuggestionsQuery() {\r
+               String maxResults = "maxResults-1";\r
+               String queryStr = "queryStr-1";\r
+               JsonObject object = VnfSearchQueryBuilder.createSuggestionsQuery(maxResults, queryStr);\r
+               Assert.assertNotNull(object);\r
+       }\r
+       \r
+       @Test\r
+       public void testSortCriteria() {\r
+               JsonArray array = VnfSearchQueryBuilder.getSortCriteria("field-1", "sortOrder-1");\r
+               Assert.assertNotNull(array);\r
+       }\r
+       \r
+       @Test\r
+       public void testCreateEntityCountsQuery_SingleAttribute() {\r
+               Map<String, String> attributes = new HashMap<>();\r
+               attributes.put("key-1", "value-1");\r
+               JsonObject object = VnfSearchQueryBuilder.createEntityCountsQuery(attributes);\r
+               Assert.assertNotNull(object);\r
+       }\r
+       \r
+       @Test\r
+       public void testCreateSummaryByEntityTypeQuery_Single() {\r
+               Map<String, String> attributes = new HashMap<>();\r
+               attributes.put("key-1", "value-1");\r
+               JsonObject object = VnfSearchQueryBuilder.createSummaryByEntityTypeQuery(attributes, "groupkey-1");\r
+               Assert.assertNotNull(object);\r
+       }\r
+       \r
+       @Test\r
+       public void testCreateSummaryByEntityTypeQuery_Multiple() {\r
+               Map<String, String> attributes = new HashMap<>();\r
+               attributes.put("key-1", "value-1");\r
+               attributes.put("key-2", "value-2");\r
+               JsonObject object = VnfSearchQueryBuilder.createSummaryByEntityTypeQuery(attributes, "groupkey-1");\r
+               Assert.assertNotNull(object);\r
+       }\r
+}\r
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 (file)
index 0000000..8c4d59d
--- /dev/null
@@ -0,0 +1,89 @@
+/**\r
+ * ============LICENSE_START=======================================================\r
+ * org.onap.aai\r
+ * ================================================================================\r
+ * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * Copyright © 2017 Amdocs\r
+ * ================================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *       http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END=========================================================\r
+ *\r
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ */\r
+package org.onap.aai.sparky.search;\r
+\r
+import java.io.File;\r
+import java.io.IOException;\r
+import java.io.PrintWriter;\r
+import java.lang.reflect.Field;\r
+import java.lang.reflect.Modifier;\r
+\r
+import javax.servlet.http.HttpServletResponse;\r
+\r
+import org.junit.Before;\r
+import org.junit.Test;\r
+import org.mockito.Mockito;\r
+import org.onap.aai.sparky.dal.elasticsearch.SearchAdapter;\r
+import org.onap.aai.sparky.dal.elasticsearch.config.ElasticSearchConfig;\r
+import org.onap.aai.sparky.dal.rest.OperationResult;\r
+import org.onap.aai.sparky.viewandinspect.config.TierSupportUiConstants;\r
+import org.onap.aai.sparky.viewandinspect.entity.QuerySearchEntity;\r
+\r
+public class VnfSearchServiceTest {\r
+\r
+       VnfSearchService searchService;\r
+       \r
+       @Before\r
+       public void init() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException, IOException {\r
+               System.setProperty("AJSC_HOME", new File(".").getCanonicalPath().replace('\\', '/'));\r
+           TierSupportUiConstants.DYNAMIC_CONFIG_APP_LOCATION = System.getProperty("AJSC_HOME")+"/src/test/resources/appconfig/";\r
+               ElasticSearchConfig.setConfig(null);\r
+        setFinalStatic();       \r
+               searchService = new VnfSearchService();\r
+       }\r
+       @Test\r
+       public void testSetZeroCountResponse() throws IOException {\r
+               HttpServletResponse response = Mockito.mock(HttpServletResponse.class);\r
+               Mockito.doNothing().when(response).setStatus(1);\r
+               Mockito.doNothing().when(response).setContentType(Mockito.anyString());\r
+               PrintWriter writer = Mockito.mock(PrintWriter.class);\r
+               Mockito.doNothing().when(writer).println(Mockito.anyString());\r
+               Mockito.doNothing().when(writer).close();\r
+               Mockito.when(response.getWriter()).thenReturn(writer);\r
+               searchService.setZeroCountResponse(response);\r
+       }\r
+       \r
+       @Test\r
+       public void testSetEmptyAggResponse() throws IOException {\r
+               HttpServletResponse response = Mockito.mock(HttpServletResponse.class);\r
+               Mockito.doNothing().when(response).setStatus(1);\r
+               Mockito.doNothing().when(response).setContentType(Mockito.anyString());\r
+               PrintWriter writer = Mockito.mock(PrintWriter.class);\r
+               Mockito.doNothing().when(writer).println(Mockito.anyString());\r
+               Mockito.doNothing().when(writer).close();\r
+               Mockito.when(response.getWriter()).thenReturn(writer);\r
+               searchService.setEmptyAggResponse(response);\r
+       }\r
+       \r
+               \r
+       static void setFinalStatic() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {\r
+               Field configField = ElasticSearchConfig.class.getDeclaredField("CONFIG_FILE");\r
+               configField.setAccessible(true);\r
+\r
+               Field modifiersField = Field.class.getDeclaredField( "modifiers" );\r
+               modifiersField.setAccessible( true );\r
+               modifiersField.setInt( configField, configField.getModifiers() & ~Modifier.FINAL );\r
+\r
+               configField.set(null, System.getProperty("AJSC_HOME")+"/src/test/resources/appconfig/elasticsearch.properties");\r
+       }\r
+}\r
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 (file)
index 0000000..e590af6
--- /dev/null
@@ -0,0 +1,86 @@
+/**\r
+ * ============LICENSE_START=======================================================\r
+ * org.onap.aai\r
+ * ================================================================================\r
+ * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * Copyright © 2017 Amdocs\r
+ * ================================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *       http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END=========================================================\r
+ *\r
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ */\r
+package org.onap.aai.sparky.synchronizer;\r
+\r
+import java.io.File;\r
+import java.io.IOException;\r
+import java.lang.reflect.Field;\r
+import java.lang.reflect.Modifier;\r
+\r
+import org.junit.Assert;\r
+import org.junit.Before;\r
+import org.junit.Test;\r
+import org.onap.aai.sparky.dal.NetworkTransaction;\r
+import org.onap.aai.sparky.dal.elasticsearch.config.ElasticSearchConfig;\r
+import org.onap.aai.sparky.dal.rest.HttpMethod;\r
+import org.onap.aai.sparky.dal.rest.OperationResult;\r
+import org.onap.aai.sparky.synchronizer.enumeration.OperationState;\r
+import org.onap.aai.sparky.synchronizer.enumeration.SynchronizerState;\r
+import org.onap.aai.sparky.viewandinspect.config.TierSupportUiConstants;\r
+\r
+public class AggregationSuggestionSynchronizerTest {\r
+\r
+       @Before\r
+       public void init() throws IOException {\r
+               System.setProperty("AJSC_HOME", new File(".").getCanonicalPath().replace('\\', '/'));\r
+           TierSupportUiConstants.DYNAMIC_CONFIG_APP_LOCATION = System.getProperty("AJSC_HOME")+"/src/test/resources/appconfig/";\r
+          // TierSupportUiConstants.CONFIG_OXM_LOCATION = System.getProperty("AJSC_HOME")+"/bundleconfig-local/oxm/";\r
+       }\r
+       \r
+       @Test\r
+       public void testDoSync() throws Exception {\r
+        ElasticSearchConfig.setConfig(null);\r
+        setFinalStatic();\r
+               AggregationSuggestionSynchronizer ass = new AggregationSuggestionSynchronizer("entity-search-index");\r
+               Assert.assertNotNull(ass);\r
+               OperationState state = ass.doSync();\r
+               Assert.assertEquals(OperationState.OK, state);\r
+\r
+        OperationResult result = new OperationResult();\r
+        result.setResultCode(200);\r
+        result.setResult("result-1");\r
+        result.setNumRequestRetries(1);\r
+        NetworkTransaction ntwTxn = new NetworkTransaction(HttpMethod.GET, "entity-1", result);\r
+        ass.updateElasticSearchCounters(ntwTxn);\r
+\r
+               SynchronizerState syncState = ass.getState();\r
+               Assert.assertEquals(SynchronizerState.IDLE, syncState);\r
+               \r
+               String statReport = ass.getStatReport(true);\r
+               Assert.assertNotNull(statReport);\r
+               Assert.assertTrue(statReport.contains("Aggregation Suggestion Synchronizer"));\r
+               \r
+               ass.shutdown();\r
+       }\r
+\r
+       static void setFinalStatic() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {\r
+               Field configField = ElasticSearchConfig.class.getDeclaredField("CONFIG_FILE");\r
+               configField.setAccessible(true);\r
+\r
+               Field modifiersField = Field.class.getDeclaredField( "modifiers" );\r
+               modifiersField.setAccessible( true );\r
+               modifiersField.setInt( configField, configField.getModifiers() & ~Modifier.FINAL );\r
+\r
+               configField.set(null, System.getProperty("AJSC_HOME")+"/src/test/resources/appconfig/elasticsearch.properties");\r
+       }\r
+}\r
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 (file)
index 0000000..c7464d3
--- /dev/null
@@ -0,0 +1,81 @@
+/**\r
+ * ============LICENSE_START=======================================================\r
+ * org.onap.aai\r
+ * ================================================================================\r
+ * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * Copyright © 2017 Amdocs\r
+ * ================================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *       http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END=========================================================\r
+ *\r
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ */\r
+package org.onap.aai.sparky.synchronizer;\r
+\r
+import org.junit.Before;\r
+import org.junit.Test;\r
+import org.mockito.Mockito;\r
+import org.onap.aai.sparky.synchronizer.SyncController.SyncActions;\r
+\r
+public class SyncControllerTest {\r
+\r
+       SyncController controller;\r
+\r
+       @Before\r
+       public void init() throws Exception {\r
+               controller = new SyncController("name-1");\r
+       }\r
+       @Test\r
+       public void testPerformAction_PreSync() {\r
+               controller.performAction(SyncActions.SYNCHRONIZE);\r
+               controller.shutdown();\r
+       }\r
+\r
+       @Test\r
+       public void testRegisterIndexCleaner_NullIndexName() {\r
+               IndexCleaner cleaner = new ElasticSearchIndexCleaner(null, null, "index_type-1", "host-1", "port-1", 1, 1);\r
+               controller.registerIndexCleaner(cleaner);\r
+       }\r
+\r
+       @Test\r
+       public void testRegisterIndexCleaner_NotNullIndexName() {\r
+               IndexCleaner cleaner = new ElasticSearchIndexCleaner(null, "index-1", "index_type-1", "host-1", "port-1", 1, 1);\r
+               controller.registerIndexCleaner(cleaner);\r
+       }\r
+\r
+       @Test\r
+       public void testRegisterIndexValidator_NullIndexValidator() {\r
+               IndexValidator validator = new IndexIntegrityValidator(null, null, "index_type-1", "host-1", "port-1", "json-1");\r
+               controller.registerIndexValidator(validator);\r
+       }\r
+\r
+       @Test\r
+       public void testRegisterIndexValidator_NotNullIndexValidator() {\r
+               IndexValidator validator = new IndexIntegrityValidator(null, "index-1", "index_type-1", "host-1", "port-1", "json-1");\r
+               controller.registerIndexValidator(validator);\r
+       }\r
+\r
+       @Test\r
+       public void testRegisterEntitySynchronizer_NullEntitySynchronizer() throws Exception {\r
+               IndexSynchronizer synchroniser = Mockito.mock(SearchableEntitySynchronizer.class);\r
+               Mockito.when(synchroniser.getIndexName()).thenReturn(null);\r
+               controller.registerEntitySynchronizer(synchroniser);\r
+       }\r
+\r
+       @Test\r
+       public void testRegisterEntitySynchronizer_NotNullEntitySynchronizer() throws Exception {\r
+               IndexSynchronizer synchroniser = Mockito.mock(SearchableEntitySynchronizer.class);\r
+               Mockito.when(synchroniser.getIndexName()).thenReturn("entity-1");\r
+               controller.registerEntitySynchronizer(synchroniser);\r
+       }\r
+}\r
index 460bdf0..5a2584f 100644 (file)
-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));
-    
-  }
-}
+/**\r
+ * ============LICENSE_START=======================================================\r
+ * org.onap.aai\r
+ * ================================================================================\r
+ * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * Copyright © 2017 Amdocs\r
+ * ================================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *       http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END=========================================================\r
+ *\r
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ */\r
+package org.onap.aai.sparky.synchronizer;\r
+\r
+import static org.junit.Assert.assertEquals;\r
+\r
+import java.io.File;\r
+import java.io.IOException;\r
+import java.lang.reflect.Field;\r
+import java.lang.reflect.Modifier;\r
+import java.text.SimpleDateFormat;\r
+import java.util.Calendar;\r
+import java.util.TimeZone;\r
+\r
+import org.junit.BeforeClass;\r
+import org.junit.Test;\r
+import org.junit.runner.RunWith;\r
+import org.mockito.runners.MockitoJUnitRunner;\r
+import org.onap.aai.sparky.config.oxm.OxmModelLoader;\r
+import org.onap.aai.sparky.dal.elasticsearch.config.ElasticSearchConfig;\r
+import org.onap.aai.sparky.synchronizer.config.SynchronizerConfiguration;\r
+import org.onap.aai.sparky.synchronizer.config.SynchronizerConstants;\r
+import org.onap.aai.sparky.viewandinspect.config.TierSupportUiConstants;\r
+\r
+@RunWith(MockitoJUnitRunner.class)\r
+public class SyncHelperTest {\r
+\r
+    private SyncHelper syncHelper;\r
+\r
+    @BeforeClass\r
+    public static void initBeforeClass() throws IOException, NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {\r
+        String configHomePath =\r
+                (new File(".").getCanonicalPath() + "/src/test/resources/appconfig/").replace('\\', '/');\r
+        TierSupportUiConstants.AJSC_HOME = configHomePath;\r
+        TierSupportUiConstants.CONFIG_HOME = configHomePath;\r
+        TierSupportUiConstants.DYNAMIC_CONFIG_APP_LOCATION = configHomePath;\r
+        ElasticSearchConfig.setConfig(null);\r
+        SynchronizerConfiguration.setInstance(null);\r
+        setFinalStatic();\r
+        System.setProperty("AJSC_HOME", new File(".").getCanonicalPath().replace('\\', '/'));\r
+        TierSupportUiConstants.DYNAMIC_CONFIG_APP_LOCATION = System.getProperty("AJSC_HOME")+"/src/test/resources/appconfig/";\r
+    }\r
+\r
+\r
+    @Test\r
+    public void testGetOxmModelLoader() throws Exception {\r
+        syncHelper = new SyncHelper(new OxmModelLoader());\r
+        OxmModelLoader oxmLoader = new OxmModelLoader();\r
+        syncHelper.setOxmModelLoader(oxmLoader);\r
+        assertEquals(oxmLoader, syncHelper.getOxmModelLoader());\r
+    }\r
+\r
+    @Test\r
+    public void testGetFirstSyncTime(){\r
+        SyncHelper syncHelper = new SyncHelper(new OxmModelLoader());\r
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z");\r
+        TimeZone tz = TimeZone.getTimeZone("05:00:00 GMT+00:00");\r
+        Calendar calendar = Calendar.getInstance(tz);\r
+        sdf.setTimeZone(tz);\r
+\r
+        calendar.set(Calendar.HOUR_OF_DAY, 1);\r
+        calendar.set(Calendar.MINUTE, 1);\r
+        calendar.set(Calendar.SECOND, 1);\r
+\r
+        long timeCurrent = calendar.getTimeInMillis();\r
+        int taskFrequencyInDay = 2;\r
+\r
+        assertEquals(calendar.getTimeInMillis(), syncHelper.getFirstSyncTime(calendar, timeCurrent, taskFrequencyInDay));\r
+        taskFrequencyInDay = 0;\r
+        assertEquals(SynchronizerConstants.DELAY_NO_PERIODIC_SYNC_IN_MS, syncHelper.getFirstSyncTime(calendar, timeCurrent, taskFrequencyInDay));\r
+        timeCurrent = timeCurrent + 100;\r
+        taskFrequencyInDay = 2;\r
+        Calendar expCalendar = calendar;\r
+        expCalendar.add(Calendar.DAY_OF_MONTH, taskFrequencyInDay);\r
+        //assertEquals(expCalendar.getTimeInMillis(), syncHelper.getFirstSyncTime(calendar, calendar.getTimeInMillis() + 100, taskFrequencyInDay));\r
+\r
+    }\r
+\r
+    static void setFinalStatic() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {\r
+        Field configField = ElasticSearchConfig.class.getDeclaredField("CONFIG_FILE");\r
+        configField.setAccessible(true);\r
+\r
+        Field modifiersField = Field.class.getDeclaredField( "modifiers" );\r
+        modifiersField.setAccessible( true );\r
+        modifiersField.setInt( configField, configField.getModifiers() & ~Modifier.FINAL );\r
+\r
+        configField.set(null, System.getProperty("AJSC_HOME")+"/src/test/resources/appconfig/elasticsearch.properties");\r
+\r
+        Field syncField = SynchronizerConfiguration.class.getDeclaredField("CONFIG_FILE");\r
+        syncField.setAccessible(true);\r
+\r
+        Field syncModifiersField = Field.class.getDeclaredField( "modifiers" );\r
+        syncModifiersField.setAccessible( true );\r
+        syncModifiersField.setInt( syncField, syncField.getModifiers() & ~Modifier.FINAL );\r
+\r
+        syncField.set(null, System.getProperty("AJSC_HOME")+"/src/test/resources/appconfig/synchronizer.properties");\r
+    }\r
+}\r
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 (file)
index 0000000..aadaff9
--- /dev/null
@@ -0,0 +1,100 @@
+/**\r
+ * ============LICENSE_START=======================================================\r
+ * org.onap.aai\r
+ * ================================================================================\r
+ * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * Copyright © 2017 Amdocs\r
+ * ================================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *       http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END=========================================================\r
+ *\r
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ */\r
+package org.onap.aai.sparky.util;\r
+\r
+import java.io.ByteArrayInputStream;\r
+import java.io.File;\r
+import java.io.IOException;\r
+import java.io.InputStream;\r
+import java.lang.reflect.InvocationTargetException;\r
+import java.lang.reflect.Method;\r
+import java.net.UnknownHostException;\r
+import java.security.KeyManagementException;\r
+import java.security.KeyStoreException;\r
+import java.security.NoSuchAlgorithmException;\r
+import java.security.cert.CertificateException;\r
+import java.security.cert.CertificateFactory;\r
+import java.security.cert.X509Certificate;\r
+\r
+import javax.net.ssl.SSLSocket;\r
+import javax.net.ssl.SSLSocketFactory;\r
+\r
+import org.junit.Assert;\r
+import org.junit.Before;\r
+import org.junit.Rule;\r
+import org.junit.Test;\r
+import org.junit.rules.TemporaryFolder;\r
+import org.mockito.Matchers;\r
+import org.mockito.Mockito;\r
+\r
+public class KeystoreBuilderTest {\r
+\r
+       @Rule\r
+       public TemporaryFolder folder = new TemporaryFolder();\r
+\r
+       KeystoreBuilder ksb;\r
+       org.onap.aai.sparky.util.test.KeystoreBuilder ksb1;\r
+\r
+       @Before\r
+       public void setUp() throws IOException, NoSuchAlgorithmException {\r
+               System.setProperty("AJSC_HOME", new File(".").getCanonicalPath().replace('\\', '/'));\r
+\r
+               folder.newFile("file1.xml");\r
+               folder.newFile("file2.xml");\r
+\r
+               String endPointList = "https://localhost:9517;https://localhost:8443";\r
+               ksb = new KeystoreBuilder(endPointList);\r
+               ksb1 = new org.onap.aai.sparky.util.test.KeystoreBuilder(endPointList);\r
+       }\r
+\r
+       @Test(expected=IOException.class)\r
+       public void testUpdateKeyStore() throws KeyManagementException, KeyStoreException, CertificateException, IOException, NoSuchAlgorithmException {\r
+               ksb.updateKeystore(folder.getRoot().getAbsolutePath(), "password-1");\r
+               ksb1.updateKeystore(folder.getRoot().getAbsolutePath(), "password-1");\r
+       }\r
+\r
+       @Test(expected=InvocationTargetException.class)\r
+       public void testCertificateChainMethods() throws NoSuchMethodException, SecurityException,\r
+                       IllegalAccessException, IllegalArgumentException, InvocationTargetException, UnknownHostException, IOException {\r
+               SSLSocketFactory factory = Mockito.mock(SSLSocketFactory.class);\r
+               SSLSocket socket = Mockito.mock(SSLSocket.class);\r
+               Mockito.when(factory.createSocket("localhost",9517)).thenReturn(socket);\r
+               Method method = KeystoreBuilder.class.getDeclaredMethod("getCertificateChainForRemoteEndpoint", String.class, int.class);\r
+               method.setAccessible(true);\r
+               X509Certificate[] certChain = (X509Certificate[])method.invoke(ksb, "localhost",9517);\r
+               Assert.assertNotNull(certChain);\r
+       }\r
+\r
+       @Test(expected=InvocationTargetException.class)\r
+       public void testCertificateChainMethods1() throws NoSuchMethodException, SecurityException,\r
+                       IllegalAccessException, IllegalArgumentException, InvocationTargetException, UnknownHostException, IOException {\r
+               SSLSocketFactory factory = Mockito.mock(SSLSocketFactory.class);\r
+               SSLSocket socket = Mockito.mock(SSLSocket.class);\r
+               Mockito.when(factory.createSocket("localhost",9517)).thenReturn(socket);\r
+               Method method = org.onap.aai.sparky.util.test.KeystoreBuilder.class.getDeclaredMethod("getCertificateChainForRemoteEndpoint", String.class, int.class);\r
+               method.setAccessible(true);\r
+               X509Certificate[] certChain = (X509Certificate[])method.invoke(ksb1, "localhost",9517);\r
+               Assert.assertNotNull(certChain);\r
+       }\r
+\r
+}\r
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 (file)
index 0000000..72ea1ed
--- /dev/null
@@ -0,0 +1,111 @@
+/**\r
+ * ============LICENSE_START=======================================================\r
+ * org.onap.aai\r
+ * ================================================================================\r
+ * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * Copyright © 2017 Amdocs\r
+ * ================================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *       http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END=========================================================\r
+ *\r
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ */\r
+package org.onap.aai.sparky.viewandinspect.services;\r
+\r
+import java.io.File;\r
+\r
+import org.junit.Assert;\r
+import org.junit.Before;\r
+import org.junit.Test;\r
+import org.onap.aai.sparky.config.oxm.OxmModelLoader;\r
+import org.onap.aai.sparky.viewandinspect.config.TierSupportUiConstants;\r
+import org.onap.aai.sparky.viewandinspect.entity.QueryRequest;\r
+\r
+public class VisualizationServiceTest {\r
+\r
+       VisualizationService service;\r
+       \r
+       @Before\r
+       public void init() throws Exception {\r
+               System.setProperty("AJSC_HOME", new File(".").getCanonicalPath().replace('\\', '/'));\r
+           TierSupportUiConstants.DYNAMIC_CONFIG_APP_LOCATION = System.getProperty("AJSC_HOME")+"/src/test/resources/appconfig/";\r
+           //TierSupportUiConstants.CONFIG_OXM_LOCATION = System.getProperty("AJSC_HOME")+"/bundleconfig-local/oxm/";\r
+           TierSupportUiConstants.STATIC_CONFIG_APP_LOCATION = System.getProperty("AJSC_HOME")+"/bundleconfig-local/etc/appprops";\r
+               OxmModelLoader loader = OxmModelLoader.getInstance();\r
+               service = new VisualizationService(loader);\r
+       }\r
+       \r
+       @Test\r
+       public void testAnalyzeQueryRequestBody_InvalidQuery() {\r
+               QueryRequest request = service.analyzeQueryRequestBody("query-json-1");\r
+               Assert.assertNull(request);\r
+       }\r
+       \r
+       @Test\r
+       public void testAnalyzeQueryRequestBody_ValidQuery() {\r
+               QueryRequest request = service.analyzeQueryRequestBody("{\"hashId\":\"hashid-1\"}");\r
+               Assert.assertNotNull(request);\r
+       }\r
+       @Test\r
+       public void testBuildVisualizationUsingGenericQuery_UnsuccessfulOperationResult() {\r
+               QueryRequest queryRequest = new QueryRequest();\r
+               queryRequest.setHashId("hash-id-1");\r
+               service.buildVisualizationUsingGenericQuery(queryRequest);\r
+       }\r
+\r
+       String queryRequest = "{\r\n" + \r
+                       "       \"variables\": [],\r\n" + \r
+                       "       \"info\": {\r\n" + \r
+                       "               \"name\": \"NamedQuery\",\r\n" + \r
+                       "               \"_postman_id\": \"8006823d-35ce-16ef-88e9-cd5b873c9e7b\",\r\n" + \r
+                       "               \"schema\": \"https://schema.getpostman.com/json/collection/v2.0.0/collection.json\"\r\n" + \r
+                       "       },\r\n" + \r
+                       "       \"item\": [\r\n" + \r
+                       "               {\r\n" + \r
+                       "                       \"name\": \"https://127.0.0.1:8443/aai/v11/service-design-and-creation/named-queries/named-query/0367193e-c785-4d5f-9cb8-7bc89dc9ddb7\",\r\n" + \r
+                       "                       \"request\": {\r\n" + \r
+                       "                               \"url\": \"https://127.0.0.1:8443/aai/v11/service-design-and-creation/named-queries/named-query/0367193e-c785-4d5f-9cb8-7bc89dc9ddb7\",\r\n" + \r
+                       "                               \"method\": \"POST\",\r\n" + \r
+                       "                               \"header\": [\r\n" + \r
+                       "                                       {\r\n" + \r
+                       "                                               \"key\": \"Content-Type\",\r\n" + \r
+                       "                                               \"value\": \"application/json\",\r\n" + \r
+                       "                                               \"description\": \"\"\r\n" + \r
+                       "                                       },\r\n" + \r
+                       "                                       {\r\n" + \r
+                       "                                               \"key\": \"X-TransactionId\",\r\n" + \r
+                       "                                               \"value\": \"9999\",\r\n" + \r
+                       "                                               \"description\": \"\"\r\n" + \r
+                       "                                       },\r\n" + \r
+                       "                                       {\r\n" + \r
+                       "                                               \"key\": \"X-FromAppId\",\r\n" + \r
+                       "                                               \"value\": \"jimmy-postman\",\r\n" + \r
+                       "                                               \"description\": \"\"\r\n" + \r
+                       "                                       },\r\n" + \r
+                       "                                       {\r\n" + \r
+                       "                                               \"key\": \"Authorization\",\r\n" + \r
+                       "                                               \"value\": \"Basic QUFJOkFBSQ==\",\r\n" + \r
+                       "                                               \"description\": \"\"\r\n" + \r
+                       "                                       }\r\n" + \r
+                       "                               ],\r\n" + \r
+                       "                               \"body\": {\r\n" + \r
+                       "                                       \"mode\": \"raw\",\r\n" + \r
+                       "                                       \"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
+                       "                               },\r\n" + \r
+                       "                               \"description\": \"\"\r\n" + \r
+                       "                       },\r\n" + \r
+                       "                       \"response\": []\r\n" + \r
+                       "               }\r\n" + \r
+                       "       ]\r\n" + \r
+                       "}";\r
+}\r