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.DefaultApi;
30 import org.oransc.ric.xappmgr.client.invoker.ApiClient;
31 import org.oransc.ric.xappmgr.client.model.AllXapps;
32 import org.oransc.ric.xappmgr.client.model.SubscriptionRequest;
33 import org.oransc.ric.xappmgr.client.model.SubscriptionResponse;
34 import org.oransc.ric.xappmgr.client.model.XAppInfo;
35 import org.oransc.ric.xappmgr.client.model.Xapp;
36 import org.oransc.ric.xappmgr.client.model.Xapp.StatusEnum;
37 import org.slf4j.Logger;
38 import org.slf4j.LoggerFactory;
39 import org.springframework.context.annotation.Bean;
40 import org.springframework.context.annotation.Configuration;
41 import org.springframework.context.annotation.Profile;
42 import org.springframework.http.HttpStatus;
45 * Creates an implementation of the xApp manager client that answers requests
50 public class XappManagerMockConfiguration {
52 private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
54 private final AllXapps allXapps;
56 public XappManagerMockConfiguration() {
57 logger.info("Configuring mock xApp Manager");
58 allXapps = new AllXapps();
59 allXapps.add(new Xapp().name("Pendulum Control").version("v1").status(StatusEnum.DEPLOYED));
60 allXapps.add(new Xapp().name("Dual Connectivity").version("v2").status(StatusEnum.DELETED));
61 allXapps.add(new Xapp().name("Admission Control").version("v3").status(StatusEnum.FAILED));
62 allXapps.add(new Xapp().name("ANR Control").version("v0").status(StatusEnum.SUPERSEDED));
66 public DefaultApi xappManagerMockClient() {
67 ApiClient mockClient = mock(ApiClient.class);
68 when(mockClient.getStatusCode()).thenReturn(HttpStatus.OK);
70 DefaultApi mockApi = mock(DefaultApi.class);
71 when(mockApi.getApiClient()).thenReturn(mockClient);
73 SubscriptionResponse subRes = new SubscriptionResponse().eventType(SubscriptionResponse.EventTypeEnum.ALL)
74 .id("subid").version(1);
75 when(mockApi.addSubscription(any(SubscriptionRequest.class))).thenReturn(subRes);
79 }).when(mockApi).deleteSubscription(any(Integer.class));
81 when(mockApi.deployXapp(any(XAppInfo.class))).thenReturn(new Xapp());
83 when(mockApi.getAllXapps()).thenReturn(allXapps);
87 }).when(mockApi).getHealth();
89 Xapp xappByName = new Xapp().name("name").status(StatusEnum.UNKNOWN).version("v1");
90 when(mockApi.getXappByName(any(String.class))).thenReturn(xappByName);
94 }).when(mockApi).undeployXapp(any(String.class));