Log configuration details to ease debugging
[portal/ric-dashboard.git] / webapp-backend / src / main / java / org / oransc / ric / portal / dashboard / config / E2ManagerMockConfiguration.java
1 /*-
2  * ========================LICENSE_START=================================
3  * ORAN-OSC
4  * %%
5  * Copyright (C) 2019 AT&T Intellectual Property and Nokia
6  * %%
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ========================LICENSE_END===================================
19  */
20 package org.oransc.ric.portal.dashboard.config;
21
22 import static org.mockito.ArgumentMatchers.any;
23 import static org.mockito.Mockito.doAnswer;
24 import static org.mockito.Mockito.mock;
25 import static org.mockito.Mockito.when;
26
27 import java.lang.invoke.MethodHandles;
28
29 import org.oransc.ric.e2mgr.client.api.EndcSetupRequestApi;
30 import org.oransc.ric.e2mgr.client.api.HealthCheckApi;
31 import org.oransc.ric.e2mgr.client.api.X2SetupRequestApi;
32 import org.oransc.ric.e2mgr.client.invoker.ApiClient;
33 import org.oransc.ric.e2mgr.client.model.SetupRequest;
34 import org.slf4j.Logger;
35 import org.slf4j.LoggerFactory;
36 import org.springframework.context.annotation.Bean;
37 import org.springframework.context.annotation.Configuration;
38 import org.springframework.context.annotation.Profile;
39 import org.springframework.http.HttpStatus;
40
41 /**
42  * Creates an implementation of the E2 manager client that answers requests with
43  * mock data.
44  */
45 @Profile("mock")
46 @Configuration
47 public class E2ManagerMockConfiguration {
48
49         private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
50
51         public E2ManagerMockConfiguration() {
52                 logger.info("Configuring mock E2 Manager");
53         }
54
55         private ApiClient apiClient() {
56                 ApiClient mockClient = mock(ApiClient.class);
57                 when(mockClient.getStatusCode()).thenReturn(HttpStatus.OK);
58                 return mockClient;
59         }
60
61         @Bean
62         public EndcSetupRequestApi endcSetupRequestApi() {
63                 ApiClient apiClient = apiClient();
64                 EndcSetupRequestApi mockApi = mock(EndcSetupRequestApi.class);
65                 when(mockApi.getApiClient()).thenReturn(apiClient);
66                 return mockApi;
67         }
68
69         @Bean
70         public HealthCheckApi healthCheckApi() {
71                 ApiClient apiClient = apiClient();
72                 HealthCheckApi mockApi = mock(HealthCheckApi.class);
73                 when(mockApi.getApiClient()).thenReturn(apiClient);
74                 doAnswer(i -> {
75                         return null;
76                 }).when(mockApi).healthCheck();
77                 return mockApi;
78         }
79
80         @Bean
81         public X2SetupRequestApi x2SetupRequestApi() {
82                 ApiClient apiClient = apiClient();
83                 X2SetupRequestApi mockApi = mock(X2SetupRequestApi.class);
84                 when(mockApi.getApiClient()).thenReturn(apiClient);
85                 doAnswer(i -> {
86                         return null;
87                 }).when(mockApi).setup(any(SetupRequest.class));
88                 return mockApi;
89         }
90
91 }