400397c439346a01d24e812682c0a2ffa06bc92e
[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.E2ManagerApi;
30 import org.oransc.ric.e2mgr.client.invoker.ApiClient;
31 import org.oransc.ric.e2mgr.client.model.SetupRequest;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
34 import org.springframework.context.annotation.Bean;
35 import org.springframework.context.annotation.Configuration;
36 import org.springframework.context.annotation.Profile;
37 import org.springframework.http.HttpStatus;
38
39 /**
40  * Creates a mock implementation of the E2 manager client API. This version
41  * answers only status codes, no data, so the mock implementations are trivial.
42  */
43 @Profile("mock")
44 @Configuration
45 public class E2ManagerMockConfiguration {
46
47         private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
48
49         public E2ManagerMockConfiguration() {
50                 logger.info("Configuring mock E2 Manager");
51         }
52
53         private ApiClient apiClient() {
54                 ApiClient mockClient = mock(ApiClient.class);
55                 when(mockClient.getStatusCode()).thenReturn(HttpStatus.OK);
56                 return mockClient;
57         }
58
59         @Bean
60         public E2ManagerApi e2ManagerApi() {
61                 ApiClient apiClient = apiClient();
62                 E2ManagerApi mockApi = mock(E2ManagerApi.class);
63                 when(mockApi.getApiClient()).thenReturn(apiClient);
64
65                 doAnswer(i -> {
66                         return null;
67                 }).when(mockApi).healthCheck();
68
69                 doAnswer(i -> {
70                         return null;
71                 }).when(mockApi).endcSetup(any(SetupRequest.class));
72
73                 doAnswer(i -> {
74                         return null;
75                 }).when(mockApi).setup(any(SetupRequest.class));
76
77                 return mockApi;
78         }
79
80 }