Add Rapp Instances
[nonrtric/plt/rappmanager.git] / rapp-manager-acm / src / test / java / com / oransc / rappmanager / acm / service / BeanTestConfiguration.java
1 package com.oransc.rappmanager.acm.service;
2
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.rest.AutomationCompositionDefinitionApiClient;
8 import com.oransc.rappmanager.acm.rest.AutomationCompositionInstanceApiClient;
9 import com.oransc.rappmanager.acm.rest.ParticipantMonitoringApiClient;
10 import lombok.RequiredArgsConstructor;
11 import org.springframework.beans.factory.annotation.Qualifier;
12 import org.springframework.boot.test.context.TestConfiguration;
13 import org.springframework.boot.web.client.RestTemplateBuilder;
14 import org.springframework.cache.CacheManager;
15 import org.springframework.cache.concurrent.ConcurrentMapCacheManager;
16 import org.springframework.context.annotation.Bean;
17 import org.springframework.web.client.RestTemplate;
18
19 @TestConfiguration
20 @RequiredArgsConstructor
21 public class BeanTestConfiguration {
22
23     private final ACMConfiguration acmConfiguration;
24
25     @Bean
26     public ObjectMapper objectMapper() {
27         ObjectMapper objectMapper = new ObjectMapper();
28         objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
29         return objectMapper;
30     }
31
32     @Bean
33     public RestTemplateBuilder restTemplateBuilder() {
34         return new RestTemplateBuilder();
35     }
36
37     @Bean
38     public CacheManager cacheManager() {
39         return new ConcurrentMapCacheManager(); // or any other CacheManager implementation you want to use in the test
40     }
41
42     @Bean
43     public RestTemplate restTemplate(RestTemplateBuilder builder) {
44         return builder.build();
45     }
46
47     @Bean("acmApiClient")
48     public ApiClient acmApiClient(RestTemplate restTemplate) {
49         ApiClient apiClient = new ApiClient(restTemplate);
50         apiClient.setUsername(acmConfiguration.getUsername());
51         apiClient.setPassword(acmConfiguration.getPassword());
52         return apiClient.setBasePath(acmConfiguration.getBaseUrl());
53     }
54
55     @Bean
56     public ParticipantMonitoringApiClient participantMonitoringApiClient(
57             @Qualifier("acmApiClient") ApiClient apiClient) {
58         return new ParticipantMonitoringApiClient(apiClient);
59     }
60
61     @Bean
62     public AutomationCompositionDefinitionApiClient automationCompositionDefinitionApiClient(
63             @Qualifier("acmApiClient") ApiClient apiClient) {
64         return new AutomationCompositionDefinitionApiClient(apiClient);
65     }
66
67     @Bean
68     public AutomationCompositionInstanceApiClient automationCompositionInstanceApiClient(
69             @Qualifier("acmApiClient") ApiClient apiClient) {
70         return new AutomationCompositionInstanceApiClient(apiClient);
71     }
72
73
74 }