bafcb1c00bf39e27c6f71e2ddfffa8de1c67ca36
[portal.git] / ecomp-portal-BE-common / src / test / java / org / onap / portalapp / portal / controller / SchedulerControllerTest.java
1 /*-
2  * ============LICENSE_START==========================================
3  * ONAP Portal
4  * ===================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ===================================================================
7  *
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
12  *
13  *             http://www.apache.org/licenses/LICENSE-2.0
14  *
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.
20  *
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
25  *
26  *             https://creativecommons.org/licenses/by/4.0/
27  *
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.
33  *
34  * ============LICENSE_END============================================
35  *
36  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
37  */
38 package org.onap.portalapp.portal.controller;
39
40 import javax.servlet.http.HttpServletRequest;
41 import javax.servlet.http.HttpServletResponse;
42
43 import org.json.simple.JSONObject;
44 import org.junit.Before;
45 import org.junit.Test;
46 import org.junit.runner.RunWith;
47 import org.mockito.InjectMocks;
48 import org.mockito.Mock;
49 import org.mockito.Mockito;
50 import org.mockito.MockitoAnnotations;
51 import org.onap.portalapp.portal.controller.SchedulerController;
52 import org.onap.portalapp.portal.core.MockEPUser;
53 import org.onap.portalapp.portal.framework.MockitoTestSuite;
54 import org.onap.portalapp.portal.scheduler.SchedulerProperties;
55 import org.onap.portalapp.portal.scheduler.SchedulerRestInterface;
56 import org.onap.portalsdk.core.util.SystemProperties;
57 import org.onap.portalsdk.core.web.support.UserUtils;
58 import org.powermock.api.mockito.PowerMockito;
59 import org.powermock.core.classloader.annotations.PrepareForTest;
60 import org.powermock.modules.junit4.PowerMockRunner;
61
62 @RunWith(PowerMockRunner.class)
63 @PrepareForTest({UserUtils.class,SystemProperties.class})
64
65 public class SchedulerControllerTest {
66
67         @Mock
68         SchedulerRestInterface schedulerRestInterface;
69         
70         
71
72         @InjectMocks
73         SchedulerController schedulerController = new SchedulerController();
74
75         @Before
76         public void setup() {
77                 MockitoAnnotations.initMocks(this);
78         }
79
80         MockEPUser mockUser = new MockEPUser();
81         MockitoTestSuite mockitoTestSuite = new MockitoTestSuite();
82
83         HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest();
84         HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse();
85         NullPointerException nullPointerException = new NullPointerException();
86
87         @Test
88         public void  getTimeSlotsTest() throws Exception{
89                 schedulerController.getTimeSlots(mockedRequest, "12");
90                 
91         }
92         
93         @Test
94         public void postCreateNewVNFChangeTest() throws Exception{
95                 //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\"]}]}}";
96                 JSONObject jsonObject =Mockito.mock(JSONObject.class);
97                 
98                 schedulerController.postCreateNewVNFChange(mockedRequest, jsonObject);
99         }
100         
101         @Test
102         public void postSubmitVnfChangeTimeslotsTest() throws Exception{
103                 JSONObject jsonObject =Mockito.mock(JSONObject.class);
104                 Mockito.when(jsonObject.get("scheduleId")).thenReturn("12");
105         PowerMockito.mockStatic(SystemProperties.class);
106                 PowerMockito.when(SystemProperties.getProperty(SchedulerProperties.SCHEDULER_SUBMIT_NEW_VNF_CHANGE)).thenReturn("/v1/ChangeManagement/schedules/{scheduleId}/approvals");
107                 schedulerController.postSubmitVnfChangeTimeslots(mockedRequest, jsonObject);
108         }
109         
110 }