AAI-1523 Batch reformat aai-core
[aai/aai-common.git] / aai-core / src / test / java / org / onap / aai / rest / EdgeNotValidAnymoreTest.java
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
21 package org.onap.aai.rest;
22
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;
27
28 import java.io.IOException;
29 import java.util.UUID;
30
31 import javax.ws.rs.core.Response;
32
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;
50
51 public class EdgeNotValidAnymoreTest extends AAISetup {
52
53     private HttpTestUtil testUtil;
54
55     @Before
56     public void setupData() throws IOException, AAIException {
57
58         String cloudRegionEndpoint =
59                 "/aai/v13/cloud-infrastructure/cloud-regions/cloud-region/junit-cloud-owner-with-vlan/junit-cloud-region-with-vlan";
60
61         String cloudRegionBody = PayloadUtil.getResourcePayload("cloud-region-with-vlan.json");
62         testUtil = new HttpTestUtil(QueryStyle.TRAVERSAL_URI);
63         testUtil.doPut(cloudRegionEndpoint, cloudRegionBody);
64
65         JanusGraphTransaction transaction = AAIGraph.getInstance().getGraph().newTransaction();
66         GraphTraversalSource g = transaction.traversal();
67
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();
72
73         Vertex vlanVertex =
74                 g.V().has("vlan-interface", "test-vlan-interface-1").has(AAIProperties.NODE_TYPE, "vlan").next();
75
76         Edge edge = configurationVertex.addEdge("org.onap.relationships.inventory.PartOf", vlanVertex);
77         addEdge(edge);
78
79         transaction.commit();
80     }
81
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());
88     }
89
90     @Test
91     public void testWhenEdgeRuleIsNoLongerValidEnsureItRetrievesVertexesWithoutOldEdges() {
92
93         String endpoint = "/aai/v14/network/configurations";
94
95         Response response = testUtil.doGet(endpoint, null);
96         assertThat(response.getStatus(), is(200));
97
98         String body = response.getEntity().toString();
99
100         assertThat(body, containsString("configuration-id"));
101         assertThat(body, not(containsString("vlan")));
102     }
103
104     @After
105     public void teardown() {
106
107         JanusGraph janusGraph = AAIGraph.getInstance().getGraph();
108         JanusGraphTransaction transaction = janusGraph.newTransaction();
109         GraphTraversalSource g = transaction.traversal();
110
111         g.V().has(AAIProperties.SOURCE_OF_TRUTH, "JUNIT").toList().forEach((edge) -> edge.remove());
112
113         transaction.commit();
114     }
115 }