Introduce FeatureManager to ResourceCommand
[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             FeatureManager featureManager) {
179         return new ALaCarteServiceCommand(inProgressStatusService, watchChildrenJobsBL, asyncInstantiationBusinessLogic, jobsBrokerService, msoRequestBuilder, msoResultHandlerService, jobAdapter, restMso, auditService, featureManager);
180     }
181
182     @Bean
183     @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
184     public MacroServiceCommand macroServiceCommand(
185             AsyncInstantiationBusinessLogic asyncInstantiationBusinessLogic,
186             JobsBrokerService jobsBrokerService,
187             MsoRequestBuilder msoRequestBuilder,
188             MsoResultHandlerService msoResultHandlerService,
189             JobAdapter jobAdapter,
190             InProgressStatusService inProgressStatusService,
191             WatchChildrenJobsBL watchChildrenJobsBL,
192             RestMsoImplementation restMso,
193             AuditService auditService,
194             FeatureManager featureManager) {
195         return new MacroServiceCommand(inProgressStatusService, watchChildrenJobsBL, asyncInstantiationBusinessLogic, jobsBrokerService, msoRequestBuilder, msoResultHandlerService, jobAdapter, restMso, auditService, featureManager);
196     }
197
198
199     @Bean
200     @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
201     public NetworkCommand networkCommand(
202             AsyncInstantiationBusinessLogic asyncInstantiationBusinessLogic,
203             RestMsoImplementation restMso,
204             MsoRequestBuilder msoRequestBuilder,
205             MsoResultHandlerService msoResultHandlerService,
206             InProgressStatusService inProgressStatusService,
207             WatchChildrenJobsBL watchChildrenJobsBL,
208             JobsBrokerService jobsBrokerService,
209             JobAdapter jobAdapter,
210             FeatureManager featureManager) {
211         return new NetworkCommand(asyncInstantiationBusinessLogic, restMso, msoRequestBuilder, msoResultHandlerService,
212                 inProgressStatusService, watchChildrenJobsBL, jobsBrokerService, jobAdapter, featureManager);
213     }
214     @Bean
215     @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
216     public InstanceGroupCommand instanceGroupCommand(
217             AsyncInstantiationBusinessLogic asyncInstantiationBusinessLogic,
218             MsoRequestBuilder msoRequestBuilder,
219             MsoResultHandlerService msoResultHandlerService,
220             InProgressStatusService inProgressStatusService,
221             WatchChildrenJobsBL watchChildrenJobsBL,
222             RestMsoImplementation restMso,
223             JobsBrokerService jobsBrokerService,
224             JobAdapter jobAdapter,
225             FeatureManager featureManager) {
226         return new InstanceGroupCommand(asyncInstantiationBusinessLogic, restMso, msoRequestBuilder, msoResultHandlerService, inProgressStatusService,
227             watchChildrenJobsBL, jobsBrokerService, jobAdapter, featureManager);
228     }
229
230     @Bean
231     @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
232     public InstanceGroupMemberCommand instanceGroupMemberCommand (
233             AsyncInstantiationBusinessLogic asyncInstantiationBusinessLogic,
234             MsoRequestBuilder msoRequestBuilder,
235             MsoResultHandlerService msoResultHandlerService,
236             InProgressStatusService inProgressStatusService,
237             WatchChildrenJobsBL watchChildrenJobsBL,
238             RestMsoImplementation restMso,
239             JobsBrokerService jobsBrokerService,
240             JobAdapter jobAdapter,
241             FeatureManager featureManager) {
242         return new InstanceGroupMemberCommand(asyncInstantiationBusinessLogic, restMso, msoRequestBuilder, msoResultHandlerService, inProgressStatusService,
243                 watchChildrenJobsBL, jobsBrokerService, jobAdapter, featureManager);
244     }
245
246
247     @Bean
248     @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
249     public VnfCommand VnfCommand(
250             AsyncInstantiationBusinessLogic asyncInstantiationBusinessLogic,
251             RestMsoImplementation restMso,
252             MsoRequestBuilder msoRequestBuilder,
253             MsoResultHandlerService msoResultHandlerService,
254             InProgressStatusService inProgressStatusService,
255             WatchChildrenJobsBL watchChildrenJobsBL,
256             JobsBrokerService jobsBrokerService,
257             JobAdapter jobAdapter,
258             FeatureManager featureManager) {
259         return new VnfCommand(asyncInstantiationBusinessLogic, restMso, msoRequestBuilder, msoResultHandlerService,
260                 inProgressStatusService, watchChildrenJobsBL, jobsBrokerService ,jobAdapter,
261                 featureManager);
262     }
263
264     @Bean
265     @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
266     public VolumeGroupCommand volumeGroupCommand(
267             AsyncInstantiationBusinessLogic asyncInstantiationBusinessLogic,
268             RestMsoImplementation restMso,
269             MsoRequestBuilder msoRequestBuilder,
270             MsoResultHandlerService msoResultHandlerService,
271             InProgressStatusService inProgressStatusService,
272             WatchChildrenJobsBL watchChildrenJobsBL,
273             JobsBrokerService jobsBrokerService,
274             JobAdapter jobAdapter,
275             FeatureManager featureManager) {
276         return new VolumeGroupCommand(asyncInstantiationBusinessLogic, restMso, msoRequestBuilder, msoResultHandlerService,
277                 inProgressStatusService, watchChildrenJobsBL, jobsBrokerService ,jobAdapter, featureManager);
278     }
279
280     @Bean
281     @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
282     public VfmoduleCommand VfmoduleCommand(
283             AsyncInstantiationBusinessLogic asyncInstantiationBusinessLogic,
284             RestMsoImplementation restMso,
285             MsoRequestBuilder msoRequestBuilder,
286             MsoResultHandlerService msoResultHandlerService,
287             InProgressStatusService inProgressStatusService,
288             WatchChildrenJobsBL watchChildrenJobsBL,
289             JobsBrokerService jobsBrokerService,
290             JobAdapter jobAdapter,
291             FeatureManager featureManager) {
292         return new VfmoduleCommand(asyncInstantiationBusinessLogic, restMso, msoRequestBuilder, msoResultHandlerService,
293                 inProgressStatusService, watchChildrenJobsBL, jobsBrokerService, jobAdapter, featureManager);
294     }
295     @Bean
296     public AuditService auditService(RestMsoImplementation msoClient, AsyncInstantiationRepository asyncInstantiationRepository) {
297         return new AuditServiceImpl(msoClient, asyncInstantiationRepository);
298     }
299
300     @Bean
301     public InProgressStatusService inProgressStatusService(AsyncInstantiationBusinessLogic asyncInstantiationBL, RestMsoImplementation restMso, AuditService auditService, FeatureManager featureManager) {
302         return new InProgressStatusService(asyncInstantiationBL, restMso, auditService, featureManager);
303     }
304
305     @Bean
306     public MsoResultHandlerService rootCommandService(AsyncInstantiationBusinessLogic asyncInstantiationBL, AuditService auditService) {
307         return new MsoResultHandlerService(asyncInstantiationBL, auditService);
308     }
309
310     @Bean
311     public CommandUtils commandUtils() {
312         return Mockito.mock(CommandUtils.class);
313     }
314
315     @Bean
316     public WatchChildrenJobsBL watchChildrenJobsService(DataAccessService dataAccessService) {
317         return new WatchChildrenJobsBL(dataAccessService);
318     }
319
320 }