Adding UI extensibility
[aai/sparky-be.git] / src / test / java / org / onap / aai / sparky / util / SuggestionsPermutationTest.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 package org.onap.aai.sparky.util;
26
27 import static org.junit.Assert.assertTrue;
28
29 import java.util.ArrayList;
30 import java.util.Arrays;
31 import java.util.HashSet;
32 import java.util.List;
33
34 import org.junit.Test;
35 import org.onap.aai.sparky.util.SuggestionsPermutation;
36
37 public class SuggestionsPermutationTest {
38
39   @Test
40   public void testGetUniqueListForSuggestions() {
41     List<String> inputList = new ArrayList<String>();
42     inputList.add("str1");
43     inputList.add("str2");
44     inputList.add("str3");
45
46     List<List<String>> expectedListOfLists = new ArrayList<List<String>>();
47     expectedListOfLists.add((new ArrayList<String>() {
48       {
49         add("str1");
50       }
51     }));
52     expectedListOfLists.add((new ArrayList<String>() {
53       {
54         add("str2");
55       }
56     }));
57     expectedListOfLists.add((new ArrayList<String>() {
58       {
59         add("str3");
60       }
61     }));
62     expectedListOfLists.add((new ArrayList<String>() {
63       {
64         add("str1");
65         add("str2");
66       }
67     }));
68     expectedListOfLists.add((new ArrayList<String>() {
69       {
70         add("str1");
71         add("str3");
72       }
73     }));
74     expectedListOfLists.add((new ArrayList<String>() {
75       {
76         add("str2");
77         add("str3");
78       }
79     }));
80     expectedListOfLists.add((new ArrayList<String>() {
81       {
82         add("str1");
83         add("str2");
84         add("str3");
85       }
86     }));
87
88     int expectedCount = expectedListOfLists.size();
89     int actualCount = 0;
90     ArrayList<ArrayList<String>> actualListOfLists =
91         SuggestionsPermutation.getNonEmptyUniqueLists(inputList);
92
93     for (List<String> list : expectedListOfLists) {
94       for (ArrayList<String> actualList : actualListOfLists) {
95         if (new HashSet(list).equals(new HashSet(actualList))) {
96           actualCount++;
97         }
98       }
99     }
100
101     assertTrue("Missing entries in the unique list of lists for input: " + inputList.toString()
102         + ". Found: " + actualListOfLists.toString() + " expected: "
103         + expectedListOfLists.toString(), actualCount == expectedCount);
104   }
105
106   @Test
107   public void testGetListPermutations() {
108     List<String> inputList = new ArrayList<String>();
109     inputList.add("str1");
110     inputList.add("str2");
111     inputList.add("str3");
112
113     List<List<String>> expectedPermutations = new ArrayList<List<String>>();
114     expectedPermutations.add((new ArrayList<String>() {
115       {
116         add("str1");
117         add("str2");
118         add("str3");
119       }
120     }));
121     expectedPermutations.add((new ArrayList<String>() {
122       {
123         add("str2");
124         add("str1");
125         add("str3");
126       }
127     }));
128     expectedPermutations.add((new ArrayList<String>() {
129       {
130         add("str2");
131         add("str3");
132         add("str1");
133       }
134     }));
135     expectedPermutations.add((new ArrayList<String>() {
136       {
137         add("str1");
138         add("str3");
139         add("str2");
140       }
141     }));
142     expectedPermutations.add((new ArrayList<String>() {
143       {
144         add("str3");
145         add("str1");
146         add("str2");
147       }
148     }));
149     expectedPermutations.add((new ArrayList<String>() {
150       {
151         add("str3");
152         add("str2");
153         add("str1");
154       }
155     }));
156
157     int expectedCount = expectedPermutations.size();
158     int actualCount = 0;
159     List<List<String>> actualPermutations = SuggestionsPermutation.getListPermutations(inputList);
160
161     for (List<String> list : expectedPermutations) {
162       for (List<String> actualList : actualPermutations) {
163         if (list.toString().equals(actualList.toString())) {
164           actualCount++;
165         }
166       }
167     }
168
169     assertTrue(
170         "Missing entries in the permutation of list: " + inputList.toString() + ". Found: "
171             + actualPermutations.toString() + " expected: " + expectedPermutations.toString(),
172         actualCount == expectedCount);
173   }
174
175   @Test
176   public void isValidSuggestionInputPermutation_verbose_successPath() {
177
178     List<String> x = new ArrayList<>(Arrays.asList("A", "B", "C", "D"));
179
180     ArrayList<ArrayList<String>> uniqueLists = SuggestionsPermutation.getNonEmptyUniqueLists(x);
181
182     assertTrue(uniqueLists.get(0).toString().equals("[A, B, C, D]"));
183     assertTrue(uniqueLists.get(1).toString().equals("[B, C, D]"));
184     assertTrue(uniqueLists.get(2).toString().equals("[A, C, D]"));
185     assertTrue(uniqueLists.get(3).toString().equals("[C, D]"));
186     assertTrue(uniqueLists.get(4).toString().equals("[A, B, D]"));
187     assertTrue(uniqueLists.get(5).toString().equals("[B, D]"));
188     assertTrue(uniqueLists.get(6).toString().equals("[A, D]"));
189     assertTrue(uniqueLists.get(7).toString().equals("[D]"));
190     assertTrue(uniqueLists.get(8).toString().equals("[A, B, C]"));
191     assertTrue(uniqueLists.get(9).toString().equals("[B, C]"));
192     assertTrue(uniqueLists.get(10).toString().equals("[A, C]"));
193     assertTrue(uniqueLists.get(11).toString().equals("[C]"));
194     assertTrue(uniqueLists.get(12).toString().equals("[A, B]"));
195     assertTrue(uniqueLists.get(13).toString().equals("[B]"));
196     assertTrue(uniqueLists.get(14).toString().equals("[A]"));
197     assertTrue(uniqueLists.size() == 15);
198
199   }
200
201 }