2 * ============LICENSE_START===================================================
3 * SPARKY (AAI UI service)
4 * ============================================================================
5 * Copyright © 2017 AT&T Intellectual Property.
6 * Copyright © 2017 Amdocs
8 * ============================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=====================================================
22 * ECOMP and OpenECOMP are trademarks
23 * and service marks of AT&T Intellectual Property.
26 package org.onap.aai.sparky.synchronizer.entity;
28 import java.io.IOException;
29 import java.util.ArrayList;
31 import org.junit.BeforeClass;
32 import org.onap.aai.sparky.search.filters.config.FiltersConfig;
33 import org.onap.aai.sparky.sync.entity.SuggestionSearchEntity;
35 import com.fasterxml.jackson.core.JsonProcessingException;
36 import com.fasterxml.jackson.databind.JsonNode;
37 import com.fasterxml.jackson.databind.ObjectMapper;
39 public class SuggestionSearchEntityTest {
40 private SuggestionSearchEntity suggestionSearchEntity;
41 ObjectMapper mapper = new ObjectMapper();
42 private static FiltersConfig config = null;
45 public static void init() throws IOException {
46 config = FiltersConfig.getInstance();
47 config.setFilterMappingsFileName("src/test/resources/filters/aaiui_views.json");
48 config.setFiltersFileName("src/test/resources/filters/aaiui_filters.json");
49 config.setViewsConfig(config.readUiViewsConfig());
50 config.setFiltersConfig(config.readUiFiltersConfig());
54 public JsonNode getTestNodeForVnf_withProvAndOrchStatus()
55 throws JsonProcessingException, IOException {
56 String str = "{" + "\"vnf-id\": \"1\"," + "\"vnf-name\": \"2\"," + "\"vnf-type\": \"3\","
57 + "\"orchestration-status\": \"o1\"," + "\"prov-status\": \"p1\"" + "}";
59 return mapper.readTree(str);
62 public JsonNode getTestNodeForVnf_withOrchStatus() throws JsonProcessingException, IOException {
63 String str = "{" + "\"vnf-id\": \"1\"," + "\"vnf-name\": \"2\"," + "\"vnf-type\": \"3\","
64 + "\"orchestration-status\": \"o1\"" + "}";
66 return mapper.readTree(str);
69 public JsonNode getFilterListForOrchestrationStatusOnly(String orcStat)
70 throws JsonProcessingException, IOException {
71 String str = "{\"filterList\":[{\"filterId\":\"2\"},{\"filterId\":\"1\",\"filterValue\":"
73 return mapper.readTree(str);
76 public String getStrFilterListForOrchestrationStatusOnly(String orcStat)
77 throws JsonProcessingException, IOException {
78 String str = "{\"filterList\":[{\"filterId\":\"2\"},{\"filterId\":\"1\",\"filterValue\":"
79 + orcStat + "}," + "{\"filterId\":\"7\"}," + "{\"filterId\":\"8\"}" + "]}";
83 public String getStrFilterListForOrcStatAndProvStat(String orcStat, String provStat)
84 throws JsonProcessingException, IOException {
85 String str = "{\"filterList\"" + ":[{\"filterId\":\"2\"," + "\"filterValue\":" + provStat
86 + "},{\"filterId\":\"1\",\"filterValue\":" + orcStat + "}," + "{\"filterId\":\"7\"},"
87 + "{\"filterId\":\"8\"}" + "]}";
91 public ArrayList<String> getSingleElementOrcStatUniqueList() {
92 ArrayList<String> list = new ArrayList<String>();
93 list.add("orchestration-status");
97 public ArrayList<String> getTwoElementUniqueList() {
98 ArrayList<String> list = new ArrayList<String>();
99 list.add("prov-status");
100 list.add("orchestration-status");
104 // Testing the filters payload (for ES) when only one suggestible attribute is present
105 // Use case: testing a single-element set from the power set of all attributes
107 * @Test public void test_params_for_suggestions_with_orcStat_o1(){ suggestionSearchEntity = new
108 * SuggestionSearchEntity(SuggestionEntityLookup.getInstance(), config);
109 * suggestionSearchEntity.setEntityType("generic-vnf"); JsonNode node = null; try{ node =
110 * getTestNodeForVnf_withOrchStatus();
111 * suggestionSearchEntity.setFilterBasedPayloadFromResponse(node,
112 * suggestionSearchEntity.getEntityType(), this.getSingleElementOrcStatUniqueList()); JSONObject
113 * json = suggestionSearchEntity.getPayload(); JSONObject exectedFilterPayload = new JSONObject(
114 * this.getStrFilterListForOrchestrationStatusOnly("o1"));
116 * final JsonNode tree1 = mapper.readTree(json.toString()); final JsonNode tree2 =
117 * mapper.readTree(exectedFilterPayload.toString());
119 * assertTrue("Filter list not equal. Found: " + json + ". Expected: " + exectedFilterPayload,
120 * tree1.equals(tree2));
122 * Map<String, String> inputOutput = suggestionSearchEntity.getInputOutputData(); Map<String,
123 * String> expectedInputOutput = new HashMap<String, String>();
124 * expectedInputOutput.put("orchestration-status", "o1"); final JsonNode tree3 =
125 * mapper.readTree(mapper.writeValueAsString(inputOutput)); final JsonNode tree4 =
126 * mapper.readTree(mapper.writeValueAsString(expectedInputOutput));
128 * assertTrue("inputs for suggestions are not equal", tree3.equals(tree4));
130 * } catch (Exception e){ fail("Failed to get test node."); } }
133 // Testing the filters payload (for ES) when multiple suggestible attributes are present
134 // Use case: testing a 2-element set from the power set of all attributes
136 * @Test public void test_params_for_suggestions_with_orcStat_o1_provStat_p1(){
137 * suggestionSearchEntity = new SuggestionSearchEntity();
138 * suggestionSearchEntity.setEntityType("generic-vnf"); JsonNode node = null; try{ node =
139 * getTestNodeForVnf_withProvAndOrchStatus();
140 * suggestionSearchEntity.setFilterBasedPayloadFromResponse(node,
141 * suggestionSearchEntity.getEntityType(), this.getTwoElementUniqueList()); JSONObject json =
142 * suggestionSearchEntity.getPayload(); JSONObject exectedFilterPayload = new JSONObject(
143 * this.getStrFilterListForOrcStatAndProvStat("o1", "p1"));
145 * final JsonNode tree1 = mapper.readTree(json.toString()); final JsonNode tree2 =
146 * mapper.readTree(exectedFilterPayload.toString());
148 * assertTrue("Filter list not equal. Found: " + json + ". Expected: " + exectedFilterPayload,
149 * tree1.equals(tree2));
151 * Map<String, String> inputOutput = suggestionSearchEntity.getInputOutputData(); Map<String,
152 * String> expectedInputOutput = new HashMap<String, String>();
153 * expectedInputOutput.put("orchestration-status", "o1"); expectedInputOutput.put("prov-status",
154 * "p1"); final JsonNode tree3 = mapper.readTree(mapper.writeValueAsString(inputOutput)); final
155 * JsonNode tree4 = mapper.readTree(mapper.writeValueAsString(expectedInputOutput));
157 * assertTrue("inputs for suggestions are not equal", tree3.equals(tree4));
159 * } catch (Exception e){ fail("Failed to get node."); } }