4b1158efd5ed34e59ab6fcfb7475e805aa534df2
[portal/ric-dashboard.git] / 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.RicInstanceList;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
31 import org.springframework.beans.factory.annotation.Autowired;
32 import org.springframework.beans.factory.annotation.Value;
33 import org.springframework.context.annotation.Bean;
34 import org.springframework.context.annotation.Profile;
35 import org.springframework.stereotype.Component;
36
37 /**
38  * Publishes a mock list of RIC instances.
39  */
40 @Component
41 @Profile("test")
42 public class RICInstanceMockConfiguration {
43
44         private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
45
46         // Publish constants for use in tests
47         public static final String INSTANCE_KEY_1 = "i1";
48         public static final String INSTANCE_KEY_2 = "i2";
49         public static final String[] INSTANCE_KEYS = { INSTANCE_KEY_1, INSTANCE_KEY_2 };
50
51         // Simulate remote method delay for UI testing
52         private int delayMs;
53
54         @Autowired
55         public RICInstanceMockConfiguration(@Value("${mock.config.delay:0}") int delayMs) {
56                 logger.debug("ctor: configured with delay {}", delayMs);
57                 this.delayMs = delayMs;
58         }
59
60         @Bean
61         public RicInstanceList ricInstanceList() throws InterruptedException {
62                 if (delayMs > 0) {
63                         logger.debug("ricInstanceList sleeping {}", delayMs);
64                         Thread.sleep(delayMs);
65                 }
66                 List<RicInstance> instances = new ArrayList<>();
67                 for (String key : INSTANCE_KEYS) {
68                         RicInstance i = new RicInstance().key(key).name("RIC Instance " + key)
69                                         .appUrlPrefix("http://" + key + ".domain.name/app")
70                                         .pltUrlPrefix("http://" + key + ".domain.name/plt")
71                                         .caasUrlPrefix("http://" + key + ".domain.name/caas");
72                         instances.add(i);
73                 }
74                 return new RicInstanceList(instances);
75         }
76
77 }