aboutsummaryrefslogtreecommitdiffstats
path: root/aai-core/src/test/java
diff options
context:
space:
mode:
authorVenkata Harish K Kajur <vk250x@att.com>2018-01-18 00:47:09 -0500
committerVenkata Harish K Kajur <vk250x@att.com>2018-01-18 17:42:01 -0500
commit6b98bb3ec93a0bbfbe0e660cabc69978b53bfee8 (patch)
tree5e68f93e33737684d63d655ac5a5c6d611f45b5e /aai-core/src/test/java
parent89e91557997a4fc11db1b574e13c07b2149a63e3 (diff)
Sync the latest code changes
Issue-ID: AAI-493 Change-Id: I5f39ce9bb19cfb9607b659bed82066cae7569ecc Signed-off-by: Venkata Harish K Kajur <vk250x@att.com>
Diffstat (limited to 'aai-core/src/test/java')
-rw-r--r--aai-core/src/test/java/org/onap/aai/dbmap/AAIGraphTest.java79
-rw-r--r--aai-core/src/test/java/org/onap/aai/introspection/JSONStrategyTest.java136
-rw-r--r--aai-core/src/test/java/org/onap/aai/introspection/PropertyPredicatesTest.java19
-rw-r--r--aai-core/src/test/java/org/onap/aai/introspection/sideeffect/DataCopyTest.java18
-rw-r--r--aai-core/src/test/java/org/onap/aai/introspection/sideeffect/DataLinkTest.java24
-rw-r--r--aai-core/src/test/java/org/onap/aai/introspection/tools/CreateUUIDTest.java91
-rw-r--r--aai-core/src/test/java/org/onap/aai/introspection/validation/IntrospectorValidationTest.java6
-rw-r--r--aai-core/src/test/java/org/onap/aai/logging/EcompErrorCategoryTest.java50
-rw-r--r--aai-core/src/test/java/org/onap/aai/logging/EcompResponseCodeTest.java49
-rw-r--r--aai-core/src/test/java/org/onap/aai/logging/EcompResponseDescriptionTest.java50
-rw-r--r--aai-core/src/test/java/org/onap/aai/logging/LoggingContextTest.java2
-rw-r--r--aai-core/src/test/java/org/onap/aai/parsers/query/GraphTraversalTest.java46
-rw-r--r--aai-core/src/test/java/org/onap/aai/parsers/query/UniqueURIQueryTest.java2
-rw-r--r--aai-core/src/test/java/org/onap/aai/parsers/relationship/RelationshipToURITest.java16
-rw-r--r--aai-core/src/test/java/org/onap/aai/parsers/uri/URIParserTest.java2
-rw-r--r--aai-core/src/test/java/org/onap/aai/parsers/uri/URIToExtensionInformationTest.java2
-rw-r--r--aai-core/src/test/java/org/onap/aai/query/builder/QueryBuilderTestAbstraction.java87
-rw-r--r--aai-core/src/test/java/org/onap/aai/query/builder/SimplePathTest.java6
-rw-r--r--aai-core/src/test/java/org/onap/aai/query/builder/TraversalQueryTest.java36
-rw-r--r--aai-core/src/test/java/org/onap/aai/rest/CloudRegionTest.java76
-rw-r--r--aai-core/src/test/java/org/onap/aai/rest/GenericVnfLInterfaceTest.java78
-rw-r--r--aai-core/src/test/java/org/onap/aai/rest/TenantTest.java93
-rw-r--r--aai-core/src/test/java/org/onap/aai/rest/db/HttpEntryTest.java223
-rw-r--r--aai-core/src/test/java/org/onap/aai/serialization/db/DbSerializerTest.java497
-rw-r--r--aai-core/src/test/java/org/onap/aai/serialization/db/EdgeRulesTest.java94
-rw-r--r--aai-core/src/test/java/org/onap/aai/serialization/engines/query/GraphTraversalQueryEngineTest.java13
-rw-r--r--aai-core/src/test/java/org/onap/aai/serialization/queryformats/ConsoleTest.java83
-rw-r--r--aai-core/src/test/java/org/onap/aai/serialization/queryformats/GraphSONTest.java80
-rw-r--r--aai-core/src/test/java/org/onap/aai/serialization/queryformats/RawFormatTest.java4
-rw-r--r--aai-core/src/test/java/org/onap/aai/serialization/queryformats/SimpleFormatTest.java1
-rw-r--r--aai-core/src/test/java/org/onap/aai/util/AAICSVWriterTest.java77
-rw-r--r--aai-core/src/test/java/org/onap/aai/util/AAIConfigCommandLinePropGetterTest.java105
-rw-r--r--aai-core/src/test/java/org/onap/aai/util/AAIRSyncUtilityTest.java55
-rw-r--r--aai-core/src/test/java/org/onap/aai/util/FileWatcherTest.java78
-rw-r--r--aai-core/src/test/java/org/onap/aai/util/GenerateXsdTest.java278
-rw-r--r--aai-core/src/test/java/org/onap/aai/util/HbaseSaltPrefixerTest.java72
-rw-r--r--aai-core/src/test/java/org/onap/aai/util/KeyValueListTest.java76
-rw-r--r--aai-core/src/test/java/org/onap/aai/util/MapperUtilTest.java72
-rw-r--r--aai-core/src/test/java/org/onap/aai/util/PojoUtilsTest.java107
-rw-r--r--aai-core/src/test/java/org/onap/aai/util/RestURLEncoderTest.java63
-rw-r--r--aai-core/src/test/java/org/onap/aai/util/StoreNotificationEventTest.java235
-rw-r--r--aai-core/src/test/java/org/onap/aai/workarounds/LegacyURITransformerTest.java104
42 files changed, 2802 insertions, 483 deletions
diff --git a/aai-core/src/test/java/org/onap/aai/dbmap/AAIGraphTest.java b/aai-core/src/test/java/org/onap/aai/dbmap/AAIGraphTest.java
new file mode 100644
index 00000000..e358dc8e
--- /dev/null
+++ b/aai-core/src/test/java/org/onap/aai/dbmap/AAIGraphTest.java
@@ -0,0 +1,79 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017 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=========================================================
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ */
+
+package org.onap.aai.dbmap;
+
+import com.thinkaurelius.titan.core.TitanFactory;
+import com.thinkaurelius.titan.core.TitanGraph;
+import com.thinkaurelius.titan.core.schema.TitanManagement;
+import org.hamcrest.CoreMatchers;
+import org.junit.*;
+import org.onap.aai.AAISetup;
+import org.onap.aai.util.AAIConstants;
+
+import static org.hamcrest.CoreMatchers.containsString;
+import static org.hamcrest.Matchers.matchesPattern;
+import static org.junit.Assert.*;
+
+public class AAIGraphTest extends AAISetup{
+
+ private static final String SERVICE_NAME = "JUNIT";
+
+ @Before
+ public void setup() {
+ System.setProperty("aai.service.name", SERVICE_NAME);
+ AAIGraph.getInstance();
+ }
+
+ @Test
+ public void getRealtimeInstanceConnectionName() throws Exception {
+
+ TitanManagement graphMgt = AAIGraph.getInstance().getGraph().openManagement();
+ String connectionInstanceName = graphMgt.getOpenInstances().stream().filter(c -> c.contains("current")).findFirst().get();
+ assertThat(connectionInstanceName, containsString(SERVICE_NAME));
+ assertThat(connectionInstanceName, containsString("realtime"));
+ assertThat(connectionInstanceName, matchesPattern("^\\d+_[\\w\\-\\d]+_" + SERVICE_NAME + "_realtime_\\d+\\(current\\)$"));
+ graphMgt.rollback();
+ }
+
+ @Test
+ public void getCachedInstanceConnectionName() throws Exception {
+
+ TitanManagement graphMgt = AAIGraph.getInstance().getGraph(DBConnectionType.CACHED).openManagement();
+ String connectionInstanceName = graphMgt.getOpenInstances().stream().filter(c -> c.contains("current")).findFirst().get();
+ assertThat(connectionInstanceName, containsString(SERVICE_NAME));
+ assertThat(connectionInstanceName, containsString("cached"));
+ assertThat(connectionInstanceName, matchesPattern("^\\d+_[\\w\\-\\d]+_" + SERVICE_NAME + "_cached_\\d+\\(current\\)$"));
+ graphMgt.rollback();
+ }
+
+ @Test
+ public void titanGraphOpenNameTest() throws Exception{
+ TitanGraph graph = TitanFactory.open(new AAIGraphConfig.Builder(AAIConstants.REALTIME_DB_CONFIG).forService(SERVICE_NAME).withGraphType("graphType").buildConfiguration());
+ TitanManagement graphMgt = graph.openManagement();
+ String connectionInstanceName = graphMgt.getOpenInstances().stream().filter(c -> c.contains("current")).findFirst().get();
+ assertThat(connectionInstanceName,matchesPattern("^\\d+_[\\w\\-\\d]+_" + SERVICE_NAME + "_graphType_\\d+\\(current\\)$"));
+ graphMgt.rollback();
+ graph.close();
+ }
+
+} \ No newline at end of file
diff --git a/aai-core/src/test/java/org/onap/aai/introspection/JSONStrategyTest.java b/aai-core/src/test/java/org/onap/aai/introspection/JSONStrategyTest.java
new file mode 100644
index 00000000..64856899
--- /dev/null
+++ b/aai-core/src/test/java/org/onap/aai/introspection/JSONStrategyTest.java
@@ -0,0 +1,136 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017 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=========================================================
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ */
+package org.onap.aai.introspection;
+
+import org.json.simple.JSONArray;
+import org.json.simple.JSONObject;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.aai.AAISetup;
+
+import java.util.HashSet;
+import java.util.Set;
+
+public class JSONStrategyTest extends AAISetup{
+ private JSONStrategy jsonStrategy;
+ private JSONStrategy jsonStrategyContainer;
+ private JSONStrategy jsonStrategyComplex;
+
+ @Before
+ public void setup(){
+ try {
+ JSONObject pserver = new JSONObject();
+ pserver.put("hostname", "value1");
+ pserver.put("numberofCpus", 4);
+ jsonStrategy = new JSONStrategy(pserver, "pserver-type");
+
+ // The values of this object are arrays containing JSONObjects
+ JSONArray pservers = new JSONArray();
+ pservers.add(pserver);
+ JSONObject container = new JSONObject();
+ container.put("pservers", pservers);
+ jsonStrategyContainer = new JSONStrategy(container, "pservers-type");
+
+ // The values of this object are JSONObjects
+ JSONObject complex = new JSONObject();
+ complex.put("pserver", pserver);
+ jsonStrategyComplex = new JSONStrategy(complex, "pservers-type");
+ }
+ catch (Exception e){
+ System.out.println("error during setup: " + e.getMessage());
+ }
+ }
+
+ @Test
+ public void getSetTest(){
+ jsonStrategy.setValue("ramInMegabytes", 1024);
+ Assert.assertEquals("value1", jsonStrategy.getValue("hostname"));
+ Assert.assertEquals(4, jsonStrategy.getValue("numberofCpus"));
+ Assert.assertEquals(1024, jsonStrategy.getValue("ramInMegabytes"));
+ }
+
+ @Test
+ public void getPropertiesTest() {
+ Set<String> expected = new HashSet<>();
+ expected.add("hostname");
+ expected.add("numberofCpus");
+ Assert.assertEquals(expected, jsonStrategy.getProperties());
+ }
+
+ @Test
+ public void getGenericTypeTest() {
+ // If the values of this object are arrays, return the type within the array
+ Assert.assertEquals("class org.json.simple.JSONObject" , jsonStrategyContainer.getGenericTypeClass("pservers").toString());
+ }
+
+ @Test
+ public void getJavaClassNameTest() {
+ Assert.assertEquals("org.json.simple.JSONObject", jsonStrategy.getJavaClassName());
+ Assert.assertEquals("org.json.simple.JSONObject", jsonStrategyContainer.getJavaClassName());
+ }
+ @Test
+ public void getTypeTest() {
+ Assert.assertEquals("java.lang.String", jsonStrategy.getType("hostname"));
+ Assert.assertEquals("java.lang.Integer", jsonStrategy.getType("numberofCpus"));
+ }
+
+ @Test
+ public void isContainerTest() {
+ Assert.assertTrue(jsonStrategyContainer.isContainer());
+ }
+
+ @Test
+ public void newInstanceOfPropertyTest() {
+ Assert.assertEquals("class org.json.simple.JSONArray", jsonStrategyContainer.newInstanceOfProperty("pservers").getClass().toString());
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void newInvalidInstanceOfPropertyTest() {
+ Assert.assertEquals(null, jsonStrategyContainer.newInstanceOfProperty("invalid").getClass().toString());
+ }
+ @Test
+ public void newInstanceOfNestedPropertyTest() {
+ Assert.assertEquals("class org.json.simple.JSONObject", jsonStrategyContainer.newInstanceOfNestedProperty("pservers").getClass().toString());
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void newInvalidInstanceOfNestedPropertyTest() {
+ jsonStrategyContainer.newInstanceOfNestedProperty("invalid").getClass().toString();
+ }
+
+ @Test
+ public void isComplexTypeTest() {
+ // Complex: The value of this key contains a JSONObject
+ Assert.assertTrue(jsonStrategyComplex.isComplexType("pserver"));
+ Assert.assertFalse(jsonStrategyContainer.isComplexType("pservers"));
+ Assert.assertFalse(jsonStrategy.isComplexType("hostname"));
+ }
+
+ @Test
+ public void isComplexGenericTypeTest() {
+ // Complex Generic: The value of this key contains an array of JSONObjects
+ Assert.assertTrue(jsonStrategyContainer.isComplexGenericType("pservers"));
+ Assert.assertFalse(jsonStrategyComplex.isComplexGenericType("pserver"));
+ Assert.assertFalse(jsonStrategy.isComplexGenericType("hostname"));
+ }
+}
diff --git a/aai-core/src/test/java/org/onap/aai/introspection/PropertyPredicatesTest.java b/aai-core/src/test/java/org/onap/aai/introspection/PropertyPredicatesTest.java
index 0250bbb3..d5eaf0b6 100644
--- a/aai-core/src/test/java/org/onap/aai/introspection/PropertyPredicatesTest.java
+++ b/aai-core/src/test/java/org/onap/aai/introspection/PropertyPredicatesTest.java
@@ -29,6 +29,7 @@ import org.onap.aai.introspection.exceptions.AAIUnknownObjectException;
import java.util.Set;
import static org.hamcrest.Matchers.hasItems;
+import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
import static org.junit.Assert.assertThat;
@@ -43,33 +44,33 @@ public class PropertyPredicatesTest extends AAISetup {
@Before
public void setup() throws Exception {
loader = LoaderFactory.createLoaderForVersion(introspectorFactoryType, version);
- obj = loader.introspectorFromName("test-object");
+ obj = loader.introspectorFromName("generic-vnf");
}
@Test
public void includeInTestGeneration() throws AAIUnknownObjectException {
Set<String> props = obj.getProperties(PropertyPredicates.includeInTestGeneration());
-
- assertThat("props not found", props,
- not(hasItems("persona-model-ver", "not-visible-test-element", "model-invariant-id", "model-version-id")));
+
+ assertThat("props not found", props,
+ not(hasItems("model-invariant-id", "model-version-id")));
}
@Test
public void isVisible() throws AAIUnknownObjectException {
Set<String> props = obj.getProperties(PropertyPredicates.isVisible());
-
- assertThat("props not found", props, not(hasItems("persona-model-ver")));
+
+ assertThat("props not found", props, hasItems("model-invariant-id", "model-version-id"));
}
@Test
public void all() throws AAIUnknownObjectException {
Set<String> props = obj.getProperties();
-
- assertThat("all found", props, hasItems("persona-model-ver", "not-visible-test-element"));
+
+ assertThat("all found", props, hasItems("model-invariant-id", "model-version-id"));
}
-
+
}
diff --git a/aai-core/src/test/java/org/onap/aai/introspection/sideeffect/DataCopyTest.java b/aai-core/src/test/java/org/onap/aai/introspection/sideeffect/DataCopyTest.java
index 4a870995..7d3cafac 100644
--- a/aai-core/src/test/java/org/onap/aai/introspection/sideeffect/DataCopyTest.java
+++ b/aai-core/src/test/java/org/onap/aai/introspection/sideeffect/DataCopyTest.java
@@ -83,9 +83,11 @@ public class DataCopyTest {
loader);
graph.traversal().addV("aai-node-type", "model", "model-invariant-id", "key1").as("v1")
- .addV("aai-node-type", "model-ver", "model-ver", "myValue", "model-version-id", "key2", "model-version", "testValue").addInE("has", "v1", EdgeProperty.CONTAINS.toString(), true)
+ .addV("aai-node-type", "model-ver", "model-ver", "myValue", "model-version-id", "key2", "model-version", "testValue")
+ .addOutE("org.onap.relationships.inventory.BelongsTo", "v1", EdgeProperty.CONTAINS.toString(), true)
.addV("aai-node-type", "model", "model-invariant-id", "key3").as("v2")
- .addV("aai-node-type", "model-ver", "model-ver", "myValue", "model-version-id", "key4").addInE("has", "v2", EdgeProperty.CONTAINS.toString(), true)
+ .addV("aai-node-type", "model-ver", "model-ver", "myValue", "model-version-id", "key4")
+ .addOutE("org.onap.relationships.inventory.BelongsTo", "v2", EdgeProperty.CONTAINS.toString(), true)
.next();
graph.tx().commit();
}
@@ -105,7 +107,7 @@ public class DataCopyTest {
public void runPopulatePersonaModelVer() throws URISyntaxException, AAIException, UnsupportedEncodingException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, SecurityException, InstantiationException, NoSuchMethodException, MalformedURLException {
final Loader loader = LoaderFactory.createLoaderForVersion(ModelType.MOXY, Version.getLatest());
- final Introspector obj = loader.introspectorFromName("test-object");
+ final Introspector obj = loader.introspectorFromName("generic-vnf");
obj.setValue("vnf-id", "myId");
obj.setValue("model-invariant-id", "key1");
obj.setValue("model-version-id", "key2");
@@ -123,7 +125,7 @@ public class DataCopyTest {
runner.execute(obj, self);
- assertEquals("value populated", "testValue", obj.getValue("persona-model-ver"));
+ assertEquals("value populated", "testValue", obj.getValue("persona-model-version"));
g.tx().rollback();
@@ -134,7 +136,7 @@ public class DataCopyTest {
public void runPopulateModelVersionId() throws URISyntaxException, AAIException, UnsupportedEncodingException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, SecurityException, InstantiationException, NoSuchMethodException, MalformedURLException {
final Loader loader = LoaderFactory.createLoaderForVersion(ModelType.MOXY, Version.v9);
- final Introspector obj = loader.introspectorFromName("test-object");
+ final Introspector obj = loader.introspectorFromName("generic-vnf");
obj.setValue("vnf-id", "myId");
obj.setValue("persona-model-id", "key1");
obj.setValue("persona-model-version", "testValue");
@@ -187,7 +189,7 @@ public class DataCopyTest {
public void expectedMissingPropertyExceptionInURI() throws AAIException, UnsupportedEncodingException {
final Loader loader = LoaderFactory.createLoaderForVersion(ModelType.MOXY, Version.getLatest());
- final Introspector obj = loader.introspectorFromName("test-object");
+ final Introspector obj = loader.introspectorFromName("generic-vnf");
obj.setValue("vnf-id", "myId");
obj.setValue("model-invariant-id", "key1");
@@ -210,7 +212,7 @@ public class DataCopyTest {
@Test
public void expectedMissingPropertyExceptionForResultingObject() throws AAIException, UnsupportedEncodingException {
final Loader loader = LoaderFactory.createLoaderForVersion(ModelType.MOXY, Version.getLatest());
- final Introspector obj = loader.introspectorFromName("test-object");
+ final Introspector obj = loader.introspectorFromName("generic-vnf");
obj.setValue("vnf-id", "myId");
obj.setValue("model-invariant-id", "key3");
obj.setValue("model-version-id", "key4");
@@ -234,7 +236,7 @@ public class DataCopyTest {
@Test
public void expectNoProcessingWithNoProperties() throws AAIException, UnsupportedEncodingException {
final Loader loader = LoaderFactory.createLoaderForVersion(ModelType.MOXY, Version.getLatest());
- final Introspector obj = loader.introspectorFromName("test-object");
+ final Introspector obj = loader.introspectorFromName("generic-vnf");
obj.setValue("vnf-id", "myId");
TransactionalGraphEngine spy = spy(dbEngine);
diff --git a/aai-core/src/test/java/org/onap/aai/introspection/sideeffect/DataLinkTest.java b/aai-core/src/test/java/org/onap/aai/introspection/sideeffect/DataLinkTest.java
index b817cc69..684bb5b8 100644
--- a/aai-core/src/test/java/org/onap/aai/introspection/sideeffect/DataLinkTest.java
+++ b/aai-core/src/test/java/org/onap/aai/introspection/sideeffect/DataLinkTest.java
@@ -31,6 +31,7 @@ import org.junit.*;
import org.junit.rules.ExpectedException;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
+import org.onap.aai.AAISetup;
import org.onap.aai.db.props.AAIProperties;
import org.onap.aai.dbmap.DBConnectionType;
import org.onap.aai.exceptions.AAIException;
@@ -52,7 +53,7 @@ import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
-public class DataLinkTest {
+public class DataLinkTest extends AAISetup {
private static TitanGraph graph;
private final static Version version = Version.getLatest();
@@ -71,8 +72,6 @@ public class DataLinkTest {
@BeforeClass
public static void setup() throws NoSuchFieldException, SecurityException, Exception {
graph = TitanFactory.build().set("storage.backend","inmemory").open();
- System.setProperty("AJSC_HOME", ".");
- System.setProperty("BUNDLECONFIG_DIR", "src/test/resources/bundleconfig-local");
loader = LoaderFactory.createLoaderForVersion(introspectorFactoryType, version);
dbEngine = new TitanDBEngine(
queryStyle,
@@ -81,13 +80,17 @@ public class DataLinkTest {
graph.traversal().addV("aai-node-type", "vpn-binding", "vpn-id", "addKey").as("v1")
.addV("aai-node-type", "vpn-binding", "vpn-id", "modifyKey").as("v2")
- .addV("aai-node-type", "route-target", "global-route-target", "modifyTargetKey", "route-target-role", "modifyRoleKey", "linked", true).addInE("has", "v2", EdgeProperty.CONTAINS.toString(), true)
+ .addV("aai-node-type", "route-target", "global-route-target", "modifyTargetKey", "route-target-role", "modifyRoleKey", "linked", true)
+ .addOutE("org.onap.relationships.inventory.BelongsTo", "v2", EdgeProperty.CONTAINS.toString(), true)
.addV("aai-node-type", "vpn-binding", "vpn-id", "deleteKey").as("v3")
- .addV("aai-node-type", "route-target", "global-route-target", "deleteTargetKey", "route-target-role", "deleteRoleKey", "linked", true).addInE("has", "v3", EdgeProperty.CONTAINS.toString(), true)
+ .addV("aai-node-type", "route-target", "global-route-target", "deleteTargetKey", "route-target-role", "deleteRoleKey", "linked", true)
+ .addOutE("org.onap.relationships.inventory.BelongsTo", "v3", EdgeProperty.CONTAINS.toString(), true)
.addV("aai-node-type", "vpn-binding", "vpn-id", "getKey").as("v4")
- .addV("aai-node-type", "route-target", "global-route-target", "getTargetKey", "route-target-role", "getRoleKey", "linked", true).addInE("has", "v4", EdgeProperty.CONTAINS.toString(), true)
+ .addV("aai-node-type", "route-target", "global-route-target", "getTargetKey", "route-target-role", "getRoleKey", "linked", true)
+ .addOutE("org.onap.relationships.inventory.BelongsTo", "v4", EdgeProperty.CONTAINS.toString(), true)
.addV("aai-node-type", "vpn-binding", "vpn-id", "getKeyNoLink").as("v5")
- .addV("aai-node-type", "route-target", "global-route-target", "getTargetKeyNoLink", "route-target-role", "getRoleKeyNoLink").addInE("has", "v5", EdgeProperty.CONTAINS.toString(), true)
+ .addV("aai-node-type", "route-target", "global-route-target", "getTargetKeyNoLink", "route-target-role", "getRoleKeyNoLink")
+ .addOutE("org.onap.relationships.inventory.BelongsTo", "v5", EdgeProperty.CONTAINS.toString(), true)
.next();
graph.tx().commit();
}
@@ -187,7 +190,12 @@ public class DataLinkTest {
runner.execute(obj, self);
assertEquals("route-target vertex not found", false, traversal.V()
- .has(AAIProperties.NODE_TYPE, "route-target").has("global-route-target", "deleteTargetKey").has("route-target-role", "deleteRoleKey").has("linked", true).hasNext());
+ .has(AAIProperties.NODE_TYPE, "route-target")
+ .has("global-route-target", "deleteTargetKey")
+ .has("route-target-role", "deleteRoleKey")
+ .has("linked", true)
+ .hasNext()
+ );
g.tx().rollback();
}
diff --git a/aai-core/src/test/java/org/onap/aai/introspection/tools/CreateUUIDTest.java b/aai-core/src/test/java/org/onap/aai/introspection/tools/CreateUUIDTest.java
new file mode 100644
index 00000000..bb2604ec
--- /dev/null
+++ b/aai-core/src/test/java/org/onap/aai/introspection/tools/CreateUUIDTest.java
@@ -0,0 +1,91 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017 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=========================================================
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ */
+package org.onap.aai.introspection.tools;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.aai.AAISetup;
+import org.onap.aai.introspection.*;
+import org.onap.aai.introspection.exceptions.AAIUnknownObjectException;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+public class CreateUUIDTest extends AAISetup {
+
+ private CreateUUID createUUID;
+
+ private Loader loader;
+ private Issue issue;
+
+ @Before
+ public void setup(){
+ createUUID = new CreateUUID();
+ loader = LoaderFactory.createLoaderForVersion(ModelType.MOXY, Version.getLatest());
+ }
+
+ /**
+ * Tests to check if the issue is not resolvable since
+ * the property that is being tested doesn't have the auto generated uuid
+ * metadata set to true in the oxm xml for the version specified
+ *
+ * @throws AAIUnknownObjectException - if the object type specified is unable to be found in the oxm
+ */
+ @Test
+ public void testNonResolvableIssueIfMissingPropNameThatIsRequired() throws AAIUnknownObjectException {
+
+ Introspector introspector = loader.introspectorFromName("pserver");
+
+ issue = new Issue();
+ issue.setDetail("Some message");
+ issue.setType(IssueType.MISSING_KEY_PROP);
+ issue.setPropName("hostname");
+ issue.setIntrospector(introspector);
+
+ boolean isIssue = createUUID.resolveIssue(issue);
+
+ assertFalse(isIssue);
+ }
+
+ /**
+ * Tests when there is a resolvable issue when the property
+ * looking for, model-element-uuid, has the auto generated uuid
+ * metadata attribute associated to it if the data is missing
+ *
+ * @throws AAIUnknownObjectException - if the object type specified is unable to be found in the oxm
+ */
+ @Test
+ public void testResolvableIssueWhenMissingPropNameAllowsToUseGeneratedUUID() throws AAIUnknownObjectException {
+
+ Introspector introspector = loader.introspectorFromName("model-element");
+
+ issue = new Issue();
+ issue.setDetail("Some message");
+ issue.setType(IssueType.MISSING_KEY_PROP);
+ issue.setPropName("model-element-uuid");
+ issue.setIntrospector(introspector);
+
+ boolean isIssue = createUUID.resolveIssue(issue);
+ assertTrue(isIssue);
+ }
+
+}
diff --git a/aai-core/src/test/java/org/onap/aai/introspection/validation/IntrospectorValidationTest.java b/aai-core/src/test/java/org/onap/aai/introspection/validation/IntrospectorValidationTest.java
index db21f578..3bba4ee0 100644
--- a/aai-core/src/test/java/org/onap/aai/introspection/validation/IntrospectorValidationTest.java
+++ b/aai-core/src/test/java/org/onap/aai/introspection/validation/IntrospectorValidationTest.java
@@ -63,7 +63,7 @@ public class IntrospectorValidationTest {
@Ignore
@Test
public void verifySuccessWhenEmpty() throws AAIException {
- Introspector obj = loader.introspectorFromName("test-object");
+ Introspector obj = loader.introspectorFromName("generic-vnf");
obj.setValue("vnf-id", "key1");
validator.validate(obj);
List<Issue> issues = validator.getIssues();
@@ -73,7 +73,7 @@ public class IntrospectorValidationTest {
@Ignore
@Test
public void verifyRequiresSingleFieldFailure() throws AAIException {
- Introspector obj = loader.introspectorFromName("test-object");
+ Introspector obj = loader.introspectorFromName("generic-vnf");
obj.setValue("vnf-id", "key1");
obj.setValue("model-invariant-id", "id1");
validator.validate(obj);
@@ -85,7 +85,7 @@ public class IntrospectorValidationTest {
@Ignore
@Test
public void verifyRequiresSuccess() throws AAIException {
- Introspector obj = loader.introspectorFromName("test-object");
+ Introspector obj = loader.introspectorFromName("generic-vnf");
obj.setValue("vnf-id", "key1");
obj.setValue("model-invariant-id", "id1");
obj.setValue("model-version-id", "version-id1");
diff --git a/aai-core/src/test/java/org/onap/aai/logging/EcompErrorCategoryTest.java b/aai-core/src/test/java/org/onap/aai/logging/EcompErrorCategoryTest.java
new file mode 100644
index 00000000..485a63f2
--- /dev/null
+++ b/aai-core/src/test/java/org/onap/aai/logging/EcompErrorCategoryTest.java
@@ -0,0 +1,50 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017 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=========================================================
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ */
+package org.onap.aai.logging;
+
+import static org.junit.Assert.*;
+import static org.mockito.Mockito.*;
+
+import ch.qos.logback.classic.Level;
+
+import ch.qos.logback.classic.spi.ILoggingEvent;
+import org.junit.*;
+
+public class EcompErrorCategoryTest {
+
+ EcompErrorCategory _ecompErrorCategory;
+ ILoggingEvent mockEvent;
+
+ @Before
+ public void setUp() throws Exception {
+
+ mockEvent = mock(ILoggingEvent.class);
+ _ecompErrorCategory= spy(EcompErrorCategory.class);
+
+ }
+ @Test
+ public void warn(){
+ String defaultCategory = "WARN";
+ assertEquals(_ecompErrorCategory.convert(mockEvent), defaultCategory);
+ }
+
+}
diff --git a/aai-core/src/test/java/org/onap/aai/logging/EcompResponseCodeTest.java b/aai-core/src/test/java/org/onap/aai/logging/EcompResponseCodeTest.java
new file mode 100644
index 00000000..522aeb2b
--- /dev/null
+++ b/aai-core/src/test/java/org/onap/aai/logging/EcompResponseCodeTest.java
@@ -0,0 +1,49 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017 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=========================================================
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ */
+package org.onap.aai.logging;
+
+import static org.junit.Assert.*;
+import static org.mockito.Mockito.*;
+
+import ch.qos.logback.classic.Level;
+
+import ch.qos.logback.classic.spi.ILoggingEvent;
+import org.junit.*;
+
+public class EcompResponseCodeTest {
+
+ EcompResponseCode _ecompResponseCode;
+ ILoggingEvent mockEvent;
+
+ @Before
+ public void setUp() throws Exception {
+
+ mockEvent = mock(ILoggingEvent.class);
+ _ecompResponseCode= spy(EcompResponseCode.class);
+
+ }
+ @Test
+ public void getDefaultCode(){
+ assertEquals(_ecompResponseCode.convert(mockEvent), LoggingContext.UNKNOWN_ERROR);
+ }
+
+}
diff --git a/aai-core/src/test/java/org/onap/aai/logging/EcompResponseDescriptionTest.java b/aai-core/src/test/java/org/onap/aai/logging/EcompResponseDescriptionTest.java
new file mode 100644
index 00000000..3453d2de
--- /dev/null
+++ b/aai-core/src/test/java/org/onap/aai/logging/EcompResponseDescriptionTest.java
@@ -0,0 +1,50 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017 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=========================================================
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ */
+package org.onap.aai.logging;
+
+import static org.junit.Assert.*;
+import static org.mockito.Mockito.*;
+
+import ch.qos.logback.classic.Level;
+
+import ch.qos.logback.classic.spi.ILoggingEvent;
+import org.junit.*;
+import org.onap.aai.logging.LoggingContext.LoggingField;
+
+public class EcompResponseDescriptionTest {
+
+ EcompResponseDescription _ecompResponseDescription;
+ ILoggingEvent mockEvent;
+
+ @Before
+ public void setUp() throws Exception {
+
+ mockEvent = mock(ILoggingEvent.class);
+ _ecompResponseDescription= spy(EcompResponseDescription.class);
+
+ }
+ @Test
+ public void getDefaultDesc(){
+ assertEquals(_ecompResponseDescription.convert(mockEvent), _ecompResponseDescription.DefaultDescription);
+ }
+
+}
diff --git a/aai-core/src/test/java/org/onap/aai/logging/LoggingContextTest.java b/aai-core/src/test/java/org/onap/aai/logging/LoggingContextTest.java
index 7885410d..46ac5997 100644
--- a/aai-core/src/test/java/org/onap/aai/logging/LoggingContextTest.java
+++ b/aai-core/src/test/java/org/onap/aai/logging/LoggingContextTest.java
@@ -53,7 +53,7 @@ public class LoggingContextTest {
}
@Test
- public void testRequestId() throws Exception { //AKA Transaction ID
+ public void testRequestId() { //AKA Transaction ID
final String sUuid = "57d51eaa-edc6-4f50-a69d-f2d4d2445120";
LoggingContext.requestId(sUuid);
diff --git a/aai-core/src/test/java/org/onap/aai/parsers/query/GraphTraversalTest.java b/aai-core/src/test/java/org/onap/aai/parsers/query/GraphTraversalTest.java
index df9d6122..968adb3c 100644
--- a/aai-core/src/test/java/org/onap/aai/parsers/query/GraphTraversalTest.java
+++ b/aai-core/src/test/java/org/onap/aai/parsers/query/GraphTraversalTest.java
@@ -126,7 +126,7 @@ public class GraphTraversalTest extends AAISetup {
QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start()
.has("physical-location-id", "key1").has("aai-node-type", "complex")
- .out("hasCtagPool")
+ .in("org.onap.relationships.inventory.BelongsTo")
.has("aai-node-type", "ctag-pool")
.has("target-pe", "key2").has("availability-zone-name", "key3");
GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start()
@@ -164,14 +164,14 @@ public class GraphTraversalTest extends AAISetup {
QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start()
.has("vnf-id", "key1").has("aai-node-type", "vce")
- .out("hasPortGroup")
+ .in("org.onap.relationships.inventory.BelongsTo")
.has("aai-node-type", "port-group")
- .has("interface-id", "key2").out("hasCTag")
+ .has("interface-id", "key2").in("org.onap.relationships.inventory.BelongsTo")
.has("aai-node-type", "cvlan-tag")
.has("cvlan-tag", 655);
GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start()
.has("vnf-id", "key1").has("aai-node-type", "vce")
- .out("hasPortGroup")
+ .in("org.onap.relationships.inventory.BelongsTo")
.has("aai-node-type", "port-group")
.has("interface-id", "key2");
assertEquals(
@@ -212,13 +212,13 @@ public class GraphTraversalTest extends AAISetup {
QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start()
.has("vnf-id", "key1").has("aai-node-type", "vce")
- .out("hasPortGroup")
+ .in("org.onap.relationships.inventory.BelongsTo")
.has("aai-node-type", "port-group")
- .has("interface-id", "key2").out("hasCTag")
+ .has("interface-id", "key2").in("org.onap.relationships.inventory.BelongsTo")
.has("aai-node-type", "cvlan-tag");
GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start()
.has("vnf-id", "key1").has("aai-node-type", "vce")
- .out("hasPortGroup")
+ .in("org.onap.relationships.inventory.BelongsTo")
.has("aai-node-type", "port-group")
.has("interface-id", "key2");
assertEquals(
@@ -296,7 +296,7 @@ public class GraphTraversalTest extends AAISetup {
GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start()
.has("cloud-owner", "mycloudowner").has("cloud-region-id", "mycloudregionid")
.has("aai-node-type", "cloud-region")
- .out("has")
+ .in("org.onap.relationships.inventory.BelongsTo")
.has("aai-node-type", "tenant")
.has("tenant-name", "Tenant1");
@@ -340,7 +340,7 @@ public class GraphTraversalTest extends AAISetup {
GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start()
.has("cloud-owner", "mycloudowner").has("cloud-region-id", "mycloudregionid")
.has("aai-node-type", "cloud-region")
- .out("has")
+ .in("org.onap.relationships.inventory.BelongsTo")
.has("aai-node-type", "tenant")
.has("tenant-name", P.within(values));
@@ -432,14 +432,14 @@ public class GraphTraversalTest extends AAISetup {
GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start()
.has("vnf-id", "key1").has("aai-node-type", "vce")
- .out("hasPortGroup")
+ .in("org.onap.relationships.inventory.BelongsTo")
.has("aai-node-type", "port-group")
- .has("interface-id", "key2").out("hasCTag")
+ .has("interface-id", "key2").in("org.onap.relationships.inventory.BelongsTo")
.has("aai-node-type", "cvlan-tag")
.has("cvlan-tag", 333);
GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start()
.has("vnf-id", "key1").has("aai-node-type", "vce")
- .out("hasPortGroup")
+ .in("org.onap.relationships.inventory.BelongsTo")
.has("aai-node-type", "port-group")
.has("interface-id", "key2");
assertEquals(
@@ -527,7 +527,7 @@ public class GraphTraversalTest extends AAISetup {
GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start()
.has("vnf-id", "key1").has(AAIProperties.NODE_TYPE, P.within("vce", "generic-vnf"))
- .union(__.out("has").has(AAIProperties.NODE_TYPE, "vf-module")).has("vf-module-id", "key2");
+ .union(__.in("org.onap.relationships.inventory.BelongsTo").has(AAIProperties.NODE_TYPE, "vf-module")).has("vf-module-id", "key2");
GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start()
.has("vnf-id", "key1").has(AAIProperties.NODE_TYPE, P.within("vce", "generic-vnf"));
@@ -621,15 +621,15 @@ public class GraphTraversalTest extends AAISetup {
@Test
public void dbAliasedSearch() throws UnsupportedEncodingException, AAIException {
- URI uri = UriBuilder.fromPath("network/test-objects").build();
+ URI uri = UriBuilder.fromPath("network/generic-vnfs").build();
MultivaluedMap<String, String> map = new MultivaluedHashMap<>();
map.putSingle("persona-model-customization-id", "key2");
QueryParser query = dbEnginev9.getQueryBuilder().createQueryFromURI(uri, map);
GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start()
- .has("aai-node-type", "test-object")
+ .has("aai-node-type", "generic-vnf")
.has("model-customization-id", "key2");
GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start()
- .has("aai-node-type", "test-object");
+ .has("aai-node-type", "generic-vnf");
assertEquals(
"gremlin query should be " + expected.toString(),
@@ -642,7 +642,7 @@ public class GraphTraversalTest extends AAISetup {
assertEquals(
"result type should be",
- "test-object",
+ "generic-vnf",
query.getResultType());
assertEquals(
"result type should be empty",
@@ -661,7 +661,7 @@ public class GraphTraversalTest extends AAISetup {
QueryParser query = dbEnginev9.getQueryBuilder().createQueryFromURI(uri, map);
GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start()
.has("aai-node-type", "vpn-binding")
- .where(__.out("has").has(AAIProperties.NODE_TYPE, "route-target").has("global-route-target", "key2"));
+ .where(__.in("org.onap.relationships.inventory.BelongsTo").has(AAIProperties.NODE_TYPE, "route-target").has("global-route-target", "key2"));
GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start()
.has("aai-node-type", "vpn-binding");
@@ -693,7 +693,7 @@ public class GraphTraversalTest extends AAISetup {
GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start()
.has("physical-location-id", "key1")
.has("aai-node-type", "complex")
- .in("locatedIn").has("aai-node-type", "pserver");
+ .in("org.onap.relationships.inventory.LocatedIn").has("aai-node-type", "pserver");
GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start()
.has("physical-location-id", "key1")
.has("aai-node-type", "complex");
@@ -727,7 +727,7 @@ public class GraphTraversalTest extends AAISetup {
GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start()
.has("physical-location-id", "key1")
.has("aai-node-type", "complex")
- .in("locatedIn").has("aai-node-type", "pserver")
+ .in("org.onap.relationships.inventory.LocatedIn").has("aai-node-type", "pserver")
.has("hostname", "key2");
GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start()
.has("physical-location-id", "key1")
@@ -762,14 +762,14 @@ public class GraphTraversalTest extends AAISetup {
GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start()
.has("physical-location-id", "key1")
.has("aai-node-type", "complex")
- .in("locatedIn").has("aai-node-type", "pserver")
+ .in("org.onap.relationships.inventory.LocatedIn").has("aai-node-type", "pserver")
.has("hostname", "key2")
- .in("runsOnPserver").has("aai-node-type", "vserver")
+ .in("tosca.relationships.HostedOn").has("aai-node-type", "vserver")
.has("vserver-id", "key3");
GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start()
.has("physical-location-id", "key1")
.has("aai-node-type", "complex")
- .in("locatedIn").has("aai-node-type", "pserver")
+ .in("org.onap.relationships.inventory.LocatedIn").has("aai-node-type", "pserver")
.has("hostname", "key2");
assertEquals(
diff --git a/aai-core/src/test/java/org/onap/aai/parsers/query/UniqueURIQueryTest.java b/aai-core/src/test/java/org/onap/aai/parsers/query/UniqueURIQueryTest.java
index 84e9c6bc..d9dcabd3 100644
--- a/aai-core/src/test/java/org/onap/aai/parsers/query/UniqueURIQueryTest.java
+++ b/aai-core/src/test/java/org/onap/aai/parsers/query/UniqueURIQueryTest.java
@@ -150,7 +150,7 @@ public class UniqueURIQueryTest extends AAISetup {
String parentKey = "vce/key1/port-group/key2";
URI uri = UriBuilder.fromPath(parentURI + "/cvlan-tags").build();
QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
- GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start().has("aai-unique-key", parentKey).out("hasCTag").has("aai-node-type", "cvlan-tag");
+ GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start().has("aai-unique-key", parentKey).in("org.onap.relationships.inventory.BelongsTo").has("aai-node-type", "cvlan-tag");
GraphTraversal<Vertex, Vertex> parentExpected = __.<Vertex>start().has("aai-unique-key",parentKey);
String parentResultType = "port-group";
String resultType = "cvlan-tag";
diff --git a/aai-core/src/test/java/org/onap/aai/parsers/relationship/RelationshipToURITest.java b/aai-core/src/test/java/org/onap/aai/parsers/relationship/RelationshipToURITest.java
index 04727067..1710986b 100644
--- a/aai-core/src/test/java/org/onap/aai/parsers/relationship/RelationshipToURITest.java
+++ b/aai-core/src/test/java/org/onap/aai/parsers/relationship/RelationshipToURITest.java
@@ -54,7 +54,7 @@ public class RelationshipToURITest extends AAISetup {
public void onlyLink() throws AAIException, URISyntaxException, IOException {
Loader loader = LoaderFactory.createLoaderForVersion(modelType, version10);
Introspector obj = loader.unmarshal("relationship", this.getJsonString("only-related-link.json"));
- URI expected = new URI("/aai/v10/network/test-objects/test-object/key1");
+ URI expected = new URI("/aai/v10/network/generic-vnfs/generic-vnf/key1");
RelationshipToURI parse = new RelationshipToURI(loader, obj);
@@ -67,7 +67,7 @@ public class RelationshipToURITest extends AAISetup {
public void onlyData() throws AAIException, URISyntaxException, IOException {
Loader loader = LoaderFactory.createLoaderForVersion(modelType, version10);
Introspector obj = loader.unmarshal("relationship", this.getJsonString("only-relationship-data.json"));
- URI expected = new URI("/network/test-objects/test-object/key1");
+ URI expected = new URI("/network/generic-vnfs/generic-vnf/key1");
RelationshipToURI parse = new RelationshipToURI(loader, obj);
@@ -80,7 +80,7 @@ public class RelationshipToURITest extends AAISetup {
public void failV10() throws AAIException, URISyntaxException, IOException {
Loader loader = LoaderFactory.createLoaderForVersion(modelType, version10);
Introspector obj = loader.unmarshal("relationship", this.getJsonString("both-failv10-successv9.json"));
- URI expected = new URI("/aai/v10/network/test-objects/test-object/key1");
+ URI expected = new URI("/aai/v10/network/generic-vnfs/generic-vnf/key1");
thrown.expect(AAIIdentityMapParseException.class);
thrown.expect(hasProperty("code", is("AAI_3000")));
@@ -93,7 +93,7 @@ public class RelationshipToURITest extends AAISetup {
public void successV9() throws AAIException, URISyntaxException, IOException {
Loader loader = LoaderFactory.createLoaderForVersion(modelType, version9);
Introspector obj = loader.unmarshal("relationship", this.getJsonString("both-failv10-successv9.json"));
- URI expected = new URI("/network/test-objects/test-object/key2");
+ URI expected = new URI("/network/generic-vnfs/generic-vnf/key2");
RelationshipToURI parse = new RelationshipToURI(loader, obj);
URI uri = parse.getUri();
@@ -107,7 +107,7 @@ public class RelationshipToURITest extends AAISetup {
public void failV9() throws AAIException, URISyntaxException, IOException {
Loader loader = LoaderFactory.createLoaderForVersion(modelType, version9);
Introspector obj = loader.unmarshal("relationship", this.getJsonString("both-successv10-failv9.json"));
- URI expected = new URI("/network/test-objects/test-object/key1");
+ URI expected = new URI("/network/generic-vnfs/generic-vnf/key1");
thrown.expect(AAIIdentityMapParseException.class);
thrown.expect(hasProperty("code", is("AAI_3000")));
@@ -122,7 +122,7 @@ public class RelationshipToURITest extends AAISetup {
public void failNothingToParse() throws AAIException, URISyntaxException, IOException {
Loader loader = LoaderFactory.createLoaderForVersion(modelType, version10);
Introspector obj = loader.unmarshal("relationship", this.getJsonString("nothing-to-parse.json"));
- URI expected = new URI("/aai/v10/network/test-objects/test-object/key1");
+ URI expected = new URI("/aai/v10/network/generic-vnfs/generic-vnf/key1");
thrown.expect(AAIIdentityMapParseException.class);
thrown.expect(hasProperty("code", is("AAI_3000")));
@@ -136,7 +136,7 @@ public class RelationshipToURITest extends AAISetup {
public void successV10() throws AAIException, URISyntaxException, IOException {
Loader loader = LoaderFactory.createLoaderForVersion(modelType, version10);
Introspector obj = loader.unmarshal("relationship", this.getJsonString("both-successv10-failv9.json"));
- URI expected = new URI("/aai/v10/network/test-objects/test-object/key1");
+ URI expected = new URI("/aai/v10/network/generic-vnfs/generic-vnf/key1");
RelationshipToURI parse = new RelationshipToURI(loader, obj);
@@ -152,7 +152,7 @@ public class RelationshipToURITest extends AAISetup {
public void ambiguousRelationship() throws AAIException, URISyntaxException, IOException {
Loader loader = LoaderFactory.createLoaderForVersion(modelType, version10);
Introspector obj = loader.unmarshal("relationship", this.getJsonString("ambiguous-relationship.json"));
- URI expected = new URI("/aai/v10/network/test-objects/test-object/key1");
+ URI expected = new URI("/aai/v10/network/generic-vnfs/generic-vnf/key1");
thrown.expect(AmbiguousMapAAIException.class);
thrown.expect(hasProperty("code", is("AAI_6146")));
diff --git a/aai-core/src/test/java/org/onap/aai/parsers/uri/URIParserTest.java b/aai-core/src/test/java/org/onap/aai/parsers/uri/URIParserTest.java
index bc3a684b..42d26f99 100644
--- a/aai-core/src/test/java/org/onap/aai/parsers/uri/URIParserTest.java
+++ b/aai-core/src/test/java/org/onap/aai/parsers/uri/URIParserTest.java
@@ -59,7 +59,7 @@ public class URIParserTest extends AAISetup {
URI uri = UriBuilder.fromPath("/aai/" + loader.getVersion() + "/network/tenants/tenant/key1/vservers/vserver/key2/l-interfaces/l-interface/key3").build();
thrown.expect(AAIException.class);
- thrown.expect(hasProperty("code", is("AAI_3000")));
+ thrown.expect(hasProperty("code", is("AAI_3001")));
new URIToDBKey(loader, uri);
}
diff --git a/aai-core/src/test/java/org/onap/aai/parsers/uri/URIToExtensionInformationTest.java b/aai-core/src/test/java/org/onap/aai/parsers/uri/URIToExtensionInformationTest.java
index ce4933a6..ca64ec76 100644
--- a/aai-core/src/test/java/org/onap/aai/parsers/uri/URIToExtensionInformationTest.java
+++ b/aai-core/src/test/java/org/onap/aai/parsers/uri/URIToExtensionInformationTest.java
@@ -53,7 +53,7 @@ public class URIToExtensionInformationTest extends AAISetup {
*/
@Test
public void vserversV8() throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException {
- URI uri = UriBuilder.fromPath("/aai/" + v8Loader.getVersion() + "/cloud-infrastructure/cloud-regions/cloud-region/att-aic/AAIAIC25/tenants/tenant/key1/vservers/vserver/key2").build();
+ URI uri = UriBuilder.fromPath("/aai/" + v8Loader.getVersion() + "/cloud-infrastructure/cloud-regions/cloud-region/testOwner1/testRegion1/tenants/tenant/key1/vservers/vserver/key2").build();
URIToExtensionInformation parse = new URIToExtensionInformation(v8Loader, uri);
String namespace = "cloudInfrastructure";
diff --git a/aai-core/src/test/java/org/onap/aai/query/builder/QueryBuilderTestAbstraction.java b/aai-core/src/test/java/org/onap/aai/query/builder/QueryBuilderTestAbstraction.java
index d478d608..b475a385 100644
--- a/aai-core/src/test/java/org/onap/aai/query/builder/QueryBuilderTestAbstraction.java
+++ b/aai-core/src/test/java/org/onap/aai/query/builder/QueryBuilderTestAbstraction.java
@@ -35,8 +35,7 @@ import org.apache.tinkerpop.gremlin.process.traversal.step.util.BulkSet;
import org.apache.tinkerpop.gremlin.structure.Edge;
import org.apache.tinkerpop.gremlin.structure.Graph;
import org.apache.tinkerpop.gremlin.structure.Vertex;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.*;
import org.onap.aai.AAISetup;
import org.onap.aai.db.props.AAIProperties;
import org.onap.aai.exceptions.AAIException;
@@ -51,19 +50,33 @@ import org.onap.aai.serialization.db.exceptions.NoEdgeRuleFoundException;
public abstract class QueryBuilderTestAbstraction extends AAISetup {
- protected Loader loader;
- protected Graph graph;
+ protected static Loader loader;
+ protected static Graph graph;
protected GraphTraversalSource g;
-
+
protected EdgeRules testEdgeRules = EdgeRules.getInstance("/dbedgerules/DbEdgeRules_TraversalQueryTest.json");
- @Before
- public void configure() throws Exception {
+
+ @BeforeClass
+ public static void setup() throws Exception {
loader = LoaderFactory.createLoaderForVersion(ModelType.MOXY, AAIProperties.LATEST);
graph = TitanFactory.build().set("storage.backend", "inmemory").open();
+ }
+
+ @Before
+ public void configure() throws Exception {
g = graph.traversal();
}
-
+
+ @After
+ public void deConfigure() throws Exception {
+ g.tx().rollback();
+ }
+
+ @AfterClass
+ public static void teardown() throws Exception {
+ graph.close();
+ }
@Test
public void createEdgeGVnfToVnfcTraversal() throws AAIException {
@@ -77,7 +90,7 @@ public abstract class QueryBuilderTestAbstraction extends AAISetup {
assertEquals(vnfc, tQ.next());
- g.tx().rollback();
+
}
@Test
@@ -94,7 +107,7 @@ public abstract class QueryBuilderTestAbstraction extends AAISetup {
assertEquals(logicalLink, next);
- g.tx().rollback();
+
}
@Test
@@ -111,7 +124,7 @@ public abstract class QueryBuilderTestAbstraction extends AAISetup {
assertEquals(logicalLink, next);
- g.tx().rollback();
+
}
@Test
@@ -128,7 +141,7 @@ public abstract class QueryBuilderTestAbstraction extends AAISetup {
assertEquals(logicalLink, next);
- g.tx().rollback();
+
}
@Test
@@ -147,7 +160,7 @@ public abstract class QueryBuilderTestAbstraction extends AAISetup {
assertEquals("Has 1 vertexes ", 1, list.size());
assertTrue("Has vertex on the default edge ", list.contains(vnfc1));
- g.tx().rollback();
+
}
@Test
@@ -172,7 +185,7 @@ public abstract class QueryBuilderTestAbstraction extends AAISetup {
assertEquals("2 - Has 1 vertexes ", 1, list2.size());
assertTrue("2 - traversal results in vce ", list2.contains(vce));
- g.tx().rollback();
+
}
@Test
@@ -191,7 +204,7 @@ public abstract class QueryBuilderTestAbstraction extends AAISetup {
assertEquals("1 - Has 1 vertexes ", 1, list.size());
assertTrue("1 - traversal results in vnfc ", list.contains(pserver));
- g.tx().rollback();
+
}
@Test
@@ -213,7 +226,7 @@ public abstract class QueryBuilderTestAbstraction extends AAISetup {
assertTrue("Has vertex on the default edge ", list.contains(vnfc1));
assertTrue("Has vertex on the re-uses edge ", list.contains(vnfc2));
- g.tx().rollback();
+
}
@Test
@@ -234,7 +247,7 @@ public abstract class QueryBuilderTestAbstraction extends AAISetup {
assertEquals("Has 1 vertexes ", 1, list.size());
assertTrue("Only returns the generic vnf vertex", list.contains(gvnf));
- g.tx().rollback();
+
}
@Test
@@ -250,7 +263,7 @@ public abstract class QueryBuilderTestAbstraction extends AAISetup {
assertEquals("Has 1 vertexes ", 1, list.size());
- g.tx().rollback();
+
}
@Test
@@ -266,7 +279,7 @@ public abstract class QueryBuilderTestAbstraction extends AAISetup {
assertEquals("Has 2 vertexes ", 2, list.size());
- g.tx().rollback();
+
}
@Test
@@ -282,7 +295,7 @@ public abstract class QueryBuilderTestAbstraction extends AAISetup {
assertEquals("Has 2 vertexes ", 2, list.size());
- g.tx().rollback();
+
}
@Test
@@ -302,7 +315,7 @@ public abstract class QueryBuilderTestAbstraction extends AAISetup {
assertEquals("Has 2 vertexes ", 1, list.size());
assertTrue("result has pserver ", list.contains(pserver));
- g.tx().rollback();
+
}
@Test
@@ -322,7 +335,7 @@ public abstract class QueryBuilderTestAbstraction extends AAISetup {
assertEquals("Has 2 vertexes ", 1, list.size());
assertEquals("result has pserver ",pserver, list.get(0).iterator().next());
- g.tx().rollback();
+
}
@Test
@@ -342,7 +355,7 @@ public abstract class QueryBuilderTestAbstraction extends AAISetup {
assertEquals("Has 2 vertexes ", 2, list.size());
assertTrue("result has pserver ", list.contains(pserver));
- g.tx().rollback();
+
}
@Test
@@ -362,7 +375,7 @@ public abstract class QueryBuilderTestAbstraction extends AAISetup {
list.add(tQ.next());
assertFalse("Has next 3 ",tQ.hasNext());
assertTrue("Has all the vertexes", list.contains(v1) && list.remove(v2));
- g.tx().rollback();
+
}
@Test
@@ -382,7 +395,7 @@ public abstract class QueryBuilderTestAbstraction extends AAISetup {
assertEquals("Has 2 vertexes ", 2, list.size());
assertTrue("result has pserver ", list.contains(pserver));
- g.tx().rollback();
+
}
@Test
@@ -402,7 +415,7 @@ public abstract class QueryBuilderTestAbstraction extends AAISetup {
assertEquals("Has 2 vertexes ", 2, list.size());
assertTrue("result has pserver ", list.contains(complex));
- g.tx().rollback();
+
}
@Test
@@ -421,7 +434,7 @@ public abstract class QueryBuilderTestAbstraction extends AAISetup {
assertEquals("1 - Has 1 edge ", 1, list.size());
assertTrue("1 - traversal results in edge ", list.contains(e));
- g.tx().rollback();
+
}
@Test
@@ -440,7 +453,7 @@ public abstract class QueryBuilderTestAbstraction extends AAISetup {
assertEquals("1 - Has 1 edge ", 1, list1.size());
assertTrue("1 - traversal results in edge ", list1.contains(e));
- g.tx().rollback();
+
}
@Test
@@ -461,7 +474,7 @@ public abstract class QueryBuilderTestAbstraction extends AAISetup {
assertTrue("result has default edge ", list.contains(e1));
assertTrue("result has other edge ", list.contains(e2));
- g.tx().rollback();
+
}
@Test
@@ -482,7 +495,7 @@ public abstract class QueryBuilderTestAbstraction extends AAISetup {
assertTrue("result has default edge ", list.contains(e1));
assertTrue("result has other edge ", list.contains(e2));
- g.tx().rollback();
+
}
@Test
@@ -504,7 +517,7 @@ public abstract class QueryBuilderTestAbstraction extends AAISetup {
assertTrue("result has default edge ", list.contains(e1));
assertTrue("result has other edge ", list.contains(e2));
- g.tx().rollback();
+
}
@Test (expected = NoEdgeRuleFoundException.class)
@@ -518,7 +531,7 @@ public abstract class QueryBuilderTestAbstraction extends AAISetup {
QueryBuilder<Edge> tQ = getNewEdgeTraversal(gvnf);
tQ.getEdgesBetweenWithLabels(EdgeType.COUSIN, "generic-vnf", "pserver", Collections.emptyList());
- g.tx().rollback();
+
}
@Test
@@ -538,7 +551,7 @@ public abstract class QueryBuilderTestAbstraction extends AAISetup {
assertEquals("Has 1 edges ", 1, list.size());
assertFalse("result does not have default edge ", list.contains(e1));
assertTrue("result has other edge ", list.contains(e2));
- g.tx().rollback();
+
}
@Test
@@ -558,7 +571,7 @@ public abstract class QueryBuilderTestAbstraction extends AAISetup {
assertEquals("Has 2 edges ", 2, list.size());
assertTrue("result has generic-vnf-pserver-A edge ", list.contains(e1));
assertTrue("result has generic-vnf-pserver-B edge ", list.contains(e2));
- g.tx().rollback();
+
}
@Test (expected = NoEdgeRuleFoundException.class)
@@ -571,7 +584,7 @@ public abstract class QueryBuilderTestAbstraction extends AAISetup {
List<Edge> list = tQ.toList();
- g.tx().rollback();
+
}
private Vertex getVertex() throws AAIException {
@@ -600,7 +613,7 @@ public abstract class QueryBuilderTestAbstraction extends AAISetup {
assertEquals("Has 1 edges ", 1, list.size());
assertFalse("result does not have default edge ", list.contains(e1));
assertTrue("result has other edge ", list.contains(e2));
- g.tx().rollback();
+
}
@Test
@@ -620,7 +633,7 @@ public abstract class QueryBuilderTestAbstraction extends AAISetup {
assertEquals("Has 2 edges ", 2, list.size());
assertTrue("result has generic-vnf-pserver-A edge ", list.contains(e1));
assertTrue("result has generic-vnf-pserver-B edge ", list.contains(e2));
- g.tx().rollback();
+
}
protected abstract QueryBuilder<Edge> getNewEdgeTraversal(Vertex v);
diff --git a/aai-core/src/test/java/org/onap/aai/query/builder/SimplePathTest.java b/aai-core/src/test/java/org/onap/aai/query/builder/SimplePathTest.java
index a3515ab9..4dfe2dbd 100644
--- a/aai-core/src/test/java/org/onap/aai/query/builder/SimplePathTest.java
+++ b/aai-core/src/test/java/org/onap/aai/query/builder/SimplePathTest.java
@@ -79,9 +79,6 @@ public class SimplePathTest extends AAISetup {
Vertex lint2 = graph.addVertex(T.label, "l-interface", T.id, "11", "aai-node-type", "l-interface",
"interface-name", "lint2", "is-port-mirrored", "true", "in-maint", "true", "is-ip-unnumbered", "false");
- Vertex loglink2 = graph.addVertex(T.label, "logical-link", T.id, "21", "aai-node-type", "logical-link",
- "link-name", "loglink2", "in-maint", "false", "link-type", "sausage");
-
Vertex lint3 = graph.addVertex(T.label, "l-interface", T.id, "12", "aai-node-type", "l-interface",
"interface-name", "lint3", "is-port-mirrored", "true", "in-maint", "true", "is-ip-unnumbered", "false");
@@ -91,8 +88,7 @@ public class SimplePathTest extends AAISetup {
rules.addTreeEdge(g, gvnf1, lint1);
rules.addEdge(g, lint1, loglink1);
rules.addEdge(g, loglink1, lint2);
- rules.addEdge(g, lint2, loglink2);
- rules.addEdge(g, loglink2, lint3);
+ rules.addEdge(g, loglink1, lint3);
rules.addTreeEdge(g, gvnf2, lint3);
return g;
diff --git a/aai-core/src/test/java/org/onap/aai/query/builder/TraversalQueryTest.java b/aai-core/src/test/java/org/onap/aai/query/builder/TraversalQueryTest.java
index 41daf17f..81d42ddb 100644
--- a/aai-core/src/test/java/org/onap/aai/query/builder/TraversalQueryTest.java
+++ b/aai-core/src/test/java/org/onap/aai/query/builder/TraversalQueryTest.java
@@ -75,20 +75,20 @@ public class TraversalQueryTest extends QueryBuilderTestAbstraction {
assertEquals("they are equal", expected, tQ.getQuery());
- g.tx().rollback();
+
}
@Test
public void traversalClones() throws UnsupportedEncodingException, AAIException, URISyntaxException {
QueryBuilder<Vertex> tQ = new TraversalQuery<>(loader, g);
- QueryBuilder<Vertex> builder = tQ.createQueryFromURI(new URI("network/test-objects/test-object/key1")).getQueryBuilder();
- GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start().has("vnf-id", "key1").has("aai-node-type", "test-object");
- GraphTraversal<Vertex, Vertex> containerExpected = __.<Vertex>start().has("aai-node-type", "test-object");
+ QueryBuilder<Vertex> builder = tQ.createQueryFromURI(new URI("network/generic-vnfs/generic-vnf/key1")).getQueryBuilder();
+ GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start().has("vnf-id", "key1").has("aai-node-type", "generic-vnf");
+ GraphTraversal<Vertex, Vertex> containerExpected = __.<Vertex>start().has("aai-node-type", "generic-vnf");
assertEquals("query object", expected.toString(), builder.getQuery().toString());
assertEquals("container query object", containerExpected.toString(), builder.getContainerQuery().getQuery().toString());
- g.tx().rollback();
+
}
@Test
@@ -96,13 +96,21 @@ public class TraversalQueryTest extends QueryBuilderTestAbstraction {
QueryBuilder<Vertex> tQ = new TraversalQuery<>(loader, g);
QueryBuilder<Vertex> builder = tQ.createQueryFromURI(new URI("network/generic-vnfs/generic-vnf/key1/l-interfaces/l-interface/key2")).getQueryBuilder();
- GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start().has("vnf-id", "key1").has("aai-node-type", "generic-vnf").out("hasLInterface").has(AAIProperties.NODE_TYPE, "l-interface").has("interface-name", "key2");
- GraphTraversal<Vertex, Vertex> containerExpected = __.<Vertex>start().has("vnf-id", "key1").has("aai-node-type", "generic-vnf").out("hasLInterface").has(AAIProperties.NODE_TYPE, "l-interface");
+ GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start()
+ .has("vnf-id", "key1")
+ .has("aai-node-type", "generic-vnf")
+ .in("org.onap.relationships.inventory.BelongsTo").has(AAIProperties.NODE_TYPE, "l-interface")
+ .has("interface-name", "key2");
+ GraphTraversal<Vertex, Vertex> containerExpected = __.<Vertex>start()
+ .has("vnf-id", "key1")
+ .has("aai-node-type", "generic-vnf")
+ .in("org.onap.relationships.inventory.BelongsTo")
+ .has(AAIProperties.NODE_TYPE, "l-interface");
assertEquals("query object", expected.toString(), builder.getQuery().toString());
assertEquals("container query object", containerExpected.toString(), builder.getContainerQuery().getQuery().toString());
- g.tx().rollback();
+
}
@Test
@@ -121,7 +129,7 @@ public class TraversalQueryTest extends QueryBuilderTestAbstraction {
assertEquals("Has 1 vertexes ", 1, list.size());
assertTrue("Has vertex on the default edge ", list.contains(vnfc1));
- g.tx().rollback();
+
}
@Test
@@ -146,7 +154,7 @@ public class TraversalQueryTest extends QueryBuilderTestAbstraction {
assertEquals("2 - Has 1 vertexes ", 1, list2.size());
assertTrue("2 - traversal results in vce ", list2.contains(vce));
- g.tx().rollback();
+
}
@Test
@@ -165,7 +173,7 @@ public class TraversalQueryTest extends QueryBuilderTestAbstraction {
assertEquals("1 - Has 1 vertexes ", 1, list.size());
assertTrue("1 - traversal results in vnfc ", list.contains(pserver));
- g.tx().rollback();
+
}
@Test
@@ -187,7 +195,7 @@ public class TraversalQueryTest extends QueryBuilderTestAbstraction {
assertTrue("Has vertex on the default edge ", list.contains(vnfc1));
assertTrue("Has vertex on the re-uses edge ", list.contains(vnfc2));
- g.tx().rollback();
+
}
@Test
@@ -207,7 +215,7 @@ public class TraversalQueryTest extends QueryBuilderTestAbstraction {
assertEquals("Has 2 vertexes ", 2, list.size());
assertTrue("result has pserver ", list.contains(pserver));
- g.tx().rollback();
+
}
@Test
@@ -227,7 +235,7 @@ public class TraversalQueryTest extends QueryBuilderTestAbstraction {
assertEquals("Has 2 vertexes ", 2, list.size());
assertTrue("result has pserver ", list.contains(complex));
- g.tx().rollback();
+
}
diff --git a/aai-core/src/test/java/org/onap/aai/rest/CloudRegionTest.java b/aai-core/src/test/java/org/onap/aai/rest/CloudRegionTest.java
new file mode 100644
index 00000000..55fdd53d
--- /dev/null
+++ b/aai-core/src/test/java/org/onap/aai/rest/CloudRegionTest.java
@@ -0,0 +1,76 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017 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=========================================================
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ */
+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.onap.aai.AAIJunitRunner;
+import org.onap.aai.HttpTestUtil;
+import org.onap.aai.PayloadUtil;
+import org.onap.aai.exceptions.AAIException;
+import org.skyscreamer.jsonassert.JSONAssert;
+
+import javax.ws.rs.core.Response;
+import java.io.IOException;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * <b>CloudRegionTest</b> is testing if you put a cloud region with all
+ * children nodes associated to it then you should be able to
+ * remove the cloud region without removing the individual child nodes first
+ */
+@RunWith(AAIJunitRunner.class)
+public class CloudRegionTest {
+
+ private HttpTestUtil httpTestUtil;
+
+ @Before
+ public void setUp(){
+ httpTestUtil = new HttpTestUtil();
+ }
+
+ @Ignore("Test is failing due to the deletion of node with children not correct will be fixed soon")
+ @Test
+ public void testPutWithAllCloudRegionChildrenNodesAndCheckIfDeleteIsSuccessful() throws IOException, AAIException {
+
+ String cloudRegionPayload = PayloadUtil.getResourcePayload("cloud-region-with-all-children.json");
+ String cloudRegionUri = "/aai/v12/cloud-infrastructure/cloud-regions/cloud-region/junit-cloud-owner/junit-cloud-region";
+
+ 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 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/rest/GenericVnfLInterfaceTest.java b/aai-core/src/test/java/org/onap/aai/rest/GenericVnfLInterfaceTest.java
new file mode 100644
index 00000000..f42eebb8
--- /dev/null
+++ b/aai-core/src/test/java/org/onap/aai/rest/GenericVnfLInterfaceTest.java
@@ -0,0 +1,78 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017 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=========================================================
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ */
+package org.onap.aai.rest;
+
+import org.json.JSONObject;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.onap.aai.AAIJunitRunner;
+import org.onap.aai.HttpTestUtil;
+import org.onap.aai.PayloadUtil;
+import org.skyscreamer.jsonassert.JSONAssert;
+
+import javax.ws.rs.core.Response;
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.junit.Assert.assertEquals;
+
+@RunWith(AAIJunitRunner.class)
+public class GenericVnfLInterfaceTest {
+
+ private HttpTestUtil httpTestUtil;
+
+ @Before
+ public void setUp(){
+ httpTestUtil = new HttpTestUtil();
+ }
+
+ @Test
+ public void testPutTwoLInterfacesToGenericVnf() throws Exception {
+
+ Map<String, String> templateValueMap = new HashMap<>();
+ templateValueMap.put("ip-address", "ipv1");
+
+ String resource = PayloadUtil.getTemplatePayload("generic-vnf-with-lag-interface.json", templateValueMap);
+ Response response = httpTestUtil.doPut("/aai/v12/network/generic-vnfs/generic-vnf/vnf1", resource);
+ assertEquals("Expecting the generic vnf to be created", 201, response.getStatus());
+
+ response = httpTestUtil.doGet("/aai/v12/network/generic-vnfs/generic-vnf/vnf1");
+ assertEquals("Expecting the generic vnf to be updated", 200, response.getStatus());
+
+ resource = response.getEntity().toString().replaceAll("ipv1\",\"resource-version\":\"\\d+\"", "ipv2\"");
+ response = httpTestUtil.doPut("/aai/v12/network/generic-vnfs/generic-vnf/vnf1", resource);
+ assertEquals("Expecting the generic vnf to be updated", 200, response.getStatus());
+
+ response = httpTestUtil.doGet("/aai/v12/network/generic-vnfs/generic-vnf/vnf1");
+ assertEquals("Expecting the generic vnf to be updated", 200, response.getStatus());
+
+ String expected = PayloadUtil.getExpectedPayload("generic-vnf-with-lag-interface.json");
+ JSONAssert.assertEquals(expected, response.getEntity().toString(), false);
+
+ JSONObject jsonObject = new JSONObject(response.getEntity().toString());
+ String resourceVersion = (String) jsonObject.get("resource-version");
+
+ response = httpTestUtil.doDelete("/aai/v12/network/generic-vnfs/generic-vnf/vnf1", resourceVersion);
+ assertEquals("Expecting the generic vnf to be deleted", 204, response.getStatus());
+ }
+}
diff --git a/aai-core/src/test/java/org/onap/aai/rest/TenantTest.java b/aai-core/src/test/java/org/onap/aai/rest/TenantTest.java
new file mode 100644
index 00000000..3de8dfa2
--- /dev/null
+++ b/aai-core/src/test/java/org/onap/aai/rest/TenantTest.java
@@ -0,0 +1,93 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017 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=========================================================
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ */
+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.onap.aai.AAIJunitRunner;
+import org.onap.aai.HttpTestUtil;
+import org.onap.aai.PayloadUtil;
+import org.skyscreamer.jsonassert.JSONAssert;
+
+import javax.ws.rs.core.Response;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.UUID;
+
+import static org.junit.Assert.assertEquals;
+
+@RunWith(AAIJunitRunner.class)
+public class TenantTest {
+
+ private HttpTestUtil httpTestUtil;
+
+ private Map<String, String> templateValuesMap;
+
+ @Before
+ public void setup(){
+ httpTestUtil = new HttpTestUtil();
+ templateValuesMap = new HashMap<>();
+ }
+
+ @Ignore("Test is failing due to the deletion of node with children not correct will be fixed soon")
+ @Test
+ public void testCloudRegionTenantDeleteSuccessWithoutDeletingVserver() throws Exception {
+
+ templateValuesMap.put("cloud-region-id", UUID.randomUUID().toString());
+ templateValuesMap.put("cloud-owner", UUID.randomUUID().toString());
+ templateValuesMap.put("tenant-id", UUID.randomUUID().toString());
+ templateValuesMap.put("vserver-id", UUID.randomUUID().toString());
+
+ String cloudRegionPayload = PayloadUtil.getTemplatePayload("cloud-region.json", templateValuesMap);
+ String cloudRegionUri = String.format("/aai/v12/cloud-infrastructure/cloud-regions/cloud-region/%s/%s",
+ templateValuesMap.get("cloud-owner"),
+ templateValuesMap.get("cloud-region-id")
+ );
+
+ String tenantUri = cloudRegionUri + "/tenants/tenant/" + templateValuesMap.get("tenant-id");
+ String tenantPayload = PayloadUtil.getTemplatePayload("tenant.json", templateValuesMap);
+
+ Response response = httpTestUtil.doPut(cloudRegionUri, cloudRegionPayload);
+ assertEquals("Expected the cloud region to be created", 201, response.getStatus());
+
+ response = httpTestUtil.doGet(tenantUri);
+ assertEquals("Expected the cloud region to be created", 200, response.getStatus());
+ String responseStr = response.getEntity().toString();
+
+ JSONAssert.assertEquals(tenantPayload, responseStr, false);
+ String resourceVersion = JsonPath.read(responseStr, "$.resource-version");
+
+ response = httpTestUtil.doDelete(tenantUri, resourceVersion);
+ assertEquals("Expected the cloud region to be created", 204, response.getStatus());
+
+ response = httpTestUtil.doGet(cloudRegionUri);
+ assertEquals("Expected the cloud region to be created", 200, response.getStatus());
+ responseStr = response.getEntity().toString();
+ resourceVersion = JsonPath.read(responseStr, "$.resource-version");
+
+ response = httpTestUtil.doDelete(cloudRegionUri, resourceVersion);
+ assertEquals("Expected the cloud region to be created", 204, response.getStatus());
+ }
+}
diff --git a/aai-core/src/test/java/org/onap/aai/rest/db/HttpEntryTest.java b/aai-core/src/test/java/org/onap/aai/rest/db/HttpEntryTest.java
index f643fc47..0d4f4f14 100644
--- a/aai-core/src/test/java/org/onap/aai/rest/db/HttpEntryTest.java
+++ b/aai-core/src/test/java/org/onap/aai/rest/db/HttpEntryTest.java
@@ -52,6 +52,7 @@ import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.anyObject;
import static org.mockito.Mockito.when;
@@ -115,6 +116,31 @@ public class HttpEntryTest extends AAISetup {
when(httpHeaders.getMediaType()).thenReturn(APPLICATION_JSON);
}
+ private Response getResponse(HttpEntry httpEntry, Loader loader, TransactionalGraphEngine dbEngine, HttpMethod method, String uri, String content) throws UnsupportedEncodingException, AAIException {
+ URI uriObject = UriBuilder.fromPath(uri).build();
+ QueryParser uriQuery = dbEngine.getQueryBuilder().createQueryFromURI(uriObject);
+ String objType = uriQuery.getResultType();
+ if (uri.endsWith("relationship")) {
+ objType = "relationship";
+ }
+ Introspector obj = null;
+ if (method.equals(HttpMethod.GET)) {
+ obj = loader.introspectorFromName(objType);
+ } else {
+ obj = loader.unmarshal(objType, content, org.onap.aai.restcore.MediaType.getEnum("application/json"));
+ }
+
+ DBRequest dbRequest =
+ new DBRequest.Builder(method, uriObject, uriQuery, obj, httpHeaders, uriInfo, "JUNIT-TRANSACTION")
+ .rawRequestContent(content).build();
+
+ List<DBRequest> dbRequestList = new ArrayList<>();
+ dbRequestList.add(dbRequest);
+
+ Pair<Boolean, List<Pair<URI, Response>>> responsesTuple = httpEntry.process(dbRequestList, "JUNIT");
+ return responsesTuple.getValue1().get(0).getValue1();
+ }
+
@Test
public void test1PutOnPserver() throws UnsupportedEncodingException, AAIException {
@@ -124,99 +150,95 @@ public class HttpEntryTest extends AAISetup {
Loader loader = httpEntry.getLoader();
TransactionalGraphEngine dbEngine = httpEntry.getDbEngine();
- URI uriObject = UriBuilder.fromPath("/cloud-infrastructure/pservers/pserver/junit-test1").build();
-
- QueryParser uriQuery = dbEngine.getQueryBuilder().createQueryFromURI(uriObject);
-
+ String uri = "/cloud-infrastructure/pservers/pserver/junit-test1";
String content = "{\"hostname\":\"junit-test1\"}";
+ Response response = getResponse(httpEntry, loader, dbEngine, HttpMethod.PUT, uri, content);
+ dbEngine.commit();
+ assertEquals("Expected the pserver to be created", 201, response.getStatus());
+ }
- Introspector obj = loader.unmarshal("pserver", content, org.onap.aai.restcore.MediaType.getEnum("application/json"));
-
- DBRequest dbRequest =
- new DBRequest.Builder(HttpMethod.PUT, uriObject, uriQuery, obj, httpHeaders, uriInfo, "JUNIT-TRANSACTION")
- .rawRequestContent(content).build();
+ @Test
+ public void test2PutOnPserverNoPInterface() throws UnsupportedEncodingException, AAIException {
- List<DBRequest> dbRequestList = new ArrayList<>();
- dbRequestList.add(dbRequest);
+ DBConnectionType type = DBConnectionType.REALTIME;
+ HttpEntry httpEntry = new HttpEntry(Version.getLatest(), ModelType.MOXY, QueryStyle.TRAVERSAL, type);
+ Loader loader = httpEntry.getLoader();
+ TransactionalGraphEngine dbEngine = httpEntry.getDbEngine();
- Pair<Boolean, List<Pair<URI, Response>>> responsesTuple = httpEntry.process(dbRequestList, "JUNIT");
- Response response = responsesTuple.getValue1().get(0).getValue1();
+ String uri = "/cloud-infrastructure/pservers/pserver/junit-test2";
+ String content = "{\"hostname\":\"junit-test2\"}";
+ Response response = getResponse(httpEntry, loader, dbEngine, HttpMethod.PUT, uri, content);
dbEngine.commit();
assertEquals("Expected the pserver to be created", 201, response.getStatus());
}
@Test
- public void test2GetOnPserver() throws UnsupportedEncodingException, AAIException {
-
+ public void test3PutOnPInterface() {
+ try {
DBConnectionType type = DBConnectionType.REALTIME;
HttpEntry httpEntry = new HttpEntry(Version.getLatest(), ModelType.MOXY, QueryStyle.TRAVERSAL, type);
Loader loader = httpEntry.getLoader();
TransactionalGraphEngine dbEngine = httpEntry.getDbEngine();
- URI uriObject = UriBuilder.fromPath("/cloud-infrastructure/pservers/pserver/junit-test1").build();
+ String uri = "/cloud-infrastructure/pservers/pserver/junit-test1/p-interfaces/p-interface/p1";
+ String content = "{\"interface-name\":\"p1\"}";
+ Response response = getResponse(httpEntry, loader, dbEngine, HttpMethod.PUT, uri, content);
+ dbEngine.commit();
+ assertEquals("Expected the p-interface to be created", 201, response.getStatus());
+ } catch (UnsupportedEncodingException | AAIException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
- QueryParser uriQuery = dbEngine.getQueryBuilder().createQueryFromURI(uriObject);
- String content = "";
- Introspector obj = loader.introspectorFromName("pserver");
+ @Test
+ public void test4GetOnPserver() throws UnsupportedEncodingException, AAIException {
- DBRequest dbRequest =
- new DBRequest.Builder(HttpMethod.GET, uriObject, uriQuery, obj, httpHeaders, uriInfo, "JUNIT-TRANSACTION")
- .rawRequestContent(content).build();
+ DBConnectionType type = DBConnectionType.REALTIME;
+ HttpEntry httpEntry = new HttpEntry(Version.getLatest(), ModelType.MOXY, QueryStyle.TRAVERSAL, type);
+ Loader loader = httpEntry.getLoader();
+ TransactionalGraphEngine dbEngine = httpEntry.getDbEngine();
- List<DBRequest> dbRequestList = new ArrayList<>();
- dbRequestList.add(dbRequest);
+ URI uriObject = UriBuilder.fromPath("/cloud-infrastructure/pservers/pserver/junit-test1").build();
- Pair<Boolean, List<Pair<URI, Response>>> responsesTuple = httpEntry.process(dbRequestList, "JUNIT");
- Response response = responsesTuple.getValue1().get(0).getValue1();
+ String uri = "/cloud-infrastructure/pservers/pserver/junit-test1";
+ String content = "{\"hostname\":\"junit-test1\", \"equip-type\":\"junit-equip-type\"}";
+ Response response = getResponse(httpEntry, loader, dbEngine, HttpMethod.GET, uri, content);
dbEngine.commit();
assertEquals("Expected the pserver to be returned", 200, response.getStatus());
}
@Test
- public void test3MergePatchOnPserver() throws UnsupportedEncodingException, AAIException {
+ public void test5MergePatchOnPserver() throws UnsupportedEncodingException, AAIException {
DBConnectionType type = DBConnectionType.REALTIME;
HttpEntry httpEntry = new HttpEntry(Version.getLatest(), ModelType.MOXY, QueryStyle.TRAVERSAL, type);
Loader loader = httpEntry.getLoader();
TransactionalGraphEngine dbEngine = httpEntry.getDbEngine();
- URI uriObject = UriBuilder.fromPath("/cloud-infrastructure/pservers/pserver/junit-test1").build();
-
- QueryParser uriQuery = dbEngine.getQueryBuilder().createQueryFromURI(uriObject);
-
+ String uri = "/cloud-infrastructure/pservers/pserver/junit-test1";
String content = "{\"hostname\":\"junit-test1\", \"equip-type\":\"junit-equip-type\"}";
-
- Introspector obj = loader.unmarshal("pserver", content, org.onap.aai.restcore.MediaType.getEnum("application/json"));
-
- DBRequest dbRequest =
- new DBRequest.Builder(HttpMethod.MERGE_PATCH, uriObject, uriQuery, obj, httpHeaders, uriInfo, "JUNIT-TRANSACTION")
- .rawRequestContent(content).build();
-
- List<DBRequest> dbRequestList = new ArrayList<>();
- dbRequestList.add(dbRequest);
-
- Pair<Boolean, List<Pair<URI, Response>>> responsesTuple = httpEntry.process(dbRequestList, "JUNIT");
- Response response = responsesTuple.getValue1().get(0).getValue1();
+ Response response = getResponse(httpEntry, loader, dbEngine, HttpMethod.MERGE_PATCH, uri, content);
dbEngine.commit();
assertEquals("Expected the pserver to be updated", 200, response.getStatus());
}
- private int doDelete(String resourceVersion) throws UnsupportedEncodingException, AAIException {
+ private int doDelete(String resourceVersion, String uri, String nodeType) throws UnsupportedEncodingException, AAIException {
queryParameters.add("resource-version", resourceVersion);
DBConnectionType type = DBConnectionType.REALTIME;
HttpEntry httpEntry = new HttpEntry(Version.getLatest(), ModelType.MOXY, QueryStyle.TRAVERSAL, type);
Loader loader = httpEntry.getLoader();
TransactionalGraphEngine dbEngine = httpEntry.getDbEngine();
- URI uriObject = UriBuilder.fromPath("/cloud-infrastructure/pservers/pserver/junit-test1").build();
+ URI uriObject = UriBuilder.fromPath(uri).build();
QueryParser uriQuery = dbEngine.getQueryBuilder().createQueryFromURI(uriObject);
String content = "";
- Introspector obj = loader.introspectorFromName("pserver");
+ Introspector obj = loader.introspectorFromName(nodeType);
DBRequest dbRequest =
new DBRequest.Builder(HttpMethod.DELETE, uriObject, uriQuery, obj, httpHeaders, uriInfo, "JUNIT-TRANSACTION")
@@ -232,7 +254,8 @@ public class HttpEntryTest extends AAISetup {
}
@Test
- public void test4DeleteOnPserver() throws UnsupportedEncodingException, AAIException {
+ public void test6DeleteOnPserver() throws UnsupportedEncodingException, AAIException {
+
DBConnectionType type = DBConnectionType.REALTIME;
HttpEntry httpEntry = new HttpEntry(Version.getLatest(), ModelType.MOXY, QueryStyle.TRAVERSAL, type);
@@ -240,22 +263,31 @@ public class HttpEntryTest extends AAISetup {
TransactionalGraphEngine dbEngine = httpEntry.getDbEngine();
URI uriObject = UriBuilder.fromPath("/cloud-infrastructure/pservers/pserver/junit-test1").build();
-
- QueryParser uriQuery = dbEngine.getQueryBuilder().createQueryFromURI(uriObject);
-
+ String uri = "/cloud-infrastructure/pservers/pserver/junit-test1";
String content = "";
+ Response response = getResponse(httpEntry, loader, dbEngine, HttpMethod.GET, uri, content);
+ dbEngine.commit();
+ String msg = response.getEntity().toString();
+ JsonObject jsonObj = new JsonParser().parse(msg).getAsJsonObject();
+ String resourceVersion = "";
+ if ( jsonObj.isJsonObject()) {
+ resourceVersion = jsonObj.get("resource-version").getAsString();
+ }
+ assertEquals("Expected the pserver to be deleted", 204, doDelete(resourceVersion, "/cloud-infrastructure/pservers/pserver/junit-test1", "pserver"));
+ }
- Introspector obj = loader.introspectorFromName("pserver");
-
- DBRequest dbRequest =
- new DBRequest.Builder(HttpMethod.GET, uriObject, uriQuery, obj, httpHeaders, uriInfo, "JUNIT-TRANSACTION")
- .rawRequestContent(content).build();
+ @Test
+ public void test7DeleteOnPserverNoPinterface() throws UnsupportedEncodingException, AAIException {
- List<DBRequest> dbRequestList = new ArrayList<>();
- dbRequestList.add(dbRequest);
+
+ DBConnectionType type = DBConnectionType.REALTIME;
+ HttpEntry httpEntry = new HttpEntry(Version.getLatest(), ModelType.MOXY, QueryStyle.TRAVERSAL, type);
+ Loader loader = httpEntry.getLoader();
+ TransactionalGraphEngine dbEngine = httpEntry.getDbEngine();
- Pair<Boolean, List<Pair<URI, Response>>> responsesTuple = httpEntry.process(dbRequestList, "JUNIT");
- Response response = responsesTuple.getValue1().get(0).getValue1();
+ String uri = "/cloud-infrastructure/pservers/pserver/junit-test2";
+ String content = "";
+ Response response = getResponse(httpEntry, loader, dbEngine, HttpMethod.GET, uri, content);
dbEngine.commit();
String msg = response.getEntity().toString();
JsonObject jsonObj = new JsonParser().parse(msg).getAsJsonObject();
@@ -263,36 +295,79 @@ public class HttpEntryTest extends AAISetup {
if ( jsonObj.isJsonObject()) {
resourceVersion = jsonObj.get("resource-version").getAsString();
}
- assertEquals("Expected the pserver to be deleted", 204, doDelete(resourceVersion));
+ assertEquals("Expected the pserver to be deleted", 204, doDelete(resourceVersion, "/cloud-infrastructure/pservers/pserver/junit-test2", "pserver"));
}
+
@Test
- public void test5FailedGetOnPserver() throws UnsupportedEncodingException, AAIException {
+ public void test8FailedGetOnPserver() throws UnsupportedEncodingException, AAIException {
DBConnectionType type = DBConnectionType.REALTIME;
HttpEntry httpEntry = new HttpEntry(Version.getLatest(), ModelType.MOXY, QueryStyle.TRAVERSAL, type);
Loader loader = httpEntry.getLoader();
TransactionalGraphEngine dbEngine = httpEntry.getDbEngine();
- URI uriObject = UriBuilder.fromPath("/cloud-infrastructure/pservers/pserver/junit-test2").build();
+ String uri = "/cloud-infrastructure/pservers/pserver/junit-test2";
+ String content = "";
+ Response response = getResponse(httpEntry, loader, dbEngine, HttpMethod.GET, uri, content);
+ dbEngine.commit();
- QueryParser uriQuery = dbEngine.getQueryBuilder().createQueryFromURI(uriObject);
+ assertEquals("Expected the pserver to be deleted", 404, response.getStatus());
+ }
- String content = "";
+ @Test
+ public void putEdgeTest() throws UnsupportedEncodingException, AAIException {
- Introspector obj = loader.introspectorFromName("pserver");
+ DBConnectionType type = DBConnectionType.REALTIME;
+ HttpEntry httpEntry = new HttpEntry(Version.getLatest(), ModelType.MOXY, QueryStyle.TRAVERSAL, type);
+ Loader loader = httpEntry.getLoader();
+ TransactionalGraphEngine dbEngine = httpEntry.getDbEngine();
- DBRequest dbRequest =
- new DBRequest.Builder(HttpMethod.GET, uriObject, uriQuery, obj, httpHeaders, uriInfo, "JUNIT-TRANSACTION")
- .rawRequestContent(content).build();
+ //Put pserver
+ String uri = "/cloud-infrastructure/pservers/pserver/junit-edge-test-pserver";
+ String content = "{\"hostname\":\"junit-edge-test-pserver\"}";
+ getResponse(httpEntry, loader, dbEngine, HttpMethod.PUT, uri, content);
+ //Put complex
+ uri = "/cloud-infrastructure/complexes/complex/junit-edge-test-complex";
+ content = "{\"physical-location-id\":\"junit-edge-test-complex\",\"physical-location-type\":\"AAIDefault\",\"street1\":\"AAIDefault\",\"city\":\"AAIDefault\",\"state\":\"NJ\",\"postal-code\":\"07748\",\"country\":\"USA\",\"region\":\"US\"}";
+ getResponse(httpEntry, loader, dbEngine, HttpMethod.PUT, uri, content);
+
+ //PutEdge
+ uri = "/cloud-infrastructure/complexes/complex/junit-edge-test-complex/relationship-list/relationship";
+ content = "{\"related-to\":\"pserver\",\"related-link\":\"/aai/" + Version.getLatest().toString() + "/cloud-infrastructure/pservers/pserver/junit-edge-test-pserver\",\"relationship-label\":\"org.onap.relationships.inventory.LocatedIn\"}";
+ Response response = getResponse(httpEntry, loader, dbEngine, HttpMethod.PUT_EDGE, uri, content);
+
+ dbEngine.rollback();
+ //System.out.println(response.getEntity().toString());
+ assertEquals("Expected the pserver to be created", 200, response.getStatus());
+ }
- List<DBRequest> dbRequestList = new ArrayList<>();
- dbRequestList.add(dbRequest);
+ @Test
+ public void putEdgeWrongLabelTest() throws UnsupportedEncodingException, AAIException {
- Pair<Boolean, List<Pair<URI, Response>>> responsesTuple = httpEntry.process(dbRequestList, "JUNIT");
- Response response = responsesTuple.getValue1().get(0).getValue1();
- dbEngine.commit();
+ DBConnectionType type = DBConnectionType.REALTIME;
+ HttpEntry httpEntry = new HttpEntry(Version.getLatest(), ModelType.MOXY, QueryStyle.TRAVERSAL, type);
+ Loader loader = httpEntry.getLoader();
+ TransactionalGraphEngine dbEngine = httpEntry.getDbEngine();
- assertEquals("Expected the pserver to be deleted", 404, response.getStatus());
+ //Put pserver
+ String uri = "/cloud-infrastructure/pservers/pserver/junit-edge-test-pserver";
+ String content = "{\"hostname\":\"junit-edge-test-pserver\"}";
+ getResponse(httpEntry, loader, dbEngine, HttpMethod.PUT, uri, content);
+ //Put complex
+ uri = "/cloud-infrastructure/complexes/complex/junit-edge-test-complex";
+ content = "{\"physical-location-id\":\"junit-edge-test-complex\",\"physical-location-type\":\"AAIDefault\",\"street1\":\"AAIDefault\",\"city\":\"AAIDefault\",\"state\":\"NJ\",\"postal-code\":\"07748\",\"country\":\"USA\",\"region\":\"US\"}";
+ getResponse(httpEntry, loader, dbEngine, HttpMethod.PUT, uri, content);
+
+ //PutEdge
+ uri = "/cloud-infrastructure/complexes/complex/junit-edge-test-complex/relationship-list/relationship";
+ content = "{\"related-to\":\"pserver\",\"related-link\":\"/aai/" + Version.getLatest().toString() + "/cloud-infrastructure/pservers/pserver/junit-edge-test-pserver\",\"relationship-label\":\"junk\"}";
+ Response response = getResponse(httpEntry, loader, dbEngine, HttpMethod.PUT_EDGE, uri, content);
+
+ dbEngine.rollback();
+ String msg = response.getEntity().toString();
+ assertEquals("Expected the pserver to be created", 400, response.getStatus());
+ assertTrue(msg.contains("ERR.5.4.6107"));
+ assertTrue(msg.contains("Required Edge-property not found in input data:no COUSIN edge rule between complex and pserver with label junk"));
}
}
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 5fade2ed..b124e5dd 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
@@ -1,28 +1,27 @@
-/*-
+/**
* ============LICENSE_START=======================================================
* org.onap.aai
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017 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
- *
+ *
+ * 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=========================================================
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
*/
-
package org.onap.aai.serialization.db;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.*;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
@@ -30,10 +29,7 @@ import java.io.UnsupportedEncodingException;
import java.lang.reflect.Field;
import java.net.URI;
import java.net.URISyntaxException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
+import java.util.*;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
import org.apache.tinkerpop.gremlin.structure.Edge;
@@ -41,10 +37,7 @@ import org.apache.tinkerpop.gremlin.structure.Graph;
import org.apache.tinkerpop.gremlin.structure.T;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
+import org.junit.*;
import org.junit.rules.ExpectedException;
import org.onap.aai.AAISetup;
import org.onap.aai.db.props.AAIProperties;
@@ -69,7 +62,7 @@ public class DbSerializerTest extends AAISetup {
@Rule
public ExpectedException thrown = ExpectedException.none();
- protected Graph graph;
+ protected static Graph graph;
protected final EdgeRules rules = EdgeRules.getInstance();
private final Version version = Version.getLatest();
@@ -82,22 +75,27 @@ public class DbSerializerTest extends AAISetup {
private DBSerializer dbser;
TransactionalGraphEngine spy;
TransactionalGraphEngine.Admin adminSpy;
-
+
+ @BeforeClass
+ public static void init() throws Exception {
+ graph = TitanFactory.build().set("storage.backend", "inmemory").open();
+ createGraph();
+
+ }
+
@Before
public void setup() throws Exception {
- graph = TitanFactory.build().set("storage.backend", "inmemory").open();
loader = LoaderFactory.createLoaderForVersion(introspectorFactoryType, version);
dbEngine = new TitanDBEngine(queryStyle, type, loader);
spy = spy(dbEngine);
adminSpy = spy(dbEngine.asAdmin());
-
- createGraph();
+
engine = new TitanDBEngine(queryStyle, type, loader);
dbser = new DBSerializer(version, engine, introspectorFactoryType, "AAI-TEST");
}
- public void createGraph() throws AAIException {
+ public static void createGraph() throws AAIException {
/*
* This setus up the test graph, For future junits , add more vertices
* and edges
@@ -115,19 +113,63 @@ public class DbSerializerTest extends AAISetup {
.next();
GraphTraversalSource g = graph.traversal();
- rules.addEdge(g, l3interipv4addresslist_1, subnet_2);
- rules.addEdge(g, l3interipv6addresslist_3, subnet_4);
- rules.addTreeEdge(g, subnet_5, l3network_6);
+ EdgeRules.getInstance().addEdge(g, l3interipv4addresslist_1, subnet_2);
+ EdgeRules.getInstance().addEdge(g, l3interipv6addresslist_3, subnet_4);
+ EdgeRules.getInstance().addTreeEdge(g, subnet_5, l3network_6);
+ }
+
+ @Test
+ public void testFindDeletableDoesNotReturnDuplicates() throws AAIException {
+ EdgeRules testRules = EdgeRules.getInstance("/dbedgerules/DbEdgeRules_test.json");
+
+ Vertex genericVnf1 = graph.addVertex("aai-node-type", "generic-vnf", "vnf-id", "vnf1", "vnf-name", "vnfName1");
+
+ Vertex lInterface1 = graph.addVertex("aai-node-type", "l-interface", "interface-name", "lInterface1");
+ Vertex lInterface2 = graph.addVertex("aai-node-type", "l-interface", "interface-name", "lInterface2");
+
+ Vertex logicalLink1 = graph.addVertex("aai-node-type", "logical-link", "link-name", "logicalLink1");
+ Vertex logicalLink2 = graph.addVertex("aai-node-type", "logical-link", "link-name", "logicalLink2");
+
+ GraphTraversalSource g = graph.traversal();
+
+ testRules.addTreeEdge(g, genericVnf1, lInterface1);
+ testRules.addTreeEdge(g, genericVnf1, lInterface2);
+ testRules.addEdge(g, lInterface1, logicalLink1);
+ testRules.addEdge(g, lInterface1, logicalLink2);
+ // This line will cause the logical link2 to be found twice under linterface 1
+ // and also under the linterface 2 and since in the past deletable returned
+ // duplicates this test checks that it shouldn't return duplicates
+ testRules.addEdge(g, lInterface2, logicalLink2);
+
+ when(spy.asAdmin()).thenReturn(adminSpy);
+ when(adminSpy.getTraversalSource()).thenReturn(g);
+ when(adminSpy.getReadOnlyTraversalSource()).thenReturn(g);
+
+ List<Vertex> deletableVertexes = spy.getQueryEngine().findDeletable(genericVnf1);
+ Set<Vertex> vertexSet = new HashSet<>();
+
+ for (Vertex deletableVertex : deletableVertexes) {
+ if(!vertexSet.contains(deletableVertex)){
+ vertexSet.add(deletableVertex);
+ } else {
+ fail("Find deletable is returning a list of duplicate vertexes");
+ }
+ }
}
@After
public void tearDown() throws Exception {
+ engine.rollback();
+ }
+
+ @AfterClass
+ public static void destroy() throws Exception {
graph.close();
}
@Test
- public void subnetDelwithInEdgesIpv4Test() throws AAIException {
+ public void subnetDelWithInEdgesIpv4Test() throws AAIException {
String expected_message = "Object is being reference by additional objects preventing it from being deleted. Please clean up references from the following types [l3-interface-ipv4-address-list]";
/*
@@ -141,7 +183,7 @@ public class DbSerializerTest extends AAISetup {
}
@Test
- public void subnetDelwithInEdgesIpv6Test() throws AAIException {
+ public void subnetDelWithInEdgesIpv6Test() throws AAIException {
String expected_message = "Object is being reference by additional objects preventing it from being deleted. Please clean up references from the following types [l3-interface-ipv6-address-list]";
/*
@@ -154,7 +196,7 @@ public class DbSerializerTest extends AAISetup {
}
@Test
- public void subnetDelwithInEdgesL3network() throws AAIException {
+ public void subnetDelWithInEdgesL3network() throws AAIException {
String expected_message = "";
/*
@@ -169,7 +211,6 @@ public class DbSerializerTest extends AAISetup {
public String testDelete(Vertex v) throws AAIException {
- // Graph g_tx = graph.newTransaction();
GraphTraversalSource traversal = graph.traversal();
when(spy.asAdmin()).thenReturn(adminSpy);
when(adminSpy.getTraversalSource()).thenReturn(traversal);
@@ -181,7 +222,6 @@ public class DbSerializerTest extends AAISetup {
serializer.delete(v, "resourceVersion", false);
} catch (AAIException exception) {
exceptionMessage = exception.getMessage();
-
}
return exceptionMessage;
@@ -197,7 +237,7 @@ public class DbSerializerTest extends AAISetup {
Vertex fromGraph = engine.tx().traversal().V().has("aai-node-type","generic-vnf").toList().get(0);
assertEquals(testVertex.id(), fromGraph.id());
assertEquals("AAI-TEST", fromGraph.property(AAIProperties.SOURCE_OF_TRUTH.toString()).value());
- engine.rollback();
+
}
@Test
@@ -205,22 +245,38 @@ public class DbSerializerTest extends AAISetup {
engine.startTransaction();
DBSerializer dbser2 = new DBSerializer(Version.getLatest(), engine, introspectorFactoryType, "AAI-TEST-2");
- Graph graph = TinkerGraph.open();
Vertex vert = graph.addVertex("aai-node-type", "generic-vnf");
dbser.touchStandardVertexProperties(vert, true);
- String resverStart = (String)vert.property(AAIProperties.RESOURCE_VERSION.toString()).value();
- String lastModTimeStart = (String)vert.property(AAIProperties.LAST_MOD_TS.toString()).value();
+ String resverStart = (String)vert.property(AAIProperties.RESOURCE_VERSION).value();
+ String lastModTimeStart = (String)vert.property(AAIProperties.LAST_MOD_TS).value();
Thread.sleep(10); //bc the resource version is set based on current time in milliseconds,
//if this test runs through too fast the value may not change
//causing the test to fail. sleeping ensures a different value
dbser2.touchStandardVertexProperties(vert, false);
- assertFalse(resverStart.equals((String)vert.property(AAIProperties.RESOURCE_VERSION.toString()).value()));
- assertFalse(lastModTimeStart.equals((String)vert.property(AAIProperties.LAST_MOD_TS.toString()).value()));
- assertEquals("AAI-TEST-2", (String)vert.property(AAIProperties.LAST_MOD_SOURCE_OF_TRUTH.toString()).value());
- engine.rollback();
+ assertFalse(resverStart.equals(vert.property(AAIProperties.RESOURCE_VERSION).value()));
+ assertFalse(lastModTimeStart.equals(vert.property(AAIProperties.LAST_MOD_TS).value()));
+ assertEquals("AAI-TEST-2", vert.property(AAIProperties.LAST_MOD_SOURCE_OF_TRUTH).value());
+
+ }
+
+ @Test
+ public void touchStandardVertexPropertiesAAIUUIDTest() throws AAIException, InterruptedException {
+ engine.startTransaction();
+
+ Graph graph = TinkerGraph.open();
+ Vertex v = graph.addVertex("aai-node-type", "generic-vnf");
+
+ dbser.touchStandardVertexProperties(v, true);
+
+ assertTrue(v.property(AAIProperties.AAI_UUID).isPresent());
+ try {
+ UUID.fromString((String)v.property(AAIProperties.AAI_UUID).value());
+ } catch (IllegalArgumentException e) {
+ fail("Vertex uuid is not valid uuid");
+ }
}
@Test
@@ -228,7 +284,7 @@ public class DbSerializerTest extends AAISetup {
engine.startTransaction();
assertTrue(dbser.verifyResourceVersion("delete", "vnfc", "abc", "abc", "vnfcs/vnfc/vnfcId"));
- engine.rollback();
+
}
@Test
@@ -237,11 +293,8 @@ public class DbSerializerTest extends AAISetup {
thrown.expect(AAIException.class);
thrown.expectMessage("resource-version passed for create of generic-vnfs/generic-vnf/myid");
- try {
- dbser.verifyResourceVersion("create", "generic-vnf", null, "old-res-ver", "generic-vnfs/generic-vnf/myid");
- } finally {
- engine.rollback();
- }
+ dbser.verifyResourceVersion("create", "generic-vnf", null, "old-res-ver", "generic-vnfs/generic-vnf/myid");
+
}
@Test
@@ -250,11 +303,8 @@ public class DbSerializerTest extends AAISetup {
thrown.expect(AAIException.class);
thrown.expectMessage("resource-version not passed for update of generic-vnfs/generic-vnf/myid");
- try {
- dbser.verifyResourceVersion("update", "generic-vnf", "current-res-ver", null, "generic-vnfs/generic-vnf/myid");
- } finally {
- engine.rollback();
- }
+ dbser.verifyResourceVersion("update", "generic-vnf", "current-res-ver", null, "generic-vnfs/generic-vnf/myid");
+
}
@Test
@@ -263,11 +313,8 @@ public class DbSerializerTest extends AAISetup {
thrown.expect(AAIException.class);
thrown.expectMessage("resource-version MISMATCH for update of generic-vnfs/generic-vnf/myid");
- try {
- dbser.verifyResourceVersion("update", "generic-vnf", "current-res-ver", "old-res-ver", "generic-vnfs/generic-vnf/myid");
- } finally {
- engine.rollback();
- }
+ dbser.verifyResourceVersion("update", "generic-vnf", "current-res-ver", "old-res-ver", "generic-vnfs/generic-vnf/myid");
+
}
@Test
@@ -291,7 +338,7 @@ public class DbSerializerTest extends AAISetup {
cr.property("aai-node-type").remove();
URI compareFailure = new URI("/unknown-uri");
assertEquals(compareFailure, dbser.getURIForVertex(ten));
- engine.rollback();
+
}
@Test
@@ -304,7 +351,7 @@ public class DbSerializerTest extends AAISetup {
assertEquals("cloud-region", crIntro.getDbName());
assertEquals("me", crIntro.getValue("cloud-owner"));
assertEquals("123", crIntro.getValue("cloud-region-id"));
- engine.rollback();
+
}
@Test
@@ -334,7 +381,7 @@ public class DbSerializerTest extends AAISetup {
(String)ten.property(AAIProperties.AAI_URI.toString()).value());
assertEquals("/cloud-infrastructure/cloud-regions/cloud-region/me/123/tenants/tenant/453/vservers/vserver/vs1",
(String)vs.property(AAIProperties.AAI_URI.toString()).value());
- engine.rollback();
+
}
@Test
@@ -347,8 +394,8 @@ public class DbSerializerTest extends AAISetup {
rules.addTreeEdge(engine.tx().traversal(), cr, ten);
Edge e = dbser.getEdgeBetween(EdgeType.TREE, ten, cr, null);
- assertEquals("has", e.label());
- engine.rollback();
+ assertEquals("org.onap.relationships.inventory.BelongsTo", e.label());
+
}
@Test
@@ -372,7 +419,7 @@ public class DbSerializerTest extends AAISetup {
assertFalse(engine.tx().traversal().V(gvnf).both("uses").hasNext());
assertFalse(engine.tx().traversal().V(vnfc).both("uses").hasNext());
- engine.rollback();
+
}
@Test
@@ -392,11 +439,11 @@ public class DbSerializerTest extends AAISetup {
relationship.setValue("relationship-data",relData);
assertTrue(dbser.createEdge(relationship, gvnf));
- assertTrue(engine.tx().traversal().V(gvnf).both("uses").hasNext());
- assertTrue(engine.tx().traversal().V(vnfc).both("uses").hasNext());
- engine.rollback();
+ assertTrue(engine.tx().traversal().V(gvnf).both("org.onap.relationships.inventory.BelongsTo").hasNext());
+ assertTrue(engine.tx().traversal().V(vnfc).both("org.onap.relationships.inventory.BelongsTo").hasNext());
+
}
-
+
@Test
public void createCousinEdgeThatShouldBeTreeTest() throws AAIException, UnsupportedEncodingException, URISyntaxException {
engine.startTransaction();
@@ -405,31 +452,27 @@ public class DbSerializerTest extends AAISetup {
Vertex vf = engine.tx().addVertex("aai-node-type","vf-module","vf-module-id","vf-id");
EdgeRules.getInstance().addTreeEdge(engine.tx().traversal(), gvnf, vf);
-
+
Introspector relationship = loader.introspectorFromName("relationship");
relationship.setValue("related-to", "vf-module");
relationship.setValue("related-link", dbser.getURIForVertex(vf).toString());
- //relationship.setValue("relationship-label", "");
Introspector relationshipList = loader.introspectorFromName("relationship-list");
relationshipList.setValue("relationship", Collections.singletonList(relationship.getUnderlyingObject()));
-
+
Introspector gvnfObj = loader.introspectorFromName("generic-vnf");
Vertex gvnf2 = dbser.createNewVertex(gvnfObj);
gvnfObj.setValue("relationship-list", relationshipList.getUnderlyingObject());
gvnfObj.setValue("vnf-id", "myvnf-1");
QueryParser uriQuery = dbEngine.getQueryBuilder().createQueryFromURI(new URI("/network/generic-vnfs/generic-vnf/myvnf-1"));
-
+
try {
dbser.serializeToDb(gvnfObj, gvnf2, uriQuery, null, "test");
} catch (AAIException e) {
assertEquals("AAI_6145", e.getCode());
- }
- finally {
- engine.rollback();
}
}
-
+
@Test
public void createEdgeNodeDoesNotExistExceptionTest() throws AAIException, UnsupportedEncodingException {
engine.startTransaction();
@@ -447,11 +490,8 @@ public class DbSerializerTest extends AAISetup {
thrown.expect(AAIException.class);
thrown.expectMessage("Node of type vnfc. Could not find object at: /network/vnfcs/vnfc/b-name");
- try {
- dbser.createEdge(relationship, gvnf);
- } finally {
- engine.rollback();
- }
+ dbser.createEdge(relationship, gvnf);
+
}
@Test
@@ -464,7 +504,7 @@ public class DbSerializerTest extends AAISetup {
gvnf.setValue("vnf-id", "myvnf");
dbser.serializeSingleVertex(gvnfVert, gvnf, "test");
assertTrue(engine.tx().traversal().V().has("aai-node-type","generic-vnf").has("vnf-id","myvnf").hasNext());
- engine.rollback();
+
}
@Test
@@ -483,10 +523,10 @@ public class DbSerializerTest extends AAISetup {
dbser.serializeSingleVertex(ten, tenIn, "test");
assertTrue(engine.tx().traversal().V().has("aai-node-type","tenant").has("tenant-id","453").has("tenant-name","mytenant").hasNext());
- engine.rollback();
+
}
-
-
+
+
@Test
public void getVertexPropertiesRelationshipHasLabelTest() throws AAIException, UnsupportedEncodingException {
engine.startTransaction();
@@ -495,15 +535,21 @@ public class DbSerializerTest extends AAISetup {
Vertex vnfc = engine.tx().addVertex("aai-node-type","vnfc","vnfc-name","vnfc-123");
EdgeRules rules = EdgeRules.getInstance();
rules.addEdge(engine.tx().traversal(), gvnf, vnfc);
-
+
Introspector obj = loader.introspectorFromName("generic-vnf");
obj = this.dbser.dbToObject(Arrays.asList(gvnf), obj, AAIProperties.MAXIMUM_DEPTH, false, "false");
-
- assertEquals("edge label between generic-vnf and vnfs is uses", "uses", obj.getWrappedValue("relationship-list").getWrappedListValue("relationship").get(0).getValue("relationship-label"));
-
- engine.rollback();
+
+ assertEquals("edge label between generic-vnf and vnfs is uses",
+ "org.onap.relationships.inventory.BelongsTo",
+ obj.getWrappedValue("relationship-list")
+ .getWrappedListValue("relationship")
+ .get(0)
+ .getValue("relationship-label")
+ );
+
+
}
-
+
@Test
public void getVertexPropertiesRelationshipOldVersionNoEdgeLabelTest() throws AAIException, UnsupportedEncodingException {
@@ -512,7 +558,7 @@ public class DbSerializerTest extends AAISetup {
Loader loader = LoaderFactory.createLoaderForVersion(introspectorFactoryType, version);
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");
EdgeRules rules = EdgeRules.getInstance();
@@ -520,19 +566,19 @@ public class DbSerializerTest extends AAISetup {
Introspector obj = loader.introspectorFromName("generic-vnf");
obj = dbser.dbToObject(Arrays.asList(gvnf), obj, AAIProperties.MAXIMUM_DEPTH, false, "false");
-
+
assertEquals("Relationship does not contain edge-property", false, obj.getWrappedValue("relationship-list").getWrappedListValue("relationship").get(0).hasProperty("relationship-label"));
-
- engine.rollback();
+
+
}
-
+
@Test
public void createEdgeWithValidLabelTest() throws AAIException, UnsupportedEncodingException, NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
-
+
EdgeRules ers = EdgeRules.getInstance("/dbedgerules/DbEdgeRules_test.json");
-
+
DBSerializer localDbser = getDBSerializerWithSpecificEdgeRules(ers);
-
+
engine.startTransaction();
Vertex gvnf = engine.tx().addVertex("aai-node-type","generic-vnf","vnf-id","myvnf");
@@ -547,16 +593,16 @@ public class DbSerializerTest extends AAISetup {
relationship.setValue("related-link", "/network/vnfcs/vnfc/a-name");
relationship.setValue("relationship-data",relData);
relationship.setValue("relationship-label", "over-uses");
-
+
assertTrue(localDbser.createEdge(relationship, gvnf));
assertTrue(engine.tx().traversal().V(gvnf).both("over-uses").hasNext());
assertTrue(engine.tx().traversal().V(vnfc).both("over-uses").hasNext());
- engine.rollback();
+
}
-
+
@Test
public void createEdgeWithInvalidLabelTest() throws AAIException, UnsupportedEncodingException, NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
-
+
engine.startTransaction();
Vertex gvnf = engine.tx().addVertex("aai-node-type","generic-vnf","vnf-id","myvnf");
@@ -573,20 +619,17 @@ public class DbSerializerTest extends AAISetup {
thrown.expect(AAIException.class);
thrown.expectMessage("no COUSIN edge rule between generic-vnf and vnfc with label NA");
- try {
- dbser.createEdge(relationship, gvnf);
- } finally {
- engine.rollback();
- }
+ dbser.createEdge(relationship, gvnf);
+
}
-
+
@Test
public void createEdgeWithValidLabelWhenSameEdgeExistsTest() throws AAIException, UnsupportedEncodingException, NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
-
+
EdgeRules ers = EdgeRules.getInstance("/dbedgerules/DbEdgeRules_test.json");
-
+
DBSerializer localDbser = getDBSerializerWithSpecificEdgeRules(ers);
-
+
engine.startTransaction();
Vertex gvnf = engine.tx().addVertex("aai-node-type","generic-vnf","vnf-id","myvnf");
@@ -601,20 +644,20 @@ public class DbSerializerTest extends AAISetup {
relationship.setValue("related-link", "/network/vnfcs/vnfc/a-name");
relationship.setValue("relationship-data",relData);
relationship.setValue("relationship-label", "re-uses");
-
+
assertTrue(localDbser.createEdge(relationship, gvnf));
assertTrue(engine.tx().traversal().V(gvnf).both("re-uses").hasNext());
assertTrue(engine.tx().traversal().V(vnfc).both("re-uses").hasNext());
assertEquals("Number of edges between vertexes is 1", Long.valueOf(1), engine.tx().traversal().V(vnfc).both().count().next());
- engine.rollback();
+
}
-
+
@Test
public void createEdgeWithValidLabelWhenDiffEdgeExistsTest() throws AAIException, UnsupportedEncodingException, NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
-
+
EdgeRules ers = EdgeRules.getInstance("/dbedgerules/DbEdgeRules_test.json");
DBSerializer localDbser = getDBSerializerWithSpecificEdgeRules(ers);
-
+
engine.startTransaction();
Vertex gvnf = engine.tx().addVertex("aai-node-type","generic-vnf","vnf-id","myvnf");
@@ -630,9 +673,9 @@ public class DbSerializerTest extends AAISetup {
relationship.setValue("relationship-data",relData);
relationship.setValue("relationship-label", "uses");
localDbser.createEdge(relationship, gvnf);
-
+
relationship.setValue("relationship-label", "re-uses");
-
+
assertTrue(localDbser.createEdge(relationship, gvnf));
assertTrue(engine.tx().traversal().V(gvnf).both("re-uses").hasNext());
assertTrue(engine.tx().traversal().V(vnfc).both("re-uses").hasNext());
@@ -640,15 +683,15 @@ public class DbSerializerTest extends AAISetup {
assertTrue(engine.tx().traversal().V(vnfc).both("uses").hasNext());
assertEquals("Number of edges between vertexes is 2", Long.valueOf(2), engine.tx().traversal().V(vnfc).both().count().next());
assertEquals("Number of edges between vertexes is 2", Long.valueOf(2), engine.tx().traversal().V(gvnf).both().count().next());
- engine.rollback();
+
}
-
+
@Test
public void createEdgeWithNoLabelTest() throws AAIException, UnsupportedEncodingException, NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
-
+
EdgeRules ers = EdgeRules.getInstance("/dbedgerules/DbEdgeRules_test.json");
DBSerializer localDbser = getDBSerializerWithSpecificEdgeRules(ers);
-
+
engine.startTransaction();
Vertex gvnf = engine.tx().addVertex("aai-node-type","generic-vnf","vnf-id","myvnf");
@@ -662,23 +705,23 @@ public class DbSerializerTest extends AAISetup {
relationship.setValue("related-link", "/network/vnfcs/vnfc/a-name");
relationship.setValue("relationship-data",relData);
localDbser.createEdge(relationship, gvnf);
-
+
assertTrue(localDbser.createEdge(relationship, gvnf));
assertTrue(engine.tx().traversal().V(gvnf).both("uses").hasNext());
assertTrue(engine.tx().traversal().V(vnfc).both("uses").hasNext());
assertEquals("Number of edges between vertexes is 1", Long.valueOf(1), engine.tx().traversal().V(vnfc).both().count().next());
assertEquals("Number of edges between vertexes is 1", Long.valueOf(1), engine.tx().traversal().V(gvnf).both().count().next());
- engine.rollback();
+
}
-
+
@Test
public void deleteEdgeWithNoLabelWhenMultipleExistsTest() throws AAIException, UnsupportedEncodingException, NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
-
+
EdgeRules ers = EdgeRules.getInstance("/dbedgerules/DbEdgeRules_test.json");
-
+
DBSerializer localDbser = getDBSerializerWithSpecificEdgeRules(ers);
-
+
engine.startTransaction();
Vertex gvnf = engine.tx().addVertex("aai-node-type","generic-vnf","vnf-id","myvnf");
@@ -694,7 +737,7 @@ public class DbSerializerTest extends AAISetup {
relationship.setValue("related-to", "vnfc");
relationship.setValue("related-link", "/network/vnfcs/vnfc/a-name");
relationship.setValue("relationship-data",relData);
-
+
assertTrue(localDbser.deleteEdge(relationship, gvnf));
assertFalse("generic-vnf has no edge uses", engine.tx().traversal().V(gvnf).both("uses").hasNext());
assertFalse("vnfc has no edge uses", engine.tx().traversal().V(vnfc).both("uses").hasNext());
@@ -704,15 +747,15 @@ public class DbSerializerTest extends AAISetup {
assertTrue("vnfc has edge re-uses", engine.tx().traversal().V(vnfc).both("over-uses").hasNext());
assertEquals("Number of edges between vertexes is 2", Long.valueOf(2), engine.tx().traversal().V(vnfc).both().count().next());
assertEquals("Number of edges between vertexes is 2", Long.valueOf(2), engine.tx().traversal().V(gvnf).both().count().next());
- engine.rollback();
+
}
-
+
@Test
public void deleteEdgeWithValidLabelWhenMultipleExistsTest() throws AAIException, UnsupportedEncodingException, NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
-
+
EdgeRules ers = EdgeRules.getInstance("/dbedgerules/DbEdgeRules_test.json");
DBSerializer localDbser = getDBSerializerWithSpecificEdgeRules(ers);
-
+
engine.startTransaction();
Vertex gvnf = engine.tx().addVertex("aai-node-type","generic-vnf","vnf-id","myvnf");
@@ -729,7 +772,7 @@ public class DbSerializerTest extends AAISetup {
relationship.setValue("related-link", "/network/vnfcs/vnfc/a-name");
relationship.setValue("relationship-data",relData);
relationship.setValue("relationship-label", "re-uses");
-
+
assertTrue(localDbser.deleteEdge(relationship, gvnf));
assertTrue("generic-vnf has edge uses", engine.tx().traversal().V(gvnf).both("uses").hasNext());
assertTrue("vnfc has edge uses", engine.tx().traversal().V(vnfc).both("uses").hasNext());
@@ -739,15 +782,15 @@ public class DbSerializerTest extends AAISetup {
assertTrue("vnfc has edge re-uses", engine.tx().traversal().V(vnfc).both("over-uses").hasNext());
assertEquals("Number of edges between vertexes is 2", Long.valueOf(2), engine.tx().traversal().V(vnfc).both().count().next());
assertEquals("Number of edges between vertexes is 2", Long.valueOf(2), engine.tx().traversal().V(gvnf).both().count().next());
- engine.rollback();
+
}
-
+
@Test
public void deleteEdgeWithValidInvalidLabelWhenMultipleExistsTest() throws AAIException, UnsupportedEncodingException, NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
-
+
EdgeRules ers = EdgeRules.getInstance("/dbedgerules/DbEdgeRules_test.json");
DBSerializer localDbser = getDBSerializerWithSpecificEdgeRules(ers);
-
+
engine.startTransaction();
Vertex gvnf = engine.tx().addVertex("aai-node-type","generic-vnf","vnf-id","myvnf");
@@ -764,24 +807,20 @@ public class DbSerializerTest extends AAISetup {
relationship.setValue("related-link", "/network/vnfcs/vnfc/a-name");
relationship.setValue("relationship-data",relData);
relationship.setValue("relationship-label", "NA");
-
+
thrown.expect(AAIException.class);
thrown.expectMessage("no COUSIN edge rule between generic-vnf and vnfc with label NA");
- try {
- localDbser.deleteEdge(relationship, gvnf);
- } finally {
- engine.rollback();
- }
+ localDbser.deleteEdge(relationship, gvnf);
}
-
+
@Test
public void serializeToDbWithLabelTest() throws AAIException, UnsupportedEncodingException, NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException, URISyntaxException {
-
+
EdgeRules ers = EdgeRules.getInstance("/dbedgerules/DbEdgeRules_test.json");
DBSerializer localDbser = getDBSerializerWithSpecificEdgeRules(ers);
-
+
engine.startTransaction();
-
+
engine.tx().addVertex("aai-node-type","vnfc","vnfc-name","a-name");
Introspector relationship = loader.introspectorFromName("relationship");
@@ -790,16 +829,16 @@ public class DbSerializerTest extends AAISetup {
relationship.setValue("relationship-label", "re-uses");
Introspector relationshipList = loader.introspectorFromName("relationship-list");
relationshipList.setValue("relationship", Collections.singletonList(relationship.getUnderlyingObject()));
-
+
Introspector gvnfObj = loader.introspectorFromName("generic-vnf");
Vertex gvnf = localDbser.createNewVertex(gvnfObj);
gvnfObj.setValue("relationship-list", relationshipList.getUnderlyingObject());
gvnfObj.setValue("vnf-id", "myvnf");
QueryParser uriQuery = dbEngine.getQueryBuilder().createQueryFromURI(new URI("/network/generic-vnfs/generic-vnf/myvnf"));
-
+
localDbser.serializeToDb(gvnfObj, gvnf, uriQuery, null, "test");
-
+
assertTrue("vertex with vnf-id myvnf exists", engine.tx().traversal().V().has("vnf-id", "myvnf").hasNext());
assertTrue("vertex with vnfc-name a-name exists", engine.tx().traversal().V().has("vnfc-name", "a-name").hasNext());
assertFalse("generic-vnf has no edge re-uses", engine.tx().traversal().V().has("vnf-id", "myvnf").both("uses").hasNext());
@@ -810,17 +849,17 @@ public class DbSerializerTest extends AAISetup {
assertFalse("vnfc has no edge re-uses", engine.tx().traversal().V().has("vnfc-name", "a-name").both("over-uses").hasNext());
assertEquals("Number of edges between vertexes is 1", Long.valueOf(1), engine.tx().traversal().V().has("vnfc-name", "a-name").both().count().next());
assertEquals("Number of edges between vertexes is 1", Long.valueOf(1), engine.tx().traversal().V().has("vnf-id", "myvnf").both().count().next());
- engine.rollback();
+
}
-
+
@Test
public void serializeToDbWithoutLabelTest() throws AAIException, UnsupportedEncodingException, NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException, URISyntaxException {
-
+
EdgeRules ers = EdgeRules.getInstance("/dbedgerules/DbEdgeRules_test.json");
DBSerializer localDbser = getDBSerializerWithSpecificEdgeRules(ers);
-
+
engine.startTransaction();
-
+
engine.tx().addVertex("aai-node-type","vnfc","vnfc-name","a-name");
Introspector relationship = loader.introspectorFromName("relationship");
@@ -829,16 +868,16 @@ public class DbSerializerTest extends AAISetup {
Introspector relationshipList = loader.introspectorFromName("relationship-list");
relationshipList.setValue("relationship", Collections.singletonList(relationship.getUnderlyingObject()));
-
+
Introspector gvnfObj = loader.introspectorFromName("generic-vnf");
Vertex gvnf = localDbser.createNewVertex(gvnfObj);
gvnfObj.setValue("relationship-list", relationshipList.getUnderlyingObject());
gvnfObj.setValue("vnf-id", "myvnf");
QueryParser uriQuery = dbEngine.getQueryBuilder().createQueryFromURI(new URI("/network/generic-vnfs/generic-vnf/myvnf"));
-
+
localDbser.serializeToDb(gvnfObj, gvnf, uriQuery, null, "test");
-
+
assertTrue("vertex with vnf-id myvnf exists", engine.tx().traversal().V().has("vnf-id", "myvnf").hasNext());
assertTrue("vertex with vnfc-name a-name exists", engine.tx().traversal().V().has("vnfc-name", "a-name").hasNext());
assertTrue("generic-vnf has edge uses", engine.tx().traversal().V().has("vnf-id", "myvnf").both("uses").hasNext());
@@ -849,17 +888,17 @@ public class DbSerializerTest extends AAISetup {
assertFalse("vnfc has no edge over-uses", engine.tx().traversal().V().has("vnfc-name", "a-name").both("over-uses").hasNext());
assertEquals("Number of edges between vertexes is 1", Long.valueOf(1), engine.tx().traversal().V().has("vnfc-name", "a-name").both().count().next());
assertEquals("Number of edges between vertexes is 1", Long.valueOf(1), engine.tx().traversal().V().has("vnf-id", "myvnf").both().count().next());
- engine.rollback();
+
}
-
+
@Test
public void serializeToDbWithInvalidLabelTest() throws AAIException, UnsupportedEncodingException, NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException, URISyntaxException {
-
+
EdgeRules ers = EdgeRules.getInstance("/dbedgerules/DbEdgeRules_test.json");
DBSerializer localDbser = getDBSerializerWithSpecificEdgeRules(ers);
-
+
engine.startTransaction();
-
+
engine.tx().addVertex("aai-node-type","vnfc","vnfc-name","a-name");
Introspector relationship = loader.introspectorFromName("relationship");
@@ -868,33 +907,29 @@ public class DbSerializerTest extends AAISetup {
relationship.setValue("relationship-label", "NA");
Introspector relationshipList = loader.introspectorFromName("relationship-list");
relationshipList.setValue("relationship", Collections.singletonList(relationship.getUnderlyingObject()));
-
+
Introspector gvnfObj = loader.introspectorFromName("generic-vnf");
Vertex gvnf = localDbser.createNewVertex(gvnfObj);
gvnfObj.setValue("relationship-list", relationshipList.getUnderlyingObject());
gvnfObj.setValue("vnf-id", "myvnf");
QueryParser uriQuery = dbEngine.getQueryBuilder().createQueryFromURI(new URI("/network/generic-vnfs/generic-vnf/myvnf"));
-
+
thrown.expect(AAIException.class);
thrown.expectMessage("No EdgeRule found for passed nodeTypes: generic-vnf, vnfc with label NA.");
- try {
- localDbser.serializeToDb(gvnfObj, gvnf, uriQuery, null, "test");
- } finally {
- engine.rollback();
- }
- engine.rollback();
+ localDbser.serializeToDb(gvnfObj, gvnf, uriQuery, null, "test");
+
}
-
+
@Test
public void serializeToDbWithLabelAndEdgeExistsTest() throws AAIException, UnsupportedEncodingException, NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException, URISyntaxException {
-
+
EdgeRules ers = EdgeRules.getInstance("/dbedgerules/DbEdgeRules_test.json");
DBSerializer localDbser = getDBSerializerWithSpecificEdgeRules(ers);
-
+
engine.startTransaction();
engine.tx().addVertex("aai-node-type","vnfc","vnfc-name","a-name");
-
+
Introspector relationship;
Introspector relationshipList;
List<Object> relList = new ArrayList<>();
@@ -905,7 +940,7 @@ public class DbSerializerTest extends AAISetup {
gvnfObj.setValue("vnf-id", "myvnf");
QueryParser uriQuery = dbEngine.getQueryBuilder().createQueryFromURI(new URI("/network/generic-vnfs/generic-vnf/myvnf"));
- // create relationship to vnfc
+ // create relationship to vnfc
relationship = loader.introspectorFromName("relationship");
relationship.setValue("related-to", "vnfc");
relationship.setValue("related-link", "/network/vnfcs/vnfc/a-name");
@@ -913,10 +948,10 @@ public class DbSerializerTest extends AAISetup {
relationshipList = loader.introspectorFromName("relationship-list");
relationshipList.setValue("relationship", relList);
gvnfObj.setValue("relationship-list", relationshipList.getUnderlyingObject());
-
+
// add gvnf to graph
localDbser.serializeToDb(gvnfObj, gvnf, uriQuery, null, "test");
-
+
// add second relationship
relationship = loader.introspectorFromName("relationship");
relationship.setValue("related-to", "vnfc");
@@ -926,9 +961,9 @@ public class DbSerializerTest extends AAISetup {
relationshipList = loader.introspectorFromName("relationship-list");
relationshipList.setValue("relationship", relList);
gvnfObj.setValue("relationship-list", relationshipList.getUnderlyingObject());
-
+
localDbser.serializeToDb(gvnfObj, gvnf, uriQuery, null, "test");
-
+
assertTrue("vertex with vnf-id myvnf exists", engine.tx().traversal().V().has("vnf-id", "myvnf").hasNext());
assertTrue("vertex with vnfc-name a-name exists", engine.tx().traversal().V().has("vnfc-name", "a-name").hasNext());
assertTrue("generic-vnf has edge uses", engine.tx().traversal().V().has("vnf-id", "myvnf").both("uses").hasNext());
@@ -939,18 +974,18 @@ public class DbSerializerTest extends AAISetup {
assertFalse("vnfc has no edge over-uses", engine.tx().traversal().V().has("vnfc-name", "a-name").both("over-uses").hasNext());
assertEquals("Number of edges between vertexes is 2", Long.valueOf(2), engine.tx().traversal().V().has("vnfc-name", "a-name").both().count().next());
assertEquals("Number of edges between vertexes is 2", Long.valueOf(2), engine.tx().traversal().V().has("vnf-id", "myvnf").both().count().next());
- engine.rollback();
+
}
-
+
@Test
public void serializeToDbWithLabelDroppingRelationshipTest() throws AAIException, UnsupportedEncodingException, NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException, URISyntaxException {
-
+
EdgeRules ers = EdgeRules.getInstance("/dbedgerules/DbEdgeRules_test.json");
DBSerializer localDbser = getDBSerializerWithSpecificEdgeRules(ers);
-
+
engine.startTransaction();
engine.tx().addVertex("aai-node-type","vnfc","vnfc-name","a-name");
-
+
Introspector relationship;
Introspector relationshipList;
List<Object> relList = new ArrayList<>();
@@ -961,7 +996,7 @@ public class DbSerializerTest extends AAISetup {
gvnfObj.setValue("vnf-id", "myvnf");
QueryParser uriQuery = dbEngine.getQueryBuilder().createQueryFromURI(new URI("/network/generic-vnfs/generic-vnf/myvnf"));
- // create relationship to vnfc
+ // create relationship to vnfc
relationship = loader.introspectorFromName("relationship");
relationship.setValue("related-to", "vnfc");
relationship.setValue("related-link", "/network/vnfcs/vnfc/a-name");
@@ -975,18 +1010,18 @@ public class DbSerializerTest extends AAISetup {
relationshipList = loader.introspectorFromName("relationship-list");
relationshipList.setValue("relationship", relList);
gvnfObj.setValue("relationship-list", relationshipList.getUnderlyingObject());
-
+
// add gvnf to graph
localDbser.serializeToDb(gvnfObj, gvnf, uriQuery, null, "test");
-
+
// drop second relationship
relList.remove(1);
relationshipList = loader.introspectorFromName("relationship-list");
relationshipList.setValue("relationship", relList);
gvnfObj.setValue("relationship-list", relationshipList.getUnderlyingObject());
-
+
localDbser.serializeToDb(gvnfObj, gvnf, uriQuery, null, "test");
-
+
assertTrue("vertex with vnf-id myvnf exists", engine.tx().traversal().V().has("vnf-id", "myvnf").hasNext());
assertTrue("vertex with vnfc-name a-name exists", engine.tx().traversal().V().has("vnfc-name", "a-name").hasNext());
assertTrue("generic-vnf has edge uses", engine.tx().traversal().V().has("vnf-id", "myvnf").both("uses").hasNext());
@@ -997,7 +1032,7 @@ public class DbSerializerTest extends AAISetup {
assertFalse("vnfc has no edge over-uses", engine.tx().traversal().V().has("vnfc-name", "a-name").both("over-uses").hasNext());
assertEquals("Number of edges between vertexes is 1", Long.valueOf(1), engine.tx().traversal().V().has("vnfc-name", "a-name").both().count().next());
assertEquals("Number of edges between vertexes is 1", Long.valueOf(1), engine.tx().traversal().V().has("vnf-id", "myvnf").both().count().next());
- engine.rollback();
+
}
private DBSerializer getDBSerializerWithSpecificEdgeRules(EdgeRules ers)
@@ -1016,9 +1051,9 @@ public class DbSerializerTest extends AAISetup {
Introspector gv = loader.introspectorFromName("generic-vnf");
gv.setValue("vnf-name", "myname");
Introspector rel = loader.introspectorFromName("relationship");
- DBSerializer dbser = new DBSerializer(Version.v11, dbEngine,
+ DBSerializer dbser = new DBSerializer(Version.v11, dbEngine,
ModelType.MOXY, "AAI-TEST");
-
+
dbser.addRelatedToProperty(rel, gv);
List<Introspector> relToProps = rel.getWrappedListValue("related-to-property");
assertTrue(relToProps.size() == 1);
@@ -1026,40 +1061,40 @@ public class DbSerializerTest extends AAISetup {
assertTrue("generic-vnf.vnf-name".equals(relToProp.getValue("property-key")));
assertTrue("myname".equals(relToProp.getValue("property-value")));
}
-
+
@Test
public void dbToObjectContainerMismatchTest() throws AAIException, UnsupportedEncodingException {
- DBSerializer dbser = new DBSerializer(Version.v11, dbEngine,
+ DBSerializer dbser = new DBSerializer(Version.v11, dbEngine,
ModelType.MOXY, "AAI-TEST");
-
+
Graph vertexMaker = TinkerGraph.open();
Vertex a = vertexMaker.addVertex(T.id, "0");
Vertex b = vertexMaker.addVertex(T.id, "1");
List<Vertex> vertices = Arrays.asList(a,b);
-
+
Loader loader = LoaderFactory.createLoaderForVersion(ModelType.MOXY, Version.v11);
Introspector intro = loader.introspectorFromName("image"); //just need any non-container object
-
+
thrown.expect(AAIException.class);
thrown.expectMessage("query object mismatch: this object cannot hold multiple items.");
-
+
dbser.dbToObject(vertices, intro, Integer.MAX_VALUE, true, "doesn't matter");
}
-
+
@Test
public void dbToObjectTest() throws AAIException, UnsupportedEncodingException {
engine.startTransaction();
-
- DBSerializer dbser = new DBSerializer(Version.getLatest(), engine,
+
+ DBSerializer dbser = new DBSerializer(Version.getLatest(), engine,
ModelType.MOXY, "AAI-TEST");
-
+
Vertex gv1 = engine.tx().addVertex("aai-node-type", "generic-vnf", "vnf-id", "id1");
Vertex gv2 = engine.tx().addVertex("aai-node-type", "generic-vnf", "vnf-id", "id2");
List<Vertex> vertices = Arrays.asList(gv1, gv2);
-
+
Loader loader = LoaderFactory.createLoaderForVersion(ModelType.MOXY, Version.getLatest());
Introspector gvContainer = loader.introspectorFromName("generic-vnfs");
-
+
Introspector res = dbser.dbToObject(vertices, gvContainer, 0, true, "true");
List<Introspector> gvs = res.getWrappedListValue("generic-vnf");
assertTrue(gvs.size() == 2);
@@ -1067,75 +1102,75 @@ public class DbSerializerTest extends AAISetup {
String vnfId = i.getValue("vnf-id");
assertTrue("id1".equals(vnfId) || "id2".equals(vnfId));
}
-
- engine.rollback();
+
+
}
-
+
@Test
public void getEdgeBetweenNoLabelTest() throws AAIException {
- DBSerializer dbser = new DBSerializer(Version.getLatest(), engine,
+ DBSerializer dbser = new DBSerializer(Version.getLatest(), engine,
ModelType.MOXY, "AAI-TEST");
-
+
engine.startTransaction();
Vertex gv = engine.tx().addVertex("aai-node-type", "generic-vnf", "vnf-id", "id1");
Vertex lint = engine.tx().addVertex("aai-node-type", "l-interface", "interface-name", "name1");
rules.addTreeEdge(engine.tx().traversal(), gv, lint);
-
+
Edge res = dbser.getEdgeBetween(EdgeType.TREE, gv, lint);
- assertTrue("hasLInterface".equals(res.label()));
- engine.rollback();
+ assertEquals("org.onap.relationships.inventory.BelongsTo", res.label());
+
}
@Test
public void deleteItemsWithTraversal() throws AAIException {
- DBSerializer dbser = new DBSerializer(Version.getLatest(), engine,
+ DBSerializer dbser = new DBSerializer(Version.getLatest(), engine,
ModelType.MOXY, "AAI-TEST");
-
+
engine.startTransaction();
Vertex gv = engine.tx().addVertex("aai-node-type", "generic-vnf", "vnf-id", "id1");
Vertex lint = engine.tx().addVertex("aai-node-type", "l-interface", "interface-name", "name1");
-
+
assertTrue(engine.tx().traversal().V().has("vnf-id", "id1").hasNext());
assertTrue(engine.tx().traversal().V().has("interface-name", "name1").hasNext());
-
+
dbser.deleteItemsWithTraversal(Arrays.asList(gv, lint));
-
+
assertTrue(!engine.tx().traversal().V().has("vnf-id", "id1").hasNext());
assertTrue(!engine.tx().traversal().V().has("interface-name", "name1").hasNext());
-
- engine.rollback();
+
+
}
-
+
@Test
public void serializeToDbWithParentTest() throws AAIException, UnsupportedEncodingException, URISyntaxException {
- DBSerializer dbser = new DBSerializer(Version.getLatest(), engine,
+ DBSerializer dbser = new DBSerializer(Version.getLatest(), engine,
ModelType.MOXY, "AAI-TEST");
-
+
engine.startTransaction();
Vertex gv = engine.tx().addVertex("aai-node-type", "generic-vnf", "vnf-id", "id1");
Vertex lint = engine.tx().addVertex("aai-node-type", "l-interface", "interface-name", "name1");
rules.addTreeEdge(engine.tx().traversal(), gv, lint);
-
+
Introspector lintIntro = loader.introspectorFromName("l-interface");
lintIntro.setValue("interface-role", "actor");
URI lintURI = new URI("/network/generic-vnfs/generic-vnf/id1/l-interfaces/l-interface/name1");
QueryParser uriQuery = dbEngine.getQueryBuilder(gv).createQueryFromURI(lintURI);
dbser.serializeToDb(lintIntro, lint, uriQuery, "test-identifier", "AAI-TEST");
-
+
assertTrue(engine.tx().traversal().V(lint).has("interface-role", "actor").hasNext());
-
- engine.rollback();
+
+
}
-
+
@Test
public void getLatestVersionViewTest() throws AAIException, UnsupportedEncodingException {
- DBSerializer dbser = new DBSerializer(Version.getLatest(), engine,
+ DBSerializer dbser = new DBSerializer(Version.getLatest(), engine,
ModelType.MOXY, "AAI-TEST");
-
+
engine.startTransaction();
- Vertex phys = engine.tx().addVertex("aai-node-type", "physical-link", "link-name", "zaldo",
+ Vertex phys = engine.tx().addVertex("aai-node-type", "physical-link", "link-name", "zaldo",
"speed-value", "very-fast", "service-provider-bandwidth-up-units", "things");
-
+
Introspector res = dbser.getLatestVersionView(phys);
assertTrue("zaldo".equals(res.getValue("link-name")));
assertTrue("very-fast".equals(res.getValue("speed-value")));
diff --git a/aai-core/src/test/java/org/onap/aai/serialization/db/EdgeRulesTest.java b/aai-core/src/test/java/org/onap/aai/serialization/db/EdgeRulesTest.java
index bc6a721f..773b9cd2 100644
--- a/aai-core/src/test/java/org/onap/aai/serialization/db/EdgeRulesTest.java
+++ b/aai-core/src/test/java/org/onap/aai/serialization/db/EdgeRulesTest.java
@@ -22,9 +22,10 @@
package org.onap.aai.serialization.db;
-import org.apache.tinkerpop.gremlin.structure.Direction;
+import org.apache.tinkerpop.gremlin.structure.*;
import org.junit.Test;
import org.onap.aai.AAISetup;
+
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@@ -34,13 +35,11 @@ import java.util.Map;
import java.util.Set;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
-import org.apache.tinkerpop.gremlin.structure.Graph;
-import org.apache.tinkerpop.gremlin.structure.T;
-import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph;
import org.junit.Rule;
import org.junit.rules.ExpectedException;
+import org.onap.aai.db.props.AAIProperties;
import org.onap.aai.exceptions.AAIException;
import org.onap.aai.introspection.Version;
import org.onap.aai.serialization.db.exceptions.EdgeMultiplicityException;
@@ -61,7 +60,7 @@ public class EdgeRulesTest extends AAISetup {
EdgeRules rules = EdgeRules.getInstance();
EdgeRule rule = rules.getEdgeRule(EdgeType.TREE, "cloud-region", "flavor");
- assertEquals("out direction", rule.getDirection(), Direction.OUT);
+ assertEquals("out direction", rule.getDirection(), Direction.IN);
}
@Test
@@ -69,7 +68,7 @@ public class EdgeRulesTest extends AAISetup {
EdgeRules rules = EdgeRules.getInstance();
EdgeRule rule = rules.getEdgeRule(EdgeType.TREE, "flavor", "cloud-region");
- assertEquals("in direction", rule.getDirection(), Direction.IN);
+ assertEquals("in direction", rule.getDirection(), Direction.OUT);
}
@Test
@@ -77,7 +76,7 @@ public class EdgeRulesTest extends AAISetup {
EdgeRules rules = EdgeRules.getInstance();
EdgeRule rule = rules.getEdgeRule(EdgeType.COUSIN, "model-ver", "model-element");
- assertEquals("in direction", rule.getDirection(), Direction.IN);
+ assertEquals("in direction", Direction.IN, rule.getDirection());
}
@Test
@@ -85,21 +84,25 @@ public class EdgeRulesTest extends AAISetup {
EdgeRules rules = EdgeRules.getInstance();
EdgeRule rule = rules.getEdgeRule(EdgeType.COUSIN, "model-element", "model-ver");
- assertEquals("out direction", rule.getDirection(), Direction.OUT);
+ assertEquals("out direction", Direction.OUT, rule.getDirection());
}
@Test
public void verifyMultipleGet() throws AAIException {
EdgeRules rules = EdgeRules.getInstance();
Map<String, EdgeRule> ruleMap = rules.getEdgeRules("model-element", "model-ver");
- assertEquals("has isA rule", "isA", ruleMap.get("isA").getLabel());
- assertEquals("has startsWith rule", "startsWith", ruleMap.get("startsWith").getLabel());
+ assertEquals("has isA rule", "org.onap.relationships.inventory.IsA",
+ ruleMap.get("org.onap.relationships.inventory.IsA").getLabel());
+ assertEquals("has startsWith rule", "org.onap.relationships.inventory.BelongsTo",
+ ruleMap.get("org.onap.relationships.inventory.BelongsTo").getLabel());
}
@Test
public void verifyMultipleGetSingleRule() throws AAIException {
EdgeRules rules = EdgeRules.getInstance();
Map<String, EdgeRule> ruleMap = rules.getEdgeRules("availability-zone", "complex");
- assertEquals("has groupsResourcesIn rule", "groupsResourcesIn", ruleMap.get("groupsResourcesIn").getLabel());
+
+ assertEquals("has org.onap.relationships.inventory.LocatedIn rule", "org.onap.relationships.inventory.LocatedIn",
+ ruleMap.get("org.onap.relationships.inventory.LocatedIn").getLabel());
}
@Test
@@ -116,7 +119,7 @@ public class EdgeRulesTest extends AAISetup {
assertEquals("true: pserver | complex", true, EdgeRules.getInstance().hasEdgeRule("pserver", "complex"));
assertEquals("false: pserver | service", false, EdgeRules.getInstance().hasEdgeRule("pserver", "service"));
}
-
+
@Test
public void hasTreeEdgeRuleTest() {
assertEquals("true: cloud-region | tenant", true, EdgeRules.getInstance().hasTreeEdgeRule("cloud-region", "tenant"));
@@ -125,7 +128,7 @@ public class EdgeRulesTest extends AAISetup {
assertEquals("true: service-instance | allotted-resource", true, EdgeRules.getInstance().hasTreeEdgeRule("service-instance", "allotted-resource"));
}
-
+
@Test
public void hasCousinEdgeRuleTest() {
assertEquals("false: cloud-region | tenant", false, EdgeRules.getInstance().hasCousinEdgeRule("cloud-region", "tenant", null));
@@ -133,11 +136,11 @@ public class EdgeRulesTest extends AAISetup {
assertEquals("true: pserver | complex", true, EdgeRules.getInstance().hasCousinEdgeRule("pserver", "complex", null));
assertEquals("true: service-instance | allotted-resource", true, EdgeRules.getInstance().hasCousinEdgeRule("service-instance", "allotted-resource", null));
assertEquals("true: logical-link | l-interface", true, EdgeRules.getInstance().hasCousinEdgeRule("logical-link", "l-interface", null));
- assertEquals("true: logical-link | l-interface : sourceLInterface", true, EdgeRules.getInstance().hasCousinEdgeRule("logical-link", "l-interface", "sourceLInterface"));
- assertEquals("true: logical-link | l-interface : targetLInterface", true, EdgeRules.getInstance().hasCousinEdgeRule("logical-link", "l-interface", "targetLInterface"));
+ assertEquals("true: logical-link | l-interface : sourceLInterface", true, EdgeRules.getInstance().hasCousinEdgeRule("logical-link", "l-interface", "org.onap.relationships.inventory.Source"));
+ assertEquals("true: logical-link | l-interface : targetLInterface", true, EdgeRules.getInstance().hasCousinEdgeRule("logical-link", "l-interface", "org.onap.relationships.inventory.Destination"));
assertEquals("false: logical-link | l-interface : blah", false, EdgeRules.getInstance().hasCousinEdgeRule("logical-link", "l-interface", "blah"));
}
-
+
@Test
public void hasEdgeRuleVertexTest() {
Graph graph = TinkerGraph.open();
@@ -153,11 +156,11 @@ public class EdgeRulesTest extends AAISetup {
Vertex v2 = graph.addVertex("aai-node-type", "tenant");
EdgeRules rules = EdgeRules.getInstance();
EdgeRule rule = rules.getEdgeRule(EdgeType.TREE, v1, v2);
- assertEquals(true, "OUT".equalsIgnoreCase(rule.getContains()));
- assertEquals(true, "OUT".equalsIgnoreCase(rule.getDeleteOtherV()));
- assertEquals(true, MultiplicityRule.ONE2MANY.equals(rule.getMultiplicityRule()));
- assertEquals(true, "IN".equalsIgnoreCase(rule.getServiceInfrastructure()));
- assertEquals(true, "OUT".equalsIgnoreCase(rule.getPreventDelete()));
+ assertEquals(true, "IN".equalsIgnoreCase(rule.getContains()));
+ assertEquals(true, "NONE".equalsIgnoreCase(rule.getDeleteOtherV()));
+ assertEquals(true, MultiplicityRule.MANY2ONE.equals(rule.getMultiplicityRule()));
+ assertEquals(true, "OUT".equalsIgnoreCase(rule.getServiceInfrastructure()));
+ assertEquals(true, "IN".equalsIgnoreCase(rule.getPreventDelete()));
}
@Test
@@ -168,7 +171,7 @@ public class EdgeRulesTest extends AAISetup {
EdgeRules rules = EdgeRules.getInstance();
GraphTraversalSource g = graph.traversal();
rules.addTreeEdge(g, v1, v2);
- assertEquals(true, g.V(v1).out("has").has("aai-node-type", "tenant").hasNext());
+ assertEquals(true, g.V(v1).in("org.onap.relationships.inventory.BelongsTo").has("aai-node-type", "tenant").hasNext());
Vertex v3 = graph.addVertex(T.id, "2", "aai-node-type", "cloud-region");
assertEquals(null, rules.addTreeEdgeIfPossible(g, v3, v2));
@@ -182,7 +185,7 @@ public class EdgeRulesTest extends AAISetup {
EdgeRules rules = EdgeRules.getInstance(Version.getLatest());
GraphTraversalSource g = graph.traversal();
rules.addEdge(g, v1, v2);
- assertEquals(true, g.V(v2).out("hasFlavor").has("aai-node-type", "flavor").hasNext());
+ assertEquals(true, g.V(v2).out("org.onap.relationships.inventory.Uses").has("aai-node-type", "flavor").hasNext());
Vertex v3 = graph.addVertex(T.id, "2", "aai-node-type", "flavor");
assertEquals(null, rules.addEdgeIfPossible(g, v3, v2));
@@ -191,7 +194,7 @@ public class EdgeRulesTest extends AAISetup {
@Test
public void multiplicityViolationTest() throws AAIException {
thrown.expect(EdgeMultiplicityException.class);
- thrown.expectMessage("multiplicity rule violated: only one edge can exist with label: uses between vf-module and volume-group");
+ thrown.expectMessage("multiplicity rule violated: only one edge can exist with label: org.onap.relationships.inventory.Uses between vf-module and volume-group");
Graph graph = TinkerGraph.open();
Vertex v1 = graph.addVertex(T.id, "1", "aai-node-type", "vf-module");
@@ -225,7 +228,7 @@ public class EdgeRulesTest extends AAISetup {
public void getAllRulesTest() {
EdgeRules rules = EdgeRules.getInstance("/dbedgerules/DbEdgeRules_test.json");
Multimap<String, EdgeRule> allRules = rules.getAllRules();
- assertEquals(14, allRules.size());
+ assertEquals(16, allRules.size());
assertEquals(true, allRules.containsKey("foo|bar"));
assertEquals(true, allRules.containsKey("foo|bar"));
assertEquals(true, allRules.containsKey("quux|foo"));
@@ -263,6 +266,15 @@ public class EdgeRulesTest extends AAISetup {
// so if any required properties are missing, the verification builds
// will catch it and incorrect rules can't get merged in.
for (Version v : Version.values()) {
+ // NOt adding descriptions prior to v12
+ switch (v.toString()) {
+ case "v7":
+ case "v8":
+ case "v9":
+ case "v10":
+ case "v11":
+ continue;
+ }
EdgeRules rules = EdgeRules.getInstance(v);
rules.getAllRules();
}
@@ -277,23 +289,23 @@ public class EdgeRulesTest extends AAISetup {
@Test
public void verifyOutDirectionUsingLabel() throws AAIException, NoEdgeRuleFoundException {
EdgeRules rules = EdgeRules.getInstance();
- EdgeRule rule = rules.getEdgeRule(EdgeType.COUSIN, "generic-vnf", "l3-network", "usesL3Network");
+ EdgeRule rule = rules.getEdgeRule(EdgeType.COUSIN, "generic-vnf", "l3-network", "org.onap.relationships.inventory.Uses");
assertEquals("out direction", rule.getDirection(), Direction.OUT);
}
@Test
- public void verifyOutDirectionLinterfaceToLinterfaceUsingLabel() throws AAIException, NoEdgeRuleFoundException {
+ public void verifyInDirectionLinterfaceToLinterfaceUsingLabel() throws AAIException, NoEdgeRuleFoundException {
EdgeRules rules = EdgeRules.getInstance();
EdgeRule rule = rules.getEdgeRule(EdgeType.TREE, "l-interface", "l-interface");
- assertEquals("out direction", rule.getDirection(), Direction.OUT);
+ assertEquals("in direction", rule.getDirection(), Direction.IN);
}
@Test
public void verifyOutFlippedDirectionUsingLabel() throws AAIException, NoEdgeRuleFoundException {
EdgeRules rules = EdgeRules.getInstance();
- EdgeRule rule = rules.getEdgeRule(EdgeType.COUSIN, "l3-network", "generic-vnf", "usesL3Network");
+ EdgeRule rule = rules.getEdgeRule(EdgeType.COUSIN, "l3-network", "generic-vnf", "org.onap.relationships.inventory.Uses");
assertEquals("in direction", rule.getDirection(), Direction.IN);
}
@@ -348,4 +360,28 @@ public class EdgeRulesTest extends AAISetup {
Map<String, EdgeRule> edgeRules = rules.getEdgeRulesWithLabels(EdgeType.COUSIN, "generic-vnf", "vnfc", labels);
}
+ @Test
+ public void addEdgeVerifyAAIUUIDCousinTest() throws AAIException {
+ Graph graph = TinkerGraph.open();
+ Vertex v1 = graph.addVertex(T.id, "1", "aai-node-type", "flavor");
+ Vertex v2 = graph.addVertex(T.id, "10", "aai-node-type", "vserver");
+ EdgeRules rules = EdgeRules.getInstance(Version.getLatest());
+ GraphTraversalSource g = graph.traversal();
+ Edge e = rules.addEdge(g, v1, v2);
+ assertTrue(e.property(AAIProperties.AAI_UUID).isPresent());
+ //assertTrue(e.property(AAIProperties.AAI_UUID).value().toString().matches("^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$"));
+ }
+
+ @Test
+ public void addEdgeVerifyAAIUUIDTreeTest() throws AAIException {
+ Graph graph = TinkerGraph.open();
+ Vertex v1 = graph.addVertex(T.id, "1", "aai-node-type", "tenant");
+ Vertex v2 = graph.addVertex(T.id, "10", "aai-node-type", "vserver");
+ EdgeRules rules = EdgeRules.getInstance(Version.getLatest());
+ GraphTraversalSource g = graph.traversal();
+ Edge e = rules.addTreeEdge(g, v1, v2);
+ assertTrue(e.property(AAIProperties.AAI_UUID).isPresent());
+ //assertTrue(e.property(AAIProperties.AAI_UUID).value().toString().matches("^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$"));
+ }
+
}
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 4b4a0e64..55002a6f 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
@@ -19,7 +19,6 @@
*
* ECOMP is a trademark and service mark of AT&T Intellectual Property.
*/
-
package org.onap.aai.serialization.engines.query;
import static org.junit.Assert.*;
@@ -31,6 +30,8 @@ import java.util.Iterator;
import java.util.List;
import java.util.Set;
+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.process.traversal.step.util.Tree;
import org.apache.tinkerpop.gremlin.structure.Direction;
@@ -51,7 +52,7 @@ import org.onap.aai.introspection.Version;
import org.onap.aai.serialization.db.EdgeRules;
public class GraphTraversalQueryEngineTest extends AAISetup {
-
+
@Test
public void testFindParents() throws AAIException {
//setup
@@ -236,13 +237,13 @@ public class GraphTraversalQueryEngineTest extends AAISetup {
GraphTraversalQueryEngine engine = new GraphTraversalQueryEngine(g);
//test
- List<Vertex> outRes = engine.findRelatedVertices(gv, Direction.OUT, "hasLInterface", "l-interface");
+ 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, "usesLogicalLink", "l-interface");
+
+ 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, "usesLogicalLink", "logical-link");
+ List<Vertex> bothRes = engine.findRelatedVertices(lint, Direction.BOTH, "tosca.relationships.network.LinksTo", "logical-link");
assertTrue(bothRes.containsAll(bothExpected) && bothExpected.containsAll(bothRes));
}
diff --git a/aai-core/src/test/java/org/onap/aai/serialization/queryformats/ConsoleTest.java b/aai-core/src/test/java/org/onap/aai/serialization/queryformats/ConsoleTest.java
new file mode 100644
index 00000000..a60eaf90
--- /dev/null
+++ b/aai-core/src/test/java/org/onap/aai/serialization/queryformats/ConsoleTest.java
@@ -0,0 +1,83 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017 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=========================================================
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ */
+package org.onap.aai.serialization.queryformats;
+
+import static org.junit.Assert.*;
+import org.junit.Test;
+import org.onap.aai.serialization.queryformats.exceptions.AAIFormatVertexException;
+
+import com.google.gson.JsonObject;
+
+public class ConsoleTest {
+
+
+ Console fM1 = new Console();
+
+ String param = "abcd";
+
+ JsonObject resultVal;
+
+ @Test
+ public void classConsoleInstantiateCheck() {
+
+ try {
+ Console fm1 = new Console();
+ assertNotNull("Created class Object is null", fm1);
+ }
+ catch(Exception e) {
+ fail();
+ }
+ }
+
+ //Below method is expecting to throw an exception
+
+ @Test(expected=NullPointerException.class)
+ public void formatObjectParamNullCheck() throws AAIFormatVertexException {
+
+ param=null;
+ Console fm3 = new Console();
+ resultVal = fm3.formatObject(param);
+ }
+
+ @Test
+ public void formatObjectResultCheck() {
+
+ try {
+ Console fm2 = new Console();
+
+ resultVal = fm2.formatObject(param);
+ assertNotNull("The result is null", resultVal);
+
+ //System.out.println(resultVal);
+
+ JsonObject jsonObj = new JsonObject();
+ jsonObj.addProperty("result", "abcd");
+
+ assertEquals(jsonObj, resultVal);
+
+ }
+ catch (Exception e) {
+ fail();
+ }
+ }
+
+}
diff --git a/aai-core/src/test/java/org/onap/aai/serialization/queryformats/GraphSONTest.java b/aai-core/src/test/java/org/onap/aai/serialization/queryformats/GraphSONTest.java
new file mode 100644
index 00000000..8f418a43
--- /dev/null
+++ b/aai-core/src/test/java/org/onap/aai/serialization/queryformats/GraphSONTest.java
@@ -0,0 +1,80 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017 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=========================================================
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ */
+package org.onap.aai.serialization.queryformats;
+
+import org.apache.tinkerpop.gremlin.structure.Graph;
+import org.apache.tinkerpop.gremlin.structure.Vertex;
+import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph;
+import org.junit.*;
+import static org.junit.Assert.assertEquals;
+
+import com.google.gson.JsonArray;
+import com.google.gson.JsonObject;
+
+public class GraphSONTest {
+
+ private Graph graph;
+ private Vertex v1;
+
+ //private JsonObject jsonObj = new JsonParser().parse("{\"id\":0,\"label\":\"vertex\",\"properties\":{\"name\":[{\"id\":1,\"value\":\"Sam\"}]}}").getAsJsonObject();
+ private JsonObject jsonObj = new JsonObject() ;
+ private JsonObject properties = new JsonObject();
+ private JsonArray name = new JsonArray() ;
+ private JsonObject idVal = new JsonObject() ;
+
+ @Before
+ public void setUp() {
+
+ jsonObj.addProperty("id", 0);
+ jsonObj.addProperty("label", "vertex");
+
+ idVal.addProperty("id", 1);
+ idVal.addProperty("value", "Sam");
+
+ name.add(idVal);
+ properties.add("name",name);
+ jsonObj.add("properties", properties);
+
+ graph = TinkerGraph.open();
+ v1 = graph.addVertex("name", "Sam");
+
+ }
+
+ @Test
+ public void classGraphSONTestWithVertex(){
+
+ GraphSON graphSonObj1 = new GraphSON();
+ JsonObject obj = graphSonObj1.formatObject(v1);
+
+ assertEquals(jsonObj, obj);
+ }
+
+ @Test
+ public void parallelThresholdCehck(){
+
+ GraphSON graphSonObj2 = new GraphSON();
+ assertEquals(50, graphSonObj2.parallelThreshold());
+
+ }
+
+
+}
diff --git a/aai-core/src/test/java/org/onap/aai/serialization/queryformats/RawFormatTest.java b/aai-core/src/test/java/org/onap/aai/serialization/queryformats/RawFormatTest.java
index a33349fd..ae76467c 100644
--- a/aai-core/src/test/java/org/onap/aai/serialization/queryformats/RawFormatTest.java
+++ b/aai-core/src/test/java/org/onap/aai/serialization/queryformats/RawFormatTest.java
@@ -92,7 +92,7 @@ public class RawFormatTest extends AAISetup {
@Test
public void verifyPserverRelatedToHasEdgeLabel () throws AAIFormatVertexException, AAIException, AAIFormatQueryResultFormatNotSupported {
- assertTrue(rawFormat.createRelationshipObject(pserver).get(0).getAsJsonObject().get("relationship-label").getAsString().equals("locatedIn"));
+ assertTrue(rawFormat.createRelationshipObject(pserver).get(0).getAsJsonObject().get("relationship-label").getAsString().equals("org.onap.relationships.inventory.LocatedIn"));
}
@Test
@@ -102,7 +102,7 @@ public class RawFormatTest extends AAISetup {
@Test
public void verifyComplexRelatedToHasEdgeLabel () throws AAIFormatVertexException, AAIException, AAIFormatQueryResultFormatNotSupported {
- assertTrue(rawFormat.createRelationshipObject(complex).get(0).getAsJsonObject().get("relationship-label").getAsString().equals("locatedIn"));
+ assertTrue(rawFormat.createRelationshipObject(complex).get(0).getAsJsonObject().get("relationship-label").getAsString().equals("org.onap.relationships.inventory.LocatedIn"));
}
@Test
diff --git a/aai-core/src/test/java/org/onap/aai/serialization/queryformats/SimpleFormatTest.java b/aai-core/src/test/java/org/onap/aai/serialization/queryformats/SimpleFormatTest.java
index ec89aa30..fd3a8893 100644
--- a/aai-core/src/test/java/org/onap/aai/serialization/queryformats/SimpleFormatTest.java
+++ b/aai-core/src/test/java/org/onap/aai/serialization/queryformats/SimpleFormatTest.java
@@ -19,7 +19,6 @@
*
* ECOMP is a trademark and service mark of AT&T Intellectual Property.
*/
-
package org.onap.aai.serialization.queryformats;
import com.google.gson.JsonObject;
diff --git a/aai-core/src/test/java/org/onap/aai/util/AAICSVWriterTest.java b/aai-core/src/test/java/org/onap/aai/util/AAICSVWriterTest.java
new file mode 100644
index 00000000..b149e95f
--- /dev/null
+++ b/aai-core/src/test/java/org/onap/aai/util/AAICSVWriterTest.java
@@ -0,0 +1,77 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017 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=========================================================
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ */
+package org.onap.aai.util;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class AAICSVWriterTest {
+
+ private final String TEMP_DIR=System.getProperty("java.io.tmpdir")+"/test.csv";
+
+ @Test
+ public void writeFile() throws IOException
+ {
+
+
+ FileWriter fileWriter = new FileWriter(TEMP_DIR);
+ AAICSVWriter aaicsvWriter = new AAICSVWriter(fileWriter, ",", '\'', null);
+ aaicsvWriter.writeColumn(new String[]{"id", "name", null});
+ aaicsvWriter.writeColumn(null);
+ aaicsvWriter.writeNext(new String[]{"1", "Test1"}, true);
+ aaicsvWriter.writeNext(new String[]{"1", "Test1"});
+ aaicsvWriter.writeNext(new String[]{"1", "Test1"});
+ aaicsvWriter.writeNext(new String[]{"1", "Test@"}, false);
+ aaicsvWriter.writeNext(new String[]{"1", "Test1"});
+ aaicsvWriter.writeNext(new String[]{"1", "Test1"});
+ aaicsvWriter.writeNext(new String[]{"1", "Test1"});
+ aaicsvWriter.writeNext(new String[]{"1", "Test1"});
+ aaicsvWriter.writeNext(new String[]{"1", "Test1"});
+ aaicsvWriter.writeNext(new String[]{"1", null});
+ aaicsvWriter.writeNext(null);
+ aaicsvWriter.close();
+ File file = new File(TEMP_DIR);
+ Assert.assertTrue("File shoud be exists", file.exists());
+ }
+
+ @Test
+ public void writeFile1() throws IOException
+ {
+ FileWriter fileWriter = new FileWriter(TEMP_DIR);
+ AAICSVWriter aaicsvWriter = new AAICSVWriter(fileWriter, ",", '\u0000', null);
+ aaicsvWriter.writeNext(new String[]{"1", "Test1"}, true);
+ aaicsvWriter.writeNext(new String[]{"1", "Tes\"t@"}, false);
+ aaicsvWriter.writeNext(new String[]{"1", "Tes\t@"}, false);
+ aaicsvWriter.writeNext(new String[]{"1", "Test,@"}, false);
+ aaicsvWriter.writeNext(new String[]{"1", "Tes\n"}, false);
+ aaicsvWriter.writeNext(new String[]{"1", "Tes\r"}, false);
+ aaicsvWriter.writeNext(new String[]{"1", "Tes\u0000"}, false);
+ aaicsvWriter.close();
+ File file = new File(TEMP_DIR);
+ Assert.assertTrue("File shoud be exists", file.exists());
+
+ }
+}
diff --git a/aai-core/src/test/java/org/onap/aai/util/AAIConfigCommandLinePropGetterTest.java b/aai-core/src/test/java/org/onap/aai/util/AAIConfigCommandLinePropGetterTest.java
new file mode 100644
index 00000000..fcce479a
--- /dev/null
+++ b/aai-core/src/test/java/org/onap/aai/util/AAIConfigCommandLinePropGetterTest.java
@@ -0,0 +1,105 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017 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=========================================================
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ */
+package org.onap.aai.util;
+
+import static org.junit.Assert.assertEquals;
+
+import java.security.Permission;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.aai.AAISetup;
+
+public class AAIConfigCommandLinePropGetterTest extends AAISetup {
+
+ private SecurityManager m;
+ private TestSecurityManager sm;
+
+ @Before
+ public void setUp()
+ {
+ m = System.getSecurityManager();
+ sm = new TestSecurityManager();
+ System.setSecurityManager(sm);
+ }
+
+ @After
+ public void tearDown()
+ {
+ System.setSecurityManager(m);
+ }
+
+ @Test
+ public void testMainNoArgs() {
+ try {
+ AAIConfigCommandLinePropGetter.main(new String[] {});
+ } catch (SecurityException se) {
+ // assert main method ends with System.exit(0)
+ assertEquals("0", se.getMessage());
+ }
+ }
+
+ @Test
+ public void testMainReadProp() {
+ try {
+ AAIConfigCommandLinePropGetter.main(new String[] {"aai.primary.filetransfer.serverlist"});
+ } catch (SecurityException se) {
+ // assert main method ends with System.exit(0)
+ assertEquals("0", se.getMessage());
+ }
+ }
+
+ @Test
+ public void testMainOneArg() {
+ try {
+ AAIConfigCommandLinePropGetter.main(new String[] {"one"});
+ } catch (SecurityException se) {
+ // assert main method ends with System.exit(0)
+ assertEquals("0", se.getMessage());
+ }
+ }
+
+ @Test
+ public void testMainMoreThanOneArg() {
+ try {
+ AAIConfigCommandLinePropGetter.main(new String[] {"one", "two"});
+ } catch (SecurityException se) {
+ // assert main method ends with System.exit(0)
+ assertEquals("0", se.getMessage());
+ }
+ }
+}
+
+class TestSecurityManager extends SecurityManager {
+ @Override
+ public void checkPermission(Permission permission) {
+ if ("exitVM".equals(permission.getName()))
+ {
+ throw new SecurityException("System.exit attempted and blocked.");
+ }
+ }
+ @Override
+ public void checkExit(int status) {
+ throw new SecurityException(Integer.toString(status));
+ }
+}
diff --git a/aai-core/src/test/java/org/onap/aai/util/AAIRSyncUtilityTest.java b/aai-core/src/test/java/org/onap/aai/util/AAIRSyncUtilityTest.java
new file mode 100644
index 00000000..f5daf3b0
--- /dev/null
+++ b/aai-core/src/test/java/org/onap/aai/util/AAIRSyncUtilityTest.java
@@ -0,0 +1,55 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017 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=========================================================
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ */
+package org.onap.aai.util;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.onap.aai.AAISetup;
+
+public class AAIRSyncUtilityTest extends AAISetup {
+
+ private static AAIRSyncUtility syncUtility;
+
+ @BeforeClass
+ public static void setUp() throws Exception {
+ syncUtility = new AAIRSyncUtility();
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testDoCommandNullCommands() throws Exception {
+ syncUtility.doCommand(null);
+ }
+
+ @Test(expected = Exception.class)
+ public void testDoCommandEmptyCommands() throws Exception {
+ List<String> commands = new ArrayList<String>();
+ syncUtility.doCommand(commands);
+ }
+
+}
diff --git a/aai-core/src/test/java/org/onap/aai/util/FileWatcherTest.java b/aai-core/src/test/java/org/onap/aai/util/FileWatcherTest.java
new file mode 100644
index 00000000..bb754c0e
--- /dev/null
+++ b/aai-core/src/test/java/org/onap/aai/util/FileWatcherTest.java
@@ -0,0 +1,78 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017 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=========================================================
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ */
+package org.onap.aai.util;
+
+import static org.junit.Assert.*;
+
+import java.io.File;
+
+import org.junit.Test;
+import org.mockito.Mockito;
+
+public class FileWatcherTest {
+
+ class FileWatcherExtension extends FileWatcher {
+
+ public FileWatcherExtension(File file) {
+ super(file);
+ }
+
+ @Override
+ protected void onChange(File file) {
+ System.out.println("do nothing");
+ }
+ }
+
+ @Test
+ public void testFileWatcher() {
+ File file = new File("helloworld");
+ file.setLastModified(new Long(123));
+ FileWatcher fileWatcher = new FileWatcherExtension(file);
+ assertNotNull(fileWatcher);
+ file.deleteOnExit();
+ }
+
+ @Test(expected=NullPointerException.class)
+ public void testFileWatcher_nullConstructor() {
+ FileWatcher fileWatcher = new FileWatcherExtension(null);
+ assertNull(fileWatcher);
+ }
+
+ @Test
+ public void testRun() {
+ // verify that code is reachable outside of conditional check in run()
+ File file = new File("helloworld");
+ file.setLastModified(new Long(100));
+ FileWatcher fileWatcher = new FileWatcherExtension(file);
+ fileWatcher.run();
+ file.deleteOnExit();
+ }
+
+ @Test
+ public void testOnChange() throws Exception {
+ FileWatcher fileWatcher = Mockito.mock(FileWatcher.class, Mockito.CALLS_REAL_METHODS);
+
+ fileWatcher.onChange(Mockito.any(File.class));
+
+ Mockito.verify(fileWatcher).onChange(Mockito.any(File.class));
+ }
+}
diff --git a/aai-core/src/test/java/org/onap/aai/util/GenerateXsdTest.java b/aai-core/src/test/java/org/onap/aai/util/GenerateXsdTest.java
index 9a36680b..9e1e33a5 100644
--- a/aai-core/src/test/java/org/onap/aai/util/GenerateXsdTest.java
+++ b/aai-core/src/test/java/org/onap/aai/util/GenerateXsdTest.java
@@ -21,35 +21,271 @@
*/
package org.onap.aai.util;
-import org.junit.Test;
-import org.onap.aai.introspection.Version;
+import static org.junit.Assert.*;
-public class GenerateXsdTest {
+import java.io.StringReader;
+
+import javax.xml.XMLConstants;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
- @Test
- public void testGenerationOfXsdAndYaml() throws Exception {
+import org.hamcrest.CoreMatchers;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+import org.xml.sax.InputSource;
- GenerateXsd generateXsd = new GenerateXsd();
- System.setProperty("gen_version", Version.getLatest().toString());
- System.setProperty("gen_type", "XSD");
- System.setProperty("yamlresponses_url", "");
- System.setProperty("yamlresponses_label", "");
+import org.onap.aai.introspection.Version;
- generateXsd.main(new String[]{});
- System.setProperty("gen_version", Version.getLatest().toString());
- System.setProperty("gen_type", "YAML");
+public class GenerateXsdTest {
+ private static final int maxSizeForXml = 20000;
+ private String testXML;
+
+ @Before
+ public void setUp() throws Exception {
+ //PowerMockito.mockStatic(GenerateXsd.class);
+ StringBuilder sb = new StringBuilder(maxSizeForXml);
+ addNamespace(sb);
+ addRelationshipList(sb);
+ addRelationship(sb);
+ addRelatedToProperty(sb);
+ addRelationshipData(sb);
+ addBusiness(sb);
+ addCustomers(sb);
+ addCustomer(sb);
+ addServiceSubscriptions(sb);
+ addServiceSubscription(sb);
+ addEndOfXML(sb);
+ testXML = sb.toString();
+ }
+
+ private void addNamespace(StringBuilder sb){
+ sb.append("<xml-bindings xmlns=\"http://www.eclipse.org/eclipselink/xsds/persistence/oxm\" package-name=\"inventory.aai.onap.org.v11\" xml-mapping-metadata-complete=\"true\">\n");
+ sb.append("<xml-schema element-form-default=\"QUALIFIED\">\n");
+ sb.append("<xml-ns namespace-uri=\"http://org.onap.aai.inventory/v11\" />\n");
+ sb.append("</xml-schema>\n");
+ sb.append("<java-types>\n");
+ sb.append("<java-type name=\"Inventory\">\n");
+ sb.append("<xml-root-element name=\"inventory\" />\n");
+ sb.append("<java-attributes>\n");
+ sb.append("<xml-element java-attribute=\"business\" name=\"business\" type=\"inventory.aai.onap.org.v11.Business\" />\n");
+ sb.append("</java-attributes>\n");
+ sb.append("</java-type>\n");
+ }
+
+ private void addRelationshipList(StringBuilder sb ) {
+ sb.append("<java-type name=\"RelationshipList\">\n");
+ sb.append("<xml-root-element name=\"relationship-list\" />\n");
+ sb.append("<java-attributes>\n");
+ sb.append("<xml-element container-type=\"java.util.ArrayList\" java-attribute=\"relationship\" name=\"relationship\" type=\"inventory.aai.onap.org.v11.Relationship\" />/n");
+ sb.append("</java-attributes>\n");
+ sb.append("</java-type>\n");
+ }
+
+ private void addRelationship(StringBuilder sb ) {
+ sb.append("<java-type name=\"Relationship\">\n");
+ sb.append("<xml-root-element name=\"relationship\" />\n");
+ sb.append("<java-attributes>\n");
+ sb.append("<xml-element java-attribute=\"relatedTo\" name=\"related-to\" type=\"java.lang.String\">\n");
+ sb.append("<xml-properties>\n");
+ sb.append("<xml-property name=\"description\" value=\"A keyword provided by A&amp;AI to indicate type of node.\" />\n");
+ sb.append("</xml-properties>\n");
+ sb.append("</xml-element>\n");
+ sb.append("<xml-element java-attribute=\"relatedLink\" name=\"related-link\" type=\"java.lang.String\">\n");
+ sb.append("<xml-properties>\n");
+ sb.append("<xml-property name=\"description\" value=\"URL to the object in A&amp;AI.\" />");
+ sb.append("</xml-properties>\n");
+ sb.append("</xml-element>\n");
+ sb.append("<xml-element container-type=\"java.util.ArrayList\" java-attribute=\"relationshipData\" name=\"relationship-data\" type=\"inventory.aai.onap.org.v11.RelationshipData\" />\n");
+ sb.append("<xml-element container-type=\"java.util.ArrayList\" java-attribute=\"relatedToProperty\" name=\"related-to-property\" type=\"inventory.aai.onap.org.v11.RelatedToProperty\" />\n");
+ sb.append("</java-attributes>\n");
+ sb.append("</java-type>\n");
+ }
+
+ private void addRelatedToProperty(StringBuilder sb) {
+ sb.append("<java-type name=\"RelatedToProperty\">\n");
+ sb.append("<xml-root-element name=\"related-to-property\" />\n");
+ sb.append("<java-attributes>\n");
+ sb.append("<xml-element java-attribute=\"propertyKey\" name=\"property-key\" type=\"java.lang.String\">\n");
+ sb.append("<xml-properties>\n");
+ sb.append("<xml-property name=\"description\" value=\"Key part of a key/value pair\" />\n");
+ sb.append("</xml-properties>\n");
+ sb.append("</xml-element>\n");
+ sb.append("<xml-element java-attribute=\"propertyValue\" name=\"property-value\" type=\"java.lang.String\">\n");
+ sb.append("<xml-properties>\n");
+ sb.append("<xml-property name=\"description\" value=\"Value part of a key/value pair\" />\n");
+ sb.append("</xml-properties>\n");
+ sb.append("</xml-element>\n");
+ sb.append("</java-attributes>\n");
+ sb.append("</java-type>\n");
+ }
+
+ private void addRelationshipData(StringBuilder sb){
+ sb.append("<java-type name=\"RelationshipData\">\n");
+ sb.append("<xml-root-element name=\"relationship-data\" />\n");
+ sb.append("<java-attributes>\n");
+ sb.append("<xml-element java-attribute=\"relationshipKey\" name=\"relationship-key\" required=\"true\" type=\"java.lang.String\">\n");
+ sb.append("<xml-properties>\n");
+ sb.append("<xml-property name=\"description\" value=\"A keyword provided by A&amp;AI to indicate an attribute.\" />\n");
+ sb.append("</xml-properties>\n");
+ sb.append("</xml-element>\n");
+ sb.append("<xml-element java-attribute=\"relationshipValue\" name=\"relationship-value\" required=\"true\" type=\"java.lang.String\">\n");
+ sb.append("<xml-properties>\n");
+ sb.append("<xml-property name=\"description\" value=\"Value of the attribute.\" />\n");
+ sb.append("</xml-properties>\n");
+ sb.append("</xml-element>\n");
+ sb.append("</java-attributes>\n");
+ sb.append("</java-type>\n");
+ }
+
+ private void addBusiness(StringBuilder sb){
+ sb.append("<java-type name=\"Business\">\n");
+ sb.append("<xml-properties>\n");
+ sb.append("<xml-property name=\"description\" value=\"Namespace for business related constructs\" />\n");
+ sb.append("</xml-properties>\n");
+ sb.append("<xml-root-element name=\"business\" />\n");
+ sb.append("<java-attributes>\n");
+ sb.append("<xml-element java-attribute=\"customers\" name=\"customers\" type=\"inventory.aai.onap.org.v11.Customers\" />\n");
+ sb.append("</java-attributes>\n");
+ sb.append("</java-type>\n");
+ }
+
+ private void addCustomers(StringBuilder sb){
+ sb.append("<java-type name=\"Customers\">\n");
+ sb.append("<xml-properties>\n");
+ sb.append("<xml-property name=\"description\" value=\"Collection of customer identifiers to provide linkage back to BSS information.\" />\n");
+ sb.append("</xml-properties>\n");
+ sb.append("<xml-root-element name=\"customers\" />\n");
+ sb.append("<java-attributes>\n");
+ sb.append("<xml-element container-type=\"java.util.ArrayList\" java-attribute=\"customer\" name=\"customer\" type=\"inventory.aai.onap.org.v11.Customer\" />\n");
+ sb.append("</java-attributes>\n");
+ sb.append("<xml-properties>\n");
+ sb.append("<xml-property name=\"maximumDepth\" value=\"0\" />\n");
+ sb.append("</xml-properties>\n");
+ sb.append("</java-type>\n");
+ }
+
+ private void addCustomer(StringBuilder sb){
+ sb.append("<java-type name=\"Customer\">\n");
+ sb.append("<xml-root-element name=\"customer\" />\n");
+ sb.append("<java-attributes>\n");
+ sb.append("<xml-element java-attribute=\"globalCustomerId\" name=\"global-customer-id\" required=\"true\" type=\"java.lang.String\" xml-key=\"true\">\n");
+ sb.append("<xml-properties>\n");
+ sb.append("<xml-property name=\"description\" value=\"Global customer id used across ECOMP to uniquely identify customer.\" />\n");
+ sb.append("</xml-properties>\n");
+ sb.append("</xml-element>\n");
+ sb.append("<xml-element java-attribute=\"subscriberName\" name=\"subscriber-name\" required=\"true\" type=\"java.lang.String\">\n");
+ sb.append("<xml-properties>\n");
+ sb.append("<xml-property name=\"description\" value=\"Subscriber name, an alternate way to retrieve a customer.\" />\n");
+ sb.append("</xml-properties>\n");
+ sb.append("</xml-element>\n");
+ sb.append("<xml-element java-attribute=\"subscriberType\" name=\"subscriber-type\" required=\"true\" type=\"java.lang.String\">\n");
+ sb.append("<xml-properties>\n");
+ sb.append("<xml-property name=\"description\" value=\"Subscriber type, a way to provide VID with only the INFRA customers.\" />\n");
+ sb.append("<xml-property name=\"defaultValue\" value=\"CUST\" />\n");
+ sb.append("</xml-properties>\n");
+ sb.append("</xml-element>\n");
+ sb.append("<xml-element java-attribute=\"resourceVersion\" name=\"resource-version\" type=\"java.lang.String\">\n");
+ sb.append("<xml-properties>\n");
+ sb.append("<xml-property name=\"description\" value=\"Used for optimistic concurrency. Must be empty on create, valid on update and delete.\" />\n");
+ sb.append("</xml-properties>\n");
+ sb.append("</xml-element>\n");
+ sb.append("<xml-element java-attribute=\"serviceSubscriptions\" name=\"service-subscriptions\" type=\"inventory.aai.onap.org.v11.ServiceSubscriptions\" />\n");
+ sb.append("<xml-element java-attribute=\"relationshipList\" name=\"relationship-list\" type=\"inventory.aai.onap.org.v11.RelationshipList\" />\n");
+ sb.append("</java-attributes>\n");
+ sb.append("<xml-properties>\n");
+ sb.append("<xml-property name=\"description\" value=\"customer identifiers to provide linkage back to BSS information.\" />\n");
+ sb.append("<xml-property name=\"nameProps\" value=\"subscriber-name\" />\n");
+ sb.append("<xml-property name=\"indexedProps\" value=\"subscriber-name,global-customer-id,subscriber-type\" />\n");
+ sb.append("<xml-property name=\"searchable\" value=\"global-customer-id,subscriber-name\" />\n");
+ sb.append("<xml-property name=\"uniqueProps\" value=\"global-customer-id\" />\n");
+ sb.append("<xml-property name=\"container\" value=\"customers\" />\n");
+ sb.append("<xml-property name=\"namespace\" value=\"business\" />\n");
+ sb.append("</xml-properties>\n");
+ sb.append("</java-type>\n");
+ }
+
+ private void addServiceSubscriptions(StringBuilder sb){
+ sb.append("<java-type name=\"ServiceSubscriptions\">\n");
+ sb.append("<xml-properties>\n");
+ sb.append("<xml-property name=\"description\" value=\"Collection of objects that group service instances.\" />\n");
+ sb.append("</xml-properties>\n");
+ sb.append("<xml-root-element name=\"service-subscriptions\" />\n");
+ sb.append("<java-attributes>\n");
+ sb.append("<xml-element container-type=\"java.util.ArrayList\" java-attribute=\"serviceSubscription\" name=\"service-subscription\" type=\"inventory.aai.onap.org.v11.ServiceSubscription\" />\n");
+ sb.append("</java-attributes>\n");
+ sb.append("</java-type>\n");
+ }
+ private void addServiceSubscription(StringBuilder sb){
+ sb.append("<java-type name=\"ServiceSubscription\">\n");
+ sb.append("<xml-root-element name=\"service-subscription\" />\n");
+ sb.append("<java-attributes>\n");
+ sb.append("<xml-element java-attribute=\"serviceType\" name=\"service-type\" required=\"true\" type=\"java.lang.String\" xml-key=\"true\">\n");
+ sb.append("<xml-properties>\n");
+ sb.append("<xml-property name=\"description\" value=\"Value defined by orchestration to identify this service across ECOMP.\" />\n");
+ sb.append("</xml-properties>\n");
+ sb.append("</xml-element>\n");
+ sb.append("<xml-element java-attribute=\"tempUbSubAccountId\" name=\"temp-ub-sub-account-id\" type=\"java.lang.String\">\n");
+ sb.append("<xml-properties>\n");
+ sb.append("<xml-property name=\"description\" value=\"This property will be deleted from A&amp;AI in the near future. Only stop gap solution.\" />\n");
+ sb.append("</xml-properties>\n");
+ sb.append("</xml-element>\n");
+ sb.append("<xml-element java-attribute=\"resourceVersion\" name=\"resource-version\" type=\"java.lang.String\">\n");
+ sb.append("<xml-properties>\n");
+ sb.append("<xml-property name=\"description\" value=\"Used for optimistic concurrency. Must be empty on create, valid on update and delete.\" />\n");
+ sb.append("</xml-properties>\n");
+ sb.append("</xml-element>\n");
+ sb.append("<xml-element java-attribute=\"relationshipList\" name=\"relationship-list\" type=\"inventory.aai.onap.org.v11.RelationshipList\" />\n");
+ sb.append("</java-attributes>\n");
+ sb.append("<xml-properties>\n");
+ sb.append("<xml-property name=\"description\" value=\"Object that group service instances.\" />\n");
+ sb.append("<xml-property name=\"indexedProps\" value=\"service-type\" />\n");
+ sb.append("<xml-property name=\"dependentOn\" value=\"customer\" />\n");
+ sb.append("<xml-property name=\"container\" value=\"service-subscriptions\" />\n");
+ sb.append("<xml-property name=\"crossEntityReference\" value=\"service-instance,service-type\" />\n");
+ sb.append("</xml-properties>\n");
+ sb.append("</java-type>\n");
+ }
+
+ private void addEndOfXML(StringBuilder sb){
+ sb.append("</java-types>\n");
+ sb.append("</xml-bindings>\n");
+ }
+
+
+ @Test
+ public void test_processOxmFile() {
+
- String wikiLink = System.getProperty("aai.wiki.link");
+ GenerateXsd generateXsd = new GenerateXsd();
+
+ //GenerateXsd generateXsdSpy = PowerMockito.spy(generateXsd);
- if(wikiLink == null){
- wikiLink = "https://wiki.onap.org/";
- }
+ //generateXsdSpy.processOxmFile(null, Version.getLatest(), testXML);
- System.setProperty("yamlresponses_url", wikiLink);
- System.setProperty("yamlresponses_label", "Response codes found in [response codes]");
+ String xsdResult = generateXsd.processOxmFile(null, Version.getLatest(), testXML);
+
+ String relationshipListExpected = " <xs:element name=\"relationship-list\">\n <xs:complexType>\n <xs:sequence>\n <xs:element ref=\"tns:relationship\" minOccurs=\"0\" maxOccurs=\"unbounded\"/>\n </xs:sequence>\n </xs:complexType>\n </xs:element>";
+ String relatedToPropertyExpected = " <xs:element name=\"related-to-property\">\n <xs:complexType>\n <xs:sequence>\n <xs:element name=\"property-key\" type=\"xs:string\" minOccurs=\"0\">\n <xs:annotation>\r\n <xs:appinfo>\r\n <annox:annotate target=\"field\">@org.onap.aai.annotations.Metadata(description=\"Key part of a key/value pair\")</annox:annotate>\r\n </xs:appinfo>\r\n </xs:annotation>\r\n </xs:element>\n"
+ + " <xs:element name=\"property-value\" type=\"xs:string\" minOccurs=\"0\">\n <xs:annotation>\r\n <xs:appinfo>\r\n <annox:annotate target=\"field\">@org.onap.aai.annotations.Metadata(description=\"Value part of a key/value pair\")</annox:annotate>\r\n </xs:appinfo>\r\n </xs:annotation>\r\n </xs:element>\n </xs:sequence>\n </xs:complexType>\n </xs:element>";
+ assertNotNull(xsdResult);
+ }
+ @Test
+ public void test_generateSwaggerFromOxmFile( ) {
+
- generateXsd.main(new String[]{});
- }
+ GenerateXsd generateXsd = new GenerateXsd();
+ String customerOperation = " /business/customers/customer/{global-customer-id}:\n get:\n tags:\n - Business\n summary: returns customer";
+ String relationshipListDefinition = " relationship-list:\n properties:\n relationship:\n type: array\n items: \n $ref: \"#/definitions/relationship\"";
+ String swaggerResult = generateXsd.generateSwaggerFromOxmFile(null, testXML);
+ assertNotNull(swaggerResult);
+ }
}
diff --git a/aai-core/src/test/java/org/onap/aai/util/HbaseSaltPrefixerTest.java b/aai-core/src/test/java/org/onap/aai/util/HbaseSaltPrefixerTest.java
new file mode 100644
index 00000000..918f8974
--- /dev/null
+++ b/aai-core/src/test/java/org/onap/aai/util/HbaseSaltPrefixerTest.java
@@ -0,0 +1,72 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017 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=========================================================
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ */
+package org.onap.aai.util;
+
+import static org.junit.Assert.*;
+
+
+import org.junit.Test;
+
+
+public class HbaseSaltPrefixerTest {
+
+ HbaseSaltPrefixer obj = HbaseSaltPrefixer.getInstance();
+
+ //Sample key value used for testing
+ String key = "foo1234";
+
+ String result = obj.prependSalt(key);
+
+ @Test
+ public void classInstantiateCheck() {
+ try {
+ assertNotNull("Created class Object is not null", obj);
+ }
+ catch(Exception e) {
+ fail();
+ }
+ }
+
+ @Test
+ public void prependSaltResult_NullCheck () {
+ try {
+ assertNotNull("result is not null", result);
+ }
+ catch(NullPointerException e) {
+ fail();
+ }
+ }
+
+ @Test
+ public void prependSaltResult_PrefixSuccessChecks () {
+ try {
+ // Ensure that '-' has been prepended
+ assertFalse(result.startsWith("-"));
+ // Ensure that *something* has been prepended
+ assertFalse(result.equalsIgnoreCase(key));
+ }
+ catch (Exception e) {
+ fail();
+ }
+ }
+
+}
diff --git a/aai-core/src/test/java/org/onap/aai/util/KeyValueListTest.java b/aai-core/src/test/java/org/onap/aai/util/KeyValueListTest.java
new file mode 100644
index 00000000..c05ffefc
--- /dev/null
+++ b/aai-core/src/test/java/org/onap/aai/util/KeyValueListTest.java
@@ -0,0 +1,76 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017 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=========================================================
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ */
+package org.onap.aai.util;
+
+import org.junit.Before;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+public class KeyValueListTest {
+ KeyValueList kv;
+ KeyValueList kv1;
+
+ @Before
+ public void setup() {
+ String key = "key";
+ String value = "value";
+ kv = new KeyValueList();
+ kv.setKey(key);
+ kv.setValue(value);
+ kv.setAdditionalProperty("name1", "val1");
+ kv1 = new KeyValueList();
+ kv1.setKey("key1");
+ kv1.setValue("value1");
+ }
+
+ @Test
+ public void getSetTest() {
+ assertEquals("key", kv.getKey());
+ assertEquals("value", kv.getValue());
+ }
+
+ @Test
+ public void additionalPropertyTest() {
+ assertEquals("Additional properties added", "val1", kv.getAdditionalProperties().get("name1"));
+ }
+
+ @Test
+ public void hashCodeTest() {
+ assertEquals("Hashing function returns the same code", kv.hashCode(), kv.hashCode());
+ assertNotEquals("Hashing function returns different code for different objects", kv.hashCode(), kv1.hashCode());
+ }
+
+ @Test
+ public void equalsTest() {
+ KeyValueList kv2 = new KeyValueList();
+ kv2.setKey("key");
+ kv2.setValue("value");
+ kv2.setAdditionalProperty("name1", "val1");
+ assertTrue("Equal KeyValueList objects", kv.equals(kv2));
+ assertFalse("Non-equal KeyValueList objects", kv.equals(kv1));
+ }
+
+ @Test
+ public void toStringTest() {
+ assertNotEquals("Different objects should return different strings", kv.toString(), kv1.toString());
+ }
+}
diff --git a/aai-core/src/test/java/org/onap/aai/util/MapperUtilTest.java b/aai-core/src/test/java/org/onap/aai/util/MapperUtilTest.java
new file mode 100644
index 00000000..dae2c22d
--- /dev/null
+++ b/aai-core/src/test/java/org/onap/aai/util/MapperUtilTest.java
@@ -0,0 +1,72 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017 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=========================================================
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ */
+package org.onap.aai.util;
+
+import org.json.JSONObject;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+public class MapperUtilTest {
+
+ public class SampleClass {
+ private String color;
+ private String shape;
+
+ public SampleClass(String c, String s){
+ color = c;
+ shape = s;
+ }
+
+ public String getColor() {
+ return color;
+ }
+
+ public void setColor(String color) {
+ this.color = color;
+ }
+
+ public String getShape() {
+ return shape;
+ }
+
+ public void setShape(String shape) {
+ this.shape = shape;
+ }
+ }
+
+ private JSONObject expectedJson;
+
+ @Before
+ public void setup(){
+ expectedJson = new JSONObject();
+ }
+
+ @Test
+ public void writeAsJSONStringTest() throws Exception {
+ expectedJson.put("color", "black");
+ expectedJson.put("shape", "box");
+ SampleClass sample = new SampleClass("black", "box");
+ assertEquals(expectedJson.toString(), MapperUtil.writeAsJSONString(sample));
+ }
+}
diff --git a/aai-core/src/test/java/org/onap/aai/util/PojoUtilsTest.java b/aai-core/src/test/java/org/onap/aai/util/PojoUtilsTest.java
new file mode 100644
index 00000000..7121a82b
--- /dev/null
+++ b/aai-core/src/test/java/org/onap/aai/util/PojoUtilsTest.java
@@ -0,0 +1,107 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017 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=========================================================
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ */
+package org.onap.aai.util;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.time.LocalDateTime;
+import java.time.Month;
+
+import org.junit.Test;
+import org.mockito.Mockito;
+
+public class PojoUtilsTest {
+
+ @Test
+ public void testGetJsonFromObject_Clazz_MockTest() throws Exception {
+
+ String obj = "helloWorld";
+ PojoUtils pojoUtils = Mockito.mock(PojoUtils.class);
+ Mockito.doCallRealMethod().when(pojoUtils).getJsonFromObject(Mockito.anyString());
+
+ pojoUtils.getJsonFromObject(obj);
+
+ Mockito.verify(pojoUtils, Mockito.times(1)).getJsonFromObject(Mockito.anyString(), Mockito.eq(false), Mockito.eq(true));
+ }
+
+ @Test
+ public void testGetJsonFromObject_Clazz() throws Exception {
+
+ PojoUtils pojoUtils = PojoUtilsTest.getInstance();
+ LocalDateTime date = LocalDateTime.of(2017, Month.SEPTEMBER, 18, 10, 55, 0, 300);
+
+ String res = pojoUtils.getJsonFromObject(date);
+
+ assertNotNull(res);
+ assertTrue(res.contains("\"dayOfMonth\" : 18"));
+ assertTrue(res.contains("\"dayOfWeek\" : \"MONDAY\""));
+ assertTrue(res.contains("\"dayOfYear\" : 261"));
+ assertTrue(res.contains("\"hour\" : 10"));
+ assertTrue(res.contains("\"minute\" : 55"));
+ assertTrue(res.contains("\"month\" : \"SEPTEMBER\""));
+ assertTrue(res.contains("\"monthValue\" : 9"));
+ assertTrue(res.contains("\"nano\" : 300"));
+ assertTrue(res.contains("\"second\" : 0"));
+ assertTrue(res.contains("\"year\" : 2017"));
+ }
+
+ @Test
+ public void testGetJsonFromObject_Clazz_null() throws Exception {
+ PojoUtils pojoUtils = PojoUtilsTest.getInstance();
+
+ String res = pojoUtils.getJsonFromObject(null);
+
+ assertNotNull(res);
+ assertEquals("null", res);
+ }
+
+ @Test
+ public void testGetJsonFromObject_null() throws Exception {
+ PojoUtils pojoUtils = PojoUtilsTest.getInstance();
+
+ String res = pojoUtils.getJsonFromObject(null, false, true);
+
+ assertNotNull(res);
+ assertEquals("null", res);
+ }
+
+ @Test
+ public void testGetJsonFromObject() throws Exception {
+ PojoUtils pojoUtils = PojoUtilsTest.getInstance();
+ LocalDateTime date = LocalDateTime.of(2017, Month.SEPTEMBER, 18, 10, 55, 0, 300);
+
+ String res = pojoUtils.getJsonFromObject(date, false, false);
+ assertNotNull(res);
+
+ res = pojoUtils.getJsonFromObject(date, true, false);
+ assertNotNull(res);
+
+ res = pojoUtils.getJsonFromObject(date, true, true);
+ assertNotNull(res);
+ }
+
+ static PojoUtils getInstance() {
+ return new PojoUtils();
+ }
+}
diff --git a/aai-core/src/test/java/org/onap/aai/util/RestURLEncoderTest.java b/aai-core/src/test/java/org/onap/aai/util/RestURLEncoderTest.java
new file mode 100644
index 00000000..e296b5e1
--- /dev/null
+++ b/aai-core/src/test/java/org/onap/aai/util/RestURLEncoderTest.java
@@ -0,0 +1,63 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017 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=========================================================
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ */
+package org.onap.aai.util;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
+
+import org.junit.Test;
+
+public class RestURLEncoderTest {
+
+ @Test
+ public void testEncodeURL() throws Exception {
+
+ String url = "nodeKeyTest&more-string strings";
+ String encodedUrl = "nodeKeyTest%26more-string%20strings";
+
+ String res = RestURLEncoder.encodeURL(url);
+ assertEquals(encodedUrl, res);
+ }
+
+ @Test
+ public void testEncodeURL_plusSign() throws Exception {
+
+ String url = "nodeKeyTest+more+string";
+ String encodedUrl = "nodeKeyTest%2Bmore%2Bstring";
+
+ String res = RestURLEncoder.encodeURL(url);
+ assertEquals(encodedUrl, res);
+ }
+
+ @Test
+ public void testEncodeURL_noException() throws Exception {
+ // no exception expected, none thrown: passes.
+ try {
+ String encodeResult = RestURLEncoder.encodeURL("");
+
+ assertNotNull("Result is not null", encodeResult);
+ } catch (Exception e) {
+ fail();
+ }
+ }
+}
diff --git a/aai-core/src/test/java/org/onap/aai/util/StoreNotificationEventTest.java b/aai-core/src/test/java/org/onap/aai/util/StoreNotificationEventTest.java
new file mode 100644
index 00000000..5c87b29e
--- /dev/null
+++ b/aai-core/src/test/java/org/onap/aai/util/StoreNotificationEventTest.java
@@ -0,0 +1,235 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017 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=========================================================
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ */
+package org.onap.aai.util;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.StringWriter;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.json.Json;
+import javax.json.JsonObject;
+
+import org.eclipse.persistence.dynamic.DynamicEntity;
+import org.eclipse.persistence.dynamic.DynamicType;
+import org.eclipse.persistence.jaxb.JAXBContextProperties;
+import org.eclipse.persistence.jaxb.JAXBMarshaller;
+import org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext;
+import org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContextFactory;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.onap.aai.AAISetup;
+import org.onap.aai.dmaap.AAIDmaapEventJMSProducer;
+import org.onap.aai.domain.notificationEvent.NotificationEvent.EventHeader;
+import org.onap.aai.exceptions.AAIException;
+import org.onap.aai.introspection.Introspector;
+import org.onap.aai.introspection.Loader;
+import org.onap.aai.introspection.LoaderFactory;
+import org.onap.aai.introspection.ModelType;
+import org.onap.aai.introspection.Version;
+
+import com.fasterxml.jackson.core.JsonGenerationException;
+import com.fasterxml.jackson.databind.JsonMappingException;
+
+public class StoreNotificationEventTest extends AAISetup {
+
+ private static AAIDmaapEventJMSProducer producer;
+ private static StoreNotificationEvent sne;
+
+ @BeforeClass
+ public static void setUp() throws Exception {
+ producer = Mockito.mock(AAIDmaapEventJMSProducer.class);
+ sne = new StoreNotificationEvent(producer, "transiationId", "sourceOfTruth");
+ }
+
+ @Test(expected = AAIException.class)
+ public void testStoreEventNullObj() throws AAIException {
+ sne.storeEvent(new EventHeader(), null);
+ }
+
+ @Test(expected = AAIException.class)
+ public void testStoreEventInvalidObjForPojoUtils() throws AAIException {
+ sne.storeEvent(new EventHeader(), new Object());
+ }
+
+ @Test
+ public void testStoreEventEmptyEventHeader() throws AAIException, JsonGenerationException, JsonMappingException, IOException {
+ JsonObject object = Json.createObjectBuilder().add("hello", "world").build();
+ String res = sne.storeEvent(new EventHeader(), object);
+
+ assertNotNull(res);
+ assertTrue(res.contains("\"cambria.partition\" : \"" + AAIConstants.UEB_PUB_PARTITION_AAI + "\""));
+ assertTrue(res.contains("\"event-header\""));
+ assertTrue(res.contains("\"id\""));
+ assertTrue(res.contains("\"timestamp\""));
+ assertTrue(res.contains("\"source-name\" : \"" + AAIConfig.get("aai.notificationEvent.default.sourceName") + "\""));
+ assertTrue(res.contains("\"domain\" : \"" + AAIConfig.get("aai.notificationEvent.default.domain") + "\""));
+ assertTrue(res.contains("\"sequence-number\" : \"" + AAIConfig.get("aai.notificationEvent.default.sequenceNumber") + "\""));
+ assertTrue(res.contains("\"severity\" : \"" + AAIConfig.get("aai.notificationEvent.default.severity") + "\""));
+ assertTrue(res.contains("\"event-type\" : \"" + AAIConfig.get("aai.notificationEvent.default.eventType") + "\""));
+ assertTrue(res.contains("\"version\" : \"" + AAIConfig.get("aai.notificationEvent.default.version") + "\""));
+ assertTrue(res.contains("\"action\" : \"UNK\""));
+ assertTrue(res.contains("\"entity-link\" : \"UNK\""));
+ assertTrue(res.contains("\"entity\""));
+ assertTrue(res.contains("\"hello\""));
+ assertTrue(res.contains("\"chars\" : \"world\""));
+ assertTrue(res.contains("\"string\" : \"world\""));
+ assertTrue(res.contains("\"valueType\" : \"STRING\""));
+ }
+
+ @Test
+ public void testStoreEvent() throws AAIException, JsonGenerationException, JsonMappingException, IOException {
+ JsonObject object = Json.createObjectBuilder().add("hello", "world").build();
+ EventHeader eh = new EventHeader();
+ eh.setId("123");
+ eh.setTimestamp("current-time");
+ eh.setEntityLink("entity-link");
+ eh.setAction("action!");
+ eh.setEventType("surprise");
+ eh.setDomain("PROD");
+ eh.setSourceName("source");
+ eh.setSequenceNumber("23");
+ eh.setSeverity("ALERT");
+ eh.setVersion("v11");
+
+ String res = sne.storeEvent(eh, object);
+
+ assertNotNull(res);
+ assertTrue(res.contains("\"cambria.partition\" : \"" + AAIConstants.UEB_PUB_PARTITION_AAI + "\""));
+ assertTrue(res.contains("\"event-header\""));
+ assertTrue(res.contains("\"id\" : \"123\""));
+ assertTrue(res.contains("\"timestamp\" : \"current-time\""));
+ assertTrue(res.contains("\"source-name\" : \"source\""));
+ assertTrue(res.contains("\"domain\" : \"PROD\""));
+ assertTrue(res.contains("\"sequence-number\" : \"23\""));
+ assertTrue(res.contains("\"severity\" : \"ALERT\""));
+ assertTrue(res.contains("\"event-type\" : \"surprise\""));
+ assertTrue(res.contains("\"version\" : \"v11\""));
+ assertTrue(res.contains("\"action\" : \"action!\""));
+ assertTrue(res.contains("\"entity-link\" : \"entity-link\""));
+ assertTrue(res.contains("\"entity\""));
+ assertTrue(res.contains("\"hello\""));
+ assertTrue(res.contains("\"chars\" : \"world\""));
+ assertTrue(res.contains("\"string\" : \"world\""));
+ assertTrue(res.contains("\"valueType\" : \"STRING\""));
+ }
+
+ @Test(expected=AAIException.class)
+ public void testStoreDynamicEventNullObj() throws AAIException {
+ DynamicEntity eventHeader = Mockito.mock(DynamicEntity.class);
+ DynamicJAXBContext notificationJaxbContext = Mockito.mock(DynamicJAXBContext.class);
+ sne.storeDynamicEvent(notificationJaxbContext, "v11", eventHeader, null);
+ }
+
+ @Test(expected = AAIException.class)
+ public void testStoreDynamicEventAAIException() throws Exception {
+ DynamicEntity eventHeader = Mockito.mock(DynamicEntity.class);
+ DynamicEntity obj = Mockito.mock(DynamicEntity.class);
+ DynamicJAXBContext notificationJaxbContext = Mockito.mock(DynamicJAXBContext.class);
+ ClassLoader cl = getClass().getClassLoader();
+ InputStream is = cl.getResourceAsStream("bundleconfig-local/etc/oxm/aai_oxm_v11.xml");
+ Map<String, Object> properties = new HashMap<String, Object>();
+ properties.put(JAXBContextProperties.OXM_METADATA_SOURCE, is);
+ DynamicJAXBContext notificationJaxbContextReal = DynamicJAXBContextFactory.createContextFromOXM(cl, properties);
+ DynamicType dtReal = notificationJaxbContextReal.getDynamicType("inventory.aai.onap.org.v11.NotificationEvent");
+ DynamicType dt = Mockito.mock(DynamicType.class);
+ DynamicEntity notificationEventReal = dtReal.newDynamicEntity();
+ JAXBMarshaller marshaller = Mockito.mock(JAXBMarshaller.class);
+
+ Mockito.when(notificationJaxbContext.getDynamicType(Mockito.anyString())).thenReturn(dt);
+ Mockito.when(dt.newDynamicEntity()).thenReturn(notificationEventReal);
+ Mockito.when(notificationJaxbContext.createMarshaller()).thenReturn(marshaller);
+ Mockito.doNothing().when(marshaller).marshal(Mockito.any(DynamicJAXBContext.class), Mockito.any(StringWriter.class));
+
+ sne.storeDynamicEvent(notificationJaxbContext, "v11", eventHeader, obj);
+ }
+
+ @Test(expected = AAIException.class)
+ public void testStoreEventIntrospectorNullObj() throws Exception {
+ Loader loader = Mockito.mock(Loader.class);
+ sne.storeEvent(loader, null, null);
+ }
+
+ @Test
+ public void testStoreEventIntrospector() throws Exception {
+ Loader loader = LoaderFactory.createLoaderForVersion(ModelType.MOXY, Version.v11);
+ Introspector eventHeader = loader.introspectorFromName("notification-event-header");
+ eventHeader.setValue("id", "123");
+ eventHeader.setValue("timestamp", "current-time");
+ eventHeader.setValue("entity-link", "entity-link");
+ eventHeader.setValue("action", "action!");
+ eventHeader.setValue("event-type", "surprise");
+ eventHeader.setValue("domain", "PROD");
+ eventHeader.setValue("source-name", "source");
+ eventHeader.setValue("sequence-number", "23");
+ eventHeader.setValue("severity", "ALERT");
+ eventHeader.setValue("version", "v11");
+
+ Introspector obj = loader.introspectorFromName("notification-event");
+
+ String res = sne.storeEvent(loader, eventHeader, obj);
+
+ assertNotNull(res);
+ assertTrue(res.contains("\"cambria.partition\":\"" + AAIConstants.UEB_PUB_PARTITION_AAI + "\""));
+ assertTrue(res.contains("\"event-header\""));
+ assertTrue(res.contains("\"id\":\"123\""));
+ assertTrue(res.contains("\"timestamp\":\"current-time\""));
+ assertTrue(res.contains("\"source-name\":\"source\""));
+ assertTrue(res.contains("\"domain\":\"PROD\""));
+ assertTrue(res.contains("\"sequence-number\":\"23\""));
+ assertTrue(res.contains("\"severity\":\"ALERT\""));
+ assertTrue(res.contains("\"event-type\":\"surprise\""));
+ assertTrue(res.contains("\"version\":\"v11\""));
+ assertTrue(res.contains("\"action\":\"action!\""));
+ assertTrue(res.contains("\"entity-link\":\"entity-link\""));
+ assertTrue(res.contains("\"notification-event\""));
+ }
+
+ @Test
+ public void testStoreEventIntrospectorEmptyEventHeader() throws Exception {
+ Loader loader = LoaderFactory.createLoaderForVersion(ModelType.MOXY, Version.v11);
+ Introspector eventHeader = loader.introspectorFromName("notification-event-header");
+ Introspector obj = loader.introspectorFromName("notification-event");
+
+ String res = sne.storeEvent(loader, eventHeader, obj);
+
+ assertNotNull(res);
+ assertTrue(res.contains("\"cambria.partition\":\"" + AAIConstants.UEB_PUB_PARTITION_AAI + "\""));
+ assertTrue(res.contains("\"event-header\""));
+ assertTrue(res.contains("\"id\""));
+ assertTrue(res.contains("\"timestamp\""));
+ assertTrue(res.contains("\"source-name\":\"" + AAIConfig.get("aai.notificationEvent.default.sourceName") + "\""));
+ assertTrue(res.contains("\"domain\":\"" + AAIConfig.get("aai.notificationEvent.default.domain") + "\""));
+ assertTrue(res.contains("\"sequence-number\":\"" + AAIConfig.get("aai.notificationEvent.default.sequenceNumber") + "\""));
+ assertTrue(res.contains("\"severity\":\"" + AAIConfig.get("aai.notificationEvent.default.severity") + "\""));
+ assertTrue(res.contains("\"event-type\":\"" + AAIConfig.get("aai.notificationEvent.default.eventType") + "\""));
+ assertTrue(res.contains("\"version\":\"" + AAIConfig.get("aai.notificationEvent.default.version") + "\""));
+ assertTrue(res.contains("\"action\":\"UNK\""));
+ assertTrue(res.contains("\"entity-link\":\"UNK\""));
+ assertTrue(res.contains("\"notification-event\""));
+ }
+}
diff --git a/aai-core/src/test/java/org/onap/aai/workarounds/LegacyURITransformerTest.java b/aai-core/src/test/java/org/onap/aai/workarounds/LegacyURITransformerTest.java
new file mode 100644
index 00000000..ebcaf750
--- /dev/null
+++ b/aai-core/src/test/java/org/onap/aai/workarounds/LegacyURITransformerTest.java
@@ -0,0 +1,104 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright (C) 2017 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.workarounds;
+
+import org.junit.Test;
+import org.onap.aai.AAISetup;
+import org.onap.aai.introspection.Version;
+
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import static org.junit.Assert.assertEquals;
+
+
+public class LegacyURITransformerTest extends AAISetup {
+
+ private LegacyURITransformer uriTransformer = LegacyURITransformer.getInstance();
+ private String fromSuccess = "http://myhostname.com:8443/aai/{version}/cloud-infrastructure/tenants/tenant/key1/vservers/vserver/key2";
+ private String toSuccess = "http://myhostname.com:8443/aai/servers/{version}/key1/vservers/key2";
+
+
+ /**
+ * V 5.
+ * @throws URISyntaxException
+ *
+ * @throws MalformedURLException the malformed URL exception
+ */
+ @Test
+ public void v5() throws URISyntaxException {
+ testSpec(Version.v8, fromSuccess, fromSuccess);
+ }
+
+
+ /**
+ * Test spec.
+ *
+ * @param version the version
+ * @param toExpected the to expected
+ * @param fromExpected the from expected
+ * @throws URISyntaxException
+ * @throws MalformedURLException the malformed URL exception
+ */
+ public void testSpec(Version version, String toExpected, String fromExpected) throws URISyntaxException {
+
+ URI toExpectedUri = new URI(toExpected.replace("{version}",version.toString()));
+ URI fromExpectedUri = new URI(fromExpected.replace("{version}",version.toString()));
+
+ URI result = toLegacyURISpec(version, fromExpectedUri);
+
+ assertEquals("to", toExpectedUri, result);
+
+ result = fromLegacyURISpec(version, toExpectedUri);
+
+ assertEquals("from", fromExpectedUri, result);
+ }
+
+
+ /**
+ * To legacy URL spec.
+ *
+ * @param version the version
+ * @param url the url
+ * @return the url
+ * @throws URISyntaxException
+ * @throws MalformedURLException the malformed URL exception
+ */
+ public URI toLegacyURISpec(Version version, URI uri) throws URISyntaxException {
+ return uri;
+ }
+
+ /**
+ * From legacy URL spec.
+ *
+ * @param version the version
+ * @param url the url
+ * @return the url
+ * @throws URISyntaxException
+ * @throws MalformedURLException the malformed URL exception
+ */
+ public URI fromLegacyURISpec(Version version, URI uri) throws URISyntaxException {
+ return uri;
+ }
+
+
+}