701bc39bd04c1efd7daf8c2f52c387879e89079d
[usecase-ui/server.git] /
1
2 /**
3  * Copyright 2025 Deutsche Telekom.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17
18 package org.onap.usecaseui.server.service.nsmf.impl;
19
20 import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
21 import static com.github.tomakehurst.wiremock.client.WireMock.equalTo;
22 import static com.github.tomakehurst.wiremock.client.WireMock.get;
23 import static com.github.tomakehurst.wiremock.client.WireMock.post;
24 import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
25 import static org.junit.Assert.assertEquals;
26 import static org.junit.Assert.assertNotNull;
27
28 import java.util.Collections;
29 import java.util.List;
30
31 import org.junit.jupiter.api.Test;
32 import org.onap.usecaseui.server.bean.nsmf.common.ServiceResult;
33 import org.onap.usecaseui.server.bean.nsmf.monitor.ServiceInfo;
34 import org.onap.usecaseui.server.bean.nsmf.monitor.ServiceList;
35 import org.onap.usecaseui.server.bean.nsmf.monitor.ServiceOnlineUserInfo;
36 import org.onap.usecaseui.server.bean.nsmf.monitor.ServiceOnlineUserList;
37 import org.onap.usecaseui.server.config.AAIClientConfig;
38 import org.onap.usecaseui.server.config.SOClientConfig;
39 import org.onap.usecaseui.server.controller.lcm.CustomerController;
40 import org.onap.usecaseui.server.service.lcm.CustomerService;
41 import org.onap.usecaseui.server.service.lcm.domain.aai.bean.AAICustomer;
42 import org.onap.usecaseui.server.service.lcm.impl.DefaultCustomerService;
43 import org.springframework.beans.factory.annotation.Autowired;
44 import org.springframework.beans.factory.annotation.Value;
45 import org.springframework.boot.test.context.SpringBootTest;
46 import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
47 import org.springframework.http.HttpHeaders;
48 import org.wiremock.spring.EnableWireMock;
49
50 @EnableWireMock
51 @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, classes = {
52     SOClientConfig.class, ResourceMonitorServiceImpl.class, ResourceMonitorServiceConvert.class
53 }, properties = {
54     "spring.main.web-application-type=none", // only temporary
55     "uui-server.client.so.baseUrl=${wiremock.server.baseUrl}",
56     "uui-server.client.so.username=InfraPortalClient",
57     "uui-server.client.so.password=password1",
58 })
59
60 public class ResourceMonitorServiceImplIntegrationTest {
61
62   @Autowired
63   ResourceMonitorServiceImpl resourceMonitorService;
64
65   @Value("${uui-server.client.so.username}")
66   String username;
67
68   @Value("${uui-server.client.so.password}")
69   String password;
70
71   @Test
72   void thatKpiRequestsAreCorrect() {
73     stubFor(
74         post("/api/datalake/v1/exposure/userNumber")
75             .withBasicAuth(username, password)
76             .withHeader(HttpHeaders.ACCEPT, equalTo("application/json"))
77             .willReturn(
78                 aResponse().withBodyFile("kpiUserNumberResponse.json")));
79
80     String timestamp = "1739307776";
81     ServiceList serviceList = new ServiceList();
82     List<ServiceInfo> serviceInfoList = List.of(new ServiceInfo());
83     serviceList.setServiceInfoList(serviceInfoList);
84     ServiceResult serviceResult = resourceMonitorService.querySlicingOnlineUserNumber(timestamp, serviceList);
85     assertNotNull(serviceResult);
86     List<ServiceOnlineUserInfo> onlineUserInfoList = ((ServiceOnlineUserList) serviceResult.getResult_body()).getServiceOnlineUserInfoList();
87     assertEquals(1, onlineUserInfoList.size());
88     assertEquals("abc", onlineUserInfoList.get(0).getId());
89   }
90 }