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 = new FiltersConfig();
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() throws JsonProcessingException, IOException{
56 + "\"vnf-id\": \"1\","
57 + "\"vnf-name\": \"2\","
58 + "\"vnf-type\": \"3\","
59 + "\"orchestration-status\": \"o1\","
60 + "\"prov-status\": \"p1\""
63 return mapper.readTree(str);
66 public JsonNode getTestNodeForVnf_withOrchStatus() throws JsonProcessingException, IOException{
68 + "\"vnf-id\": \"1\","
69 + "\"vnf-name\": \"2\","
70 + "\"vnf-type\": \"3\","
71 + "\"orchestration-status\": \"o1\""
74 return mapper.readTree(str);
77 public JsonNode getFilterListForOrchestrationStatusOnly(String orcStat) throws JsonProcessingException, IOException{
78 String str = "{\"filterList\":[{\"filterId\":\"2\"},{\"filterId\":\"1\",\"filterValue\":"
80 return mapper.readTree(str);
83 public String getStrFilterListForOrchestrationStatusOnly(String orcStat)
84 throws JsonProcessingException, IOException{
85 String str = "{\"filterList\":[{\"filterId\":\"2\"},{\"filterId\":\"1\",\"filterValue\":"
87 + "{\"filterId\":\"7\"},"
88 + "{\"filterId\":\"8\"}"
93 public String getStrFilterListForOrcStatAndProvStat(String orcStat, String provStat)
94 throws JsonProcessingException, IOException{
95 String str = "{\"filterList\""
96 + ":[{\"filterId\":\"2\","
97 + "\"filterValue\":" + provStat
98 + "},{\"filterId\":\"1\",\"filterValue\":"
100 + "{\"filterId\":\"7\"},"
101 + "{\"filterId\":\"8\"}"
106 public ArrayList<String> getSingleElementOrcStatUniqueList(){
107 ArrayList<String> list = new ArrayList<String>();
108 list.add("orchestration-status");
112 public ArrayList<String> getTwoElementUniqueList(){
113 ArrayList<String> list = new ArrayList<String>();
114 list.add("prov-status");
115 list.add("orchestration-status");
119 // Testing the filters payload (for ES) when only one suggestible attribute is present
120 // Use case: testing a single-element set from the power set of all attributes
122 public void test_params_for_suggestions_with_orcStat_o1(){
123 suggestionSearchEntity = new SuggestionSearchEntity(SuggestionEntityLookup.getInstance(), config);
124 suggestionSearchEntity.setEntityType("generic-vnf");
125 JsonNode node = null;
127 node = getTestNodeForVnf_withOrchStatus();
128 suggestionSearchEntity.setFilterBasedPayloadFromResponse(node,
129 suggestionSearchEntity.getEntityType(), this.getSingleElementOrcStatUniqueList());
130 JSONObject json = suggestionSearchEntity.getPayload();
131 JSONObject exectedFilterPayload = new JSONObject(
132 this.getStrFilterListForOrchestrationStatusOnly("o1"));
134 final JsonNode tree1 = mapper.readTree(json.toString());
135 final JsonNode tree2 = mapper.readTree(exectedFilterPayload.toString());
137 assertTrue("Filter list not equal. Found: " + json + ". Expected: " + exectedFilterPayload,
138 tree1.equals(tree2));
140 Map<String, String> inputOutput = suggestionSearchEntity.getInputOutputData();
141 Map<String, String> expectedInputOutput = new HashMap<String, String>();
142 expectedInputOutput.put("orchestration-status", "o1");
143 final JsonNode tree3 = mapper.readTree(mapper.writeValueAsString(inputOutput));
144 final JsonNode tree4 = mapper.readTree(mapper.writeValueAsString(expectedInputOutput));
146 assertTrue("inputs for suggestions are not equal", tree3.equals(tree4));
148 } catch (Exception e){
149 fail("Failed to get test node.");
153 //Testing the filters payload (for ES) when multiple suggestible attributes are present
154 // Use case: testing a 2-element set from the power set of all attributes
156 public void test_params_for_suggestions_with_orcStat_o1_provStat_p1(){
157 suggestionSearchEntity = new SuggestionSearchEntity();
158 suggestionSearchEntity.setEntityType("generic-vnf");
159 JsonNode node = null;
161 node = getTestNodeForVnf_withProvAndOrchStatus();
162 suggestionSearchEntity.setFilterBasedPayloadFromResponse(node,
163 suggestionSearchEntity.getEntityType(), this.getTwoElementUniqueList());
164 JSONObject json = suggestionSearchEntity.getPayload();
165 JSONObject exectedFilterPayload = new JSONObject(
166 this.getStrFilterListForOrcStatAndProvStat("o1", "p1"));
168 final JsonNode tree1 = mapper.readTree(json.toString());
169 final JsonNode tree2 = mapper.readTree(exectedFilterPayload.toString());
171 assertTrue("Filter list not equal. Found: " + json + ". Expected: " + exectedFilterPayload,
172 tree1.equals(tree2));
174 Map<String, String> inputOutput = suggestionSearchEntity.getInputOutputData();
175 Map<String, String> expectedInputOutput = new HashMap<String, String>();
176 expectedInputOutput.put("orchestration-status", "o1");
177 expectedInputOutput.put("prov-status", "p1");
178 final JsonNode tree3 = mapper.readTree(mapper.writeValueAsString(inputOutput));
179 final JsonNode tree4 = mapper.readTree(mapper.writeValueAsString(expectedInputOutput));
181 assertTrue("inputs for suggestions are not equal", tree3.equals(tree4));
183 } catch (Exception e){
184 fail("Failed to get node.");