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.oransc.ric.xappmgr.client.model.XappInstance;
38 import org.slf4j.Logger;
39 import org.slf4j.LoggerFactory;
40 import org.springframework.context.annotation.Bean;
41 import org.springframework.context.annotation.Configuration;
42 import org.springframework.context.annotation.Profile;
43 import org.springframework.http.HttpStatus;
46 * Creates an implementation of the xApp manager client that answers requests
51 public class XappManagerMockConfiguration {
53 private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
55 private final AllXapps allXapps;
57 public XappManagerMockConfiguration() {
58 logger.info("Configuring mock xApp Manager");
59 Xapp ac = new Xapp().name("Admission Control").version("v3").status(StatusEnum.FAILED);
60 ac.addInstancesItem(new XappInstance().name("cdef-3456").ip("3.4.5.6").port(200).status(XappInstance.StatusEnum.RUNNING));
61 Xapp an = new Xapp().name("ANR Control").version("v0").status(StatusEnum.SUPERSEDED);
62 an.addInstancesItem(new XappInstance().name("fedc-8765").ip("8.7.6.5").port(400).status(XappInstance.StatusEnum.RUNNING));
63 Xapp dc = new Xapp().name("Dual Connectivity").version("v2").status(StatusEnum.DELETED);
64 dc.addInstancesItem(new XappInstance().name("def0-6789").ip("6.7.8.9").port(300).status(XappInstance.StatusEnum.COMPLETED));
65 Xapp pc = new Xapp().name("Pendulum Control").version("v1").status(StatusEnum.DEPLOYED);
66 pc.addInstancesItem(new XappInstance().name("abcd-1234").ip("1.2.3.4").port(100).status(XappInstance.StatusEnum.RUNNING));
67 allXapps = new AllXapps();
75 public DefaultApi xappManagerMockClient() {
76 ApiClient mockClient = mock(ApiClient.class);
77 when(mockClient.getStatusCode()).thenReturn(HttpStatus.OK);
79 DefaultApi mockApi = mock(DefaultApi.class);
80 when(mockApi.getApiClient()).thenReturn(mockClient);
82 SubscriptionResponse subRes = new SubscriptionResponse().eventType(SubscriptionResponse.EventTypeEnum.ALL)
83 .id("subid").version(1);
84 when(mockApi.addSubscription(any(SubscriptionRequest.class))).thenReturn(subRes);
88 }).when(mockApi).deleteSubscription(any(Integer.class));
90 when(mockApi.deployXapp(any(XAppInfo.class))).thenReturn(new Xapp());
92 when(mockApi.getAllXapps()).thenReturn(allXapps);
96 }).when(mockApi).getHealth();
98 Xapp xappByName = new Xapp().name("name").status(StatusEnum.UNKNOWN).version("v1");
99 when(mockApi.getXappByName(any(String.class))).thenReturn(xappByName);
103 }).when(mockApi).undeployXapp(any(String.class));