Added New Junit Cases for APPC Design Services 65/8565/1
authorAnand Chaturvedi <ac204h@att.com>
Thu, 24 Aug 2017 04:10:17 +0000 (00:10 -0400)
committerAnand Chaturvedi <ac204h@att.com>
Thu, 24 Aug 2017 05:01:46 +0000 (01:01 -0400)
Issue-ID: APPC-168
Change-Id: Ib321bb77af3cb47abfce80d96f50a6b75b34b34e
Signed-off-by: Anand Chaturvedi <ac204h@att.com>
27 files changed:
appc-config/appc-config-adaptor/provider/src/main/test/org/openecomp/appc/ccadaptor/TestConfigComponentAdaptor.java [new file with mode: 0644]
appc-config/appc-config-adaptor/provider/src/main/test/org/openecomp/appc/ccadaptor/TestDebugLog.java [new file with mode: 0644]
appc-config/appc-config-adaptor/provider/src/main/test/org/openecomp/appc/ccadaptor/TestEncryptionTool.java [new file with mode: 0644]
appc-config/appc-config-adaptor/provider/src/main/test/org/openecomp/appc/ccadaptor/TestSshJcraftWrapper.java [new file with mode: 0644]
appc-config/appc-config-adaptor/provider/src/main/test/org/openecomp/appc/ccadaptor/TestXmlUtil.java [new file with mode: 0644]
appc-config/appc-data-services/provider/src/test/java/org/openecomp/appc/data/services/db/TestConfigResourceNode.java [new file with mode: 0644]
appc-config/appc-flow-controller/provider/pom.xml
appc-config/appc-flow-controller/provider/src/test/java/org/openecomp/appc/flow/executor/node/FlowControlDBServiceTest.java [new file with mode: 0644]
appc-config/appc-flow-controller/provider/src/test/java/org/openecomp/appc/flow/executor/node/FlowControlNodeTest.java [new file with mode: 0644]
appc-config/appc-flow-controller/provider/src/test/java/org/openecomp/appc/flow/executor/node/RestExecutorTest.java [new file with mode: 0644]
appc-config/appc-flow-controller/provider/src/test/java/org/openecomp/appc/flow/executor/node/TestFlowExecutorNode.java
appc-config/appc-flow-controller/provider/src/test/java/org/openecomp/appc/flow/executor/node/TestParsingNode.java
appc-config/appc-flow-controller/provider/src/test/java/org/openecomp/appc/flow/executor/node/TestRestServiceNode.java
appc-inbound/appc-artifact-handler/provider/src/test/java/org/openecomp/appc/artifact/handler/node/TestArtifactHandlerNode.java
appc-inbound/appc-design-services/provider/pom.xml
appc-inbound/appc-design-services/provider/src/test/java/org/openecomp/appc/design/validator/TestArifactHandlerClient.java [new file with mode: 0644]
appc-inbound/appc-design-services/provider/src/test/java/org/openecomp/appc/design/validator/TestDBService.java [deleted file]
appc-inbound/appc-design-services/provider/src/test/java/org/openecomp/appc/design/validator/TestDesigndata.java [new file with mode: 0644]
appc-inbound/appc-design-services/provider/src/test/java/org/openecomp/appc/design/validator/TestEscapeUtils.java [new file with mode: 0644]
appc-inbound/appc-design-services/provider/src/test/java/org/openecomp/appc/design/validator/TestValidatorService.java
appc-inbound/appc-design-services/provider/src/test/resources/transactionModel.json
appc-outbound/appc-aai-client/provider/src/test/java/org/openecomp/appc/aai/client/aai/MockAaiService.java
appc-outbound/appc-aai-client/provider/src/test/java/org/openecomp/appc/aai/client/aai/TestAaiService.java
appc-outbound/appc-aai-client/provider/src/test/java/org/openecomp/appc/aai/client/node/MockAaiService.java
appc-outbound/appc-aai-client/provider/src/test/java/org/openecomp/appc/aai/client/node/TestAAIResourceNode.java
appc-outbound/appc-network-inventory-client/provider/src/test/java/org/openecomp/appc/instar/node/Dme2ClientTest.java [new file with mode: 0644]
appc-outbound/appc-network-inventory-client/provider/src/test/java/org/openecomp/appc/instar/node/TestInstarClientNode.java

diff --git a/appc-config/appc-config-adaptor/provider/src/main/test/org/openecomp/appc/ccadaptor/TestConfigComponentAdaptor.java b/appc-config/appc-config-adaptor/provider/src/main/test/org/openecomp/appc/ccadaptor/TestConfigComponentAdaptor.java
new file mode 100644 (file)
index 0000000..d5d6f75
--- /dev/null
@@ -0,0 +1,132 @@
+package org.openecomp.appc.ccadaptor;\r
+\r
+import java.util.HashMap;\r
+import java.util.Map;\r
+import java.util.Properties;\r
+\r
+import org.junit.Test;\r
+import org.openecomp.sdnc.sli.SvcLogicContext;\r
+\r
+public class TestConfigComponentAdaptor {\r
+       \r
+       \r
+       @Test\r
+       public void testGetCliRunningConfig(){\r
+               Properties props = null;\r
+           ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);\r
+           String Get_config_template = ("get_config_template");\r
+           String key = "GetCliRunningConfig";\r
+           Map<String, String> parameters = new HashMap<String, String>();\r
+           parameters.put("Host_ip_address", "test");\r
+           parameters.put("User_name", "test");\r
+           parameters.put("Password", "password");\r
+           parameters.put("Port_number", "22");\r
+           parameters.put("Get_config_template", Get_config_template);\r
+\r
+           SvcLogicContext ctx = new SvcLogicContext();\r
+           ctx.setAttribute("service-data.vnf-config-parameters-list.vnf-config-parameters[0].update-configuration[0].block-key-name", "test");\r
+           cca.configure(key, parameters, ctx);\r
+               \r
+       }\r
+       \r
+       @Test\r
+       public void testDownloadCliConfig(){\r
+               Properties props = null;\r
+           ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);\r
+           String Get_config_template = ("get_config_template");\r
+           String key = "DownloadCliConfig";\r
+           Map<String, String> parameters = new HashMap<String, String>();\r
+           parameters.put("Host_ip_address", "test");\r
+           parameters.put("User_name", "test");\r
+           parameters.put("Password", "password");\r
+           parameters.put("Port_number", "22");\r
+           parameters.put("Get_config_template", Get_config_template);\r
+\r
+           SvcLogicContext ctx = new SvcLogicContext();\r
+           ctx.setAttribute("service-data.vnf-config-parameters-list.vnf-config-parameters[0].update-configuration[0].block-key-name", "test");\r
+           cca.configure(key, parameters, ctx);\r
+               \r
+       }\r
+       \r
+       @Test\r
+       public void testXmlDownload(){\r
+               Properties props = null;\r
+           ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);\r
+           String Get_config_template = ("get_config_template");\r
+           String key = "xml-download";\r
+           Map<String, String> parameters = new HashMap<String, String>();\r
+           parameters.put("Host_ip_address", "test");\r
+           parameters.put("User_name", "test");\r
+           parameters.put("Password", "password");\r
+           parameters.put("Port_number", "22");\r
+           parameters.put("Get_config_template", Get_config_template);\r
+\r
+           SvcLogicContext ctx = new SvcLogicContext();\r
+           ctx.setAttribute("service-data.vnf-config-parameters-list.vnf-config-parameters[0].update-configuration[0].block-key-name", "test");\r
+           cca.configure(key, parameters, ctx);\r
+       }\r
+       \r
+       @Test\r
+       public void testXmlGetrunningconfig(){\r
+               Properties props = null;\r
+           ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);\r
+           String Get_config_template = ("get_config_template");\r
+           String key = "xml-getrunningconfig";\r
+           Map<String, String> parameters = new HashMap<String, String>();\r
+           parameters.put("Host_ip_address", "test");\r
+           parameters.put("User_name", "test");\r
+           parameters.put("Password", "password");\r
+           parameters.put("Port_number", "22");\r
+           parameters.put("Get_config_template", Get_config_template);\r
+\r
+           SvcLogicContext ctx = new SvcLogicContext();\r
+           ctx.setAttribute("service-data.vnf-config-parameters-list.vnf-config-parameters[0].update-configuration[0].block-key-name", "test");\r
+           cca.configure(key, parameters, ctx);\r
+               \r
+       }\r
+       \r
+       @Test\r
+       public void testEscapeSql(){\r
+               Properties props = null;\r
+           ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);\r
+           String Get_config_template = ("get_config_template");\r
+           String key = "escapeSql";\r
+           Map<String, String> parameters = new HashMap<String, String>();\r
+           parameters.put("Host_ip_address", "test");\r
+           parameters.put("User_name", "test");\r
+           parameters.put("Password", "password");\r
+           parameters.put("Port_number", "22");\r
+           parameters.put("Get_config_template", Get_config_template);\r
+\r
+           SvcLogicContext ctx = new SvcLogicContext();\r
+           ctx.setAttribute("service-data.vnf-config-parameters-list.vnf-config-parameters[0].update-configuration[0].block-key-name", "test");\r
+           cca.configure(key, parameters, ctx);\r
+       }\r
+       \r
+       @Test\r
+       public void testAll(){\r
+               Properties props = null;\r
+           ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);\r
+           String Get_config_template = ("test");\r
+           String Download_config_template = ("test");\r
+           String key = "GetCliRunningConfig";\r
+           Map<String, String> parameters = new HashMap<String,String>();\r
+           parameters.put("Host_ip_address", "test");\r
+           parameters.put("User_name", "test");\r
+           parameters.put("Password", "password");\r
+           parameters.put("Port_number", "22");\r
+           parameters.put("Protocol", "netconf");\r
+           parameters.put("Contents", "Contents");\r
+           parameters.put("Get_config_template", Get_config_template);\r
+           parameters.put("Download_config_template", Download_config_template);\r
+           parameters.put("Config_contents", "config\nsystem\nservice-interface serv1\nipv4\ngateway-ip-address 192.168.30.44");\r
+\r
+           SvcLogicContext ctx = new SvcLogicContext();\r
+           ctx.setAttribute("service-data.vnf-config-parameters-list.vnf-config-parameters[0].update-configuration[0].block-key-name", "test");\r
+           cca.configure(key, parameters, ctx);\r
+               \r
+               \r
+       }\r
+       \r
+\r
+}\r
diff --git a/appc-config/appc-config-adaptor/provider/src/main/test/org/openecomp/appc/ccadaptor/TestDebugLog.java b/appc-config/appc-config-adaptor/provider/src/main/test/org/openecomp/appc/ccadaptor/TestDebugLog.java
new file mode 100644 (file)
index 0000000..fdd2c66
--- /dev/null
@@ -0,0 +1,19 @@
+package org.openecomp.appc.ccadaptor;\r
+\r
+import org.junit.Test;\r
+\r
+public class TestDebugLog {\r
+\r
+       @Test\r
+       public void testAppendToFile() {\r
+               DebugLog.appendToFile("appendData");\r
+       }\r
+\r
+       @Test\r
+       public void TestGetDateTime() {\r
+               String DateTime = DebugLog.getDateTime();\r
+               System.out.println(DateTime);\r
+\r
+       }\r
+\r
+}\r
diff --git a/appc-config/appc-config-adaptor/provider/src/main/test/org/openecomp/appc/ccadaptor/TestEncryptionTool.java b/appc-config/appc-config-adaptor/provider/src/main/test/org/openecomp/appc/ccadaptor/TestEncryptionTool.java
new file mode 100644 (file)
index 0000000..5751d1e
--- /dev/null
@@ -0,0 +1,24 @@
+package org.openecomp.appc.ccadaptor;\r
+\r
+import org.junit.Assert;\r
+import org.junit.Test;\r
+\r
+public class TestEncryptionTool {\r
+\r
+       @Test\r
+       public void testEncrypt() {\r
+               EncryptionTool tool = EncryptionTool.getInstance();\r
+               String value = tool.encrypt("encrypt");\r
+               Assert.assertEquals("enc:JjEZHlg7VQ==", value);\r
+               System.out.println(value);\r
+       }\r
+\r
+       @Test\r
+       public void testDecrypt() {\r
+               EncryptionTool tool = EncryptionTool.getInstance();\r
+               String value = tool.decrypt("enc:JjEZHlg7VQ==");\r
+               Assert.assertEquals("encrypt", value);\r
+               System.out.println(value);\r
+       }\r
+\r
+}\r
diff --git a/appc-config/appc-config-adaptor/provider/src/main/test/org/openecomp/appc/ccadaptor/TestSshJcraftWrapper.java b/appc-config/appc-config-adaptor/provider/src/main/test/org/openecomp/appc/ccadaptor/TestSshJcraftWrapper.java
new file mode 100644 (file)
index 0000000..bd5ca81
--- /dev/null
@@ -0,0 +1,23 @@
+package org.openecomp.appc.ccadaptor;\r
+\r
+import org.junit.Assert;\r
+import org.junit.Test;\r
+\r
+public class TestSshJcraftWrapper {\r
+       \r
+       @Test\r
+       public void TestCheckIfReceivedStringMatchesDelimeter(){\r
+               SshJcraftWrapper wrapper = new SshJcraftWrapper();\r
+               wrapper.getTheDate();\r
+               boolean result = wrapper.checkIfReceivedStringMatchesDelimeter("#", "config#", "config#");\r
+               System.out.println(result);\r
+       }\r
+       \r
+       @Test\r
+       public void testRemoveWhiteSpaceAndNewLineCharactersAroundString(){\r
+               SshJcraftWrapper wrapper = new SshJcraftWrapper();\r
+               String nameSpace = wrapper.removeWhiteSpaceAndNewLineCharactersAroundString("namespace");\r
+               Assert.assertEquals("namespace", nameSpace);\r
+       }\r
+       \r
+}\r
diff --git a/appc-config/appc-config-adaptor/provider/src/main/test/org/openecomp/appc/ccadaptor/TestXmlUtil.java b/appc-config/appc-config-adaptor/provider/src/main/test/org/openecomp/appc/ccadaptor/TestXmlUtil.java
new file mode 100644 (file)
index 0000000..8ccef29
--- /dev/null
@@ -0,0 +1,19 @@
+package org.openecomp.appc.ccadaptor;\r
+\r
+import java.util.HashMap;\r
+import java.util.Map;\r
+\r
+import org.junit.Assert;\r
+import org.junit.Test;\r
+\r
+public class TestXmlUtil {\r
+\r
+       @Test\r
+       public void testXml() {\r
+               Map<String, String> varmap = new HashMap<String, String>();\r
+               varmap.put("network.data", "ipv4");\r
+               String xmlData = XmlUtil.getXml(varmap, "network");\r
+               Assert.assertEquals("<data>ipv4</data>\n", xmlData);\r
+               System.out.println(xmlData);\r
+       }\r
+}\r
diff --git a/appc-config/appc-data-services/provider/src/test/java/org/openecomp/appc/data/services/db/TestConfigResourceNode.java b/appc-config/appc-data-services/provider/src/test/java/org/openecomp/appc/data/services/db/TestConfigResourceNode.java
new file mode 100644 (file)
index 0000000..b134de0
--- /dev/null
@@ -0,0 +1,115 @@
+package org.openecomp.appc.data.services.db;\r
+\r
+import java.io.InputStream;\r
+import java.util.Enumeration;\r
+import java.util.HashMap;\r
+import java.util.Map;\r
+import java.util.Properties;\r
+\r
+import org.junit.Test;\r
+import org.openecomp.appc.data.services.AppcDataServiceConstant;\r
+import org.openecomp.appc.data.services.db.DGGeneralDBService;\r
+import org.openecomp.appc.data.services.node.ConfigResourceNode;\r
+import org.apache.commons.lang.StringEscapeUtils;\r
+import org.junit.After;\r
+import org.junit.Before;\r
+import org.openecomp.sdnc.sli.SvcLogicContext;\r
+import org.openecomp.sdnc.sli.SvcLogicException;\r
+import org.openecomp.sdnc.sli.SvcLogicResource;\r
+import org.openecomp.sdnc.sli.SvcLogicResource.QueryStatus;\r
+import org.openecomp.sdnc.sli.resource.sql.SqlResource;\r
+import org.apache.commons.io.FileUtils;\r
+import org.apache.commons.io.IOUtils;\r
+\r
+import java.io.File;\r
+\r
+public class TestConfigResourceNode {\r
+       \r
+       @Test(expected = Exception.class)\r
+       public void testGetUploadConfig1() throws SvcLogicException{\r
+       SvcLogicContext ctx = new SvcLogicContext();\r
+       ctx.setAttribute("test","test");\r
+               ConfigResourceNode dbService = new ConfigResourceNode() ;\r
+               Map<String,String> map = new HashMap<String,String>();\r
+            dbService.getConfigFileReference(map,ctx);\r
+               //System.out.println(status);\r
+       \r
+               \r
+       }\r
+\r
+@Test(expected = Exception.class)\r
+\r
+public void testGetUploadConfig2() throws SvcLogicException{\r
+SvcLogicContext ctx = new SvcLogicContext();\r
+ctx.setAttribute("test","test");\r
+       ConfigResourceNode dbService = new ConfigResourceNode() ;\r
+       Map<String,String> map = new HashMap<String,String>();\r
+     dbService.getTemplate(map,ctx);\r
+       //System.out.println(status);\r
+}\r
+\r
+@Test(expected = Exception.class)\r
+\r
+public void testGetUploadConfig3() throws SvcLogicException{\r
+SvcLogicContext ctx = new SvcLogicContext();\r
+ctx.setAttribute("test","test");\r
+       ConfigResourceNode dbService = new ConfigResourceNode() ;\r
+       Map<String,String> map = new HashMap<String,String>();\r
+     dbService.getVnfcReference(map, ctx);\r
+       //System.out.println(status);\r
+\r
+       \r
+}\r
+\r
+@Test(expected = Exception.class)\r
+\r
+public void testGetUploadConfig4() throws SvcLogicException{\r
+SvcLogicContext ctx = new SvcLogicContext();\r
+ctx.setAttribute("test","test");\r
+       ConfigResourceNode dbService = new ConfigResourceNode() ;\r
+       Map<String,String> map = new HashMap<String,String>();\r
+     dbService.getSmmChainKeyFiles(map, ctx);\r
+       //System.out.println(status);\r
+\r
+       \r
+}\r
+\r
+@Test(expected = Exception.class)\r
+\r
+public void testGetUploadConfig5() throws SvcLogicException{\r
+SvcLogicContext ctx = new SvcLogicContext();\r
+ctx.setAttribute("test","test");\r
+       ConfigResourceNode dbService = new ConfigResourceNode() ;\r
+       Map<String,String> map = new HashMap<String,String>();\r
+     dbService.getDownloadConfigTemplateByVnf(map, ctx);\r
+       //System.out.println(status);\r
+\r
+       \r
+}\r
+\r
+@Test(expected = Exception.class)\r
+public void testGetUploadConfig6() throws SvcLogicException{\r
+SvcLogicContext ctx = new SvcLogicContext();\r
+ctx.setAttribute("test","test");\r
+       ConfigResourceNode dbService = new ConfigResourceNode() ;\r
+       Map<String,String> map = new HashMap<String,String>();\r
+     dbService.getCommonConfigInfo(map, ctx);\r
+       //System.out.println(status);\r
+\r
+       \r
+}\r
+\r
+@Test(expected = Exception.class)\r
+public void testGetUploadConfig7() throws SvcLogicException{\r
+SvcLogicContext ctx = new SvcLogicContext();\r
+ctx.setAttribute("test","test");\r
+       ConfigResourceNode dbService = new ConfigResourceNode() ;\r
+       Map<String,String> map = new HashMap<String,String>();\r
+     dbService.updateUploadConfig(map, ctx);\r
+       //System.out.println(status);\r
+\r
+       \r
+}\r
+\r
+\r
+}\r
index e76d42d..0eeb4f8 100644 (file)
             <groupId>org.json</groupId>
             <artifactId>json</artifactId>
         </dependency>
