Add ACM interceptor for DME
[nonrtric/plt/rappmanager.git] / rapp-manager-acm / src / test / java / com / oransc / rappmanager / acm / service / BeanTestConfiguration.java
1 /*-
2  * ============LICENSE_START======================================================================
3  * Copyright (C) 2023 Nordix Foundation. All rights reserved.
4  * Copyright (C) 2023 OpenInfra Foundation Europe. All rights reserved.
5  * ===============================================================================================
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  * ============LICENSE_END========================================================================
18  */
19
20 package com.oransc.rappmanager.acm.service;
21
22 import com.fasterxml.jackson.databind.DeserializationFeature;
23 import com.fasterxml.jackson.databind.ObjectMapper;
24 import com.google.gson.Gson;
25 import com.oransc.rappmanager.acm.ApiClient;
26 import com.oransc.rappmanager.acm.configuration.ACMConfiguration;
27 import com.oransc.rappmanager.acm.configuration.JacksonMessageConverterConfiguration;
28 import com.oransc.rappmanager.acm.rest.AutomationCompositionDefinitionApiClient;
29 import com.oransc.rappmanager.acm.rest.AutomationCompositionInstanceApiClient;
30 import com.oransc.rappmanager.acm.rest.ParticipantMonitoringApiClient;
31 import lombok.RequiredArgsConstructor;
32 import org.springframework.beans.factory.annotation.Qualifier;
33 import org.springframework.boot.test.context.TestConfiguration;
34 import org.springframework.boot.web.client.RestTemplateBuilder;
35 import org.springframework.cache.CacheManager;
36 import org.springframework.cache.concurrent.ConcurrentMapCacheManager;
37 import org.springframework.context.annotation.Bean;
38 import org.springframework.web.client.RestTemplate;
39
40 @TestConfiguration
41 @RequiredArgsConstructor
42 public class BeanTestConfiguration {
43
44     private final ACMConfiguration acmConfiguration;
45
46     @Bean
47     public ObjectMapper objectMapper() {
48         ObjectMapper objectMapper = new ObjectMapper();
49         objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
50         return objectMapper;
51     }
52
53     @Bean
54     public Gson gson() {
55         return new Gson();
56     }
57
58     @Bean
59     public RestTemplateBuilder restTemplateBuilder() {
60         return new RestTemplateBuilder();
61     }
62
63     @Bean
64     public CacheManager cacheManager() {
65         return new ConcurrentMapCacheManager(); // or any other CacheManager implementation you want to use in the test
66     }
67
68     @Bean
69     public RestTemplate restTemplate(RestTemplateBuilder builder, ObjectMapper objectMapper) {
70         RestTemplate restTemplate = builder.build();
71         restTemplate.getMessageConverters().add(new JacksonMessageConverterConfiguration(objectMapper));
72         return restTemplate;
73     }
74
75     @Bean("acmApiClient")
76     public ApiClient acmApiClient(RestTemplate restTemplate) {
77         ApiClient apiClient = new ApiClient(restTemplate);
78         apiClient.setUsername(acmConfiguration.getUsername());
79         apiClient.setPassword(acmConfiguration.getPassword());
80         return apiClient.setBasePath(acmConfiguration.getBaseUrl());
81     }
82
83     @Bean
84     public ParticipantMonitoringApiClient participantMonitoringApiClient(
85             @Qualifier("acmApiClient") ApiClient apiClient) {
86         return new ParticipantMonitoringApiClient(apiClient);
87     }
88
89     @Bean
90     public AutomationCompositionDefinitionApiClient automationCompositionDefinitionApiClient(
91             @Qualifier("acmApiClient") ApiClient apiClient) {
92         return new AutomationCompositionDefinitionApiClient(apiClient);
93     }
94
95     @Bean
96     public AutomationCompositionInstanceApiClient automationCompositionInstanceApiClient(
97             @Qualifier("acmApiClient") ApiClient apiClient) {
98         return new AutomationCompositionInstanceApiClient(apiClient);
99     }
100
101
102 }