Merge "[AAI] Fix doc config files"
[aai/aai-common.git] / aai-core / src / test / java / org / onap / aai / rest / VnfcRelationshipIssueTest.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 junit.framework.TestCase.fail;
24 import static org.junit.Assert.assertEquals;
25
26 import java.util.Arrays;
27 import java.util.Collection;
28
29 import javax.ws.rs.core.Response;
30
31 import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
32 import org.janusgraph.core.JanusGraphTransaction;
33 import org.junit.*;
34 import org.junit.runner.RunWith;
35 import org.junit.runners.Parameterized;
36 import org.onap.aai.AAISetup;
37 import org.onap.aai.HttpTestUtil;
38 import org.onap.aai.PayloadUtil;
39 import org.onap.aai.dbmap.AAIGraph;
40 import org.onap.aai.serialization.engines.QueryStyle;
41 import org.slf4j.Logger;
42 import org.slf4j.LoggerFactory;
43 import org.springframework.test.context.junit4.rules.SpringClassRule;
44 import org.springframework.test.context.junit4.rules.SpringMethodRule;
45
46 @RunWith(value = Parameterized.class)
47 public class VnfcRelationshipIssueTest extends AAISetup {
48
49     private static final Logger LOGGER = LoggerFactory.getLogger(VnfcRelationshipIssueTest.class);
50     private HttpTestUtil httpTestUtil;
51
52     @ClassRule
53     public static final SpringClassRule SPRING_CLASS_RULE = new SpringClassRule();
54
55     @Rule
56     public final SpringMethodRule springMethodRule = new SpringMethodRule();
57
58     @Parameterized.Parameter(value = 0)
59     public QueryStyle queryStyle;
60
61     @Parameterized.Parameters(name = "QueryStyle.{0}")
62     public static Collection<Object[]> data() {
63         return Arrays.asList(new Object[][] {{QueryStyle.TRAVERSAL}, {QueryStyle.TRAVERSAL_URI}});
64     }
65
66     @Before
67     public void setUp() {
68         httpTestUtil = new HttpTestUtil(queryStyle);
69     }
70
71     @Test
72     public void testCreateVnfWithVfModuleAndCreateVnfcRelatedToVfModule() throws Exception {
73
74         String genericVnfUri = "/aai/v14/network/generic-vnfs/generic-vnf/test-vnf11";
75         String genericVnfPayload = PayloadUtil.getResourcePayload("generic-vnf-with-vf-module.json");
76
77         Response response = httpTestUtil.doPut(genericVnfUri, genericVnfPayload);
78         assertEquals("Expected the generic vnf to be created", 201, response.getStatus());
79
80         String vnfcUri = "/aai/v14/network/vnfcs/vnfc/test-vnfc11";
81         String vnfcPaylaod = PayloadUtil.getResourcePayload("vnfc-related-to-vf-module.json");
82
83         response = httpTestUtil.doPut(vnfcUri, vnfcPaylaod);
84         assertEquals("Expected the generic vnf to be created", 201, response.getStatus());
85     }
86
87     @After
88     public void tearDown() {
89
90         JanusGraphTransaction transaction = AAIGraph.getInstance().getGraph().newTransaction();
91         boolean success = true;
92
93         try {
94
95             GraphTraversalSource g = transaction.traversal();
96
97             g.V().has("source-of-truth", "JUNIT").toList().forEach(v -> v.remove());
98
99         } catch (Exception ex) {
100             success = false;
101             LOGGER.error("Unable to remove the vertexes", ex);
102         } finally {
103             if (success) {
104                 transaction.commit();
105             } else {
106                 transaction.rollback();
107                 fail("Unable to teardown the graph");
108             }
109         }
110
111     }
112 }