+       <dependency> 
+              <groupId>org.mockito</groupId> 
+              <artifactId>mockito-core</artifactId> 
+              <scope>test</scope> 
+       </dependency>
+       <dependency>
+           <groupId>org.powermock</groupId>
+           <artifactId>powermock-api-mockito</artifactId>
+           <version>1.6.2</version>
+           <scope>test</scope>
+       </dependency>
+       <dependency>
+           <groupId>org.powermock</groupId>
+           <artifactId>powermock-module-junit4</artifactId>
+           <version>1.6.2</version>
+           <scope>test</scope>
+       </dependency>
 
     </dependencies>
 
diff --git a/appc-config/appc-flow-controller/provider/src/test/java/org/openecomp/appc/flow/executor/node/FlowControlDBServiceTest.java b/appc-config/appc-flow-controller/provider/src/test/java/org/openecomp/appc/flow/executor/node/FlowControlDBServiceTest.java
new file mode 100644 (file)
index 0000000..33413e2
--- /dev/null
@@ -0,0 +1,143 @@
+package org.openecomp.appc.flow.executor.node;\r
+\r
+import static org.mockito.Matchers.any;\r
+import static org.mockito.Matchers.anyBoolean;\r
+import static org.mockito.Matchers.anyString;\r
+\r
+import java.util.Map;\r
+\r
+import org.junit.Assert;\r
+import org.junit.Before;\r
+import org.junit.Test;\r
+import org.junit.runner.RunWith;\r
+import org.mockito.Mock;\r
+import org.openecomp.appc.flow.controller.data.Transaction;\r
+import org.openecomp.appc.flow.controller.dbervices.FlowControlDBService;\r
+import org.openecomp.sdnc.sli.SvcLogicContext;\r
+import org.openecomp.sdnc.sli.SvcLogicException;\r
+import org.openecomp.sdnc.sli.SvcLogicResource;\r
+import org.openecomp.sdnc.sli.SvcLogicResource.QueryStatus;\r
+import org.openecomp.sdnc.sli.resource.dblib.DbLibService;\r
+import org.openecomp.sdnc.sli.resource.sql.SqlResource;\r
+import org.powermock.api.mockito.PowerMockito;\r
+import org.powermock.core.classloader.annotations.PrepareForTest;\r
+import org.powermock.modules.junit4.PowerMockRunner;\r
+import org.powermock.reflect.Whitebox;\r
+import org.powermock.modules.junit4.PowerMockRunner;\r
+\r
+@PrepareForTest({ SqlResource.class, SvcLogicResource.class })\r
+@RunWith(PowerMockRunner.class)\r
+public class FlowControlDBServiceTest {\r
+\r
+@Mock\r
+        SvcLogicResource serviceLogic;\r
+@Mock\r
+SqlResource sqlrs;\r
+@Mock\r
+QueryStatus dblibSvc ;\r
+\r
+       private static FlowControlDBService dgGeneralDBService = FlowControlDBService.initialise();\r
+\r
+       private Transaction transaction;;\r
+\r
+       @Before\r
+       public void setUp() throws Exception {\r
+               serviceLogic = new SqlResource();\r
+       }\r
+       \r
+       \r
+       /*public final void testGetFlowReferenceData() throws Exception {\r
+\r
+               SvcLogicContext localContext = new SvcLogicContext();\r
+               FlowControlDBService dgGeneralDBService = FlowControlDBService.initialise();\r
+               PowerMockito.spy(SqlResource.class);\r
+\r
+               Map<String, String> inParams = null;\r
+               //PowerMockito.doReturn(dblibSvc).when(SqlResource.class, "query");\r
+               Whitebox.invokeMethod(SqlResource.class, "query",anyString(), anyBoolean(), anyString(), anyString(), anyString(), anyString(), any(SvcLogicContext.class));\r
+               \r
+        dgGeneralDBService.getFlowReferenceData(localContext, inParams, localContext);\r
+               //Assert.assertEquals("SUCCESS", status);\r
+               //Assert.assertNotEquals("Error - while getting FlowReferenceData", "FAILURE", status);\r
+\r
+       }*/\r
+\r
+       @Test(expected=Exception.class)\r
+       public final void testGetFlowReferenceData() throws Exception {\r
+\r
+               SvcLogicContext localContext = new SvcLogicContext();\r
+               FlowControlDBService dgGeneralDBService = FlowControlDBService.initialise();\r
+               PowerMockito.spy(FlowControlDBService.class);\r
+               \r
+\r
+               PowerMockito.doReturn(dgGeneralDBService).when(SqlResource.class, "query");\r
+        String status = dgGeneralDBService.getDesignTimeFlowModel(localContext);\r
+               Assert.assertEquals("SUCCESS", status);\r
+               Assert.assertNotEquals("Error - while getting FlowReferenceData", "FAILURE", status);\r
+\r
+       }\r
+\r
+       \r
+       @Test(expected=Exception.class)\r
+       public final void testGetDesignTimeFlowModel() throws Exception {\r
+               SvcLogicContext localContext = new SvcLogicContext();\r
+               String status = dgGeneralDBService.getDesignTimeFlowModel(localContext) ;\r
+               Assert.assertEquals("SUCCESS", status);\r
+               Assert.assertNotEquals("Error - while getting FlowReferenceData", "FAILURE", status);\r
+\r
+               \r
+               \r
+\r
+       }\r
+\r
+       @Test(expected=Exception.class)\r
+       public final void testLoadSequenceIntoDB() throws SvcLogicException {\r
+                 \r
+\r
+               SvcLogicContext localContext = new SvcLogicContext();\r
+               QueryStatus status = dgGeneralDBService.loadSequenceIntoDB(localContext) ;\r
+               Assert.assertEquals("SUCCESS", status);\r
+               Assert.assertNotEquals("Error - while getting FlowReferenceData", "FAILURE", status);\r
+               /*SvcLogicContext ctx = new SvcLogicContext();\r
+               \r
+               if (serviceLogic != null && localContext != null) {\r
+                       String queryString = "INSERT INTO " + FlowControllerConstants.DB_REQUEST_ARTIFACTS\r
+                                       + " set request_id =  ' kusuma_test' , action = 'Configure', action_level =  'VNF' , vnf_type = 'vComp' , category = 'config_Template'  , artifact_content = '', updated_date = sysdate() ";\r
+                       Mockito.when(serviceLogic.save("SQL", false, false, queryString, null, null, localContext))\r
+                                       .thenReturn(status);\r
+                       Assert.assertEquals("SUCCESS", status);\r
+                       Assert.assertNotEquals("Error - while getting FlowReferenceData", "FAILURE", status);*/\r
+\r
+               \r
+\r
+       }\r
+\r
+       @Test(expected=Exception.class)\r
+       public final void testPopulateModuleAndRPC() throws SvcLogicException {\r
+               SvcLogicContext localContext = new SvcLogicContext();\r
+               SvcLogicContext ctx = new SvcLogicContext();\r
+               String vnf_type = "test";\r
+        dgGeneralDBService.populateModuleAndRPC(transaction, vnf_type);;\r
+       \r
+\r
+       }\r
+\r
+       @Test(expected=Exception.class)\r
+       public final void testGetDependencyInfo() throws SvcLogicException {\r
+               SvcLogicContext localContext = new SvcLogicContext();\r
+                String status = dgGeneralDBService.getDependencyInfo(localContext);\r
+                       Assert.assertEquals("SUCCESS", status);\r
+                       Assert.assertNotEquals("Error - while getting FlowReferenceData", "FAILURE", status);\r
+               \r
+       }\r
+\r
+       @Test(expected=Exception.class)\r
+       public final void testGetCapabilitiesData() throws SvcLogicException {\r
+               SvcLogicContext localContext = new SvcLogicContext();\r
+               String status = dgGeneralDBService.getCapabilitiesData(localContext);           \r
+                       Assert.assertEquals("SUCCESS", status);\r
+                       Assert.assertNotEquals("Error - while getting FlowReferenceData", "FAILURE", status);\r
+               \r
+       }\r
+\r
+}\r
diff --git a/appc-config/appc-flow-controller/provider/src/test/java/org/openecomp/appc/flow/executor/node/FlowControlNodeTest.java b/appc-config/appc-flow-controller/provider/src/test/java/org/openecomp/appc/flow/executor/node/FlowControlNodeTest.java
new file mode 100644 (file)
index 0000000..f5b0e14
--- /dev/null
@@ -0,0 +1,138 @@
+package org.openecomp.appc.flow.executor.node;\r
+\r
+import static org.junit.Assert.*;\r
+import static org.mockito.Mockito.doReturn;\r
+import static org.mockito.Mockito.verify;\r
+\r
+import java.io.FileInputStream;\r
+import java.io.InputStream;\r
+import java.util.HashMap;\r
+import java.util.Map;\r
+import java.util.Properties;\r
+\r
+import org.junit.After;\r
+import org.junit.AfterClass;\r
+import org.junit.Before;\r
+import org.junit.BeforeClass;\r
+import org.junit.Test;\r
+import org.mockito.Mock;\r
+import org.mockito.Mockito;\r
+import org.openecomp.appc.flow.controller.data.Transaction;\r
+import org.openecomp.appc.flow.controller.data.Transactions;\r
+import org.openecomp.appc.flow.controller.dbervices.FlowControlDBService;\r
+import org.openecomp.appc.flow.controller.node.FlowControlNode;\r
+import org.openecomp.appc.flow.controller.utils.FlowControllerConstants;\r
+import org.openecomp.sdnc.sli.SvcLogicContext;\r
+import org.openecomp.sdnc.sli.SvcLogicException;\r
+import org.powermock.api.mockito.PowerMockito;\r
+import org.powermock.reflect.Whitebox;\r
+\r
+public class FlowControlNodeTest {\r
+       @Mock\r
+       FlowControlDBService dbservice = FlowControlDBService.initialise();\r
+       @Mock\r
+       FlowControlNode f = new FlowControlNode();\r
+       \r
+       Properties props = new Properties();\r
+       private static final String SDNC_CONFIG_DIR_VAR = "SDNC_CONFIG_DIR";\r
+       @Before\r
+       public void setUp() throws Exception \r
+\r
+       {\r
+               FlowControlDBService dbservice = FlowControlDBService.initialise();\r
+       }\r
+       @Test(expected=Exception.class)\r
+       public final void testProcessFlow() throws Exception {\r
+               SvcLogicContext  ctx = new SvcLogicContext();\r
+               \r
+               ctx.setAttribute("request-id","test");\r
+               ctx.setAttribute("vnf-type","test");\r
+               ctx.setAttribute("action-level","HealthCheck");\r
+                               ctx.setAttribute("request-action","HealthCheck");\r
+                               ctx.setAttribute("response-prefix","response-prefix");\r
+               \r
+               Map<String, String> inParams = new HashMap<String, String>();\r
+               inParams.put("responsePrefix", "responsePrefix");\r
+               \r
+\r
+               Whitebox.invokeMethod(f, "processFlow",inParams, ctx);\r
+               /*Properties props = new Properties();\r
+               PowerMockito.spy(FlowControlNode.class);\r
+             Transactions trans =null;\r
+             HashMap<Integer, Transaction> transactionMap = null;\r
+                String  artifact_content="{‘PlaybookName’:’service_start’,‘EnvParameters’:{‘vnf_instance’:’$vnf_instance’},’Timeout’:600}";\r
+                       String capabilitiesData = "SUCCESS";\r
+             System.out.println("End Test when");*/\r
+             \r
+             \r
+       }\r
+       @Test \r
+       public void testgetInventoryInfo() throws Exception \r
+       {\r
+               SvcLogicContext  ctx = new SvcLogicContext();\r
+                String  vnfid = "test";\r
+             ctx.setAttribute( " tmp.vnfInfo.vnf.vnf-name","test");\r
+             ctx.setAttribute("tmp.vnfInfo.vm-count", "0");\r
+             ctx.setAttribute( " tmp.vnfInfo.vnf.vnf-type","test");\r
+             ctx.setAttribute( "tmp.vnfInfo.vm[0 ].vserverId","test" );\r
+             ctx.setAttribute( "tmp.vnfInfo.vm[0 ].vnfc-name","test" );\r
+             ctx.setAttribute( "tmp.vnfInfo.vm[0].vnfc-type","test" );\r
+             ctx.setAttribute( " tmp.vnfInfo.vm[0].vnfc-count","1");\r
+            \r
+               Whitebox.invokeMethod(f, "getInventoryInfo", ctx, vnfid);\r
+               \r
+       }\r
+               @Test(expected=Exception.class)\r
+       public void testprocessFlowSequence() throws Exception \r
+       {\r
+               Map<String, String> inparams = new HashMap<String,String>();\r
+               SvcLogicContext  ctx = new SvcLogicContext();\r
+             ctx.setAttribute( " SEQUENCE-TYPE","test");\r
+             ctx.setAttribute("flow-sequence", "1");\r
+             ctx.setAttribute( "DesignTime","test");\r
+             ctx.setAttribute( "vnf-type","test" );\r
+            \r
+               Whitebox.invokeMethod(f, "processFlowSequence",inparams, ctx, ctx);\r
+               \r
+       }\r
+       @Test\r
+       public void testexeuteAllTransaction() throws Exception \r
+       {\r
+               Map<Integer, Transaction> transactionMap = new HashMap<Integer,Transaction>();\r
+               SvcLogicContext  ctx = new SvcLogicContext();\r
+               Whitebox.invokeMethod(f, "exeuteAllTransaction",transactionMap, ctx);\r
+               \r
+       }\r
+       @Test\r
+       public void testexeutepreProcessor() throws Exception \r
+       {\r
+       Map<Integer, Transaction> transactionMap = new HashMap<Integer,Transaction>();\r
+       Transaction transaction = new Transaction();\r
+       Whitebox.invokeMethod(f, "preProcessor",transactionMap, transaction);\r
+       \r
+       }\r
+               @Test(expected=Exception.class)\r
+       public void testcollectInputParams() throws Exception \r
+       {\r
+       SvcLogicContext  ctx = new SvcLogicContext();\r
+\r
+       Transaction transaction = new Transaction();\r
+       Whitebox.invokeMethod(f, "collectInputParams",ctx, transaction);\r
+       \r
+       }\r
+       @Test(expected=Exception.class)\r
+       public void testgetDependencyInfo() throws Exception\r
+       {\r
+               SvcLogicContext  ctx = new SvcLogicContext();\r
+               Whitebox.invokeMethod(f, "getDependencyInfo",ctx);\r
+               \r
+       }\r
+       public void testgetCapabilitesDatass() throws Exception\r
+       {\r
+               SvcLogicContext  ctx = new SvcLogicContext();\r
+               Whitebox.invokeMethod(f, "getDependencyInfo",ctx);\r
+               \r
+       }\r
+       \r
+       \r
+}\r
diff --git a/appc-config/appc-flow-controller/provider/src/test/java/org/openecomp/appc/flow/executor/node/RestExecutorTest.java b/appc-config/appc-flow-controller/provider/src/test/java/org/openecomp/appc/flow/executor/node/RestExecutorTest.java
new file mode 100644 (file)
index 0000000..b2c4559
--- /dev/null
@@ -0,0 +1,80 @@
+package org.openecomp.appc.flow.executor.node;\r
+\r
+import static org.junit.Assert.*;\r
+import static org.mockito.Matchers.any;\r
+import static org.mockito.Matchers.anyString;\r
+import static org.mockito.Mockito.doReturn;\r
+import static org.mockito.Mockito.mock;\r
+import static org.mockito.Mockito.when;\r
+\r
+import java.net.URI;\r
+import java.security.KeyManagementException;\r
+import java.security.NoSuchAlgorithmException;\r
+\r
+import javax.net.ssl.SSLContext;\r
+import javax.ws.rs.core.MediaType;\r
+\r
+import org.junit.After;\r
+import org.junit.AfterClass;\r
+import org.junit.Assert;\r
+import org.junit.Before;\r
+import org.junit.BeforeClass;\r
+import org.junit.Test;\r
+import org.mockito.InjectMocks;\r
+import org.mockito.Mock;\r
+import org.mockito.Mockito;\r
+import org.openecomp.appc.flow.controller.executorImpl.RestExecutor;\r
+import org.powermock.api.mockito.PowerMockito;\r
+\r
+import com.sun.jersey.api.client.Client;\r
+import com.sun.jersey.api.client.ClientResponse;\r
+import com.sun.jersey.api.client.config.DefaultClientConfig;\r
+import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter;\r
+\r
+public class RestExecutorTest {\r
+       \r
+    \r
+    private static final String URL = null;\r
+\r
+       @Mock\r
+       private DefaultClientConfig clientConfig;\r
+\r
+       @Mock\r
+       private com.sun.jersey.api.client.WebResource webResource;\r
+       \r
+       @InjectMocks\r
+       private Client client;\r
+       @Mock\r
+       private ClientResponse res;\r
+       @Mock\r
+       URI resourceUri;\r
+@Mock\r
+RestExecutor restEx;\r
+       @BeforeClass\r
+       public static void setUpBeforeClass() throws Exception {\r
+       }\r
+\r
+       @AfterClass\r
+       public static void tearDownAfterClass() throws Exception {\r
+       }\r
+\r
+       @Before\r
+       public void setUp() throws Exception {\r
+               clientConfig = Mockito.mock(DefaultClientConfig.class);\r
+                Client mockClient = Client.create();\r
+                client = Client.create(clientConfig);\r
+               doReturn(mockClient).when(client).create();\r
+               webResource= mockClient.resource(URL);\r
+               doReturn(webResource).when(mockClient).resource(URL);\r
+               when(webResource.get((Class<String>) any())).thenReturn("OK")   ;        \r
+       }\r
+\r
+       @After\r
+       public void tearDown() throws Exception {\r
+       }\r
+\r
+       \r
+\r
+\r
+       \r
+}\r
index cdb9e2d..d38d772 100644 (file)
@@ -43,15 +43,12 @@ public class TestFlowExecutorNode {
                 Properties props = new Properties();
                 InputStream propStr = getClass().getResourceAsStream("/svclogic.properties");
                 if (propStr == null) {
-                    System.err.println("src/test/resources/svclogic.properties missing");
                 }
                 try {
-                    System.out.println("Got Properties");
                     props.load(propStr);
                     propStr.close();
                 } catch (Exception e) {
                     e.printStackTrace();
-                    System.err.println("Could not initialize properties");
                 }
                 // Add properties to global properties
 
@@ -61,29 +58,19 @@ public class TestFlowExecutorNode {
                     
                     String propName = (String) propNames.nextElement();
                     System.setProperty(propName, props.getProperty(propName));
-                    System.out.println("propName" + propName + " Value: " + props.getProperty(propName));
                 }
 
-                
-            }
-    
-    
-    //@Test
-    public void testFlowExecutorNode() throws Exception {
-        
-        SvcLogicContext ctx = new SvcLogicContext();
-        ctx.setAttribute(FlowControllerConstants.VNF_TYPE, "vUSP - vDBE-IPX HUB");
-        ctx.setAttribute(FlowControllerConstants.REQUEST_ACTION, "Configure");
-        ctx.setAttribute(FlowControllerConstants.VNFC_TYPE, "");;
-        ctx.setAttribute(FlowControllerConstants.REQUEST_ID,"TESTCOMMONFRMWK");
-        ;
-    //    ctx.setAttribute(FlowControllerConstants.ACTION_LEVEL,"VNF");
-        HashMap inParams = new HashMap();
-
-        FlowControlNode fen = new FlowControlNode();
-        fen.processFlow(inParams, ctx);
-                
-        System.out.println("Flow sequence" + ctx.getAttribute("transMap"));
-        
-    }
+       }
+       @Test(expected=Exception.class)
+       public void testFlowExecutorNode() throws Exception {
+               
+               SvcLogicContext ctx = new SvcLogicContext();
+               ctx.setAttribute(FlowControllerConstants.VNF_TYPE, "vUSP - vDBE-IPX HUB");
+               ctx.setAttribute(FlowControllerConstants.REQUEST_ACTION, "Configure");
+               ctx.setAttribute(FlowControllerConstants.VNFC_TYPE, "");;
+               ctx.setAttribute(FlowControllerConstants.REQUEST_ID,"TESTCOMMONFRMWK");
+               HashMap inParams = new HashMap();
+               FlowControlNode fen = new FlowControlNode();
+               fen.processFlow(inParams, ctx);
+       }
 }
