2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ===================================================================
8 * Unless otherwise specified, all software contained herein is licensed
9 * under the Apache License, Version 2.0 (the "License");
10 * you may not use this software except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * Unless otherwise specified, all documentation contained herein is licensed
22 * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
23 * you may not use this documentation except in compliance with the License.
24 * You may obtain a copy of the License at
26 * https://creativecommons.org/licenses/by/4.0/
28 * Unless required by applicable law or agreed to in writing, documentation
29 * distributed under the License is distributed on an "AS IS" BASIS,
30 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31 * See the License for the specific language governing permissions and
32 * limitations under the License.
34 * ============LICENSE_END============================================
38 package org.onap.portalapp.portal.controller;
40 import javax.servlet.http.HttpServletRequest;
41 import javax.servlet.http.HttpServletResponse;
43 import org.apache.poi.ss.formula.functions.T;
44 import org.json.simple.JSONObject;
45 import org.junit.Before;
46 import org.junit.Test;
47 import org.junit.runner.RunWith;
48 import org.mockito.InjectMocks;
49 import org.mockito.Matchers;
50 import org.mockito.Mock;
51 import org.mockito.Mockito;
52 import org.mockito.MockitoAnnotations;
53 import org.onap.portalapp.portal.controller.SchedulerController;
54 import org.onap.portalapp.portal.core.MockEPUser;
55 import org.onap.portalapp.portal.framework.MockitoTestSuite;
56 import org.onap.portalapp.portal.scheduler.SchedulerProperties;
57 import org.onap.portalapp.portal.scheduler.SchedulerRestInterface;
58 import org.onap.portalapp.portal.scheduler.restobjects.RestObject;
59 import org.onap.portalsdk.core.util.SystemProperties;
60 import org.onap.portalsdk.core.web.support.UserUtils;
61 import org.powermock.api.mockito.PowerMockito;
62 import org.powermock.core.classloader.annotations.PrepareForTest;
63 import org.powermock.modules.junit4.PowerMockRunner;
65 @RunWith(PowerMockRunner.class)
66 @PrepareForTest({UserUtils.class,SystemProperties.class,SchedulerProperties.class})
68 public class SchedulerControllerTest {
71 SchedulerRestInterface schedulerRestInterface;
76 SchedulerController schedulerController = new SchedulerController();
80 MockitoAnnotations.initMocks(this);
83 MockEPUser mockUser = new MockEPUser();
84 MockitoTestSuite mockitoTestSuite = new MockitoTestSuite();
86 HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest();
87 HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse();
88 NullPointerException nullPointerException = new NullPointerException();
91 public void getTimeSlotsTest() throws Exception{
92 schedulerController.getTimeSlots(mockedRequest, "12");
97 public void getTimeSlotsTestWithException1() throws Exception{
98 JSONObject jsonObject =Mockito.mock(JSONObject.class);
99 RestObject<T> restObject=new RestObject<>();
100 Mockito.doThrow(new NullPointerException()).when(schedulerRestInterface).Get(Matchers.any(),Matchers.any(),Matchers.any(),Matchers.any());
101 schedulerController.getTimeSlots(mockedRequest, "12");
107 public void getTimeSlotsTestWithexception() throws Exception{
108 schedulerController.getTimeSlots(mockedRequest, null);
113 public void postCreateNewVNFChangeTest() throws Exception{
114 //String testJsonData="{\"domain\":\"ChangeManagement\",\"scheduleName\":\"VnfUpgrade/DWF\",\"userId\":\"su7376\",\"domainData\":[{\"WorkflowName\":\"HEAT Stack Software Update for vNFs\",\"CallbackUrl\":\"http://127.0.0.1:8989/scheduler/v1/loopbacktest/vid\",\"CallbackData\":\"testing\"}],\"schedulingInfo\":{\"normalDurationInSeconds\":60,\"additionalDurationInSeconds\":60,\"concurrencyLimit\":60,\"policyId\":\"SNIRO_CM_1707.Config_MS_Demo_TimeLimitAndVerticalTopology_zone_localTime.1.xml\",\"vnfDetails\":[{\"groupId\":\"group1\",\"node\":[\"satmo415vbc\",\"satmo455vbc\"]}]}}";
115 JSONObject jsonObject =Mockito.mock(JSONObject.class);
117 schedulerController.postCreateNewVNFChange(mockedRequest, jsonObject);
121 public void postCreateNewVNFChangeTestWithException1() throws Exception{
122 JSONObject jsonObject =Mockito.mock(JSONObject.class);
123 RestObject<T> restObject=new RestObject<>();
124 Mockito.doThrow(new NullPointerException()).when(schedulerRestInterface).Post(Matchers.any(),Matchers.any(),Matchers.any(),Matchers.any());
125 schedulerController.postCreateNewVNFChange(mockedRequest, jsonObject);
131 public void postCreateNewVNFChangeTestWithException() throws Exception{
132 //String testJsonData="{\"domain\":\"ChangeManagement\",\"scheduleName\":\"VnfUpgrade/DWF\",\"userId\":\"su7376\",\"domainData\":[{\"WorkflowName\":\"HEAT Stack Software Update for vNFs\",\"CallbackUrl\":\"http://127.0.0.1:8989/scheduler/v1/loopbacktest/vid\",\"CallbackData\":\"testing\"}],\"schedulingInfo\":{\"normalDurationInSeconds\":60,\"additionalDurationInSeconds\":60,\"concurrencyLimit\":60,\"policyId\":\"SNIRO_CM_1707.Config_MS_Demo_TimeLimitAndVerticalTopology_zone_localTime.1.xml\",\"vnfDetails\":[{\"groupId\":\"group1\",\"node\":[\"satmo415vbc\",\"satmo455vbc\"]}]}}";
133 JSONObject jsonObject =Mockito.mock(JSONObject.class);
135 schedulerController.postCreateNewVNFChange(mockedRequest, null);
139 public void postSubmitVnfChangeTimeslotsTest() throws Exception{
140 JSONObject jsonObject =Mockito.mock(JSONObject.class);
141 Mockito.when(jsonObject.get("scheduleId")).thenReturn("12");
142 PowerMockito.mockStatic(SystemProperties.class);
143 PowerMockito.when(SystemProperties.getProperty(SchedulerProperties.SCHEDULER_SUBMIT_NEW_VNF_CHANGE)).thenReturn("/v1/ChangeManagement/schedules/{scheduleId}/approvals");
144 schedulerController.postSubmitVnfChangeTimeslots(mockedRequest, jsonObject);
148 public void postSubmitVnfChangeTimeslotsTestWithException1() throws Exception{
149 JSONObject jsonObject =Mockito.mock(JSONObject.class);
150 RestObject<T> restObject=new RestObject<>();
151 Mockito.doThrow(new NullPointerException()).when(schedulerRestInterface).Post(Matchers.any(),Matchers.any(),Matchers.any(),Matchers.any());
152 schedulerController.postSubmitVnfChangeTimeslots(mockedRequest, jsonObject);
157 public void postSubmitVnfChangeTimeslotsTestWithException() throws Exception{
158 JSONObject jsonObject =Mockito.mock(JSONObject.class);
159 Mockito.when(jsonObject.get("scheduleId")).thenReturn("12");
160 PowerMockito.mockStatic(SystemProperties.class);
161 PowerMockito.when(SystemProperties.getProperty(SchedulerProperties.SCHEDULER_SUBMIT_NEW_VNF_CHANGE)).thenReturn("/v1/ChangeManagement/schedules/{scheduleId}/approvals");
162 schedulerController.postSubmitVnfChangeTimeslots(mockedRequest, null);
166 public void getSchedulerConstantTestWithException() throws Exception{
167 JSONObject jsonObject =Mockito.mock(JSONObject.class);
168 Mockito.when(jsonObject.get("scheduleId")).thenReturn("12");
169 PowerMockito.mockStatic(SystemProperties.class);
170 PowerMockito.when(SystemProperties.getProperty(SchedulerProperties.SCHEDULER_CALLBACK_URL)).thenReturn("mockedRequest");
171 schedulerController.getSchedulerConstant(mockedRequest, mockedResponse);
175 public void getSchedulerConstantTest() throws Exception{
176 JSONObject jsonObject =Mockito.mock(JSONObject.class);
177 //Mockito.when(jsonObject.get("scheduleId")).thenReturn("12");
178 PowerMockito.mockStatic(SystemProperties.class);
179 PowerMockito.when(SystemProperties.getProperty(SchedulerProperties.SCHEDULER_CALLBACK_URL)).thenReturn("callbackUrl");
180 schedulerController.getSchedulerConstant(mockedRequest, mockedResponse);