Add multi-layer RIC instance selector
[portal/ric-dashboard.git] / dashboard / webapp-backend / src / test / java / org / oransc / ric / portal / dashboard / controller / A1MediatorControllerTest.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 package org.oransc.ric.portal.dashboard.controller;
21
22 import java.io.IOException;
23 import java.lang.invoke.MethodHandles;
24 import java.net.URI;
25 import java.util.List;
26
27 import org.junit.Assert;
28 import org.junit.jupiter.api.Assertions;
29 import org.junit.jupiter.api.Test;
30 import org.oransc.ric.a1med.client.model.PolicyTypeSchema;
31 import org.oransc.ric.portal.dashboard.DashboardConstants;
32 import org.oransc.ric.portal.dashboard.config.A1MediatorMockConfiguration;
33 import org.oransc.ric.portal.dashboard.config.RICInstanceMockConfiguration;
34 import org.oransc.ric.portal.dashboard.model.SuccessTransport;
35 import org.slf4j.Logger;
36 import org.slf4j.LoggerFactory;
37 import org.springframework.core.ParameterizedTypeReference;
38 import org.springframework.http.HttpEntity;
39 import org.springframework.http.HttpMethod;
40 import org.springframework.http.ResponseEntity;
41
42 import com.fasterxml.jackson.databind.JsonNode;
43 import com.fasterxml.jackson.databind.ObjectMapper;
44
45 public class A1MediatorControllerTest extends AbstractControllerTest {
46
47         private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
48
49         @Test
50         public void versionTest() {
51                 URI uri = buildUri(null, A1MediatorController.CONTROLLER_PATH, DashboardConstants.VERSION_METHOD);
52                 logger.info("Invoking {}", uri);
53                 SuccessTransport st = restTemplate.getForObject(uri, SuccessTransport.class);
54                 Assertions.assertFalse(st.getData().toString().isEmpty());
55         }
56
57         @Test
58         public void getTypeIdsTest() throws IOException {
59                 URI uri = buildUri(null, A1MediatorController.CONTROLLER_PATH, DashboardConstants.RIC_INSTANCE_KEY,
60                                 RICInstanceMockConfiguration.INSTANCE_KEY_1, A1MediatorController.PP_TYPE_ID);
61                 logger.info("Invoking {}", uri);
62                 ResponseEntity<List<Integer>> response = testRestTemplateStandardRole().exchange(uri, HttpMethod.GET, null,
63                                 new ParameterizedTypeReference<List<Integer>>() {
64                                 });
65                 Assertions.assertTrue(response.getStatusCode().is2xxSuccessful());
66                 Assert.assertFalse(response.getBody().isEmpty());
67         }
68
69         @Test
70         public void getPolicyTypeTest() throws IOException {
71                 URI uri = buildUri(null, A1MediatorController.CONTROLLER_PATH, DashboardConstants.RIC_INSTANCE_KEY,
72                                 RICInstanceMockConfiguration.INSTANCE_KEY_1, A1MediatorController.PP_TYPE_ID,
73                                 Integer.toString(A1MediatorMockConfiguration.ADMISSION_CONTROL_POLICY_ID));
74                 logger.info("Invoking {}", uri);
75                 ResponseEntity<PolicyTypeSchema> response = testRestTemplateStandardRole().exchange(uri, HttpMethod.GET, null,
76                                 PolicyTypeSchema.class);
77                 Assertions.assertTrue(response.getStatusCode().is2xxSuccessful());
78                 Assert.assertFalse(response.getBody().getName().isEmpty());
79         }
80
81         @Test
82         public void getInstanceTest() throws IOException {
83                 URI uri = buildUri(null, A1MediatorController.CONTROLLER_PATH, DashboardConstants.RIC_INSTANCE_KEY,
84                                 RICInstanceMockConfiguration.INSTANCE_KEY_1, A1MediatorController.PP_TYPE_ID,
85                                 Integer.toString(A1MediatorMockConfiguration.ADMISSION_CONTROL_POLICY_ID),
86                                 A1MediatorController.PP_INST_ID, A1MediatorMockConfiguration.AC_CONTROL_NAME);
87                 logger.info("Invoking {}", uri);
88                 ResponseEntity<String> response = testRestTemplateStandardRole().exchange(uri, HttpMethod.GET, null,
89                                 String.class);
90                 Assertions.assertTrue(response.getStatusCode().is2xxSuccessful());
91                 Assert.assertFalse(response.getBody().isEmpty());
92         }
93
94         @Test
95         public void putInstanceTest() throws IOException {
96                 URI uri = buildUri(null, A1MediatorController.CONTROLLER_PATH, DashboardConstants.RIC_INSTANCE_KEY,
97                                 RICInstanceMockConfiguration.INSTANCE_KEY_1, A1MediatorController.PP_TYPE_ID,
98                                 Integer.toString(A1MediatorMockConfiguration.ADMISSION_CONTROL_POLICY_ID),
99                                 A1MediatorController.PP_INST_ID, A1MediatorMockConfiguration.AC_CONTROL_NAME);
100                 ObjectMapper mapper = new ObjectMapper();
101                 JsonNode body = mapper.readTree("{ \"policy\" : true }");
102                 HttpEntity<JsonNode> entity = new HttpEntity<>(body);
103                 logger.info("Invoking {} with body {}", uri, body);
104                 ResponseEntity<Void> voidResponse = testRestTemplateAdminRole().exchange(uri, HttpMethod.PUT, entity,
105                                 Void.class);
106                 Assertions.assertTrue(voidResponse.getStatusCode().is2xxSuccessful());
107         }
108
109 }