2 * ============LICENSE_START======================================================================
3 * Copyright (C) 2023 OpenInfra Foundation Europe. All rights reserved.
4 * ===============================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 * ============LICENSE_END========================================================================
19 package com.oransc.rappmanager.sme.service;
21 import com.fasterxml.jackson.databind.DeserializationFeature;
22 import com.fasterxml.jackson.databind.ObjectMapper;
23 import com.oransc.rappmanager.sme.configuration.SmeConfiguration;
24 import com.oransc.rappmanager.sme.provider.rest.DefaultApiClient;
25 import lombok.RequiredArgsConstructor;
26 import org.springframework.beans.factory.annotation.Qualifier;
27 import org.springframework.boot.test.context.TestConfiguration;
28 import org.springframework.boot.web.client.RestTemplateBuilder;
29 import org.springframework.cache.CacheManager;
30 import org.springframework.cache.concurrent.ConcurrentMapCacheManager;
31 import org.springframework.context.annotation.Bean;
32 import org.springframework.web.client.RestTemplate;
35 @RequiredArgsConstructor
36 public class BeanTestConfiguration {
38 private final SmeConfiguration smeConfiguration;
41 public ObjectMapper objectMapper() {
42 ObjectMapper objectMapper = new ObjectMapper();
43 objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
48 public RestTemplateBuilder restTemplateBuilder() {
49 return new RestTemplateBuilder();
53 public CacheManager cacheManager() {
54 return new ConcurrentMapCacheManager(); // or any other CacheManager implementation you want to use in the test
58 public RestTemplate restTemplate(RestTemplateBuilder builder) {
59 return builder.build();
62 @Bean("smeProviderApiClient")
63 public com.oransc.rappmanager.sme.provider.ApiClient smeProviderApiClient(RestTemplate restTemplate) {
64 return new com.oransc.rappmanager.sme.provider.ApiClient(restTemplate);
67 @Bean("smePublishServiceApiClient")
68 public com.oransc.rappmanager.sme.publishservice.ApiClient smePublishServiceApiClient(RestTemplate restTemplate) {
69 return new com.oransc.rappmanager.sme.publishservice.ApiClient(restTemplate);
72 @Bean("smeInvokerApiClient")
73 public com.oransc.rappmanager.sme.invoker.ApiClient smeInvokerApiClient(RestTemplate restTemplate) {
74 return new com.oransc.rappmanager.sme.invoker.ApiClient(restTemplate);
78 public DefaultApiClient defaultProviderApiClient(
79 @Qualifier("smeProviderApiClient") com.oransc.rappmanager.sme.provider.ApiClient apiClient) {
80 apiClient.setBasePath(smeConfiguration.getBaseUrl() + smeConfiguration.getProviderBasePath());
81 return new DefaultApiClient(apiClient);
85 public com.oransc.rappmanager.sme.publishservice.rest.DefaultApiClient defaultPublishServiceApiClient(
86 @Qualifier("smePublishServiceApiClient") com.oransc.rappmanager.sme.publishservice.ApiClient apiClient) {
87 apiClient.setBasePath(smeConfiguration.getBaseUrl() + smeConfiguration.getPublishApiBasePath());
88 return new com.oransc.rappmanager.sme.publishservice.rest.DefaultApiClient(apiClient);
92 public com.oransc.rappmanager.sme.invoker.rest.DefaultApiClient defaultInvokerApiClient(
93 @Qualifier("smeInvokerApiClient") com.oransc.rappmanager.sme.invoker.ApiClient apiClient) {
94 apiClient.setBasePath(smeConfiguration.getBaseUrl() + smeConfiguration.getInvokerBasePath());
95 return new com.oransc.rappmanager.sme.invoker.rest.DefaultApiClient(apiClient);