2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright © 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============================================
36 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
38 package org.onap.portalsdk.workflow.controllers;
40 import java.util.ArrayList;
41 import java.util.Date;
42 import java.util.List;
44 import javax.servlet.http.HttpServletRequest;
45 import javax.servlet.http.HttpServletResponse;
46 import javax.servlet.http.HttpSession;
48 import org.junit.Assert;
49 import org.junit.Test;
50 import org.junit.runner.RunWith;
51 import org.mockito.InjectMocks;
52 import org.mockito.Mock;
53 import org.mockito.Mockito;
54 import org.onap.portalsdk.core.domain.User;
55 import org.onap.portalsdk.workflow.models.Workflow;
56 import org.onap.portalsdk.workflow.models.WorkflowLite;
57 import org.onap.portalsdk.workflow.services.WorkflowService;
58 import org.powermock.api.mockito.PowerMockito;
59 import org.powermock.modules.junit4.PowerMockRunner;
60 import org.springframework.mock.web.MockHttpServletRequest;
61 import org.springframework.mock.web.MockHttpServletResponse;
63 @RunWith(PowerMockRunner.class)
64 public class WorkflowControllerTest {
67 private WorkflowController workflowController;
70 private WorkflowService workflowService;
73 public void saveCronJob() throws Exception {
74 MockHttpServletRequest request = new MockHttpServletRequest();
76 HttpServletResponse response = new MockHttpServletResponse();
78 workflowController.saveCronJob(request, response);
79 Assert.assertTrue(true);
83 public void getWorkflowListTest() {
85 List<Workflow> workflows = new ArrayList<>();
86 Workflow wfl = new Workflow();
90 wfl.setDescription("Testing");
91 wfl.setActive(Boolean.TRUE);
92 wfl.setCreated(new Date());
93 User user = new User();
94 user.setFirstName("FNAME");
95 user.setLastName("LNAME");
97 wfl.setCreatedBy(user);
98 wfl.setModifiedBy(user);
99 wfl.setLastUpdated(new Date());
100 wfl.setWorkflowKey("KEY");
101 wfl.setRunLink("RLINK");
102 wfl.setSuspendLink("SLINK");
105 Mockito.when(workflowService.getAllWorkflows()).thenReturn(workflows);
107 String respone = workflowController.getWorkflowList();
108 Assert.assertNotNull(respone);
112 public void getWorkflowListEmptyTest() {
114 List<Workflow> workflows = new ArrayList<>();
115 Workflow wfl = new Workflow();
119 wfl.setDescription("Testing");
120 wfl.setActive(Boolean.TRUE);
121 wfl.setCreated(new Date());
123 wfl.setCreatedBy(null);
124 wfl.setModifiedBy(null);
125 wfl.setLastUpdated(null);
126 wfl.setWorkflowKey("KEY");
127 wfl.setRunLink("RLINK");
128 wfl.setSuspendLink("SLINK");
131 Mockito.when(workflowService.getAllWorkflows()).thenReturn(workflows);
133 String respone = workflowController.getWorkflowList();
134 Assert.assertNotNull(respone);
138 public void getWorkflowListNullTest() {
139 Mockito.when(workflowService.getAllWorkflows()).thenReturn(null);
140 String respone = workflowController.getWorkflowList();
141 Assert.assertNotNull(respone);
145 public void addWorkflowTest() {
146 Workflow workflow = new Workflow();
147 HttpServletRequest request = PowerMockito.mock(HttpServletRequest.class);
148 HttpSession mockSession = PowerMockito.mock(HttpSession.class);
149 Mockito.when(request.getSession()).thenReturn(mockSession);
151 User user = new User();
152 user.setLoginId("123");
153 Mockito.when(mockSession.getAttribute("user")).thenReturn(user);
155 workflowController.addWorkflow(workflow, request);
156 Assert.assertTrue(true);
160 public void editWorkflowTest() {
161 WorkflowLite workflow = new WorkflowLite();
162 HttpServletRequest request = PowerMockito.mock(HttpServletRequest.class);
163 HttpSession mockSession = PowerMockito.mock(HttpSession.class);
164 Mockito.when(request.getSession()).thenReturn(mockSession);
166 User user = new User();
167 user.setLoginId("123");
168 Mockito.when(mockSession.getAttribute("user")).thenReturn(user);
170 workflowController.editWorkflow(workflow, request);
171 Assert.assertTrue(true);
175 public void removeWorkflowTest() {
176 Long workflowId = 123L;
177 HttpServletRequest request = new MockHttpServletRequest();
178 HttpServletResponse response = new MockHttpServletResponse();
179 workflowController.removeWorkflow(workflowId, request, response);
180 Assert.assertTrue(true);
183 @Test(expected = UnsupportedOperationException.class)
184 public void removeAllWorkflows() {
185 workflowController.removeAllWorkflows();
189 public void getWorkflowPartialPageTest(){
190 workflowController.getWorkflowPartialPage();
191 Assert.assertTrue(true);