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.serialization.db;
23 import org.apache.tinkerpop.gremlin.structure.Graph;
24 import org.apache.tinkerpop.gremlin.structure.Vertex;
25 import org.janusgraph.core.JanusGraphFactory;
27 import org.junit.rules.ExpectedException;
28 import org.onap.aai.AAISetup;
29 import org.onap.aai.db.props.AAIProperties;
30 import org.onap.aai.edges.EdgeIngestor;
31 import org.onap.aai.exceptions.AAIException;
32 import org.onap.aai.introspection.Introspector;
33 import org.onap.aai.introspection.Loader;
34 import org.onap.aai.introspection.ModelType;
35 import org.onap.aai.parsers.query.QueryParser;
36 import org.onap.aai.serialization.engines.JanusGraphDBEngine;
37 import org.onap.aai.serialization.engines.QueryStyle;
38 import org.onap.aai.serialization.engines.TransactionalGraphEngine;
39 import org.onap.aai.setup.SchemaVersion;
40 import org.springframework.beans.factory.annotation.Autowired;
41 import org.springframework.test.annotation.DirtiesContext;
43 import java.io.UnsupportedEncodingException;
45 import java.net.URISyntaxException;
46 import java.util.Collections;
48 import static com.jayway.jsonpath.matchers.JsonPathMatchers.hasJsonPath;
49 import static org.hamcrest.Matchers.*;
50 import static org.junit.Assert.assertThat;
51 import static org.junit.Assert.assertTrue;
53 @DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS)
54 public class EdgerPairCanBeBothCousinAndParentChildTest extends AAISetup {
56 // to use, set thrown.expect to whatever your test needs
57 // this line establishes default of expecting no exception to be thrown
59 public ExpectedException thrown = ExpectedException.none();
61 protected static Graph graph;
64 protected EdgeSerializer edgeSer;
66 protected EdgeIngestor ei;
68 private SchemaVersion version;
69 private final ModelType introspectorFactoryType = ModelType.MOXY;
70 private Loader loader;
71 private TransactionalGraphEngine engine;
73 public QueryStyle queryStyle = QueryStyle.TRAVERSAL_URI;
75 public static final String SOURCE_OF_TRUTH = "EdgerPairCanBeBothCousinAndParentChildTest";
76 private static final String gvnfAUri = "/network/generic-vnfs/generic-vnf/gvnf-a" + SOURCE_OF_TRUTH;
77 private static final String lagIntAUri = gvnfAUri + "/lag-interfaces/lag-interface/lagint-a";
78 private static final String lintUri = lagIntAUri + "/l-interfaces/l-interface/lint";
80 private static final String gvnfBUri = "/network/generic-vnfs/generic-vnf/gvnf-b" + SOURCE_OF_TRUTH;
81 private static final String lagIntBUri = gvnfBUri + "/lag-interfaces/lag-interface/lagint-b";
84 public static void init() {
85 graph = JanusGraphFactory.build().set("storage.backend", "inmemory").open();
90 public void setup() throws UnsupportedEncodingException, AAIException, URISyntaxException {
91 version = schemaVersions.getDefaultVersion();
92 loader = loaderFactory.createLoaderForVersion(introspectorFactoryType, version);
93 engine = new JanusGraphDBEngine(queryStyle, loader);
98 public void cleanup() {
103 * Using latest version (see schema-ingest.properties)
104 * Create generic-vnf with lag-interface that has an l-interface
105 * Create generic-vnf with lag-interface relationship the l-interface
107 private void initData() throws UnsupportedEncodingException, AAIException, URISyntaxException {
108 engine.startTransaction();
109 DBSerializer serializer = new DBSerializer(version, engine, introspectorFactoryType, SOURCE_OF_TRUTH, AAIProperties.MINIMUM_DEPTH);
112 Introspector gvnf = loader.introspectorFromName("generic-vnf");
113 gvnf.setValue("vnf-id", "gvnf-a" + SOURCE_OF_TRUTH);
114 gvnf.setValue("vnf-name", "gvnf" + SOURCE_OF_TRUTH + "-name");
116 Introspector lagInt = loader.introspectorFromName("lag-interface");
117 lagInt.setValue("interface-name", "lagint-a");
119 Introspector lint = loader.introspectorFromName("l-interface");
120 lint.setValue("interface-name", "lint");
122 Introspector lagints = loader.introspectorFromName("lag-interfaces");
123 Introspector lints = loader.introspectorFromName("l-interfaces");
125 lints.setValue("l-interface", Collections.singletonList(lint.getUnderlyingObject()));
126 lagInt.setValue("l-interfaces", lints.getUnderlyingObject());
127 lagints.setValue("lag-interface", Collections.singletonList(lagInt.getUnderlyingObject()));
128 gvnf.setValue("lag-interfaces", lagints.getUnderlyingObject());
132 Vertex gvnfV = serializer.createNewVertex(gvnf);
133 QueryParser uriQuery = engine.getQueryBuilder().createQueryFromURI(new URI(gvnfAUri));
134 serializer.serializeToDb(gvnf, gvnfV, uriQuery, "generic-vnf", gvnf.marshal(false));
136 assertTrue("generic-vnf-a created", engine.tx().traversal().V()
137 .has(AAIProperties.AAI_URI, gvnfAUri)
139 assertTrue("lag-int-a created", engine.tx().traversal().V()
140 .has(AAIProperties.AAI_URI, lagIntAUri)
142 assertTrue("l-int created", engine.tx().traversal().V()
143 .has(AAIProperties.AAI_URI, lintUri)
148 gvnf = loader.introspectorFromName("generic-vnf");
149 gvnf.setValue("vnf-id", "gvnf-b" + SOURCE_OF_TRUTH);
150 gvnf.setValue("vnf-name", "gvnf" + SOURCE_OF_TRUTH + "-name");
152 lagInt = loader.introspectorFromName("lag-interface");
153 lagInt.setValue("interface-name", "lagint-b");
154 Introspector relationship = loader.introspectorFromName("relationship");
155 relationship.setValue("related-link", lintUri);
156 Introspector relationshipList = loader.introspectorFromName("relationship-list");
157 relationshipList.setValue("relationship", Collections.singletonList(relationship.getUnderlyingObject()));
158 lagInt.setValue("relationship-list", relationshipList.getUnderlyingObject());
160 lagints = loader.introspectorFromName("lag-interfaces");
161 lagints.setValue("lag-interface", Collections.singletonList(lagInt.getUnderlyingObject()));
162 gvnf.setValue("lag-interfaces", lagints.getUnderlyingObject());
164 gvnfV = serializer.createNewVertex(gvnf);
165 uriQuery = engine.getQueryBuilder().createQueryFromURI(new URI(gvnfAUri));
166 serializer.serializeToDb(gvnf, gvnfV, uriQuery, "generic-vnf", gvnf.marshal(false));
168 engine.tx().traversal().V().forEachRemaining(v -> System.out.println(v.<String>value(AAIProperties.AAI_URI)));
169 assertTrue("generic-vnf-b created", engine.tx().traversal().V()
170 .has(AAIProperties.AAI_URI, gvnfBUri)
172 assertTrue("lag-int-b created", engine.tx().traversal().V()
173 .has(AAIProperties.AAI_URI, lagIntBUri)
175 assertTrue("lag-interface relationship l-interface created", engine.tx().traversal().V()
176 .has(AAIProperties.AAI_URI, lagIntBUri)
178 .has(AAIProperties.AAI_URI, lintUri)
184 public void verifyReadOfGenericVnfATest() throws AAIException, UnsupportedEncodingException {
185 DBSerializer serializer = new DBSerializer(version, engine, introspectorFactoryType, SOURCE_OF_TRUTH, AAIProperties.MINIMUM_DEPTH);
187 String gvnfALatestView = serializer.getLatestVersionView(
188 engine.tx().traversal().V().has(AAIProperties.AAI_URI, gvnfAUri).next()).marshal(false);
190 assertThat(gvnfALatestView,
192 "$.lag-interfaces.lag-interface[*]",
195 assertThat(gvnfALatestView,
197 "$.lag-interfaces.lag-interface[*].l-interfaces.l-interface[*]",
200 assertThat(gvnfALatestView,
202 "$.lag-interfaces.lag-interface[*].l-interfaces.l-interface[*].relationship-list.relationship[*].related-link",
204 "/aai/" + schemaVersions.getDefaultVersion() + lagIntBUri
210 public void verifyReadOfGenericVnfBTest() throws AAIException, UnsupportedEncodingException {
211 DBSerializer serializer = new DBSerializer(version, engine, introspectorFactoryType, SOURCE_OF_TRUTH, AAIProperties.MINIMUM_DEPTH);
213 String gvnfBLatestView = serializer.getLatestVersionView(
214 engine.tx().traversal().V().has(AAIProperties.AAI_URI, gvnfBUri).next()).marshal(false);
216 assertThat(gvnfBLatestView,
218 "$.lag-interfaces.lag-interface[*]",
221 assertThat(gvnfBLatestView,
223 "$.lag-interfaces.lag-interface[*].l-interfaces.l-interface[*]"
225 assertThat(gvnfBLatestView,
227 "$.lag-interfaces.lag-interface[*].relationship-list.relationship[*].related-link",
229 "/aai/" + schemaVersions.getDefaultVersion() + lintUri