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
10 * http://www.apache.org/licenses/LICENSE-2.0
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========================================================================
20 package com.oransc.rappmanager.acm.service;
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;
41 @RequiredArgsConstructor
42 public class BeanTestConfiguration {
44 private final ACMConfiguration acmConfiguration;
47 public ObjectMapper objectMapper() {
48 ObjectMapper objectMapper = new ObjectMapper();
49 objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
59 public RestTemplateBuilder restTemplateBuilder() {
60 return new RestTemplateBuilder();
64 public CacheManager cacheManager() {
65 return new ConcurrentMapCacheManager(); // or any other CacheManager implementation you want to use in the test
69 public RestTemplate restTemplate(RestTemplateBuilder builder, ObjectMapper objectMapper) {
70 RestTemplate restTemplate = builder.build();
71 restTemplate.getMessageConverters().add(new JacksonMessageConverterConfiguration(objectMapper));
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());
84 public ParticipantMonitoringApiClient participantMonitoringApiClient(
85 @Qualifier("acmApiClient") ApiClient apiClient) {
86 return new ParticipantMonitoringApiClient(apiClient);
90 public AutomationCompositionDefinitionApiClient automationCompositionDefinitionApiClient(
91 @Qualifier("acmApiClient") ApiClient apiClient) {
92 return new AutomationCompositionDefinitionApiClient(apiClient);
96 public AutomationCompositionInstanceApiClient automationCompositionInstanceApiClient(
97 @Qualifier("acmApiClient") ApiClient apiClient) {
98 return new AutomationCompositionInstanceApiClient(apiClient);