dc794b88d94284d281ef422be4f3dbea6ce02049
[aai/traversal.git] /
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
4  * ================================================================================
5  * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20 package org.onap.aai.rest.history;
21
22 import static org.hamcrest.CoreMatchers.is;
23 import static org.junit.Assert.*;
24
25 import com.google.gson.JsonArray;
26 import com.google.gson.JsonElement;
27 import com.google.gson.JsonParser;
28
29 import java.util.*;
30
31 import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
32 import org.janusgraph.core.JanusGraphTransaction;
33 import org.junit.Ignore;
34 import org.junit.Test;
35 import org.onap.aai.PayloadUtil;
36 import org.onap.aai.db.props.AAIProperties;
37 import org.onap.aai.dbmap.AAIGraph;
38 import org.slf4j.Logger;
39 import org.slf4j.LoggerFactory;
40 import org.springframework.http.HttpEntity;
41 import org.springframework.http.HttpMethod;
42 import org.springframework.http.HttpStatus;
43 import org.springframework.http.ResponseEntity;
44
45 @Ignore("The lifecycle format requires the history schema to be loaded.  "
46     + "Because aaigraph is a singleton its very complicated to have 2 different schemas loaded for testing.  "
47     + "This needs to be addressed.")
48 public class DslConsumerHistoryLifecycleNodeDeletedThenRecreatedTest
49     extends AbstractSpringHistoryRestTest {
50
51     private static final Logger LOGGER =
52         LoggerFactory.getLogger(DslConsumerHistoryLifecycleNodeDeletedThenRecreatedTest.class);
53
54     @Override
55     public void createTestGraph() {
56         JanusGraphTransaction transaction = AAIGraph.getInstance().getGraph().newTransaction();
57         boolean success = true;
58         try {
59             GraphTraversalSource g = transaction.traversal();
60             /*
61              * Pserver
62              * - created pserver @ time 100
63              * - equip-type = first-ps-type
64              * - update equip-type @ 500
65              * - equip-type = first-ps-type-update
66              * - deleted pserver @ time 1000
67              */
68             g.addV()
69                 .property(AAIProperties.NODE_TYPE, "pserver", AAIProperties.SOURCE_OF_TRUTH,
70                     "JUNIT-C", AAIProperties.START_TX_ID, "JUNIT-C", AAIProperties.END_SOT,
71                     "JUNIT-D", AAIProperties.END_TX_ID, "JUNIT-D", AAIProperties.START_TS, 100L,
72                     AAIProperties.END_TS, 1000L)
73                 .property(AAIProperties.AAI_URI,
74                     "/cloud-infrastructure/pservers/pserver/test-pserver-dsl",
75                     AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", AAIProperties.START_TX_ID, "JUNIT-C",
76                     AAIProperties.END_SOT, "JUNIT-D", AAIProperties.END_TX_ID, "JUNIT-D",
77                     AAIProperties.START_TS, 100L, AAIProperties.END_TS, 1000L)
78                 .property(AAIProperties.RESOURCE_VERSION, "100", AAIProperties.SOURCE_OF_TRUTH,
79                     "JUNIT-C", AAIProperties.START_TX_ID, "JUNIT-C", AAIProperties.END_SOT,
80                     "JUNIT-U", AAIProperties.END_TX_ID, "JUNIT-U", AAIProperties.START_TS, 100L,
81                     AAIProperties.END_TS, 500L)
82                 .property(AAIProperties.RESOURCE_VERSION, "500", AAIProperties.SOURCE_OF_TRUTH,
83                     "JUNIT-U", AAIProperties.START_TX_ID, "JUNIT-U", AAIProperties.END_SOT,
84                     "JUNIT-D", AAIProperties.END_TX_ID, "JUNIT-D", AAIProperties.START_TS, 500L,
85                     AAIProperties.END_TS, 1000L)
86                 .property("hostname", "test-pserver-dsl", AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C",
87                     AAIProperties.START_TX_ID, "JUNIT-C", AAIProperties.END_SOT, "JUNIT-D",
88                     AAIProperties.END_TX_ID, "JUNIT-D", AAIProperties.START_TS, 100L,
89                     AAIProperties.END_TS, 1000L)
90                 .property("in-maint", false, AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C",
91                     AAIProperties.START_TX_ID, "JUNIT-C", AAIProperties.END_SOT, "JUNIT-D",
92                     AAIProperties.END_TX_ID, "JUNIT-D", AAIProperties.START_TS, 100L,
93                     AAIProperties.END_TS, 1000L)
94                 .property("equip-type", "first-ps-type", AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C",
95                     AAIProperties.START_TX_ID, "JUNIT-C", AAIProperties.END_SOT, "JUNIT-U",
96                     AAIProperties.END_TX_ID, "JUNIT-U", AAIProperties.START_TS, 100L,
97                     AAIProperties.END_TS, 500L)
98                 .property("equip-type", "first-ps-type-update", AAIProperties.SOURCE_OF_TRUTH,
99                     "JUNIT-U", AAIProperties.START_TX_ID, "JUNIT-U", AAIProperties.END_SOT,
100                     "JUNIT-D", AAIProperties.END_TX_ID, "JUNIT-D", AAIProperties.START_TS, 500L,
101                     AAIProperties.END_TS, 1000L)
102                 .property(AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", AAIProperties.SOURCE_OF_TRUTH,
103                     "JUNIT-C", AAIProperties.START_TX_ID, "JUNIT-C", AAIProperties.END_SOT,
104                     "JUNIT-D", AAIProperties.END_TX_ID, "JUNIT-D", AAIProperties.START_TS, 100L,
105                     AAIProperties.END_TS, 1000L)
106                 .property(AAIProperties.END_SOT, "JUNIT-D", AAIProperties.SOURCE_OF_TRUTH,
107                     "JUNIT-D", AAIProperties.START_TX_ID, "JUNIT-D", AAIProperties.END_SOT,
108                     "JUNIT-D", AAIProperties.END_TX_ID, "JUNIT-D", AAIProperties.START_TS, 100L,
109                     AAIProperties.END_TS, 1000L)
110                 .property(AAIProperties.START_TS, 100L, AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C",
111                     AAIProperties.START_TX_ID, "JUNIT-C", AAIProperties.END_SOT, "JUNIT-D",
112                     AAIProperties.END_TX_ID, "JUNIT-D", AAIProperties.START_TS, 100L,
113                     AAIProperties.END_TS, 1000L)
114                 .property(AAIProperties.END_TS, 1000L, AAIProperties.SOURCE_OF_TRUTH, "JUNIT-D",
115                     AAIProperties.START_TX_ID, "JUNIT-D", AAIProperties.END_SOT, "JUNIT-D",
116                     AAIProperties.END_TX_ID, "JUNIT-D", AAIProperties.START_TS, 1000L,
117                     AAIProperties.END_TS, 1000L)
118                 .next();
119
120             /*
121              * Pserver
122              * - created pserver @ time 10000
123              * - equip-type = second-ps-type
124              * - delete equip-type @ 13000
125              * - recreate equip-type @ 15000
126              * - equip-type = second-ps-type-recreated
127              * - update equip-type @ 17000
128              * - equip-type = second-ps-type-update
129              * - delete equip-type @ 20000
130              */
131             g.addV()
132                 .property(AAIProperties.NODE_TYPE, "pserver", AAIProperties.SOURCE_OF_TRUTH,
133                     "JUNIT-C", AAIProperties.START_TX_ID, "JUNIT-C", AAIProperties.START_TS, 10000L)
134                 .property(AAIProperties.AAI_URI,
135                     "/cloud-infrastructure/pservers/pserver/test-pserver-dsl",
136                     AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", AAIProperties.START_TX_ID, "JUNIT-C",
137                     AAIProperties.START_TS, 10000L)
138                 .property(AAIProperties.RESOURCE_VERSION, "10000", AAIProperties.SOURCE_OF_TRUTH,
139                     "JUNIT-C", AAIProperties.START_TX_ID, "JUNIT-C", AAIProperties.END_SOT,
140                     "JUNIT-U-1", AAIProperties.END_TX_ID, "JUNIT-U-1", AAIProperties.START_TS,
141                     10000L, AAIProperties.END_TS, 13000L)
142                 .property(AAIProperties.RESOURCE_VERSION, "13000", AAIProperties.SOURCE_OF_TRUTH,
143                     "JUNIT-U-1", AAIProperties.START_TX_ID, "JUNIT-U-1", AAIProperties.END_SOT,
144                     "JUNIT-U-2", AAIProperties.END_TX_ID, "JUNIT-U-2", AAIProperties.START_TS,
145                     13000L, AAIProperties.END_TS, 15000L)
146                 .property(AAIProperties.RESOURCE_VERSION, "15000", AAIProperties.SOURCE_OF_TRUTH,
147                     "JUNIT-U-2", AAIProperties.START_TX_ID, "JUNIT-U-2", AAIProperties.END_SOT,
148                     "JUNIT-U-3", AAIProperties.END_TX_ID, "JUNIT-U-3", AAIProperties.START_TS,
149                     15000L, AAIProperties.END_TS, 17000L)
150                 .property(AAIProperties.RESOURCE_VERSION, "17000", AAIProperties.SOURCE_OF_TRUTH,
151                     "JUNIT-U-3", AAIProperties.START_TX_ID, "JUNIT-U-3", AAIProperties.END_SOT,
152                     "JUNIT-U-4", AAIProperties.END_TX_ID, "JUNIT-U-4", AAIProperties.START_TS,
153                     17000L, AAIProperties.END_TS, 20000L)
154                 .property(AAIProperties.RESOURCE_VERSION, "20000", AAIProperties.SOURCE_OF_TRUTH,
155                     "JUNIT-U-4", AAIProperties.START_TX_ID, "JUNIT-U-4", AAIProperties.START_TS,
156                     20000L)
157                 .property("hostname", "test-pserver-dsl", AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C",
158                     AAIProperties.START_TX_ID, "JUNIT-C", AAIProperties.START_TS, 10000L)
159                 .property("in-maint", true, AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C",
160                     AAIProperties.START_TX_ID, "JUNIT-C", AAIProperties.START_TS, 10000L)
161                 .property("equip-type", "second-ps-type", AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C",
162                     AAIProperties.START_TX_ID, "JUNIT-C", AAIProperties.END_SOT, "JUNIT-U-1",
163                     AAIProperties.END_TX_ID, "JUNIT-U-1", AAIProperties.START_TS, 10000L,
164                     AAIProperties.END_TS, 13000L)
165                 .property("equip-type", "second-ps-type-recreated", AAIProperties.SOURCE_OF_TRUTH,
166                     "JUNIT-U-2", AAIProperties.START_TX_ID, "JUNIT-U-2", AAIProperties.END_SOT,
167                     "JUNIT-U-3", AAIProperties.END_TX_ID, "JUNIT-U-3", AAIProperties.START_TS,
168                     15000L, AAIProperties.END_TS, 17000L)
169                 .property("equip-type", "second-ps-type-update", AAIProperties.SOURCE_OF_TRUTH,
170                     "JUNIT-U-3", AAIProperties.START_TX_ID, "JUNIT-U-3", AAIProperties.START_TS,
171                     17000L, AAIProperties.END_SOT, "JUNIT-U-4", AAIProperties.END_TX_ID,
172                     "JUNIT-U-4", AAIProperties.END_TS, 20000L)
173                 .property(AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", AAIProperties.SOURCE_OF_TRUTH,
174                     "JUNIT-C", AAIProperties.START_TX_ID, "JUNIT-C", AAIProperties.START_TS, 10000L)
175                 .property(AAIProperties.START_TS, 10000L, AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C",
176                     AAIProperties.START_TX_ID, "JUNIT-C", AAIProperties.START_TS, 10000L)
177                 .next();
178         } catch (Exception ex) {
179             success = false;
180         } finally {
181             if (success) {
182                 transaction.commit();
183             } else {
184                 transaction.rollback();
185                 fail("Unable to setup the graph");
186             }
187         }
188     }
189
190     private JsonArray getResultsForPserverLookupByHostname(String endpoint) throws Exception {
191         return getResultsForPserverLookupByHostnameAndAnother(endpoint, "");
192     }
193
194     private JsonArray getResultsForPserverLookupByHostnameAndAnother(String endpoint,
195         String additionalFilterInParen) throws Exception {
196         Map<String, String> dslQueryMap = new HashMap<>();
197         dslQueryMap.put("dsl-query",
198             "pserver*('hostname','test-pserver-dsl')" + additionalFilterInParen);
199         String payload = PayloadUtil.getTemplatePayload("dsl-query.json", dslQueryMap);
200         httpEntity = new HttpEntity(payload, headers);
201         ResponseEntity responseEntity =
202             restTemplate.exchange(baseUrl + endpoint, HttpMethod.PUT, httpEntity, String.class);
203         JsonArray results = new JsonParser().parse(responseEntity.getBody().toString())
204             .getAsJsonObject().getAsJsonArray("results");
205         LOGGER.debug("Response for PUT request with uri {} : {}", baseUrl + endpoint,
206             responseEntity.getBody());
207
208         assertNotNull("Response from /aai/v14/dsl is not null", responseEntity);
209         assertEquals("Expected the response to be 200", HttpStatus.OK,
210             responseEntity.getStatusCode());
211         return results;
212     }
213
214     private void verifyEquipTypeValues(JsonArray results, String... expectedEquipTypes) {
215         List<String> expected = Arrays.asList(expectedEquipTypes);
216         final List<String> actualEquipType = new ArrayList<>();
217         for (JsonElement result : results) {
218             for (JsonElement property : result.getAsJsonObject().get("properties")
219                 .getAsJsonArray()) {
220                 if (property.getAsJsonObject().get("key").getAsString().equals("equip-type")) {
221                     if (property.getAsJsonObject().has("value")
222                         && !property.getAsJsonObject().get("value").isJsonNull()) {
223                         actualEquipType.add(property.getAsJsonObject().get("value").getAsString());
224                     } else {
225                         actualEquipType.add(null);
226                     }
227                 }
228             }
229         }
230         assertThat("Verify equip-type in lifecycle", actualEquipType, is(expected));
231     }
232
233     private void verifyEquipTypeSoTs(JsonArray results, String... expectedSTOs) {
234         List<String> expected = Arrays.asList(expectedSTOs);
235         final List<String> actualEquipType = new ArrayList<>();
236         for (JsonElement result : results) {
237             for (JsonElement property : result.getAsJsonObject().get("properties")
238                 .getAsJsonArray()) {
239                 if (property.getAsJsonObject().get("key").getAsString().equals("equip-type")) {
240                     if (property.getAsJsonObject().has("sot")
241                         && !property.getAsJsonObject().get("sot").isJsonNull()) {
242                         actualEquipType.add(property.getAsJsonObject().get("sot").getAsString());
243                     } else {
244                         actualEquipType.add(null);
245                     }
246                 }
247             }
248         }
249         assertThat("Verify equip-type SoTs in lifecycle", actualEquipType, is(expected));
250     }
251
252     private void verifyEquipTypeTxId(JsonArray results, String... expectedSTOs) {
253         List<String> expected = Arrays.asList(expectedSTOs);
254         final List<String> actualEquipType = new ArrayList<>();
255         for (JsonElement result : results) {
256             for (JsonElement property : result.getAsJsonObject().get("properties")
257                 .getAsJsonArray()) {
258                 if (property.getAsJsonObject().get("key").getAsString().equals("equip-type")) {
259                     if (property.getAsJsonObject().has("tx-id")
260                         && !property.getAsJsonObject().get("tx-id").isJsonNull()) {
261                         actualEquipType.add(property.getAsJsonObject().get("tx-id").getAsString());
262                     } else {
263                         actualEquipType.add(null);
264                     }
265                 }
266             }
267         }
268         assertThat("Verify equip-type tx-ids in lifecycle", actualEquipType, is(expected));
269     }
270
271     private void verifyEquipTypeTimestamps(JsonArray results, Long... expectedSTOs) {
272         List<Long> expected = Arrays.asList(expectedSTOs);
273         final List<Long> actualEquipType = new ArrayList<>();
274         for (JsonElement result : results) {
275             for (JsonElement property : result.getAsJsonObject().get("properties")
276                 .getAsJsonArray()) {
277                 if (property.getAsJsonObject().get("key").getAsString().equals("equip-type")) {
278                     if (property.getAsJsonObject().has("timestamp")
279                         && !property.getAsJsonObject().get("timestamp").isJsonNull()) {
280                         actualEquipType
281                             .add(property.getAsJsonObject().get("timestamp").getAsLong());
282                     } else {
283                         actualEquipType.add(null);
284                     }
285                 }
286             }
287         }
288         assertThat("Verify equip-type timestamps in lifecycle", actualEquipType, is(expected));
289     }
290
291     private void verifyNodeTimestamps(JsonArray results, Long... nodeTimestamps) {
292         List<Long> expected = Arrays.asList(nodeTimestamps);
293         final List<Long> actualEquipType = new ArrayList<>();
294         for (JsonElement result : results) {
295             result.getAsJsonObject().get("node-actions").getAsJsonArray()
296                 .forEach(jsonElement -> actualEquipType
297                     .add(jsonElement.getAsJsonObject().get("timestamp").getAsLong()));
298         }
299         assertThat("Verify node-changes timestamps in lifecycle", actualEquipType, is(expected));
300     }
301
302     private void verifyNodeSot(JsonArray results, String... nodeSots) {
303         List<String> expected = Arrays.asList(nodeSots);
304         final List<String> actualEquipType = new ArrayList<>();
305         for (JsonElement result : results) {
306             result.getAsJsonObject().get("node-actions").getAsJsonArray()
307                 .forEach(jsonElement -> actualEquipType
308                     .add(jsonElement.getAsJsonObject().get("sot").getAsString()));
309         }
310         assertThat("Verify node-changes sot in lifecycle", actualEquipType, is(expected));
311     }
312
313     @Test
314     public void lifecycleQueryNoStartOrEndTsTest() throws Exception {
315
316         String endpoint = "/aai/v14/dsl?format=lifecycle";
317         JsonArray results = getResultsForPserverLookupByHostname(endpoint);
318         assertEquals("Result size", 1, results.size());
319
320         verifyEquipTypeValues(results, null, "second-ps-type-update", "second-ps-type-recreated",
321             null, "second-ps-type", "first-ps-type-update", "first-ps-type");
322         verifyEquipTypeSoTs(results, "JUNIT-U-4", "JUNIT-U-3", "JUNIT-U-2", "JUNIT-U-1", "JUNIT-C",
323             "JUNIT-U", "JUNIT-C");
324         verifyEquipTypeTxId(results, "JUNIT-U-4", "JUNIT-U-3", "JUNIT-U-2", "JUNIT-U-1", "JUNIT-C",
325             "JUNIT-U", "JUNIT-C");
326         verifyEquipTypeTimestamps(results, 20000L, 17000L, 15000L, 13000L, 10000L, 500L, 100L);
327         verifyNodeTimestamps(results, 10000L, 1000L, 100L);
328
329         String equipType = "first-ps-type";
330         results = getResultsForPserverLookupByHostnameAndAnother(endpoint,
331             "('equip-type','" + equipType + "')");
332         assertEquals("Filter equip-type on " + equipType, 1, results.size());
333         verifyEquipTypeValues(results, "first-ps-type-update", "first-ps-type");
334         verifyEquipTypeSoTs(results, "JUNIT-U", "JUNIT-C");
335         verifyEquipTypeTxId(results, "JUNIT-U", "JUNIT-C");
336         verifyEquipTypeTimestamps(results, 500L, 100L);
337         verifyNodeTimestamps(results, 1000L, 100L);
338
339         equipType = "second-ps-type-recreated";
340         results = getResultsForPserverLookupByHostnameAndAnother(endpoint,
341             "('equip-type','" + equipType + "')");
342         assertEquals("Filter equip-type on " + equipType, 1, results.size());
343         verifyEquipTypeValues(results, null, "second-ps-type-update", "second-ps-type-recreated",
344             null, "second-ps-type");
345         verifyEquipTypeSoTs(results, "JUNIT-U-4", "JUNIT-U-3", "JUNIT-U-2", "JUNIT-U-1", "JUNIT-C");
346         verifyEquipTypeTxId(results, "JUNIT-U-4", "JUNIT-U-3", "JUNIT-U-2", "JUNIT-U-1", "JUNIT-C");
347         verifyEquipTypeTimestamps(results, 20000L, 17000L, 15000L, 13000L, 10000L);
348         verifyNodeTimestamps(results, 10000L);
349     }
350
351     @Test
352     public void lifecycleQueryStartTsBeforeCreationTimeTest() throws Exception {
353
354         String endpoint = "/aai/v14/dsl?format=lifecycle&startTs=50";
355         JsonArray results = getResultsForPserverLookupByHostname(endpoint);
356         assertEquals("Result size", 1, results.size());
357
358         verifyEquipTypeValues(results, null, "second-ps-type-update", "second-ps-type-recreated",
359             null, "second-ps-type", "first-ps-type-update", "first-ps-type");
360         verifyEquipTypeSoTs(results, "JUNIT-U-4", "JUNIT-U-3", "JUNIT-U-2", "JUNIT-U-1", "JUNIT-C",
361             "JUNIT-U", "JUNIT-C");
362         verifyEquipTypeTxId(results, "JUNIT-U-4", "JUNIT-U-3", "JUNIT-U-2", "JUNIT-U-1", "JUNIT-C",
363             "JUNIT-U", "JUNIT-C");
364         verifyEquipTypeTimestamps(results, 20000L, 17000L, 15000L, 13000L, 10000L, 500L, 100L);
365         verifyNodeTimestamps(results, 10000L, 1000L, 100L);
366
367         String equipType = "first-ps-type";
368         results = getResultsForPserverLookupByHostnameAndAnother(endpoint,
369             "('equip-type','" + equipType + "')");
370         assertEquals("Filter equip-type on " + equipType, 1, results.size());
371         verifyEquipTypeValues(results, "first-ps-type-update", "first-ps-type");
372         verifyEquipTypeSoTs(results, "JUNIT-U", "JUNIT-C");
373         verifyEquipTypeTxId(results, "JUNIT-U", "JUNIT-C");
374         verifyEquipTypeTimestamps(results, 500L, 100L);
375         verifyNodeTimestamps(results, 1000L, 100L);
376
377         equipType = "second-ps-type-recreated";
378         results = getResultsForPserverLookupByHostnameAndAnother(endpoint,
379             "('equip-type','" + equipType + "')");
380         assertEquals("Filter equip-type on " + equipType, 1, results.size());
381         verifyEquipTypeValues(results, null, "second-ps-type-update", "second-ps-type-recreated",
382             null, "second-ps-type");
383         verifyEquipTypeSoTs(results, "JUNIT-U-4", "JUNIT-U-3", "JUNIT-U-2", "JUNIT-U-1", "JUNIT-C");
384         verifyEquipTypeTxId(results, "JUNIT-U-4", "JUNIT-U-3", "JUNIT-U-2", "JUNIT-U-1", "JUNIT-C");
385         verifyEquipTypeTimestamps(results, 20000L, 17000L, 15000L, 13000L, 10000L);
386         verifyNodeTimestamps(results, 10000L);
387     }
388
389     @Test
390     public void lifecycleQueryStartTsAtCreationTimeTest() throws Exception {
391
392         String endpoint = "/aai/v14/dsl?format=lifecycle&startTs=100";
393         JsonArray results = getResultsForPserverLookupByHostname(endpoint);
394         assertEquals("Result size", 1, results.size());
395
396         verifyEquipTypeValues(results, null, "second-ps-type-update", "second-ps-type-recreated",
397             null, "second-ps-type", "first-ps-type-update", "first-ps-type");
398         verifyEquipTypeSoTs(results, "JUNIT-U-4", "JUNIT-U-3", "JUNIT-U-2", "JUNIT-U-1", "JUNIT-C",
399             "JUNIT-U", "JUNIT-C");
400         verifyEquipTypeTxId(results, "JUNIT-U-4", "JUNIT-U-3", "JUNIT-U-2", "JUNIT-U-1", "JUNIT-C",
401             "JUNIT-U", "JUNIT-C");
402         verifyEquipTypeTimestamps(results, 20000L, 17000L, 15000L, 13000L, 10000L, 500L, 100L);
403         verifyNodeTimestamps(results, 10000L, 1000L, 100L);
404     }
405
406     @Test
407     public void lifecycleQueryStartTsAfterCreationTimeTest() throws Exception {
408
409         String endpoint = "/aai/v14/dsl?format=lifecycle&startTs=300";
410         JsonArray results = getResultsForPserverLookupByHostname(endpoint);
411         assertEquals("Result size", 1, results.size());
412
413         verifyEquipTypeValues(results, null, "second-ps-type-update", "second-ps-type-recreated",
414             null, "second-ps-type", "first-ps-type-update");
415         verifyEquipTypeSoTs(results, "JUNIT-U-4", "JUNIT-U-3", "JUNIT-U-2", "JUNIT-U-1", "JUNIT-C",
416             "JUNIT-U");
417         verifyEquipTypeTxId(results, "JUNIT-U-4", "JUNIT-U-3", "JUNIT-U-2", "JUNIT-U-1", "JUNIT-C",
418             "JUNIT-U");
419         verifyEquipTypeTimestamps(results, 20000L, 17000L, 15000L, 13000L, 10000L, 500L);
420         verifyNodeTimestamps(results, 10000L, 1000L);
421     }
422
423     @Test
424     public void lifecycleQueryStartTsAtFirstUpdateTimeTest() throws Exception {
425
426         String endpoint = "/aai/v14/dsl?format=lifecycle&startTs=500";
427         JsonArray results = getResultsForPserverLookupByHostname(endpoint);
428         assertEquals("Result size", 1, results.size());
429
430         verifyEquipTypeValues(results, null, "second-ps-type-update", "second-ps-type-recreated",
431             null, "second-ps-type", "first-ps-type-update");
432         verifyEquipTypeSoTs(results, "JUNIT-U-4", "JUNIT-U-3", "JUNIT-U-2", "JUNIT-U-1", "JUNIT-C",
433             "JUNIT-U");
434         verifyEquipTypeTxId(results, "JUNIT-U-4", "JUNIT-U-3", "JUNIT-U-2", "JUNIT-U-1", "JUNIT-C",
435             "JUNIT-U");
436         verifyEquipTypeTimestamps(results, 20000L, 17000L, 15000L, 13000L, 10000L, 500L);
437         verifyNodeTimestamps(results, 10000L, 1000L);
438     }
439
440     @Test
441     public void lifecycleQueryStartTsAfterFirstUpdateTimeTest() throws Exception {
442
443         String endpoint = "/aai/v14/dsl?format=lifecycle&startTs=700";
444         JsonArray results = getResultsForPserverLookupByHostname(endpoint);
445         assertEquals("Result size", 1, results.size());
446
447         verifyEquipTypeValues(results, null, "second-ps-type-update", "second-ps-type-recreated",
448             null, "second-ps-type");
449         verifyEquipTypeSoTs(results, "JUNIT-U-4", "JUNIT-U-3", "JUNIT-U-2", "JUNIT-U-1", "JUNIT-C");
450         verifyEquipTypeTxId(results, "JUNIT-U-4", "JUNIT-U-3", "JUNIT-U-2", "JUNIT-U-1", "JUNIT-C");
451         verifyEquipTypeTimestamps(results, 20000L, 17000L, 15000L, 13000L, 10000L);
452         verifyNodeTimestamps(results, 10000L, 1000L);
453     }
454
455     @Test
456     public void lifecycleQueryStartTsAtFirstDeleteTimeTest() throws Exception {
457
458         String endpoint = "/aai/v14/dsl?format=lifecycle&startTs=1000";
459         JsonArray results = getResultsForPserverLookupByHostname(endpoint);
460         assertEquals("Result size", 1, results.size());
461
462         verifyEquipTypeValues(results, null, "second-ps-type-update", "second-ps-type-recreated",
463             null, "second-ps-type");
464         verifyEquipTypeSoTs(results, "JUNIT-U-4", "JUNIT-U-3", "JUNIT-U-2", "JUNIT-U-1", "JUNIT-C");
465         verifyEquipTypeTxId(results, "JUNIT-U-4", "JUNIT-U-3", "JUNIT-U-2", "JUNIT-U-1", "JUNIT-C");
466         verifyEquipTypeTimestamps(results, 20000L, 17000L, 15000L, 13000L, 10000L);
467         verifyNodeTimestamps(results, 10000L, 1000L);
468     }
469
470     @Test
471     public void lifecycleQueryStartTsAfterFirstDeleteTimeTest() throws Exception {
472
473         String endpoint = "/aai/v14/dsl?format=lifecycle&startTs=5000";
474         JsonArray results = getResultsForPserverLookupByHostname(endpoint);
475         assertEquals("Result size", 1, results.size());
476
477         verifyEquipTypeValues(results, null, "second-ps-type-update", "second-ps-type-recreated",
478             null, "second-ps-type");
479         verifyEquipTypeSoTs(results, "JUNIT-U-4", "JUNIT-U-3", "JUNIT-U-2", "JUNIT-U-1", "JUNIT-C");
480         verifyEquipTypeTxId(results, "JUNIT-U-4", "JUNIT-U-3", "JUNIT-U-2", "JUNIT-U-1", "JUNIT-C");
481         verifyEquipTypeTimestamps(results, 20000L, 17000L, 15000L, 13000L, 10000L);
482         verifyNodeTimestamps(results, 10000L);
483     }
484
485     @Test
486     public void lifecycleQueryStartTsAtSecondCreateTimeTest() throws Exception {
487
488         String endpoint = "/aai/v14/dsl?format=lifecycle&startTs=10000";
489         JsonArray results = getResultsForPserverLookupByHostname(endpoint);
490         assertEquals("Result size", 1, results.size());
491
492         verifyEquipTypeValues(results, null, "second-ps-type-update", "second-ps-type-recreated",
493             null, "second-ps-type");
494         verifyEquipTypeSoTs(results, "JUNIT-U-4", "JUNIT-U-3", "JUNIT-U-2", "JUNIT-U-1", "JUNIT-C");
495         verifyEquipTypeTxId(results, "JUNIT-U-4", "JUNIT-U-3", "JUNIT-U-2", "JUNIT-U-1", "JUNIT-C");
496         verifyEquipTypeTimestamps(results, 20000L, 17000L, 15000L, 13000L, 10000L);
497         verifyNodeTimestamps(results, 10000L);
498     }
499
500     @Test
501     public void lifecycleQueryStartTsAfterSecondCreateTimeTest() throws Exception {
502
503         String endpoint = "/aai/v14/dsl?format=lifecycle&startTs=12000";
504         JsonArray results = getResultsForPserverLookupByHostname(endpoint);
505         assertEquals("Result size", 1, results.size());
506
507         verifyEquipTypeValues(results, null, "second-ps-type-update", "second-ps-type-recreated",
508             null);
509         verifyEquipTypeSoTs(results, "JUNIT-U-4", "JUNIT-U-3", "JUNIT-U-2", "JUNIT-U-1");
510         verifyEquipTypeTxId(results, "JUNIT-U-4", "JUNIT-U-3", "JUNIT-U-2", "JUNIT-U-1");
511         verifyEquipTypeTimestamps(results, 20000L, 17000L, 15000L, 13000L);
512         verifyNodeTimestamps(results);
513     }
514
515     @Test
516     public void lifecycleQueryStartTsAtEquipTypeFirstDeleteOnSecondPsTimeTest() throws Exception {
517
518         String endpoint = "/aai/v14/dsl?format=lifecycle&startTs=13000";
519         JsonArray results = getResultsForPserverLookupByHostname(endpoint);
520         assertEquals("Result size", 1, results.size());
521
522         verifyEquipTypeValues(results, null, "second-ps-type-update", "second-ps-type-recreated",
523             null);
524         verifyEquipTypeSoTs(results, "JUNIT-U-4", "JUNIT-U-3", "JUNIT-U-2", "JUNIT-U-1");
525         verifyEquipTypeTxId(results, "JUNIT-U-4", "JUNIT-U-3", "JUNIT-U-2", "JUNIT-U-1");
526         verifyEquipTypeTimestamps(results, 20000L, 17000L, 15000L, 13000L);
527         verifyNodeTimestamps(results);
528     }
529
530     @Test
531     public void lifecycleQueryStartTsAfterEquipTypeFirstDeleteOnSecondPsTimeTest()
532         throws Exception {
533
534         String endpoint = "/aai/v14/dsl?format=lifecycle&startTs=14000";
535         JsonArray results = getResultsForPserverLookupByHostname(endpoint);
536         assertEquals("Result size", 1, results.size());
537
538         verifyEquipTypeValues(results, null, "second-ps-type-update", "second-ps-type-recreated");
539         verifyEquipTypeSoTs(results, "JUNIT-U-4", "JUNIT-U-3", "JUNIT-U-2");
540         verifyEquipTypeTxId(results, "JUNIT-U-4", "JUNIT-U-3", "JUNIT-U-2");
541         verifyEquipTypeTimestamps(results, 20000L, 17000L, 15000L);
542         verifyNodeTimestamps(results);
543     }
544
545     @Test
546     public void lifecycleQueryStartTsAtEquipTypeRecreateOnSecondPsTimeTest() throws Exception {
547
548         String endpoint = "/aai/v14/dsl?format=lifecycle&startTs=15000";
549         JsonArray results = getResultsForPserverLookupByHostname(endpoint);
550         assertEquals("Result size", 1, results.size());
551
552         verifyEquipTypeValues(results, null, "second-ps-type-update", "second-ps-type-recreated");
553         verifyEquipTypeSoTs(results, "JUNIT-U-4", "JUNIT-U-3", "JUNIT-U-2");
554         verifyEquipTypeTxId(results, "JUNIT-U-4", "JUNIT-U-3", "JUNIT-U-2");
555         verifyEquipTypeTimestamps(results, 20000L, 17000L, 15000L);
556         verifyNodeTimestamps(results);
557     }
558
559     @Test
560     public void lifecycleQueryStartTsAfterEquipTypeRecreateOnSecondPsTimeTest() throws Exception {
561
562         String endpoint = "/aai/v14/dsl?format=lifecycle&startTs=16000";
563         JsonArray results = getResultsForPserverLookupByHostname(endpoint);
564         assertEquals("Result size", 1, results.size());
565
566         verifyEquipTypeValues(results, null, "second-ps-type-update");
567         verifyEquipTypeSoTs(results, "JUNIT-U-4", "JUNIT-U-3");
568         verifyEquipTypeTxId(results, "JUNIT-U-4", "JUNIT-U-3");
569         verifyEquipTypeTimestamps(results, 20000L, 17000L);
570         verifyNodeTimestamps(results);
571     }
572
573     @Test
574     public void lifecycleQueryStartTsAtEquipTypeUpdateOnSecondPsTimeTest() throws Exception {
575
576         String endpoint = "/aai/v14/dsl?format=lifecycle&startTs=17000";
577         JsonArray results = getResultsForPserverLookupByHostname(endpoint);
578         assertEquals("Result size", 1, results.size());
579
580         verifyEquipTypeValues(results, null, "second-ps-type-update");
581         verifyEquipTypeSoTs(results, "JUNIT-U-4", "JUNIT-U-3");
582         verifyEquipTypeTxId(results, "JUNIT-U-4", "JUNIT-U-3");
583         verifyEquipTypeTimestamps(results, 20000L, 17000L);
584         verifyNodeTimestamps(results);
585     }
586
587     @Test
588     public void lifecycleQueryStartTsAfterEquipTypeUpdateOnSecondPsTimeTest() throws Exception {
589
590         String endpoint = "/aai/v14/dsl?format=lifecycle&startTs=19000";
591         JsonArray results = getResultsForPserverLookupByHostname(endpoint);
592         assertEquals("Result size", 1, results.size());
593
594         verifyEquipTypeValues(results, new String[] {null});
595         verifyEquipTypeSoTs(results, "JUNIT-U-4");
596         verifyEquipTypeTxId(results, "JUNIT-U-4");
597         verifyEquipTypeTimestamps(results, 20000L);
598         verifyNodeTimestamps(results);
599     }
600
601     @Test
602     public void lifecycleQueryStartTsOnEquipTypeSecondDeleteOnSecondPsTimeTest() throws Exception {
603
604         String endpoint = "/aai/v14/dsl?format=lifecycle&startTs=20000";
605         JsonArray results = getResultsForPserverLookupByHostname(endpoint);
606         assertEquals("Result size", 1, results.size());
607
608         verifyEquipTypeValues(results, new String[] {null});
609         verifyEquipTypeSoTs(results, "JUNIT-U-4");
610         verifyEquipTypeTxId(results, "JUNIT-U-4");
611         verifyEquipTypeTimestamps(results, 20000L);
612         verifyNodeTimestamps(results);
613     }
614
615     @Test
616     public void lifecycleQueryStartTsAfterEquipTypeSecondDeleteOnSecondPsTimeTest()
617         throws Exception {
618
619         String endpoint = "/aai/v14/dsl?format=lifecycle&startTs=22000";
620         JsonArray results = getResultsForPserverLookupByHostname(endpoint);
621         assertEquals("Result size", 0, results.size());
622
623         verifyEquipTypeValues(results);
624         verifyEquipTypeSoTs(results);
625         verifyEquipTypeTxId(results);
626         verifyEquipTypeTimestamps(results);
627         verifyNodeTimestamps(results);
628     }
629
630     @Test
631     public void lifecycleQueryStartTsBeforeCreationEndTimeAfterEquipTypeSecondDeleteOnSecondPsTimeTest()
632         throws Exception {
633
634         String endpoint = "/aai/v14/dsl?format=lifecycle&startTs=50&endTs=22000";
635         JsonArray results = getResultsForPserverLookupByHostname(endpoint);
636         assertEquals("Result size", 1, results.size());
637
638         verifyEquipTypeValues(results, null, "second-ps-type-update", "second-ps-type-recreated",
639             null, "second-ps-type", "first-ps-type-update", "first-ps-type");
640         verifyEquipTypeSoTs(results, "JUNIT-U-4", "JUNIT-U-3", "JUNIT-U-2", "JUNIT-U-1", "JUNIT-C",
641             "JUNIT-U", "JUNIT-C");
642         verifyEquipTypeTxId(results, "JUNIT-U-4", "JUNIT-U-3", "JUNIT-U-2", "JUNIT-U-1", "JUNIT-C",
643             "JUNIT-U", "JUNIT-C");
644         verifyEquipTypeTimestamps(results, 20000L, 17000L, 15000L, 13000L, 10000L, 500L, 100L);
645         verifyNodeTimestamps(results, 10000L, 1000L, 100L);
646     }
647
648     @Test
649     public void lifecycleQueryStartTsBeforeCreationEndTimeAtEquipTypeSecondDeleteOnSecondPsTimeTest()
650         throws Exception {
651
652         String endpoint = "/aai/v14/dsl?format=lifecycle&startTs=50&endTs=20000";
653         JsonArray results = getResultsForPserverLookupByHostname(endpoint);
654         assertEquals("Result size", 1, results.size());
655
656         verifyEquipTypeValues(results, null, "second-ps-type-update", "second-ps-type-recreated",
657             null, "second-ps-type", "first-ps-type-update", "first-ps-type");
658         verifyEquipTypeSoTs(results, "JUNIT-U-4", "JUNIT-U-3", "JUNIT-U-2", "JUNIT-U-1", "JUNIT-C",
659             "JUNIT-U", "JUNIT-C");
660         verifyEquipTypeTxId(results, "JUNIT-U-4", "JUNIT-U-3", "JUNIT-U-2", "JUNIT-U-1", "JUNIT-C",
661             "JUNIT-U", "JUNIT-C");
662         verifyEquipTypeTimestamps(results, 20000L, 17000L, 15000L, 13000L, 10000L, 500L, 100L);
663         verifyNodeTimestamps(results, 10000L, 1000L, 100L);
664     }
665
666     @Test
667     public void lifecycleQueryStartTsBeforeCreationEndTimeBeforeEquipTypeSecondDeleteOnSecondPsTimeTest()
668         throws Exception {
669
670         String endpoint = "/aai/v14/dsl?format=lifecycle&startTs=50&endTs=19000";
671         JsonArray results = getResultsForPserverLookupByHostname(endpoint);
672         assertEquals("Result size", 1, results.size());
673
674         verifyEquipTypeValues(results, "second-ps-type-update", "second-ps-type-recreated", null,
675             "second-ps-type", "first-ps-type-update", "first-ps-type");
676         verifyEquipTypeSoTs(results, "JUNIT-U-3", "JUNIT-U-2", "JUNIT-U-1", "JUNIT-C", "JUNIT-U",
677             "JUNIT-C");
678         verifyEquipTypeTxId(results, "JUNIT-U-3", "JUNIT-U-2", "JUNIT-U-1", "JUNIT-C", "JUNIT-U",
679             "JUNIT-C");
680         verifyEquipTypeTimestamps(results, 17000L, 15000L, 13000L, 10000L, 500L, 100L);
681         verifyNodeTimestamps(results, 10000L, 1000L, 100L);
682     }
683
684     @Test
685     public void lifecycleQueryStartTsBeforeCreationEndTimeBeforeSecondPsCreateTimeTest()
686         throws Exception {
687
688         String endpoint = "/aai/v14/dsl?format=lifecycle&startTs=50&endTs=9000";
689         JsonArray results = getResultsForPserverLookupByHostname(endpoint);
690         assertEquals("Result size", 1, results.size());
691
692         verifyEquipTypeValues(results, "first-ps-type-update", "first-ps-type");
693         verifyEquipTypeSoTs(results, "JUNIT-U", "JUNIT-C");
694         verifyEquipTypeTxId(results, "JUNIT-U", "JUNIT-C");
695         verifyEquipTypeTimestamps(results, 500L, 100L);
696         verifyNodeTimestamps(results, 1000L, 100L);
697     }
698
699     @Test
700     public void verifyNodeActionsWithNoTimeRangeTest() throws Exception {
701
702         String endpoint = "/aai/v14/dsl?format=lifecycle";
703         JsonArray results = getResultsForPserverLookupByHostname(endpoint);
704         assertEquals("Result size", 1, results.size());
705         verifyNodeTimestamps(results, 10000L, 1000L, 100L);
706         verifyNodeSot(results, "JUNIT-C", "JUNIT-D", "JUNIT-C");
707     }
708
709 }