Fix sample rapp generator to support helm artifact alone rApps
[nonrtric/plt/rappmanager.git] / rapp-manager-sme / src / test / java / com / oransc / rappmanager / sme / service / BeanTestConfiguration.java
1 /*
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
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
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========================================================================
17  */
18
19 package com.oransc.rappmanager.sme.service;
20
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;
33
34 @TestConfiguration
35 @RequiredArgsConstructor
36 public class BeanTestConfiguration {
37
38     private final SmeConfiguration smeConfiguration;
39
40     @Bean
41     public ObjectMapper objectMapper() {
42         ObjectMapper objectMapper = new ObjectMapper();
43         objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
44         return objectMapper;
45     }
46
47     @Bean
48     public RestTemplateBuilder restTemplateBuilder() {
49         return new RestTemplateBuilder();
50     }
51
52     @Bean
53     public CacheManager cacheManager() {
54         return new ConcurrentMapCacheManager(); // or any other CacheManager implementation you want to use in the test
55     }
56
57     @Bean
58     public RestTemplate restTemplate(RestTemplateBuilder builder) {
59         return builder.build();
60     }
61
62     @Bean("smeProviderApiClient")
63     public com.oransc.rappmanager.sme.provider.ApiClient smeProviderApiClient(RestTemplate restTemplate) {
64         return new com.oransc.rappmanager.sme.provider.ApiClient(restTemplate);
65     }
66
67     @Bean("smePublishServiceApiClient")
68     public com.oransc.rappmanager.sme.publishservice.ApiClient smePublishServiceApiClient(RestTemplate restTemplate) {
69         return new com.oransc.rappmanager.sme.publishservice.ApiClient(restTemplate);
70     }
71
72     @Bean("smeInvokerApiClient")
73     public com.oransc.rappmanager.sme.invoker.ApiClient smeInvokerApiClient(RestTemplate restTemplate) {
74         return new com.oransc.rappmanager.sme.invoker.ApiClient(restTemplate);
75     }
76
77     @Bean
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);
82     }
83
84     @Bean
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);
89     }
90
91     @Bean
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);
96     }
97 }