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.AllXappConfig;
33 import org.oransc.ric.xappmgr.client.model.AllXapps;
34 import org.oransc.ric.xappmgr.client.model.ConfigMetadata;
35 import org.oransc.ric.xappmgr.client.model.SubscriptionRequest;
36 import org.oransc.ric.xappmgr.client.model.SubscriptionResponse;
37 import org.oransc.ric.xappmgr.client.model.XAppConfig;
38 import org.oransc.ric.xappmgr.client.model.XAppInfo;
39 import org.oransc.ric.xappmgr.client.model.Xapp;
40 import org.oransc.ric.xappmgr.client.model.Xapp.StatusEnum;
41 import org.oransc.ric.xappmgr.client.model.XappInstance;
42 import org.slf4j.Logger;
43 import org.slf4j.LoggerFactory;
44 import org.springframework.context.annotation.Bean;
45 import org.springframework.context.annotation.Configuration;
46 import org.springframework.context.annotation.Profile;
47 import org.springframework.http.HttpStatus;
50 * Creates an implementation of the xApp manager client that answers requests
55 public class XappManagerMockConfiguration {
57 private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
59 private final AllXapps allXapps;
60 private final AllXappConfig allXappConfigs;
62 public XappManagerMockConfiguration() {
63 logger.info("Configuring mock xApp Manager");
64 final String[] appNames = { "AdmissionControl", "Automatic Neighbor Relation", "Dual Connectivity" };
65 final String configJson = " { \"config\" : \"example\" }";
66 final String descriptorJson = " { \"descriptor\" : \"example\" }";
67 allXappConfigs = new AllXappConfig();
68 allXapps = new AllXapps();
69 for (String n : appNames) {
70 ConfigMetadata metadata = new ConfigMetadata().configName("config-" + n).name(n).namespace("namespace");
71 XAppConfig config = new XAppConfig().config(configJson).descriptor(descriptorJson).metadata(metadata);
72 allXappConfigs.add(config);
73 Xapp xapp = new Xapp().name(n).version("version").status(StatusEnum.UNKNOWN);
74 xapp.addInstancesItem(new XappInstance().name("abcd-1234").ip("1.2.3.4").port(200)
75 .status(XappInstance.StatusEnum.RUNNING));
81 // Use the same name as regular configuration
82 public HealthApi xappMgrHealthApi() {
83 ApiClient mockClient = mock(ApiClient.class);
84 when(mockClient.getStatusCode()).thenReturn(HttpStatus.OK);
85 HealthApi mockApi = mock(HealthApi.class);
86 when(mockApi.getApiClient()).thenReturn(mockClient);
89 }).when(mockApi).getHealthAlive();
92 }).when(mockApi).getHealthReady();
97 // Use the same name as regular configuration
98 public XappApi xappMgrXappApi() {
99 ApiClient mockClient = mock(ApiClient.class);
100 when(mockClient.getStatusCode()).thenReturn(HttpStatus.OK);
102 XappApi mockApi = mock(XappApi.class);
103 when(mockApi.getApiClient()).thenReturn(mockClient);
105 when(mockApi.getAllXappConfig()).thenReturn(allXappConfigs);
107 when(mockApi.createXappConfig(any(XAppConfig.class))).thenReturn(new XAppConfig());
109 when(mockApi.modifyXappConfig(any(XAppConfig.class))).thenReturn(new XAppConfig());
113 }).when(mockApi).deleteXappConfig(any(ConfigMetadata.class));
115 when(mockApi.deployXapp(any(XAppInfo.class))).thenReturn(new Xapp());
117 when(mockApi.getAllXapps()).thenReturn(allXapps);
119 Xapp xappByName = new Xapp().name("name").status(StatusEnum.UNKNOWN).version("v1");
120 when(mockApi.getXappByName(any(String.class))).thenReturn(xappByName);
124 }).when(mockApi).undeployXapp(any(String.class));
126 SubscriptionResponse subRes = new SubscriptionResponse().eventType(SubscriptionResponse.EventTypeEnum.ALL)
127 .id("subid").version(1);
128 when(mockApi.addSubscription(any(SubscriptionRequest.class))).thenReturn(subRes);
132 }).when(mockApi).deleteSubscription(any(String.class));