From d4a7658f72decfef05d15973d5cee13910eb47ae Mon Sep 17 00:00:00 2001 From: Kailun Qin Date: Tue, 27 Mar 2018 18:23:01 +0800 Subject: Port nfvo/vnf_functest for framework merge Merged VNF onboarding test functions and frameworks locating separately in nfvo/vnf_functest and vnfsdk/vnf-sdk-function-test seed code. 1) Reconstructed by aligning with the original interface and sequence design; 2) Replaced Restful calls with local invokes; 3) Implemented DB support (PostgreSQL) for persistent recording; 4) Added unit tests associated; 5) Unified package names to "onap"; 6) Fixed several inherent issues. Issue-ID: VNFSDK-178 Change-Id: I2147c5df8dd400adef71dafca9073b12d992d2df Signed-off-by: Kailun Qin --- .../org/onap/vnfsdk/functest/FileUtilTest.java | 60 ++++++ .../onap/vnfsdk/functest/TaskExecutionTest.java | 98 +++++++++ .../VnfSdkFuncTestAppConfigurationTest.java | 38 ++++ .../vnfsdk/functest/VnfSdkFuncTestAppTest.java | 60 ++++++ .../onap/vnfsdk/functest/common/TestConfig.java | 44 +++++ .../vnfsdk/functest/db/TaskMgrCaseTblDAOTest.java | 79 ++++++++ .../vnfsdk/functest/db/TaskMgrTaskTblDAOTest.java | 87 ++++++++ .../externalservice/entity/EnvironmentMapTest.java | 48 +++++ .../externalservice/entity/EnvironmentTest.java | 45 +++++ .../entity/OPerationStatusHandlerTest.java | 63 ++++++ .../entity/OperationStatusTest.java | 48 +++++ .../externalservice/entity/ServiceNodeTest.java | 44 +++++ .../entity/ServiceRegisterEntityTest.java | 68 +++++++ .../vnfsdk/functest/models/CaseRecordTest.java | 55 ++++++ .../vnfsdk/functest/models/TaskRecordTest.java | 65 ++++++ .../responsehandler/TestResultMapTest.java | 51 +++++ .../responsehandler/TestResultParserTest.java | 59 ++++++ .../functest/responsehandler/TestResultTest.java | 44 +++++ .../VnfFuncTestResponseHandlerTest.java | 46 +++++ .../functest/scriptmgr/ScriptManagerTest.java | 173 ++++++++++++++++ .../vnfsdk/functest/taskmgr/TaskManagerTest.java | 218 +++++++++++++++++++++ .../vnfsdk/functest/util/RestResponseUtilTest.java | 68 +++++++ .../onap/vnfsdk/functest/util/TestGsonUtil.java | 56 ++++++ 23 files changed, 1617 insertions(+) create mode 100644 vnf-sdk-function-test/src/test/java/org/onap/vnfsdk/functest/FileUtilTest.java create mode 100644 vnf-sdk-function-test/src/test/java/org/onap/vnfsdk/functest/TaskExecutionTest.java create mode 100644 vnf-sdk-function-test/src/test/java/org/onap/vnfsdk/functest/VnfSdkFuncTestAppConfigurationTest.java create mode 100644 vnf-sdk-function-test/src/test/java/org/onap/vnfsdk/functest/VnfSdkFuncTestAppTest.java create mode 100644 vnf-sdk-function-test/src/test/java/org/onap/vnfsdk/functest/common/TestConfig.java create mode 100644 vnf-sdk-function-test/src/test/java/org/onap/vnfsdk/functest/db/TaskMgrCaseTblDAOTest.java create mode 100644 vnf-sdk-function-test/src/test/java/org/onap/vnfsdk/functest/db/TaskMgrTaskTblDAOTest.java create mode 100644 vnf-sdk-function-test/src/test/java/org/onap/vnfsdk/functest/externalservice/entity/EnvironmentMapTest.java create mode 100644 vnf-sdk-function-test/src/test/java/org/onap/vnfsdk/functest/externalservice/entity/EnvironmentTest.java create mode 100644 vnf-sdk-function-test/src/test/java/org/onap/vnfsdk/functest/externalservice/entity/OPerationStatusHandlerTest.java create mode 100644 vnf-sdk-function-test/src/test/java/org/onap/vnfsdk/functest/externalservice/entity/OperationStatusTest.java create mode 100644 vnf-sdk-function-test/src/test/java/org/onap/vnfsdk/functest/externalservice/entity/ServiceNodeTest.java create mode 100644 vnf-sdk-function-test/src/test/java/org/onap/vnfsdk/functest/externalservice/entity/ServiceRegisterEntityTest.java create mode 100644 vnf-sdk-function-test/src/test/java/org/onap/vnfsdk/functest/models/CaseRecordTest.java create mode 100644 vnf-sdk-function-test/src/test/java/org/onap/vnfsdk/functest/models/TaskRecordTest.java create mode 100644 vnf-sdk-function-test/src/test/java/org/onap/vnfsdk/functest/responsehandler/TestResultMapTest.java create mode 100644 vnf-sdk-function-test/src/test/java/org/onap/vnfsdk/functest/responsehandler/TestResultParserTest.java create mode 100644 vnf-sdk-function-test/src/test/java/org/onap/vnfsdk/functest/responsehandler/TestResultTest.java create mode 100644 vnf-sdk-function-test/src/test/java/org/onap/vnfsdk/functest/responsehandler/VnfFuncTestResponseHandlerTest.java create mode 100644 vnf-sdk-function-test/src/test/java/org/onap/vnfsdk/functest/scriptmgr/ScriptManagerTest.java create mode 100644 vnf-sdk-function-test/src/test/java/org/onap/vnfsdk/functest/taskmgr/TaskManagerTest.java create mode 100644 vnf-sdk-function-test/src/test/java/org/onap/vnfsdk/functest/util/RestResponseUtilTest.java create mode 100644 vnf-sdk-function-test/src/test/java/org/onap/vnfsdk/functest/util/TestGsonUtil.java (limited to 'vnf-sdk-function-test/src/test/java/org/onap') diff --git a/vnf-sdk-function-test/src/test/java/org/onap/vnfsdk/functest/FileUtilTest.java b/vnf-sdk-function-test/src/test/java/org/onap/vnfsdk/functest/FileUtilTest.java new file mode 100644 index 0000000..01e2c0b --- /dev/null +++ b/vnf-sdk-function-test/src/test/java/org/onap/vnfsdk/functest/FileUtilTest.java @@ -0,0 +1,60 @@ +/* + * 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.onap.vnfsdk.functest; + +import org.junit.Test; + +import java.io.File; + +import static org.junit.Assert.assertTrue; + +public class FileUtilTest { + + private String createDirPath = "." + File.separator + "tempvnf"; + + private String deleteDirPath = createDirPath; + + private String zipFileName = "src/test/resources/RobotScript.zip"; + + @Test + public void testCreateDirectory() { + + assertTrue(FileUtil.createDirectory(createDirPath)); + } + + @Test + public void testDeleteDirectory() { + FileUtil.deleteDirectory(deleteDirPath); + } + + @Test + public void testDeleteFile() { + assertTrue(FileUtil.deleteFile(new File(deleteDirPath))); + } + + @Test + public void testGetDirectory() { + FileUtil.getDirectory("."); + assertTrue(true); + } + + @Test + public void testConvertZipFiletoByteArray() { + byte[] byteArrayFile = FileUtil.convertZipFiletoByteArray(zipFileName); + // assertNotNull(byteArrayFile); + } +} diff --git a/vnf-sdk-function-test/src/test/java/org/onap/vnfsdk/functest/TaskExecutionTest.java b/vnf-sdk-function-test/src/test/java/org/onap/vnfsdk/functest/TaskExecutionTest.java new file mode 100644 index 0000000..86dc566 --- /dev/null +++ b/vnf-sdk-function-test/src/test/java/org/onap/vnfsdk/functest/TaskExecutionTest.java @@ -0,0 +1,98 @@ +/* + * 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.onap.vnfsdk.functest; + +import mockit.Mock; +import mockit.MockUp; +import org.junit.Before; +import org.junit.Test; +import org.onap.vnfsdk.functest.externalservice.entity.Environment; +import org.onap.vnfsdk.functest.externalservice.entity.EnvironmentMap; + +import java.util.UUID; + +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 executeId = UUID.randomUUID(); + + @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() { + @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, executeId); + } catch (Exception e) { + e.printStackTrace(); + } + } + + @Test + public void testUploadScript() { + new MockUp() { + @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/onap/vnfsdk/functest/VnfSdkFuncTestAppConfigurationTest.java b/vnf-sdk-function-test/src/test/java/org/onap/vnfsdk/functest/VnfSdkFuncTestAppConfigurationTest.java new file mode 100644 index 0000000..b727e35 --- /dev/null +++ b/vnf-sdk-function-test/src/test/java/org/onap/vnfsdk/functest/VnfSdkFuncTestAppConfigurationTest.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.onap.vnfsdk.functest; + +import io.dropwizard.db.DataSourceFactory; +import org.junit.Test; + +import static org.junit.Assert.assertNotNull; + +public class VnfSdkFuncTestAppConfigurationTest { + + @Test + public void vnfSdkFuncTestBean() { + VnfSdkFuncTestAppConfiguration vnfSdkBean = new VnfSdkFuncTestAppConfiguration(); + vnfSdkBean.setTemplate(""); + vnfSdkBean.setServiceIp("127.0.0.1"); + vnfSdkBean.setDataSourceFactory(new DataSourceFactory()); + + assertNotNull(vnfSdkBean); + assertNotNull(vnfSdkBean.getTemplate()); + assertNotNull(vnfSdkBean.getServiceIp()); + assertNotNull(vnfSdkBean.getDataSourceFactory()); + } +} diff --git a/vnf-sdk-function-test/src/test/java/org/onap/vnfsdk/functest/VnfSdkFuncTestAppTest.java b/vnf-sdk-function-test/src/test/java/org/onap/vnfsdk/functest/VnfSdkFuncTestAppTest.java new file mode 100644 index 0000000..684f8a3 --- /dev/null +++ b/vnf-sdk-function-test/src/test/java/org/onap/vnfsdk/functest/VnfSdkFuncTestAppTest.java @@ -0,0 +1,60 @@ +/* + * 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.onap.vnfsdk.functest; + +import io.dropwizard.Application; +import io.dropwizard.setup.Environment; +import org.junit.Before; +import org.junit.Test; +import org.onap.vnfsdk.functest.common.Config; + +import static org.junit.Assert.assertNotNull; + +public class VnfSdkFuncTestAppTest { + + private VnfSdkFuncTestApp vnfSdkFuncTestApp; + + private Environment environment; + + private Application vnfsdkFuncApp; + + @Before + public void setUp() { + vnfsdkFuncApp = new VnfSdkFuncTestApp(); + } + + @Test + public void RunApp() { + + try { + + VnfSdkFuncTestAppConfiguration oConfig = new VnfSdkFuncTestAppConfiguration(); + Config.setConfigration(oConfig); + + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } + + @Test + public void testGetName() { + assertNotNull(vnfsdkFuncApp.getName()); + } + +} diff --git a/vnf-sdk-function-test/src/test/java/org/onap/vnfsdk/functest/common/TestConfig.java b/vnf-sdk-function-test/src/test/java/org/onap/vnfsdk/functest/common/TestConfig.java new file mode 100644 index 0000000..132fdf8 --- /dev/null +++ b/vnf-sdk-function-test/src/test/java/org/onap/vnfsdk/functest/common/TestConfig.java @@ -0,0 +1,44 @@ +/* + * 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.onap.vnfsdk.functest.common; + +import io.dropwizard.db.DataSourceFactory; +import org.junit.Before; +import org.junit.Test; +import org.onap.vnfsdk.functest.VnfSdkFuncTestAppConfiguration; + +import static org.junit.Assert.assertNotNull; + +public class TestConfig { + + private VnfSdkFuncTestAppConfiguration vnfSdkBean; + + @Before + public void setUp() { + vnfSdkBean = new VnfSdkFuncTestAppConfiguration(); + } + + @Test + public void testVnfSdkConfigBean() { + vnfSdkBean.setTemplate(""); + vnfSdkBean.setServiceIp("127.0.0.1"); + vnfSdkBean.setDataSourceFactory(new DataSourceFactory()); + + Config.setConfigration(vnfSdkBean); + assertNotNull(Config.getConfigration()); + } +} diff --git a/vnf-sdk-function-test/src/test/java/org/onap/vnfsdk/functest/db/TaskMgrCaseTblDAOTest.java b/vnf-sdk-function-test/src/test/java/org/onap/vnfsdk/functest/db/TaskMgrCaseTblDAOTest.java new file mode 100644 index 0000000..11e7f07 --- /dev/null +++ b/vnf-sdk-function-test/src/test/java/org/onap/vnfsdk/functest/db/TaskMgrCaseTblDAOTest.java @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2018 Intel Corporation Intellectual Property + * + * 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.onap.vnfsdk.functest.db; + +import io.dropwizard.testing.junit.DAOTestRule; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.onap.vnfsdk.functest.models.CaseRecord; + +import javax.persistence.PersistenceException; +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; + +public class TaskMgrCaseTblDAOTest { + + @Rule + public DAOTestRule daoTestRule = DAOTestRule.newBuilder() + .addEntityClass(CaseRecord.class) + .build(); + private String taskID = "c0a1a373-8635-484d-bc6c-307a606cb8a1"; + private String funcID = ""; + private String testID = "INTEL"; + private String testResult = "SUCCESS"; + private String testDescription = ""; + private TaskMgrCaseTblDAO taskMgrCaseTblDAO; + + @Before + public void setUp() throws Exception { + taskMgrCaseTblDAO = new TaskMgrCaseTblDAO(daoTestRule.getSessionFactory()); + } + + @Test + public void testSaveOrUpdate() { + final CaseRecord caseRecord = daoTestRule.inTransaction(() -> taskMgrCaseTblDAO.saveOrUpdate(new CaseRecord(taskID, funcID, testID, testResult, testDescription))); + assertThat(caseRecord.getTaskID()).isEqualTo("c0a1a373-8635-484d-bc6c-307a606cb8a1"); + assertThat(caseRecord.getTestID()).isEqualTo("INTEL"); + assertThat(caseRecord.getTestResult()).isEqualTo("SUCCESS"); + assertThat(taskMgrCaseTblDAO.findByTaskID(caseRecord.getTaskID()).equals(caseRecord)); + } + + @Test + public void findAll() { + daoTestRule.inTransaction(() -> { + taskMgrCaseTblDAO.saveOrUpdate(new CaseRecord(taskID, funcID, testID, testResult, testDescription)); + taskID = "c0a1a373-8635-484d-bc6c-307a606cb8a2"; + testResult = "NOT FOUND"; + taskMgrCaseTblDAO.saveOrUpdate(new CaseRecord(taskID, funcID, testID, testResult, testDescription)); + taskID = "c0a1a373-8635-484d-bc6c-307a606cb8a3"; + testResult = "FAILURE"; + taskMgrCaseTblDAO.saveOrUpdate(new CaseRecord(taskID, funcID, testID, testResult, testDescription)); + }); + + final List caseRecordList = taskMgrCaseTblDAO.findAll(); + assertThat(caseRecordList).extracting("taskID").containsOnly("c0a1a373-8635-484d-bc6c-307a606cb8a1", "c0a1a373-8635-484d-bc6c-307a606cb8a2", "c0a1a373-8635-484d-bc6c-307a606cb8a3"); + assertThat(caseRecordList).extracting("testResult").containsOnly("SUCCESS", "NOT FOUND", "FAILURE"); + } + + @Test(expected = PersistenceException.class) + public void handlesNullTaskID() { + testID = null; + daoTestRule.inTransaction(() -> taskMgrCaseTblDAO.saveOrUpdate(new CaseRecord(taskID, funcID, testID, testResult, testDescription))); + } +} diff --git a/vnf-sdk-function-test/src/test/java/org/onap/vnfsdk/functest/db/TaskMgrTaskTblDAOTest.java b/vnf-sdk-function-test/src/test/java/org/onap/vnfsdk/functest/db/TaskMgrTaskTblDAOTest.java new file mode 100644 index 0000000..e6ff003 --- /dev/null +++ b/vnf-sdk-function-test/src/test/java/org/onap/vnfsdk/functest/db/TaskMgrTaskTblDAOTest.java @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2018 Intel Corporation Intellectual Property + * + * 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.onap.vnfsdk.functest.db; + +import io.dropwizard.testing.junit.DAOTestRule; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.onap.vnfsdk.functest.models.TaskRecord; + +import javax.persistence.PersistenceException; +import java.util.List; +import java.util.Optional; + +import static org.assertj.core.api.Assertions.assertThat; + +public class TaskMgrTaskTblDAOTest { + @Rule + public DAOTestRule daoTestRule = DAOTestRule.newBuilder() + .addEntityClass(TaskRecord.class) + .build(); + private String packageID = "1234567890"; + private String taskID = "c0a1a373-8635-484d-bc6c-307a606cb8a1"; + private String envID = "0034b3f3-caea-4138-b186-e260a0cc509c"; + private String uploadID = "3dbf7978-0e5d-4fa8-ade7-bf6450b54a9b"; + private String operID = "3dbf7978-0e5d-4fa8-ade7-bf6450b54a9b"; + private String funcID = ""; + private String status = "CREATED"; + private String operFinished = "True"; + private String operResult = "SUCCESS"; + private String operResultMessage = ""; + private TaskMgrTaskTblDAO taskMgrTaskTblDAO; + + @Before + public void setUp() throws Exception { + taskMgrTaskTblDAO = new TaskMgrTaskTblDAO(daoTestRule.getSessionFactory()); + } + + @Test + public void testSaveOrUpdate() { + final TaskRecord taskRecord = daoTestRule.inTransaction(() -> taskMgrTaskTblDAO.saveOrUpdate(new TaskRecord(packageID, taskID, envID, uploadID, operID, funcID, status, operFinished, operResult, operResultMessage))); + assertThat(taskRecord.getTaskID()).isEqualTo("c0a1a373-8635-484d-bc6c-307a606cb8a1"); + assertThat(taskRecord.getStatus()).isEqualTo("CREATED"); + assertThat(taskRecord.getOperResult()).isEqualTo("SUCCESS"); + assertThat(taskMgrTaskTblDAO.findByPackageID(taskRecord.getPackageID())).isEqualTo(Optional.of(taskRecord)); + assertThat(taskMgrTaskTblDAO.findByTaskID(taskRecord.getTaskID()).get(0).equals(taskRecord)); + } + + @Test + public void findAll() { + daoTestRule.inTransaction(() -> { + taskMgrTaskTblDAO.saveOrUpdate(new TaskRecord(packageID, taskID, envID, uploadID, operID, funcID, status, operFinished, operResult, operResultMessage)); + packageID = "1234567891"; + taskID = "c0a1a373-8635-484d-bc6c-307a606cb8a2"; + status = "NOT FOUND"; + taskMgrTaskTblDAO.saveOrUpdate(new TaskRecord(packageID, taskID, envID, uploadID, operID, funcID, status, operFinished, operResult, operResultMessage)); + packageID = "1234567892"; + taskID = "c0a1a373-8635-484d-bc6c-307a606cb8a3"; + status = "DONE"; + taskMgrTaskTblDAO.saveOrUpdate(new TaskRecord(packageID, taskID, envID, uploadID, operID, funcID, status, operFinished, operResult, operResultMessage)); + }); + + final List taskRecordList = taskMgrTaskTblDAO.findAll(); + assertThat(taskRecordList).extracting("taskID").containsOnly("c0a1a373-8635-484d-bc6c-307a606cb8a1", "c0a1a373-8635-484d-bc6c-307a606cb8a2", "c0a1a373-8635-484d-bc6c-307a606cb8a3"); + assertThat(taskRecordList).extracting("status").containsOnly("CREATED", "NOT FOUND", "DONE"); + } + + @Test(expected = PersistenceException.class) + public void handlesNullTaskID() { + taskID = null; + daoTestRule.inTransaction(() -> taskMgrTaskTblDAO.saveOrUpdate(new TaskRecord(packageID, taskID, envID, uploadID, operID, funcID, status, operFinished, operResult, operResultMessage))); + } +} diff --git a/vnf-sdk-function-test/src/test/java/org/onap/vnfsdk/functest/externalservice/entity/EnvironmentMapTest.java b/vnf-sdk-function-test/src/test/java/org/onap/vnfsdk/functest/externalservice/entity/EnvironmentMapTest.java new file mode 100644 index 0000000..887171b --- /dev/null +++ b/vnf-sdk-function-test/src/test/java/org/onap/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.onap.vnfsdk.functest.externalservice.entity; + +import org.junit.Test; + +import java.util.UUID; + +import static org.junit.Assert.assertNotNull; + +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/onap/vnfsdk/functest/externalservice/entity/EnvironmentTest.java b/vnf-sdk-function-test/src/test/java/org/onap/vnfsdk/functest/externalservice/entity/EnvironmentTest.java new file mode 100644 index 0000000..61ae077 --- /dev/null +++ b/vnf-sdk-function-test/src/test/java/org/onap/vnfsdk/functest/externalservice/entity/EnvironmentTest.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.onap.vnfsdk.functest.externalservice.entity; + +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.assertNotNull; + +public class EnvironmentTest { + private Environment environment = null; + + @Before + public void setUp() { + environment = new Environment(); + } + + @Test + public void testEnvironment() { + environment.setRemoteIp("192.168.4.47"); + environment.setUserName("root"); + environment.setPassword("root123"); + environment.setPath("src\\test\\resources"); + + assertNotNull(environment); + assertNotNull(environment.getRemoteIp()); + assertNotNull(environment.getUserName()); + assertNotNull(environment.getPassword()); + assertNotNull(environment.getPath()); + } +} diff --git a/vnf-sdk-function-test/src/test/java/org/onap/vnfsdk/functest/externalservice/entity/OPerationStatusHandlerTest.java b/vnf-sdk-function-test/src/test/java/org/onap/vnfsdk/functest/externalservice/entity/OPerationStatusHandlerTest.java new file mode 100644 index 0000000..bbfc3db --- /dev/null +++ b/vnf-sdk-function-test/src/test/java/org/onap/vnfsdk/functest/externalservice/entity/OPerationStatusHandlerTest.java @@ -0,0 +1,63 @@ +/* + * 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.onap.vnfsdk.functest.externalservice.entity; + +import org.junit.Test; +import org.onap.vnfsdk.functest.externalservice.entity.OperationStatus.operResultCode; + +import javax.ws.rs.core.Response; +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +public class OPerationStatusHandlerTest { + + private UUID uuid = UUID.randomUUID(); + + private Map operStatusMap = new HashMap(); + + 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/onap/vnfsdk/functest/externalservice/entity/OperationStatusTest.java b/vnf-sdk-function-test/src/test/java/org/onap/vnfsdk/functest/externalservice/entity/OperationStatusTest.java new file mode 100644 index 0000000..37b8d2a --- /dev/null +++ b/vnf-sdk-function-test/src/test/java/org/onap/vnfsdk/functest/externalservice/entity/OperationStatusTest.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.onap.vnfsdk.functest.externalservice.entity; + +import org.junit.Before; +import org.junit.Test; +import org.onap.vnfsdk.functest.externalservice.entity.OperationStatus.operResultCode; + +import static org.junit.Assert.assertNotNull; + + +public class OperationStatusTest { + + private OperationStatus operationStatus = null; + + @Before + public void setUp() { + operationStatus = new OperationStatus(); + } + + @Test + public void testOperationStatus() { + operationStatus.setoResultCode(operResultCode.SUCCESS); + operationStatus.setOperResultMessage("success"); + operationStatus.setOperFinished(true); + + assertNotNull(operationStatus); + assertNotNull(operationStatus.getoResultCode()); + assertNotNull(operationStatus.getoResultCode()); + assertNotNull(operationStatus.isOperFinished()); + + } + +} diff --git a/vnf-sdk-function-test/src/test/java/org/onap/vnfsdk/functest/externalservice/entity/ServiceNodeTest.java b/vnf-sdk-function-test/src/test/java/org/onap/vnfsdk/functest/externalservice/entity/ServiceNodeTest.java new file mode 100644 index 0000000..24e780f --- /dev/null +++ b/vnf-sdk-function-test/src/test/java/org/onap/vnfsdk/functest/externalservice/entity/ServiceNodeTest.java @@ -0,0 +1,44 @@ +/* + * 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.onap.vnfsdk.functest.externalservice.entity; + +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.assertNotNull; + +public class ServiceNodeTest { + + private ServiceNode serviceNode = null; + + @Before + public void setUp() { + serviceNode = new ServiceNode(); + } + + @Test + public void testServiceNode() { + serviceNode.setIp("192.168.4.47"); + serviceNode.setPort("8080"); + serviceNode.setTtl(10); + + assertNotNull(serviceNode); + assertNotNull(serviceNode.getIp()); + assertNotNull(serviceNode.getPort()); + assertNotNull(serviceNode.getTtl()); + } +} diff --git a/vnf-sdk-function-test/src/test/java/org/onap/vnfsdk/functest/externalservice/entity/ServiceRegisterEntityTest.java b/vnf-sdk-function-test/src/test/java/org/onap/vnfsdk/functest/externalservice/entity/ServiceRegisterEntityTest.java new file mode 100644 index 0000000..493882f --- /dev/null +++ b/vnf-sdk-function-test/src/test/java/org/onap/vnfsdk/functest/externalservice/entity/ServiceRegisterEntityTest.java @@ -0,0 +1,68 @@ +/* + * 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.onap.vnfsdk.functest.externalservice.entity; + +import org.junit.Before; +import org.junit.Test; + +import java.util.ArrayList; +import java.util.List; + +import static org.junit.Assert.assertNotNull; + +public class ServiceRegisterEntityTest { + + private ServiceRegisterEntity serviceRegistry; + private ServiceNode serviceNode; + + @Before + public void setUp() { + serviceRegistry = new ServiceRegisterEntity(); + serviceNode = new ServiceNode(); + } + + @Test + public void ServiceRegisterEntity() { + + List nodes = new ArrayList(); + + serviceRegistry.setServiceName("nfvo"); + serviceRegistry.setVersion("5.6"); + serviceRegistry.setProtocol("http"); + serviceRegistry.setVisualRange("range"); + + serviceNode.setIp("192.168.4.47"); + serviceNode.setPort("8080"); + serviceNode.setTtl(10); + nodes.add(serviceNode); + + serviceRegistry.setNodes(nodes); + + assertNotNull(serviceRegistry); + assertNotNull(serviceRegistry.getServiceName()); + assertNotNull(serviceRegistry.getVersion()); + assertNotNull(serviceRegistry.getProtocol()); + assertNotNull(serviceRegistry.getVisualRange()); + assertNotNull(serviceRegistry.getNodes()); + + } + + @Test + public void testSetSingleNode() { + serviceRegistry.setSingleNode("192.168.4.47", "8080", 10); + } +} diff --git a/vnf-sdk-function-test/src/test/java/org/onap/vnfsdk/functest/models/CaseRecordTest.java b/vnf-sdk-function-test/src/test/java/org/onap/vnfsdk/functest/models/CaseRecordTest.java new file mode 100644 index 0000000..49535df --- /dev/null +++ b/vnf-sdk-function-test/src/test/java/org/onap/vnfsdk/functest/models/CaseRecordTest.java @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2018 Intel Corporation Intellectual Property + * + * 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.onap.vnfsdk.functest.models; + +import org.junit.Before; +import org.junit.Test; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertThat; + +public class CaseRecordTest { + + private CaseRecord caseRecord = null; + + private String taskID = "c0a1a373-8635-484d-bc6c-307a606cb8a1"; + private String funcID = ""; + private String testID = "INTEL"; + private String testResult = "SUCCESS"; + private String testDescription = ""; + + @Before + public void setUp() { + caseRecord = new CaseRecord(); + } + + @Test + public void testCaseRecord() { + caseRecord.setTaskID(taskID); + caseRecord.setFuncID(funcID); + caseRecord.setTestID(testID); + caseRecord.setTestResult(testResult); + caseRecord.setTestDescription(testDescription); + + assertNotNull(caseRecord); + assertNotNull(caseRecord.getTestID()); + assertThat(caseRecord.getTestID(), is("INTEL")); + assertNotNull(caseRecord.getTestResult(), is("SUCCESS")); + assertNotNull(caseRecord.getTestDescription(), is("")); + } +} diff --git a/vnf-sdk-function-test/src/test/java/org/onap/vnfsdk/functest/models/TaskRecordTest.java b/vnf-sdk-function-test/src/test/java/org/onap/vnfsdk/functest/models/TaskRecordTest.java new file mode 100644 index 0000000..f51a6b5 --- /dev/null +++ b/vnf-sdk-function-test/src/test/java/org/onap/vnfsdk/functest/models/TaskRecordTest.java @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2018 Intel Corporation Intellectual Property + * + * 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.onap.vnfsdk.functest.models; + +import org.junit.Before; +import org.junit.Test; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertThat; + +public class TaskRecordTest { + + private TaskRecord taskRecord = null; + + private String packageID = "1234567890"; + private String taskID = "c0a1a373-8635-484d-bc6c-307a606cb8a1"; + private String envID = "0034b3f3-caea-4138-b186-e260a0cc509c"; + private String uploadID = "3dbf7978-0e5d-4fa8-ade7-bf6450b54a9b"; + private String operID = "3dbf7978-0e5d-4fa8-ade7-bf6450b54a9b"; + private String funcID = ""; + private String status = "CREATED"; + private String operFinished = "True"; + private String operResult = "SUCCESS"; + private String operResultMessage = ""; + + @Before + public void setUp() { + taskRecord = new TaskRecord(); + } + + @Test + public void testTaskRecord() { + taskRecord.setPackageID(packageID); + taskRecord.setTaskID(taskID); + taskRecord.setEnvID(envID); + taskRecord.setUploadID(uploadID); + taskRecord.setOperID(operID); + taskRecord.setFuncID(funcID); + taskRecord.setStatus(status); + taskRecord.setOperFinished(operFinished); + taskRecord.setOperResult(operResult); + taskRecord.setOperResultMessage(operResultMessage); + + assertNotNull(taskRecord); + assertNotNull(taskRecord.getPackageID()); + assertThat(taskRecord.getTaskID(), is("c0a1a373-8635-484d-bc6c-307a606cb8a1")); + assertNotNull(taskRecord.getOperFinished(), is("True")); + assertNotNull(taskRecord.getOperResult(), is("SUCCESS")); + } +} diff --git a/vnf-sdk-function-test/src/test/java/org/onap/vnfsdk/functest/responsehandler/TestResultMapTest.java b/vnf-sdk-function-test/src/test/java/org/onap/vnfsdk/functest/responsehandler/TestResultMapTest.java new file mode 100644 index 0000000..e70be84 --- /dev/null +++ b/vnf-sdk-function-test/src/test/java/org/onap/vnfsdk/functest/responsehandler/TestResultMapTest.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2018 Intel Corporation Intellectual Property + * + * 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.onap.vnfsdk.functest.responsehandler; + +import org.junit.Test; + +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +import static org.junit.Assert.assertNotNull; + +public class TestResultMapTest { + + private UUID uuid = UUID.randomUUID(); + + private Map testResultMap = new HashMap(); + + @Test + public void testGetInstance() { + assertNotNull(TestResultMap.getInstance()); + } + + @Test + public void testGetTestResultMap() { + assertNotNull(TestResultMap.getInstance().getTestResultMap()); + } + + @Test + public void testSetTestResultMap() { + TestResult testResult = new TestResult(); + testResult.setName("INTEL"); + testResult.setStatus("SUCCESS"); + testResult.setDescription("INTEL TEST"); + testResultMap.put(uuid, testResult); + } +} diff --git a/vnf-sdk-function-test/src/test/java/org/onap/vnfsdk/functest/responsehandler/TestResultParserTest.java b/vnf-sdk-function-test/src/test/java/org/onap/vnfsdk/functest/responsehandler/TestResultParserTest.java new file mode 100644 index 0000000..2357346 --- /dev/null +++ b/vnf-sdk-function-test/src/test/java/org/onap/vnfsdk/functest/responsehandler/TestResultParserTest.java @@ -0,0 +1,59 @@ +/* + * 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.onap.vnfsdk.functest.responsehandler; + +import org.junit.Before; +import org.junit.Test; + +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + +import static org.junit.Assert.assertNotNull; + +public class TestResultParserTest { + + private TestResultParser testResParser = null; + private UUID UUIDTask = UUID.randomUUID(); + + @Before + public void setUp() { + testResParser = new TestResultParser(); + } + + @Test + public void testPopulateResultList() { + assertNotNull(testResParser.populateResultList(UUIDTask.toString(), "src/test/resources/sample.xml")); + } + + @Test + public void testParseResultData() { + String taskID = "12919afc-5975-4da9-bd41-c050b305262c"; + String xmlFile = "src/test/resources/sample.xml"; + List resultData = new ArrayList<>(); + try { + Class resParser = Class.forName("org.onap.vnfsdk.functest.responsehandler.TestResultParser"); + Object resParserObj = resParser.newInstance(); + Method m = resParserObj.getClass().getDeclaredMethod("parseResultData", new Class[]{String.class, String.class, List.class}); + m.setAccessible(true); + m.invoke(resParserObj, taskID, xmlFile, resultData); + } catch (Exception e) { + e.printStackTrace(); + } + } +} diff --git a/vnf-sdk-function-test/src/test/java/org/onap/vnfsdk/functest/responsehandler/TestResultTest.java b/vnf-sdk-function-test/src/test/java/org/onap/vnfsdk/functest/responsehandler/TestResultTest.java new file mode 100644 index 0000000..d5bd6b0 --- /dev/null +++ b/vnf-sdk-function-test/src/test/java/org/onap/vnfsdk/functest/responsehandler/TestResultTest.java @@ -0,0 +1,44 @@ +/* + * 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.onap.vnfsdk.functest.responsehandler; + +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.assertNotNull; + +public class TestResultTest { + + private TestResult testResult = null; + + @Before + public void setUp() { + testResult = new TestResult(); + } + + @Test + public void testResultTest() { + testResult.setName("Huawei"); + testResult.setDescription("description"); + testResult.setStatus("success"); + + assertNotNull(testResult); + assertNotNull(testResult.getName()); + assertNotNull(testResult.getStatus()); + assertNotNull(testResult.getDescription()); + } +} diff --git a/vnf-sdk-function-test/src/test/java/org/onap/vnfsdk/functest/responsehandler/VnfFuncTestResponseHandlerTest.java b/vnf-sdk-function-test/src/test/java/org/onap/vnfsdk/functest/responsehandler/VnfFuncTestResponseHandlerTest.java new file mode 100644 index 0000000..26007e3 --- /dev/null +++ b/vnf-sdk-function-test/src/test/java/org/onap/vnfsdk/functest/responsehandler/VnfFuncTestResponseHandlerTest.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.onap.vnfsdk.functest.responsehandler; + +import org.junit.Test; + +import java.lang.reflect.Method; + +import static org.junit.Assert.assertNotNull; + +public class VnfFuncTestResponseHandlerTest { + + private VnfFuncTestResponseHandler vnfSdkFuncHandler; + + @Test + public void testGetInstance() { + vnfSdkFuncHandler = VnfFuncTestResponseHandler.getInstance(); + assertNotNull(vnfSdkFuncHandler); + } + + @Test + public void testLoadConfigurations() { + try { + Object vnfFuncTestResponseHandlerObj = VnfFuncTestResponseHandler.getInstance(); + Method m = vnfFuncTestResponseHandlerObj.getClass().getDeclaredMethod("loadConfigurations"); + m.setAccessible(true); + m.invoke(vnfFuncTestResponseHandlerObj); + } catch (Exception e) { + e.printStackTrace(); + } + } +} diff --git a/vnf-sdk-function-test/src/test/java/org/onap/vnfsdk/functest/scriptmgr/ScriptManagerTest.java b/vnf-sdk-function-test/src/test/java/org/onap/vnfsdk/functest/scriptmgr/ScriptManagerTest.java new file mode 100644 index 0000000..cf77560 --- /dev/null +++ b/vnf-sdk-function-test/src/test/java/org/onap/vnfsdk/functest/scriptmgr/ScriptManagerTest.java @@ -0,0 +1,173 @@ +/* + * Copyright (c) 2018 Intel Corporation Intellectual Property + * + * 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.onap.vnfsdk.functest.scriptmgr; + +import io.dropwizard.testing.junit.DAOTestRule; +import mockit.Mock; +import mockit.MockUp; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.onap.vnfsdk.functest.FileUtil; +import org.onap.vnfsdk.functest.db.TaskMgrCaseTblDAO; +import org.onap.vnfsdk.functest.db.TaskMgrTaskTblDAO; +import org.onap.vnfsdk.functest.externalservice.entity.OperationStatus; +import org.onap.vnfsdk.functest.externalservice.entity.OperationStatusHandler; +import org.onap.vnfsdk.functest.models.CaseRecord; +import org.onap.vnfsdk.functest.models.TaskRecord; +import org.onap.vnfsdk.functest.responsehandler.VnfFuncTestResponseHandler; +import org.onap.vnfsdk.functest.util.RestResponseUtil; +import org.onap.vnfsdk.functest.util.ZipCompressor; + +import javax.ws.rs.core.Response; +import java.io.File; +import java.io.FileInputStream; +import java.io.InputStream; +import java.net.URL; +import java.util.UUID; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +public class ScriptManagerTest { + + @Rule + public DAOTestRule daoTestRule = DAOTestRule.newBuilder() + .addEntityClass(TaskRecord.class) + .addEntityClass(CaseRecord.class) + .build(); + private ScriptManager scriptManager; + private TaskMgrTaskTblDAO taskMgrTaskTblDAO; + private TaskMgrCaseTblDAO taskMgrCaseTblDAO; + private String instanceId; + private UUID taskID = UUID.fromString("59d1e651-df9f-4008-902f-e3b377e6ec30"); + private UUID envID = UUID.fromString("f5881897-c748-4f6e-9294-92c730faa001"); + private UUID operID = UUID.fromString("ed058d84-4a42-4c8e-8ecf-90de4c5a8bc8"); + private Response response = null; + + @Before + public void setUp() { + taskMgrTaskTblDAO = new TaskMgrTaskTblDAO(daoTestRule.getSessionFactory()); + taskMgrCaseTblDAO = new TaskMgrCaseTblDAO(daoTestRule.getSessionFactory()); + scriptManager = new ScriptManager(taskMgrTaskTblDAO, taskMgrCaseTblDAO); + } + + @Test + public void testUploadFuncTestPackage() { + URL url = Thread.currentThread().getContextClassLoader().getResource("RobotScript"); + // Some temporary folder uploaded in github + String zipFileName = "https://github.com/zoul/Finch/zipball/master/"; + + new MockUp() { + + @Mock + public String[] getDirectory(String directory) { + File file = new File("temp"); + return file.list(); + } + }; + + try { + // InputStream mockInputStream = new FileInputStream(zipFileName); + UUID uploadID = scriptManager.uploadFuncTestPackage(taskID, envID, zipFileName); + assertNotNull(uploadID); + } catch (Exception e) { + e.printStackTrace(); + } + } + + @Test + public void testGetOperationResult() { + try { + response = scriptManager.getOperationResult(operID); + assertNotNull(response); + assertEquals(200, response.getStatus()); + } catch (Exception e) { + e.printStackTrace(); + } + } + + @Test + public void testDownloadResults() { + MockUp mockOperationStatusHandler = new MockUp() { + + @Mock + public Response getOperationStatus(UUID uuid) { + OperationStatus operstatus = new OperationStatus(); + operstatus.setOperFinished(true); + operstatus.setoResultCode(OperationStatus.operResultCode.SUCCESS); + operstatus.setOperResultMessage("finished"); + return response; + } + }; + + MockUp mockVnfFuncTestResponseHandler = new MockUp() { + + @Mock + public Response downloadResults(String taskID) { + OperationStatus operstatus = new OperationStatus(); + operstatus.setOperFinished(true); + operstatus.setoResultCode(OperationStatus.operResultCode.SUCCESS); + operstatus.setOperResultMessage("finished"); + + return RestResponseUtil.getSuccessResponse(operstatus); + } + }; + + try { + response = scriptManager.downloadResults(taskID); + assertNotNull(response); + assertEquals(200, response.getStatus()); + } catch (Exception e) { + e.printStackTrace(); + } + + mockOperationStatusHandler.tearDown(); + mockVnfFuncTestResponseHandler.tearDown(); + } + + @Test + public void testStoreChunkFileInLocal() { + URL url = Thread.currentThread().getContextClassLoader().getResource("RobotScript"); + String zipFileName = url.getPath() + ".zip"; + + try { + new ZipCompressor(zipFileName).compress(url.getPath()); + InputStream mockInputStream = new FileInputStream(zipFileName); + String chunkFilePath = + scriptManager.storeChunkFileInLocal("src/test/resources", "chunkFileInLocal", mockInputStream); + assertNotNull(chunkFilePath); + } catch (Exception e) { + e.printStackTrace(); + } + } + + @Test + public void testSetEnvironment() { + try { + + String jsonInput = + "{\"remoteIp\":\"192.168.4.47\",\"userName\":\"root\",\"password\":\"root123\", \"path\":\"/src/test/resources\"}"; + envID = scriptManager.setEnvironment(jsonInput); +// scriptManager.executeFunctionTest(taskID.toString(), response.getEntity().toString(), "robot"); + assertNotNull(envID); + } catch (Exception e) { + e.printStackTrace(); + } + } + +} diff --git a/vnf-sdk-function-test/src/test/java/org/onap/vnfsdk/functest/taskmgr/TaskManagerTest.java b/vnf-sdk-function-test/src/test/java/org/onap/vnfsdk/functest/taskmgr/TaskManagerTest.java new file mode 100644 index 0000000..921a8e0 --- /dev/null +++ b/vnf-sdk-function-test/src/test/java/org/onap/vnfsdk/functest/taskmgr/TaskManagerTest.java @@ -0,0 +1,218 @@ +/* + * Copyright (c) 2018 Intel Corporation Intellectual Property + * + * 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.onap.vnfsdk.functest.taskmgr; + +import io.dropwizard.testing.junit.DAOTestRule; +import mockit.Mock; +import mockit.MockUp; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.onap.vnfsdk.functest.db.TaskMgrCaseTblDAO; +import org.onap.vnfsdk.functest.db.TaskMgrTaskTblDAO; +import org.onap.vnfsdk.functest.externalservice.entity.OperationStatus; +import org.onap.vnfsdk.functest.externalservice.entity.OperationStatusHandler; +import org.onap.vnfsdk.functest.models.CaseRecord; +import org.onap.vnfsdk.functest.models.TaskRecord; +import org.onap.vnfsdk.functest.scriptmgr.ScriptManager; +import org.onap.vnfsdk.functest.util.RestResponseUtil; + +import javax.ws.rs.core.Response; +import java.lang.reflect.Method; +import java.util.UUID; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +public class TaskManagerTest { + + @Rule + public DAOTestRule daoTestRule = DAOTestRule.newBuilder() + .addEntityClass(TaskRecord.class) + .addEntityClass(CaseRecord.class) + .build(); + private TaskManager taskManager; + private ScriptManager scriptManager; + private TaskMgrTaskTblDAO taskMgrTaskTblDAO; + private TaskMgrCaseTblDAO taskMgrCaseTblDAO; + private Response response = null; + private TaskManager.RequestBody requestBody; + private String packageID = "1234567890"; + private String taskID = "c0a1a373-8635-484d-bc6c-307a606cb8a1"; + private String envID = "0034b3f3-caea-4138-b186-e260a0cc509c"; + private String uploadID = "3dbf7978-0e5d-4fa8-ade7-bf6450b54a9b"; + private String operID = "3dbf7978-0e5d-4fa8-ade7-bf6450b54a9b"; + private String funcID = ""; + private String status = "CREATED"; + private String operFinished = "True"; + private String operResult = "SUCCESS"; + private String operResultMessage = ""; + private String testID = "NOT CREATED"; + private String testResult = "NULL"; + private String testDescription = ""; + + @Before + public void setUp() throws Exception { + taskMgrTaskTblDAO = new TaskMgrTaskTblDAO(daoTestRule.getSessionFactory()); + taskMgrCaseTblDAO = new TaskMgrCaseTblDAO(daoTestRule.getSessionFactory()); + scriptManager = new ScriptManager(taskMgrTaskTblDAO, taskMgrCaseTblDAO); + taskManager = new TaskManager(taskMgrTaskTblDAO, taskMgrCaseTblDAO, scriptManager); + requestBody = new TaskManager.RequestBody(); + requestBody.setPackageID("1234567890"); + } + + @Test + public void testStartOnboardTestingPackageIDAbsentInDB() { + new MockUp() { + @Mock + public UUID uploadFuncTestPackage(UUID taskID, UUID envID, String url) { + return UUID.randomUUID(); + } + }; + + try { + response = taskManager.startOnboardTesting(requestBody); + assertNotNull(response); + assertEquals(201, response.getStatus()); + } catch (Exception e) { + e.printStackTrace(); + } + } + + @Test + public void testStartOnboardTestingPackageIDAlreadyPresentInDB() { + try { + daoTestRule.inTransaction(() -> taskMgrTaskTblDAO.saveOrUpdate(new TaskRecord(packageID, taskID, envID, uploadID, operID, funcID, status, operFinished, operResult, operResultMessage))); + response = taskManager.startOnboardTesting(requestBody); + assertNotNull(response); + assertEquals(500, response.getStatus()); + } catch (Exception e) { + e.printStackTrace(); + } + } + + @Test + public void testQueryTestStatusPresentInDB() { + try { + daoTestRule.inTransaction(() -> taskMgrTaskTblDAO.saveOrUpdate(new TaskRecord(packageID, taskID, envID, uploadID, operID, funcID, status, operFinished, operResult, operResultMessage))); + response = taskManager.queryTestStatus(taskID); + assertNotNull(response); + assertEquals(200, response.getStatus()); + } catch (Exception e) { + e.printStackTrace(); + } + } + + @Test + public void testQueryTestStatusPresentInOperationStatus() { + try { + daoTestRule.inTransaction(() -> taskMgrTaskTblDAO.saveOrUpdate(new TaskRecord(packageID, taskID, envID, uploadID, operID, funcID, status, operFinished, operResult, operResultMessage))); + UUID operID = UUID.fromString(taskMgrTaskTblDAO.findByTaskID(taskID).get(0).getOperID()); + OperationStatus operStatus = new OperationStatus(); + operStatus.setoResultCode(OperationStatus.operResultCode.SUCCESS); + operStatus.setOperResultMessage("Execute function test finished"); + operStatus.setOperFinished(true); + OperationStatusHandler.getInstance().setOperStatusMap(operID, operStatus); + + response = taskManager.queryTestStatus(taskID); + assertNotNull(response); + assertEquals(200, response.getStatus()); + } catch (Exception e) { + e.printStackTrace(); + } + } + + @Test + public void testQueryTestStatusAbsent() { + try { + response = taskManager.queryTestStatus(taskID); + assertNotNull(response); + assertEquals(404, response.getStatus()); + } catch (Exception e) { + e.printStackTrace(); + } + } + + @Test + public void testCollectTaskResultCreated() { + try { + testID = "INTEL"; + daoTestRule.inTransaction(() -> taskMgrCaseTblDAO.saveOrUpdate(new CaseRecord(taskID, funcID, testID, testResult, testDescription))); + response = taskManager.collectTaskResult(taskID); + assertNotNull(response); + assertEquals(200, response.getStatus()); + } catch (Exception e) { + e.printStackTrace(); + } + } + + @Test + public void testCollectTaskResultUncreated() { + new MockUp() { + @Mock + public Response downloadResults(UUID taskID) { + return RestResponseUtil.getSuccessResponse(null); + } + }; + try { + daoTestRule.inTransaction(() -> taskMgrCaseTblDAO.saveOrUpdate(new CaseRecord(taskID, funcID, testID, testResult, testDescription))); + response = taskManager.collectTaskResult(taskID); + assertNotNull(response); + assertEquals(200, response.getStatus()); + } catch (Exception e) { + e.printStackTrace(); + } + } + + @Test + public void testCollectTaskResultAbsent() { + try { + response = taskManager.collectTaskResult(taskID); + assertNotNull(response); + assertEquals(404, response.getStatus()); + } catch (Exception e) { + e.printStackTrace(); + } + } + + @Test + public void testInitOnboardTesting() { + TaskRecord taskRecord = new TaskRecord(); + CaseRecord caseRecord = new CaseRecord(); + + try { + TaskManager taskManagerObj = new TaskManager(taskMgrTaskTblDAO, taskMgrCaseTblDAO, scriptManager); + Method m = taskManagerObj.getClass().getDeclaredMethod("initOnboardTesting", new Class[]{TaskRecord.class, CaseRecord.class, String.class}); + m.setAccessible(true); + m.invoke(taskManagerObj, taskRecord, caseRecord, packageID); + } catch (Exception e) { + e.printStackTrace(); + } + } + + @Test + public void testLoadEnvConfigurations() { + try { + TaskManager loadEnvConfigurationsObj = new TaskManager(taskMgrTaskTblDAO, taskMgrCaseTblDAO, scriptManager); + Method m = loadEnvConfigurationsObj.getClass().getDeclaredMethod("loadEnvConfigurations"); + m.setAccessible(true); + m.invoke(loadEnvConfigurationsObj); + } catch (Exception e) { + e.printStackTrace(); + } + } +} diff --git a/vnf-sdk-function-test/src/test/java/org/onap/vnfsdk/functest/util/RestResponseUtilTest.java b/vnf-sdk-function-test/src/test/java/org/onap/vnfsdk/functest/util/RestResponseUtilTest.java new file mode 100644 index 0000000..fcb47dc --- /dev/null +++ b/vnf-sdk-function-test/src/test/java/org/onap/vnfsdk/functest/util/RestResponseUtilTest.java @@ -0,0 +1,68 @@ +/* + * 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.onap.vnfsdk.functest.util; + +import org.junit.Before; +import org.junit.Test; +import org.onap.vnfsdk.functest.externalservice.entity.Environment; + +import javax.ws.rs.core.Response; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +public class RestResponseUtilTest { + + private Response response; + private Object envObj; + + @Before + public void setUp() { + envObj = new Environment(); + ((Environment) envObj).setRemoteIp("192.168.4.47"); + ((Environment) envObj).setUserName("root"); + ((Environment) envObj).setPassword("root123"); + ((Environment) envObj).setPath("src\\test\\resources"); + } + + + @Test + public void testGetSuccessResponse() { + response = RestResponseUtil.getSuccessResponse(envObj); + assertNotNull(response); + assertEquals(200, response.getStatus()); + } + + @Test + public void testGetCreateSussceeResponse() { + response = RestResponseUtil.getCreateSuccessResponse(envObj); + assertNotNull(response); + assertEquals(201, response.getStatus()); + } + + @Test + public void testGetErrorResponse() { + response = RestResponseUtil.getErrorResponse(envObj); + assertEquals(500, response.getStatus()); + } + + @Test + public void testGetNotFoundResponse() { + response = RestResponseUtil.getNotFoundResponse(envObj); + assertEquals(404, response.getStatus()); + } +} diff --git a/vnf-sdk-function-test/src/test/java/org/onap/vnfsdk/functest/util/TestGsonUtil.java b/vnf-sdk-function-test/src/test/java/org/onap/vnfsdk/functest/util/TestGsonUtil.java new file mode 100644 index 0000000..04687ca --- /dev/null +++ b/vnf-sdk-function-test/src/test/java/org/onap/vnfsdk/functest/util/TestGsonUtil.java @@ -0,0 +1,56 @@ +/* + * 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.onap.vnfsdk.functest.util; + +import org.junit.Test; +import org.onap.vnfsdk.functest.externalservice.entity.Environment; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +public class TestGsonUtil { + + @Test + public void testGenerateId() { + assertNotNull(GsonUtil.generateId()); + } + + @Test + public void testIsNotEmpty() { + assertTrue(GsonUtil.isNotEmpty("junittestcase")); + } + + @Test + public void testGetNowTime() { + assertNotNull(GsonUtil.getNowTime()); + } + + @Test + public void testObjectToString() { + try { + Object envObj = new Environment(); + ((Environment) envObj).setRemoteIp("192.168.4.47"); + ((Environment) envObj).setUserName("root"); + ((Environment) envObj).setPassword("root123"); + ((Environment) envObj).setPath("src\\test\\resources"); + + assertNotNull(GsonUtil.objectToString(envObj)); + } catch (Exception e) { + e.printStackTrace(); + } + } +} -- cgit 1.2.3-korg