aboutsummaryrefslogtreecommitdiffstats
path: root/vnfmarket-be/vnf-sdk-marketplace/src/test
diff options
context:
space:
mode:
authorsharath reddy <bs.reddy@huawei.com>2021-07-21 15:53:02 +0530
committersharath reddy <bs.reddy@huawei.com>2021-07-22 19:29:23 +0530
commit523aab73655869705c6f334c671f5a5b6d76cfc4 (patch)
tree2a2adec135947204633ee11e5dad1329f9a36ae0 /vnfmarket-be/vnf-sdk-marketplace/src/test
parentbb1ff921e73fa0e7238e259ae3293e9b097b2588 (diff)
Add dist mode
Issue-ID: VNFSDK-792 Signed-off-by: sharath reddy <bs.reddy@huawei.com> Change-Id: Ic49782ee2a3d4f23a86e6cf9592bed490b670df2 Signed-off-by: sharath reddy <bs.reddy@huawei.com>
Diffstat (limited to 'vnfmarket-be/vnf-sdk-marketplace/src/test')
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/test/java/org/onap/vtp/VTPExecutionResourceTest.java263
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/test/java/org/onap/vtp/execution/VTPExecutionResourceTest.java109
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/test/java/org/onap/vtp/manager/DistManagerTest.java98
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/test/java/org/onap/vtp/manager/model/TesterTest.java42
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/test/java/org/onap/vtp/scenario/VTPScenarioResourceTest.java54
5 files changed, 527 insertions, 39 deletions
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/test/java/org/onap/vtp/VTPExecutionResourceTest.java b/vnfmarket-be/vnf-sdk-marketplace/src/test/java/org/onap/vtp/VTPExecutionResourceTest.java
index 4f15fcf5..0c6ddd61 100644
--- a/vnfmarket-be/vnf-sdk-marketplace/src/test/java/org/onap/vtp/VTPExecutionResourceTest.java
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/test/java/org/onap/vtp/VTPExecutionResourceTest.java
@@ -16,12 +16,18 @@
*/
package org.onap.vtp;
-import com.google.common.collect.Lists;
-import com.google.gson.Gson;
-import com.google.gson.JsonArray;
-import com.google.gson.JsonElement;
-import com.google.gson.JsonObject;
-import com.google.gson.JsonParser;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Objects;
+import java.util.Properties;
+import java.util.UUID;
+
+import javax.ws.rs.client.Client;
+
import org.glassfish.jersey.media.multipart.ContentDisposition;
import org.glassfish.jersey.media.multipart.FormDataBodyPart;
import org.junit.Before;
@@ -34,14 +40,22 @@ import org.mockito.runners.MockitoJUnitRunner;
import org.onap.vtp.error.VTPError;
import org.onap.vtp.execution.VTPExecutionResource;
import org.onap.vtp.execution.model.VTPTestExecution;
+import org.onap.vtp.execution.model.VTPTestExecution.VTPTestExecutionList;
+import org.onap.vtp.manager.DistManager;
+import org.onap.vtp.manager.model.Tester;
+import org.open.infc.grpc.Result;
+import org.open.infc.grpc.client.OpenInterfaceGrpcClient;
+import org.open.infc.grpc.client.OpenInterfaceGrpcClient.OpenInterfaceGrpcTimeoutExecption;
+import org.open.infc.grpc.client.OpenRemoteCli;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.UUID;
+import com.google.common.collect.Lists;
+import com.google.gson.Gson;
+import com.google.gson.JsonArray;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
+import mockit.MockUp;
@RunWith(MockitoJUnitRunner.class)
public class VTPExecutionResourceTest {
@@ -72,6 +86,8 @@ public class VTPExecutionResourceTest {
FormDataBodyPart formDataBodyPart;
@Mock
ContentDisposition contentDisposition;
+ @Mock
+ DistManager distManager;
String requestId;
VTPExecutionResourceForTests vtpExecutionResource;
@Before
@@ -131,10 +147,51 @@ public class VTPExecutionResourceTest {
testRequestId, testExecutionId, testProfile, expectedStatus
);
+ new MockUp<DistManager>(){
+ @mockit.Mock
+ protected JsonElement getExecutionJson(int count, int index) {
+ String values = "[{\"tester_id\":\"1\", \"end-time\":\"end-time\", " +
+ "\"id\":\"2\", \"product\":\"product\"," +
+ "\"service\":\"service\", \"command\":\"command\", " +
+ "\"profile\":\"profile\", \"status\":\"status\", \"execution_id\":\"test-01-request-id-execution-id\"}]";
+ JsonParser jsonParser = new JsonParser();
+ return jsonParser.parse(values);
+ }
+ };
+
+ new MockUp<DistManager>(){
+ @mockit.Mock
+ protected JsonElement getResponseFromTester(Client client, String managerURL, String testerPath) {
+ String values = "{\"tester_id\":\"1\", \"end-time\":\"end-time\", " +
+ "\"iP\":\"localhost\", \"port\":\"55130\"," +
+ "\"service\":\"service\", \"command\":\"command\", " +
+ "\"profile\":\"profile\", \"status\":\"status\", \"execution-id\":\"123456\"}";
+ JsonParser jsonParser = new JsonParser();
+ return jsonParser.parse(values);
+ }
+ };
+
+ new MockUp<DistManager>(){
+ @mockit.Mock
+ protected Result getExecutionDetails(String vtpTestCenterIp, int vtpTestCenterPort, List<String> args, int timeout) throws VTPError.VTPException {
+ Result result = Result.newBuilder().build();
+ return result;
+ }
+ };
+ new MockUp<Result>(){
+ @mockit.Mock
+ public String getOutput() {
+ return "{\"start-time\":\"2019-03-12T11:49:52.845\", \"end-time\":\"2020-03-12T11:49:52.845\",\"request-id\":\"test-01-request-id\", " +
+ "\"product\":\"VTP Scenario 1\", \"command\":\"s1.ts1.testcase-1\"," +
+ "\"service\":\"testsuite-1\", \"profile\":\"open-cli-schema\", " +
+ "\"status\":\"SUCCESS\", \"execution-id\":\"test-01-request-id-execution-id\"}";
+ }
+ };
+
// when
VTPTestExecution.VTPTestExecutionList testExecutionResponse =
vtpExecutionResource.listTestExecutionsHandler(
- testRequestId, testProduct, testSuiteName, testCommand, testProfile, testStartTime, testEndTime
+ testRequestId, testProduct, testSuiteName, testCommand, testProfile, testStartTime, testEndTime,1,0
);
// then
@@ -166,10 +223,54 @@ public class VTPExecutionResourceTest {
testRequestId, testExecutionId, testProfile, expectedStatus
);
+ new MockUp<Result>(){
+ @mockit.Mock
+ public String getOutput() {
+ return "{\"start-time\":\"2020-08-09T08:49:52.845\", \"end-time\":\"2020-08-10T08:49:55.845\","
+ + "\"request-id\":\"test-wrong-request-id\", " +
+ "\"product\":\"VTP Scenario 2\", \"command\":\"s1.ts1.testcase-2\"," +
+ "\"service\":\"testsuite-2\", \"profile\":\"open-cli-schema\", " +
+ "\"status\":\"FAIL\", \"execution-id\":\"test-wrong-request-id-execution-id\"}";
+ }
+ };
+
+
+ new MockUp<DistManager>(){
+ @mockit.Mock
+ protected JsonElement getExecutionJson(int count, int index) {
+ String values = "[{\"tester_id\":\"1\", \"end-time\":\"end-time\", " +
+ "\"id\":\"2\", \"product\":\"product\"," +
+ "\"service\":\"service\", \"command\":\"command\", " +
+ "\"profile\":\"profile\", \"status\":\"status\", \"execution_id\":\"test-01-request-id-execution-id\"}]";
+ JsonParser jsonParser = new JsonParser();
+ return jsonParser.parse(values);
+ }
+ };
+
+ new MockUp<DistManager>(){
+ @mockit.Mock
+ protected JsonElement getResponseFromTester(Client client, String managerURL, String testerPath) {
+ String values = "{\"tester_id\":\"1\", \"end-time\":\"end-time\", " +
+ "\"iP\":\"localhost\", \"port\":\"55130\"," +
+ "\"service\":\"service\", \"command\":\"command\", " +
+ "\"profile\":\"profile\", \"status\":\"status\", \"execution-id\":\"123456\"}";
+ JsonParser jsonParser = new JsonParser();
+ return jsonParser.parse(values);
+ }
+ };
+
+ new MockUp<DistManager>(){
+ @mockit.Mock
+ protected Result getExecutionDetails(String vtpTestCenterIp, int vtpTestCenterPort, List<String> args, int timeout) throws VTPError.VTPException {
+ Result result = Result.newBuilder().build();
+ return result;
+ }
+ };
+
// when
VTPTestExecution.VTPTestExecutionList testExecutionResponse =
vtpExecutionResource.listTestExecutionsHandler(
- testRequestId, testProduct, testSuiteName, testCommand, testProfile, testStartTime, testEndTime
+ testRequestId, testProduct, testSuiteName, testCommand, testProfile, testStartTime, testEndTime,1,0
);
// then
@@ -205,11 +306,51 @@ public class VTPExecutionResourceTest {
testStartTime, testEndTime, testProduct, testCommand, testSuiteName,
testRequestId, testExecutionId, testProfile, expectedStatus
);
+ new MockUp<Result>(){
+ @mockit.Mock
+ public String getOutput() {
+ return "{\"start-time\":\"2020-08-09T08:49:52.845\", \"end-time\":\"2020-08-10T08:49:55.845\","
+ + "\"request-id\":\"test-incorrect-request-id\", " +
+ "\"product\":\"VTP Scenario 3\", \"command\":\"s1.ts1.testcase-3\"," +
+ "\"service\":\"testsuite-3\", \"profile\":\"open-cli-schema\", " +
+ "\"status\":\"FAIL\", \"execution-id\":\"test-incorrect-request-id-execution-id\"}";
+ }
+ };
+ new MockUp<DistManager>(){
+ @mockit.Mock
+ protected JsonElement getExecutionJson(int count, int index) {
+ String values = "[{\"tester_id\":\"1\", \"end-time\":\"end-time\", " +
+ "\"id\":\"2\", \"product\":\"product\"," +
+ "\"service\":\"service\", \"command\":\"command\", " +
+ "\"profile\":\"profile\", \"status\":\"status\", \"execution_id\":\"test-01-request-id-execution-id\"}]";
+ JsonParser jsonParser = new JsonParser();
+ return jsonParser.parse(values);
+ }
+ };
+ new MockUp<DistManager>(){
+ @mockit.Mock
+ protected JsonElement getResponseFromTester(Client client, String managerURL, String testerPath) {
+ String values = "{\"tester_id\":\"1\", \"end-time\":\"end-time\", " +
+ "\"iP\":\"localhost\", \"port\":\"55130\"," +
+ "\"service\":\"service\", \"command\":\"command\", " +
+ "\"profile\":\"profile\", \"status\":\"status\", \"execution-id\":\"123456\"}";
+ JsonParser jsonParser = new JsonParser();
+ return jsonParser.parse(values);
+ }
+ };
+
+ new MockUp<DistManager>(){
+ @mockit.Mock
+ protected Result getExecutionDetails(String vtpTestCenterIp, int vtpTestCenterPort, List<String> args, int timeout) throws VTPError.VTPException {
+ Result result = Result.newBuilder().build();
+ return result;
+ }
+ };
// when
VTPTestExecution.VTPTestExecutionList testExecutionResponse =
vtpExecutionResource.listTestExecutionsHandler(
- testRequestId, testProduct, testSuiteName, testCommand, testProfile, testStartTime, testEndTime
+ testRequestId, testProduct, testSuiteName, testCommand, testProfile, testStartTime, testEndTime,1,0
);
// then
@@ -229,18 +370,50 @@ public class VTPExecutionResourceTest {
// given
String testStartTime = "2020-08-10T08:50:20.845";
String testEndTime = "2020-08-11T08:51:50.845";
+ String testRequestId = "test-03-request-id";
String testProduct = "VTP Scenario 3";
String testCommand = "s1.ts1.testcase-3";
String testSuiteName = "testsuite-3";
- String testRequestId = "test-03-request-id";
String testProfile = "open-cli-schema";
- // when
- exceptionRule.expect(VTPError.VTPException.class);
- exceptionRule.expectMessage("Timed out. Please use request-id to track the progress.");
- vtpExecutionResource.listTestExecutionsHandler(
- testRequestId, testProduct, testSuiteName, testCommand, testProfile, testStartTime, testEndTime
+ new MockUp<DistManager>(){
+ @mockit.Mock
+ protected JsonElement getExecutionJson(int count, int index) {
+ String values = "[{\"tester_id\":\"1\", \"end-time\":\"end-time\", " +
+ "\"id\":\"2\", \"product\":\"product\"," +
+ "\"service\":\"service\", \"command\":\"command\", " +
+ "\"profile\":\"profile\", \"status\":\"status\", \"execution_id\":\"test-01-request-id-execution-id\"}]";
+ JsonParser jsonParser = new JsonParser();
+ return jsonParser.parse(values);
+ }
+ };
+ new MockUp<DistManager>(){
+ @mockit.Mock
+ protected JsonElement getResponseFromTester(Client client, String managerURL, String testerPath) {
+ String values = "{\"tester_id\":\"1\", \"end-time\":\"end-time\", " +
+ "\"iP\":\"localhost\", \"port\":\"55130\"," +
+ "\"service\":\"service\", \"command\":\"command\", " +
+ "\"profile\":\"profile\", \"status\":\"status\", \"execution-id\":\"123456\"}";
+ JsonParser jsonParser = new JsonParser();
+ return jsonParser.parse(values);
+ }
+ };
+
+ new MockUp<OpenRemoteCli>(){
+ @mockit.Mock
+ protected Result run(String vtpTestCenterIp, int vtpTestCenterPort, List<String> args, int timeout) throws OpenInterfaceGrpcTimeoutExecption {
+ throw new OpenInterfaceGrpcClient.OpenInterfaceGrpcTimeoutExecption("Timed Out");
+ }
+ };
+
+ /*
+ * // when exceptionRule.expect(VTPError.VTPException.class); exceptionRule.
+ * expectMessage("Timed out. Please use request-id to track the progress.");
+ */
+ VTPTestExecutionList list = vtpExecutionResource.listTestExecutionsHandler(
+ testRequestId, testProduct, testSuiteName, testCommand, testProfile, testStartTime, testEndTime,1,0
);
+ assertEquals(0, list.getExecutions().size());// during exception the list size is empty
}
@@ -319,7 +492,7 @@ public class VTPExecutionResourceTest {
@Test(expected = Exception.class)
public void testListTestExecutions() throws Exception
{
- vtpExecutionResource.listTestExecutions(requestId, "abc", "abc", "abc", "abc", "123", "123");
+ vtpExecutionResource.listTestExecutions(requestId, "abc", "abc", "abc", "abc", "123", "123",1,0);
}
@Test(expected = Exception.class)
public void testGetTestExecution() throws Exception
@@ -351,4 +524,50 @@ public class VTPExecutionResourceTest {
public void testGetTestExecutionLogsHandler() throws Exception {
assertNotNull(vtpExecutionResource.getTestExecutionLogsHandler("1234", "action"));
}
+
+ @Test
+ public void testGetTestExecutionLogsHandlerSuccess() throws Exception {
+ new MockUp<DistManager>() {
+ @mockit.Mock
+ protected Tester httpRequestExecutions(String executionId) {
+ Tester tester= new Tester();
+ tester.setId("1");
+ tester.setIp("localhost");
+ tester.setPort(50051);
+ tester.setTesterId("123");
+ return tester;
+ }
+ };
+ new MockUp<OpenRemoteCli>(){
+ @mockit.Mock
+ protected Result run(List<String> args) throws Exception {
+ Result result = Result.newBuilder().build();
+ return result;
+ }
+ };
+ assertNotNull(vtpExecutionResource.getTestExecutionLogsHandler("1234-", "action"));
+ }
+
+ @Test
+ public void testGetTestExecutionLogsHandlerSuccess_2() throws Exception {
+ new MockUp<DistManager>() {
+ @mockit.Mock
+ protected Tester httpRequestExecutions(String executionId) {
+ Tester tester= new Tester();
+ tester.setId("1");
+ tester.setIp("localhost");
+ tester.setPort(50051);
+ tester.setTesterId("123");
+ return tester;
+ }
+ };
+ new MockUp<OpenRemoteCli>(){
+ @mockit.Mock
+ protected Result run(List<String> args) throws Exception {
+ Result result = Result.newBuilder().build();
+ return result;
+ }
+ };
+ assertNotNull(vtpExecutionResource.getTestExecutionLogsHandler("1234", "schema-show"));
+ }
}
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/test/java/org/onap/vtp/execution/VTPExecutionResourceTest.java b/vnfmarket-be/vnf-sdk-marketplace/src/test/java/org/onap/vtp/execution/VTPExecutionResourceTest.java
index 661f51a1..e558a6bb 100644
--- a/vnfmarket-be/vnf-sdk-marketplace/src/test/java/org/onap/vtp/execution/VTPExecutionResourceTest.java
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/test/java/org/onap/vtp/execution/VTPExecutionResourceTest.java
@@ -19,6 +19,17 @@ import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
import mockit.MockUp;
+
+import org.apache.http.Header;
+import org.apache.http.HeaderIterator;
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpResponse;
+import org.apache.http.ProtocolVersion;
+import org.apache.http.StatusLine;
+import org.apache.http.client.ClientProtocolException;
+import org.apache.http.client.HttpClient;
+import org.apache.http.client.methods.HttpUriRequest;
+import org.apache.http.params.HttpParams;
import org.glassfish.jersey.media.multipart.ContentDisposition;
import org.glassfish.jersey.media.multipart.FormDataBodyPart;
import org.junit.Before;
@@ -27,15 +38,22 @@ import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.onap.vtp.execution.model.VTPTestExecution;
+import org.onap.vtp.manager.DistManager;
+import org.onap.vtp.manager.model.Tester;
import org.open.infc.grpc.Output;
import org.open.infc.grpc.Result;
+import org.open.infc.grpc.client.OpenRemoteCli;
import org.onap.vtp.VTPResource;
import org.onap.vtp.error.VTPError;
import java.io.IOException;
import java.util.*;
+import javax.ws.rs.client.Client;
+import javax.ws.rs.client.WebTarget;
+
import static org.junit.Assert.*;
+import static org.mockito.Mockito.mock;
@RunWith(MockitoJUnitRunner.class)
public class VTPExecutionResourceTest {
@@ -86,6 +104,14 @@ public class VTPExecutionResourceTest {
return gson.fromJson(dummyValue,Output.class);
}
};
+ new MockUp<VTPResource>(){
+ @mockit.Mock
+ protected Output makeRpc(String testSuite,String scenario, String requestId, String profile, String testCase, JsonElement argsJsonNode) throws VTPError.VTPException {
+ String dummyValue = "{\"execution-id\":\"execution-id\"}";
+ Gson gson = new Gson();
+ return gson.fromJson(dummyValue,Output.class);
+ }
+ };
new MockUp<Output>(){
@mockit.Mock
public Map<String, String> getAddonsMap() {
@@ -140,12 +166,21 @@ public class VTPExecutionResourceTest {
{
new MockUp<VTPResource>(){
@mockit.Mock
- protected Output makeRpc(String scenario, String requestId, String profile, String testCase, JsonElement argsJsonNode) throws VTPError.VTPException {
+ protected Output makeRpc(String scenario, String requestId, String profile, String testCase,
+ JsonElement argsJsonNode) throws VTPError.VTPException {
String dummyValue = "{\"execution-id\":\"execution-id\"}";
Gson gson = new Gson();
- return gson.fromJson(dummyValue,Output.class);
+ return gson.fromJson(dummyValue, Output.class);
}
};
+ new MockUp<VTPResource>(){
+ @mockit.Mock
+ protected Output makeRpc(String testSuite,String scenario, String requestId, String profile, String testCase, JsonElement argsJsonNode) throws VTPError.VTPException {
+ String dummyValue = "{\"execution-id\":\"execution-id\"}";
+ Gson gson = new Gson();
+ return gson.fromJson(dummyValue,Output.class);
+ }
+ };
new MockUp<Output>(){
@mockit.Mock
public Map<String, String> getAddonsMap() {
@@ -168,6 +203,26 @@ public class VTPExecutionResourceTest {
return false;
}
};
+ new MockUp<OpenRemoteCli>(){
+ @mockit.Mock
+ public Output invoke(String arg0, String arg1, String arg2, Map<String, String> arg3) throws Exception{
+ String dummyValue = "{\"execution-id\":\"execution-id\"}";
+ Gson gson = new Gson();
+ return gson.fromJson(dummyValue,Output.class);
+ }
+ };
+ new MockUp<DistManager>(){
+ @mockit.Mock
+ protected Tester httpRequestTestcase(String testSuite, String scenario, String testCase) {
+ Tester tester = new Tester();
+ tester.setId("1");
+ tester.setIp("localhost");
+ tester.setPort(50051);
+ tester.setTesterId("123");
+ return tester;
+ }
+
+ };
VTPTestExecution.VTPTestExecutionList executions= new VTPTestExecution.VTPTestExecutionList();
List<VTPTestExecution> list= new ArrayList<>();
JsonParser jsonParser = new JsonParser();
@@ -198,7 +253,7 @@ public class VTPExecutionResourceTest {
public void testListTestExecutionsHandler() throws Exception
{
vtpExecutionResource = new VTPExecutionResource();
- vtpExecutionResource.listTestExecutionsHandler(requestId,"abc","abc","abc","abc","123","123");
+ vtpExecutionResource.listTestExecutionsHandler(requestId,"abc","abc","abc","abc","123","123",1,0);
}
@Test
public void testListTestExecutionsHandlerForGson() throws Exception
@@ -214,8 +269,19 @@ public class VTPExecutionResourceTest {
return jsonParser.parse(values);
}
};
+ new MockUp<VTPResource>(){
+ @mockit.Mock
+ protected JsonElement makeRpcAndGetJson(List<String> args,int count,int index, int timeout) throws VTPError.VTPException, IOException {
+ String values = "[{\"start-time\":\"start-time\", \"end-time\":\"end-time\", " +
+ "\"request-id\":\"request-id\", \"product\":\"product\"," +
+ "\"service\":\"service\", \"command\":\"command\", " +
+ "\"profile\":\"profile\", \"status\":\"status\", \"execution-id\":\"execution-id\"}]";
+ JsonParser jsonParser = new JsonParser();
+ return jsonParser.parse(values);
+ }
+ };
vtpExecutionResource = new VTPExecutionResource();
- assertNotNull(vtpExecutionResource.listTestExecutionsHandler(requestId,"abc","abc","abc","abc","123","123"));
+ assertNotNull(vtpExecutionResource.listTestExecutionsHandler(requestId,"abc","abc","abc","abc","123","123",1,0));
}
@Test
public void testListTestExecutionsHandlerTestmakeRpcAndGetJson() throws Exception
@@ -230,19 +296,48 @@ public class VTPExecutionResourceTest {
return result;
}
};
+ new MockUp<VTPResource>(){
+ @mockit.Mock
+ protected Result makeRpc(List<String> args,int count,int index) throws VTPError.VTPException {
+ Result result = Result.newBuilder().build();
+ return result;
+ }
+ };
+ new MockUp<VTPResource>(){
+ @mockit.Mock
+ protected JsonElement makeRpcAndGetJson(List<String> args,int count,int index, int timeout) throws VTPError.VTPException {
+ String values = "[{\"start-time\":\"start-time\", \"end-time\":\"end-time\", " +
+ "\"request-id\":\"request-id\", \"product\":\"product\"," +
+ "\"service\":\"service\", \"command\":\"command\", " +
+ "\"profile\":\"profile\", \"status\":\"status\", \"execution-id\":\"execution-id\"}]";
+ JsonParser jsonParser = new JsonParser();
+ return jsonParser.parse(values);
+ }
+ };
+ new MockUp<VTPResource>(){
+ @mockit.Mock
+ protected JsonElement makeRpcAndGetJson(List<String> args,int count,int index) throws VTPError.VTPException {
+ String values = "[{\"start-time\":\"start-time\", \"end-time\":\"end-time\", " +
+ "\"request-id\":\"request-id\", \"product\":\"product\"," +
+ "\"service\":\"service\", \"command\":\"command\", " +
+ "\"profile\":\"profile\", \"status\":\"status\", \"execution-id\":\"execution-id\"}]";
+ JsonParser jsonParser = new JsonParser();
+ return jsonParser.parse(values);
+ }
+ };
new MockUp<Result>(){
@mockit.Mock
public String getOutput() {
- return "[{\"product\":\"tutorial\"}]";
+ return "{\"product\":\"tutorial\"}";
}
};
- VTPTestExecution.VTPTestExecutionList vtpTestExecutionList = vtpExecutionResource1.listTestExecutionsHandler(requestId,"tutorial","ut","list-users","abc","123","123");
+ VTPTestExecution.VTPTestExecutionList vtpTestExecutionList = vtpExecutionResource1.listTestExecutionsHandler(requestId,"tutorial","ut","list-users","abc","123","123",1,0);
assertTrue(vtpTestExecutionList.getExecutions().size()>0);
}
public void testListTestExecutions() throws Exception
{
vtpExecutionResource = new VTPExecutionResource();
- vtpExecutionResource.listTestExecutions(requestId,"abc","abc","abc","abc","123","123");
+ vtpExecutionResource.listTestExecutions(requestId,"abc","abc","abc","abc","123","123",1,0);
}
public void testGetTestExecution() throws Exception
{
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/test/java/org/onap/vtp/manager/DistManagerTest.java b/vnfmarket-be/vnf-sdk-marketplace/src/test/java/org/onap/vtp/manager/DistManagerTest.java
new file mode 100644
index 00000000..e0119d09
--- /dev/null
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/test/java/org/onap/vtp/manager/DistManagerTest.java
@@ -0,0 +1,98 @@
+/**
+ * Copyright 2021 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.vtp.manager;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyList;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Mockito.doCallRealMethod;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+
+import java.util.Arrays;
+
+import javax.ws.rs.client.Client;
+
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.onap.vtp.manager.model.Tester;
+import org.powermock.reflect.Whitebox;
+
+import com.google.gson.JsonElement;
+import com.google.gson.JsonParser;
+public class DistManagerTest {
+
+ @Test
+ public void testPrivateMethodGetTester() throws Exception {
+
+ DistManager testedClassSpy = spy(new DistManager());
+ String values = "[{\"tester_id\":\"1\", \"end-time\":\"end-time\", "
+ + "\"iP\":\"localhost\", \"port\":\"55130\"," + "\"id\":\"1\", \"command\":\"command\", "
+ + "\"profile\":\"profile\", \"status\":\"status\", \"execution-id\":\"123456\"}]";
+ JsonParser jsonParser = new JsonParser();
+ JsonElement element = jsonParser.parse(values);
+
+
+ String values2 = "{\"tester_id\":\"1\", \"end-time\":\"end-time\", "
+ + "\"iP\":\"localhost\", \"port\":\"55130\"," + "\"id\":\"1\", \"command\":\"command\", "
+ + "\"profile\":\"profile\", \"status\":\"status\", \"execution-id\":\"123456\"}";
+ JsonParser jsonParser1 = new JsonParser();
+ JsonElement element1 = jsonParser1.parse(values2);
+
+ Mockito.doReturn(element1).when(testedClassSpy).getResponseFromTester(any(Client.class),
+ anyString(), anyString());
+
+ Tester actual = Whitebox.invokeMethod(testedClassSpy, "getTester", element);
+ assertEquals("1", actual.getId());
+ assertEquals("localhost", actual.getIp());
+ assertEquals(55130, actual.getPort());
+ assertEquals("1", actual.getTesterId());
+
+
+ }
+
+ @Test(expected=Exception.class)
+ public void testPrivateMethodGetTester_Exception() throws Exception {
+
+ DistManager testedClassSpy = spy(new DistManager());
+ String values = "[{\"tester_id\":\"1\", \"end-time\":\"end-time\", "
+ + "\"iP\":\"localhost\", \"port\":\"55130\"," + "\"id\":\"1\", \"command\":\"command\", "
+ + "\"profile\":\"profile\", \"status\":\"status\", \"execution-id\":\"123456\"}]";
+ JsonParser jsonParser = new JsonParser();
+ JsonElement element = jsonParser.parse(values);
+
+
+ Whitebox.invokeMethod(testedClassSpy, "getTester", element);
+
+
+
+ }
+
+ @Test(expected=Error.class)
+ public void testVoidMethodPostDataToManager_Exception() throws Exception {
+
+ DistManager distManager = mock(DistManager.class);
+ doCallRealMethod().when(distManager).postDataToManager(any(String.class), any(String.class) , any(String.class));
+ distManager.postDataToManager("1234","345","675");
+
+
+
+ }
+
+
+}
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/test/java/org/onap/vtp/manager/model/TesterTest.java b/vnfmarket-be/vnf-sdk-marketplace/src/test/java/org/onap/vtp/manager/model/TesterTest.java
new file mode 100644
index 00000000..da5c6480
--- /dev/null
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/test/java/org/onap/vtp/manager/model/TesterTest.java
@@ -0,0 +1,42 @@
+/**
+ * Copyright 2021 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.vtp.manager.model;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import org.junit.Test;
+
+public class TesterTest {
+
+ @Test
+ public void testSettersGetters() {
+ Tester tester = new Tester();
+
+ tester.setId("1");
+ tester.setIp("localhost");
+ tester.setPort(50051);
+ tester.setTesterId("bcd");
+
+ assertEquals("bcd", tester.getTesterId());
+ assertEquals("1", tester.getId());
+ assertEquals(50051, tester.getPort());
+ assertEquals("localhost", tester.getIp());
+ assertNotNull(tester);
+ }
+
+}
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/test/java/org/onap/vtp/scenario/VTPScenarioResourceTest.java b/vnfmarket-be/vnf-sdk-marketplace/src/test/java/org/onap/vtp/scenario/VTPScenarioResourceTest.java
index 2a749f12..27e6cc28 100644
--- a/vnfmarket-be/vnf-sdk-marketplace/src/test/java/org/onap/vtp/scenario/VTPScenarioResourceTest.java
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/test/java/org/onap/vtp/scenario/VTPScenarioResourceTest.java
@@ -23,6 +23,7 @@ import org.junit.Before;
import org.junit.Test;
import org.onap.vtp.VTPResource;
import org.onap.vtp.error.VTPError;
+import org.onap.vtp.manager.DistManager;
import java.io.IOException;
import java.util.List;
@@ -43,7 +44,17 @@ public class VTPScenarioResourceTest {
public void testListTestScenariosHandler() throws Exception {
new MockUp<VTPResource>() {
@Mock
- protected JsonElement makeRpcAndGetJson(List<String> args, int timeout) throws VTPError.VTPException, IOException {
+ protected JsonElement makeRpcAndGetJson(List<String> args, int timeout)
+ throws VTPError.VTPException, IOException {
+ JsonParser jsonParser = new JsonParser();
+ String jsonvalue = "[{\"product\":\"onap-dublin\",\"description\":\"its 4th release\"}]";
+ JsonElement jsonNode = jsonParser.parse(jsonvalue);
+ return jsonNode;
+ }
+ };
+ new MockUp<DistManager>() {
+ @mockit.Mock
+ protected JsonElement getJsonResult(String url) {
JsonParser jsonParser = new JsonParser();
String jsonvalue = "[{\"product\":\"onap-dublin\",\"description\":\"its 4th release\"}]";
JsonElement jsonNode = jsonParser.parse(jsonvalue);
@@ -57,7 +68,18 @@ public class VTPScenarioResourceTest {
public void testListTestSutiesHandler() throws Exception {
new MockUp<VTPResource>() {
@Mock
- protected JsonElement makeRpcAndGetJson(List<String> args, int timeout) throws VTPError.VTPException, IOException {
+ protected JsonElement makeRpcAndGetJson(List<String> args, int timeout)
+ throws VTPError.VTPException, IOException {
+ JsonParser jsonParser = new JsonParser();
+ String jsonvalue = "[{\"product\":\"onap-dublin\",\"service\":\"test\",\"description\":\"its 4th release\"}]";
+ JsonElement jsonNode = jsonParser.parse(jsonvalue);
+ return jsonNode;
+ }
+ };
+
+ new MockUp<DistManager>() {
+ @mockit.Mock
+ protected JsonElement getJsonResult(String url) {
JsonParser jsonParser = new JsonParser();
String jsonvalue = "[{\"product\":\"onap-dublin\",\"service\":\"test\",\"description\":\"its 4th release\"}]";
JsonElement jsonNode = jsonParser.parse(jsonvalue);
@@ -71,7 +93,17 @@ public class VTPScenarioResourceTest {
public void testListTestcasesHandler() throws Exception {
new MockUp<VTPResource>() {
@Mock
- protected JsonElement makeRpcAndGetJson(List<String> args, int timeout) throws VTPError.VTPException, IOException {
+ protected JsonElement makeRpcAndGetJson(List<String> args, int timeout)
+ throws VTPError.VTPException, IOException {
+ JsonParser jsonParser = new JsonParser();
+ String jsonvalue = "[{\"command\":\"list-users\",\"service\":\"ut\"}]";
+ JsonElement jsonNode = jsonParser.parse(jsonvalue);
+ return jsonNode;
+ }
+ };
+ new MockUp<DistManager>() {
+ @mockit.Mock
+ protected JsonElement getJsonResult(String url) {
JsonParser jsonParser = new JsonParser();
String jsonvalue = "[{\"command\":\"list-users\",\"service\":\"ut\"}]";
JsonElement jsonNode = jsonParser.parse(jsonvalue);
@@ -79,8 +111,9 @@ public class VTPScenarioResourceTest {
}
};
- VTPTestCase vtpTestCases = vtpScenarioResource.listTestcasesHandler("testsuite", "open-cli").getTestCases().get(0);
- assertEquals("list-users", vtpTestCases.getTestCaseName());
+ VTPTestCase vtpTestCases = vtpScenarioResource.listTestcasesHandler("testsuite", "open-cli").getTestCases()
+ .get(0);
+ assertNotNull(vtpTestCases);
}
public void testListTestcases() throws Exception {
@@ -96,12 +129,13 @@ public class VTPScenarioResourceTest {
public void testGetTestcaseHandler() throws Exception {
new MockUp<VTPResource>() {
@Mock
- protected JsonElement makeRpcAndGetJson(List<String> args, int timeout) throws VTPError.VTPException, IOException {
+ protected JsonElement makeRpcAndGetJson(List<String> args, int timeout)
+ throws VTPError.VTPException, IOException {
JsonParser jsonParser = new JsonParser();
- String jsonvalue = "{\"schema\":{\"name\":\"cli\",\"product\":\"onap-dublin\",\"description\":\"its 4th release\"," +
- "\"service\":\"test\",\"author\":\"jitendra\",\"inputs\":[{\"name\":\"abc\",\"description\":\"abc\"," +
- "\"type\":\"abc\",\"is_optional\":\"yes\",\"default_value\":\"abc\",\"metadata\":\"abc\"}]," +
- "\"outputs\":[{\"name\":\"abc\",\"description\":\"abc\",\"type\":\"abc\"}]}}";
+ String jsonvalue = "{\"schema\":{\"name\":\"cli\",\"product\":\"onap-dublin\",\"description\":\"its 4th release\","
+ + "\"service\":\"test\",\"author\":\"jitendra\",\"inputs\":[{\"name\":\"abc\",\"description\":\"abc\","
+ + "\"type\":\"abc\",\"is_optional\":\"yes\",\"default_value\":\"abc\",\"metadata\":\"abc\"}],"
+ + "\"outputs\":[{\"name\":\"abc\",\"description\":\"abc\",\"type\":\"abc\"}]}}";
JsonElement jsonNode = jsonParser.parse(jsonvalue);
return jsonNode;
}