aboutsummaryrefslogtreecommitdiffstats
path: root/aai-resources/src/test/java/org
diff options
context:
space:
mode:
Diffstat (limited to 'aai-resources/src/test/java/org')
-rw-r--r--aai-resources/src/test/java/org/openecomp/aai/dbgen/DbMethTest.java90
-rw-r--r--aai-resources/src/test/java/org/openecomp/aai/dbgen/DbRunTest.java341
-rw-r--r--aai-resources/src/test/java/org/openecomp/aai/migration/VertexMergeTest.java190
-rw-r--r--aai-resources/src/test/java/org/openecomp/aai/query/builder/TraversalQueryTest.java105
-rw-r--r--aai-resources/src/test/java/org/openecomp/aai/schema/db/AuditOXMTest.java2
-rw-r--r--aai-resources/src/test/java/org/openecomp/aai/schema/db/ManageSchemaTest.java2
-rw-r--r--aai-resources/src/test/java/org/openecomp/aai/util/AAITxnLogTest.java361
-rw-r--r--aai-resources/src/test/java/org/openecomp/aai/util/DataConversionHelperTest.java88
-rw-r--r--aai-resources/src/test/java/org/openecomp/aai/util/DeleteResourceTest.java108
-rw-r--r--aai-resources/src/test/java/org/openecomp/aai/util/JettyObfuscationConversionCommandLineUtilTest.java71
10 files changed, 1251 insertions, 107 deletions
diff --git a/aai-resources/src/test/java/org/openecomp/aai/dbgen/DbMethTest.java b/aai-resources/src/test/java/org/openecomp/aai/dbgen/DbMethTest.java
new file mode 100644
index 0000000..420daa7
--- /dev/null
+++ b/aai-resources/src/test/java/org/openecomp/aai/dbgen/DbMethTest.java
@@ -0,0 +1,90 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * org.openecomp.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.openecomp.aai.dbgen;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.junit.Ignore;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+import org.openecomp.aai.exceptions.AAIException;
+
+public class DbMethTest {
+
+ @Rule
+ public ExpectedException expectedEx = ExpectedException.none();
+
+ @Test
+ public void testGetEdgeTagPropPutHash() throws AAIException {
+ Map<String, String> expectedMap = new HashMap<>();
+ expectedMap.put("usesResource", "false");
+ expectedMap.put("isParent", "false");
+ expectedMap.put("SVC-INFRA", "true");
+ expectedMap.put("hasDelTarget", "false");
+
+ assertEquals(expectedMap, DbMeth.getEdgeTagPropPutHash("", "", "pserver|complex").get("locatedIn").getEdgeProperties());
+ }
+
+ @Test
+ public void testGetEdgeTagPropPutHash2() throws AAIException {
+ Map<String, String> expectedMap = new HashMap<>();
+ expectedMap.put("usesResource", "false");
+ expectedMap.put("isParent", "false");
+ expectedMap.put("SVC-INFRA", "false");
+ expectedMap.put("hasDelTarget", "false");
+
+ assertEquals(expectedMap, DbMeth.getEdgeTagPropPutHash("", "", "service-instance|allotted-resource").get("uses").getEdgeProperties());
+ }
+
+ @Test
+ public void testGetEdgeTagPropPutHash3() throws AAIException {
+ Map<String, String> expectedMap = new HashMap<>();
+ expectedMap.put("usesResource", "false");
+ expectedMap.put("isParent", "true");
+ expectedMap.put("SVC-INFRA", "false");
+ expectedMap.put("hasDelTarget", "false");
+
+ assertEquals(expectedMap, DbMeth.getEdgeTagPropPutHash("", "", "service-instance|allotted-resource").get("has").getEdgeProperties());
+ }
+
+ @Ignore
+ @Test
+ public void getGetEdgeTagPropPutHashThrowsExceptionWhenNoRuleExists() throws Exception {
+ expectedEx.expect(AAIException.class);
+ expectedEx.expectMessage("AAI_6120");
+ DbMeth.getEdgeTagPropPutHash("", "", "complex|pserver");
+ }
+
+ @Ignore
+ @Test
+ public void getGetEdgeTagPropPutHashThrowsExceptionWhenNoRuleExists1() throws Exception {
+ expectedEx.expect(AAIException.class);
+ expectedEx.expectMessage("AAI_6120");
+ DbMeth.getEdgeTagPropPutHash("", "", "complex");
+ }
+
+
+}
diff --git a/aai-resources/src/test/java/org/openecomp/aai/dbgen/DbRunTest.java b/aai-resources/src/test/java/org/openecomp/aai/dbgen/DbRunTest.java
new file mode 100644
index 0000000..cef8019
--- /dev/null
+++ b/aai-resources/src/test/java/org/openecomp/aai/dbgen/DbRunTest.java
@@ -0,0 +1,341 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * org.openecomp.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.openecomp.aai.dbgen;
+
+import java.nio.file.attribute.FileTime;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.HashMap;
+import java.util.Iterator;
+
+import org.openecomp.aai.dbmap.AAIGraph;
+import org.openecomp.aai.exceptions.AAIException;
+import org.openecomp.aai.logging.ErrorLogHelper;
+import org.openecomp.aai.util.AAIConfig;
+import org.openecomp.aai.util.DbTestGetFileTime;
+import com.thinkaurelius.titan.core.TitanTransaction;
+import com.thinkaurelius.titan.core.TitanVertex;
+
+public class DbRunTest {
+
+ /**
+ * The main method.
+ *
+ * @param args the arguments
+ */
+ public static void main(String[] args) {
+
+ String testid = "NA";
+ TitanTransaction graph = null;
+
+ boolean runIt = false;
+ try {
+ AAIConfig.init();
+ ErrorLogHelper.loadProperties();
+ if (args.length > 0) {
+ System.out.println( "DbRunTest called with " + args.length + " arguments");
+
+
+ } else {
+ System.out.print("usage: DbRunTest <testid> <processDelay milliseconds> <processName> <loopcnt>\n");
+ return;
+ }
+ } catch (AAIException e) {
+ System.out.print("Threw a AAIException -- \n");
+ System.out.println(e.getMessage());
+ } catch (Exception ex) {
+ System.out.print("Threw a regular ole Exception \n");
+ System.out.println(ex.getMessage());
+ }
+
+
+
+ //System.out.println("skipping Titan graph for now...");
+ //TitanGraph graph = null;
+
+
+ String processName = "NA";
+ if ( args.length > 1 )
+ processName = args[2].trim();
+
+ try {
+ System.out.println(processName + " ---- NOTE --- about to open graph (takes a little while)--------\n");
+
+ graph = AAIGraph.getInstance().getGraph().newTransaction();
+
+ if( graph == null ){
+ System.out.println(processName + "Error creating Titan graph. \n");
+ return;
+ }
+ } catch( Exception ex ){
+ System.out.println( processName + " ERROR: caught this exception: " + ex );
+ return;
+ }
+
+ testid = args[0].trim();
+ runIt = true;
+ Integer processDelay = new Integer(args[1].trim() ); // delay of write
+ Integer loopCnt = new Integer(args[3].trim() ); // delay of write
+
+ String path = "NA";
+ try {
+
+ path = AAIConfig.get("dbruntest.path" ); // uses file create-timestamp
+ Integer writeDelay = new Integer(AAIConfig.get("dbruntest.delay" )); // delay seconds from create-timestamp
+ Integer loopDelay = new Integer(AAIConfig.get("dbruntest.loopdelay" )); // delay seconds from create-timestamp for next loop
+
+ DbTestGetFileTime getFileTime = new DbTestGetFileTime();
+ FileTime fileTime = getFileTime.createFileReturnTime( path );
+ long createMillis = fileTime.toMillis();
+ System.out.println(processName + " delays to use " + writeDelay + " processDelay " + processDelay);
+ System.out.println(processName + " test control file " + path + " creation time :"
+ + new SimpleDateFormat("dd/MM/yyyy HH:mm:ss:SSS")
+ .format(fileTime.toMillis()));
+
+ long delayMillis = writeDelay * 60 * 1000;
+ long loopMillis = loopDelay * 60 * 1000;
+
+ int loops = loopCnt.intValue();
+
+ long sleepTime;
+ for ( int i = 0; i < loops; ++i ) {
+
+ if ( i > 0 )
+ delayMillis = loopMillis * i; // to find the time the write will be done
+ delayMillis += processDelay.intValue();
+
+ System.out.println(processName + " test control file " + path + " write time :"
+ + new SimpleDateFormat("dd/MM/yyyy HH:mm:ss:SSS")
+ .format(createMillis + delayMillis));
+
+ Calendar now = Calendar.getInstance();
+ long myMillis = now.getTimeInMillis();
+ System.out.println(processName + " test control file " + path + " current time :"
+ + new SimpleDateFormat("dd/MM/yyyy HH:mm:ss:SSS")
+ .format(myMillis));
+ // total sleep based on current time, time file was created, and any delay per process
+
+ if ( i == 0 )
+ sleepTime = createMillis + delayMillis - myMillis; // + processDelay.intValue()
+ else
+ sleepTime = createMillis + ( loopMillis * i ) - myMillis;
+ sleepTime += processDelay.intValue();
+ System.out.println(processName + " sleep " + sleepTime + " current time :"
+ + new SimpleDateFormat("dd/MM/yyyy HH:mm:ss:SSS")
+ .format(myMillis));
+ Thread.sleep(sleepTime);
+
+ System.out.println(processName + " out of sleep for loop count " + i);
+
+ if (runIt) {
+ // include loop in unique-id string
+ runMultiLevelTest(graph, testid + i + "-", processName);
+ }
+
+ } // end loop
+
+
+ } catch ( Exception io ) {
+ System.out.println( processName + " Exception getting creation time " + path + " message " + io.getMessage());
+ io.printStackTrace();
+ }
+
+
+
+
+
+ if( graph != null && graph.isOpen() ){
+ System.out.println(processName + "About to call graph.shutdown()");
+ graph.tx().close();
+ System.out.println(processName + " -- AFTER call graph.shutdown()");
+ }
+
+ System.out.println(processName + " -- Boom!");
+ System.exit(0);
+
+ }// end of main()
+
+
+
+ /**
+ * Run multi level test.
+ *
+ * @param graph the graph
+ * @param testIdentifier the test identifier
+ * @param processName the process name
+ */
+ private static void runMultiLevelTest(TitanTransaction graph, String testIdentifier, String processName) {
+
+ try {
+ String useRollback = AAIConfig.get("dbruntest.rollback");
+
+ // l3-interface-ipv6-address-list -> vlan -> l-interface -> vnic -> vserver -> tenant
+
+ HashMap<String, Object> propHash7 = new HashMap<String, Object>();
+ propHash7.put("tenant-name", testIdentifier + "tenantName");
+ propHash7.put("tenant-id", testIdentifier + "tenantId");
+ TitanVertex tenantVtx = DbMeth.persistAaiNode("junkTransId",
+ "testApp", graph, "tenant", propHash7, true, null);
+
+
+ HashMap<String, Object> propHash8 = new HashMap<String, Object>();
+ propHash8.put("vserver-selflink", testIdentifier + "vserverSelfThing");
+ propHash8.put("vserver-id", testIdentifier + "vserverID");
+ propHash8.put("vserver-name", testIdentifier + "vserverName");
+ propHash8.put("vserver-name2", testIdentifier + "vserverName2");
+ TitanVertex vserverVtx = DbMeth.persistAaiNode("junkTransId",
+ "testApp", graph, "vserver", propHash8, true, tenantVtx);
+
+ HashMap<String, Object> propHash10 = new HashMap<String, Object>();
+ propHash10.put("interface-name", testIdentifier + "logIntfOnVpe");
+ TitanVertex logIntfVtx = DbMeth.persistAaiNode("junkTransId",
+ "testApp", graph, "l-interface", propHash10, true, vserverVtx);
+
+ HashMap<String, Object> propHash11 = new HashMap<String, Object>();
+ propHash11.put("vlan-interface", testIdentifier + "vlanIntf");
+ TitanVertex vlanVtx = DbMeth.persistAaiNode("junkTransId",
+ "testApp", graph, "vlan", propHash11, true, logIntfVtx);
+
+ HashMap<String, Object> propHash12 = new HashMap<String, Object>();
+ propHash12.put("l3-interface-ipv6-address", testIdentifier + "v6 pool");
+ TitanVertex l3PoolVtx = DbMeth.persistAaiNode("junkTransId",
+ "testApp", graph, "l3-interface-ipv6-address-list", propHash12, true, vlanVtx);
+
+ System.out.println(processName + " ---- did the persist on all the nodes -- ");
+
+ DbMeth.persistAaiEdge("junkTransId", "junkApp", graph, vserverVtx, tenantVtx);
+ DbMeth.persistAaiEdge("junkTransId", "junkApp", graph, logIntfVtx, vserverVtx);
+ DbMeth.persistAaiEdge("junkTransId", "junkApp", graph, vlanVtx, logIntfVtx);
+ DbMeth.persistAaiEdge("junkTransId", "junkApp", graph, l3PoolVtx, vlanVtx);
+
+ System.out.println(processName + " ---- persisted all the edges -- ");
+
+ if ( useRollback.toUpperCase().equals("Y")) {
+ System.out.print(processName + " using rollback for unittesting\n");
+ if (graph != null) {
+ graph.tx().rollback();
+ }
+ } else {
+ graph.tx().commit();
+ System.out.println(processName + " ---- Ran graph.commit() -- ");
+ }
+ HashMap<String, Object> propHash0 = new HashMap<String, Object>();
+ propHash0.put("l3-interface-ipv6-address-list.l3-interface-ipv6-address", testIdentifier + "v6 pool");
+ propHash0.put("tenant.tenant-name", testIdentifier + "tenantName");
+ propHash0.put("tenant.tenant-id", testIdentifier + "tenantId");
+ propHash0.put("vserver.vserver-selflink", testIdentifier + "vserverSelfThing");
+ propHash0.put("vserver.vserver-id", testIdentifier + "vserverID");
+ propHash0.put("vserver.vserver-name", testIdentifier + "vserverName");
+ propHash0.put("vserver.vserver-name2", testIdentifier + "vserverName2");
+ propHash0.put("l-interface.interface-name", testIdentifier + "logIntfOnVpe");
+ propHash0.put("vlan.vlan-interface", testIdentifier + "vlanIntf");
+
+
+ System.out.println(processName + " ---- First try the getUniqueNodeWithDepParams trail: ");
+
+ TitanVertex poolV = DbMeth.getUniqueNodeWithDepParams("junkTransId", "junkAppId", graph, "l3-interface-ipv6-address-list", propHash0, null);
+
+ ArrayList <String> retArr = DbMeth.showPropertiesForNode("junkTransId", "junkFromAppId", poolV);
+ for( String info : retArr ){ System.out.println(info); }
+
+/*
+ * RelationshipUtils replaced with RelationshipGraph
+ * System.out.println(processName + " ---- Next try the figureRelData trail: ");
+ List <RelationshipData> relDatList = RelationshipUtils.figureRelData("junkTransId", "junkAppId", graph, poolV, "");
+ System.out.println(processName + " ---- Looks like it worked ----------");
+ Iterator<RelationshipData> iterDat = relDatList.iterator();
+ while (iterDat.hasNext()) {
+ RelationshipData relDat = iterDat.next();
+ System.out.println(processName + " relData: key = ["
+ + relDat.getRelationshipKey() + "], val = ["
+ + relDat.getRelationshipValue() + "]");
+ }*/
+
+
+ HashMap<String, Object> propHash = new HashMap<String, Object>();
+ ArrayList<TitanVertex> vertList;
+
+ propHash.put("tenant-id", testIdentifier + "tenantId");
+ vertList = DbMeth.getNodes("junkTransId",
+ "testApp", graph, "tenant", propHash, false, null, true);
+
+ Iterator<TitanVertex> iter = vertList.iterator();
+
+ int vertexCnt = 0;
+ while( iter.hasNext() ) {
+ ++vertexCnt;
+ TitanVertex tvx = iter.next();
+ System.out.println(processName + " Found tenant " + vertexCnt );
+ DbMeth.showPropertiesForNode( "junkId", "junkApp", tvx );
+ }
+ if ( vertexCnt == 0 )
+ System.out.println(processName + " no tenant found" );
+
+ propHash = new HashMap<String, Object>();
+
+ propHash.put("vserver-id", testIdentifier + "vserverID");
+ vertList = DbMeth.getNodes("junkTransId",
+ "testApp", graph, "vserver", propHash, false, null, true);
+
+ iter = vertList.iterator();
+
+ vertexCnt = 0;
+ while( iter.hasNext() ) {
+ ++vertexCnt;
+ TitanVertex tvx = iter.next();
+ System.out.println(processName + " Found vserver " + vertexCnt );
+ DbMeth.showPropertiesForNode( "junkId", "junkApp", tvx );
+ }
+ if ( vertexCnt == 0 )
+ System.out.println(processName + " no vserver found" );
+
+ if ( useRollback.toUpperCase().equals("Y")) {
+ System.out.print(processName + " using rollback for unittesting\n");
+ if (graph != null) {
+ graph.tx().rollback();
+ }
+ }
+
+ }
+ catch (AAIException e) {
+ System.out.print(processName + " Threw an AAIException -- calling graph.rollback()\n");
+ System.out.println("exMsg = [" + e.getMessage() + "]");
+ if (graph != null) {
+ graph.tx().rollback();
+ }
+ }
+ catch (Exception ex) {
+ System.out.print(processName + " Threw a regular ole Exception calling graph.rollback()\n");
+ System.out.println(ex.getMessage());
+ System.out.println(ex.toString());
+ if (graph != null) {
+ graph.tx().rollback();
+ }
+ }
+
+
+
+ return;
+ }
+
+
+}
diff --git a/aai-resources/src/test/java/org/openecomp/aai/migration/VertexMergeTest.java b/aai-resources/src/test/java/org/openecomp/aai/migration/VertexMergeTest.java
new file mode 100644
index 0000000..1b5b67b
--- /dev/null
+++ b/aai-resources/src/test/java/org/openecomp/aai/migration/VertexMergeTest.java
@@ -0,0 +1,190 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * org.openecomp.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.openecomp.aai.migration;
+
+import static org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
+
+import java.io.UnsupportedEncodingException;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
+import org.apache.tinkerpop.gremlin.structure.Vertex;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Ignore;
+import org.junit.Test;
+
+import org.openecomp.aai.db.props.AAIProperties;
+import org.openecomp.aai.dbmap.DBConnectionType;
+import org.openecomp.aai.introspection.Loader;
+import org.openecomp.aai.introspection.LoaderFactory;
+import org.openecomp.aai.introspection.ModelType;
+import org.openecomp.aai.introspection.Version;
+import org.openecomp.aai.serialization.db.DBSerializer;
+import org.openecomp.aai.serialization.db.EdgeRules;
+import org.openecomp.aai.serialization.engines.QueryStyle;
+import org.openecomp.aai.serialization.engines.TitanDBEngine;
+import org.openecomp.aai.serialization.engines.TransactionalGraphEngine;
+//import org.openecomp.aai.serialization.queryformats.QueryFormatTestHelper;
+import org.openecomp.aai.util.AAIConstants;
+import com.thinkaurelius.titan.core.Cardinality;
+import com.thinkaurelius.titan.core.TitanFactory;
+import com.thinkaurelius.titan.core.TitanGraph;
+import com.thinkaurelius.titan.core.TitanTransaction;
+import com.thinkaurelius.titan.core.schema.TitanManagement;
+
+@Ignore
+public class VertexMergeTest {
+
+
+ private final static Version version = Version.v10;
+ private final static ModelType introspectorFactoryType = ModelType.MOXY;
+ private final static QueryStyle queryStyle = QueryStyle.TRAVERSAL;
+ private final static DBConnectionType type = DBConnectionType.REALTIME;
+ private static Loader loader;
+ private static TransactionalGraphEngine dbEngine;
+ private static TitanGraph graph;
+ private static EdgeRules rules;
+ private static GraphTraversalSource g;
+ private static TitanTransaction tx;
+ @BeforeClass
+ public static void setUp() throws NoSuchFieldException, SecurityException, Exception {
+ graph = TitanFactory.build().set("storage.backend","inmemory").open();
+ tx = graph.newTransaction();
+ g = tx.traversal();
+ System.setProperty("AJSC_HOME", ".");
+ System.setProperty("BUNDLECONFIG_DIR", "bundleconfig-local");
+// QueryFormatTestHelper.setFinalStatic(AAIConstants.class.getField("AAI_HOME_ETC_OXM"), "src/test/resources/org/openecomp/aai/introspection/");
+ loader = LoaderFactory.createLoaderForVersion(introspectorFactoryType, version);
+ dbEngine = new TitanDBEngine(
+ queryStyle,
+ type,
+ loader);
+ rules = EdgeRules.getInstance();
+
+ TitanManagement mgmt = graph.openManagement();
+ mgmt.makePropertyKey("test-list").dataType(String.class).cardinality(Cardinality.SET).make();
+ mgmt.commit();
+ Vertex pserverSkeleton = g.addV().property("aai-node-type", "pserver").property("hostname", "TEST1")
+ .property("source-of-truth", "AAI-EXTENSIONS").property("fqdn", "test1.com").property("test-list", "value1").next();
+
+ Vertex pInterface1 = g.addV().property("aai-node-type", "p-interface").property("interface-name", "p-interface1")
+ .property(AAIProperties.AAI_URI, "/cloud-infrastructure/pservers/pserver/TEST1/p-interfaces/p-interface/p-interface1").next();
+
+ Vertex pInterface2 = g.addV().property("aai-node-type", "p-interface").property("interface-name", "p-interface2")
+ .property(AAIProperties.AAI_URI, "/cloud-infrastructure/pservers/pserver/TEST1/p-interfaces/p-interface/p-interface2").next();
+
+ Vertex pInterface2Secondary = g.addV().property("aai-node-type", "p-interface").property("interface-name", "p-interface2").property("special-prop", "value")
+ .property(AAIProperties.AAI_URI, "/cloud-infrastructure/pservers/pserver/TEST1/p-interfaces/p-interface/p-interface2").next();
+
+ Vertex lInterface1 = g.addV().property("aai-node-type", "l-interface").property("interface-name", "l-interface1").property("special-prop", "value")
+ .property(AAIProperties.AAI_URI, "/cloud-infrastructure/pservers/pserver/TEST1/p-interfaces/p-interface/p-interface2/l-interfaces/l-interface/l-interface1").next();
+
+ Vertex lInterface1Canopi = g.addV().property("aai-node-type", "l-interface").property("interface-name", "l-interface1")
+ .property(AAIProperties.AAI_URI, "/cloud-infrastructure/pservers/pserver/TEST1/p-interfaces/p-interface/p-interface2/l-interfaces/l-interface/l-interface1").next();
+
+ Vertex logicalLink = g.addV().property("aai-node-type", "logical-link").property("link-name", "logical-link1")
+ .property(AAIProperties.AAI_URI, "/network/logical-links/logical-link/logical-link1").next();
+ Vertex pserverCanopi = g.addV().property("aai-node-type", "pserver").property("hostname", "TEST1")
+ .property("source-of-truth", "CANOPI-WS").property("fqdn", "test2.com").property("test-list", "value2").next();
+
+ Vertex complex1 = g.addV().property("aai-node-type", "complex").property("physical-location-id", "complex1")
+ .property("source-of-truth", "RO").next();
+
+ Vertex complex2 = g.addV().property("aai-node-type", "complex").property("physical-location-id", "complex2")
+ .property("source-of-truth", "RCT").next();
+
+ Vertex vserver1 = g.addV().property("aai-node-type", "vserver").property("vserver-id", "vserver1")
+ .property("source-of-truth", "RO").next();
+
+ Vertex vserver2 = g.addV().property("aai-node-type", "vserver").property("vserver-id", "vserver2")
+ .property("source-of-truth", "RCT").next();
+ Vertex vserver3 = g.addV().property("aai-node-type", "vserver").property("vserver-id", "vserver3")
+ .property("source-of-truth", "RCT").next();
+ Vertex vserver4 = g.addV().property("aai-node-type", "vserver").property("vserver-id", "vserver4")
+ .property("source-of-truth", "RCT").next();
+ Vertex vserver5 = g.addV().property("aai-node-type", "vserver").property("vserver-id", "vserver5")
+ .property("source-of-truth", "RCT").next();
+
+
+ rules.addEdge(g, pserverSkeleton, complex1);
+ rules.addEdge(g, pserverSkeleton, vserver1);
+ rules.addEdge(g, pserverSkeleton, vserver2);
+ rules.addTreeEdge(g, pserverSkeleton, pInterface1);
+ rules.addTreeEdge(g, pserverSkeleton, pInterface2Secondary);
+ rules.addTreeEdge(g, pInterface2Secondary, lInterface1);
+ rules.addEdge(g, lInterface1, logicalLink);
+ rules.addEdge(g, pserverCanopi, complex2);
+ rules.addEdge(g, pserverCanopi, vserver3);
+ rules.addEdge(g, pserverCanopi, vserver4);
+ rules.addEdge(g, pserverCanopi, vserver5);
+ rules.addTreeEdge(g, pserverCanopi, pInterface2);
+ rules.addTreeEdge(g, pInterface2, lInterface1Canopi);
+
+ Map<String, Set<String>> forceCopy = new HashMap<>();
+ Set<String> forceSet = new HashSet<>();
+ forceSet.add("fqdn");
+ forceCopy.put("pserver", forceSet);
+
+ TransactionalGraphEngine spy = spy(dbEngine);
+ TransactionalGraphEngine.Admin adminSpy = spy(dbEngine.asAdmin());
+ GraphTraversalSource traversal = g;
+ GraphTraversalSource readOnly = g;
+ when(spy.asAdmin()).thenReturn(adminSpy);
+ when(adminSpy.getTraversalSource()).thenReturn(traversal);
+ when(adminSpy.getReadOnlyTraversalSource()).thenReturn(readOnly);
+ DBSerializer serializer = new DBSerializer(version, spy, introspectorFactoryType, "Merge test");
+
+ VertexMerge merge = new VertexMerge.Builder(loader, spy, serializer).build();
+ merge.performMerge(pserverCanopi, pserverSkeleton, forceCopy);
+ }
+ @AfterClass
+ public static void cleanUp() {
+ tx.rollback();
+ graph.close();
+ }
+
+ @Test
+ public void run() throws UnsupportedEncodingException {
+
+ assertEquals("pserver merged", false, g.V().has("hostname", "TEST1").has("source-of-truth", "AAI-EXTENSIONS").hasNext());
+ assertThat("pserver list merge", Arrays.asList("value1", "value2"), containsInAnyOrder(g.V().has("hostname", "TEST1").values("test-list").toList().toArray()));
+ assertEquals("canopi pserver has one edge to vserver2", 1, g.V().has("hostname", "TEST1").both().has("vserver-id", "vserver2").toList().size());
+ assertEquals("canopi pserver has one edge to vserver1", 1, g.V().has("hostname", "TEST1").both().has("vserver-id", "vserver1").toList().size());
+ assertEquals("canopi pserver retained edge to complex2", true, g.V().has("hostname", "TEST1").both().has("physical-location-id", "complex2").hasNext());
+ assertEquals("canopi pserver received forced prop", "test1.com", g.V().has("hostname", "TEST1").values("fqdn").next());
+ assertEquals("pserver skeleton child copied", true, g.V().has("hostname", "TEST1").both().has("interface-name", "p-interface1").hasNext());
+ assertEquals("pserver skeleton child merged", true, g.V().has("hostname", "TEST1").both().has("interface-name", "p-interface2").has("special-prop", "value").hasNext());
+ assertEquals("l-interface child merged", true, g.V().has("hostname", "TEST1").both().has("interface-name", "p-interface2").both().has("interface-name", "l-interface1").has("special-prop", "value").hasNext());
+ assertEquals("l-interface child cousin edge merged", true, g.V().has("hostname", "TEST1").both().has("interface-name", "p-interface2").both().has("interface-name", "l-interface1").both().has("link-name", "logical-link1").hasNext());
+ assertEquals("one l-interface1 found", new Long(1), g.V().has("interface-name", "l-interface1").count().next());
+ assertEquals("one p-interface2 found", new Long(1), g.V().has("interface-name", "p-interface2").count().next());
+
+ }
+}
diff --git a/aai-resources/src/test/java/org/openecomp/aai/query/builder/TraversalQueryTest.java b/aai-resources/src/test/java/org/openecomp/aai/query/builder/TraversalQueryTest.java
deleted file mode 100644
index 694e99e..0000000
--- a/aai-resources/src/test/java/org/openecomp/aai/query/builder/TraversalQueryTest.java
+++ /dev/null
@@ -1,105 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * org.openecomp.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.openecomp.aai.query.builder;
-
-import static org.junit.Assert.assertEquals;
-
-import java.io.UnsupportedEncodingException;
-import java.net.URI;
-import java.net.URISyntaxException;
-
-import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;
-import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
-import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__;
-import org.apache.tinkerpop.gremlin.structure.Vertex;
-import org.junit.BeforeClass;
-import org.junit.Ignore;
-import org.junit.Test;
-import org.mockito.Mock;
-
-import org.openecomp.aai.db.props.AAIProperties;
-import org.openecomp.aai.exceptions.AAIException;
-import org.openecomp.aai.introspection.Introspector;
-import org.openecomp.aai.introspection.Loader;
-import org.openecomp.aai.introspection.LoaderFactory;
-import org.openecomp.aai.introspection.ModelType;
-//import org.openecomp.aai.serialization.queryformats.QueryFormatTestHelper;
-import org.openecomp.aai.util.AAIConstants;
-
-public class TraversalQueryTest {
-
- public static Loader loader;
- @Mock public GraphTraversalSource g;
- @BeforeClass
- public static void configure() throws NoSuchFieldException, SecurityException, Exception {
-
- System.setProperty("AJSC_HOME", ".");
- System.setProperty("BUNDLECONFIG_DIR", "bundleconfig-local");
-// QueryFormatTestHelper.setFinalStatic(AAIConstants.class.getField("AAI_HOME_ETC_OXM"), "src/test/resources/org/openecomp/aai/introspection/");
- loader = LoaderFactory.createLoaderForVersion(ModelType.MOXY, AAIProperties.LATEST);
- }
-
- @Test
- public void unionQuery() {
- TraversalQuery tQ = new TraversalQuery(loader, g);
- TraversalQuery tQ2 = new TraversalQuery(loader, g);
- TraversalQuery tQ3 = new TraversalQuery(loader, g);
- tQ.union(
- tQ2.getVerticesByProperty("test1", "value1"),
- tQ3.getVerticesByIndexedProperty("test2", "value2"));
-
- GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start()
- .union(__.has("test1", "value1"),__.has("test2", "value2"));
-
- assertEquals("they are equal", expected, tQ.getQuery());
-
- }
-
- @Test
- @Ignore
- public void traversalClones() throws UnsupportedEncodingException, AAIException, URISyntaxException {
- TraversalQuery tQ = new TraversalQuery(loader, g);
- Introspector test = loader.introspectorFromName("test-object");
- QueryBuilder 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");
-
- assertEquals("query object", expected.toString(), builder.getQuery().toString());
- assertEquals("container query object", containerExpected.toString(), builder.getContainerQuery().getQuery().toString());
-
- }
-
- @Test
- public void nestedTraversalClones() throws UnsupportedEncodingException, AAIException, URISyntaxException {
-
- TraversalQuery tQ = new TraversalQuery(loader, g);
- QueryBuilder 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");
-
- assertEquals("query object", expected.toString(), builder.getQuery().toString());
- assertEquals("container query object", containerExpected.toString(), builder.getContainerQuery().getQuery().toString());
-
- }
-
-
-
-}
diff --git a/aai-resources/src/test/java/org/openecomp/aai/schema/db/AuditOXMTest.java b/aai-resources/src/test/java/org/openecomp/aai/schema/db/AuditOXMTest.java
index 8188bdd..8e9e322 100644
--- a/aai-resources/src/test/java/org/openecomp/aai/schema/db/AuditOXMTest.java
+++ b/aai-resources/src/test/java/org/openecomp/aai/schema/db/AuditOXMTest.java
@@ -45,7 +45,7 @@ public class AuditOXMTest {
*/
@BeforeClass
public static void before() {
- System.setProperty("AJSC_HOME", "./src/test/resources/");;
+ System.setProperty("AJSC_HOME", ".");
System.setProperty("BUNDLECONFIG_DIR", "bundleconfig-local");
}
diff --git a/aai-resources/src/test/java/org/openecomp/aai/schema/db/ManageSchemaTest.java b/aai-resources/src/test/java/org/openecomp/aai/schema/db/ManageSchemaTest.java
index 9b7dd7c..9dade87 100644
--- a/aai-resources/src/test/java/org/openecomp/aai/schema/db/ManageSchemaTest.java
+++ b/aai-resources/src/test/java/org/openecomp/aai/schema/db/ManageSchemaTest.java
@@ -43,7 +43,7 @@ public class ManageSchemaTest {
private TitanGraph graph = null;
@BeforeClass
public static void before() {
- System.setProperty("AJSC_HOME", "./src/test/resources/");;
+ System.setProperty("AJSC_HOME", ".");
System.setProperty("BUNDLECONFIG_DIR", "bundleconfig-local");
}
diff --git a/aai-resources/src/test/java/org/openecomp/aai/util/AAITxnLogTest.java b/aai-resources/src/test/java/org/openecomp/aai/util/AAITxnLogTest.java
new file mode 100644
index 0000000..57ba3eb
--- /dev/null
+++ b/aai-resources/src/test/java/org/openecomp/aai/util/AAITxnLogTest.java
@@ -0,0 +1,361 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * org.openecomp.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.openecomp.aai.util;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.io.IOException;
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+import java.util.List;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hbase.HBaseConfiguration;
+import org.apache.hadoop.hbase.client.Get;
+import org.apache.hadoop.hbase.client.HTable;
+import org.apache.hadoop.hbase.client.Result;
+import org.apache.hadoop.hbase.client.ResultScanner;
+import org.apache.hadoop.hbase.client.Scan;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Rule;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.agent.PowerMockAgent;
+import org.powermock.modules.junit4.rule.PowerMockRule;
+
+import org.openecomp.aai.domain.notificationEvent.NotificationEvent;
+import org.openecomp.aai.domain.translog.TransactionLogEntries;
+import org.openecomp.aai.domain.translog.TransactionLogEntry;
+import org.openecomp.aai.exceptions.AAIException;
+import com.fasterxml.jackson.core.JsonGenerationException;
+import com.fasterxml.jackson.databind.JsonMappingException;
+
+
+@Ignore
+@PrepareForTest({HBaseConfiguration.class, Configuration.class,
+ HTable.class, Result.class, ResultScanner.class, Scan.class,
+ Get.class, NotificationEvent.class,
+ NotificationEvent.EventHeader.class, PojoUtils.class, AAITxnLog.class})
+
+public class AAITxnLogTest {
+
+ @Rule
+ public PowerMockRule rule = new PowerMockRule();
+
+ static {
+ PowerMockAgent.initializeIfNeeded();
+ }
+
+ AAITxnLog aaiTnxLog;
+ Configuration config;
+ HTable htable;
+ Result result;
+ ResultScanner resScanner;
+ Scan scan;
+ Get g;
+ NotificationEvent notif;
+ NotificationEvent.EventHeader ehNotif;
+ PojoUtils pu;
+
+ boolean hasNotifEvent = true;
+ final String notifPayload = "A random payload";
+ final String notifID = "1";
+ final String notifEntityLink = "nLink";
+ final String notifAction = "nAction";
+ final String notifStatus = "nStatus";
+ final String notifTopic = "nTopic";
+
+ final String tid = "tidVal";
+ final String status = "statusVal";
+ final String rqstTm = "rqstTmVal";
+ final String respTm = "respTmVal";
+ final String srcId = "srcIdVal";
+ final String rsrcId = "rsrcIdVal";
+ final String rsrcType = "rsrcTypeVal";
+ final String rqstBuf = "rqstBufVal";
+ final String respBuf = "respBufVal";
+
+
+ /**
+ * Initialize.
+ */
+ @Before
+ public void initialize(){
+ partialSetupForAAIConfig();
+ PowerMockito.mockStatic(HBaseConfiguration.class);
+ config = PowerMockito.mock(Configuration.class);
+ htable = PowerMockito.mock(HTable.class);
+ result = PowerMockito.mock(Result.class);
+ resScanner = PowerMockito.mock(ResultScanner.class);
+ scan = PowerMockito.mock(Scan.class);
+ g = PowerMockito.mock(Get.class);
+ notif = PowerMockito.mock(NotificationEvent.class);
+ ehNotif = PowerMockito.mock(NotificationEvent.EventHeader.class);
+ pu = PowerMockito.mock(PojoUtils.class);
+
+
+ mockNotificationEvent();
+
+ Mockito.when(HBaseConfiguration.create()).thenReturn(config);
+ aaiTnxLog = new AAITxnLog(tid, srcId);
+
+ try {
+ PowerMockito.whenNew(HTable.class).withAnyArguments().thenReturn(htable);
+ PowerMockito.whenNew(Get.class).withAnyArguments().thenReturn(g);
+ PowerMockito.whenNew(PojoUtils.class).withAnyArguments().thenReturn(pu);
+ PowerMockito.whenNew(Scan.class).withAnyArguments().thenReturn(scan);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ mockResult();
+
+ try {
+ PowerMockito.when(htable.get(g)).thenReturn(result);
+ PowerMockito.when(htable.getScanner(scan)).thenReturn(resScanner);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * Method to test 'put' operation without a notification event.
+ */
+ @Test
+ public void testPut_withoutNotifEvent(){
+ String htid = aaiTnxLog.put(tid, status, rqstTm, respTm, srcId, rsrcId, rsrcType, rqstBuf, respBuf);
+ try {
+ TransactionLogEntry tle = aaiTnxLog.get(htid);
+ hasNotifEvent = false;
+ validateTransactionLogEntry(tle);
+ } catch (AAIException e) {
+ fail("Cant read back data from htable");
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * Method to test 'put' operation with a notification event.
+ */
+ @Test
+ public void testPut_withNotifEvent(){
+ hasNotifEvent = true;
+ String htid = aaiTnxLog.put(tid, status, rqstTm, respTm, srcId, rsrcId, rsrcType, rqstBuf, respBuf, hasNotifEvent, notif);
+ try {
+ TransactionLogEntry tle = aaiTnxLog.get(htid);
+ validateTransactionLogEntry(tle);
+ } catch (AAIException e) {
+ fail("Cant read back data from htable");
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * Method to test 'scan' over an empty htable.
+ */
+ @Test
+ public void testScan_withEmptyHTable(){
+ String key = tid;
+ List<String> res = aaiTnxLog.scan(key);
+ assertTrue("Scan output should be empty", res.size() == 0 );
+ }
+
+ /**
+ * Method to test 'scan' operation.
+ */
+ @Test
+ public void testScan(){
+ try {
+ PowerMockito.when(resScanner.next()).thenReturn(result).thenReturn(null);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ List<String> res = aaiTnxLog.scan(tid);
+ assertTrue("Scan output should not be empty", res.size()==1);
+ assertTrue("Did not find entry in 'scan'", res.get(0).equals(result.toString()));
+ }
+
+ /**
+ * Method to test 'scanFiltered' with an empty htable.
+ */
+ @Test
+ public void testScanFiltered_withEmptyHTable(){
+ aaiTnxLog.put(tid, status, rqstTm, respTm, srcId, rsrcId, rsrcType, rqstBuf, respBuf, true, new NotificationEvent());
+ TransactionLogEntries tles = aaiTnxLog.scanFiltered(0, 100, null, null, null, null, null);
+ assertTrue ("scanFilstered output should be empty", tles.getTransactionLogEntries().size() == 0);
+ }
+
+ /**
+ * Method to test 'scanFiltered' operation.
+ */
+ @Test
+ public void testScanFiltered(){
+ try {
+ PowerMockito.when(resScanner.next()).thenReturn(result).thenReturn(null);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ aaiTnxLog.put(tid, status, rqstTm, respTm, srcId, rsrcId, rsrcType, rqstBuf, respBuf, true, new NotificationEvent());
+ TransactionLogEntries tles = aaiTnxLog.scanFiltered(0, 100, null, null, null, null, null);
+ assertFalse ("scanFilstered output should not be empty", tles.getTransactionLogEntries().size() == 0);
+ validateTransactionLogEntry(tles.getTransactionLogEntries().get(0));
+ }
+
+ /**
+ * Helper method to validate the contents of a TransactionalLogEntry.
+ *
+ * @param tle TransactionalLogEntry to compare against
+ */
+ public void validateTransactionLogEntry(TransactionLogEntry tle){
+ String pre = "validateTransactionLogEntry: ";
+ String post = " didn't match";
+ assertEquals(pre + "tid" + post, tle.getTransactionLogEntryId(), tid);
+ assertEquals(pre + "status" + post, tle.getStatus(), status);
+ assertEquals(pre + "rqstDate" + post, tle.getRqstDate(), rqstTm);
+ assertEquals(pre + "respDate" + post, tle.getRespDate(), respTm);
+ assertEquals(pre + "srcId" + post, tle.getSourceId(), srcId);
+ assertEquals(pre + "rsrcId" + post, tle.getResourceId(), rsrcId);
+ assertEquals(pre + "rqstBuf" + post, tle.getRqstBuf(), rqstBuf);
+ assertEquals(pre + "respBuf" + post, tle.getrespBuf(), respBuf);
+ if ( hasNotifEvent){
+ assertEquals(pre + "notifPayload" + post, tle.getNotificationPayload(), notifPayload);
+ assertEquals(pre + "notifStatus" + post, tle.getNotificationStatus(), notifStatus);
+ assertEquals(pre + "notifID" + post, tle.getNotificationId(), notifID);
+ assertEquals(pre + "notifTopic" + post, tle.getNotificationTopic(), notifTopic);
+ assertEquals(pre + "notifEntityLink" + post, tle.getNotificationEntityLink(), notifEntityLink);
+ assertEquals(pre + "notifAction" + post, tle.getNotificationAction(), notifAction);
+ }
+ }
+
+
+
+ /**
+ * Helper method to mock PojoUtils.
+ */
+ public void mockPojoUtils(){
+
+ try {
+ PowerMockito.when(pu.getJsonFromObject(notif)).thenReturn(notifPayload);
+ } catch (JsonGenerationException e) {e.printStackTrace();}
+ catch (JsonMappingException e) {e.printStackTrace();}
+ catch (IOException e) {e.printStackTrace(); }
+ }
+
+
+
+ /**
+ * Helper method to mock a notification event handler.
+ */
+ public void mockNotifEventHandler(){
+ PowerMockito.when(ehNotif.getId()).thenReturn(notifID);
+ PowerMockito.when(ehNotif.getEntityLink()).thenReturn(notifEntityLink);
+ PowerMockito.when(ehNotif.getAction()).thenReturn(notifAction);
+ PowerMockito.when(ehNotif.getStatus()).thenReturn(notifStatus);
+ }
+
+ /**
+ * Helper method to mock a notification event.
+ */
+ public void mockNotificationEvent(){
+ mockPojoUtils();
+ mockNotifEventHandler();
+ PowerMockito.when(notif.getEventHeader()).thenReturn(ehNotif);
+ PowerMockito.when(notif.getEventHeader().getEventType()).thenReturn(null);
+ PowerMockito.when(notif.getEventHeader().getStatus()).thenReturn(null);
+ }
+
+
+ /**
+ * Helper method to build a mock-Result.
+ */
+ public void mockResult(){
+ PowerMockito.when(result.getValue(Bytes.toBytes("transaction"),Bytes.toBytes("tid"))).thenReturn(Bytes.toBytes(tid));
+ PowerMockito.when(result.getValue(Bytes.toBytes("transaction"),Bytes.toBytes("status"))).thenReturn(Bytes.toBytes(status));
+ PowerMockito.when(result.getValue(Bytes.toBytes("transaction"),Bytes.toBytes("rqstDate"))).thenReturn(Bytes.toBytes(rqstTm));
+ PowerMockito.when(result.getValue(Bytes.toBytes("transaction"),Bytes.toBytes("respDate"))).thenReturn(Bytes.toBytes(respTm));
+ PowerMockito.when(result.getValue(Bytes.toBytes("transaction"),Bytes.toBytes("sourceId"))).thenReturn(Bytes.toBytes(srcId));
+
+ PowerMockito.when(result.getValue(Bytes.toBytes("resource"),Bytes.toBytes("resourceId"))).thenReturn(Bytes.toBytes(rsrcId));
+ PowerMockito.when(result.getValue(Bytes.toBytes("resource"),Bytes.toBytes("resourceType"))).thenReturn(Bytes.toBytes(rsrcType));
+
+ PowerMockito.when(result.getValue(Bytes.toBytes("payload"),Bytes.toBytes("rqstBuf"))).thenReturn(Bytes.toBytes(rqstBuf));
+ PowerMockito.when(result.getValue(Bytes.toBytes("payload"),Bytes.toBytes("respBuf"))).thenReturn(Bytes.toBytes(respBuf));
+
+ PowerMockito.when(result.getValue(Bytes.toBytes("notification"),Bytes.toBytes("notificationPayload"))).thenReturn(Bytes.toBytes(notifPayload));
+ PowerMockito.when(result.getValue(Bytes.toBytes("notification"),Bytes.toBytes("notificationStatus"))).thenReturn(Bytes.toBytes(notifStatus));
+ PowerMockito.when(result.getValue(Bytes.toBytes("notification"),Bytes.toBytes("notificationId"))).thenReturn(Bytes.toBytes(notifID));
+ PowerMockito.when(result.getValue(Bytes.toBytes("notification"),Bytes.toBytes("notificationTopic"))).thenReturn(Bytes.toBytes(notifTopic));
+ PowerMockito.when(result.getValue(Bytes.toBytes("notification"),Bytes.toBytes("notificationEntityLink"))).thenReturn(Bytes.toBytes(notifEntityLink));
+ PowerMockito.when(result.getValue(Bytes.toBytes("notification"),Bytes.toBytes("notificationAction"))).thenReturn(Bytes.toBytes(notifAction));
+ }
+
+
+ /**
+ * Helper method to load aai config from test configuration file
+ * This requires that the 'test_aaiconfig.properties' file is available
+ */
+
+ static void setFinalStatic(Field field, Object newValue) throws Exception {
+ field.setAccessible(true);
+ Field modifiersField = Field.class.getDeclaredField("modifiers");
+ modifiersField.setAccessible(true);
+ modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL);
+ field.set(null, newValue);
+ }
+
+ /**
+ * Partial setup for AAI config.
+ */
+ public void partialSetupForAAIConfig(){
+
+ try {
+ setFinalStatic(AAIConfig.class.getDeclaredField("GlobalPropFileName"), "src/test/resources/test_aaiconfig.properties");
+ }
+ catch (SecurityException e) {fail();}
+ catch (NoSuchFieldException e) {fail();}
+ catch (Exception e) {fail();}
+
+ AAIConfig.reloadConfig();
+ }
+
+ /**
+ * Helper method to set the file name of aaiconfig.properties file
+ *
+ * @param field Private static filed for update
+ * @param newValue New value to be used
+ * @throws Exception the exception
+ */
+ public void modifyFinalStatic(Field field, Object newValue) throws Exception {
+ field.setAccessible(true);
+ Field modifiersField = Field.class.getDeclaredField("modifiers");
+ modifiersField.setAccessible(true);
+ modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL);
+ field.set(null, newValue);
+ }
+
+}
diff --git a/aai-resources/src/test/java/org/openecomp/aai/util/DataConversionHelperTest.java b/aai-resources/src/test/java/org/openecomp/aai/util/DataConversionHelperTest.java
new file mode 100644
index 0000000..356010a
--- /dev/null
+++ b/aai-resources/src/test/java/org/openecomp/aai/util/DataConversionHelperTest.java
@@ -0,0 +1,88 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * org.openecomp.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.openecomp.aai.util;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.powermock.modules.agent.PowerMockAgent;
+import org.powermock.modules.junit4.rule.PowerMockRule;
+
+public class DataConversionHelperTest {
+
+ @Rule
+ public PowerMockRule rule = new PowerMockRule();
+
+ static {
+ PowerMockAgent.initializeIfNeeded();
+ }
+
+ /**
+ * Test convertIPVersionNumToString with value "4".
+ */
+ @Test
+ public void testConvertIPVersionNumToString_withNum4(){
+ assertEquals(DataConversionHelper.IPVERSION_IPV4, DataConversionHelper.convertIPVersionNumToString("4"));
+ }
+
+ /**
+ * Test convertIPVersionNumToString with value "6".
+ */
+ @Test
+ public void testConvertIPVersionNumToString_withNum6(){
+ assertEquals(DataConversionHelper.IPVERSION_IPV6, DataConversionHelper.convertIPVersionNumToString("6"));
+ }
+
+ /**
+ * Test convertIPVersionNumToString with a value other than "4" or "6".
+ */
+ @Test
+ public void testConvertIPVersionNumToString_withAThirdNumber(){
+ assertEquals(DataConversionHelper.IPVERSION_UNKNOWN, DataConversionHelper.convertIPVersionNumToString("-1"));
+ }
+
+ /**
+ * Test convertIPVersionStringToNum with "v4".
+ */
+ @Test
+ public void testConvertIPVersionStringToNum_withV4(){
+ assertEquals("4", DataConversionHelper.convertIPVersionStringToNum(DataConversionHelper.IPVERSION_IPV4));
+ }
+
+ /**
+ * Test convertIPVersionStringToNum with "v6".
+ */
+ @Test
+ public void testConvertIPVersionStringToNum_withV6(){
+ assertEquals("6", DataConversionHelper.convertIPVersionStringToNum(DataConversionHelper.IPVERSION_IPV6));
+ }
+
+ /**
+ * Test convertIPVersionStringToNum with an illegal version.
+ */
+ @Test
+ public void testConvertIPVersionStringToNum_withRandomString(){
+ assertEquals("0", DataConversionHelper.convertIPVersionStringToNum("test string"));
+ }
+
+
+}
diff --git a/aai-resources/src/test/java/org/openecomp/aai/util/DeleteResourceTest.java b/aai-resources/src/test/java/org/openecomp/aai/util/DeleteResourceTest.java
new file mode 100644
index 0000000..1522e80
--- /dev/null
+++ b/aai-resources/src/test/java/org/openecomp/aai/util/DeleteResourceTest.java
@@ -0,0 +1,108 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * org.openecomp.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.openecomp.aai.util;
+
+
+
+import static org.junit.Assert.assertEquals;
+
+import static org.junit.Assert.assertFalse;
+
+import static org.junit.Assert.assertTrue;
+
+import static org.junit.Assert.fail;
+
+import org.junit.Test;
+
+
+
+import org.openecomp.aai.domain.yang.PhysicalLink;
+
+
+
+public class DeleteResourceTest {
+
+
+
+ /**
+ * Test getInstance.
+ */
+
+ @Test
+
+ public void testGetInstance(){
+
+ Object obj = null;
+
+ try {
+
+ obj = DeleteResource.getInstance(DeleteResource.class);
+
+ } catch (IllegalAccessException | InstantiationException e) {
+
+ e.printStackTrace();
+
+ }
+
+ assertTrue("Didn't get right instance", obj instanceof DeleteResource);
+
+ }
+
+
+
+ /**
+ * Test GetResourceVersion.
+ */
+
+ @Test
+
+ public void testGetResourceVersion(){
+
+ String version = "aVersion";
+
+ PhysicalLink plink = new PhysicalLink();
+
+ plink.setResourceVersion(version);
+
+ assertEquals("Versions didn't match", version, DeleteResource.GetResourceVersion(plink));
+
+ }
+
+
+
+ /**
+ * Test null in GetResourceVersion.
+ */
+
+ @Test
+
+ public void testGetResourceVersion_withNull(){
+
+ PhysicalLink plink = new PhysicalLink();
+
+ assertEquals("Versions didn't match", null, DeleteResource.GetResourceVersion(plink));
+
+ }
+
+
+
+}
+
diff --git a/aai-resources/src/test/java/org/openecomp/aai/util/JettyObfuscationConversionCommandLineUtilTest.java b/aai-resources/src/test/java/org/openecomp/aai/util/JettyObfuscationConversionCommandLineUtilTest.java
new file mode 100644
index 0000000..e1fb24a
--- /dev/null
+++ b/aai-resources/src/test/java/org/openecomp/aai/util/JettyObfuscationConversionCommandLineUtilTest.java
@@ -0,0 +1,71 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * org.openecomp.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.openecomp.aai.util;
+
+import static org.junit.Assert.*;
+
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.junit.Test;
+
+
+public class JettyObfuscationConversionCommandLineUtilTest {
+ private final ByteArrayOutputStream testOut = new ByteArrayOutputStream();
+
+ /**
+ * Test.
+ */
+ @Test
+ public void test() {
+ //setup, this will catch main's print statements for evaluation
+ System.setOut(new PrintStream(testOut));
+
+ /* ------ TEST OBFUSCATION ----*/
+ JettyObfuscationConversionCommandLineUtil.main(new String[]{"-e", "hello world"});
+ /*
+ * testOut was also catching any logging statements which interfered with result checking.
+ * This regex business was the workaround - it tries to find the expected value in
+ * the results and asserts against that.
+ */
+ String obfResult = testOut.toString();
+ String obfExpected = "OBF:1thf1ugo1x151wfw1ylz11tr1ymf1wg21x1h1uh21th7";
+ Pattern obfExpectPat = Pattern.compile(obfExpected);
+ Matcher obfMatch = obfExpectPat.matcher(obfResult);
+ assertTrue(obfMatch.find());
+
+ testOut.reset(); //clear out previous result
+
+ /* ------ TEST DEOBFUSCATION ----- */
+ JettyObfuscationConversionCommandLineUtil.main(new String[]{"-d", obfExpected});
+ String deobfResult = testOut.toString();
+ String deobfExpected = "hello world";
+ Pattern deobfExpectPat = Pattern.compile(deobfExpected);
+ Matcher deobfMatch = deobfExpectPat.matcher(deobfResult);
+ assertTrue(deobfMatch.find());
+
+ //clean up, resets to stdout
+ System.setOut(null);
+ }
+
+}