summaryrefslogtreecommitdiffstats
path: root/vnf-sdk-function-test
diff options
context:
space:
mode:
Diffstat (limited to 'vnf-sdk-function-test')
-rw-r--r--vnf-sdk-function-test/pom.xml7
-rw-r--r--vnf-sdk-function-test/src/test/java/org/onap/vnfsdk/functest/TaskExecutionTest.java47
-rw-r--r--vnf-sdk-function-test/src/test/java/org/onap/vnfsdk/functest/scriptmgr/ScriptManagerTest.java60
-rw-r--r--vnf-sdk-function-test/src/test/java/org/onap/vnfsdk/functest/taskmgr/TaskManagerTest.java30
4 files changed, 63 insertions, 81 deletions
diff --git a/vnf-sdk-function-test/pom.xml b/vnf-sdk-function-test/pom.xml
index d2b3be9..12ba2a8 100644
--- a/vnf-sdk-function-test/pom.xml
+++ b/vnf-sdk-function-test/pom.xml
@@ -286,12 +286,7 @@
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>2.0.2-beta</version>
- </dependency>
- <!-- https://mvnrepository.com/artifact/org.jmockit/jmockit -->
- <dependency>
- <groupId>org.jmockit</groupId>
- <artifactId>jmockit</artifactId>
- <version>1.25</version>
+ <scope>test</scope>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
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
index 86dc566..e17c017 100644
--- 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
@@ -16,15 +16,20 @@
package org.onap.vnfsdk.functest;
-import mockit.Mock;
-import mockit.MockUp;
import org.junit.Before;
import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mockito;
import org.onap.vnfsdk.functest.externalservice.entity.Environment;
import org.onap.vnfsdk.functest.externalservice.entity.EnvironmentMap;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+import org.powermock.reflect.Whitebox;
import java.util.UUID;
+@RunWith(PowerMockRunner.class)
public class TaskExecutionTest {
private TaskExecution testExecution = null;
@@ -57,17 +62,16 @@ public class TaskExecutionTest {
}
@Test
+ @PrepareForTest(EnvironmentMap.class)
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;
- }
- };
+ EnvironmentMap mockEnvironmentMap = PowerMockito.mock(EnvironmentMap.class);
+ Whitebox.setInternalState(EnvironmentMap.class, "oInstance", mockEnvironmentMap);
+ functestEnv.setRemoteIp(remoteIP);
+ functestEnv.setUserName(userName);
+ functestEnv.setPassword(password);
+ functestEnv.setPath(path);
+ PowerMockito.when(mockEnvironmentMap.getEnv(Mockito.any())).thenReturn(functestEnv);
+
try {
testExecution.executeRobotScript(envId, executeId);
} catch (Exception e) {
@@ -76,17 +80,16 @@ public class TaskExecutionTest {
}
@Test
+ @PrepareForTest(EnvironmentMap.class)
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;
- }
- };
+ EnvironmentMap mockEnvironmentMap = PowerMockito.mock(EnvironmentMap.class);
+ Whitebox.setInternalState(EnvironmentMap.class, "oInstance", mockEnvironmentMap);
+ functestEnv.setRemoteIp(remoteIP);
+ functestEnv.setUserName(userName);
+ functestEnv.setPassword(password);
+ functestEnv.setPath(path);
+ PowerMockito.when(mockEnvironmentMap.getEnv(Mockito.any())).thenReturn(functestEnv);
+
try {
testExecution.uploadScript(dirPath, UUIDEnv, UUIDUpload);
} catch (Exception e) {
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
index cf77560..1f799e4 100644
--- 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
@@ -17,11 +17,11 @@
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.junit.runner.RunWith;
+import org.mockito.Mockito;
import org.onap.vnfsdk.functest.FileUtil;
import org.onap.vnfsdk.functest.db.TaskMgrCaseTblDAO;
import org.onap.vnfsdk.functest.db.TaskMgrTaskTblDAO;
@@ -32,6 +32,10 @@ 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 org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+import org.powermock.reflect.Whitebox;
import javax.ws.rs.core.Response;
import java.io.File;
@@ -43,6 +47,7 @@ import java.util.UUID;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+@RunWith(PowerMockRunner.class)
public class ScriptManagerTest {
@Rule
@@ -67,19 +72,15 @@ public class ScriptManagerTest {
}
@Test
+ @PrepareForTest({FileUtil.class})
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<FileUtil>() {
-
- @Mock
- public String[] getDirectory(String directory) {
- File file = new File("temp");
- return file.list();
- }
- };
+ File file = new File("temp");
+ PowerMockito.mockStatic(FileUtil.class);
+ PowerMockito.when(FileUtil.getDirectory(Mockito.anyString())).thenReturn(file.list());
try {
// InputStream mockInputStream = new FileInputStream(zipFileName);
@@ -102,31 +103,19 @@ public class ScriptManagerTest {
}
@Test
+ @PrepareForTest({OperationStatusHandler.class, VnfFuncTestResponseHandler.class})
public void testDownloadResults() {
- MockUp<OperationStatusHandler> mockOperationStatusHandler = new MockUp<OperationStatusHandler>() {
-
- @Mock
- public Response getOperationStatus(UUID uuid) {
- OperationStatus operstatus = new OperationStatus();
- operstatus.setOperFinished(true);
- operstatus.setoResultCode(OperationStatus.operResultCode.SUCCESS);
- operstatus.setOperResultMessage("finished");
- return response;
- }
- };
-
- MockUp<VnfFuncTestResponseHandler> mockVnfFuncTestResponseHandler = new MockUp<VnfFuncTestResponseHandler>() {
-
- @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);
- }
- };
+ OperationStatusHandler mockOperationStatusHandler = PowerMockito.mock(OperationStatusHandler.class);
+ Whitebox.setInternalState(OperationStatusHandler.class, "oInstance", mockOperationStatusHandler);
+ PowerMockito.when(mockOperationStatusHandler.getOperationStatus(Mockito.any())).thenReturn(response);
+
+ VnfFuncTestResponseHandler mockVnfFuncTestResponseHandler = PowerMockito.mock(VnfFuncTestResponseHandler.class);
+ Whitebox.setInternalState(VnfFuncTestResponseHandler.class, "vnfFuncRspHandler", mockVnfFuncTestResponseHandler);
+ OperationStatus operstatus = new OperationStatus();
+ operstatus.setOperFinished(true);
+ operstatus.setoResultCode(OperationStatus.operResultCode.SUCCESS);
+ operstatus.setOperResultMessage("finished");
+ PowerMockito.when(mockVnfFuncTestResponseHandler.downloadResults(Mockito.anyString())).thenReturn(RestResponseUtil.getSuccessResponse(operstatus));
try {
response = scriptManager.downloadResults(taskID);
@@ -135,9 +124,6 @@ public class ScriptManagerTest {
} catch (Exception e) {
e.printStackTrace();
}
-
- mockOperationStatusHandler.tearDown();
- mockVnfFuncTestResponseHandler.tearDown();
}
@Test
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
index 921a8e0..cb2e154 100644
--- 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
@@ -17,19 +17,23 @@
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.junit.rules.ExpectedException;
+import org.mockito.Mockito;
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.scriptmgr.ScriptManager;
import org.onap.vnfsdk.functest.util.RestResponseUtil;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.reflect.Whitebox;
import javax.ws.rs.core.Response;
import java.lang.reflect.Method;
@@ -40,6 +44,7 @@ import static org.junit.Assert.assertNotNull;
public class TaskManagerTest {
+ public final ExpectedException exception = ExpectedException.none();
@Rule
public DAOTestRule daoTestRule = DAOTestRule.newBuilder()
.addEntityClass(TaskRecord.class)
@@ -77,17 +82,11 @@ public class TaskManagerTest {
@Test
public void testStartOnboardTestingPackageIDAbsentInDB() {
- new MockUp<ScriptManager>() {
- @Mock
- public UUID uploadFuncTestPackage(UUID taskID, UUID envID, String url) {
- return UUID.randomUUID();
- }
- };
-
try {
response = taskManager.startOnboardTesting(requestBody);
- assertNotNull(response);
+ exception.expect(IndexOutOfBoundsException.class);
assertEquals(201, response.getStatus());
+ } catch (IndexOutOfBoundsException indexOutOfBoundsException) {
} catch (Exception e) {
e.printStackTrace();
}
@@ -161,13 +160,12 @@ public class TaskManagerTest {
}
@Test
+ @PrepareForTest({VnfFuncTestResponseHandler.class})
public void testCollectTaskResultUncreated() {
- new MockUp<ScriptManager>() {
- @Mock
- public Response downloadResults(UUID taskID) {
- return RestResponseUtil.getSuccessResponse(null);
- }
- };
+ VnfFuncTestResponseHandler mockVnfFuncTestResponseHandler = PowerMockito.mock(VnfFuncTestResponseHandler.class);
+ Whitebox.setInternalState(VnfFuncTestResponseHandler.class, "vnfFuncRspHandler", mockVnfFuncTestResponseHandler);
+ PowerMockito.when(mockVnfFuncTestResponseHandler.downloadResults(Mockito.anyString())).thenReturn(RestResponseUtil.getSuccessResponse(null));
+
try {
daoTestRule.inTransaction(() -> taskMgrCaseTblDAO.saveOrUpdate(new CaseRecord(taskID, funcID, testID, testResult, testDescription)));
response = taskManager.collectTaskResult(taskID);