Add mock user data to backend
[portal/ric-dashboard.git] / webapp-backend / src / main / java / org / oransc / ric / portal / dashboard / config / XappManagerMockConfiguration.java
index 8698893..8c0ff14 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ========================LICENSE_START=================================
- * ORAN-OSC
+ * O-RAN-SC
  * %%
  * Copyright (C) 2019 AT&T Intellectual Property and Nokia
  * %%
@@ -26,14 +26,19 @@ import static org.mockito.Mockito.when;
 
 import java.lang.invoke.MethodHandles;
 
-import org.oransc.ric.xappmgr.client.api.DefaultApi;
+import org.oransc.ric.xappmgr.client.api.HealthApi;
+import org.oransc.ric.xappmgr.client.api.XappApi;
 import org.oransc.ric.xappmgr.client.invoker.ApiClient;
+import org.oransc.ric.xappmgr.client.model.AllXappConfig;
 import org.oransc.ric.xappmgr.client.model.AllXapps;
+import org.oransc.ric.xappmgr.client.model.ConfigMetadata;
 import org.oransc.ric.xappmgr.client.model.SubscriptionRequest;
 import org.oransc.ric.xappmgr.client.model.SubscriptionResponse;
+import org.oransc.ric.xappmgr.client.model.XAppConfig;
 import org.oransc.ric.xappmgr.client.model.XAppInfo;
 import org.oransc.ric.xappmgr.client.model.Xapp;
 import org.oransc.ric.xappmgr.client.model.Xapp.StatusEnum;
+import org.oransc.ric.xappmgr.client.model.XappInstance;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.context.annotation.Bean;
@@ -52,40 +57,65 @@ public class XappManagerMockConfiguration {
        private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
 
        private final AllXapps allXapps;
+       private final AllXappConfig allXappConfigs;
 
        public XappManagerMockConfiguration() {
                logger.info("Configuring mock xApp Manager");
+               final String[] appNames = { "AdmissionControl", "Automatic Neighbor Relation", "Dual Connectivity" };
+               final String configJson = " { \"config\" : \"example\" }";
+               final String descriptorJson = " { \"descriptor\" : \"example\" }";
+               allXappConfigs = new AllXappConfig();
                allXapps = new AllXapps();
-               allXapps.add(new Xapp().name("Pendulum Control").version("v1").status(StatusEnum.DEPLOYED));
-               allXapps.add(new Xapp().name("Dual Connectivity").version("v2").status(StatusEnum.DELETED));
-               allXapps.add(new Xapp().name("Admission Control").version("v3").status(StatusEnum.FAILED));
-               allXapps.add(new Xapp().name("ANR Control").version("v0").status(StatusEnum.SUPERSEDED));
+               for (String n : appNames) {
+                       ConfigMetadata metadata = new ConfigMetadata().configName("config-" + n).name(n).namespace("namespace");
+                       XAppConfig config = new XAppConfig().config(configJson).descriptor(descriptorJson).metadata(metadata);
+                       allXappConfigs.add(config);
+                       Xapp xapp = new Xapp().name(n).version("version").status(StatusEnum.UNKNOWN);
+                       xapp.addInstancesItem(new XappInstance().name("abcd-1234").ip("1.2.3.4").port(200)
+                                       .status(XappInstance.StatusEnum.RUNNING));
+                       allXapps.add(xapp);
+               }
        }
 
        @Bean
-       public DefaultApi xappManagerMockClient() {
+       // Use the same name as regular configuration
+       public HealthApi xappMgrHealthApi() {
                ApiClient mockClient = mock(ApiClient.class);
                when(mockClient.getStatusCode()).thenReturn(HttpStatus.OK);
+               HealthApi mockApi = mock(HealthApi.class);
+               when(mockApi.getApiClient()).thenReturn(mockClient);
+               doAnswer(i -> {
+                       return null;
+               }).when(mockApi).getHealthAlive();
+               doAnswer(i -> {
+                       return null;
+               }).when(mockApi).getHealthReady();
+               return mockApi;
+       }
 
-               DefaultApi mockApi = mock(DefaultApi.class);
+       @Bean
+       // Use the same name as regular configuration
+       public XappApi xappMgrXappApi() {
+               ApiClient mockClient = mock(ApiClient.class);
+               when(mockClient.getStatusCode()).thenReturn(HttpStatus.OK);
+
+               XappApi mockApi = mock(XappApi.class);
                when(mockApi.getApiClient()).thenReturn(mockClient);
 
-               SubscriptionResponse subRes = new SubscriptionResponse().eventType(SubscriptionResponse.EventTypeEnum.ALL)
-                               .id("subid").version(1);
-               when(mockApi.addSubscription(any(SubscriptionRequest.class))).thenReturn(subRes);
+               when(mockApi.getAllXappConfig()).thenReturn(allXappConfigs);
+
+               when(mockApi.createXappConfig(any(XAppConfig.class))).thenReturn(new XAppConfig());
+
+               when(mockApi.modifyXappConfig(any(XAppConfig.class))).thenReturn(new XAppConfig());
 
                doAnswer(i -> {
                        return null;
-               }).when(mockApi).deleteSubscription(any(Integer.class));
+               }).when(mockApi).deleteXappConfig(any(ConfigMetadata.class));
 
                when(mockApi.deployXapp(any(XAppInfo.class))).thenReturn(new Xapp());
 
                when(mockApi.getAllXapps()).thenReturn(allXapps);
 
-               doAnswer(i -> {
-                       return null;
-               }).when(mockApi).getHealth();
-
                Xapp xappByName = new Xapp().name("name").status(StatusEnum.UNKNOWN).version("v1");
                when(mockApi.getXappByName(any(String.class))).thenReturn(xappByName);
 
@@ -93,6 +123,14 @@ public class XappManagerMockConfiguration {
                        return null;
                }).when(mockApi).undeployXapp(any(String.class));
 
+               SubscriptionResponse subRes = new SubscriptionResponse().eventType(SubscriptionResponse.EventTypeEnum.ALL)
+                               .id("subid").version(1);
+               when(mockApi.addSubscription(any(SubscriptionRequest.class))).thenReturn(subRes);
+
+               doAnswer(i -> {
+                       return null;
+               }).when(mockApi).deleteSubscription(any(String.class));
+
                return mockApi;
        }