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.post;
23 import static com.github.tomakehurst.wiremock.client.WireMock.put;
24 import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
25 import static org.junit.Assert.assertEquals;
26 import static org.mockito.Mockito.mock;
27 import static org.mockito.Mockito.when;
29 import java.nio.charset.StandardCharsets;
30 import java.nio.file.Files;
31 import java.nio.file.Paths;
33 import org.hibernate.Session;
34 import org.hibernate.SessionFactory;
35 import org.hibernate.Transaction;
36 import org.junit.jupiter.api.BeforeEach;
37 import org.junit.jupiter.api.Test;
38 import org.mockito.Mock;
39 import org.onap.usecaseui.server.bean.intent.CCVPNInstance;
40 import org.onap.usecaseui.server.config.AAIClientConfig;
41 import org.onap.usecaseui.server.config.SOClientConfig;
42 import org.onap.usecaseui.server.service.csmf.SlicingService;
43 import org.onap.usecaseui.server.service.csmf.config.SlicingProperties;
44 import org.onap.usecaseui.server.service.csmf.impl.SlicingServiceImpl;
45 import org.onap.usecaseui.server.service.intent.IntentAaiClient;
46 import org.onap.usecaseui.server.service.intent.IntentSoService;
47 import org.onap.usecaseui.server.service.intent.config.IntentProperties;
48 import org.onap.usecaseui.server.service.lcm.impl.DefaultServiceLcmService;
49 import org.onap.usecaseui.server.service.nsmf.impl.ResourceMgtServiceImpl;
50 import org.springframework.beans.factory.annotation.Autowired;
51 import org.springframework.beans.factory.annotation.Value;
52 import org.springframework.boot.context.properties.EnableConfigurationProperties;
53 import org.springframework.boot.test.context.SpringBootTest;
54 import org.springframework.boot.test.mock.mockito.MockBean;
55 import org.springframework.http.HttpHeaders;
56 import org.wiremock.spring.EnableWireMock;
58 import lombok.SneakyThrows;
63 AAIClientConfig.class,
65 SlicingServiceImpl.class,
66 SlicingProperties.class,
67 IntentProperties.class
70 "uui-server.client.aai.baseUrl=${wiremock.server.baseUrl}",
71 "uui-server.client.aai.username=AAI",
72 "uui-server.client.aai.password=AAI",
73 "uui-server.client.so.baseUrl=${wiremock.server.baseUrl}",
74 "uui-server.client.so.username=InfraPortalClient",
75 "uui-server.client.so.password=password1",
76 "uui-server.slicing.service-invariant-uuid=someServiceInvariantUuid",
77 "uui-server.slicing.service-uuid=someServiceUuid",
78 "uui-server.slicing.global-subscriber-id=someGlobalSubscriberId",
79 "uui-server.slicing.service-type=someServiceType",
80 "uui-server.ccvpn.globalCustomerId=defaultGlobalCustomerId"
83 @EnableConfigurationProperties
84 public class IntentInstanceServiceIntegrationTest {
86 @Value("${uui-server.client.so.username}")
89 @Value("${uui-server.client.so.password}")
92 @Value("${uui-server.client.aai.username}")
95 @Value("${uui-server.client.aai.password}")
99 ResourceMgtServiceImpl resourceMgtServiceImpl;
102 DefaultServiceLcmService lcmService;
105 SlicingService slicingService;
108 IntentAaiClient intentAaiClient;
111 IntentSoService intentSoService;
114 IntentProperties intentProperties;
121 SessionFactory sessionFactory = mock(SessionFactory.class);
122 Transaction transaction = mock(Transaction.class);
123 when(sessionFactory.openSession()).thenReturn(session);
124 when(session.beginTransaction()).thenReturn(transaction);
125 this.intentService = new IntentInstanceServiceImpl(slicingService, intentAaiClient, intentSoService, sessionFactory, resourceMgtServiceImpl, intentProperties);
128 IntentInstanceServiceImpl intentService;
132 void thatCCVPNInstanceCanBeCreated() {
133 byte[] requestBytes = Files.readAllBytes(Paths.get("src/test/resources/__files/requests/createIntentRequest.json"));
134 String expectedRequestBody = new String(requestBytes, StandardCharsets.UTF_8);
136 post("/so/infra/serviceIntent/v1/create")
137 .withBasicAuth(soUsername, soPassword)
138 .withHeader(HttpHeaders.ACCEPT, equalTo("application/json"))
139 .withHeader("X-TransactionId", equalTo("9999"))
140 .withHeader("X-FromAppId", equalTo("onap-cli"))
141 .withRequestBody(equalToJson(expectedRequestBody))
143 aResponse().withBodyFile("createIntentResponse.json")
147 get("/aai/v24/business/customers/customer/defaultGlobalCustomerId")
148 .withBasicAuth(aaiUsername, aaiPassword)
149 .withHeader(HttpHeaders.ACCEPT, equalTo("application/json"))
150 .withHeader("X-TransactionId", equalTo("7777"))
151 .withHeader("X-FromAppId", equalTo("uui"))
153 aResponse().withBodyFile("customersResponse.json")
157 get("/aai/v24/business/customers/customer/defaultGlobalCustomerId/service-subscriptions/service-subscription/defaultServiceType")
158 .withBasicAuth(aaiUsername, aaiPassword)
159 .withHeader(HttpHeaders.ACCEPT, equalTo("application/json"))
160 .withHeader("X-TransactionId", equalTo("7777"))
161 .withHeader("X-FromAppId", equalTo("uui"))
163 aResponse().withBodyFile("customersResponse.json")
167 put("/aai/v24/business/customers/customer/defaultGlobalCustomerId/service-subscriptions/service-subscription/defaultServiceType/service-instances/service-instance/IBN-someInstanceId")
168 .withBasicAuth(aaiUsername, aaiPassword)
169 .withHeader(HttpHeaders.ACCEPT, equalTo("application/json"))
170 .withHeader("X-TransactionId", equalTo("7777"))
171 .withHeader("X-FromAppId", equalTo("uui"))
173 aResponse().withBodyFile("customersResponse.json")
176 CCVPNInstance ccVpnInstance = new CCVPNInstance();
177 ccVpnInstance.setInstanceId("someInstanceId");
178 ccVpnInstance.setAccessPointOneName("accessPointOneName");
179 int result = intentService.createCCVPNInstance(ccVpnInstance);
180 assertEquals(1, result);