clear isFailed and statusMessage when get it from frontend request
[vid.git] / vid-app-common / src / test / java / org / onap / vid / config / JobCommandsConfigWithMockedMso.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * VID
4  * ================================================================================
5  * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.vid.config;
22
23 import org.hibernate.SessionFactory;
24 import org.mockito.Mockito;
25 import org.onap.portalsdk.core.service.DataAccessService;
26 import org.onap.vid.aai.AaiClientInterface;
27 import org.onap.vid.aai.util.HttpsAuthClient;
28 import org.onap.vid.aai.util.SSLContextProvider;
29 import org.onap.vid.aai.util.ServletRequestHelper;
30 import org.onap.vid.aai.util.SystemPropertyHelper;
31 import org.onap.vid.dal.AsyncInstantiationRepository;
32 import org.onap.vid.job.JobAdapter;
33 import org.onap.vid.job.JobsBrokerService;
34 import org.onap.vid.job.command.ALaCarteServiceCommand;
35 import org.onap.vid.job.command.CommandUtils;
36 import org.onap.vid.job.command.InProgressStatusService;
37 import org.onap.vid.job.command.InstanceGroupCommand;
38 import org.onap.vid.job.command.InstanceGroupMemberCommand;
39 import org.onap.vid.job.command.JobCommandFactory;
40 import org.onap.vid.job.command.MacroServiceCommand;
41 import org.onap.vid.job.command.MsoRequestBuilder;
42 import org.onap.vid.job.command.MsoResultHandlerService;
43 import org.onap.vid.job.command.NetworkCommand;
44 import org.onap.vid.job.command.VfmoduleCommand;
45 import org.onap.vid.job.command.VnfCommand;
46 import org.onap.vid.job.command.VolumeGroupCommand;
47 import org.onap.vid.job.command.WatchChildrenJobsBL;
48 import org.onap.vid.job.impl.JobAdapterImpl;
49 import org.onap.vid.job.impl.JobWorker;
50 import org.onap.vid.job.impl.JobsBrokerServiceInDatabaseImpl;
51 import org.onap.vid.model.ModelUtil;
52 import org.onap.vid.mso.RestMsoImplementation;
53 import org.onap.vid.services.AsyncInstantiationBusinessLogic;
54 import org.onap.vid.services.AsyncInstantiationBusinessLogicImpl;
55 import org.onap.vid.services.AuditService;
56 import org.onap.vid.services.AuditServiceImpl;
57 import org.onap.vid.services.CloudOwnerService;
58 import org.onap.vid.services.InstantiationTemplatesService;
59 import org.onap.vid.services.VersionService;
60 import org.springframework.beans.factory.config.ConfigurableBeanFactory;
61 import org.springframework.context.ApplicationContext;
62 import org.springframework.context.annotation.Bean;
63 import org.springframework.context.annotation.Configuration;
64 import org.springframework.context.annotation.Scope;
65 import org.togglz.core.manager.FeatureManager;
66
67 @Configuration
68 public class JobCommandsConfigWithMockedMso {
69
70     @Bean
71     public RestMsoImplementation restMso() {
72         return Mockito.mock(RestMsoImplementation.class);
73     }
74
75     @Bean
76     public VersionService versionService() {
77         return Mockito.mock(VersionService.class);
78     }
79
80     @Bean
81     public JobsBrokerService jobsBrokerService(DataAccessService dataAccessService, SessionFactory sessionFactory, VersionService versionService) {
82         return new JobsBrokerServiceInDatabaseImpl(dataAccessService, sessionFactory, 200, 0,versionService);
83     }
84
85     @Bean
86     public SSLContextProvider sslContextProvider() {
87         return new SSLContextProvider();
88     }
89
90     @Bean
91     public SystemPropertyHelper systemPropertyHelper() {
92         return new SystemPropertyHelper();
93     }
94
95     @Bean
96     public ServletRequestHelper servletRequestHelper() {
97         return new ServletRequestHelper();
98     }
99
100     @Bean
101     public HttpsAuthClient httpsAuthClientFactory(SystemPropertyHelper systemPropertyHelper, SSLContextProvider sslContextProvider, FeatureManager featureManager){
102         return new HttpsAuthClient("some random path", systemPropertyHelper, sslContextProvider, featureManager);
103     }
104
105
106     @Bean
107     public JobAdapter jobAdapter(FeatureManager featureManager) {
108         return new JobAdapterImpl(featureManager);
109     }
110
111     @Bean
112     public JobCommandFactory jobCommandFactory(ApplicationContext applicationContext) {
113         return new JobCommandFactory(applicationContext);
114     }
115
116     @Bean
117     public JobWorker jobWorker(JobsBrokerService jobsBrokerService, JobCommandFactory jobCommandFactory) {
118         JobWorker jobWorker = new JobWorker();
119         jobWorker.setJobsBrokerService(jobsBrokerService);
120         jobWorker.setJobCommandFactory(jobCommandFactory);
121         return jobWorker;
122     }
123
124     @Bean
125     public FeatureManager featureManager() {
126         return Mockito.mock(FeatureManager.class);
127     }
128
129     @Bean
130     public MsoRequestBuilder msoRequestHandlerService(AsyncInstantiationBusinessLogic asyncInstantiationBusinessLogic,
131                                                       CloudOwnerService cloudOwnerService,
132                                                       AaiClientInterface aaiClient,
133                                                       FeatureManager featureManager) {
134         return new MsoRequestBuilder(asyncInstantiationBusinessLogic, cloudOwnerService, aaiClient, featureManager);
135     }
136     @Bean
137     public AsyncInstantiationRepository asyncInstantiationRepository(DataAccessService dataAccessService) {
138         return new AsyncInstantiationRepository(dataAccessService);
139     }
140
141     @Bean
142     public AsyncInstantiationBusinessLogic asyncInstantiationBusinessLogic(JobAdapter jobAdapter,
143                                                                            JobsBrokerService jobsBrokerService,
144                                                                            SessionFactory sessionFactory,
145                                                                            AaiClientInterface aaiClient,
146                                                                            FeatureManager featureManager,
147                                                                            CloudOwnerService cloudOwnerService,
148                                                                            AsyncInstantiationRepository asyncInstantiationRepository,
149                                                                            AuditService auditService) {
150         return new AsyncInstantiationBusinessLogicImpl(jobAdapter, jobsBrokerService, sessionFactory, aaiClient, featureManager, cloudOwnerService, asyncInstantiationRepository, auditService);
151     }
152
153     @Bean
154     public ModelUtil modelUtil() {return new ModelUtil();}
155
156     @Bean
157     public InstantiationTemplatesService instantiationTemplatesService(
158         ModelUtil modelUtil,
159         AsyncInstantiationRepository asyncInstantiationRepository,
160         FeatureManager featureManager
161         ) {
162         return new InstantiationTemplatesService(modelUtil, asyncInstantiationRepository, featureManager);
163     };
164
165
166     @Bean
167     @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
168     public ALaCarteServiceCommand aLaCarteServiceCommand(
169             AsyncInstantiationBusinessLogic asyncInstantiationBusinessLogic,
170             JobsBrokerService jobsBrokerService,
171             MsoRequestBuilder msoRequestBuilder,
172             MsoResultHandlerService msoResultHandlerService,
173             JobAdapter jobAdapter,
174             InProgressStatusService inProgressStatusService,
175             WatchChildrenJobsBL watchChildrenJobsBL,
176             RestMsoImplementation restMso,
177             AuditService auditService) {
178         return new ALaCarteServiceCommand(inProgressStatusService, watchChildrenJobsBL, asyncInstantiationBusinessLogic, jobsBrokerService, msoRequestBuilder, msoResultHandlerService, jobAdapter, restMso, auditService);
179     }
180
181     @Bean
182     @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
183     public MacroServiceCommand macroServiceCommand(
184             AsyncInstantiationBusinessLogic asyncInstantiationBusinessLogic,
185             JobsBrokerService jobsBrokerService,
186             MsoRequestBuilder msoRequestBuilder,
187             MsoResultHandlerService msoResultHandlerService,
188             JobAdapter jobAdapter,
189             InProgressStatusService inProgressStatusService,
190             WatchChildrenJobsBL watchChildrenJobsBL,
191             RestMsoImplementation restMso,
192             AuditService auditService) {
193         return new MacroServiceCommand(inProgressStatusService, watchChildrenJobsBL, asyncInstantiationBusinessLogic, jobsBrokerService, msoRequestBuilder, msoResultHandlerService, jobAdapter, restMso, auditService);
194     }
195
196
197     @Bean
198     @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
199     public NetworkCommand networkCommand(
200             AsyncInstantiationBusinessLogic asyncInstantiationBusinessLogic,
201             RestMsoImplementation restMso,
202             MsoRequestBuilder msoRequestBuilder,
203             MsoResultHandlerService msoResultHandlerService,
204             InProgressStatusService inProgressStatusService,
205             WatchChildrenJobsBL watchChildrenJobsBL,
206             JobsBrokerService jobsBrokerService,
207             JobAdapter jobAdapter) {
208         return new NetworkCommand(asyncInstantiationBusinessLogic, restMso, msoRequestBuilder, msoResultHandlerService,
209                 inProgressStatusService, watchChildrenJobsBL, jobsBrokerService, jobAdapter);
210     }
211     @Bean
212     @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
213     public InstanceGroupCommand instanceGroupCommand(
214             AsyncInstantiationBusinessLogic asyncInstantiationBusinessLogic,
215             MsoRequestBuilder msoRequestBuilder,
216             MsoResultHandlerService msoResultHandlerService,
217             InProgressStatusService inProgressStatusService,
218             WatchChildrenJobsBL watchChildrenJobsBL,
219             RestMsoImplementation restMso,
220             JobsBrokerService jobsBrokerService,
221             JobAdapter jobAdapter) {
222         return new InstanceGroupCommand(asyncInstantiationBusinessLogic, restMso, msoRequestBuilder, msoResultHandlerService, inProgressStatusService, watchChildrenJobsBL, jobsBrokerService, jobAdapter);
223     }
224
225     @Bean
226     @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
227     public InstanceGroupMemberCommand instanceGroupMemberCommand (
228             AsyncInstantiationBusinessLogic asyncInstantiationBusinessLogic,
229             MsoRequestBuilder msoRequestBuilder,
230             MsoResultHandlerService msoResultHandlerService,
231             InProgressStatusService inProgressStatusService,
232             WatchChildrenJobsBL watchChildrenJobsBL,
233             RestMsoImplementation restMso,
234             JobsBrokerService jobsBrokerService,
235             JobAdapter jobAdapter) {
236         return new InstanceGroupMemberCommand(asyncInstantiationBusinessLogic, restMso, msoRequestBuilder, msoResultHandlerService, inProgressStatusService,
237                 watchChildrenJobsBL, jobsBrokerService, jobAdapter);
238     }
239
240
241     @Bean
242     @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
243     public VnfCommand VnfCommand(
244             AsyncInstantiationBusinessLogic asyncInstantiationBusinessLogic,
245             RestMsoImplementation restMso,
246             MsoRequestBuilder msoRequestBuilder,
247             MsoResultHandlerService msoResultHandlerService,
248             InProgressStatusService inProgressStatusService,
249             WatchChildrenJobsBL watchChildrenJobsBL,
250             JobsBrokerService jobsBrokerService,
251             JobAdapter jobAdapter,
252             FeatureManager featureManager) {
253         return new VnfCommand(asyncInstantiationBusinessLogic, restMso, msoRequestBuilder, msoResultHandlerService,
254                 inProgressStatusService, watchChildrenJobsBL, jobsBrokerService ,jobAdapter,
255                 featureManager);
256     }
257
258     @Bean
259     @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
260     public VolumeGroupCommand volumeGroupCommand(
261             AsyncInstantiationBusinessLogic asyncInstantiationBusinessLogic,
262             RestMsoImplementation restMso,
263             MsoRequestBuilder msoRequestBuilder,
264             MsoResultHandlerService msoResultHandlerService,
265             InProgressStatusService inProgressStatusService,
266             WatchChildrenJobsBL watchChildrenJobsBL,
267             JobsBrokerService jobsBrokerService,
268             JobAdapter jobAdapter) {
269         return new VolumeGroupCommand(asyncInstantiationBusinessLogic, restMso, msoRequestBuilder, msoResultHandlerService,
270                 inProgressStatusService, watchChildrenJobsBL, jobsBrokerService ,jobAdapter);
271     }
272
273     @Bean
274     @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
275     public VfmoduleCommand VfmoduleCommand(
276             AsyncInstantiationBusinessLogic asyncInstantiationBusinessLogic,
277             RestMsoImplementation restMso,
278             MsoRequestBuilder msoRequestBuilder,
279             MsoResultHandlerService msoResultHandlerService,
280             InProgressStatusService inProgressStatusService,
281             WatchChildrenJobsBL watchChildrenJobsBL,
282             JobsBrokerService jobsBrokerService,
283             JobAdapter jobAdapter) {
284         return new VfmoduleCommand(asyncInstantiationBusinessLogic, restMso, msoRequestBuilder, msoResultHandlerService,
285                 inProgressStatusService, watchChildrenJobsBL, jobsBrokerService, jobAdapter);
286     }
287     @Bean
288     public AuditService auditService(RestMsoImplementation msoClient, AsyncInstantiationRepository asyncInstantiationRepository) {
289         return new AuditServiceImpl(msoClient, asyncInstantiationRepository);
290     }
291
292     @Bean
293     public InProgressStatusService inProgressStatusService(AsyncInstantiationBusinessLogic asyncInstantiationBL, RestMsoImplementation restMso, AuditService auditService, FeatureManager featureManager) {
294         return new InProgressStatusService(asyncInstantiationBL, restMso, auditService, featureManager);
295     }
296
297     @Bean
298     public MsoResultHandlerService rootCommandService(AsyncInstantiationBusinessLogic asyncInstantiationBL, AuditService auditService) {
299         return new MsoResultHandlerService(asyncInstantiationBL, auditService);
300     }
301
302     @Bean
303     public CommandUtils commandUtils() {
304         return Mockito.mock(CommandUtils.class);
305     }
306
307     @Bean
308     public WatchChildrenJobsBL watchChildrenJobsService(DataAccessService dataAccessService) {
309         return new WatchChildrenJobsBL(dataAccessService);
310     }
311
312 }