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.oranosc.ric.portal.dash.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 org.oranosc.ric.xappmgr.client.api.DefaultApi;
28 import org.oranosc.ric.xappmgr.client.invoker.ApiClient;
29 import org.oranosc.ric.xappmgr.client.model.AllXapps;
30 import org.oranosc.ric.xappmgr.client.model.SubscriptionRequest;
31 import org.oranosc.ric.xappmgr.client.model.SubscriptionResponse;
32 import org.oranosc.ric.xappmgr.client.model.XAppInfo;
33 import org.oranosc.ric.xappmgr.client.model.Xapp;
34 import org.oranosc.ric.xappmgr.client.model.Xapp.StatusEnum;
35 import org.springframework.context.annotation.Bean;
36 import org.springframework.context.annotation.Configuration;
37 import org.springframework.context.annotation.Primary;
38 import org.springframework.context.annotation.Profile;
39 import org.springframework.http.HttpStatus;
42 * Creates an implementation of the xApp manager client that answers requests
47 public class XappManagerMockConfiguration {
49 private final AllXapps allXapps;
51 public XappManagerMockConfiguration() {
52 allXapps = new AllXapps();
53 allXapps.add(new Xapp().name("Pendulum Control").version("v1").status(StatusEnum.DEPLOYED));
54 allXapps.add(new Xapp().name("Dual Connectivity").version("v2").status(StatusEnum.DELETED));
55 allXapps.add(new Xapp().name("Admission Control").version("v3").status(StatusEnum.FAILED));
56 allXapps.add(new Xapp().name("ANR Control").version("v0").status(StatusEnum.SUPERSEDED));
61 public DefaultApi xappManagerMockClient() {
62 ApiClient mockClient = mock(ApiClient.class);
63 when(mockClient.getStatusCode()).thenReturn(HttpStatus.OK);
65 DefaultApi mockApi = mock(DefaultApi.class);
66 when(mockApi.getApiClient()).thenReturn(mockClient);
68 SubscriptionResponse subRes = new SubscriptionResponse().eventType(SubscriptionResponse.EventTypeEnum.ALL)
69 .id("subid").version(1);
70 when(mockApi.addSubscription(any(SubscriptionRequest.class))).thenReturn(subRes);
74 }).when(mockApi).deleteSubscription(any(Integer.class));
76 when(mockApi.deployXapp(any(XAppInfo.class))).thenReturn(new Xapp());
78 when(mockApi.getAllXapps()).thenReturn(allXapps);
82 }).when(mockApi).getHealth();
84 Xapp xappByName = new Xapp().name("name").status(StatusEnum.UNKNOWN).version("v1");
85 when(mockApi.getXappByName(any(String.class))).thenReturn(xappByName);
89 }).when(mockApi).undeployXapp(any(String.class));