summaryrefslogtreecommitdiffstats
path: root/src/test/java/org/onap/aai/sparky/synchronizer/entity/SuggestionSearchEntityTest.java
blob: 8063e05411f5ad5ee94cac38aaa12eb928a74b06 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/**
 * ============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.synchronizer.entity;

import java.io.IOException;
import java.util.ArrayList;

import org.junit.BeforeClass;
import org.onap.aai.sparky.search.filters.config.FiltersConfig;
import org.onap.aai.sparky.sync.entity.SuggestionSearchEntity;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;

public class SuggestionSearchEntityTest {
  private SuggestionSearchEntity suggestionSearchEntity;
  ObjectMapper mapper = new ObjectMapper();
  private static FiltersConfig config = null;

  @BeforeClass
  public static void init() throws IOException {
    config = FiltersConfig.getInstance();
    config.setFilterMappingsFileName("src/test/resources/filters/aaiui_views.json");
    config.setFiltersFileName("src/test/resources/filters/aaiui_filters.json");
    config.setViewsConfig(config.readUiViewsConfig());
    config.setFiltersConfig(config.readUiFiltersConfig());

  }

  public JsonNode getTestNodeForVnf_withProvAndOrchStatus()
      throws JsonProcessingException, IOException {
    String str = "{" + "\"vnf-id\": \"1\"," + "\"vnf-name\": \"2\"," + "\"vnf-type\": \"3\","
        + "\"orchestration-status\": \"o1\"," + "\"prov-status\": \"p1\"" + "}";

    return mapper.readTree(str);
  }

  public JsonNode getTestNodeForVnf_withOrchStatus() throws JsonProcessingException, IOException {
    String str = "{" + "\"vnf-id\": \"1\"," + "\"vnf-name\": \"2\"," + "\"vnf-type\": \"3\","
        + "\"orchestration-status\": \"o1\"" + "}";

    return mapper.readTree(str);
  }

  public JsonNode getFilterListForOrchestrationStatusOnly(String orcStat)
      throws JsonProcessingException, IOException {
    String str = "{\"filterList\":[{\"filterId\":\"2\"},{\"filterId\":\"1\",\"filterValue\":"
        + orcStat + "}]}";
    return mapper.readTree(str);
  }

  public String getStrFilterListForOrchestrationStatusOnly(String orcStat)
      throws JsonProcessingException, IOException {
    String str = "{\"filterList\":[{\"filterId\":\"2\"},{\"filterId\":\"1\",\"filterValue\":"
        + orcStat + "}," + "{\"filterId\":\"7\"}," + "{\"filterId\":\"8\"}" + "]}";
    return str;
  }

  public String getStrFilterListForOrcStatAndProvStat(String orcStat, String provStat)
      throws JsonProcessingException, IOException {
    String str = "{\"filterList\"" + ":[{\"filterId\":\"2\"," + "\"filterValue\":" + provStat
        + "},{\"filterId\":\"1\",\"filterValue\":" + orcStat + "}," + "{\"filterId\":\"7\"},"
        + "{\"filterId\":\"8\"}" + "]}";
    return str;
  }

  public ArrayList<String> getSingleElementOrcStatUniqueList() {
    ArrayList<String> list = new ArrayList<String>();
    list.add("orchestration-status");
    return list;
  }

  public ArrayList<String> getTwoElementUniqueList() {
    ArrayList<String> list = new ArrayList<String>();
    list.add("prov-status");
    list.add("orchestration-status");
    return list;
  }

  // Testing the filters payload (for ES) when only one suggestible attribute is present
  // Use case: testing a single-element set from the power set of all attributes
  /*
   * @Test public void test_params_for_suggestions_with_orcStat_o1(){ suggestionSearchEntity = new
   * SuggestionSearchEntity(SuggestionEntityLookup.getInstance(), config);
   * suggestionSearchEntity.setEntityType("generic-vnf"); JsonNode node = null; try{ node =
   * getTestNodeForVnf_withOrchStatus();
   * suggestionSearchEntity.setFilterBasedPayloadFromResponse(node,
   * suggestionSearchEntity.getEntityType(), this.getSingleElementOrcStatUniqueList()); JSONObject
   * json = suggestionSearchEntity.getPayload(); JSONObject exectedFilterPayload = new JSONObject(
   * this.getStrFilterListForOrchestrationStatusOnly("o1"));
   * 
   * final JsonNode tree1 = mapper.readTree(json.toString()); final JsonNode tree2 =
   * mapper.readTree(exectedFilterPayload.toString());
   * 
   * assertTrue("Filter list not equal. Found: " + json + ". Expected: " + exectedFilterPayload,
   * tree1.equals(tree2));
   * 
   * Map<String, String> inputOutput = suggestionSearchEntity.getInputOutputData(); Map<String,
   * String> expectedInputOutput = new HashMap<String, String>();
   * expectedInputOutput.put("orchestration-status", "o1"); final JsonNode tree3 =
   * mapper.readTree(mapper.writeValueAsString(inputOutput)); final JsonNode tree4 =
   * mapper.readTree(mapper.writeValueAsString(expectedInputOutput));
   * 
   * assertTrue("inputs for suggestions are not equal", tree3.equals(tree4));
   * 
   * } catch (Exception e){ fail("Failed to get test node."); } }
   */

  // Testing the filters payload (for ES) when multiple suggestible attributes are present
  // Use case: testing a 2-element set from the power set of all attributes
  /*
   * @Test public void test_params_for_suggestions_with_orcStat_o1_provStat_p1(){
   * suggestionSearchEntity = new SuggestionSearchEntity();
   * suggestionSearchEntity.setEntityType("generic-vnf"); JsonNode node = null; try{ node =
   * getTestNodeForVnf_withProvAndOrchStatus();
   * suggestionSearchEntity.setFilterBasedPayloadFromResponse(node,
   * suggestionSearchEntity.getEntityType(), this.getTwoElementUniqueList()); JSONObject json =
   * suggestionSearchEntity.getPayload(); JSONObject exectedFilterPayload = new JSONObject(
   * this.getStrFilterListForOrcStatAndProvStat("o1", "p1"));
   * 
   * final JsonNode tree1 = mapper.readTree(json.toString()); final JsonNode tree2 =
   * mapper.readTree(exectedFilterPayload.toString());
   * 
   * assertTrue("Filter list not equal. Found: " + json + ". Expected: " + exectedFilterPayload,
   * tree1.equals(tree2));
   * 
   * Map<String, String> inputOutput = suggestionSearchEntity.getInputOutputData(); Map<String,
   * String> expectedInputOutput = new HashMap<String, String>();
   * expectedInputOutput.put("orchestration-status", "o1"); expectedInputOutput.put("prov-status",
   * "p1"); final JsonNode tree3 = mapper.readTree(mapper.writeValueAsString(inputOutput)); final
   * JsonNode tree4 = mapper.readTree(mapper.writeValueAsString(expectedInputOutput));
   * 
   * assertTrue("inputs for suggestions are not equal", tree3.equals(tree4));
   * 
   * } catch (Exception e){ fail("Failed to get node."); } }
   */
}