2 * ========================LICENSE_START=================================
5 * Copyright (C) 2019 AT&T Intellectual Property and Nokia
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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===================================
20 package org.oransc.ric.portal.dashboard.config;
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;
27 import java.lang.invoke.MethodHandles;
29 import org.oransc.ric.xappmgr.client.api.HealthApi;
30 import org.oransc.ric.xappmgr.client.api.XappApi;
31 import org.oransc.ric.xappmgr.client.invoker.ApiClient;
32 import org.oransc.ric.xappmgr.client.model.AllXapps;
33 import org.oransc.ric.xappmgr.client.model.SubscriptionRequest;
34 import org.oransc.ric.xappmgr.client.model.SubscriptionResponse;
35 import org.oransc.ric.xappmgr.client.model.XAppInfo;
36 import org.oransc.ric.xappmgr.client.model.Xapp;
37 import org.oransc.ric.xappmgr.client.model.Xapp.StatusEnum;
38 import org.oransc.ric.xappmgr.client.model.XappInstance;
39 import org.slf4j.Logger;
40 import org.slf4j.LoggerFactory;
41 import org.springframework.context.annotation.Bean;
42 import org.springframework.context.annotation.Configuration;
43 import org.springframework.context.annotation.Profile;
44 import org.springframework.http.HttpStatus;
47 * Creates an implementation of the xApp manager client that answers requests
52 public class XappManagerMockConfiguration {
54 private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
56 private final AllXapps allXapps;
58 public XappManagerMockConfiguration() {
59 logger.info("Configuring mock xApp Manager");
60 Xapp ac = new Xapp().name("Admission Control").version("v3").status(StatusEnum.FAILED);
62 new XappInstance().name("cdef-3456").ip("3.4.5.6").port(200).status(XappInstance.StatusEnum.RUNNING));
63 Xapp an = new Xapp().name("ANR Control").version("v0").status(StatusEnum.SUPERSEDED);
65 new XappInstance().name("fedc-8765").ip("8.7.6.5").port(400).status(XappInstance.StatusEnum.RUNNING));
66 Xapp dc = new Xapp().name("Dual Connectivity").version("v2").status(StatusEnum.DELETED);
68 new XappInstance().name("def0-6789").ip("6.7.8.9").port(300).status(XappInstance.StatusEnum.COMPLETED));
69 allXapps = new AllXapps();
76 public HealthApi xappHealthMockApi() {
77 ApiClient mockClient = mock(ApiClient.class);
78 when(mockClient.getStatusCode()).thenReturn(HttpStatus.OK);
79 HealthApi mockApi = mock(HealthApi.class);
80 when(mockApi.getApiClient()).thenReturn(mockClient);
83 }).when(mockApi).getHealth();
88 public XappApi xappMgrMockApi() {
89 ApiClient mockClient = mock(ApiClient.class);
90 when(mockClient.getStatusCode()).thenReturn(HttpStatus.OK);
92 XappApi mockApi = mock(XappApi.class);
93 when(mockApi.getApiClient()).thenReturn(mockClient);
95 SubscriptionResponse subRes = new SubscriptionResponse().eventType(SubscriptionResponse.EventTypeEnum.ALL)
96 .id("subid").version(1);
97 when(mockApi.addSubscription(any(SubscriptionRequest.class))).thenReturn(subRes);
101 }).when(mockApi).deleteSubscription(any(Integer.class));
103 when(mockApi.deployXapp(any(XAppInfo.class))).thenReturn(new Xapp());
105 when(mockApi.getAllXapps()).thenReturn(allXapps);
108 Xapp xappByName = new Xapp().name("name").status(StatusEnum.UNKNOWN).version("v1");
109 when(mockApi.getXappByName(any(String.class))).thenReturn(xappByName);
113 }).when(mockApi).undeployXapp(any(String.class));