a1e925a76d7c65c5ecd22cb33101061022de0f61
[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.intent.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.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;
28
29 import java.nio.charset.StandardCharsets;
30 import java.nio.file.Files;
31 import java.nio.file.Paths;
32
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;
57
58 import lombok.SneakyThrows;
59
60 @EnableWireMock
61 @SpringBootTest(
62   classes = {
63         AAIClientConfig.class,
64         SOClientConfig.class,
65         SlicingServiceImpl.class,
66         SlicingProperties.class,
67         IntentProperties.class
68   },
69   properties = {
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"
81   }
82 )
83 @EnableConfigurationProperties
84 public class IntentInstanceServiceIntegrationTest {
85
86   @Value("${uui-server.client.so.username}")
87   String soUsername;
88
89   @Value("${uui-server.client.so.password}")
90   String soPassword;
91
92   @Value("${uui-server.client.aai.username}")
93   String aaiUsername;
94
95   @Value("${uui-server.client.aai.password}")
96   String aaiPassword;
97
98   @Mock
99   ResourceMgtServiceImpl resourceMgtServiceImpl;
100
101   @MockBean
102   DefaultServiceLcmService lcmService;
103
104   @Autowired
105   SlicingService slicingService;
106
107   @Autowired
108   IntentAaiClient intentAaiClient;
109
110   @Autowired
111   IntentSoService intentSoService;
112
113   @Autowired
114   IntentProperties intentProperties;
115
116   @Mock
117   Session session;
118
119   @BeforeEach
120   void setup() {
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);
126   }
127
128   IntentInstanceServiceImpl intentService;
129
130   @Test
131   @SneakyThrows
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);
135     stubFor(
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))
142         .willReturn(
143             aResponse().withBodyFile("createIntentResponse.json")
144         ));
145
146     stubFor(
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"))
152         .willReturn(
153             aResponse().withBodyFile("customersResponse.json")
154         ));
155
156     stubFor(
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"))
162         .willReturn(
163             aResponse().withBodyFile("customersResponse.json")
164         ));
165
166     stubFor(
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"))
172         .willReturn(
173             aResponse().withBodyFile("customersResponse.json")
174         ));
175
176     CCVPNInstance ccVpnInstance = new CCVPNInstance();
177     ccVpnInstance.setInstanceId("someInstanceId");
178     ccVpnInstance.setAccessPointOneName("accessPointOneName");
179     int result = intentService.createCCVPNInstance(ccVpnInstance);
180     assertEquals(1, result);
181   }
182
183 }