Add unit tests

Resolved:VNFSDK-21
VNF SDK Function tests

Change-Id: I8ed06549a0c741b4a5f46ce7d5ad8ce68b730aac
Signed-off-by: Murali-P <murali.p@huawei.com>
diff --git a/vnf-sdk-function-test/pom.xml b/vnf-sdk-function-test/pom.xml
index a1aa46e..b9c783c 100644
--- a/vnf-sdk-function-test/pom.xml
+++ b/vnf-sdk-function-test/pom.xml
@@ -240,5 +240,16 @@
             <scope>test</scope>
         </dependency>
         <!-- UT end -->
+        <dependency>
+            <groupId>org.mockito</groupId>
+            <artifactId>mockito-all</artifactId>
+            <version>1.9.5</version>
+        </dependency>
+        <!-- https://mvnrepository.com/artifact/org.jmockit/jmockit -->
+		<dependency>
+    		<groupId>org.jmockit</groupId>
+    		<artifactId>jmockit</artifactId>
+    		<version>1.19</version>
+		</dependency>	        
     </dependencies>
 </project>
diff --git a/vnf-sdk-function-test/src/test/java/org/openo/vnfsdk/functest/externalservice/entity/EnvironmentMapTest.java b/vnf-sdk-function-test/src/test/java/org/openo/vnfsdk/functest/externalservice/entity/EnvironmentMapTest.java
new file mode 100644
index 0000000..56ff72b
--- /dev/null
+++ b/vnf-sdk-function-test/src/test/java/org/openo/vnfsdk/functest/externalservice/entity/EnvironmentMapTest.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * 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.
+ */
+
+package org.openo.vnfsdk.functest.externalservice.entity;
+
+import static org.junit.Assert.assertNotNull;
+
+import java.util.UUID;
+
+import org.junit.Test;
+
+public class EnvironmentMapTest {
+
+    private UUID uuid = UUID.randomUUID();
+
+    @Test
+    public void testGetInstance() {
+        assertNotNull(EnvironmentMap.getInstance());
+    }
+
+    @Test
+    public void testGetEnvmap() {
+        assertNotNull(EnvironmentMap.getInstance().getEnvmap());
+    }
+
+    @Test
+    public void testAddEnv() {
+        EnvironmentMap.getInstance().addEnv(uuid, new Environment());
+    }
+
+    @Test
+    public void testDelEnv() {
+        EnvironmentMap.getInstance().delEnv(uuid);
+    }
+}
diff --git a/vnf-sdk-function-test/src/test/java/org/openo/vnfsdk/functest/externalservice/entity/EnvironmentTest.java b/vnf-sdk-function-test/src/test/java/org/openo/vnfsdk/functest/externalservice/entity/EnvironmentTest.java
new file mode 100644
index 0000000..78ef2d8
--- /dev/null
+++ b/vnf-sdk-function-test/src/test/java/org/openo/vnfsdk/functest/externalservice/entity/EnvironmentTest.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * 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.
+ */
+
+package org.openo.vnfsdk.functest.externalservice.entity;
+
+import org.junit.Before;
+import org.junit.Test;
+
+public class EnvironmentTest {
+	private Environment environment = null;
+	
+	@Before
+	public void setUp() {
+		environment = new Environment();
+	}
+	
+	@Test
+	public void testSetRemoteIp() {
+		environment.setRemoteIp( "192.168.4.47" );
+	}
+	
+	@Test
+	public void testSetUserName() {
+		environment.setUserName( "root" );
+	}
+	
+	@Test
+	public void testSetPassword() {
+		environment.setPassword( "root123" );
+	}
+	
+	@Test
+	public void testSetPath() {
+		environment.setPath( "src\\test\\resources" );
+	}
+}
diff --git a/vnf-sdk-function-test/src/test/java/org/openo/vnfsdk/functest/externalservice/entity/OPerationStatusHandlerTest.java b/vnf-sdk-function-test/src/test/java/org/openo/vnfsdk/functest/externalservice/entity/OPerationStatusHandlerTest.java
new file mode 100644
index 0000000..5c19d7a
--- /dev/null
+++ b/vnf-sdk-function-test/src/test/java/org/openo/vnfsdk/functest/externalservice/entity/OPerationStatusHandlerTest.java
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * 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.
+ */
+
+package org.openo.vnfsdk.functest.externalservice.entity;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.UUID;
+
+import javax.ws.rs.core.Response;
+
+import org.junit.Test;
+import org.openo.vnfsdk.functest.externalservice.entity.OperationStatus.operResultCode;
+
+public class OPerationStatusHandlerTest {
+
+    private UUID uuid = UUID.randomUUID();
+
+    private Map<UUID, OperationStatus> operStatusMap = new HashMap<UUID, OperationStatus>();
+
+    private Response response = null;
+
+    @Test
+    public void testGetInstance() {
+        assertNotNull(OperationStatusHandler.getInstance());
+    }
+
+    @Test
+    public void testGetOperStatusMap() {
+        assertNotNull(OperationStatusHandler.getInstance().getOperStatusMap());
+    }
+
+    @Test
+    public void testSetOperStatusMap() {
+        OperationStatus operationStatus = new OperationStatus();
+        operationStatus.setoResultCode(operResultCode.SUCCESS);
+        operationStatus.setOperResultMessage("success");
+        operationStatus.setOperFinished(true);
+        operStatusMap.put(uuid, operationStatus);
+    }
+
+    @Test
+    public void testGetOperationStatus() {
+        response = OperationStatusHandler.getInstance().getOperationStatus(uuid);
+        assertNotNull(response);
+        assertEquals(200, response.getStatus());
+    }
+}
diff --git a/vnf-sdk-function-test/src/test/java/org/openo/vnfsdk/functest/externalservice/entity/OperationStatusTest.java b/vnf-sdk-function-test/src/test/java/org/openo/vnfsdk/functest/externalservice/entity/OperationStatusTest.java
new file mode 100644
index 0000000..12a861c
--- /dev/null
+++ b/vnf-sdk-function-test/src/test/java/org/openo/vnfsdk/functest/externalservice/entity/OperationStatusTest.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * 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.
+ */
+
+package org.openo.vnfsdk.functest.externalservice.entity;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.openo.vnfsdk.functest.externalservice.entity.OperationStatus.operResultCode;
+
+public class OperationStatusTest {
+
+    private OperationStatus operationStatus = null;
+
+    @Before
+    public void setUp() {
+        operationStatus = new OperationStatus();
+    }
+
+    @Test
+    public void setTestResultCode() {
+        operationStatus.setoResultCode(operResultCode.SUCCESS);
+    }
+
+    @Test
+    public void setOperResultMsg() {
+        operationStatus.setOperResultMessage("success");
+    }
+
+    @Test
+    public void testOperationFinished() {
+        operationStatus.setOperFinished(true);
+    }
+}
diff --git a/vnf-sdk-function-test/src/test/java/org/openo/vnfsdk/functest/externalservice/entity/ServiceNodeTest.java b/vnf-sdk-function-test/src/test/java/org/openo/vnfsdk/functest/externalservice/entity/ServiceNodeTest.java
new file mode 100644
index 0000000..4884a9f
--- /dev/null
+++ b/vnf-sdk-function-test/src/test/java/org/openo/vnfsdk/functest/externalservice/entity/ServiceNodeTest.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * 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.
+ */
+
+package org.openo.vnfsdk.functest.externalservice.entity;
+
+import org.junit.Before;
+import org.junit.Test;
+
+public class ServiceNodeTest {
+
+    private ServiceNode serviceNode = null;
+
+    @Before
+    public void setUp() {
+        serviceNode = new ServiceNode();
+    }
+
+    @Test
+    public void testSetIP() {
+        serviceNode.setIp("192.168.4.47");
+    }
+
+    @Test
+    public void testSetPort() {
+        serviceNode.setPort("8080");
+    }
+
+    @Test
+    public void testSetTtl() {
+        serviceNode.setTtl(80);
+    }
+}
diff --git a/vnf-sdk-function-test/src/test/java/org/openo/vnfsdk/functest/resource/CommonManagerTest.java b/vnf-sdk-function-test/src/test/java/org/openo/vnfsdk/functest/resource/CommonManagerTest.java
index 5bda1ec..e4f59f2 100644
--- a/vnf-sdk-function-test/src/test/java/org/openo/vnfsdk/functest/resource/CommonManagerTest.java
+++ b/vnf-sdk-function-test/src/test/java/org/openo/vnfsdk/functest/resource/CommonManagerTest.java
@@ -40,12 +40,27 @@
 
     private String instanceId = "1234567";
 
