9a4035a36b146d235f5f4e9f3ae095b6559078f4
[usecase-ui/server.git] /
1 /**
2  * Copyright 2025 Deutsche Telekom.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package org.onap.usecaseui.server.service.lcm.impl;
17
18 import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
19 import static com.github.tomakehurst.wiremock.client.WireMock.equalTo;
20 import static com.github.tomakehurst.wiremock.client.WireMock.get;
21 import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
22 import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo;
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertNotNull;
25 import java.util.List;
26 import org.junit.jupiter.api.Test;
27 import org.onap.usecaseui.server.config.AAIClientConfig;
28 import org.onap.usecaseui.server.config.SDCClientConfig;
29 import org.onap.usecaseui.server.config.SDCClientProperties;
30 import org.onap.usecaseui.server.service.lcm.domain.sdc.bean.SDCServiceTemplate;
31 import org.springframework.beans.factory.annotation.Autowired;
32 import org.springframework.beans.factory.annotation.Value;
33 import org.springframework.boot.context.properties.EnableConfigurationProperties;
34 import org.springframework.boot.test.context.SpringBootTest;
35 import org.springframework.http.HttpHeaders;
36 import org.wiremock.spring.EnableWireMock;
37
38 import lombok.SneakyThrows;
39
40 @EnableWireMock
41 @EnableConfigurationProperties(SDCClientProperties.class)
42 @SpringBootTest(
43     classes = {
44         AAIClientConfig.class, SDCClientConfig.class , DefaultServiceTemplateService.class
45     },
46     properties = {
47         "client.aai.baseUrl=${wiremock.server.baseUrl}",
48         "client.aai.username=AAI",
49         "client.aai.password=AAI",
50         "uui-server.client.sdc.base-url=${wiremock.server.baseUrl}",
51         "uui-server.client.sdc.username=someUser",
52         "uui-server.client.sdc.password=somePassword",
53     })
54 public class DefaultServiceTemplateServiceIntegrationTest {
55
56     @Autowired
57     DefaultServiceTemplateService defaultServiceTemplateService;
58
59     @Value("${uui-server.client.sdc.username}")
60     String username;
61
62     @Value("${uui-server.client.sdc.password}")
63     String password;
64
65     @Test
66     @SneakyThrows
67     void thatSDCCatalogRequestsAreCorrect() {
68         stubFor(
69             get(urlPathEqualTo("/api/sdc/v1/catalog/services"))
70             .withQueryParam("category", equalTo("E2E Service"))
71             .withQueryParam("distributionStatus", equalTo("DISTRIBUTED"))
72             .withBasicAuth(username, password)
73             .withHeader(HttpHeaders.ACCEPT, equalTo("application/json"))
74             .withHeader("X-ECOMP-InstanceID", equalTo("777"))
75             .willReturn(
76                 aResponse().withBodyFile("serviceTemplateResponse.json")
77             ));
78         List<SDCServiceTemplate> serviceTemplates = defaultServiceTemplateService.listDistributedServiceTemplate();
79         assertNotNull(serviceTemplates);
80         assertEquals(1, serviceTemplates.size());
81         assertEquals("someCategory", serviceTemplates.get(0).getCategory());
82         assertEquals("someInvariantUuid", serviceTemplates.get(0).getInvariantUUID());
83         assertEquals("someName", serviceTemplates.get(0).getName());
84         assertEquals("/foo/bar", serviceTemplates.get(0).getToscaModelURL());
85         assertEquals("someUuid", serviceTemplates.get(0).getUuid());
86         assertEquals("someVersion", serviceTemplates.get(0).getVersion());
87     }
88 }