b05d817495c062067bb39260877128b71b02f133
[portal/ric-dashboard.git] / webapp-backend / src / main / java / org / oransc / ric / portal / dashboard / config / E2ManagerMockConfiguration.java
1 /*-
2  * ========================LICENSE_START=================================
3  * O-RAN-SC
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.HealthCheckApi;
30 import org.oransc.ric.e2mgr.client.api.NodebApi;
31 import org.oransc.ric.e2mgr.client.invoker.ApiClient;
32 import org.oransc.ric.e2mgr.client.model.GetNodebResponse;
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 a mock implementation of the E2 manager client API. This version
43  * answers only status codes, no data, so the mock implementations are trivial.
44  */
45 @Profile("mock")
46 @Configuration
47 public class E2ManagerMockConfiguration {
48
49         private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
50
51         private final GetNodebResponse nodebResponse;
52         
53         public E2ManagerMockConfiguration() {
54                 logger.info("Configuring mock E2 Manager");
55                 nodebResponse = new GetNodebResponse().ip("1.2.3.4").port(123).ranName("myRan");
56         }
57
58         private ApiClient apiClient() {
59                 ApiClient mockClient = mock(ApiClient.class);
60                 when(mockClient.getStatusCode()).thenReturn(HttpStatus.OK);
61                 return mockClient;
62         }
63
64         @Bean
65         public HealthCheckApi e2HealthCheckApi() {
66                 ApiClient apiClient = apiClient();
67                 HealthCheckApi mockApi = mock(HealthCheckApi.class);
68                 when(mockApi.getApiClient()).thenReturn(apiClient);
69
70                 doAnswer(i -> {
71                         return null;
72                 }).when(mockApi).healthGet();
73
74                 return mockApi;
75         }
76
77         @Bean
78         public NodebApi e2NodebApi() {
79                 ApiClient apiClient = apiClient();
80                 NodebApi mockApi = mock(NodebApi.class);
81                 when(mockApi.getApiClient()).thenReturn(apiClient);
82
83                 doAnswer(i -> {
84                         return nodebResponse;
85                 }).when(mockApi).getNb(any(String.class));
86
87                 doAnswer(i -> {
88                         return null;
89                 }).when(mockApi).endcSetup(any(SetupRequest.class));
90
91                 doAnswer(i -> {
92                         return null;
93                 }).when(mockApi).x2Setup(any(SetupRequest.class));
94
95                 return mockApi;
96         }
97
98 }