2 * Copyright 2019 Huawei Technologies Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 import com.google.gson.JsonElement;
19 import com.google.gson.JsonParser;
20 import org.glassfish.jersey.media.multipart.ContentDisposition;
21 import org.glassfish.jersey.media.multipart.FormDataBodyPart;
22 import org.junit.Before;
23 import org.junit.Test;
24 import org.junit.runner.RunWith;
25 import org.mockito.Mock;
26 import org.mockito.runners.MockitoJUnitRunner;
27 import org.onap.vtp.execution.VTPExecutionResource;
28 import org.onap.vtp.execution.model.VTPTestExecution;
29 import org.open.infc.grpc.Result;
31 import java.io.IOException;
34 import static org.junit.Assert.*;
35 import static org.mockito.Mockito.*;
37 @RunWith(MockitoJUnitRunner.class)
38 public class VTPExecutionResourceTest {
41 FormDataBodyPart formDataBodyPart;
43 ContentDisposition contentDisposition;
45 VTPExecutionResource vtpExecutionResource;
47 public void setUp() throws Exception {
48 vtpExecutionResource= new VTPExecutionResource();
49 requestId = UUID.randomUUID().toString();
51 @Test(expected = Exception.class)
52 public void testExecuteHandler() throws Exception
54 VTPTestExecution.VTPTestExecutionList executions= new VTPTestExecution.VTPTestExecutionList();
55 List<VTPTestExecution> list= new ArrayList<>();
56 JsonParser jsonParser = new JsonParser();
57 String jsonString = "{\"name\":\"Mahesh Kumar\", \"age\":\"nine\",\"verified\":\"false\"}";
58 JsonElement rootNode = jsonParser.parse(jsonString);
60 VTPTestExecution vtp=new VTPTestExecution();
61 vtp.setEndTime("2019-03-12T11:49:52.845");
62 vtp.setProfile("open-cli-schema");
63 vtp.setStatus("pass");
64 vtp.setRequestId(requestId);
65 vtp.setExecutionId("executionid");
66 vtp.setParameters(rootNode);
67 vtp.setResults(rootNode);
68 vtp.setScenario("VTP Scenario 1");
69 vtp.setStartTime("2019-04-12T11:49:52.845");
70 vtp.setTestCaseName("s1.ts1.testcase-1");
71 vtp.setTestSuiteName("testsuite-1");
73 executions.setExecutions(list);
74 System.out.println(executions.getExecutions());
75 assertNotNull(executions.getExecutions());
76 vtpExecutionResource.executeHandler(executions,null);
77 //vtpExecutionResource.executeHandler(executions,requestId);
80 @Test(expected = Exception.class)
81 public void testListTestExecutionsHandler() throws Exception
83 vtpExecutionResource.listTestExecutionsHandler(requestId,"VTP Scenario 1","testsuite-1","s1.ts1.testcase-1","open-cli-schema","2019-03-12T11:49:52.845","2020-03-12T11:49:52.845");
87 // public void testListTestExecutionsHandler1() throws Exception
88 // { VTPExecutionResource vtpExecutionResource1=mock(VTPExecutionResource.class);
89 // List<String> list= new ArrayList<>();
91 // Result result= Result.getDefaultInstance();
93 // when(vtpExecutionResource1.makeRpc(list)).thenReturn(result);
94 // verify(vtpExecutionResource1).makeRpc(list);
98 @Test(expected = Exception.class)
99 public void testListTestExecutions() throws Exception
101 vtpExecutionResource.listTestExecutions(requestId,"abc","abc","abc","abc","123","123");
103 @Test(expected = Exception.class)
104 public void testGetTestExecution() throws Exception
106 //assertNotNull(vtpExecutionResource.getTestExecution("abc"));
107 assertNotNull(vtpExecutionResource.getTestExecution("1234"));
109 @Test(expected = Exception.class)
110 public void testGetTestExecutionHandler() throws Exception
112 //assertNotNull(vtpExecutionResource.getTestExecution("abc"));
113 assertNotNull(vtpExecutionResource.getTestExecutionHandler("1234"));
116 @Test(expected = NullPointerException.class)
117 public void testExecuteTestcases() throws Exception
120 List<FormDataBodyPart> bodyParts= new ArrayList<>();
121 formDataBodyPart.setName("abc");
122 formDataBodyPart.setValue("123");
123 formDataBodyPart.setContentDisposition(contentDisposition);
124 formDataBodyPart.getContentDisposition().getFileName();
125 bodyParts.add(formDataBodyPart);
126 vtpExecutionResource.executeTestcases(requestId,bodyParts,"exeJson") ;
129 @Test(expected = Exception.class)
130 public void testGetTestExecutionLogsHandler() throws Exception {
131 assertNotNull(vtpExecutionResource.getTestExecutionLogsHandler("1234", "action"));