Adding interfaces in documentation
[aai/sparky-be.git] / src / test / java / org / onap / aai / sparky / synchronizer / entity / SuggestionSearchEntityTest.java
1 /**
2  * ============LICENSE_START===================================================
3  * SPARKY (AAI UI service)
4  * ============================================================================
5  * Copyright © 2017 AT&T Intellectual Property.
6  * Copyright © 2017 Amdocs
7  * All rights reserved.
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
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
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=====================================================
21  *
22  * ECOMP and OpenECOMP are trademarks
23  * and service marks of AT&T Intellectual Property.
24  */
25
26 package org.onap.aai.sparky.synchronizer.entity;
27
28 import java.io.IOException;
29 import java.util.ArrayList;
30
31 import org.junit.BeforeClass;
32 import org.onap.aai.sparky.search.filters.config.FiltersConfig;
33 import org.onap.aai.sparky.sync.entity.SuggestionSearchEntity;
34
35 import com.fasterxml.jackson.core.JsonProcessingException;
36 import com.fasterxml.jackson.databind.JsonNode;
37 import com.fasterxml.jackson.databind.ObjectMapper;
38
39 public class SuggestionSearchEntityTest {
40   private SuggestionSearchEntity suggestionSearchEntity;
41   ObjectMapper mapper = new ObjectMapper();
42   private static FiltersConfig config = null; 
43
44   @BeforeClass
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());
51     
52   }
53   
54   public JsonNode getTestNodeForVnf_withProvAndOrchStatus() throws JsonProcessingException, IOException{
55     String str = "{"
56         + "\"vnf-id\": \"1\","
57         + "\"vnf-name\": \"2\","
58         + "\"vnf-type\": \"3\","
59         + "\"orchestration-status\": \"o1\","
60         + "\"prov-status\": \"p1\""
61         + "}";
62     
63     return mapper.readTree(str);
64   }
65   
66   public JsonNode getTestNodeForVnf_withOrchStatus() throws JsonProcessingException, IOException{
67     String str = "{"
68         + "\"vnf-id\": \"1\","
69         + "\"vnf-name\": \"2\","
70         + "\"vnf-type\": \"3\","
71         + "\"orchestration-status\": \"o1\""
72         + "}";
73     
74     return mapper.readTree(str);
75   }
76   
77   public JsonNode getFilterListForOrchestrationStatusOnly(String orcStat) throws JsonProcessingException, IOException{
78     String str = "{\"filterList\":[{\"filterId\":\"2\"},{\"filterId\":\"1\",\"filterValue\":"
79         + orcStat + "}]}";
80     return mapper.readTree(str);
81   }
82   
83   public String getStrFilterListForOrchestrationStatusOnly(String orcStat) 
84       throws JsonProcessingException, IOException{
85     String str = "{\"filterList\":[{\"filterId\":\"2\"},{\"filterId\":\"1\",\"filterValue\":"
86         + orcStat + "},"
87         + "{\"filterId\":\"7\"},"
88         + "{\"filterId\":\"8\"}"
89         + "]}";
90     return str;
91   }
92   
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\":"
99         + orcStat + "},"
100             + "{\"filterId\":\"7\"},"
101             + "{\"filterId\":\"8\"}"
102             + "]}";
103     return str;
104   }
105   
106   public ArrayList<String> getSingleElementOrcStatUniqueList(){
107     ArrayList<String> list = new ArrayList<String>();
108     list.add("orchestration-status");
109     return list; 
110   }
111   
112   public ArrayList<String> getTwoElementUniqueList(){
113     ArrayList<String> list = new ArrayList<String>();
114     list.add("prov-status");
115     list.add("orchestration-status");
116     return list; 
117   }
118   
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
121   /*@Test
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;
126     try{
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"));
133
134       final JsonNode tree1 = mapper.readTree(json.toString());
135       final JsonNode tree2 = mapper.readTree(exectedFilterPayload.toString());
136
137       assertTrue("Filter list not equal. Found: " + json + ". Expected: " + exectedFilterPayload,
138           tree1.equals(tree2));
139       
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));
145
146       assertTrue("inputs for suggestions are not equal", tree3.equals(tree4));
147       
148     } catch (Exception e){
149       fail("Failed to get test node.");
150     }
151   }*/
152   
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
155   /*@Test
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;
160     try{
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"));
167
168       final JsonNode tree1 = mapper.readTree(json.toString());
169       final JsonNode tree2 = mapper.readTree(exectedFilterPayload.toString());
170
171       assertTrue("Filter list not equal. Found: " + json + ". Expected: " + exectedFilterPayload,
172           tree1.equals(tree2));
173       
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));
180
181       assertTrue("inputs for suggestions are not equal", tree3.equals(tree4));
182       
183     } catch (Exception e){
184       fail("Failed to get node.");
185     }
186   }*/
187 }