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