+    private Response response = null;
+
     @Before
     public void setUp() {
         commonManger = new CommonManager();
     }
 
     @Test
+    public void testSetEnvironment() {
+        try {
+
+            String jsonInput =
+                    "{\"RemoteIp\":\"192.168.4.47\",\"UserName\":\"root\",\"Password\":\"root123\", \"Path\":\"/src/test/resources\"}";
+            response = commonManger.setEnvironment(jsonInput);
+            assertNotNull(response);
+        } catch(Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    @Test
     public void testexecuteFunc() throws FileNotFoundException {
 
         URL url = Thread.currentThread().getContextClassLoader().getResource("RobotScript");
diff --git a/vnf-sdk-function-test/src/test/java/org/openo/vnfsdk/functests/TaskExecutionTest.java b/vnf-sdk-function-test/src/test/java/org/openo/vnfsdk/functests/TaskExecutionTest.java
new file mode 100644
index 0000000..295542b
--- /dev/null
+++ b/vnf-sdk-function-test/src/test/java/org/openo/vnfsdk/functests/TaskExecutionTest.java
@@ -0,0 +1,105 @@
+/*
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * 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.
+ */
+
+package org.openo.vnfsdk.functests;
+
+import java.util.UUID;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import org.openo.vnfsdk.functest.TaskExecution;
+import org.openo.vnfsdk.functest.externalservice.entity.Environment;
+
+import org.openo.vnfsdk.functest.externalservice.entity.EnvironmentMap;
+
+import mockit.Mock;
+import mockit.MockUp;
+
+public class TaskExecutionTest {
+	
+	private TaskExecution testExecution = null;
+	private Environment functestEnv = null;	
+	
+	private String dirPath = "src\\test\\resources\\RobotScript";
+	private UUID UUIDEnv = UUID.randomUUID();
+	private UUID UUIDUpload = UUID.randomUUID();
+	private UUID uniqueKey = UUID.randomUUID();
+	private String remoteIP = "192.168.4.47";
+	private String userName = "root";
+	private String password = "root123";
+	private String path = "src\\test\\resources";
+	private UUID envId = UUID.randomUUID();
+	private UUID uploadId = UUID.randomUUID();
+	private UUID executeId = UUID.randomUUID();
+	private String frameworkType = "robotframework";
+	
+	
+	@Before
+	public void setUp() {
+		testExecution = new TaskExecution();
+		functestEnv = new Environment();
+	}
+	
+	@Test
+	public void testExecuteScript() {
+		try {
+			testExecution.executeScript( dirPath, uniqueKey );
+		} catch( Exception e ) {
+			e.printStackTrace();
+		}		
+	}
+	
+	@Test
+	public void testExecuteRobotScript() {
+		new MockUp<EnvironmentMap>() {
+            @Mock
+            public synchronized Environment getEnv( UUID uuid ) {   
+            	functestEnv.setRemoteIp( remoteIP );
+            	functestEnv.setUserName( userName );
+            	functestEnv.setPassword( password );
+            	functestEnv.setPath( path );
+                return functestEnv;           	
+            }
+        };
+        try {
+        	testExecution.executeRobotScript(envId, uploadId, executeId, frameworkType );
+        } catch( Exception e ) {
+        	e.printStackTrace();
+        }        
+	}	
+	
+	@Test
+	public void testUploadScript() {
+		 new MockUp<EnvironmentMap>() {
+	            @Mock
+	            public synchronized Environment getEnv( UUID uuid ) {   
+	            	functestEnv.setRemoteIp( remoteIP );
+	            	functestEnv.setUserName( userName );
+	            	functestEnv.setPassword( password );
+	            	functestEnv.setPath( path );
+	                return functestEnv;           	
+	            }
+	        };
+	        try {
+	        	testExecution.uploadScript( dirPath, UUIDEnv, UUIDUpload );
+	        } catch( Exception e ) {
+	        	e.printStackTrace();
+	        }	
+	}
+		
+	
+}
diff --git a/vnf-sdk-function-test/src/test/java/org/openo/vnfsdkfunctest/responsehandler/TestResultParserTest.java b/vnf-sdk-function-test/src/test/java/org/openo/vnfsdkfunctest/responsehandler/TestResultParserTest.java
new file mode 100644
index 0000000..9f43adc
--- /dev/null
+++ b/vnf-sdk-function-test/src/test/java/org/openo/vnfsdkfunctest/responsehandler/TestResultParserTest.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * 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.
+ */
+
+package org.openo.vnfsdkfunctest.responsehandler;
+
+import static org.junit.Assert.assertNotNull;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.openo.vnfsdk.functest.responsehandler.TestResultParser;
+
+public class TestResultParserTest {
+
+    private TestResultParser testResParser = null;
+
+    @Before
+    public void setUp() {
+        testResParser = new TestResultParser();
+    }
+
+    @Test
+    public void testPopulateResultList() {
+        assertNotNull(testResParser.populateResultList("src/test/resources/sample.xml"));
+    }
+}
diff --git a/vnf-sdk-function-test/src/test/java/org/openo/vnfsdkfunctest/responsehandler/TestResultTest.java b/vnf-sdk-function-test/src/test/java/org/openo/vnfsdkfunctest/responsehandler/TestResultTest.java
new file mode 100644
index 0000000..a2b50f3
--- /dev/null
+++ b/vnf-sdk-function-test/src/test/java/org/openo/vnfsdkfunctest/responsehandler/TestResultTest.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * 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.
+ */
+
+package org.openo.vnfsdkfunctest.responsehandler;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.openo.vnfsdk.functest.responsehandler.TestResult;
+
+public class TestResultTest {
+
+    private TestResult testResult = null;
+
+    @Before
+    public void setUp() {
+        testResult = new TestResult();
+    }
+
+    @Test
+    public void testSetName() {
+        testResult.setName("Huawei");
+    }
+
+    @Test
+    public void testSetDescription() {
+        testResult.setDescription("description");
+    }
+
+    @Test
+    public void testStatus() {
+        testResult.setStatus("success");
+    }
+}