1 package com.oransc.rappmanager.acm.service;
3 import com.fasterxml.jackson.databind.DeserializationFeature;
4 import com.fasterxml.jackson.databind.ObjectMapper;
5 import com.oransc.rappmanager.acm.ApiClient;
6 import com.oransc.rappmanager.acm.configuration.ACMConfiguration;
7 import com.oransc.rappmanager.acm.configuration.JacksonMessageConverterConfiguration;
8 import com.oransc.rappmanager.acm.rest.AutomationCompositionDefinitionApiClient;
9 import com.oransc.rappmanager.acm.rest.AutomationCompositionInstanceApiClient;
10 import com.oransc.rappmanager.acm.rest.ParticipantMonitoringApiClient;
11 import lombok.RequiredArgsConstructor;
12 import org.springframework.beans.factory.annotation.Qualifier;
13 import org.springframework.boot.test.context.TestConfiguration;
14 import org.springframework.boot.web.client.RestTemplateBuilder;
15 import org.springframework.cache.CacheManager;
16 import org.springframework.cache.concurrent.ConcurrentMapCacheManager;
17 import org.springframework.context.annotation.Bean;
18 import org.springframework.web.client.RestTemplate;
21 @RequiredArgsConstructor
22 public class BeanTestConfiguration {
24 private final ACMConfiguration acmConfiguration;
27 public ObjectMapper objectMapper() {
28 ObjectMapper objectMapper = new ObjectMapper();
29 objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
34 public RestTemplateBuilder restTemplateBuilder() {
35 return new RestTemplateBuilder();
39 public CacheManager cacheManager() {
40 return new ConcurrentMapCacheManager(); // or any other CacheManager implementation you want to use in the test
44 public RestTemplate restTemplate(RestTemplateBuilder builder, ObjectMapper objectMapper) {
45 RestTemplate restTemplate = builder.build();
46 restTemplate.getMessageConverters().add(new JacksonMessageConverterConfiguration(objectMapper));
51 public ApiClient acmApiClient(RestTemplate restTemplate) {
52 ApiClient apiClient = new ApiClient(restTemplate);
53 apiClient.setUsername(acmConfiguration.getUsername());
54 apiClient.setPassword(acmConfiguration.getPassword());
55 return apiClient.setBasePath(acmConfiguration.getBaseUrl());
59 public ParticipantMonitoringApiClient participantMonitoringApiClient(
60 @Qualifier("acmApiClient") ApiClient apiClient) {
61 return new ParticipantMonitoringApiClient(apiClient);
65 public AutomationCompositionDefinitionApiClient automationCompositionDefinitionApiClient(
66 @Qualifier("acmApiClient") ApiClient apiClient) {
67 return new AutomationCompositionDefinitionApiClient(apiClient);
71 public AutomationCompositionInstanceApiClient automationCompositionInstanceApiClient(
72 @Qualifier("acmApiClient") ApiClient apiClient) {
73 return new AutomationCompositionInstanceApiClient(apiClient);