2 * ============LICENSE_START=======================================================
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
22 package org.onap.vid.config;
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.AaiClientInterface;
31 import org.onap.vid.aai.AaiOverTLSClient;
32 import org.onap.vid.aai.AaiOverTLSClientInterface;
33 import org.onap.vid.aai.AaiOverTLSPropertySupplier;
34 import org.onap.vid.aai.util.HttpsAuthClient;
35 import org.onap.vid.aai.util.SSLContextProvider;
36 import org.onap.vid.aai.util.SystemPropertyHelper;
37 import org.onap.vid.client.SyncRestClient;
38 import org.onap.vid.job.JobAdapter;
39 import org.onap.vid.job.JobsBrokerService;
40 import org.onap.vid.job.command.InProgressStatusCommand;
41 import org.onap.vid.job.command.JobCommandFactory;
42 import org.onap.vid.job.command.ServiceInstantiationCommand;
43 import org.onap.vid.job.impl.JobAdapterImpl;
44 import org.onap.vid.job.impl.JobWorker;
45 import org.onap.vid.job.impl.JobsBrokerServiceInDatabaseImpl;
46 import org.onap.vid.mso.RestMsoImplementation;
47 import org.onap.vid.services.AsyncInstantiationBusinessLogic;
48 import org.onap.vid.services.AsyncInstantiationBusinessLogicImpl;
49 import org.onap.vid.services.AuditService;
50 import org.onap.vid.services.AuditServiceImpl;
51 import org.springframework.beans.factory.config.ConfigurableBeanFactory;
52 import org.springframework.context.ApplicationContext;
53 import org.springframework.context.annotation.Bean;
54 import org.springframework.context.annotation.Configuration;
55 import org.springframework.context.annotation.Scope;
58 public class JobCommandsConfigWithMockedMso {
61 public RestMsoImplementation restMso() {
62 return Mockito.mock(RestMsoImplementation.class);
66 public JobsBrokerService jobsBrokerService(DataAccessService dataAccessService, SessionFactory sessionFactory) {
67 return new JobsBrokerServiceInDatabaseImpl(dataAccessService, sessionFactory, 200, 0);
71 public HttpsAuthClient httpsAuthClientFactory(){
72 return new HttpsAuthClient("some random path", new SystemPropertyHelper(), new SSLContextProvider());
76 public JobAdapter jobAdapter() {
77 return new JobAdapterImpl();
81 public JobCommandFactory jobCommandFactory(ApplicationContext applicationContext) {
82 return new JobCommandFactory(applicationContext);
86 public JobWorker jobWorker(JobsBrokerService jobsBrokerService, JobCommandFactory jobCommandFactory) {
87 JobWorker jobWorker = new JobWorker();
88 jobWorker.setJobsBrokerService(jobsBrokerService);
89 jobWorker.setJobCommandFactory(jobCommandFactory);
94 public AaiOverTLSClientInterface AaiOverTLSClient(){
95 io.joshworks.restclient.http.mapper.ObjectMapper objectMapper = new io.joshworks.restclient.http.mapper.ObjectMapper() {
97 ObjectMapper om = new ObjectMapper();
100 public <T> T readValue(String s, Class<T> aClass) {
102 return om.readValue(s, aClass);
103 } catch (IOException e) {
104 throw new RuntimeException(e);
109 public String writeValue(Object o) {
111 return om.writeValueAsString(o);
112 } catch (JsonProcessingException e) {
113 throw new RuntimeException(e);
118 return new AaiOverTLSClient(new SyncRestClient(objectMapper), new AaiOverTLSPropertySupplier());
122 public AsyncInstantiationBusinessLogic asyncInstantiationBusinessLogic(DataAccessService dataAccessService,
123 JobAdapter jobAdapter,
124 JobsBrokerService jobsBrokerService,
125 SessionFactory sessionFactory,
126 AaiClientInterface aaiClient,
127 AaiOverTLSClientInterface aaiOverTLSClientInterface) {
128 return new AsyncInstantiationBusinessLogicImpl(dataAccessService, jobAdapter, jobsBrokerService, sessionFactory, aaiClient, aaiOverTLSClientInterface);
132 @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
133 public ServiceInstantiationCommand serviceInstantiationCommand() {
134 return new ServiceInstantiationCommand();
138 @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
139 public InProgressStatusCommand inProgressStatusCommand() {
140 return new InProgressStatusCommand();
144 public AuditService auditService() {
145 return new AuditServiceImpl();