From 8ed8d2f6cacc55263470af007d7ecec23666bbfc Mon Sep 17 00:00:00 2001 From: Venkata Harish K Kajur Date: Wed, 7 Jun 2017 23:53:59 -0400 Subject: [AAI-ONAP] Get latest changes from develop sync Change-Id: I2bf80b4af4e3db84cf61fd98bc0ad6efb5e0551b Signed-off-by: Venkata Harish K Kajur --- .../java/org/openecomp/aai/dbgen/DbMethTest.java | 90 ------ .../java/org/openecomp/aai/dbgen/DbRunTest.java | 341 --------------------- .../java/org/openecomp/aai/util/AAIUtilsTest.java | 112 ------- .../org/openecomp/aai/util/DeleteResourceTest.java | 108 ------- 4 files changed, 651 deletions(-) delete mode 100644 aai-resources/src/test/java/org/openecomp/aai/dbgen/DbMethTest.java delete mode 100644 aai-resources/src/test/java/org/openecomp/aai/dbgen/DbRunTest.java delete mode 100644 aai-resources/src/test/java/org/openecomp/aai/util/AAIUtilsTest.java delete mode 100644 aai-resources/src/test/java/org/openecomp/aai/util/DeleteResourceTest.java (limited to 'aai-resources/src/test/java/org') 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 deleted file mode 100644 index 420daa7..0000000 --- a/aai-resources/src/test/java/org/openecomp/aai/dbgen/DbMethTest.java +++ /dev/null @@ -1,90 +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.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 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 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 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 deleted file mode 100644 index cef8019..0000000 --- a/aai-resources/src/test/java/org/openecomp/aai/dbgen/DbRunTest.java +++ /dev/null @@ -1,341 +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.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 \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 propHash7 = new HashMap(); - propHash7.put("tenant-name", testIdentifier + "tenantName"); - propHash7.put("tenant-id", testIdentifier + "tenantId"); - TitanVertex tenantVtx = DbMeth.persistAaiNode("junkTransId", - "testApp", graph, "tenant", propHash7, true, null); - - - HashMap propHash8 = new HashMap(); - 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 propHash10 = new HashMap(); - propHash10.put("interface-name", testIdentifier + "logIntfOnVpe"); - TitanVertex logIntfVtx = DbMeth.persistAaiNode("junkTransId", - "testApp", graph, "l-interface", propHash10, true, vserverVtx); - - HashMap propHash11 = new HashMap(); - propHash11.put("vlan-interface", testIdentifier + "vlanIntf"); - TitanVertex vlanVtx = DbMeth.persistAaiNode("junkTransId", - "testApp", graph, "vlan", propHash11, true, logIntfVtx); - - HashMap propHash12 = new HashMap(); - 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 propHash0 = new HashMap(); - 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 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 relDatList = RelationshipUtils.figureRelData("junkTransId", "junkAppId", graph, poolV, ""); - System.out.println(processName + " ---- Looks like it worked ----------"); - Iterator iterDat = relDatList.iterator(); - while (iterDat.hasNext()) { - RelationshipData relDat = iterDat.next(); - System.out.println(processName + " relData: key = [" - + relDat.getRelationshipKey() + "], val = [" - + relDat.getRelationshipValue() + "]"); - }*/ - - - HashMap propHash = new HashMap(); - ArrayList vertList; - - propHash.put("tenant-id", testIdentifier + "tenantId"); - vertList = DbMeth.getNodes("junkTransId", - "testApp", graph, "tenant", propHash, false, null, true); - - Iterator 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(); - - 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/util/AAIUtilsTest.java b/aai-resources/src/test/java/org/openecomp/aai/util/AAIUtilsTest.java deleted file mode 100644 index 0bba892..0000000 --- a/aai-resources/src/test/java/org/openecomp/aai/util/AAIUtilsTest.java +++ /dev/null @@ -1,112 +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.util; - -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import java.text.DateFormat; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; -import java.util.TimeZone; -import java.util.concurrent.TimeUnit; - -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.powermock.modules.agent.PowerMockAgent; -import org.powermock.modules.junit4.rule.PowerMockRule; - -public class AAIUtilsTest { - - @Rule - public PowerMockRule rule = new PowerMockRule(); - - static { - PowerMockAgent.initializeIfNeeded(); - } - - - AAIUtils testObj; - - /** - * Initialize. - */ - @Before - public void initialize(){ - testObj = new AAIUtils(); - } - - /** - * Test nullCheck with null. - */ - @Test - public void testNullCheck_withNull(){ - List newList = null; - assertNotNull("method nullCheck should not return null", AAIUtils.nullCheck(newList)); - } - - /** - * Test nullCheck with a List. - */ - @Test - public void testNullCheck_withList(){ - List newList = new ArrayList(); - newList.add("testString"); - assertNotNull("method nullCheck failed for a List", AAIUtils.nullCheck(newList)); - } - - /** - * Test genDate using a past and a future date. - */ - @Test - public void testGenDate(){ - - Date d1 = new Date(0); - - DateFormat formatter = new SimpleDateFormat("YYMMdd-HH:mm:ss:SSS"); - formatter.setTimeZone(TimeZone.getTimeZone("GMT")); - formatter.setLenient(false); - - Date d2 = null; - - try { - d2 = formatter.parse(AAIUtils.genDate()); - } catch (ParseException e) { - fail("Date parsing exception"); - e.printStackTrace(); - } - - try { - TimeUnit.SECONDS.sleep(1); - } catch (InterruptedException e1) {} - - Date d3 = new Date(); - - assertTrue("Generated date is not after a past date", d2.after(d1)); - assertTrue("Generated date is not before a future date", d2.before(d3)); - } - -} 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 deleted file mode 100644 index 1522e80..0000000 --- a/aai-resources/src/test/java/org/openecomp/aai/util/DeleteResourceTest.java +++ /dev/null @@ -1,108 +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.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)); - - } - - - -} - -- cgit 1.2.3-korg