2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 Nordix Foundation.
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.so.adapters.vnfmadapter.rest;
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertNotNull;
25 import static org.junit.Assert.assertNull;
26 import static org.mockito.ArgumentMatchers.eq;
27 import static org.mockito.Mockito.doReturn;
28 import static org.mockito.Mockito.verify;
29 import static org.onap.so.client.RestTemplateConfig.CONFIGURABLE_REST_TEMPLATE;
30 import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo;
31 import static org.springframework.test.web.client.response.MockRestResponseCreators.withStatus;
32 import static org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess;
33 import com.google.gson.Gson;
35 import java.util.Optional;
36 import org.hamcrest.BaseMatcher;
37 import org.hamcrest.Description;
38 import org.junit.Before;
39 import org.junit.Test;
40 import org.junit.runner.RunWith;
41 import org.mockito.ArgumentCaptor;
42 import org.mockito.hamcrest.MockitoHamcrest;
43 import org.onap.aai.domain.yang.EsrSystemInfo;
44 import org.onap.aai.domain.yang.EsrSystemInfoList;
45 import org.onap.aai.domain.yang.EsrVnfm;
46 import org.onap.aai.domain.yang.EsrVnfmList;
47 import org.onap.aai.domain.yang.GenericVnf;
48 import org.onap.aai.domain.yang.Relationship;
49 import org.onap.aai.domain.yang.RelationshipData;
50 import org.onap.aai.domain.yang.RelationshipList;
51 import org.onap.so.adapters.vnfmadapter.VnfmAdapterApplication;
52 import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse200;
53 import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse201;
54 import org.onap.so.adapters.vnfmadapter.rest.exceptions.VnfmNotFoundException;
55 import org.onap.so.client.aai.AAIResourcesClient;
56 import org.onap.so.client.aai.entities.uri.AAIResourceUri;
57 import org.onap.vnfmadapter.v1.model.CreateVnfRequest;
58 import org.onap.vnfmadapter.v1.model.CreateVnfResponse;
59 import org.onap.vnfmadapter.v1.model.DeleteVnfResponse;
60 import org.onap.vnfmadapter.v1.model.OperationEnum;
61 import org.onap.vnfmadapter.v1.model.OperationStateEnum;
62 import org.onap.vnfmadapter.v1.model.QueryJobResponse;
63 import org.onap.vnfmadapter.v1.model.Tenant;
64 import org.springframework.beans.factory.annotation.Autowired;
65 import org.springframework.beans.factory.annotation.Qualifier;
66 import org.springframework.boot.test.context.SpringBootTest;
67 import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
68 import org.springframework.boot.test.mock.mockito.MockBean;
69 import org.springframework.boot.test.web.client.TestRestTemplate;
70 import org.springframework.boot.web.server.LocalServerPort;
71 import org.springframework.http.HttpStatus;
72 import org.springframework.http.MediaType;
73 import org.springframework.http.RequestEntity;
74 import org.springframework.http.ResponseEntity;
75 import org.springframework.test.context.ActiveProfiles;
76 import org.springframework.test.context.junit4.SpringRunner;
77 import org.springframework.test.web.client.MockRestServiceServer;
78 import org.springframework.web.client.RestTemplate;
79 import org.threeten.bp.LocalDateTime;
80 import org.threeten.bp.OffsetDateTime;
81 import org.threeten.bp.ZoneOffset;
84 @RunWith(SpringRunner.class)
85 @SpringBootTest(classes = VnfmAdapterApplication.class, webEnvironment = WebEnvironment.RANDOM_PORT)
86 @ActiveProfiles("test")
88 public class VnfmAdapterControllerTest {
90 private static final OffsetDateTime JAN_1_2019_12_00 =
91 OffsetDateTime.of(LocalDateTime.of(2019, 1, 1, 12, 0), ZoneOffset.UTC);
92 private static final OffsetDateTime JAN_1_2019_1_00 =
93 OffsetDateTime.of(LocalDateTime.of(2019, 1, 1, 1, 0), ZoneOffset.UTC);
94 private static final String CLOUD_OWNER = "myTestCloudOwner";
95 private static final String REGION = "myTestRegion";
96 private static final String TENANT_ID = "myTestTenantId";
101 @Qualifier(CONFIGURABLE_REST_TEMPLATE)
102 private RestTemplate testRestTemplate;
103 private MockRestServiceServer mockRestServer;
106 AAIResourcesClient aaiResourcesClient;
109 VnfmAdapterController controller;
110 Gson gson = new Gson();
113 public void setUp() throws Exception {
114 mockRestServer = MockRestServiceServer.bindTo(testRestTemplate).build();
118 public void createVnf_ValidRequest_Returns202AndJobId() throws Exception {
119 final Tenant tenant = new Tenant().cloudOwner(CLOUD_OWNER).regionName(REGION).tenantId(TENANT_ID);
120 final CreateVnfRequest createVnfRequest = new CreateVnfRequest().name("myTestName").tenant(tenant);
122 setUpGenericVnfInMockAai("vnfmType2");
123 setUpVnfmsInMockAai();
126 mockRestServer.expect(requestTo("http://dummy.value/until/create/implememted/vnfId/instantiate"))
127 .andRespond(withStatus(HttpStatus.ACCEPTED).contentType(MediaType.APPLICATION_JSON)
128 .location(new URI("http://vnfm2:8080/vnf_lcm_op_occs/123456")));
131 final InlineResponse200 firstOperationQueryResponse = createOperationQueryResponse(
132 org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse200.OperationEnum.INSTANTIATE,
133 org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse200.OperationStateEnum.PROCESSING);
134 mockRestServer.expect(requestTo("http://vnfm2:8080/vnf_lcm_op_occs/123456"))
135 .andRespond(withSuccess(gson.toJson(firstOperationQueryResponse), MediaType.APPLICATION_JSON));
137 final InlineResponse200 secondOperationQueryReponse = createOperationQueryResponse(
138 org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse200.OperationEnum.INSTANTIATE,
139 org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse200.OperationStateEnum.COMPLETED);
140 mockRestServer.expect(requestTo("http://vnfm2:8080/vnf_lcm_op_occs/123456"))
141 .andRespond(withSuccess(gson.toJson(secondOperationQueryReponse), MediaType.APPLICATION_JSON));
143 // Invoke the create request
145 final ResponseEntity<CreateVnfResponse> createVnfResponse =
146 controller.vnfCreate("myTestVnfId", createVnfRequest, "asadas", "so", "1213");
147 assertEquals(HttpStatus.ACCEPTED, createVnfResponse.getStatusCode());
148 assertNotNull(createVnfResponse.getBody().getJobId());
150 final ArgumentCaptor<GenericVnf> genericVnfArgument = ArgumentCaptor.forClass(GenericVnf.class);
151 final ArgumentCaptor<AAIResourceUri> uriArgument = ArgumentCaptor.forClass(AAIResourceUri.class);
153 verify(aaiResourcesClient).update(uriArgument.capture(), genericVnfArgument.capture());
155 assertEquals("/network/generic-vnfs/generic-vnf/myTestVnfId", uriArgument.getValue().build().toString());
157 assertEquals("myTestVnfId", genericVnfArgument.getValue().getVnfId());
158 assertEquals(1, genericVnfArgument.getValue().getRelationshipList().getRelationship().size());
159 final Relationship createdRelationship =
160 genericVnfArgument.getValue().getRelationshipList().getRelationship().get(0);
161 assertEquals("esr-vnfm", createdRelationship.getRelatedTo());
162 assertEquals("tosca.relationships.DependsOn", createdRelationship.getRelationshipLabel());
163 assertEquals("/aai/v15/external-system/esr-vnfm-list/esr-vnfm/vnfm2", createdRelationship.getRelatedLink());
165 // check the job status
167 final ResponseEntity<QueryJobResponse> firstJobQueryResponse =
168 controller.jobQuery(createVnfResponse.getBody().getJobId(), "", "so", "1213");
169 assertEquals(OperationEnum.INSTANTIATE, firstJobQueryResponse.getBody().getOperation());
170 assertEquals(OperationStateEnum.PROCESSING, firstJobQueryResponse.getBody().getOperationState());
171 assertEquals(JAN_1_2019_12_00, firstJobQueryResponse.getBody().getStartTime());
172 assertEquals(JAN_1_2019_1_00, firstJobQueryResponse.getBody().getStateEnteredTime());
174 final ResponseEntity<QueryJobResponse> secondJobQueryResponse =
175 controller.jobQuery(createVnfResponse.getBody().getJobId(), "", "so", "1213");
176 assertEquals(OperationEnum.INSTANTIATE, secondJobQueryResponse.getBody().getOperation());
177 assertEquals(OperationStateEnum.COMPLETED, secondJobQueryResponse.getBody().getOperationState());
178 assertEquals(JAN_1_2019_12_00, secondJobQueryResponse.getBody().getStartTime());
179 assertEquals(JAN_1_2019_1_00, secondJobQueryResponse.getBody().getStateEnteredTime());
182 @Test(expected = IllegalArgumentException.class)
183 public void createVnf_VnfAlreadyExistsOnVnfm_ThrowsIllegalArgumentException() throws Exception {
184 final Tenant tenant = new Tenant().cloudOwner(CLOUD_OWNER).regionName(REGION).tenantId(TENANT_ID);
185 final CreateVnfRequest createVnfRequest = new CreateVnfRequest().name("myTestName").tenant(tenant);
187 final GenericVnf genericVnf = setUpGenericVnfInMockAai("vnfmType1");
188 addSelfLinkToGenericVnf(genericVnf);
190 final InlineResponse201 reponse = new InlineResponse201();
191 mockRestServer.expect(requestTo(new URI("http://vnfm:8080/vnfs/myTestVnfIdOnVnfm")))
192 .andRespond(withSuccess(gson.toJson(reponse), MediaType.APPLICATION_JSON));
194 controller.vnfCreate("myTestVnfId", createVnfRequest, "asadas", "so", "1213");
197 @Test(expected = VnfmNotFoundException.class)
198 public void createVnf_NoMatchingVnfmFound_ThrowsException() throws Exception {
199 final Tenant tenant = new Tenant().cloudOwner(CLOUD_OWNER).regionName(REGION).tenantId(TENANT_ID);
200 final CreateVnfRequest createVnfRequest = new CreateVnfRequest().name("myTestName").tenant(tenant);
202 setUpGenericVnfInMockAai("anotherType");
203 setUpVnfmsInMockAai();
205 controller.vnfCreate("myTestVnfId", createVnfRequest, "asadas", "so", "1213");
209 public void createVnf_VnfmAlreadyAssociatedWithVnf_Returns202AndJobId() throws Exception {
210 final Tenant tenant = new Tenant().cloudOwner(CLOUD_OWNER).regionName(REGION).tenantId(TENANT_ID);
211 final CreateVnfRequest createVnfRequest = new CreateVnfRequest().name("myTestName").tenant(tenant);
213 final GenericVnf genericVnf = setUpGenericVnfInMockAai("vnfmType2");
214 addRelationshipFromGenericVnfToVnfm(genericVnf, "vnfm1");
215 setUpVnfmsInMockAai();
218 mockRestServer.expect(requestTo("http://dummy.value/until/create/implememted/vnfId/instantiate"))
219 .andRespond(withStatus(HttpStatus.ACCEPTED).contentType(MediaType.APPLICATION_JSON)
220 .location(new URI("http://vnfm2:8080/vnf_lcm_op_occs/123456")));
222 final ResponseEntity<CreateVnfResponse> response =
223 controller.vnfCreate("myTestVnfId", createVnfRequest, "asadas", "so", "1213");
224 assertEquals(HttpStatus.ACCEPTED, response.getStatusCode());
225 assertNotNull(response.getBody().getJobId());
229 public void createVnf_UnauthorizedUser_Returns401() throws Exception {
230 final TestRestTemplate restTemplateWrongPassword = new TestRestTemplate("test", "wrongPassword");
231 final Tenant tenant = new Tenant().cloudOwner(CLOUD_OWNER).regionName(REGION).tenantId(TENANT_ID);
232 final CreateVnfRequest createVnfRequest = new CreateVnfRequest().name("myTestName").tenant(tenant);
234 final RequestEntity<CreateVnfRequest> request =
235 RequestEntity.post(new URI("http://localhost:" + port + "/so/vnfm-adapter/v1/vnfs/myVnfId"))
236 .accept(MediaType.APPLICATION_JSON).contentType(MediaType.APPLICATION_JSON)
237 .header("X-ONAP-RequestId", "myRequestId").header("X-ONAP-InvocationID", "myInvocationId")
238 .body(createVnfRequest);
239 final ResponseEntity<CreateVnfResponse> response =
240 restTemplateWrongPassword.exchange(request, CreateVnfResponse.class);
241 assertEquals(401, response.getStatusCode().value());
245 public void deleteVnf_ValidRequest_Returns202AndJobId() throws Exception {
246 final TestRestTemplate restTemplate = new TestRestTemplate("test", "test");
248 final GenericVnf genericVnf = setUpGenericVnfInMockAai("vnfmType");
249 addSelfLinkToGenericVnf(genericVnf);
250 addRelationshipFromGenericVnfToVnfm(genericVnf, "vnfm");
252 mockRestServer.expect(requestTo("http://vnfm:8080/vnfs/myTestVnfIdOnVnfm/terminate"))
253 .andRespond(withStatus(HttpStatus.ACCEPTED).contentType(MediaType.APPLICATION_JSON)
254 .location(new URI("http://vnfm2:8080/vnf_lcm_op_occs/1234567")));
256 final InlineResponse200 firstOperationQueryResponse = createOperationQueryResponse(
257 org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse200.OperationEnum.TERMINATE,
258 org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse200.OperationStateEnum.PROCESSING);
259 mockRestServer.expect(requestTo("http://vnfm:8080/vnf_lcm_op_occs/1234567"))
260 .andRespond(withSuccess(gson.toJson(firstOperationQueryResponse), MediaType.APPLICATION_JSON));
263 final InlineResponse200 secondOperationQueryReponse = createOperationQueryResponse(
264 org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse200.OperationEnum.TERMINATE,
265 org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse200.OperationStateEnum.COMPLETED);
266 mockRestServer.expect(requestTo("http://vnfm:8080/vnf_lcm_op_occs/1234567"))
267 .andRespond(withSuccess(gson.toJson(secondOperationQueryReponse), MediaType.APPLICATION_JSON));
270 final RequestEntity<Void> request = RequestEntity
271 .delete(new URI("http://localhost:" + port + "/so/vnfm-adapter/v1/vnfs/myTestVnfId"))
272 .accept(MediaType.APPLICATION_JSON).header("X-ONAP-RequestId", "myRequestId")
273 .header("X-ONAP-InvocationID", "myInvocationId").header("Content-Type", "application/json").build();
274 final ResponseEntity<DeleteVnfResponse> deleteVnfResponse =
275 restTemplate.exchange(request, DeleteVnfResponse.class);
276 assertEquals(202, deleteVnfResponse.getStatusCode().value());
277 assertNotNull(deleteVnfResponse.getBody().getJobId());
280 final EsrSystemInfo esrSystemInfo = new EsrSystemInfo();
281 esrSystemInfo.setServiceUrl("http://vnfm:8080");
282 esrSystemInfo.setType("vnfmType");
283 esrSystemInfo.setSystemType("VNFM");
284 final EsrSystemInfoList esrSystemInfoList = new EsrSystemInfoList();
285 esrSystemInfoList.getEsrSystemInfo().add(esrSystemInfo);
287 doReturn(Optional.of(esrSystemInfoList)).when(aaiResourcesClient).get(eq(EsrSystemInfoList.class),
288 MockitoHamcrest.argThat(new AaiResourceUriMatcher("/external-system/esr-vnfm-list/esr-vnfm/...")));
291 final ResponseEntity<QueryJobResponse> firstJobQueryResponse =
292 controller.jobQuery(deleteVnfResponse.getBody().getJobId(), "", "so", "1213");
293 assertEquals(OperationEnum.TERMINATE, firstJobQueryResponse.getBody().getOperation());
294 assertEquals(OperationStateEnum.PROCESSING, firstJobQueryResponse.getBody().getOperationState());
295 assertEquals(JAN_1_2019_12_00, firstJobQueryResponse.getBody().getStartTime());
296 assertEquals(JAN_1_2019_1_00, firstJobQueryResponse.getBody().getStateEnteredTime());
298 final ResponseEntity<QueryJobResponse> secondJobQueryResponse =
299 controller.jobQuery(deleteVnfResponse.getBody().getJobId(), "", "so", "1213");
300 assertEquals(OperationEnum.TERMINATE, secondJobQueryResponse.getBody().getOperation());
301 assertEquals(OperationStateEnum.PROCESSING, secondJobQueryResponse.getBody().getOperationState());
302 assertEquals(JAN_1_2019_12_00, secondJobQueryResponse.getBody().getStartTime());
303 assertEquals(JAN_1_2019_1_00, secondJobQueryResponse.getBody().getStateEnteredTime());
307 public void deleteVnf_GenericVnfNotFound_Returns404() throws Exception {
308 final TestRestTemplate restTemplate = new TestRestTemplate("test", "test");
310 final RequestEntity<Void> request = RequestEntity
311 .delete(new URI("http://localhost:" + port + "/so/vnfm-adapter/v1/vnfs/myNonExistingVnfId"))
312 .accept(MediaType.APPLICATION_JSON).header("X-ONAP-RequestId", "myRequestId")
313 .header("X-ONAP-InvocationID", "myInvocationId").header("Content-Type", "application/json").build();
314 final ResponseEntity<DeleteVnfResponse> deleteVnfResponse =
315 restTemplate.exchange(request, DeleteVnfResponse.class);
316 assertEquals(404, deleteVnfResponse.getStatusCode().value());
317 assertNull(deleteVnfResponse.getBody().getJobId());
321 public void deleteVnf_NoAssignedVnfm_Returns400() throws Exception {
322 final TestRestTemplate restTemplate = new TestRestTemplate("test", "test");
324 setUpGenericVnfInMockAai("vnfmType");
326 final RequestEntity<Void> request = RequestEntity
327 .delete(new URI("http://localhost:" + port + "/so/vnfm-adapter/v1/vnfs/myTestVnfId"))
328 .accept(MediaType.APPLICATION_JSON).header("X-ONAP-RequestId", "myRequestId")
329 .header("X-ONAP-InvocationID", "myInvocationId").header("Content-Type", "application/json").build();
330 final ResponseEntity<DeleteVnfResponse> deleteVnfResponse =
331 restTemplate.exchange(request, DeleteVnfResponse.class);
332 assertEquals(400, deleteVnfResponse.getStatusCode().value());
333 assertNull(deleteVnfResponse.getBody().getJobId());
337 public void deleteVnf_ErrorStatusCodeFromVnfm_Returns500() throws Exception {
338 final TestRestTemplate restTemplate = new TestRestTemplate("test", "test");
340 final GenericVnf genericVnf = setUpGenericVnfInMockAai("vnfmType");
341 addSelfLinkToGenericVnf(genericVnf);
342 addRelationshipFromGenericVnfToVnfm(genericVnf, "vnfm");
344 mockRestServer.expect(requestTo("http://vnfm:8080/vnfs/myTestVnfIdOnVnfm/terminate"))
345 .andRespond(withStatus(HttpStatus.BAD_REQUEST).contentType(MediaType.APPLICATION_JSON));
348 final RequestEntity<Void> request = RequestEntity
349 .delete(new URI("http://localhost:" + port + "/so/vnfm-adapter/v1/vnfs/myTestVnfId"))
350 .accept(MediaType.APPLICATION_JSON).header("X-ONAP-RequestId", "myRequestId")
351 .header("X-ONAP-InvocationID", "myInvocationId").header("Content-Type", "application/json").build();
352 final ResponseEntity<DeleteVnfResponse> deleteVnfResponse =
353 restTemplate.exchange(request, DeleteVnfResponse.class);
354 assertEquals(500, deleteVnfResponse.getStatusCode().value());
355 assertNull(deleteVnfResponse.getBody().getJobId());
359 private InlineResponse200 createOperationQueryResponse(
360 final org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse200.OperationEnum operation,
361 final org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse200.OperationStateEnum operationState) {
362 final InlineResponse200 response = new InlineResponse200();
363 response.setId("9876");
364 response.setOperation(operation);
365 response.setOperationState(operationState);
366 response.setStartTime(JAN_1_2019_12_00);
367 response.setStateEnteredTime(JAN_1_2019_1_00);
368 response.setVnfInstanceId("myVnfInstanceId");
372 private GenericVnf createGenericVnf(final String type) {
373 final GenericVnf genericVnf = new GenericVnf();
374 genericVnf.setVnfId("myTestVnfId");
375 genericVnf.setNfType(type);
379 private GenericVnf setUpGenericVnfInMockAai(final String type) {
380 final GenericVnf genericVnf = createGenericVnf(type);
382 doReturn(Optional.of(genericVnf)).when(aaiResourcesClient).get(eq(GenericVnf.class),
383 MockitoHamcrest.argThat(new AaiResourceUriMatcher("/network/generic-vnfs/generic-vnf/myTestVnfId")));
387 private void addSelfLinkToGenericVnf(final GenericVnf vnf) {
388 vnf.setSelflink("http://vnfm:8080/vnfs/myTestVnfIdOnVnfm");
391 private void addRelationshipFromGenericVnfToVnfm(final GenericVnf genericVnf, final String vnfmId) {
392 final Relationship relationshipToVnfm = new Relationship();
393 relationshipToVnfm.setRelatedLink(
394 "/aai/v15/external-system/esr-vnfm-li// final InlineResponse201 vnfInstance = new InlineResponse201();\n"
395 + "// vnfInstance.setInstantiationState(InstantiationStateEnum.NOT_INSTANTIATED);\n"
396 + "// mockRestServer.expect(requestTo(\"http://dummy.value/until/create/implememted/vnfId\"))\n"
397 + "// .andRespond(withSuccess(gson.toJson(vnfInstance), MediaType.APPLICATION_JSON));st/esr-vnfm/"
399 relationshipToVnfm.setRelatedTo("esr-vnfm");
400 final RelationshipData relationshipData = new RelationshipData();
401 relationshipData.setRelationshipKey("esr-vnfm.vnfm-id");
402 relationshipData.setRelationshipValue(vnfmId);
403 relationshipToVnfm.getRelationshipData().add(relationshipData);
405 final RelationshipList relationshipList = new RelationshipList();
406 relationshipList.getRelationship().add(relationshipToVnfm);
407 genericVnf.setRelationshipList(relationshipList);
410 private void setUpVnfmsInMockAai() {
411 final EsrSystemInfo esrSystemInfo1 = new EsrSystemInfo();
412 esrSystemInfo1.setServiceUrl("http://vnfm1:8080");
413 esrSystemInfo1.setType("vnfmType1");
414 esrSystemInfo1.setSystemType("VNFM");
415 final EsrSystemInfoList esrSystemInfoList1 = new EsrSystemInfoList();
416 esrSystemInfoList1.getEsrSystemInfo().add(esrSystemInfo1);
418 final EsrVnfm esrVnfm1 = new EsrVnfm();
419 esrVnfm1.setVnfmId("vnfm1");
420 esrVnfm1.setEsrSystemInfoList(esrSystemInfoList1);
421 esrVnfm1.setResourceVersion("1234");
423 final EsrSystemInfo esrSystemInfo2 = new EsrSystemInfo();
424 esrSystemInfo2.setServiceUrl("http://vnfm2:8080");
425 esrSystemInfo2.setType("vnfmType2");
426 esrSystemInfo2.setSystemType("VNFM");
427 final EsrSystemInfoList esrSystemInfoList2 = new EsrSystemInfoList();
428 esrSystemInfoList2.getEsrSystemInfo().add(esrSystemInfo2);
430 final EsrVnfm esrVnfm2 = new EsrVnfm();
431 esrVnfm2.setVnfmId("vnfm2");
432 esrVnfm2.setEsrSystemInfoList(esrSystemInfoList2);
433 esrVnfm2.setResourceVersion("1234");
435 final EsrVnfmList esrVnfmList = new EsrVnfmList();
436 esrVnfmList.getEsrVnfm().add(esrVnfm1);
437 esrVnfmList.getEsrVnfm().add(esrVnfm2);
439 doReturn(Optional.of(esrVnfmList)).when(aaiResourcesClient).get(eq(EsrVnfmList.class),
440 MockitoHamcrest.argThat(new AaiResourceUriMatcher("/external-system/esr-vnfm-list")));
442 doReturn(Optional.of(esrSystemInfoList1)).when(aaiResourcesClient).get(eq(EsrSystemInfoList.class),
443 MockitoHamcrest.argThat(new AaiResourceUriMatcher(
444 "/external-system/esr-vnfm-list/esr-vnfm/vnfm1/esr-system-info-list")));
445 doReturn(Optional.of(esrSystemInfoList2)).when(aaiResourcesClient).get(eq(EsrSystemInfoList.class),
446 MockitoHamcrest.argThat(new AaiResourceUriMatcher(
447 "/external-system/esr-vnfm-list/esr-vnfm/vnfm2/esr-system-info-list")));
450 private void setUpVimInMockAai() {
451 final EsrSystemInfo esrSystemInfo = new EsrSystemInfo();
452 esrSystemInfo.setServiceUrl("http://myVim:8080");
453 esrSystemInfo.setType("openstack");
454 esrSystemInfo.setSystemType("VIM");
455 esrSystemInfo.setCloudDomain("myDomain");
456 esrSystemInfo.setUserName("myUser");
457 esrSystemInfo.setPassword("myPassword");
459 final EsrSystemInfoList esrSystemInfoList = new EsrSystemInfoList();
460 esrSystemInfoList.getEsrSystemInfo().add(esrSystemInfo);
462 doReturn(Optional.of(esrSystemInfoList)).when(aaiResourcesClient).get(eq(EsrSystemInfoList.class),
463 MockitoHamcrest.argThat(new AaiResourceUriMatcher("/cloud-infrastructure/cloud-regions/cloud-region/"
464 + CLOUD_OWNER + "/" + REGION + "/esr-system-info-list")));
467 private class AaiResourceUriMatcher extends BaseMatcher<AAIResourceUri> {
469 final String uriAsString;
471 public AaiResourceUriMatcher(final String uriAsString) {
472 this.uriAsString = uriAsString;
476 public boolean matches(final Object item) {
477 if (item instanceof AAIResourceUri) {
478 if (uriAsString.endsWith("...")) {
479 return ((AAIResourceUri) item).build().toString()
480 .startsWith(uriAsString.substring(0, uriAsString.indexOf("...")));
482 return ((AAIResourceUri) item).build().toString().equals(uriAsString);
488 public void describeTo(final Description description) {}