2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.aai.rest;
23 import static org.hamcrest.CoreMatchers.containsString;
24 import static org.hamcrest.CoreMatchers.is;
25 import static org.hamcrest.Matchers.not;
26 import static org.junit.Assert.assertThat;
28 import java.io.IOException;
29 import java.util.UUID;
31 import javax.ws.rs.core.Response;
33 import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
34 import org.apache.tinkerpop.gremlin.structure.Edge;
35 import org.apache.tinkerpop.gremlin.structure.Vertex;
36 import org.janusgraph.core.JanusGraph;
37 import org.janusgraph.core.JanusGraphTransaction;
38 import org.junit.After;
39 import org.junit.Before;
40 import org.junit.Test;
41 import org.onap.aai.AAISetup;
42 import org.onap.aai.HttpTestUtil;
43 import org.onap.aai.PayloadUtil;
44 import org.onap.aai.db.props.AAIProperties;
45 import org.onap.aai.dbmap.AAIGraph;
46 import org.onap.aai.edges.enums.EdgeField;
47 import org.onap.aai.edges.enums.EdgeProperty;
48 import org.onap.aai.exceptions.AAIException;
49 import org.onap.aai.serialization.engines.QueryStyle;
51 public class EdgeNotValidAnymoreTest extends AAISetup {
53 private HttpTestUtil testUtil;
56 public void setupData() throws IOException, AAIException {
58 String cloudRegionEndpoint =
59 "/aai/v13/cloud-infrastructure/cloud-regions/cloud-region/junit-cloud-owner-with-vlan/junit-cloud-region-with-vlan";
61 String cloudRegionBody = PayloadUtil.getResourcePayload("cloud-region-with-vlan.json");
62 testUtil = new HttpTestUtil(QueryStyle.TRAVERSAL_URI);
63 testUtil.doPut(cloudRegionEndpoint, cloudRegionBody);
65 JanusGraphTransaction transaction = AAIGraph.getInstance().getGraph().newTransaction();
66 GraphTraversalSource g = transaction.traversal();
68 Vertex configurationVertex = g.addV().property(AAIProperties.NODE_TYPE, "configuration")
69 .property("configuration-id", "ci1").property("configuration-type", "ci1")
70 .property(AAIProperties.AAI_URI, "/network/configurations/configuration/ci1")
71 .property(AAIProperties.SOURCE_OF_TRUTH, "JUNIT").next();
74 g.V().has("vlan-interface", "test-vlan-interface-1").has(AAIProperties.NODE_TYPE, "vlan").next();
76 Edge edge = configurationVertex.addEdge("org.onap.relationships.inventory.PartOf", vlanVertex);
82 public void addEdge(Edge edge) {
83 edge.property(EdgeProperty.CONTAINS.toString(), "NONE");
84 edge.property(EdgeProperty.DELETE_OTHER_V.toString(), "NONE");
85 edge.property(EdgeProperty.PREVENT_DELETE.toString(), "NONE");
86 edge.property(EdgeField.PRIVATE.toString(), false);
87 edge.property(AAIProperties.AAI_UUID, UUID.randomUUID().toString());
91 public void testWhenEdgeRuleIsNoLongerValidEnsureItRetrievesVertexesWithoutOldEdges() {
93 String endpoint = "/aai/v14/network/configurations";
95 Response response = testUtil.doGet(endpoint, null);
96 assertThat(response.getStatus(), is(200));
98 String body = response.getEntity().toString();
100 assertThat(body, containsString("configuration-id"));
101 assertThat(body, not(containsString("vlan")));
105 public void teardown() {
107 JanusGraph janusGraph = AAIGraph.getInstance().getGraph();
108 JanusGraphTransaction transaction = janusGraph.newTransaction();
109 GraphTraversalSource g = transaction.traversal();
111 g.V().has(AAIProperties.SOURCE_OF_TRUTH, "JUNIT").toList().forEach((edge) -> edge.remove());
113 transaction.commit();