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 org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
24 import org.janusgraph.core.JanusGraphTransaction;
26 import org.junit.runner.RunWith;
27 import org.junit.runners.Parameterized;
28 import org.onap.aai.AAISetup;
29 import org.onap.aai.HttpTestUtil;
30 import org.onap.aai.PayloadUtil;
31 import org.onap.aai.dbmap.AAIGraph;
32 import org.onap.aai.serialization.engines.QueryStyle;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
35 import org.springframework.test.context.junit4.rules.SpringClassRule;
36 import org.springframework.test.context.junit4.rules.SpringMethodRule;
38 import javax.ws.rs.core.Response;
39 import java.util.Arrays;
40 import java.util.Collection;
42 import static junit.framework.TestCase.fail;
43 import static org.junit.Assert.assertEquals;
45 @RunWith(value = Parameterized.class)
46 public class VnfcRelationshipIssueTest extends AAISetup {
48 private static final Logger LOGGER = LoggerFactory.getLogger(VnfcRelationshipIssueTest.class);
49 private HttpTestUtil httpTestUtil;
52 public static final SpringClassRule SPRING_CLASS_RULE = new SpringClassRule();
55 public final SpringMethodRule springMethodRule = new SpringMethodRule();
57 @Parameterized.Parameter(value = 0)
58 public QueryStyle queryStyle;
60 @Parameterized.Parameters(name = "QueryStyle.{0}")
61 public static Collection<Object[]> data() {
62 return Arrays.asList(new Object[][] {{QueryStyle.TRAVERSAL}, {QueryStyle.TRAVERSAL_URI}});
67 httpTestUtil = new HttpTestUtil(queryStyle);
71 public void testCreateVnfWithVfModuleAndCreateVnfcRelatedToVfModule() throws Exception {
73 String genericVnfUri = "/aai/v14/network/generic-vnfs/generic-vnf/test-vnf11";
74 String genericVnfPayload = PayloadUtil.getResourcePayload("generic-vnf-with-vf-module.json");
76 Response response = httpTestUtil.doPut(genericVnfUri, genericVnfPayload);
77 assertEquals("Expected the generic vnf to be created", 201, response.getStatus());
79 String vnfcUri = "/aai/v14/network/vnfcs/vnfc/test-vnfc11";
80 String vnfcPaylaod = PayloadUtil.getResourcePayload("vnfc-related-to-vf-module.json");
82 response = httpTestUtil.doPut(vnfcUri, vnfcPaylaod);
83 assertEquals("Expected the generic vnf to be created", 201, response.getStatus());
87 public void tearDown() {
89 JanusGraphTransaction transaction = AAIGraph.getInstance().getGraph().newTransaction();
90 boolean success = true;
94 GraphTraversalSource g = transaction.traversal();
96 g.V().has("source-of-truth", "JUNIT").toList().forEach(v -> v.remove());
98 } catch (Exception ex) {
100 LOGGER.error("Unable to remove the vertexes", ex);
103 transaction.commit();
105 transaction.rollback();
106 fail("Unable to teardown the graph");