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 junit.framework.TestCase.fail;
24 import static org.junit.Assert.assertEquals;
26 import java.util.Arrays;
27 import java.util.Collection;
29 import javax.ws.rs.core.Response;
31 import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
32 import org.janusgraph.core.JanusGraphTransaction;
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;
46 @RunWith(value = Parameterized.class)
47 public class VnfcRelationshipIssueTest extends AAISetup {
49 private static final Logger LOGGER = LoggerFactory.getLogger(VnfcRelationshipIssueTest.class);
50 private HttpTestUtil httpTestUtil;
53 public static final SpringClassRule SPRING_CLASS_RULE = new SpringClassRule();
56 public final SpringMethodRule springMethodRule = new SpringMethodRule();
58 @Parameterized.Parameter(value = 0)
59 public QueryStyle queryStyle;
61 @Parameterized.Parameters(name = "QueryStyle.{0}")
62 public static Collection<Object[]> data() {
63 return Arrays.asList(new Object[][] {{QueryStyle.TRAVERSAL}, {QueryStyle.TRAVERSAL_URI}});
68 httpTestUtil = new HttpTestUtil(queryStyle);
72 public void testCreateVnfWithVfModuleAndCreateVnfcRelatedToVfModule() throws Exception {
74 String genericVnfUri = "/aai/v14/network/generic-vnfs/generic-vnf/test-vnf11";
75 String genericVnfPayload = PayloadUtil.getResourcePayload("generic-vnf-with-vf-module.json");
77 Response response = httpTestUtil.doPut(genericVnfUri, genericVnfPayload);
78 assertEquals("Expected the generic vnf to be created", 201, response.getStatus());
80 String vnfcUri = "/aai/v14/network/vnfcs/vnfc/test-vnfc11";
81 String vnfcPaylaod = PayloadUtil.getResourcePayload("vnfc-related-to-vf-module.json");
83 response = httpTestUtil.doPut(vnfcUri, vnfcPaylaod);
84 assertEquals("Expected the generic vnf to be created", 201, response.getStatus());
88 public void tearDown() {
90 JanusGraphTransaction transaction = AAIGraph.getInstance().getGraph().newTransaction();
91 boolean success = true;
95 GraphTraversalSource g = transaction.traversal();
97 g.V().has("source-of-truth", "JUNIT").toList().forEach(v -> v.remove());
99 } catch (Exception ex) {
101 LOGGER.error("Unable to remove the vertexes", ex);
104 transaction.commit();
106 transaction.rollback();
107 fail("Unable to teardown the graph");