846a994b5736a092a82b99bb8848bf5d439b63c8
[portal/sdk.git] /
1 /*
2  * ============LICENSE_START==========================================
3  * ONAP Portal SDK
4  * ===================================================================
5  * Copyright © 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.portalsdk.workflow.services;
39
40 import java.util.ArrayList;
41 import java.util.List;
42
43 import org.hibernate.SessionFactory;
44 import org.junit.Assert;
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.onap.portalsdk.core.service.DataAccessService;
51 import org.onap.portalsdk.workflow.dao.WorkflowDAO;
52 import org.onap.portalsdk.workflow.domain.WorkflowSchedule;
53 import org.onap.portalsdk.workflow.scheduler.WorkFlowScheduleRegistry;
54 import org.powermock.modules.junit4.PowerMockRunner;
55 import org.springframework.context.ApplicationContext;
56
57
58 @RunWith(PowerMockRunner.class)
59 public class WorkflowScheduleServiceImplTest {
60
61         @Mock
62         private SessionFactory sessionFactory;
63         
64         @Mock
65         private WorkflowDAO workflowDAO;
66                 
67         @Mock
68         private WorkflowScheduleService workflowScheduleService;
69         
70         @Mock
71         private WorkFlowScheduleRegistry workflowRegistry;
72
73         @Mock
74         private ApplicationContext appContext;
75         
76         @Mock
77         private DataAccessService dataAccessService;
78         
79         @InjectMocks
80         private WorkflowScheduleServiceImpl workflowScheduleServiceImpl;
81         
82         @Test
83         public void findAllTest(){
84                 workflowScheduleServiceImpl.findAll();
85                 Assert.assertTrue(true);
86         }
87         
88         @Test
89         public void saveWorkflowScheduleTest(){
90                 WorkflowSchedule ws = new WorkflowSchedule();
91                 workflowScheduleServiceImpl.saveWorkflowSchedule(ws);
92                 Assert.assertTrue(true);
93         }
94         
95         @Test
96         public void triggerWorkflowSchedulingTest() {
97                 WorkflowSchedule ws = new WorkflowSchedule();
98                 
99                 List<WorkflowSchedule> allWorkflows = new ArrayList<>();
100                 allWorkflows.add(ws);
101                 Mockito.when(dataAccessService.executeQuery(Mockito.anyString(), Mockito.anyMap())).thenReturn(allWorkflows);
102                 
103                 workflowScheduleServiceImpl.triggerWorkflowScheduling();
104                 Assert.assertTrue(true);
105         }
106         
107         @Test
108         public void getWorkflowScheduleByKey() {
109                 Long key = 123L;
110                 WorkflowSchedule ws = new WorkflowSchedule();
111                 Mockito.when(dataAccessService.getDomainObject(WorkflowSchedule.class, key, null)).thenReturn(ws);
112                 WorkflowSchedule workflowSchedule = workflowScheduleServiceImpl.getWorkflowScheduleByKey(key);
113                 Assert.assertNotNull(workflowSchedule);
114         }
115 }