c1ac6a219fa3d82d7054c9c8974402f21ee4ed24
[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 AT&T Intellectual Property. All rights reserved.
6  * Modifications Copyright (C) 2018 Nokia. All rights reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.vid.config;
23
24 import com.fasterxml.jackson.core.JsonProcessingException;
25 import com.fasterxml.jackson.databind.ObjectMapper;
26 import java.io.IOException;
27 import org.hibernate.SessionFactory;
28 import org.mockito.Mockito;
29 import org.onap.portalsdk.core.service.DataAccessService;
30 import org.onap.vid.aai.AaiOverTLSClient;
31 import org.onap.vid.aai.AaiOverTLSClientInterface;
32 import org.onap.vid.aai.AaiOverTLSPropertySupplier;
33 import org.onap.vid.aai.util.HttpsAuthClient;
34 import org.onap.vid.aai.util.SSLContextProvider;
35 import org.onap.vid.aai.util.SystemPropertyHelper;
36 import org.onap.vid.client.SyncRestClient;
37 import org.onap.vid.job.JobAdapter;
38 import org.onap.vid.job.JobsBrokerService;
39 import org.onap.vid.job.command.InProgressStatusCommand;
40 import org.onap.vid.job.command.JobCommandFactory;
41 import org.onap.vid.job.command.ServiceInstantiationCommand;
42 import org.onap.vid.job.impl.JobAdapterImpl;
43 import org.onap.vid.job.impl.JobWorker;
44 import org.onap.vid.job.impl.JobsBrokerServiceInDatabaseImpl;
45 import org.onap.vid.mso.RestMsoImplementation;
46 import org.onap.vid.services.AsyncInstantiationBusinessLogic;
47 import org.onap.vid.services.AsyncInstantiationBusinessLogicImpl;
48 import org.onap.vid.services.AuditService;
49 import org.onap.vid.services.AuditServiceImpl;
50 import org.springframework.beans.factory.config.ConfigurableBeanFactory;
51 import org.springframework.context.ApplicationContext;
52 import org.springframework.context.annotation.Bean;
53 import org.springframework.context.annotation.Configuration;
54 import org.springframework.context.annotation.Scope;
55
56 @Configuration
57 public class JobCommandsConfigWithMockedMso {
58
59     @Bean
60     public RestMsoImplementation restMso() {
61         return Mockito.mock(RestMsoImplementation.class);
62     }
63
64     @Bean
65     public JobsBrokerService jobsBrokerService(DataAccessService dataAccessService, SessionFactory sessionFactory) {
66         return new JobsBrokerServiceInDatabaseImpl(dataAccessService, sessionFactory, 200, 0);
67     }
68
69     @Bean
70     public HttpsAuthClient httpsAuthClientFactory(){
71         return new HttpsAuthClient("some random path", new SystemPropertyHelper(), new SSLContextProvider());
72     }
73
74     @Bean
75     public JobAdapter jobAdapter() {
76         return new JobAdapterImpl();
77     }
78
79     @Bean
80     public JobCommandFactory jobCommandFactory(ApplicationContext applicationContext) {
81         return new JobCommandFactory(applicationContext);
82     }
83
84     @Bean
85     public JobWorker jobWorker(JobsBrokerService jobsBrokerService, JobCommandFactory jobCommandFactory) {
86         JobWorker jobWorker = new JobWorker();
87         jobWorker.setJobsBrokerService(jobsBrokerService);
88         jobWorker.setJobCommandFactory(jobCommandFactory);
89         return jobWorker;
90     }
91
92     @Bean
93     public AaiOverTLSClientInterface AaiOverTLSClient(){
94         io.joshworks.restclient.http.mapper.ObjectMapper objectMapper = new io.joshworks.restclient.http.mapper.ObjectMapper() {
95
96             ObjectMapper om = new ObjectMapper();
97
98             @Override
99             public <T> T readValue(String s, Class<T> aClass) {
100                 try {
101                     return om.readValue(s, aClass);
102                 } catch (IOException e) {
103                     throw new RuntimeException(e);
104                 }
105             }
106
107             @Override
108             public String writeValue(Object o) {
109                 try {
110                     return om.writeValueAsString(o);
111                 } catch (JsonProcessingException e) {
112                     throw new RuntimeException(e);
113                 }
114             }
115         };
116
117         return new AaiOverTLSClient(new SyncRestClient(objectMapper), new AaiOverTLSPropertySupplier());
118     }
119
120     @Bean
121     public AsyncInstantiationBusinessLogic asyncInstantiationBusinessLogic(DataAccessService dataAccessService,
122                                                                            JobAdapter jobAdapter,
123                                                                            JobsBrokerService jobsBrokerService,
124                                                                            SessionFactory sessionFactory,
125                                                                            AaiOverTLSClientInterface aaiOverTLSClientInterface) {
126         return new AsyncInstantiationBusinessLogicImpl(dataAccessService, jobAdapter, jobsBrokerService, sessionFactory, aaiOverTLSClientInterface);
127     }
128
129     @Bean
130     @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
131     public ServiceInstantiationCommand serviceInstantiationCommand() {
132         return new ServiceInstantiationCommand();
133     }
134
135     @Bean
136     @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
137     public InProgressStatusCommand inProgressStatusCommand() {
138         return new InProgressStatusCommand();
139     }
140
141     @Bean
142     public AuditService auditService() {
143         return new AuditServiceImpl();
144     }
145
146 }