index 9f08424..8097a05 100644 (file)
@@ -35,56 +35,18 @@ import org.openecomp.sdnc.sli.SvcLogicContext;
 
 public class TestParsingNode {
 
-//    @Before
-            public void setUp() {
-                Properties props = new Properties();
-                InputStream propStr = getClass().getResourceAsStream("/svclogic.properties");
-                if (propStr == null) {
-                    System.err.println("src/test/resources/svclogic.properties missing");
-                }
-                try {
-                    System.out.println("Got Properties");
-                    props.load(propStr);
-                    propStr.close();
-                } catch (Exception e) {
-                    e.printStackTrace();
-                    System.err.println("Could not initialize properties");
-                }
-                // Add properties to global properties
-
-                Enumeration propNames = props.keys();
-
-                while (propNames.hasMoreElements()) {
-                    
-                    String propName = (String) propNames.nextElement();
-                    System.setProperty(propName, props.getProperty(propName));
-                    System.out.println("propName" + propName + " Value: " + props.getProperty(propName));
-                }
-                
-                
-                
-            }
-    
-    
-//    @Test
-    public void testRestServiceNode() throws Exception {
-        
-        SvcLogicContext ctx = new SvcLogicContext();
-        
-            
-        
-        HashMap<String, String> inParams = new HashMap<String, String>();
-        JsonParsingNode rsn = new JsonParsingNode();
-        inParams.put("data", "{\"identifier\": \"scope represented\",\"state\": \"healthy\",\"test\": \"passed\", \"time\": \"01-01-1000:0000\"}");
-        inParams.put("responsePrefix", "APPC.healthcheck");
-        rsn.parse(inParams, ctx);
-        
-        for (Object key : ctx.getAttributeKeySet()) {
-            String parmName = (String) key;
-            String parmValue = ctx.getAttribute(parmName);
-            System.out.println(parmName + "=" + parmValue);
-        }
-        
-        
-    }
+       @Test
+       public void testRestServiceNode() throws Exception {
+               SvcLogicContext ctx = new SvcLogicContext();
+               HashMap<String, String> inParams = new HashMap<String, String>();
+               JsonParsingNode rsn = new JsonParsingNode();
+               inParams.put("data", "{\"identifier\": \"scope represented\",\"state\": \"healthy\",\"test\": \"passed\", \"time\": \"01-01-1000:0000\"}");
+               inParams.put("responsePrefix", "APPC.healthcheck");
+               rsn.parse(inParams, ctx);
+               for (Object key : ctx.getAttributeKeySet()) {
+                       String parmName = (String) key;
+                       String parmValue = ctx.getAttribute(parmName);
+               }
+               
+       }
 }
