summaryrefslogtreecommitdiffstats
path: root/aai-core/src/test/java
diff options
context:
space:
mode:
Diffstat (limited to 'aai-core/src/test/java')
-rw-r--r--aai-core/src/test/java/org/onap/aai/HttpTestUtil.java52
-rw-r--r--aai-core/src/test/java/org/onap/aai/parsers/uri/URIToObjectTest.java51
-rw-r--r--aai-core/src/test/java/org/onap/aai/rest/EdgeNotValidAnymoreTest.java120
-rw-r--r--aai-core/src/test/java/org/onap/aai/rest/EntitlementTest.java96
-rw-r--r--aai-core/src/test/java/org/onap/aai/rest/ModelElementTest.java98
-rw-r--r--aai-core/src/test/java/org/onap/aai/rest/PserverDuplicateTest.java135
-rw-r--r--aai-core/src/test/java/org/onap/aai/rest/VipAddressListTest.java99
-rw-r--r--aai-core/src/test/java/org/onap/aai/serialization/db/DbSerializerTest.java17
-rw-r--r--aai-core/src/test/java/org/onap/aai/serialization/engines/query/GraphTraversalQueryEngineTest.java157
9 files changed, 711 insertions, 114 deletions
diff --git a/aai-core/src/test/java/org/onap/aai/HttpTestUtil.java b/aai-core/src/test/java/org/onap/aai/HttpTestUtil.java
index 82a3efdf..92cb59c5 100644
--- a/aai-core/src/test/java/org/onap/aai/HttpTestUtil.java
+++ b/aai-core/src/test/java/org/onap/aai/HttpTestUtil.java
@@ -52,11 +52,11 @@ import static org.mockito.Mockito.when;
public class HttpTestUtil extends RESTAPI {
-
- protected HttpEntry traversalHttpEntry;
-
- protected HttpEntry traversalUriHttpEntry;
-
+
+ protected HttpEntry traversalHttpEntry;
+
+ protected HttpEntry traversalUriHttpEntry;
+
private static final EELFLogger logger = EELFManager.getInstance().getLogger(HttpTestUtil.class);
protected static final MediaType APPLICATION_JSON = MediaType.valueOf("application/json");
@@ -77,7 +77,7 @@ public class HttpTestUtil extends RESTAPI {
this.queryStyle = qs;
traversalHttpEntry = SpringContextAware.getBean("traversalUriHttpEntry", HttpEntry.class);
traversalUriHttpEntry = SpringContextAware.getBean("traversalUriHttpEntry", HttpEntry.class);
-
+
}
public void init(){
@@ -121,7 +121,10 @@ public class HttpTestUtil extends RESTAPI {
try {
- uri = uri.replaceAll("/aai/", "");
+ if(uri.startsWith("/aai/")){
+ uri = uri.substring(5);
+ }
+
logger.info("Starting the put request for the uri {} with payload {}", uri, payload);
String [] arr = uri.split("/");
@@ -142,7 +145,7 @@ public class HttpTestUtil extends RESTAPI {
Mockito.when(uriInfo.getPath()).thenReturn(uri);
DBConnectionType type = DBConnectionType.REALTIME;
-
+
traversalHttpEntry.setHttpEntryProperties(version, type);
Loader loader = traversalHttpEntry.getLoader();
dbEngine = traversalHttpEntry.getDbEngine();
@@ -206,7 +209,7 @@ public class HttpTestUtil extends RESTAPI {
return response;
}
- public Response doGet(String uri) throws UnsupportedEncodingException, AAIException {
+ public Response doGet(String uri, String depth){
this.init();
Response response = null;
@@ -215,8 +218,11 @@ public class HttpTestUtil extends RESTAPI {
try {
- uri = uri.replaceAll("/aai/", "");
- logger.info("Starting the GET request for the uri {} with depth {}", uri, "all");
+ if(uri.startsWith("/aai/")){
+ uri = uri.substring(5);
+ }
+
+ logger.info("Starting the GET request for the uri {} with depth {}", uri, depth);
String [] arr = uri.split("/");
@@ -240,21 +246,29 @@ public class HttpTestUtil extends RESTAPI {
dbEngine = traversalHttpEntry.getDbEngine();
URI uriObject = UriBuilder.fromPath(uri).build();
- URIToObject uriToObject = new URIToObject(loader, uriObject);
- String objType = uriToObject.getEntityName();
- queryParameters.add("depth", "all");
+ if(depth != null){
+ queryParameters.add("depth", depth);
+ }
+
QueryParser uriQuery = dbEngine.getQueryBuilder().createQueryFromURI(uriObject, queryParameters);
Mockito.when(uriInfo.getPath()).thenReturn(uri);
+ URIToObject uriToObject = new URIToObject(loader, uriObject);
+ String objType = "";
+ if (!uriQuery.getContainerType().equals("")) {
+ objType = uriQuery.getContainerType();
+ } else {
+ objType = uriQuery.getResultType();
+ }
logger.info("Unmarshalling the payload to this {}", objType);
Introspector obj = loader.introspectorFromName(objType);
DBRequest dbRequest =
- new DBRequest.Builder(HttpMethod.GET, uriObject, uriQuery, obj, httpHeaders, uriInfo, "JUNIT-TRANSACTION")
- .build();
+ new DBRequest.Builder(HttpMethod.GET, uriObject, uriQuery, obj, httpHeaders, uriInfo, "JUNIT-TRANSACTION")
+ .build();
List<DBRequest> dbRequestList = new ArrayList<>();
dbRequestList.add(dbRequest);
@@ -288,6 +302,10 @@ public class HttpTestUtil extends RESTAPI {
return response;
}
+ public Response doGet(String uri) throws UnsupportedEncodingException, AAIException {
+ return this.doGet(uri, "all");
+ }
+
public Response doDelete(String uri, String resourceVersion) throws UnsupportedEncodingException, AAIException {
this.init();
@@ -321,7 +339,7 @@ public class HttpTestUtil extends RESTAPI {
Mockito.when(uriInfo.getPath()).thenReturn(uri);
DBConnectionType type = DBConnectionType.REALTIME;
traversalHttpEntry.setHttpEntryProperties(version, type);
-
+
traversalHttpEntry.setHttpEntryProperties(version, type);
Loader loader = traversalHttpEntry.getLoader();
dbEngine = traversalHttpEntry.getDbEngine();
diff --git a/aai-core/src/test/java/org/onap/aai/parsers/uri/URIToObjectTest.java b/aai-core/src/test/java/org/onap/aai/parsers/uri/URIToObjectTest.java
index c7c1f4ca..fc2c64a1 100644
--- a/aai-core/src/test/java/org/onap/aai/parsers/uri/URIToObjectTest.java
+++ b/aai-core/src/test/java/org/onap/aai/parsers/uri/URIToObjectTest.java
@@ -19,6 +19,7 @@
*/
package org.onap.aai.parsers.uri;
+import org.onap.aai.schema.enums.ObjectMetadata;
import org.onap.aai.setup.SchemaVersion;
import org.junit.Ignore;
@@ -65,7 +66,7 @@ public class URIToObjectTest extends AAISetup {
currentVersion = schemaVersions.getDefaultVersion();
loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getRelatedLinkVersion());
}
-
+
@Test
public void uri() throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException {
URI uri = UriBuilder.fromPath("/aai/" + loader.getVersion() + "/cloud-infrastructure/cloud-regions/cloud-region/mycloudowner/mycloudregionid/tenants/tenant/key1/vservers/vserver/key2/l-interfaces/l-interface/key3").build();
@@ -74,11 +75,11 @@ public class URIToObjectTest extends AAISetup {
String expected = "{\"cloud-owner\":\"mycloudowner\",\"cloud-region-id\":\"mycloudregionid\",\"tenants\":{\"tenant\":[{\"tenant-id\":\"key1\",\"vservers\":{\"vserver\":[{\"vserver-id\":\"key2\",\"l-interfaces\":{\"l-interface\":[{\"interface-name\":\"key3\"}]}}]}}]}}";
String topEntity = "cloud-region";
String entity = "l-interface";
-
+
testSet(result.marshal(false), parse, expected, topEntity, entity, version);
}
-
+
/**
* Uri no version.
*
@@ -86,7 +87,7 @@ public class URIToObjectTest extends AAISetup {
* @throws AAIException the AAI exception
* @throws IllegalArgumentException the illegal argument exception
* @throws UnsupportedEncodingException the unsupported encoding exception
- * @throws AAIUnknownObjectException
+ * @throws AAIUnknownObjectException
*/
@Test
public void uriNoVersion() throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException, AAIUnknownObjectException {
@@ -106,12 +107,12 @@ public class URIToObjectTest extends AAISetup {
String expected = "{\"cloud-owner\":\"mycloudowner\",\"cloud-region-id\":\"mycloudregionid\",\"tenants\":{\"tenant\":[{\"tenant-id\":\"key1\",\"tenant-name\":\"name1\",\"vservers\":{\"vserver\":[{\"vserver-id\":\"key2\",\"vserver-name\":\"name2\",\"l-interfaces\":{\"l-interface\":[{\"interface-name\":\"key3\"}]}}]}}]}}";
String topEntity = "cloud-region";
String entity = "l-interface";
-
+
testSet(result.marshal(false), parse, expected, topEntity, entity, version);
-
+
}
-
+
/**
* Bad URI.
@@ -124,13 +125,13 @@ public class URIToObjectTest extends AAISetup {
@Test
public void badURI() throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException {
URI uri = UriBuilder.fromPath("/aai/" + loader.getVersion() + "/cloud-infrastructure/cloud-regions/cloud-region/mycloudowner/mycloudregionid/tenants/tenant/key1/vservers/vserver/key2/l-interadsfaces/l-interface/key3").build();
-
+
thrown.expect(AAIException.class);
thrown.expect(hasProperty("code", is("AAI_3000")));
-
+
new URIToObject(loader, uri);
}
-
+
/**
* Starts with valid namespace.
*
@@ -147,10 +148,10 @@ public class URIToObjectTest extends AAISetup {
String expected = "{\"cloud-owner\":\"mycloudowner\",\"cloud-region-id\":\"mycloudregionid\",\"tenants\":{\"tenant\":[{\"tenant-id\":\"key1\",\"vservers\":{\"vserver\":[{\"vserver-id\":\"key2\",\"l-interfaces\":{\"l-interface\":[{\"interface-name\":\"key3\"}]}}]}}]}}";
String topEntity = "cloud-region";
String entity = "l-interface";
-
+
testSet(result.marshal(false), parse, expected, topEntity, entity, version);
}
-
+
/**
* Single top level.
*
@@ -165,14 +166,14 @@ public class URIToObjectTest extends AAISetup {
URIToObject parse = new URIToObject(loader, uri);
Introspector result = parse.getTopEntity();
String expected = "{\"vnf-id\":\"key1\"}";
-
+
String topEntity = "generic-vnf";
String entity = "generic-vnf";
-
+
testSet(result.marshal(false), parse, expected, topEntity, entity, version);
}
-
+
/**
* Naming exceptions.
*
@@ -190,11 +191,11 @@ public class URIToObjectTest extends AAISetup {
String expected = "{\"vnf-id\":\"key1\",\"port-groups\":{\"port-group\":[{\"interface-id\":\"key2\",\"cvlan-tags\":{\"cvlan-tag-entry\":[{\"cvlan-tag\":655}]}}]}}";
String topEntity = "vce";
String entity = "cvlan-tag";
-
+
testSet(result.marshal(false), parse, expected, topEntity, entity, version);
}
-
+
/**
* No list object.
*
@@ -212,23 +213,23 @@ public class URIToObjectTest extends AAISetup {
String entity = "l3-interface-ipv4-address-list";
String expected = "{\"equipment-name\":\"0e6189fd-9257-49b9-a3be-d7ba980ccfc9\",\"lag-interfaces\":{\"lag-interface\":[{\"interface-name\":\"8ae5aa76-d597-4382-b219-04f266fe5e37\",\"l-interfaces\":{\"l-interface\":[{\"interface-name\":\"9e141d03-467b-437f-b4eb-b3133ec1e205\",\"l3-interface-ipv4-address-list\":[{\"l3-interface-ipv4-address\":\"8f19f0ea-a81f-488e-8d5c-9b7b53696c11\"}]}]}}]}}";
testSet(result.marshal(false), parse, expected, topEntity, entity, version);
-
+
}
-
+
@Test
public void relativePath() throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException {
URI uri = UriBuilder.fromPath("./l-interfaces/l-interface/key1").build();
URIToObject parse = new URIToObject(loader, uri);
Introspector result = parse.getEntity();
String expected = "{\"interface-name\":\"key1\"}";
-
+
String topEntity = "l-interface";
String entity = "l-interface";
-
+
testSet(result.marshal(false), parse, expected, topEntity, entity, version);
}
-
+
/**
* Test set.
*
@@ -241,15 +242,15 @@ public class URIToObjectTest extends AAISetup {
*/
public void testSet(String json, URIToObject parse, String expected, String topEntity, String entity, SchemaVersion version) {
assertEquals("blah", expected, json);
-
+
assertEquals("top entity", topEntity, parse.getTopEntityName());
assertEquals("entity", entity, parse.getEntityName());
assertEquals("entity object", entity, parse.getEntity().getDbName());
-
+
assertEquals("parent list object", 1, parse.getParentList().size());
-
+
assertEquals("object version", version, parse.getObjectVersion());
}
}
diff --git a/aai-core/src/test/java/org/onap/aai/rest/EdgeNotValidAnymoreTest.java b/aai-core/src/test/java/org/onap/aai/rest/EdgeNotValidAnymoreTest.java
new file mode 100644
index 00000000..1a69fc58
--- /dev/null
+++ b/aai-core/src/test/java/org/onap/aai/rest/EdgeNotValidAnymoreTest.java
@@ -0,0 +1,120 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.aai.rest;
+
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
+import org.apache.tinkerpop.gremlin.structure.Edge;
+import org.apache.tinkerpop.gremlin.structure.Vertex;
+import org.janusgraph.core.JanusGraph;
+import org.janusgraph.core.JanusGraphTransaction;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.aai.AAISetup;
+import org.onap.aai.HttpTestUtil;
+import org.onap.aai.PayloadUtil;
+import org.onap.aai.db.props.AAIProperties;
+import org.onap.aai.dbmap.AAIGraph;
+import org.onap.aai.edges.enums.EdgeField;
+import org.onap.aai.edges.enums.EdgeProperty;
+import org.onap.aai.exceptions.AAIException;
+import org.onap.aai.serialization.engines.QueryStyle;
+
+import javax.ws.rs.core.Response;
+import java.io.IOException;
+import java.util.UUID;
+
+import static org.hamcrest.CoreMatchers.containsString;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.Matchers.not;
+import static org.junit.Assert.assertThat;
+
+public class EdgeNotValidAnymoreTest extends AAISetup {
+
+ private HttpTestUtil testUtil;
+
+ @Before
+ public void setupData() throws IOException, AAIException {
+
+ String cloudRegionEndpoint = "/aai/v13/cloud-infrastructure/cloud-regions/cloud-region/junit-cloud-owner-with-vlan/junit-cloud-region-with-vlan";
+
+ String cloudRegionBody = PayloadUtil.getResourcePayload("cloud-region-with-vlan.json");
+ testUtil = new HttpTestUtil(QueryStyle.TRAVERSAL_URI);
+ testUtil.doPut(cloudRegionEndpoint, cloudRegionBody);
+
+ JanusGraphTransaction transaction = AAIGraph.getInstance().getGraph().newTransaction();
+ GraphTraversalSource g = transaction.traversal();
+
+ Vertex configurationVertex = g.addV()
+ .property( AAIProperties.NODE_TYPE, "configuration")
+ .property( "configuration-id", "ci1")
+ .property( "configuration-type", "ci1")
+ .property( AAIProperties.AAI_URI, "/network/configurations/configuration/ci1")
+ .property(AAIProperties.SOURCE_OF_TRUTH, "JUNIT")
+ .next();
+
+ Vertex vlanVertex = g.V()
+ .has("vlan-interface", "test-vlan-interface-1")
+ .has(AAIProperties.NODE_TYPE, "vlan")
+ .next();
+
+ Edge edge = configurationVertex.addEdge("org.onap.relationships.inventory.PartOf", vlanVertex);
+ addEdge(edge);
+
+ transaction.commit();
+ }
+
+ public void addEdge(Edge edge) {
+ edge.property(EdgeProperty.CONTAINS.toString(), "NONE");
+ edge.property(EdgeProperty.DELETE_OTHER_V.toString(), "NONE");
+ edge.property(EdgeProperty.PREVENT_DELETE.toString(), "NONE");
+ edge.property(EdgeField.PRIVATE.toString(), false);
+ edge.property(AAIProperties.AAI_UUID, UUID.randomUUID().toString());
+ }
+
+ @Test
+ public void testWhenEdgeRuleIsNoLongerValidEnsureItRetrievesVertexesWithoutOldEdges() {
+
+ String endpoint = "/aai/v14/network/configurations";
+
+ Response response = testUtil.doGet(endpoint, null);
+ assertThat(response.getStatus(), is(200));
+
+ String body = response.getEntity().toString();
+
+ assertThat(body, containsString("configuration-id"));
+ assertThat(body, not(containsString("vlan")));
+ }
+
+ @After
+ public void teardown(){
+
+ JanusGraph janusGraph = AAIGraph.getInstance().getGraph();
+ JanusGraphTransaction transaction = janusGraph.newTransaction();
+ GraphTraversalSource g = transaction.traversal();
+
+ g.V()
+ .has(AAIProperties.SOURCE_OF_TRUTH, "JUNIT")
+ .toList()
+ .forEach((edge) -> edge.remove());
+
+ transaction.commit();
+ }
+}
diff --git a/aai-core/src/test/java/org/onap/aai/rest/EntitlementTest.java b/aai-core/src/test/java/org/onap/aai/rest/EntitlementTest.java
new file mode 100644
index 00000000..3559b9d6
--- /dev/null
+++ b/aai-core/src/test/java/org/onap/aai/rest/EntitlementTest.java
@@ -0,0 +1,96 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.aai.rest;
+
+import com.jayway.jsonpath.JsonPath;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.onap.aai.AAISetup;
+import org.onap.aai.HttpTestUtil;
+import org.onap.aai.PayloadUtil;
+import org.onap.aai.exceptions.AAIException;
+import org.onap.aai.serialization.engines.QueryStyle;
+import org.skyscreamer.jsonassert.JSONAssert;
+import org.springframework.test.annotation.DirtiesContext;
+
+import javax.ws.rs.core.Response;
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.util.Arrays;
+import java.util.Collection;
+
+import static org.junit.Assert.assertEquals;
+
+@RunWith(value = Parameterized.class)
+@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS)
+public class EntitlementTest extends AAISetup {
+
+ private HttpTestUtil httpTestUtil;
+
+ @Parameterized.Parameter(value = 0)
+ public QueryStyle queryStyle;
+
+ private String vnfPayload;
+
+ private String vnfUri;
+
+ @Parameterized.Parameters(name = "QueryStyle.{0}")
+ public static Collection<Object[]> data() {
+ return Arrays.asList(new Object[][]{
+ {QueryStyle.TRAVERSAL_URI}
+ });
+ }
+
+ @Before
+ public void setUp() throws IOException {
+ httpTestUtil = new HttpTestUtil(queryStyle);
+ vnfPayload = PayloadUtil.getResourcePayload("vnf.json");
+ vnfUri = "/aai/v14/network/generic-vnfs/generic-vnf/vnf1";
+ }
+
+ @Test
+ public void testPutGenericVnfAndThenInsertEntitlement() throws IOException, AAIException {
+ String entitlementPayload = PayloadUtil.getResourcePayload("entitlement.json");
+ String entitlementUri = "/aai/v14/network/generic-vnfs/generic-vnf/vnf1/entitlements/entitlement/g1/r1";
+ Response response = httpTestUtil.doPut(vnfUri, vnfPayload);
+ assertEquals("Expected the Generic Vnf to be created", 201, response.getStatus());
+
+ response = httpTestUtil.doGet(vnfUri);
+ assertEquals("Expected the Generic Vnf to be found", 200, response.getStatus());
+ String jsonResponse = response.getEntity().toString();
+ JSONAssert.assertEquals(vnfPayload, jsonResponse, false);
+
+ response = httpTestUtil.doPut(entitlementUri, entitlementPayload);
+ assertEquals("Expected the Entitlement to be created", 201, response.getStatus());
+ }
+
+ @After
+ public void tearDown() throws UnsupportedEncodingException, AAIException {
+ Response response = httpTestUtil.doGet(vnfUri);
+ assertEquals("Expected the Generic Vnf to be found", 200, response.getStatus());
+ String jsonResponse = response.getEntity().toString();
+ String resourceVersion = JsonPath.read(jsonResponse, "$.resource-version");
+ response = httpTestUtil.doDelete(vnfUri, resourceVersion);
+ assertEquals("Expected the cloud region to be deleted", 204, response.getStatus());
+ }
+}
diff --git a/aai-core/src/test/java/org/onap/aai/rest/ModelElementTest.java b/aai-core/src/test/java/org/onap/aai/rest/ModelElementTest.java
new file mode 100644
index 00000000..d808c993
--- /dev/null
+++ b/aai-core/src/test/java/org/onap/aai/rest/ModelElementTest.java
@@ -0,0 +1,98 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.aai.rest;
+
+import com.jayway.jsonpath.JsonPath;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.onap.aai.AAISetup;
+import org.onap.aai.HttpTestUtil;
+import org.onap.aai.PayloadUtil;
+import org.onap.aai.exceptions.AAIException;
+import org.onap.aai.serialization.engines.QueryStyle;
+import org.skyscreamer.jsonassert.JSONAssert;
+import org.springframework.test.annotation.DirtiesContext;
+
+import javax.ws.rs.core.Response;
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.util.Arrays;
+import java.util.Collection;
+
+import static org.junit.Assert.assertEquals;
+
+@RunWith(value = Parameterized.class)
+@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS)
+public class ModelElementTest extends AAISetup {
+
+ private HttpTestUtil httpTestUtil;
+
+ @Parameterized.Parameter(value = 0)
+ public QueryStyle queryStyle;
+
+ private String modelPayload;
+ private String modelElementPayload;
+
+ private String modelUri;
+ private String modelElementUri;
+
+ @Parameterized.Parameters(name = "QueryStyle.{0}")
+ public static Collection<Object[]> data() {
+ return Arrays.asList(new Object[][]{
+ {QueryStyle.TRAVERSAL_URI}
+ });
+ }
+
+ @Before
+ public void setUp() throws IOException {
+ httpTestUtil = new HttpTestUtil(queryStyle);
+ modelPayload = PayloadUtil.getResourcePayload("model.json");
+ modelElementPayload = PayloadUtil.getResourcePayload("model-element.json");
+ modelUri = "/aai/v14/service-design-and-creation/models/model/24c04fc5-f3f8-43ec-8792-c6f940638676-test1";
+ modelElementUri = "/aai/v14/service-design-and-creation/models/model/24c04fc5-f3f8-43ec-8792-c6f940638676-test1/model-vers/model-ver/0c4c59f0-9864-43ca-b0c2-ca38746b72a5-test1/model-elements/model-element/0dc2b8b6-af8d-4213-970b-7861a603fc86-test1/model-constraints/model-constraint/782ba24a-28ab-4fd0-8e69-da10cc5373f3-test1/constrained-element-sets/constrained-element-set/a33e65c3-1198-4d4c-9799-2b521e4c4212-test1/element-choice-sets/element-choice-set/7df27a94-06c8-46ef-9fc2-5900d8cffbb0-test1/model-elements/model-element/acf8b6cf-e051-4c1b-bcad-b24792f826cf-test1";
+ }
+
+ @Test
+ public void testPutModelAndThenModelElementAndItShouldSucceed() throws IOException, AAIException {
+ Response response = httpTestUtil.doPut(modelUri, modelPayload);
+ assertEquals("Expected the cloud region to be created", 201, response.getStatus());
+
+ response = httpTestUtil.doGet(modelUri);
+ assertEquals("Expected the cloud region to be found", 200, response.getStatus());
+ String jsonResponse = response.getEntity().toString();
+ JSONAssert.assertEquals(modelPayload, jsonResponse, false);
+
+ response = httpTestUtil.doPut(modelElementUri, modelElementPayload);
+ assertEquals("Expected the cloud region to be created", 201, response.getStatus());
+ }
+
+ @After
+ public void tearDown() throws UnsupportedEncodingException, AAIException {
+ Response response = httpTestUtil.doGet(modelUri);
+ assertEquals("Expected the cloud region to be found", 200, response.getStatus());
+ String jsonResponse = response.getEntity().toString();
+ String resourceVersion = JsonPath.read(jsonResponse, "$.resource-version");
+ response = httpTestUtil.doDelete(modelUri, resourceVersion);
+ assertEquals("Expected the cloud region to be deleted", 204, response.getStatus());
+ }
+}
diff --git a/aai-core/src/test/java/org/onap/aai/rest/PserverDuplicateTest.java b/aai-core/src/test/java/org/onap/aai/rest/PserverDuplicateTest.java
new file mode 100644
index 00000000..71e53be8
--- /dev/null
+++ b/aai-core/src/test/java/org/onap/aai/rest/PserverDuplicateTest.java
@@ -0,0 +1,135 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.aai.rest;
+
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
+import org.apache.tinkerpop.gremlin.structure.Vertex;
+import org.janusgraph.core.JanusGraph;
+import org.janusgraph.core.JanusGraphTransaction;
+import org.junit.Test;
+import org.onap.aai.AAISetup;
+import org.onap.aai.HttpTestUtil;
+import org.onap.aai.db.props.AAIProperties;
+import org.onap.aai.dbmap.AAIGraph;
+import org.onap.aai.serialization.engines.QueryStyle;
+
+import javax.ws.rs.core.Response;
+import java.util.List;
+import java.util.UUID;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.fail;
+
+public class PserverDuplicateTest extends AAISetup {
+
+ private static final EELFLogger LOGGER = EELFManager.getInstance().getLogger(PserverDuplicateTest.class);
+
+ private HttpTestUtil testUtil;
+
+ private String hostname;
+
+ public boolean createDuplicate() throws InterruptedException {
+
+ hostname = getHostname();
+ final String aaiUri = "/cloud-infrastructure/pservers/pserver/" + hostname;
+ final int threads = getNumberOfThreads();
+
+ ExecutorService service = Executors.newFixedThreadPool(threads);
+
+ JanusGraph janusGraph = AAIGraph.getInstance().getGraph();
+ // Due to the lazy instantiation of the graph, it needs to create a new transaction to create schema
+ janusGraph.newTransaction().rollback();
+
+ service.invokeAll(
+ IntStream.range(0, threads)
+ .mapToObj((i) -> (Callable<Void>) () -> {
+ JanusGraphTransaction transaction = janusGraph.newTransaction();
+ GraphTraversalSource g = transaction.traversal();
+ g.addV()
+ .property(AAIProperties.AAI_URI, aaiUri)
+ .property(AAIProperties.NODE_TYPE, "pserver")
+ .property("hostname", hostname)
+ .next();
+ transaction.commit();
+ return null;
+ }).collect(Collectors.toList())
+ , 7, TimeUnit.SECONDS
+ );
+
+ JanusGraphTransaction readOnlyTransaction = AAIGraph.getInstance().getGraph().buildTransaction().readOnly().start();
+ GraphTraversalSource g = readOnlyTransaction.traversal();
+
+ List<Vertex> pserverList = g.V().has(AAIProperties.AAI_URI, aaiUri).toList();
+ LOGGER.debug("Number of pservers with uri {} is {}", aaiUri, pserverList.size());
+
+ testUtil = new HttpTestUtil(QueryStyle.TRAVERSAL_URI);
+
+ if(pserverList.size() == 1){
+ return false;
+ }
+ return true;
+ }
+
+
+ @Test
+ public void testWhenDuplicatesExistInGraphThatGetAllSuceeds() throws InterruptedException {
+
+ int totalRetries = getNumOfRetries();
+ for(int retry = 0; retry < totalRetries; retry++){
+ if(!this.createDuplicate()){
+ if(retry == (totalRetries-1)){
+ fail("Unable to produce duplicates in the graph, " +
+ "please increase retry or ignore test if it becomes impossible to create duplicate this test");
+ }
+ } else {
+ // Successfully created a duplicate in the janus graph
+ break;
+ }
+ }
+
+ String endpoint = "/aai/v14/cloud-infrastructure/pservers";
+
+ Response response = testUtil.doGet(endpoint, null);
+ LOGGER.info("GET ALL Pservers with duplicates status code {} and body {}", response.getStatus(), response.getEntity());
+ assertThat(response.getStatus(), is(200));
+ }
+
+ public String getHostname(){
+ return UUID.randomUUID().toString();
+ }
+
+ public int getNumOfRetries(){
+ return 10;
+ }
+
+ public int getNumberOfThreads(){
+ return 10;
+ }
+}
+
diff --git a/aai-core/src/test/java/org/onap/aai/rest/VipAddressListTest.java b/aai-core/src/test/java/org/onap/aai/rest/VipAddressListTest.java
new file mode 100644
index 00000000..0351c2c3
--- /dev/null
+++ b/aai-core/src/test/java/org/onap/aai/rest/VipAddressListTest.java
@@ -0,0 +1,99 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.aai.rest;
+
+import com.jayway.jsonpath.JsonPath;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.onap.aai.AAISetup;
+import org.onap.aai.HttpTestUtil;
+import org.onap.aai.PayloadUtil;
+import org.onap.aai.exceptions.AAIException;
+import org.onap.aai.serialization.engines.QueryStyle;
+import org.skyscreamer.jsonassert.JSONAssert;
+
+import javax.ws.rs.core.Response;
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Collection;
+
+import static org.junit.Assert.assertEquals;
+
+@RunWith(value = Parameterized.class)
+public class VipAddressListTest extends AAISetup {
+
+ private HttpTestUtil httpTestUtil;
+
+ @Parameterized.Parameter(value = 0)
+ public QueryStyle queryStyle;
+
+ @Parameterized.Parameters(name = "QueryStyle.{0}")
+ public static Collection<Object[]> data() {
+ return Arrays.asList(new Object[][]{
+ {QueryStyle.TRAVERSAL_URI}
+ });
+ }
+
+ @Before
+ public void setUp(){
+ httpTestUtil = new HttpTestUtil(queryStyle);
+ }
+
+ @Test
+ public void testPutWithAllCloudRegionChildrenNodesAndCheckIfDeleteIsSuccessful() throws IOException, AAIException {
+
+ String cloudRegionPayload = PayloadUtil.getResourcePayload("cloud-region.json");
+ String cloudRegionUri = "/aai/v14/cloud-infrastructure/cloud-regions/cloud-region/cloud-region-owner-with-vip-ipv4/cloud-region-id-with-vip-ipv4";
+
+ Response response = httpTestUtil.doPut(cloudRegionUri, cloudRegionPayload);
+ assertEquals("Expected the cloud region to be created", 201, response.getStatus());
+
+ response = httpTestUtil.doGet(cloudRegionUri);
+ assertEquals("Expected the cloud region to be found", 200, response.getStatus());
+ String jsonResponse = response.getEntity().toString();
+
+ JSONAssert.assertEquals(cloudRegionPayload, jsonResponse, false);
+
+ String vipIpv4Uri = cloudRegionUri + "/vip-ipv4-address-list/vip-ipv4-address-list-1";
+ String vipIpv4Payload = PayloadUtil.getResourcePayload("vip-ipv4-address-list.json");
+
+ response = httpTestUtil.doPut(vipIpv4Uri, vipIpv4Payload);
+ assertEquals("Expected the ipv4 address list to be created", 201, response.getStatus());
+
+ response = httpTestUtil.doGet(vipIpv4Uri);
+ assertEquals("Expected the ipv4 address list to be found", 200, response.getStatus());
+
+ jsonResponse = response.getEntity().toString();
+ String resourceVersion = JsonPath.read(jsonResponse, "$.resource-version");
+
+ response = httpTestUtil.doDelete(vipIpv4Uri, resourceVersion);
+ assertEquals("Expected the ipv4 address list to be deleted", 204, response.getStatus());
+
+ response = httpTestUtil.doGet(cloudRegionUri);
+ jsonResponse = response.getEntity().toString();
+ resourceVersion = JsonPath.read(jsonResponse, "$.resource-version");
+
+ response = httpTestUtil.doDelete(cloudRegionUri, resourceVersion);
+ assertEquals("Expected the cloud region to be deleted", 204, response.getStatus());
+ }
+}
diff --git a/aai-core/src/test/java/org/onap/aai/serialization/db/DbSerializerTest.java b/aai-core/src/test/java/org/onap/aai/serialization/db/DbSerializerTest.java
index a5b968b3..5041c7d1 100644
--- a/aai-core/src/test/java/org/onap/aai/serialization/db/DbSerializerTest.java
+++ b/aai-core/src/test/java/org/onap/aai/serialization/db/DbSerializerTest.java
@@ -465,16 +465,18 @@ public class DbSerializerTest extends AAISetup {
public void getURIForVertexTest() throws AAIException, URISyntaxException, UnsupportedEncodingException {
engine.startTransaction();
- Vertex cr = engine.tx().addVertex("aai-node-type", "cloud-region", "cloud-owner", "me", "cloud-region-id", "123");
+ Vertex cr = engine.tx().addVertex("aai-node-type", "cloud-region", "cloud-owner", "me", "cloud-region-id", "123", "aai-uri", "/cloud-infrastructure/cloud-regions/cloud-region/me/123");
Vertex ten = engine.tx().addVertex("aai-node-type", "tenant", "tenant-id", "453");
edgeSer.addTreeEdge(engine.tx().traversal(), cr, ten);
+ ten.property("aai-uri", "/cloud-infrastructure/cloud-regions/cloud-region/me/123/tenants/tenant/453");
+
URI compare = new URI("/cloud-infrastructure/cloud-regions/cloud-region/me/123/tenants/tenant/453");
assertEquals(compare, dbser.getURIForVertex(ten));
- cr.property("aai-node-type").remove();
URI compareFailure = new URI("/unknown-uri");
+ ten.property("aai-uri").remove();
assertEquals(compareFailure, dbser.getURIForVertex(ten));
}
@@ -619,9 +621,10 @@ public class DbSerializerTest extends AAISetup {
public void serializeSingleVertexChildTest() throws AAIException, UnsupportedEncodingException {
engine.startTransaction();
- Vertex cr = engine.tx().addVertex("aai-node-type", "cloud-region", "cloud-owner", "me", "cloud-region-id", "123");
+ Vertex cr = engine.tx().addVertex("aai-node-type", "cloud-region", "cloud-owner", "me", "cloud-region-id", "123", "aai-uri", "/cloud-infrastructure/cloud-regions/cloud-region/me/123");
Introspector tenIn = loader.introspectorFromName("tenant");
Vertex ten = dbser.createNewVertex(tenIn);
+ ten.property("aai-uri", cr.property("aai-uri").value().toString() + "/tenants/tenant/453");
edgeSer.addTreeEdge(engine.tx().traversal(), cr, ten);
@@ -639,8 +642,8 @@ public class DbSerializerTest extends AAISetup {
public void getVertexPropertiesRelationshipHasLabelTest() throws AAIException, UnsupportedEncodingException {
engine.startTransaction();
- Vertex gvnf = engine.tx().addVertex("aai-node-type","generic-vnf","vnf-id","vnf-123");
- Vertex vnfc = engine.tx().addVertex("aai-node-type","vnfc","vnfc-name","vnfc-123");
+ Vertex gvnf = engine.tx().addVertex("aai-node-type","generic-vnf","vnf-id","vnf-123","aai-uri", "/network/generic-vnfs/generic-vnf/vnf-123");
+ Vertex vnfc = engine.tx().addVertex("aai-node-type","vnfc","vnfc-name","vnfc-123","aai-uri", "/network/vnfcs/vnfc/vnfc-123");
edgeSer.addEdge(engine.tx().traversal(), gvnf, vnfc);
@@ -672,8 +675,8 @@ public class DbSerializerTest extends AAISetup {
engine.startTransaction();
- Vertex gvnf = engine.tx().addVertex("aai-node-type","generic-vnf","vnf-id","vnf-123");
- Vertex vnfc = engine.tx().addVertex("aai-node-type","vnfc","vnfc-name","vnfc-123");
+ Vertex gvnf = engine.tx().addVertex("aai-node-type","generic-vnf","vnf-id","vnf-123", "aai-uri", "/network/generic-vnfs/generic-vnf/vnf-123");
+ Vertex vnfc = engine.tx().addVertex("aai-node-type","vnfc","vnfc-name","vnfc-123", "aai-uri", "/network/vnfcs/vnfc/vnfc-123");
edgeSer.addEdge(engine.tx().traversal(), gvnf, vnfc);
diff --git a/aai-core/src/test/java/org/onap/aai/serialization/engines/query/GraphTraversalQueryEngineTest.java b/aai-core/src/test/java/org/onap/aai/serialization/engines/query/GraphTraversalQueryEngineTest.java
index a24855b8..b9431217 100644
--- a/aai-core/src/test/java/org/onap/aai/serialization/engines/query/GraphTraversalQueryEngineTest.java
+++ b/aai-core/src/test/java/org/onap/aai/serialization/engines/query/GraphTraversalQueryEngineTest.java
@@ -38,6 +38,7 @@ import org.springframework.test.annotation.DirtiesContext;
import java.io.InputStream;
import java.util.*;
+import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
@@ -53,30 +54,30 @@ public class GraphTraversalQueryEngineTest extends AAISetup {
public void testFindParents() throws AAIException {
//setup
Graph graph = TinkerGraph.open();
-
+
Vertex cloudreg = graph.addVertex(T.id, "00", "aai-node-type", "cloud-region");
Vertex tenant = graph.addVertex(T.id, "10", "aai-node-type", "tenant");
Vertex vserver = graph.addVertex(T.id, "20", "aai-node-type", "vserver");
-
+
GraphTraversalSource g = graph.traversal();
-
+
edgeSer.addTreeEdge(g, cloudreg, tenant);
edgeSer.addTreeEdge(g, tenant, vserver);
-
+
//expect start vertex back plus any parents
List<Vertex> crExpected = new ArrayList<>(Arrays.asList(cloudreg)); //no parents
List<Vertex> tenExpected = new ArrayList<>(Arrays.asList(tenant, cloudreg)); //only has the immediate parent
List<Vertex> vsExpected = new ArrayList<>(Arrays.asList(vserver, tenant, cloudreg)); //parent & grandparent
-
+
GraphTraversalQueryEngine engine = new GraphTraversalQueryEngine(g);
-
+
//test
List<Vertex> crRes = engine.findParents(cloudreg);
assertTrue(crRes.containsAll(crExpected) && crExpected.containsAll(crRes));
-
+
List<Vertex> tenRes = engine.findParents(tenant);
assertTrue(tenRes.containsAll(tenExpected) && tenExpected.containsAll(tenRes));
-
+
List<Vertex> vsRes = engine.findParents(vserver);
assertTrue(vsRes.containsAll(vsExpected) && vsExpected.containsAll(vsRes));
//verify expected ordering - start, parent, grandparent
@@ -84,131 +85,157 @@ public class GraphTraversalQueryEngineTest extends AAISetup {
assertTrue(vsRes.get(1).equals(tenant));
assertTrue(vsRes.get(2).equals(cloudreg));
}
-
+
+ @Test
+ public void testFindAllParentsGivenAaiUris(){
+
+ //setup
+ Graph graph = TinkerGraph.open();
+
+ Vertex cloudreg = graph.addVertex(T.id, "00", "aai-node-type", "cloud-region", "aai-uri", "/cloud-infrastructure/cloud-regions/cloud-region/testowner/testid");
+ Vertex tenant = graph.addVertex(T.id, "10", "aai-node-type", "tenant", "aai-uri", "/cloud-infrastructure/cloud-regions/cloud-region/testowner/testid/tenants/tenant/testTenant1");
+ Vertex vserver = graph.addVertex(T.id, "20", "aai-node-type", "vserver", "aai-uri", "/cloud-infrastructure/cloud-regions/cloud-region/testowner/testid/tenants/tenant/testTenant1/vservers/vserver/testVserver1");
+
+ String [] uris = new String[]{
+ "/cloud-infrastructure/cloud-regions/cloud-region/testowner/testid/tenants/tenant/testTenant1",
+ "/cloud-infrastructure/cloud-regions/cloud-region/testowner/testid/tenants/tenant/testTenant1/vservers/vserver/testVserver1",
+ "/cloud-infrastructure/cloud-regions/cloud-region/testowner/testid"
+ };
+
+ GraphTraversalSource g = graph.traversal();
+ GraphTraversalQueryEngine queryEngine = new GraphTraversalQueryEngine(g);
+ List<Vertex> vertices = queryEngine.findParents(uris);
+
+ assertThat("Returned vertices should be 3 cloud region, tenant and vserver", vertices.size(), is(3));
+ assertThat("Expected the first element back to be vserver", vertices.get(0), is(vserver));
+ assertThat("Expected the second element back to be tenant", vertices.get(1), is(tenant));
+ assertThat("Expected the element back to be cloud region", vertices.get(2), is(cloudreg));
+ }
+
@Test
public void testFindAllChildren() throws AAIException {
//setup
Graph graph = TinkerGraph.open();
-
+
Vertex cloudreg = graph.addVertex(T.id, "00", "aai-node-type", "cloud-region");
Vertex tenant = graph.addVertex(T.id, "10", "aai-node-type", "tenant");
Vertex vserver = graph.addVertex(T.id, "20", "aai-node-type", "vserver");
Vertex vserver2 = graph.addVertex(T.id, "21", "aai-node-type", "vserver");
Vertex oam = graph.addVertex(T.id, "30", "aai-node-type", "oam-network");
-
+
GraphTraversalSource g = graph.traversal();
-
+
edgeSer.addTreeEdge(g, cloudreg, tenant);
edgeSer.addTreeEdge(g, tenant, vserver);
edgeSer.addTreeEdge(g, tenant, vserver2);
edgeSer.addTreeEdge(g, cloudreg, oam);
-
+
List<Vertex> crExpected = new ArrayList<>(Arrays.asList(cloudreg, tenant, vserver, vserver2, oam));
List<Vertex> vsExpected = new ArrayList<>(Arrays.asList(vserver));
-
+
GraphTraversalQueryEngine engine = new GraphTraversalQueryEngine(g);
-
+
//test
List<Vertex> crRes = engine.findAllChildren(cloudreg);
assertTrue(crRes.containsAll(crExpected) && crExpected.containsAll(crRes));
-
+
List<Vertex> vsRes = engine.findAllChildren(vserver);
assertTrue(vsRes.containsAll(vsExpected) && vsExpected.containsAll(vsRes));
}
-
+
@Test
public void testFindChildrenOfType() throws AAIException {
//setup
Graph graph = TinkerGraph.open();
-
+
Vertex gv = graph.addVertex(T.id, "00", "aai-node-type", "generic-vnf");
Vertex lint1 = graph.addVertex(T.id, "10", "aai-node-type", "l-interface");
Vertex lint2 = graph.addVertex(T.id, "11", "aai-node-type", "l-interface");
Vertex lag = graph.addVertex(T.id, "20", "aai-node-type", "lag-interface");
Vertex lint3 = graph.addVertex(T.id, "12", "aai-node-type", "l-interface");
-
+
GraphTraversalSource g = graph.traversal();
-
+
edgeSer.addTreeEdge(g, gv, lint1);
edgeSer.addTreeEdge(g, gv, lint2);
edgeSer.addTreeEdge(g, gv, lag);
edgeSer.addTreeEdge(g, lag, lint3);
-
+
List<Vertex> expected = new ArrayList<>(Arrays.asList(lint1, lint2));
-
+
GraphTraversalQueryEngine engine = new GraphTraversalQueryEngine(g);
-
+
//test
List<Vertex> results = engine.findChildrenOfType(gv, "l-interface");
assertTrue(results.containsAll(expected) && expected.containsAll(results));
}
-
+
@Test
public void testFindChildren() throws AAIException {
//setup
Graph graph = TinkerGraph.open();
-
+
Vertex gv = graph.addVertex(T.id, "00", "aai-node-type", "generic-vnf");
Vertex lint1 = graph.addVertex(T.id, "10", "aai-node-type", "l-interface");
Vertex lint2 = graph.addVertex(T.id, "11", "aai-node-type", "l-interface");
Vertex lag = graph.addVertex(T.id, "20", "aai-node-type", "lag-interface");
Vertex lint3 = graph.addVertex(T.id, "12", "aai-node-type", "l-interface");
-
+
GraphTraversalSource g = graph.traversal();
-
+
edgeSer.addTreeEdge(g, gv, lint1);
edgeSer.addTreeEdge(g, gv, lint2);
edgeSer.addTreeEdge(g, gv, lag);
edgeSer.addTreeEdge(g, lag, lint3);
-
+
List<Vertex> expected = new ArrayList<>(Arrays.asList(lint1, lint2, lag));
-
+
GraphTraversalQueryEngine engine = new GraphTraversalQueryEngine(g);
-
+
//test
List<Vertex> results = engine.findChildren(gv);
assertTrue(results.containsAll(expected) && expected.containsAll(results));
}
-
+
@Test
public void testFindRelatedVertices() throws AAIException {
//setup
-
+
Graph graph = TinkerGraph.open();
-
+
Vertex gv = graph.addVertex(T.id, "00", "aai-node-type", "generic-vnf");
Vertex lint = graph.addVertex(T.id, "10", "aai-node-type", "l-interface");
Vertex lint2 = graph.addVertex(T.id, "11", "aai-node-type", "l-interface");
Vertex log = graph.addVertex(T.id, "20", "aai-node-type", "logical-link");
-
+
GraphTraversalSource g = graph.traversal();
-
+
edgeSer.addTreeEdge(g, gv, lint);
edgeSer.addEdge(g, lint, log);
edgeSer.addEdge(g, log, lint2);
-
+
List<Vertex> outExpected = new ArrayList<>(Arrays.asList(lint));
List<Vertex> inExpected = new ArrayList<>(Arrays.asList(lint, lint2));
List<Vertex> bothExpected = new ArrayList<>(Arrays.asList(log));
-
+
GraphTraversalQueryEngine engine = new GraphTraversalQueryEngine(g);
-
+
//test
List<Vertex> outRes = engine.findRelatedVertices(gv, Direction.IN, "org.onap.relationships.inventory.BelongsTo", "l-interface");
assertTrue(outRes.containsAll(outExpected) && outExpected.containsAll(outRes));
List<Vertex> inRes = engine.findRelatedVertices(log, Direction.IN, "tosca.relationships.network.LinksTo", "l-interface");
assertTrue(inRes.containsAll(inExpected) && inExpected.containsAll(inRes));
-
+
List<Vertex> bothRes = engine.findRelatedVertices(lint, Direction.BOTH, "tosca.relationships.network.LinksTo", "logical-link");
assertTrue(bothRes.containsAll(bothExpected) && bothExpected.containsAll(bothRes));
}
-
+
@Test
public void testFindSubGraph() throws AAIException, EdgeRuleNotFoundException, AmbiguousRuleChoiceException {
//setup
Graph graph = TinkerGraph.open();
-
+
Vertex cr = graph.addVertex(T.id, "00", "aai-node-type", "cloud-region");
Vertex ten = graph.addVertex(T.id, "10", "aai-node-type", "tenant");
Vertex ten2 = graph.addVertex(T.id, "11", "aai-node-type", "tenant");
@@ -225,7 +252,7 @@ public class GraphTraversalQueryEngineTest extends AAISetup {
Vertex modelVer = graph.addVertex(T.id, "100", "aai-node-type", "model-ver");
GraphTraversalSource g = graph.traversal();
-
+
Edge crTen = edgeSer.addTreeEdge(g, cr, ten);
Edge crTen2 = edgeSer.addTreeEdge(g, cr, ten2);
Edge tenVs = edgeSer.addTreeEdge(g, ten, vs);
@@ -234,14 +261,14 @@ public class GraphTraversalQueryEngineTest extends AAISetup {
Edge lintLog = edgeSer.addEdge(g, lint, log);
Edge vsGv = edgeSer.addEdge(g, vs, gv);
edgeSer.addEdge(g, gv, vnfc);
-
+
edgeSer.addTreeEdge(g, gv, lag);
edgeSer.addTreeEdge(g, lag, lint2);
Edge modelVerEdge = edgeSer.addPrivateEdge(g, gv, modelVer, null);
edgeSer.addTreeEdge(g, comp, ctag);
Edge crComp = edgeSer.addEdge(g, cr, comp);
-
+
//findSubGraph(cr, 0, true)
List<Element> expected1 = new ArrayList<>(Arrays.asList(cr));
//findSubGraph(cr, 2, true)
@@ -249,48 +276,48 @@ public class GraphTraversalQueryEngineTest extends AAISetup {
crTen, crTen2, tenVs, tenVs2));
//findSubGraph(cr)
List<Element> expected3 = new ArrayList<>(Arrays.asList(cr, ten, ten2, comp, vs, vs2, lint, gv, log,
- crTen, crTen2, crComp, tenVs, tenVs2, vsLInt,
+ crTen, crTen2, crComp, tenVs, tenVs2, vsLInt,
vsGv, lintLog));
-
+
GraphTraversalQueryEngine engine = new GraphTraversalQueryEngine(g);
-
+
//test
Tree<Element> res1 = engine.findSubGraph(cr, 0, true);
Set<Element> resList1 = treeToList(res1);
assertTrue(resList1.containsAll(expected1) && expected1.containsAll(resList1));
-
+
Tree<Element> res2 = engine.findSubGraph(cr, 2, true);
Set<Element> resList2 = treeToList(res2);
assertTrue(resList2.containsAll(expected2) && expected2.containsAll(resList2));
-
+
Tree<Element> res3 = engine.findSubGraph(cr);
Set<Element> resList3 = treeToList(res3);
assertThat(resList3, containsInAnyOrder(expected3.toArray()));
// assertTrue(resList3.containsAll(expected3) && expected3.containsAll(resList3));
}
-
+
/**
- * convenience helper method to make it easier to check the contents of the tree against
+ * convenience helper method to make it easier to check the contents of the tree against
* a list of expected results
* @param tree - the tree whose contents you want in collection form
* @return set of the contents of the tree
*/
private Set<Element> treeToList(Tree<Element> tree) {
Set<Element> ret = new HashSet<>();
-
+
for (Element key : tree.keySet()) {
ret.add(key);
ret.addAll(treeToList(tree.get(key)));
}
-
+
return ret;
}
-
+
@Test
public void testFindEdgesForVersion() throws AAIException, EdgeRuleNotFoundException, AmbiguousRuleChoiceException {
//setup
Graph graph = TinkerGraph.open();
-
+
Vertex gv = graph.addVertex(T.id, "00", "aai-node-type", "generic-vnf");
Vertex vnfc = graph.addVertex(T.id, "10", "aai-node-type", "vnfc");
Vertex lob = graph.addVertex(T.id, "20", "aai-node-type", "line-of-business");
@@ -303,16 +330,16 @@ public class GraphTraversalQueryEngineTest extends AAISetup {
.addEdge("some-edge", cr, CONTAINS.toString(), "NONE");
GraphTraversalSource g = graph.traversal();
-
+
edgeSer.addTreeEdge(g, gv, lint); //tree edge so shouldn't appear in results
Edge gvVnfc = edgeSer.addEdge(g, gv, vnfc);
edgeSer.addEdge(g, gv, lob); //v11/12 not v10
Edge gvMvEdge = edgeSer.addPrivateEdge(g, gv, mv, null);
List<Edge> expected = new ArrayList<>(Arrays.asList(gvVnfc));
-
+
GraphTraversalQueryEngine engine = new GraphTraversalQueryEngine(g);
-
+
//test
Loader loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getRelatedLinkVersion());
List<Edge> results = engine.findEdgesForVersion(gv, loader);
@@ -322,27 +349,27 @@ public class GraphTraversalQueryEngineTest extends AAISetup {
results = engine.findEdgesForVersion(cr, loader);
assertThat(results, containsInAnyOrder(expected.toArray()));
}
-
+
@Test
public void testFindCousinVertices() throws AAIException {
//setup
Graph graph = TinkerGraph.open();
-
+
Vertex gv = graph.addVertex(T.id, "00", "aai-node-type", "generic-vnf");
Vertex vnfc = graph.addVertex(T.id, "10", "aai-node-type", "vnfc");
Vertex lob = graph.addVertex(T.id, "20", "aai-node-type", "line-of-business");
Vertex lint = graph.addVertex(T.id, "30", "aai-node-type", "l-interface");
-
+
GraphTraversalSource g = graph.traversal();
-
+
edgeSer.addTreeEdge(g, gv, lint); //tree edge so shouldn't appear in results
edgeSer.addEdge(g, gv, vnfc);
edgeSer.addEdge(g, gv, lob);
-
+
List<Vertex> expected = new ArrayList<>(Arrays.asList(vnfc, lob));
-
+
GraphTraversalQueryEngine engine = new GraphTraversalQueryEngine(g);
-
+
//test
List<Vertex> results = engine.findCousinVertices(gv);
assertTrue(results.containsAll(expected) && expected.containsAll(results));