Add multi-layer RIC instance selector
[portal/ric-dashboard.git] / dashboard / webapp-backend / src / test / java / org / oransc / ric / portal / dashboard / config / RICInstanceMockConfiguration.java
1 /*-
2  * ========================LICENSE_START=================================
3  * O-RAN-SC
4  * %%
5  * Copyright (C) 2019 AT&T Intellectual Property
6  * %%
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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===================================
19  */
20
21 package org.oransc.ric.portal.dashboard.config;
22
23 import java.lang.invoke.MethodHandles;
24 import java.util.ArrayList;
25 import java.util.List;
26
27 import org.oransc.ric.portal.dashboard.model.RicInstance;
28 import org.oransc.ric.portal.dashboard.model.RicRegion;
29 import org.oransc.ric.portal.dashboard.model.RicRegionList;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
32 import org.springframework.context.annotation.Bean;
33 import org.springframework.context.annotation.Configuration;
34 import org.springframework.context.annotation.Profile;
35
36 /**
37  * Publishes a mock list of RIC instances.
38  */
39 @Configuration
40 @Profile("test")
41 public class RICInstanceMockConfiguration {
42
43         private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
44
45         // Publish constants for use in tests
46         public static final String REGION_NAME_1 = "Region AAA";
47         public static final String REGION_NAME_2 = "Region DDD";
48         public static final String INSTANCE_KEY_1 = "i1";
49         public static final String INSTANCE_KEY_2 = "i2";
50         public static final String[] INSTANCE_KEYS = { INSTANCE_KEY_1, INSTANCE_KEY_2 };
51
52         // No constructor needed, don't simulate delay from the Dashboard
53
54         @Bean
55         public RicRegionList ricRegions() {
56                 logger.debug("Creating mock bean ricRegions");
57                 List<RicRegion> regions = new ArrayList<>();
58                 RicRegion region1 = new RicRegion().name(REGION_NAME_1);
59                 regions.add(region1);
60                 List<RicInstance> instances1 = new ArrayList<>();
61                 region1.setInstances(instances1);
62                 String key1 = INSTANCE_KEY_1;
63                 instances1.add(new RicInstance().key(key1).name("RIC Instance " + key1) //
64                                 .appUrlPrefix("http://" + key1 + ".domain.name/app") //
65                                 .pltUrlPrefix("http://" + key1 + ".domain.name/plt") //
66                                 .caasUrlPrefix("http://" + key1 + ".domain.name/caas"));
67                 RicRegion region2 = new RicRegion().name(REGION_NAME_2);
68                 regions.add(region2);
69                 List<RicInstance> instances2 = new ArrayList<>();
70                 region2.setInstances(instances2);
71                 String key2 = INSTANCE_KEY_2;
72                 instances2.add(new RicInstance().key(key2).name("RIC Instance " + key2) //
73                                 .appUrlPrefix("http://" + key2 + ".domain.name/app") //
74                                 .pltUrlPrefix("http://" + key2 + ".domain.name/plt") //
75                                 .caasUrlPrefix("http://" + key2 + ".domain.name/caas"));
76                 return new RicRegionList(regions);
77         }
78
79 }