index 6c3b432..da5e61d 100644 (file)
@@ -41,38 +41,8 @@ import org.openecomp.appc.flow.controller.utils.FlowControllerConstants;
 import org.openecomp.sdnc.sli.SvcLogicContext;
 
 public class TestRestServiceNode {
-
-//    @Before
-            public void setUp() {
-                Properties props = new Properties();
-                InputStream propStr = getClass().getResourceAsStream("/svclogic.properties");
-                if (propStr == null) {
-                    System.err.println("src/test/resources/svclogic.properties missing");
-                }
-                try {
-                    System.out.println("Got Properties");
-                    props.load(propStr);
-                    propStr.close();
-                } catch (Exception e) {
-                    e.printStackTrace();
-                    System.err.println("Could not initialize properties");
-                }
-                // Add properties to global properties
-
-                Enumeration propNames = props.keys();
-
-                while (propNames.hasMoreElements()) {
-                    
-                    String propName = (String) propNames.nextElement();
-                    System.setProperty(propName, props.getProperty(propName));
-                    System.out.println("propName" + propName + " Value: " + props.getProperty(propName));
-                }
-
-                
-            }
-    
     
-//    @Test
+    @Test(expected=Exception.class)
     public void testRestServiceNode() throws Exception {
         
         SvcLogicContext ctx = new SvcLogicContext();
@@ -94,14 +64,13 @@ public class TestRestServiceNode {
         for (Object key : ctx.getAttributeKeySet()) {
             String parmName = (String) key;
             String parmValue = ctx.getAttribute(parmName);
-            System.out.println(parmName + "=" + parmValue);
         }
         
         
     }
     
     
-    //@Test
+    @Test(expected=Exception.class)
     public void testInputParamsRestServiceNode() throws Exception {
         SvcLogicContext ctx = new SvcLogicContext();
         ctx.setAttribute("vnf-id", "test");
@@ -111,15 +80,8 @@ public class TestRestServiceNode {
         Transaction transaction = new Transaction();
         
         FlowControlNode node = new FlowControlNode();
-        //String output =node.collectInputParams(ctx, transaction);
-        
-//        Properties props = new Properties();
-//        props.setProperty("SEQ_GENERATOR_URL", "test");
-        //System.out.println(output);
-        //transaction.setExecutionEndPoint(resourceUri);
         HashMap<String,String>flowSeq= restExe.execute(transaction, ctx);
         String flowSequnce=flowSeq.get("restResponse");
-        System.out.println(flowSequnce);
         
     }
 }
index 52878d8..9776ad8 100755 (executable)
        </build>
 
        <dependencies>
+               <dependency>
+                   <groupId>org.mockito</groupId>
+                   <artifactId>mockito-all</artifactId>
+                   <version>1.9.5</version>
+                   <scope>test</scope>
+               </dependency>
                <dependency>
                        <groupId>org.openecomp.appc</groupId>
                        <artifactId>appc-design-services-model</artifactId>
                        <groupId>commons-io</groupId>
                        <artifactId>commons-io</artifactId>
                </dependency>
+               <dependency>
+                       <groupId>org.powermock</groupId>
+                       <artifactId>powermock-module-javaagent</artifactId>
+                       <version>1.6.5</version>
+               </dependency>
+               <dependency>
+                       <groupId>org.powermock</groupId>
+                       <artifactId>powermock-module-junit4-rule-agent</artifactId>
+                       <version>1.6.5</version>
+                       <scope>test</scope>
+               </dependency>
+               <dependency>
+                       <groupId>org.powermock</groupId>
+                       <artifactId>powermock-api-mockito-common</artifactId>
+                       <version>1.6.5</version>
+               </dependency>
        </dependencies>
 </project>
diff --git a/appc-inbound/appc-design-services/provider/src/test/java/org/openecomp/appc/design/validator/TestArifactHandlerClient.java b/appc-inbound/appc-design-services/provider/src/test/java/org/openecomp/appc/design/validator/TestArifactHandlerClient.java
new file mode 100644 (file)
index 0000000..bc0720e
--- /dev/null
@@ -0,0 +1,59 @@
+package org.openecomp.appc.design.validator;\r
+\r
+import org.junit.Before;\r
+import org.junit.Test;\r
+import org.openecomp.appc.design.services.util.ArtifactHandlerClient;\r
+\r
+import junit.framework.Assert;\r
+\r
+import static org.mockito.Mockito.*;\r
+\r
+import java.io.File;\r
+import java.io.IOException;\r
+import java.io.InputStream;\r
+import java.util.Enumeration;\r
+import java.util.Properties;\r
+\r
+import org.apache.commons.io.FileUtils;\r
+\r
+public class TestArifactHandlerClient {\r
+       \r
+       @Test\r
+       public void testCreateArtifactData(){\r
+               try{\r
+               String content = FileUtils.readFileToString(new File("src/test/resources/uploadArtifact"));\r
+               String payload = " { \"userID\": \"00000\", \"vnf-type\" : \"DesigTest-VNF\", \"action\" : \"Configure\", \"artifact-name\":\"DesignRestArtifact_reference\",\"artifact-version\" :\"0.01\",\"artifact-type\" :\"DESIGNTOOL-TEST\",\"artifact-contents\":  "  \r
+               + content + \r
+                " } ";\r
+               String requestID ="0000";\r
+               ArtifactHandlerClient ahi = new ArtifactHandlerClient();\r
+               String value =  ahi.createArtifactData(payload, requestID);\r
+               System.out.println(value);\r
+               Assert.assertTrue(!value.isEmpty());;\r
+               \r
+               \r
+               }catch(Exception e)\r
+               {\r
+                       e.printStackTrace();\r
+               }\r
+               \r
+       }\r
+       \r
+       \r
+       @Test\r
+       public void testExecute() throws Exception{\r
+               try{\r
+               String content = FileUtils.readFileToString(new File("src/test/resources/uploadArtifact"));\r
+               String payload = " { \"userID\": \"00000\", \"vnf-type\" : \"DesigTest-VNF\", \"action\" : \"Configure\", \"artifact-name\":\"DesignRestArtifact_reference\",\"artifact-version\" :\"0.01\",\"artifact-type\" :\"DESIGNTOOL-TEST\",\"artifact-contents\":  "  \r
+               + content + \r
+                " } ";\r
+               String rpc = "Test_Configure";\r
+               \r
+                       ArtifactHandlerClient ahi = new ArtifactHandlerClient();\r
+                ahi.execute(payload, rpc);\r
+               }catch(Exception e)\r
+               {\r
+                       e.printStackTrace();\r
+               }\r
+       }\r
+}\r
diff --git a/appc-inbound/appc-design-services/provider/src/test/java/org/openecomp/appc/design/validator/TestDBService.java b/appc-inbound/appc-design-services/provider/src/test/java/org/openecomp/appc/design/validator/TestDBService.java
deleted file mode 100644 (file)
index 81a620a..0000000
+++ /dev/null
@@ -1,48 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP : APPC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Copyright (C) 2017 Amdocs
- * =============================================================================
- * 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.
- * 
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.appc.design.validator;
-
-import java.io.File;
-import java.io.InputStream;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.Properties;
-
-import org.apache.commons.io.FileUtils;
-import org.junit.Before;
-import org.junit.Test;
-import org.openecomp.appc.design.dbervices.DesignDBService;
-import org.openecomp.appc.design.services.util.DesignServiceConstants;
-import org.openecomp.appc.design.services.util.EscapeUtils;
-import org.openecomp.sdnc.sli.SvcLogicContext;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import junit.framework.Assert;
-
-public class TestDBService {
-
-//Onap Migration    
-}
diff --git a/appc-inbound/appc-design-services/provider/src/test/java/org/openecomp/appc/design/validator/TestDesigndata.java b/appc-inbound/appc-design-services/provider/src/test/java/org/openecomp/appc/design/validator/TestDesigndata.java
new file mode 100644 (file)
index 0000000..4d46a0e
--- /dev/null
@@ -0,0 +1,116 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Copyright (C) 2017 Amdocs
+ * =============================================================================
+ * 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.
+ * 
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.appc.design.validator;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.opendaylight.yang.gen.v1.org.openecomp.appc.rev170627.DbserviceInput;
+import org.openecomp.appc.design.data.ArtifactInfo;
+import org.openecomp.appc.design.data.DesignInfo;
+import org.openecomp.appc.design.data.DesignRequest;
+import org.openecomp.appc.design.data.DesignResponse;
+import org.openecomp.appc.design.data.StatusInfo;
+import org.openecomp.appc.design.dbervices.DbResponseProcessor;
+import org.openecomp.appc.design.dbervices.DbService;
+import org.openecomp.appc.design.services.impl.DesignServicesImpl;
+import org.openecomp.sdnc.sli.resource.dblib.DbLibService;
+
+public class TestDesigndata {
+       
+       
+               
+       DesignResponse dr = new DesignResponse();
+       
+       
+       
+       @Test
+       public void testSetUserID(){
+               
+                dr.setUserId("00000");
+                
+                String str = dr.getUserId();
+                System.out.println(str);
+       }
+       
+       @Test
+       public void testSetDesignInfoList(){
+               DesignInfo di = new DesignInfo();
+               List<DesignInfo> li = new ArrayList<DesignInfo>();
+               di.setAction("TestAction");
+               di.setArtifact_name("TestName");
+               di.setArtifact_type("TestType");
+               di.setInCart("TestCart");
+               di.setProtocol("TestProtocol");
+               di.setVnf_type("TestVNF");
+               di.setVnfc_type("TestVNFC");
+               li.add(di);
+               dr.setDesignInfoList(li);
+               System.out.println(dr.getDesignInfoList());
+       }
+       
+       @Test
+       public void testSetArtifactInfo(){
+               ArtifactInfo ai = new ArtifactInfo();
+               List<ArtifactInfo> li = new ArrayList<ArtifactInfo>();
+               ai.setArtifact_content("TestContent");
+               li.add(ai);
+               dr.setArtifactInfo(li);
+               System.out.println(dr.getArtifactInfo());
+               
+       }
+       @Test
+       public void testStatusInfo(){
+               StatusInfo si = new StatusInfo();
+               List<StatusInfo> li = new ArrayList<StatusInfo>();
+               si.setAction("TestAction");
+               si.setAction_status("TestActionStatus");
+               si.setArtifact_status("TestArtifactStatus");
+               si.setVnf_type("TestVNF");
+               si.setVnfc_type("TestVNFC");
+               li.add(si);
+               dr.setStatusInfoList(li);
+               System.out.println(dr.getStatusInfoList());
+       }
+       @Test
+       public void testDesignRequest(){
+               DesignRequest dreq = new DesignRequest();
+               dreq.setAction("TestAction");
+               dreq.setArtifact_contents("TestContent");
+               dreq.setArtifact_name("TestName");
+               dreq.setProtocol("TestProtocol");
+               dreq.setUserId("0000");
+               dreq.setVnf_type("testvnf");
+               dreq.setVnfc_type("testvnfc");
+               System.out.println(dreq.getAction() + dreq.getArtifact_contents() + dreq.getArtifact_name() + dreq.getProtocol() + dreq.getUserId() + dreq.getVnf_type()+ dreq.getVnfc_type());
+       System.out.println(dreq.toString());
+       }
+       
+
+}
diff --git a/appc-inbound/appc-design-services/provider/src/test/java/org/openecomp/appc/design/validator/TestEscapeUtils.java b/appc-inbound/appc-design-services/provider/src/test/java/org/openecomp/appc/design/validator/TestEscapeUtils.java
new file mode 100644 (file)
index 0000000..e3c5c17
--- /dev/null
@@ -0,0 +1,19 @@
+package org.openecomp.appc.design.validator;\r
+\r
+import org.junit.Test;\r
+import org.openecomp.appc.design.services.util.EscapeUtils;\r
+\r
+public class TestEscapeUtils {\r
+\r
+       @Test\r
+       public void EscapeUtils(){\r
+               \r
+               EscapeUtils escapeUtils = new EscapeUtils();\r
+               \r
+               String str = escapeUtils.escapeSql("\\'Test Data\\'");\r
+               \r
+               System.out.println(str);\r
+               \r
+               \r
+       }\r
+}\r
index 1757c3c..05aeb30 100644 (file)
@@ -42,4 +42,140 @@ public class TestValidatorService {
 
 //Onap Migration    
 
+    private final Logger logger = LoggerFactory.getLogger(TestValidatorService.class);
+@Test
+    public void testvalidXMLValidation() throws Exception {
+        String response = null;
+        String xmlString = "<xml><configure>"
+                + "<operation>create</operation>"
+                + "<base>"
+                + "<request-information>"
+                + "<source>SDN-GP</source>"
+                + "</request-information>"
+                + "</base>" 
+                + "</configure>"
+                + "</xml>";
+        
+        ValidatorService vs = new ValidatorService();
+        try{
+         response = vs.execute("", xmlString, "XML");
+        }
+        catch(Exception e){
+            System.out.println(e.getMessage());
+        }
+            
+        Assert.assertEquals("success", response);
+        
+    }
+    @Test
+    public void testInvalidXMLValidation() throws Exception {
+        String response = null;
+        String xmlString = "<xml><configure>"
+                + "<operation>create</operation>"
+                + "<base>"
+                + "<request-information>"
+                + "<source>SDN-GP</source>"
+                + "</request-information>"
+                + "</configure>"
+                + "</xml>";
+        
+        ValidatorService vs = new ValidatorService();
+        try{
+         response = vs.execute("", xmlString, "XML");
+        }
+        catch(Exception e){
+            System.out.println(e.getMessage());
+        }
+            
+        Assert.assertEquals(null, response);
+        
+    }
+    @Test
+    public void testYAMLValidation() throws Exception {
+        String response = null;
+        String YAMLString = "en:";
+            
+        
+        ValidatorService vs = new ValidatorService();
+        try{
+         response = vs.execute("", YAMLString, "YAML");
+        }
+        catch(Exception e){
+            System.out.println(e.getMessage());
+            e.printStackTrace();
+        }
+            
+        Assert.assertEquals("success", response);
+        
+    }
+    @Test
+    public void testInvalidYAMLValidation() throws Exception {
+        String response = null;
+        String YAMLString = "Test \n A:";
+            
+        
+        ValidatorService vs = new ValidatorService();
+        try{
+         response = vs.execute("", YAMLString,"YAML");
+        }
+        catch(Exception e){
+            System.out.println(e.getMessage());
+        }
+            
+        Assert.assertEquals(null, response);
+        
+    }
+    
+@Test
+    public void testJSONValidation() throws Exception {
+        String response = null;
+        String YAMLString = "{\"Test\": \"Test1\" }";
+            
+        
+        ValidatorService vs = new ValidatorService();
+        try{
+         response = vs.execute("", YAMLString, "JSON");
+        }
+        catch(Exception e){
+            System.out.println(e.getMessage());
+        
+        }            
+        Assert.assertEquals("success", response);
+        
+    }
+    @Test
+    public void testInvalidJSONValidation() throws Exception {
+        String response = null;
+        String YAMLString = "{\"Test\" \"Test1\" }";
+            
+        
+        ValidatorService vs = new ValidatorService();
+        try{
+         response = vs.execute("", YAMLString, "JSON");
+        }
+        catch(Exception e){
+            System.out.println(e.getMessage());
+        
+        }            
+        Assert.assertEquals(null, response);
+        
+    }
+    
+    @Test
+    public void testainvalidvalidateVelocity() throws Exception {
+        String response = null;
+        String validateVelocity = "{\"Test\" \"Test1\" }";
+            
+        
+        ValidatorService vs = new ValidatorService();
+        try{
+         response = vs.execute("", validateVelocity, "Velocity");
+        }
+        catch(Exception e){
+            System.out.println(e.getMessage());
+        
+        }            
+        Assert.assertEquals(null, response);
+        
+    }
 }
index e69de29..a82eaf0 100644 (file)
@@ -0,0 +1,19 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APP-C
+ * ================================================================================
+ * 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=========================================================
+ */
index 92f57ff..a58522a 100644 (file)
@@ -40,7 +40,502 @@ import org.openecomp.sdnc.sli.SvcLogicResource;
 import org.openecomp.sdnc.sli.aai.AAIClient;
 
 public class MockAaiService extends AaiService {
-       
-       //ONAP migration
-       
+    
+    //ONAP migration
+    
+    private static final EELFLogger log = EELFManager.getInstance().getLogger(MockAaiService.class);
+         private AAIClient aaiClient;
+         
+         public MockAaiService(AAIClient aaic) {
+             super(aaic);
+         }
+         
+         
+         /*public MockAaiService() {
+              super(new AAIClientMock());
+         }*/
+         
+         public SvcLogicContext readResource(String query, String prefix, String resourceType) throws Exception {
+             log.info("In MockRead Resource");   
+             SvcLogicContext resourceContext = new SvcLogicContext();
+               
+                //prefix = StringUtils.isNotBlank(prefix) ? (prefix+".") : "";
+                if ( "generic-vnf".equals(resourceType) ) {
+                    populateGenericVnfContext(resourceContext, prefix);
+                }
+                else if("vserver".equals(resourceType) ) {
+                    populateVmContext(resourceContext, prefix);
+                }
+                else if("vnfc".equals(resourceType) ) {
+                    populateVnfcContext(resourceContext, prefix);
+                }
+              
+               
+                return resourceContext;
+                
+                
+                
+         }
+         
+         public void addVnfc(String vnfcName, Map<String, String> params, String prefix) throws Exception  {
+             
+             
+             if ( vnfcName.startsWith("ibcx")) {
+                assertEquals("ibcxvm0002func0001", vnfcName);
+                 
+                 
+                 log.info("In AddVnfc " + vnfcName);
+                 Map<String, String> expectedParams  = getExpectedParams();
+                 
+                 
+                /*    for (Map.Entry<String, String> entry : params.entrySet()) {
+                            String key = entry.getKey();
+                            String value = entry.getValue();
+        
+        
+                           log.info("key= " + key + "value = " + value );
+                         
+                    }*/
+                 assertEquals(params, expectedParams);
+             }
+         }
+        
+         
+         public void updateResource( String resource, String resourceKey,  Map<String, String> params)  throws Exception {
+                
+                 Map<String, String> expectedParams = new HashMap<String, String>();
+             
+                
+                expectedParams.put("prov-status", "NVTPROV"); 
+                assertEquals(params, expectedParams);
+                
+                if ( "vserver".equals(resource))  {
+                    
+                    String key  = "vserver.vserver-id = 'ibcx00000'" +
+                            " AND tenant.tenant-id = 'tenantId'" + 
+                            " AND cloud-region.cloud-owner = 'cloudOwner'" + 
+                            " AND cloud-region.cloud-region-id = 'cloudRegionId'";
+                    
+                    assertEquals(key, resourceKey);
+                }
+                else if ( "generic-vnf".equals(resource))  {
+                    assertEquals(resourceKey, "generic-vnf.vnf-id = 'ibcx000000'");
+                }
+                else
+                    fail("Invalid resource " + resource);
+                
+            
+            
+            
+            } 
+         
+        public Map<String, String> getExpectedParams() throws Exception {
+            Map<String, String> vnfcParams = new HashMap<String, String>();
+             
+            vnfcParams.put("vnfc-function-code", "func0");
+            
+            
+            
+            vnfcParams.put("vnfc-type", "ssc0");
+            
+            vnfcParams.put("ipaddress-v4-oam-vip", "000.00.00.00");
+            
+            vnfcParams.put("prov-status", "NVTPROV");
+            vnfcParams.put("orchestration-status", "CONFIGURED");
+            vnfcParams.put("in-maint", "false");
+            vnfcParams.put("is-closed-loop", "false");
+            vnfcParams.put("group-notation","2");
+            
+            
+            vnfcParams.put("relationship-list.relationship[0].related-to","vserver");
+            vnfcParams.put("relationship-list.relationship[0].relationship-data[0].relationship-key","vserver.vserver-id");
+            vnfcParams.put("relationship-list.relationship[0].relationship-data[0].relationship-value","ibcx00000");
+            
+            
+            vnfcParams.put("relationship-list.relationship[0].relationship-data[1].relationship-key","tenant.tenant-id");
+            vnfcParams.put("relationship-list.relationship[0].relationship-data[1].relationship-value","tenantId");
+            
+            
+            vnfcParams.put("relationship-list.relationship[0].relationship-data[2].relationship-key","cloud-region.cloud-owner");
+            vnfcParams.put("relationship-list.relationship[0].relationship-data[2].relationship-value","cloudOwner");
+            
+            
+            vnfcParams.put("relationship-list.relationship[0].relationship-data[3].relationship-key","cloud-region.cloud-region-id");
+            vnfcParams.put("relationship-list.relationship[0].relationship-data[3].relationship-value","cloudRegionId");
+            
+            
+            vnfcParams.put("relationship-list.relationship[1].related-to","generic-vnf");
+            vnfcParams.put("relationship-list.relationship[1].relationship-data[0].relationship-key","generic-vnf.vnf-id");
+            vnfcParams.put("relationship-list.relationship[1].relationship-data[0].relationship-value","ibcx000000");
+            
+            
+            vnfcParams.put("relationship-list.relationship[2].related-to","vf-module");
+            vnfcParams.put("relationship-list.relationship[2].relationship-data[0].relationship-key","generic-vnf.vnf-id");
+            vnfcParams.put("relationship-list.relationship[2].relationship-data[0].relationship-value","ibcx000000");
+            
+            
+            vnfcParams.put("relationship-list.relationship[2].relationship-data[1].relationship-key","vf-module.vf-module-id");
+            vnfcParams.put("relationship-list.relationship[2].relationship-data[1].relationship-value","vfModuleId");
+        
+            return vnfcParams;
+        }
+        public void populateVnfcContext(SvcLogicContext ctx, String prefix) {
+             log.info("In populateVnfcContext " + prefix);
+             
+             ctx.setAttribute(prefix + ".vnfc-type", "vnfctype1");
+             ctx.setAttribute(prefix + ".vnfc-function-code", "funccode1");
+             ctx.setAttribute(prefix + ".group-notation", "grpnot1");
+        }
+         
+        public void populateVmContext(SvcLogicContext ctx, String prefix) {
+            log.info("In populateVmContext " + prefix);
+             
+            ctx.setAttribute(prefix + ".vserver-name", "ibcx0000000");
+            
+            
+            ctx.setAttribute(prefix + ".relationship-list.relationship_length", "3");
+                 
+                 // Junk
+            ctx.setAttribute(prefix + ".relationship-list.relationship[0].related-to", "test");
+            ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data_length", "1");
+            ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[0].relationship-key", "vnfc.vnfc-name");
+            ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[0].relationship-value", "test");
+                 
+                 
+                 
+             // VNFC
+             ctx.setAttribute(prefix + ".relationship-list.relationship[1].related-to", "vnfc");
+             ctx.setAttribute(prefix + ".relationship-list.relationship[1].relationship-data_length", "1");
+             ctx.setAttribute(prefix + ".relationship-list.relationship[1].relationship-data[0].relationship-key", "vnfc.vnfc-name");
+             ctx.setAttribute(prefix + ".relationship-list.relationship[1].relationship-data[0].relationship-value", "ibcx0001vm001vnfc1");
+                 
+                 
+             // VFModule
+                 
+             ctx.setAttribute(prefix + ".relationship-list.relationship[2].related-to", "vf-module");
+             ctx.setAttribute(prefix + ".relationship-list.relationship[2].relationship-data_length", "1");
+             ctx.setAttribute(prefix + ".relationship-list.relationship[2].relationship-data[0].relationship-key", "vf-module.vf-module-id");
+             ctx.setAttribute(prefix + ".relationship-list.relationship[2].relationship-data[0].relationship-value", "vfModule1");
+                 
+                 
+        }
+
+        public void populateGenericVnfContext(SvcLogicContext ctx, String prefix)  throws Exception {
+            
+             log.info("In populateGenericVnf " + prefix);
+             ctx.setAttribute(prefix + ".vnf-name", "ibvcx0001");
+             ctx.setAttribute(prefix + ".vnf-type", "vUSP-Metaswitch");
+             
+             ctx.setAttribute(prefix + ".relationship-list.relationship_length", "3");
+             
+            /* // VM1
+             ctx.setAttribute(prefix + ".relationship-list.relationship[0].related-to", "vserver");
+             ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data_length", "4");
+             ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[0].relationship-key", "vserver.vserver-id");
+             ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[0].relationship-value", "ibcx001vm001-id");
+             ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[1].relationship-key", "tenant.tenant-id");
+             ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[1].relationship-value", "sometenant");
+             ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[2].relationship-key", "cloud-region.cloud-owner");
+             ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[2].relationship-value", "ATTAIC");
+             ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[3].relationship-key", "cloud-region.cloud-region-id");
+             ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[3].relationship-value", "testcloudregionid");
+           
+             
+             //ctx.setAttribute(prefix + ".relationship-list.relationship_length", "3");
+*/             
+             // VM1
+             ctx.setAttribute(prefix + ".relationship-list.relationship[0].related-to", "vserver");
+             ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data_length", "4");
+             ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[0].relationship-key", "vserver.vserver-id");
+             ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[0].relationship-value", "ibcx001vm001-id");
+             ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[1].relationship-key", "tenant.tenant-id");
+             ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[1].relationship-value", "sometenant");
+             ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[2].relationship-key", "cloud-region.cloud-owner");
+             ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[2].relationship-value", "ATTAIC");
+             ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[3].relationship-key", "cloud-region.cloud-region-id");
+             ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[3].relationship-value", "testcloudregionid");
+             
+             
+             // VM2
+             ctx.setAttribute(prefix + ".relationship-list.relationship[1].related-to", "vserver");
+             ctx.setAttribute(prefix + ".relationship-list.relationship[1].relationship-data_length", "4");
+             ctx.setAttribute(prefix + ".relationship-list.relationship[1].relationship-data[0].relationship-key", "vserver.vserver-id");
+             ctx.setAttribute(prefix + ".relationship-list.relationship[1].relationship-data[0].relationship-value", "ibcx000000");
+             
+                
+             ctx.setAttribute(prefix + ".relationship-list.relationship[1].relationship-data[1].relationship-key", "tenant.tenant-id");
+             ctx.setAttribute(prefix + ".relationship-list.relationship[1].relationship-data[1].relationship-value", "sometenant");
+             
+             ctx.setAttribute(prefix + ".relationship-list.relationship[1].relationship-data[2].relationship-key", "cloud-region.cloud-owner");
+             ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[2].relationship-value", "ATTAIC");
+             
+             ctx.setAttribute(prefix + ".relationship-list.relationship[1].relationship-data[3].relationship-key", "cloud-region.cloud-region-id");
+             ctx.setAttribute(prefix + ".relationship-list.relationship[1].relationship-data[3].relationship-value", "testcloudregionid");
+             
+             
+             // Unrelated 
+             ctx.setAttribute(prefix + ".relationship-list.relationship[2].related-to", "junk");
+             
+             ctx.setAttribute(prefix + ".relationship-list.relationship[2].relationship-data_length", "4");
+             
+             
+             ctx.setAttribute(prefix + ".relationship-list.relationship[2].relationship-data[0].relationship-key", "test");
+             ctx.setAttribute(prefix + ".relationship-list.relationship[2].relationship-data[0].relationship-value", "ibcx000000");
+             
+                
+             ctx.setAttribute(prefix + ".relationship-list.relationship[2].relationship-data[1].relationship-key", "test1");
+             ctx.setAttribute(prefix + ".relationship-list.relationship[2].relationship-data[1].relationship-value", "sometenant");
+             
+             ctx.setAttribute(prefix + ".relationship-list.relationship[2].relationship-data[2].relationship-key", "test2");
+             ctx.setAttribute(prefix + ".relationship-list.relationship[2].relationship-data[2].relationship-value", "ATTAIC");
+             
+             ctx.setAttribute(prefix + ".relationship-list.relationship[2].relationship-data[3].relationship-key", "test3");
+             ctx.setAttribute(prefix + ".relationship-list.relationship[2].relationship-data[3].relationship-value", "testcloudregionid");
+         }
+    
+         
+         
+         public void populateFirstVnfcData(SvcLogicContext ctx, String prefix) throws Exception {
+             
+                    
+                    
+             ctx.setAttribute(prefix + "vnf.vm-count", "4");
+             
+             ctx.setAttribute(prefix+ "vm[0].vnfc-type", "mmc");
+             ctx.setAttribute(prefix+ "vm[0].vnfc-name", "vnfcname1");
+             
+             ctx.setAttribute(prefix+ "vm[1].vnfc-type", "mmc");
+             ctx.setAttribute(prefix+ "vm[1].vnfc-name", "vnfcname2");
+             
+             ctx.setAttribute(prefix+ "vm[2].vnfc-type", "ssc");
+             ctx.setAttribute(prefix+ "vm[2].vnfc-name", "vnfcname3");
+             
+             ctx.setAttribute(prefix+ "vm[3].vnfc-type", "ssc");
+             ctx.setAttribute(prefix+ "vm[3].vnfc-name", "vnfcname4");
+         }
+         
+         
+         
+         public void populateGroupNotation(SvcLogicContext ctx, String prefix) throws Exception {
+             
+                
+                
+             ctx.setAttribute(prefix + "vnf.vm-count", "5");
+             
+             ctx.setAttribute(prefix+ "vm[0].vserver-name", "ibcxvm0001");
+             ctx.setAttribute(prefix+ "vm[0].group-notation", "grpNot1");
+             
+             ctx.setAttribute(prefix+ "vm[1].vserver-name", "ibcxvm0002");
+             ctx.setAttribute(prefix+ "vm[1].group-notation", "grpNot2");
+             
+            
+             ctx.setAttribute(prefix+ "vm[2].vserver-name", "ibcxvm0003");
+             ctx.setAttribute(prefix+ "vm[2].group-notation", "grpNot3");
+             
+             ctx.setAttribute(prefix+ "vm[3].vserver-name", "ibcxvm0004");
+             ctx.setAttribute(prefix+ "vm[3].group-notation", "4");
+             
+             ctx.setAttribute(prefix+ "vm[4].vserver-name", "ibcxvm0005");
+             ctx.setAttribute(prefix+ "vm[4].group-notation", "4");
+         }
+         
+         
+         public void populateVnfcRef(SvcLogicContext ctx) throws Exception {
+             
+             for (int i = 0; i < 2; i++ ) {
+             
+                 String vnfcRefKey = "vnfcReference[" + i+ "].";
+                
+                
+                
+                ctx.setAttribute(vnfcRefKey+ "VM-INSTANCE", String.valueOf(i));
+                ctx.setAttribute(vnfcRefKey+ "VNFC-INSTANCE", "1");
+                
+                
+                //if ( i == 0 || i == 1 ) {
+                    ctx.setAttribute(vnfcRefKey+ "GROUP-NOTATION-TYPE", "fixed-value");
+                    ctx.setAttribute(vnfcRefKey+ "GROUP-NOTATION-VALUE", "2");
+                //}
+                
+                ctx.setAttribute(vnfcRefKey+ "VNFC-TYPE", "ssc"+i );
+                
+                ctx.setAttribute(vnfcRefKey+ "VNFC-FUNCTION-CODE", "func" +i);
+                
+                ctx.setAttribute(vnfcRefKey+ "IPADDRESS-V4-OAM-VIP", "Y");
+             }
+             
+         }
+             
+         public void populateAllVnfInfo(SvcLogicContext ctx, String prefix) throws Exception {
+             
+             ctx.setAttribute("vnf-id", "ibcx000000");
+                     
+             ctx.setAttribute("vnf-host-ip-address", "000.00.00.00");
+             ctx.setAttribute(prefix + ".vnf.vm-count", "2");
+             
+             
+             
+             
+             ctx.setAttribute(prefix+ ".vm[0].vserver-name", "ibcxvm0000");
+             ctx.setAttribute(prefix+ ".vm[0].vnfc-name", "VNFCNAME");
+             
+             ctx.setAttribute(prefix+ ".vm[0].vserver-id", "ibcxvm0001id");
+             ctx.setAttribute(prefix+ ".vm[0].tenant-id", "tenantid");
+             ctx.setAttribute(prefix+ ".vm[0].cloud-owner", "cloudOwner");
+             ctx.setAttribute(prefix+ ".vm[0].cloud-region-id", "cloudRegionId");
+             
+             ctx.setAttribute(prefix+ ".vm[0].vf-module-id", "vfModuleId");
+             
+             
+             
+             ctx.setAttribute(prefix+ ".vm[1].vserver-name", "ibcxvm0002");
+             
+             ctx.setAttribute(prefix+ ".vm[1].vserver-id", "ibcx00000");
+             ctx.setAttribute(prefix+ ".vm[1].tenant-id", "tenantId");
+             ctx.setAttribute(prefix+ ".vm[1].cloud-owner", "cloudOwner");
+             ctx.setAttribute(prefix+ ".vm[1].cloud-region-id", "cloudRegionId");
+             
+             ctx.setAttribute(prefix+ ".vm[1].vf-module-id", "vfModuleId");
+             
+            
+             //ctx.setAttribute(prefix+ ".vm[1].vserver-name", "ibcxvm0002");
+                                  
+            
+            
+             
+         }
+         
+         
+         
+         public void populateAllVnfInfo1(SvcLogicContext ctx, String prefix) throws Exception {
+             
+             ctx.setAttribute("vnf-id", "dbjx0001v");
+                     
+             ctx.setAttribute("vnf-host-ip-address", "000.00.00.00");
+             ctx.setAttribute(prefix + ".vnf.vm-count", "2");
+             
+             
+             
+             
+             ctx.setAttribute(prefix+ ".vm[0].vserver-name", "dbjx0001vm001");
+            
+             
+             ctx.setAttribute(prefix+ ".vm[0].vserver-id", "dbjx0001vm0001id");
+             ctx.setAttribute(prefix+ ".vm[0].tenant-id", "tenantid1");
+             ctx.setAttribute(prefix+ ".vm[0].cloud-owner", "cloudOwner1");
+             ctx.setAttribute(prefix+ ".vm[0].cloud-region-id", "cloudRegionId1");
+             
+             ctx.setAttribute(prefix+ ".vm[0].vf-module-id", "vfModuleId1");
+             
+             
+             
+             ctx.setAttribute(prefix+ ".vm[1].vserver-name", "dbjx0001vm002");
+             
+             ctx.setAttribute(prefix+ ".vm[1].vserver-id", "dbjx0001vm0002id");
+             ctx.setAttribute(prefix+ ".vm[1].tenant-id", "tenantId2");
+             ctx.setAttribute(prefix+ ".vm[1].cloud-owner", "cloudOwner2");
+             ctx.setAttribute(prefix+ ".vm[1].cloud-region-id", "cloudRegionId2");
+             
+             ctx.setAttribute(prefix+ ".vm[1].vf-module-id", "vfModuleId2");
+             
+            
+             
+         }
+         
+         public void populateVnfcRefFirstVnfcName(SvcLogicContext ctx) throws Exception {
+             
+            
+             for (int i = 0; i < 2; i++ ) {
+             
+                 String vnfcRefKey = "vnfcReference[" + i+ "].";
+                
+                
+                
+                ctx.setAttribute(vnfcRefKey+ "VM-INSTANCE", String.valueOf(i));
+                ctx.setAttribute(vnfcRefKey+ "VNFC-INSTANCE", "1");
+                
+                
+                
+                ctx.setAttribute(vnfcRefKey+ "GROUP-NOTATION-TYPE", "first-vnfc-name");
+                ctx.setAttribute(vnfcRefKey+ "GROUP-NOTATION-VALUE", "pair");
+                
+                
+                ctx.setAttribute(vnfcRefKey+ "VNFC-TYPE", "vDBE-I? - DBJX" );
+                
+                ctx.setAttribute(vnfcRefKey+ "VNFC-FUNCTION-CODE", "dbj");
+                
+                ctx.setAttribute(vnfcRefKey+ "IPADDRESS-V4-OAM-VIP", "Y");
+             }
+             
+         }
+         
+         public void populateVnfcRefRelValueSame(SvcLogicContext ctx) throws Exception {
+             
+                
+             for (int i = 0; i < 2; i++ ) {
+             
+                 String vnfcRefKey = "vnfcReference[" + i+ "].";
+                
+                
+                
+                ctx.setAttribute(vnfcRefKey+ "VM-INSTANCE", String.valueOf(i));
+                ctx.setAttribute(vnfcRefKey+ "VNFC-INSTANCE", "1");
+                
+                
+                
+                if ( i == 0 ) {
+                    ctx.setAttribute(vnfcRefKey+ "GROUP-NOTATION-TYPE", "fixed-value");
+                    ctx.setAttribute(vnfcRefKey+ "GROUP-NOTATION-VALUE", "1");
+                }
+                else {
+                    ctx.setAttribute(vnfcRefKey+ "GROUP-NOTATION-TYPE", "relative-value");
+                    ctx.setAttribute(vnfcRefKey+ "GROUP-NOTATION-VALUE", "same");
+                }
+                
+                    
+                
+                ctx.setAttribute(vnfcRefKey+ "VNFC-TYPE", "v-I? - DBJX" );
+                
+                ctx.setAttribute(vnfcRefKey+ "VNFC-FUNCTION-CODE", "dbj");
+                
+                ctx.setAttribute(vnfcRefKey+ "IPADDRESS-V4-OAM-VIP", "Y");
+             }
+             
+         }
+         
+         
+         public void populateVnfcRefRelValueNext(SvcLogicContext ctx) throws Exception {
+             
+                
+             for (int i = 0; i < 2; i++ ) {
+             
+                 String vnfcRefKey = "vnfcReference[" + i+ "].";
+                
+                
+                
+                ctx.setAttribute(vnfcRefKey+ "VM-INSTANCE", String.valueOf(i));
+                ctx.setAttribute(vnfcRefKey+ "VNFC-INSTANCE", "1");
+                
+                
+                
+                if ( i == 0 ) {
+                    ctx.setAttribute(vnfcRefKey+ "GROUP-NOTATION-TYPE", "fixed-value");
+                    ctx.setAttribute(vnfcRefKey+ "GROUP-NOTATION-VALUE", "1");
+                }
+                else {
+                    ctx.setAttribute(vnfcRefKey+ "GROUP-NOTATION-TYPE", "relative-value");
+                    ctx.setAttribute(vnfcRefKey+ "GROUP-NOTATION-VALUE", "next");
+                }
+                
+                    
+                
+                ctx.setAttribute(vnfcRefKey+ "VNFC-TYPE", "v-I? - DBJX" );
+                
+                ctx.setAttribute(vnfcRefKey+ "VNFC-FUNCTION-CODE", "dbj");
+                
+                ctx.setAttribute(vnfcRefKey+ "IPADDRESS-V4-OAM-VIP", "Y");
+             }
+             
+         }
+
 }
index 4cf6acf..0207d0a 100644 (file)
 
 package org.openecomp.appc.aai.client.aai;
 
-import java.awt.List;
-import java.io.File;
-import java.nio.charset.Charset;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
+import static org.junit.Assert.assertEquals;
+
 import java.util.HashMap;
 import java.util.Map;
 
-import org.apache.commons.io.FileUtils;
-import org.apache.commons.io.IOUtils;
-import org.apache.commons.lang3.StringUtils;
-import org.junit.Assert;
 import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.openecomp.appc.aai.client.AppcAaiClientConstant;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.FrameworkUtil;
-import org.osgi.framework.ServiceReference;
+import org.openecomp.sdnc.sli.SvcLogicContext;
+import org.openecomp.sdnc.sli.aai.AAIClient;
 
 import com.att.eelf.configuration.EELFLogger;
 import com.att.eelf.configuration.EELFManager;
-import org.openecomp.sdnc.sli.SvcLogicContext;
-import org.openecomp.sdnc.sli.aai.AAIClient;
-import org.openecomp.sdnc.sli.aai.AAIService;
-import org.openecomp.sdnc.sli.SvcLogicResource;
 
-import java.util.HashMap;
-import java.util.Map;
+public class TestAaiService {
+       // ONAP merging
 
-import static org.junit.Assert.*;
+       private static final EELFLogger log = EELFManager.getInstance().getLogger(TestAaiService.class);
+       private AAIClient aaiClient;
 
+       @Test
+       public void testGetGenericVnfInfo() throws Exception {
 
+               MockAaiService mockAai = new MockAaiService(aaiClient);
 
-public class TestAaiService {
-       // ONAP merging
+               Map<String, String> inParams = new HashMap<String, String>();
+               inParams.put("vnfId", "ibcxvm0000");
+               inParams.put("responsePrefix", "tmp.vnfInfo");
+
+               SvcLogicContext ctx = new SvcLogicContext();
+
+               mockAai.getGenericVnfInfo(inParams, ctx);
+
+               assertEquals(ctx.getAttribute("tmp.vnfInfo.vnf.vnf-type"), "vUSP-Metaswitch");
+               assertEquals(ctx.getAttribute("tmp.vnfInfo.vm-count"), "2");
+               assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[0].vserver-id"), "ibcx001vm001-id");
+               assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[1].vserver-id"), "ibcx000000");
+       }
+
+       @Test
+       public void testGetVmInfo() throws Exception {
+
+               MockAaiService mockAai = new MockAaiService(aaiClient);
+
+               Map<String, String> inParams = new HashMap<String, String>();
+               inParams.put("vserverId", "vserverId1");
+               inParams.put("tenantId", "tenantId1");
+               inParams.put("cloudOwner", "cloudOwner1");
+               inParams.put("cloudRegionId", "cloudRegionId1");
+               inParams.put("responsePrefix", "tmp.vnfInfo");
+
+               SvcLogicContext ctx = new SvcLogicContext();
+
+               mockAai.getVMInfo(inParams, ctx);
+
+               printContext(ctx);
+
+               assertEquals(ctx.getAttribute("tmp.vnfInfo.vm.vserver-name"), "ibcx0000000");
+               assertEquals(ctx.getAttribute("tmp.vnfInfo.vm.vnfc-count"), "1");
+               assertEquals(ctx.getAttribute("tmp.vnfInfo.vm.vf-module-id"), "vfModule1");
+               assertEquals(ctx.getAttribute("tmp.vnfInfo.vm.vnfc[0].vnfc-name"), "ibcx0001vm001vnfc1");
+
+       }
+
+       @Test
+       public void testGetVnfcInfo() throws Exception {
+
+               MockAaiService mockAai = new MockAaiService(aaiClient);
+
+               Map<String, String> inParams = new HashMap<String, String>();
+               inParams.put("vnfcName", "vnfcName1");
+
+               inParams.put("responsePrefix", "tmp.vnfInfo");
+
+               SvcLogicContext ctx = new SvcLogicContext();
+
+               mockAai.getVnfcInfo(inParams, ctx);
+
+               printContext(ctx);
+
+               assertEquals(ctx.getAttribute("tmp.vnfInfo.vnfc.vnfc-type"), null);
+               assertEquals(ctx.getAttribute("tmp.vnfInfo.vnfc.vnfc-function-code"), null);
+               assertEquals(ctx.getAttribute("tmp.vnfInfo.vnfc.group-notation"), "grpnot1");
+
+       }
+
+       @Test
+       public void testGetFirstVnfcNameForVnfcType() throws Exception {
+
+               MockAaiService mockAai = new MockAaiService(aaiClient);
+
+               String prefix = "tmp.vnfInfo.";
+
+               SvcLogicContext ctx = new SvcLogicContext(); // VNFC with specified vnfc
+                                                                                                               // type found
+               mockAai.populateFirstVnfcData(ctx, prefix);
+               String firstVnfcName = mockAai.getFirstVnfcNameForVnfcType(ctx, prefix, "ssc");
+               assertEquals(firstVnfcName, "vnfcname3");
+
+               ctx = new SvcLogicContext(); // no VMS found
+               firstVnfcName = mockAai.getFirstVnfcNameForVnfcType(ctx, prefix, "ssc");
+               assertEquals(firstVnfcName, null);
+
+               ctx = new SvcLogicContext(); // no VMS found with specified type
+               mockAai.populateFirstVnfcData(ctx, prefix);
+               firstVnfcName = mockAai.getFirstVnfcNameForVnfcType(ctx, prefix, "test");
+               assertEquals(firstVnfcName, null);
+
+       }
+
+       @Test
+       public void testGroupNotation() throws Exception {
+
+               MockAaiService mockAai = new MockAaiService(aaiClient);
+
+               String prefix = "tmp.vnfInfo.";
+
+               SvcLogicContext ctx = new SvcLogicContext();
+               mockAai.populateGroupNotation(ctx, prefix);
+
+               // printContext(ctx);
+               String grpNotation = mockAai.getGroupNotationForVServer(ctx, prefix, "ibcxvm0002");
+               assertEquals(grpNotation, "grpNot2");
+
+               ctx = new SvcLogicContext(); // no VMS found
+               grpNotation = mockAai.getGroupNotationForVServer(ctx, prefix, "ibcxvm0002");
+               assertEquals(grpNotation, null);
+
+               ctx = new SvcLogicContext(); // no VMS found with specified name
+               mockAai.populateGroupNotation(ctx, prefix);
+               grpNotation = mockAai.getGroupNotationForVServer(ctx, prefix, "test");
+               assertEquals(grpNotation, null);
+
+       }
+
+       @Test
+       public void testGetGroupNotation() throws Exception {
+
+               MockAaiService mockAai = new MockAaiService(aaiClient);
+
+               String prefix = "tmp.vnfInfo.";
+
+               SvcLogicContext ctx = new SvcLogicContext();
+
+               String grpNotation = mockAai.getGroupNotation("fixed-value", "2", null, null, null, null, null);
+               assertEquals(grpNotation, "2");
+
+               mockAai.populateFirstVnfcData(ctx, prefix); // Existing VNFC Found
+               grpNotation = mockAai.getGroupNotation("first-vnfc-name", "2", "currentVnfcName", "currentVServerName", prefix,
+                               ctx, "ssc");
+               assertEquals(grpNotation, "vnfcname32");
+
+               ctx = new SvcLogicContext(); // no vnfcs exist in A&AI- Use current
+                                                                               // vnfcName
+               grpNotation = mockAai.getGroupNotation("first-vnfc-name", "2", "currentVnfcName", "currentVServerName", prefix,
+                               ctx, "ssc");
+               assertEquals(grpNotation, "currentVnfcName2");
+
+               ctx = new SvcLogicContext();
+               mockAai.populateGroupNotation(ctx, prefix);
+               grpNotation = mockAai.getGroupNotation("relative-value", "same", "currentVnfcName", "ibcxvm0003", prefix, ctx,
+                               "ssc");
+               assertEquals(grpNotation, "grpNot2");
+
+               ctx = new SvcLogicContext();
+               mockAai.populateGroupNotation(ctx, prefix);
+               grpNotation = mockAai.getGroupNotation("relative-value", "next", "currentVnfcName", "ibcxvm0006", prefix, ctx,
+                               "ssc");
+               assertEquals(grpNotation, "5");
+
+               ctx = new SvcLogicContext();
+               mockAai.populateGroupNotation(ctx, prefix);
+               grpNotation = mockAai.getGroupNotation("relative-value", "next", "currentVnfcName", "ibcxvm0003", prefix, ctx,
+                               "ssc");
+               assertEquals(grpNotation, null); // Null if grpNotation is not numeric
+
+       }
+
+       @Test
+       public void testInsertVnfcs() throws Exception {
+
+               MockAaiService mockAai = new MockAaiService(aaiClient);
+
+               Map<String, String> inParams = new HashMap<String, String>();
+
+               inParams.put("responsePrefix", "tmp.vnfInfo");
+
+               SvcLogicContext ctx = new SvcLogicContext();
+
+               mockAai.populateVnfcRef(ctx);
+
+               mockAai.populateAllVnfInfo(ctx, "tmp.vnfInfo");
+
+               // mockAai.insertVnfcs(inParams,ctx,2, 2) ;
+       }
+
+       @Test
+       public void testUpdateVServerStatus() throws Exception {
+
+               MockAaiService mockAai = new MockAaiService(aaiClient);
+
+               Map<String, String> inParams = new HashMap<String, String>();
+
+               inParams.put("responsePrefix", "tmp.vnfInfo");
+
+               SvcLogicContext ctx = new SvcLogicContext();
+
+               mockAai.populateAllVnfInfo(ctx, "tmp.vnfInfo");
+
+               mockAai.updateVServerStatus(inParams, ctx, 2);
+       }
+
+       @Test
+       public void testInsertVnfcsForFirstVnfc() throws Exception {
+
+               MockAaiService mockAai = new MockAaiService(aaiClient);
+
+               Map<String, String> inParams = new HashMap<String, String>();
+
+               inParams.put("responsePrefix", "tmp.vnfInfo");
+
+               SvcLogicContext ctx = new SvcLogicContext();
+
+               mockAai.populateVnfcRefFirstVnfcName(ctx);
+
+               mockAai.populateAllVnfInfo1(ctx, "tmp.vnfInfo");
+
+               mockAai.insertVnfcs(inParams, ctx, 2, 2);
+
+               
+       }
+       @Test
+       public void testInsertVnfcsForRelativeValueSame() throws Exception {
+
+               MockAaiService mockAai = new MockAaiService(aaiClient);
+
+               Map<String, String> inParams = new HashMap<String, String>();
+
+               inParams.put("responsePrefix", "tmp.vnfInfo");
+
+               SvcLogicContext ctx = new SvcLogicContext();
+
+               mockAai.populateVnfcRefRelValueSame(ctx);
+
+               mockAai.populateAllVnfInfo1(ctx, "tmp.vnfInfo");
+
+               mockAai.insertVnfcs(inParams, ctx, 2, 2);
+
+               assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-name"), "dbjx0001vm001dbj001");
+               assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-function-code"), "dbj");
+               assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-type"), "v-I? - DBJX");
+               assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[0].group-notation"), "1");
+               assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-name"), "dbjx0001vm002dbj001");
+               assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-function-code"), "dbj");
+               assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-type"), "v-I? - DBJX");
+               assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[1].group-notation"), "1");
+       }
+
+       @Test
+       public void testInsertVnfcsForRelativeValueNext() throws Exception {
+
+               MockAaiService mockAai = new MockAaiService(aaiClient);
+
+               Map<String, String> inParams = new HashMap<String, String>();
+
+               inParams.put("responsePrefix", "tmp.vnfInfo");
+
+               SvcLogicContext ctx = new SvcLogicContext();
+
+               mockAai.populateVnfcRefRelValueNext(ctx);
+
+               mockAai.populateAllVnfInfo1(ctx, "tmp.vnfInfo");
+
+               mockAai.insertVnfcs(inParams, ctx, 2, 2);
+
+       
+       
+               assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-name"), "dbjx0001vm001dbj001");
+               assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-function-code"), "dbj");
+               assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-type"), "v-I? - DBJX");
+               assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[0].group-notation"), "1");
+               assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-name"), "dbjx0001vm002dbj001");
+               assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-function-code"), "dbj");
+               assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-type"), "v-I? - DBJX");
+               assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[1].group-notation"), "2");
+       }
+
+       @Test
+       public void testUpdateVnfStatus() throws Exception {
+
+               MockAaiService mockAai = new MockAaiService(aaiClient);
+
+               Map<String, String> inParams = new HashMap<String, String>();
+
+               inParams.put("responsePrefix", "tmp.vnfInfo");
+
+               SvcLogicContext ctx = new SvcLogicContext();
+
+               mockAai.populateAllVnfInfo(ctx, "tmp.vnfInfo");
+
+               mockAai.updateVnfStatus(inParams, ctx);
+       }
+
+       @Test
+       public void testReadResource() throws Exception {
+
+               MockAaiService mockAai = new MockAaiService(aaiClient);
+               // AaiService mockAai = new AaiService(new AAIClientMock());
+
+               String vnfId = "ibcx0001v";
+               String resourceKey = "generic-vnf.vnf-id = '" + vnfId + "'";
+               String resourceType = "generic-vnf";
+               String queryPrefix = "vnfInfo";
+               SvcLogicContext ctx = mockAai.readResource(resourceKey, queryPrefix, resourceType);
+
+               // System.out.println("VNF TYPE " + queryPrefix + ".vnf.vnf-type");
+
+               assertEquals(ctx.getAttribute("vnfInfo.vnf-type"), "vUSP-Metaswitch");
+
+       }
+       private void printContext(SvcLogicContext ctx) throws Exception {
+               for (String key : ctx.getAttributeKeySet()) {
+                       log.info(" KEY " + key);
+                       log.info(" VALUE " + ctx.getAttribute(key));
+               }
+       }
 }
index 41fa6da..ac7a673 100644 (file)
@@ -22,6 +22,7 @@
  * ============LICENSE_END=========================================================
  */
 
+
 package org.openecomp.appc.aai.client.node;
 import static junit.framework.Assert.assertEquals;
 
@@ -39,6 +40,49 @@ import org.openecomp.sdnc.sli.SvcLogicContext;
 import org.openecomp.sdnc.sli.aai.AAIClient;
 
 public class MockAaiService extends AaiService {
-       
-       // ONAP merging
+    
+    // ONAP merging
+    private static final EELFLogger log = EELFManager.getInstance().getLogger(MockAaiService.class);
+         private AAIClient aaiClient;
+           
+         /*public MockAaiService() {
+              super(new AAIClientMock());
+         }*/
+         
+
+         public MockAaiService(AAIClient aaic) {
+             super(aaic);
+         }
+        
+        public void getVMInfo(Map<String, String> params,SvcLogicContext ctx )     throws Exception {
+            log.info("Received Mock getVmInfo call with params : " + params);
+            String vserverId =  params.get("vserverId");
+            String prefix = params.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
+            if ( vserverId.equals("ibcm0001id")) {
+                ctx.setAttribute(prefix + ".vm.vserver-name", "vserverName1");
+                ctx.setAttribute(prefix + ".vm.vf-module-id", "vfModule1");
+            }
+            else {
+                ctx.setAttribute(prefix + ".vm.vserver-name", "vserverName2");
+                ctx.setAttribute(prefix + ".vm.vf-module-id", "vfModule2");
+                ctx.setAttribute(prefix + ".vm.vnfc[0].vnfc-name", "vnfcName2");
+            }
+                
+        }
+         
+        
+        public void getVnfcInfo(Map<String, String> params,SvcLogicContext ctx )     throws Exception {
+            log.info("Received Mock getVmInfo call with params : " + params);
+            String prefix = params.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
+            
+            String vnfcName =  params.get("vnfcName");
+            
+            if ( vnfcName.equals("vnfcName2") ) {
+                ctx.setAttribute(prefix + ".vnfc.vnfc-type", "vnfcType2");
+                ctx.setAttribute(prefix + ".vnfc.vnfc-function-code", "vnfcFuncCode2");
+                ctx.setAttribute(prefix + ".vnfc.group-notation", "vnfcGrpNot2");
+            }
+        
+        
+        }
 }
index 5f88a9a..c589dc3 100644 (file)
@@ -46,12 +46,193 @@ import org.openecomp.appc.aai.client.aai.TestAaiService;
 import com.att.eelf.configuration.EELFLogger;
 import com.att.eelf.configuration.EELFManager;
 import org.openecomp.sdnc.sli.SvcLogicContext;
+
+import org.openecomp.sdnc.sli.SvcLogicException;
 import org.openecomp.sdnc.sli.aai.AAIClient;
 
 import com.fasterxml.jackson.databind.ObjectMapper;
 
 
 public class TestAAIResourceNode {
-       
-       //Removed for ONAP integration
+    
+    //Removed for ONAP integration
+
+    private static final EELFLogger log = EELFManager.getInstance().getLogger(TestAAIResourceNode.class);
+    
+    @Test
+    public void sortVServer() throws Exception{
+        
+        //log.info("Test");
+        
+        ArrayList<Map<String, String>> vservers = new ArrayList<Map<String, String>>();
+        HashMap<String, String> vserverMap = new HashMap<String, String>();
+        vserverMap.put("vserver-id", "vserverId9");
+        vserverMap.put("tenant-id", "tenantId9");
+        vserverMap.put("cloud-owner", "cloudOwner9");
+        vserverMap.put("cloud-region-id", "cloudRegionId9");
+        vserverMap.put("vserver-name", "vServerName9");
+        vservers.add(vserverMap);
+        vserverMap = new HashMap<String, String>();
+        vserverMap.put("vserver-id", "vserverId1");
+        vserverMap.put("tenant-id", "tenantId1");
+        vserverMap.put("cloud-owner", "cloudOwner1");
+        vserverMap.put("cloud-region-id", "cloudRegionId1");
+        vserverMap.put("vserver-name", "vServerName1");
+        vservers.add(vserverMap);
+        vserverMap = new HashMap<String, String>();
+        vserverMap.put("vserver-id", "vserverId3");
+        vserverMap.put("tenant-id", "tenantId3");
+        vserverMap.put("cloud-owner", "cloudOwner3");
+        vserverMap.put("cloud-region-id", "cloudRegionId3");
+        vserverMap.put("vserver-name", "vServerName3");
+        vservers.add(vserverMap);
+        Collections.sort(vservers, new Comparator<Map<String, String>>() {
+            @Override
+            public int compare(Map<String, String> o1, Map<String, String> o2) {
+                return o1.get("vserver-name").compareTo(o2.get("vserver-name"));
+            }
+        });
+        
+        SvcLogicContext ctx = new SvcLogicContext();
+        AAIResourceNode aai = new AAIResourceNode();
+        aai.populateContext(vservers, ctx, "vserver.");
+        log.info(ctx.getAttribute("vserver.vm[0].vserver-name"));
+    }
+
+    @Test
+    public void testAllVServer() throws Exception{
+        
+        MockAAIResourceNode mrn = new MockAAIResourceNode();
+        SvcLogicContext ctx = new SvcLogicContext();
+        populateAllVServerInfo(ctx, "tmp.vnfInfo");
+        Map<String, String> inParams  =new HashMap<String, String>();
+        inParams.put("responsePrefix", "tmp.vnfInfo");
+        mrn.getAllVServersVnfcsInfo(inParams, ctx);
+        assertEquals(ctx.getAttribute("tmp.vnfInfo.vm-count"), "2");
+        assertEquals(ctx.getAttribute("tmp.vnfInfo.vnf.vm-count"), "2");
+        assertEquals(ctx.getAttribute("tmp.vnfInfo.vnf.vm-with-no-vnfcs-count"), "0");
+        // VM1
+        assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[0].vserver-id"), "ibcsm0002id");
+        assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[0].tenant-id"), "tenantid2");
+        assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[0].cloud-owner"), "cloudOwner2");
+        assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[0].cloud-region-id"), "cloudRegionId2");
+        assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[0].vserver-name"), "vserverName2");
+        assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[0].vf-module-id"), "vfModule2");
+        //assertNull(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-name"));
+        
+        // VM2
+        assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[1].vserver-id"), "ibcxvm0001id");
+        assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[1].tenant-id"), "tenantid1");
+        assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[1].cloud-owner"), "cloudOwner1");
+        assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[1].cloud-region-id"), "cloudRegionId1");
+        assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[1].vserver-name"), "vserverName2");
+        assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[1].vf-module-id"), "vfModule2");
+        assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-name"), "vnfcName2");
+        assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-type"), "vnfcType2");
+        assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-function-code"), "vnfcFuncCode2");
+        assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[1].group-notation"), "vnfcGrpNot2");
+    }
+    public void populateAllVServerInfo(SvcLogicContext ctx, String prefix) throws Exception {
+         ctx.setAttribute("vnf-id", "ibcx0001v");
+         ctx.setAttribute("vnf-host-ip-address", "000.00.00.00");
+         ctx.setAttribute(prefix + ".vm-count", "2");
+         ctx.setAttribute(prefix+ ".vm[0].vserver-id", "ibcsm0002id");
+         ctx.setAttribute(prefix+ ".vm[0].tenant-id", "tenantid2");
+         ctx.setAttribute(prefix+ ".vm[0].cloud-owner", "cloudOwner2");
+         ctx.setAttribute(prefix+ ".vm[0].cloud-region-id", "cloudRegionId2");
+         ctx.setAttribute(prefix+ ".vm[1].vserver-id", "ibcxvm0001id");
+         ctx.setAttribute(prefix+ ".vm[1].tenant-id", "tenantid1");
+         ctx.setAttribute(prefix+ ".vm[1].cloud-owner", "cloudOwner1");
+         ctx.setAttribute(prefix+ ".vm[1].cloud-region-id", "cloudRegionId1");
+         
+    }
+    
+    public static class MockAAIResourceNode extends AAIResourceNode {
+        private static final EELFLogger log = EELFManager.getInstance().getLogger(MockAAIResourceNode.class);
+         private AAIClient aaiClient;
+        
+        public AaiService getAaiService() {
+            log.info("In MockAAI");
+            return new MockAaiService(aaiClient);
+        }
+    }
+
+    @Test
+    public void testPopulateContext() throws Exception{
+        
+        ArrayList<Map<String, String>> vservers = new ArrayList<Map<String, String>>();
+        HashMap<String, String> vserverMap = new HashMap<String, String>();
+        vserverMap = new HashMap<String, String>();
+        vserverMap.put("vserver-id", "vserverId1");
+        vserverMap.put("tenant-id", "tenantId1");
+        vserverMap.put("cloud-owner", "cloudOwner1");
+        vserverMap.put("cloud-region-id", "cloudRegionId1");
+        vserverMap.put("vserver-name", "vServerName1");
+        vserverMap.put("vnfc-name", "vnfcName1");
+        vservers.add(vserverMap);
+        vserverMap = new HashMap<String, String>();
+        vserverMap.put("vserver-id", "vserverId3");
+        vserverMap.put("tenant-id", "tenantId3");
+        vserverMap.put("cloud-owner", "cloudOwner3");
+        vserverMap.put("cloud-region-id", "cloudRegionId3");
+        vserverMap.put("vserver-name", "vServerName3");
+        vservers.add(vserverMap);
+        vserverMap = new HashMap<String, String>();
+        vserverMap.put("vserver-id", "vserverId9");
+        vserverMap.put("tenant-id", "tenantId9");
+        vserverMap.put("cloud-owner", "cloudOwner9");
+        vserverMap.put("cloud-region-id", "cloudRegionId9");
+        vserverMap.put("vserver-name", "vServerName9");
+        vservers.add(vserverMap);
+        SvcLogicContext ctx = new SvcLogicContext();
+        AAIResourceNode aai = new AAIResourceNode();
+        aai.populateContext(vservers, ctx, "tmp.vnfInfo.");
+        assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[0].vserver-name"), "vServerName1");
+        assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[0].tenant-id"), "tenantId1");
+        assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[0].cloud-owner"), "cloudOwner1");
+        assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[0].cloud-region-id"), "cloudRegionId1");
+        assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[0].vserver-id"), "vserverId1");
+        assertEquals(ctx.getAttribute("vm-name"), "vServerName3");
+    }
+    
+    @Test
+    public final void testGetVnfInfo() {
+        SvcLogicContext ctx = new SvcLogicContext();
+        AAIResourceNode aai = new AAIResourceNode();
+Map<String, String> inParams  =new HashMap<String, String>();
+        inParams.put("responsePrefix", "tmp.vnfInfo");
+        try {
+            aai.getVnfInfo(inParams, ctx);
+        } catch (SvcLogicException e) {
+            e.printStackTrace();
+        }
+    
+    }
+    @Test
+    public final void testaddVnfcs()
+    {
+        SvcLogicContext ctx = new SvcLogicContext();
+        AAIResourceNode aai = new AAIResourceNode();
+Map<String, String> inParams  =new HashMap<String, String>();
+        inParams.put("responsePrefix", "tmp.vnfInfo");
+        try {
+            aai.addVnfcs(inParams, ctx);
+        } catch (SvcLogicException e) {
+            e.printStackTrace();
+        }
+        
+    }
+    @Test
+    public final void  testupdateVnfAndVServerStatus(){
+        SvcLogicContext ctx = new SvcLogicContext();
+        AAIResourceNode aai = new AAIResourceNode();
+Map<String, String> inParams  =new HashMap<String, String>();
+        
+        inParams.put("responsePrefix", "tmp.vnfInfo");
+        try {
+            aai.updateVnfAndVServerStatus(inParams, ctx);
+        } catch (SvcLogicException e) {
+            e.printStackTrace();
+        }
+    }
 }
diff --git a/appc-outbound/appc-network-inventory-client/provider/src/test/java/org/openecomp/appc/instar/node/Dme2ClientTest.java b/appc-outbound/appc-network-inventory-client/provider/src/test/java/org/openecomp/appc/instar/node/Dme2ClientTest.java
new file mode 100644 (file)
index 0000000..e69de29
index ca88d54..00e580c 100644 (file)
@@ -48,6 +48,36 @@ import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter;
 
 
 public class TestInstarClientNode {
-       
-       //ONAP Migration
+    
+    //ONAP Migration
+
+    @Test(expected=Exception.class)
+    public void testInstarClientNode() throws Exception {
+    
+        SvcLogicContext ctx = new SvcLogicContext();
+        String key_conetent = IOUtils.toString(TestInstarClientNode.class.getClassLoader().getResourceAsStream("templates/sampleKeyContents"), Charset.defaultCharset());
+        Map<String, String> inParams = new HashMap<String, String>();
+        inParams.put(InstarClientConstant.INPUT_PARAM_RESPONSE_PRIFIX, "TEST");
+        inParams.put(InstarClientConstant.INSTAR_KEYS, "LOCAL_ACCESS_IP_ADDR");
+        inParams.put("operationName", InstarClientConstant.OPERATION_GET_IPADDRESS_BY_VNF_NAME);
+        ctx.setAttribute("INSTAR.LOCAL_ACCESS_IP_ADDR", key_conetent);
+        ctx.setAttribute(InstarClientConstant.INPUT_PARAM_RESPONSE_PRIFIX, "TEST");
+        ctx.setAttribute(InstarClientConstant.VNF_NAME, "basx0003v");
+        InstarClientNode icn  = new InstarClientNode();
+        icn.getInstarInfo(inParams, ctx);
+        String address = (new JSONObject(ctx.getAttribute("TEST." + InstarClientConstant.INSTAR_KEY_VALUES))).getString("LOCAL_ACCESS_IP_ADDR");
+    }
+    @Test(expected=Exception.class)
+    public void testInstarData() throws Exception {
+        
+        InstarClientNode inNode = new InstarClientNode();
+         SvcLogicContext ctx  = new SvcLogicContext ();
+         Map<String, String> inParams = new HashMap<String, String>();
+
+         inParams.put(InstarClientConstant.VNF_NAME, "basx0003v");
+         inParams.put("operationName", InstarClientConstant.OPERATION_GET_IPADDRESS_BY_VNF_NAME);         
+         inNode.getInstarData(inParams, ctx);
+         
+
+    }
 }