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