a3520f5630fb60db9c7d0945be5a68d46b9ca8ae
[aai/aai-common.git] / aai-core / src / test / java / org / onap / aai / rest / PrivateEdgeIntegrationOldClientTest.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 package org.onap.aai.rest;
21
22
23 import com.jayway.jsonpath.JsonPath;
24 import org.apache.tinkerpop.gremlin.structure.Edge;
25 import org.junit.Before;
26 import org.junit.Test;
27 import org.junit.runner.RunWith;
28 import org.junit.runners.Parameterized;
29 import org.onap.aai.AAISetup;
30 import org.onap.aai.HttpTestUtil;
31 import org.onap.aai.PayloadUtil;
32 import org.onap.aai.dbmap.AAIGraph;
33 import org.onap.aai.serialization.engines.QueryStyle;
34 import org.onap.aai.setup.SchemaVersion;
35 import org.springframework.test.annotation.DirtiesContext;
36
37 import javax.ws.rs.core.Response;
38 import java.util.*;
39
40 import static org.hamcrest.CoreMatchers.containsString;
41 import static org.hamcrest.CoreMatchers.not;
42 import static org.hamcrest.MatcherAssert.assertThat;
43 import static org.hamcrest.core.Is.is;
44 import static org.junit.Assert.assertNotNull;
45
46 @RunWith(value = Parameterized.class)
47 @DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS)
48 public class PrivateEdgeIntegrationOldClientTest extends AAISetup {
49
50     private HttpTestUtil httpTestUtil;
51     private Map<String, String> relationshipMap;
52
53     private String modelId;
54     private String modelVerId;
55
56
57     @Parameterized.Parameter(value = 0)
58     public QueryStyle queryStyle;
59
60     @Parameterized.Parameter(value = 1)
61     public SchemaVersion version;
62
63     @Parameterized.Parameters(name = "QueryStyle.{0} {1}")
64     public static Collection<Object[]> data() {
65         return Arrays.asList(new Object[][]{
66                 {QueryStyle.TRAVERSAL, new SchemaVersion("v14")},
67                 {QueryStyle.TRAVERSAL_URI, new SchemaVersion("v14")},
68         });
69     }
70
71     @Before
72     public void setUpModelData() throws Exception {
73         httpTestUtil = new HttpTestUtil(QueryStyle.TRAVERSAL);
74         relationshipMap = new HashMap<>();
75
76         modelId = "test-model-" + UUID.randomUUID().toString();
77         modelVerId = "test-model-ver-" + UUID.randomUUID().toString();
78
79         Map<String, String> modelTemplateValues = new HashMap<>();
80         modelTemplateValues.put("model-invariant-id", modelId);
81
82         String modelPayload =  PayloadUtil.getTemplatePayload("model.json", modelTemplateValues);
83
84         Response response = httpTestUtil.doPut("/aai/"+version.toString()+"/service-design-and-creation/models/model/" + modelId, modelPayload);
85
86         assertNotNull(response);
87         assertThat("Model was not successfully created", response.getStatus(), is(201));
88
89         Map<String, String> modelVersionTemplateValues = new HashMap<>();
90         modelVersionTemplateValues.put("model-version-id", modelVerId);
91         modelVersionTemplateValues.put("model-name", "some-model");
92         modelVersionTemplateValues.put("model-version", "testValue");
93
94         String modelVersionPayload =  PayloadUtil.getTemplatePayload("model-ver.json", modelVersionTemplateValues);
95
96         response = httpTestUtil.doPut("/aai/"+version.toString()+"/service-design-and-creation/models/model/" + modelId + "/model-vers/model-ver/" + modelVerId, modelVersionPayload);
97         assertNotNull(response);
98         assertThat("Model was not successfully created", response.getStatus(), is(201));
99     }
100
101     @Test
102     public void testPutGenericVnfWithModelInfoToMatchExistingModelAndCheckIfPrivateEdgeCreatedAndDoGetOnOldModelAndMakeSureNoRelationship() throws Exception {
103
104         Map<String, String> genericVnfHashMap = new HashMap<>();
105         String genericVnf = "test-generic-" + UUID.randomUUID().toString();
106
107         genericVnfHashMap.put("vnf-id", genericVnf);
108         genericVnfHashMap.put("model-invariant-id", modelId);
109         genericVnfHashMap.put("model-version-id", modelVerId);
110         String genericVnfPayload = PayloadUtil.getTemplatePayload("generic-vnf.json", genericVnfHashMap);
111
112         Response response = httpTestUtil.doPut("/aai/"+version.toString()+"/network/generic-vnfs/generic-vnf/" + genericVnf, genericVnfPayload);
113         assertNotNull("Response returned null", response);
114         assertThat("Check the generic vnf is created", response.getStatus(), is(201));
115
116         response = httpTestUtil.doGet("/aai/"+version.toString()+"/network/generic-vnfs/generic-vnf/" + genericVnf);
117         assertNotNull("Response returned null", response);
118         assertThat("Check the generic vnf is created", response.getStatus(), is(200));
119         assertThat(response.getEntity().toString(), not(containsString("relationship-list")));
120
121         List<Edge> edges = AAIGraph.getInstance().getGraph().newTransaction().traversal().E().has("private", true).toList();
122         assertNotNull("List of edges should not be null", edges);
123         assertThat(edges.size(), is(1));
124         Edge oldEdge = edges.get(0);
125         assertNotNull(oldEdge);
126
127         response = httpTestUtil.doGet("/aai/v11/network/generic-vnfs/generic-vnf/" + genericVnf);
128         assertNotNull("Response returned null", response);
129         assertThat("Check the generic vnf is created", response.getStatus(), is(200));
130         assertThat(response.getEntity().toString(), not(containsString("relationship-list")));
131
132         String resourceVersion = JsonPath.read(response.getEntity().toString(), "$.resource-version");
133         response = httpTestUtil.doDelete("/aai/"+version.toString()+"/network/generic-vnfs/generic-vnf/" + genericVnf, resourceVersion);
134         assertNotNull("Response returned null", response);
135         assertThat("Check the generic vnf is deleted", response.getStatus(), is(204));
136
137         edges = AAIGraph.getInstance().getGraph().newTransaction().traversal().E().has("private", true).toList();
138         assertNotNull("List of edges should not be null", edges);
139         assertThat(edges.size(), is(0));
140     }
141
142 }