2 * Copyright 2025 Deutsche Telekom.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org.onap.usecaseui.server.service.intent.impl;
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.equalToJson;
21 import static com.github.tomakehurst.wiremock.client.WireMock.get;
22 import static com.github.tomakehurst.wiremock.client.WireMock.getRequestedFor;
23 import static com.github.tomakehurst.wiremock.client.WireMock.post;
24 import static com.github.tomakehurst.wiremock.client.WireMock.postRequestedFor;
25 import static com.github.tomakehurst.wiremock.client.WireMock.put;
26 import static com.github.tomakehurst.wiremock.client.WireMock.putRequestedFor;
27 import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
28 import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
29 import static org.junit.Assert.assertEquals;
30 import static org.mockito.Mockito.mock;
31 import static org.mockito.Mockito.when;
33 import java.nio.charset.StandardCharsets;
34 import java.nio.file.Files;
35 import java.nio.file.Paths;
37 import org.hibernate.Session;
38 import org.hibernate.SessionFactory;
39 import org.hibernate.Transaction;
40 import org.junit.jupiter.api.BeforeEach;
41 import org.junit.jupiter.api.Test;
42 import org.mockito.Mock;
43 import org.onap.usecaseui.server.bean.intent.CCVPNInstance;
44 import org.onap.usecaseui.server.config.AAIClientConfig;
45 import org.onap.usecaseui.server.config.SOClientConfig;
46 import org.onap.usecaseui.server.service.csmf.SlicingService;
47 import org.onap.usecaseui.server.service.csmf.config.SlicingProperties;
48 import org.onap.usecaseui.server.service.csmf.impl.SlicingServiceImpl;
49 import org.onap.usecaseui.server.service.intent.IntentAaiClient;
50 import org.onap.usecaseui.server.service.intent.IntentSoService;
51 import org.onap.usecaseui.server.service.intent.config.IntentProperties;
52 import org.onap.usecaseui.server.service.lcm.impl.DefaultServiceLcmService;
53 import org.onap.usecaseui.server.service.nsmf.impl.ResourceMgtServiceImpl;
54 import org.springframework.beans.factory.annotation.Autowired;
55 import org.springframework.beans.factory.annotation.Value;
56 import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
57 import org.springframework.boot.context.properties.EnableConfigurationProperties;
58 import org.springframework.boot.test.context.SpringBootTest;
59 import org.springframework.boot.test.mock.mockito.MockBean;
60 import org.springframework.http.HttpHeaders;
61 import org.wiremock.spring.EnableWireMock;
63 import com.github.tomakehurst.wiremock.client.WireMock;
65 import lombok.SneakyThrows;
68 @EnableAutoConfiguration
69 @SpringBootTest(classes = {
70 AAIClientConfig.class,
72 SlicingServiceImpl.class,
73 SlicingProperties.class,
74 IntentProperties.class
76 "uui-server.client.aai.baseUrl=${wiremock.server.baseUrl}",
77 "uui-server.client.aai.username=AAI",
78 "uui-server.client.aai.password=AAI",
79 "uui-server.client.so.baseUrl=${wiremock.server.baseUrl}",
80 "uui-server.client.so.username=InfraPortalClient",
81 "uui-server.client.so.password=password1",
82 "uui-server.slicing.service-invariant-uuid=someServiceInvariantUuid",
83 "uui-server.slicing.service-uuid=someServiceUuid",
84 "uui-server.slicing.global-subscriber-id=someGlobalSubscriberId",
85 "uui-server.slicing.service-type=someServiceType",
86 "uui-server.ccvpn.globalCustomerId=defaultGlobalCustomerId"
88 @EnableConfigurationProperties
89 public class IntentInstanceServiceIntegrationTest {
91 @Value("${uui-server.client.so.username}")
94 @Value("${uui-server.client.so.password}")
97 @Value("${uui-server.client.aai.username}")
100 @Value("${uui-server.client.aai.password}")
103 @Value("${uui-server.client.aai.apiVersion}")
107 ResourceMgtServiceImpl resourceMgtServiceImpl;
110 DefaultServiceLcmService lcmService;
113 SlicingService slicingService;
116 IntentAaiClient intentAaiClient;
119 IntentSoService intentSoService;
122 IntentProperties intentProperties;
129 SessionFactory sessionFactory = mock(SessionFactory.class);
130 Transaction transaction = mock(Transaction.class);
131 when(sessionFactory.openSession()).thenReturn(session);
132 when(session.beginTransaction()).thenReturn(transaction);
133 this.intentService = new IntentInstanceServiceImpl(slicingService, intentAaiClient, intentSoService, sessionFactory,
134 resourceMgtServiceImpl, intentProperties);
137 IntentInstanceServiceImpl intentService;
141 void thatCCVPNInstanceCanBeCreated() {
142 byte[] requestBytes = Files.readAllBytes(Paths.get("src/test/resources/__files/requests/createIntentRequest.json"));
143 String expectedRequestBody = new String(requestBytes, StandardCharsets.UTF_8);
145 post("/so/infra/serviceIntent/v1/create")
146 .withBasicAuth(soUsername, soPassword)
147 .withHeader(HttpHeaders.ACCEPT, equalTo("application/json"))
148 .withHeader("X-TransactionId", equalTo("9999"))
149 .withHeader("X-FromAppId", equalTo("onap-cli"))
150 .withRequestBody(equalToJson(expectedRequestBody))
152 aResponse().withBodyFile("createIntentResponse.json")));
155 get("/aai/%s/business/customers/customer/defaultGlobalCustomerId".formatted(apiVersion))
156 .withBasicAuth(aaiUsername, aaiPassword)
157 .withHeader(HttpHeaders.ACCEPT, equalTo("application/json"))
158 .withHeader("X-TransactionId", equalTo("7777"))
159 .withHeader("X-FromAppId", equalTo("uui"))
161 aResponse().withBodyFile("customersResponse.json")));
164 get("/aai/%s/business/customers/customer/defaultGlobalCustomerId/service-subscriptions/service-subscription/defaultServiceType".formatted(apiVersion))
165 .withBasicAuth(aaiUsername, aaiPassword)
166 .withHeader(HttpHeaders.ACCEPT, equalTo("application/json"))
167 .withHeader("X-TransactionId", equalTo("7777"))
168 .withHeader("X-FromAppId", equalTo("uui"))
170 aResponse().withBodyFile("customersResponse.json")));
173 put("/aai/%s/business/customers/customer/defaultGlobalCustomerId/service-subscriptions/service-subscription/defaultServiceType/service-instances/service-instance/IBN-someInstanceId".formatted(apiVersion))
174 .withBasicAuth(aaiUsername, aaiPassword)
175 .withHeader(HttpHeaders.ACCEPT, equalTo("application/json"))
176 .withHeader("X-TransactionId", equalTo("7777"))
177 .withHeader("X-FromAppId", equalTo("uui"))
179 aResponse().withBodyFile("customersResponse.json")));
181 CCVPNInstance ccVpnInstance = new CCVPNInstance();
182 ccVpnInstance.setInstanceId("someInstanceId");
183 ccVpnInstance.setAccessPointOneName("accessPointOneName");
184 int result = intentService.createCCVPNInstance(ccVpnInstance);
185 assertEquals(1, result);
186 WireMock.verify(postRequestedFor(urlEqualTo("/so/infra/serviceIntent/v1/create")));
187 WireMock.verify(getRequestedFor(urlEqualTo("/aai/%s/business/customers/customer/defaultGlobalCustomerId".formatted(apiVersion))));
188 WireMock.verify(getRequestedFor(urlEqualTo(
189 "/aai/%s/business/customers/customer/defaultGlobalCustomerId/service-subscriptions/service-subscription/defaultServiceType".formatted(apiVersion))));
190 WireMock.verify(putRequestedFor(urlEqualTo(
191 "/aai/%s/business/customers/customer/defaultGlobalCustomerId/service-subscriptions/service-subscription/defaultServiceType/service-instances/service-instance/IBN-someInstanceId".formatted(apiVersion))));