Code Improvements-Vnfsdk-refrepo sonar issue fixes
[vnfsdk/refrepo.git] / vnfmarket-be / vnf-sdk-marketplace / src / test / java / org / onap / vtp / VTPExecutionResourceTest.java
1 /**
2  * Copyright 2019 Huawei Technologies Co., Ltd.
3  *
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
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 package org.onap.vtp;
17
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;
30
31 import java.io.IOException;
32 import java.util.*;
33
34 import static org.junit.Assert.*;
35 import static org.mockito.Mockito.*;
36
37 @RunWith(MockitoJUnitRunner.class)
38 public class VTPExecutionResourceTest {
39
40     @Mock
41     FormDataBodyPart formDataBodyPart;
42     @Mock
43     ContentDisposition contentDisposition;
44     String requestId;
45     VTPExecutionResource vtpExecutionResource;
46     @Before
47     public void setUp() throws Exception {
48         vtpExecutionResource= new VTPExecutionResource();
49         requestId = UUID.randomUUID().toString();
50     }
51     @Test(expected = Exception.class)
52     public void testExecuteHandler() throws Exception
53     {
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);
59
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");
72         list.add(vtp);
73         executions.setExecutions(list);
74         System.out.println(executions.getExecutions());
75         assertNotNull(executions.getExecutions());
76        vtpExecutionResource.executeHandler(executions,null);
77        //vtpExecutionResource.executeHandler(executions,requestId);
78         //for handler
79     }
80     @Test(expected = Exception.class)
81     public void testListTestExecutionsHandler() throws Exception
82     {
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");
84     }
85 //
86 //    @Test
87 //    public void testListTestExecutionsHandler1() throws Exception
88 //    {   VTPExecutionResource vtpExecutionResource1=mock(VTPExecutionResource.class);
89 //        List<String> list= new ArrayList<>();
90 //         list.add("abc");
91 //       Result result= Result.getDefaultInstance();
92 //
93 //    when(vtpExecutionResource1.makeRpc(list)).thenReturn(result);
94 //     verify(vtpExecutionResource1).makeRpc(list);
95 //
96 //    }
97
98     @Test(expected = Exception.class)
99     public void testListTestExecutions() throws Exception
100     {
101         vtpExecutionResource.listTestExecutions(requestId,"abc","abc","abc","abc","123","123");
102     }
103     @Test(expected = Exception.class)
104     public void testGetTestExecution() throws Exception
105     {
106         //assertNotNull(vtpExecutionResource.getTestExecution("abc"));
107         assertNotNull(vtpExecutionResource.getTestExecution("1234"));
108     }
109     @Test(expected = Exception.class)
110     public void testGetTestExecutionHandler() throws Exception
111     {
112         //assertNotNull(vtpExecutionResource.getTestExecution("abc"));
113         assertNotNull(vtpExecutionResource.getTestExecutionHandler("1234"));
114     }
115
116     @Test(expected = NullPointerException.class)
117     public void testExecuteTestcases() throws Exception
118     {
119
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") ;
127     }
128
129     @Test(expected = Exception.class)
130     public void testGetTestExecutionLogsHandler() throws Exception {
131         assertNotNull(vtpExecutionResource.getTestExecutionLogsHandler("1234", "action"));
132     }
133 }