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 com.google.gson.Gson;
24 import org.hamcrest.BaseMatcher;
25 import org.hamcrest.Description;
26 import org.junit.Before;
27 import org.junit.Test;
28 import org.junit.runner.RunWith;
29 import org.mockito.ArgumentCaptor;
30 import org.mockito.hamcrest.MockitoHamcrest;
31 import org.onap.aai.domain.yang.*;
32 import org.onap.so.adapters.vnfmadapter.VnfmAdapterApplication;
33 import org.onap.so.adapters.vnfmadapter.extclients.SdcPackageProvider;
34 import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.*;
35 import org.onap.so.adapters.vnfmadapter.rest.exceptions.VnfmNotFoundException;
36 import org.onap.so.client.aai.AAIResourcesClient;
37 import org.onap.so.client.aai.entities.uri.AAIResourceUri;
38 import org.onap.vnfmadapter.v1.model.CreateVnfRequest;
39 import org.onap.vnfmadapter.v1.model.Tenant;
40 import org.onap.vnfmadapter.v1.model.*;
41 import org.springframework.beans.factory.annotation.Autowired;
42 import org.springframework.beans.factory.annotation.Qualifier;
43 import org.springframework.boot.test.context.SpringBootTest;
44 import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
45 import org.springframework.boot.test.mock.mockito.MockBean;
46 import org.springframework.boot.test.web.client.TestRestTemplate;
47 import org.springframework.boot.web.server.LocalServerPort;
48 import org.springframework.http.HttpStatus;
49 import org.springframework.http.MediaType;
50 import org.springframework.http.RequestEntity;
51 import org.springframework.http.ResponseEntity;
52 import org.springframework.test.context.ActiveProfiles;
53 import org.springframework.test.context.junit4.SpringRunner;
54 import org.springframework.test.web.client.MockRestServiceServer;
55 import org.springframework.web.client.RestTemplate;
56 import org.threeten.bp.LocalDateTime;
57 import org.threeten.bp.OffsetDateTime;
58 import org.threeten.bp.ZoneOffset;
60 import java.util.Optional;
61 import static org.junit.Assert.*;
62 import static org.mockito.ArgumentMatchers.eq;
63 import static org.mockito.Mockito.doReturn;
64 import static org.mockito.Mockito.verify;
65 import static org.onap.so.client.RestTemplateConfig.CONFIGURABLE_REST_TEMPLATE;
66 import static org.springframework.test.web.client.match.MockRestRequestMatchers.content;
67 import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo;
68 import static org.springframework.test.web.client.response.MockRestResponseCreators.*;
70 @RunWith(SpringRunner.class)
71 @SpringBootTest(classes = VnfmAdapterApplication.class, webEnvironment = WebEnvironment.RANDOM_PORT)
72 @ActiveProfiles("test")
74 public class VnfmAdapterControllerTest {
76 private static final OffsetDateTime JAN_1_2019_12_00 =
77 OffsetDateTime.of(LocalDateTime.of(2019, 1, 1, 12, 0), ZoneOffset.UTC);
78 private static final OffsetDateTime JAN_1_2019_1_00 =
79 OffsetDateTime.of(LocalDateTime.of(2019, 1, 1, 1, 0), ZoneOffset.UTC);
80 private static final String CLOUD_OWNER = "myTestCloudOwner";
81 private static final String REGION = "myTestRegion";
82 private static final String TENANT_ID = "myTestTenantId";
87 @Qualifier(CONFIGURABLE_REST_TEMPLATE)
88 private RestTemplate testRestTemplate;
89 private MockRestServiceServer mockRestServer;
92 AAIResourcesClient aaiResourcesClient;
95 SdcPackageProvider sdcPackageProvider;
98 VnfmAdapterController controller;
99 Gson gson = new Gson();
102 public void setUp() throws Exception {
103 mockRestServer = MockRestServiceServer.bindTo(testRestTemplate).build();
107 public void createVnf_ValidRequest_Returns202AndJobId() throws Exception {
108 final Tenant tenant = new Tenant().cloudOwner(CLOUD_OWNER).regionName(REGION).tenantId(TENANT_ID);
109 final CreateVnfRequest createVnfRequest = new CreateVnfRequest().name("myTestName").tenant(tenant);
111 setUpGenericVnfInMockAai("vnfmType2");
112 setUpVnfmsInMockAai();
115 final String expectedsubscriptionRequest =
116 "{\"filter\":{\"vnfInstanceSubscriptionFilter\":{\"vnfInstanceIds\":[\"vnfId\"]},\"notificationTypes\":[\"VnfLcmOperationOccurrenceNotification\"]},\"callbackUri\":\"https://so-vnfm-adapter.onap:30406/so/vnfm-adapter/v1/lcn/VnfLcmOperationOccurrenceNotification\",\"authentication\":{\"authType\":[\"BASIC\"],\"paramsBasic\":{\"userName\":\"vnfm\",\"password\":\"$2a$10$Fh9ffgPw2vnmsghsRD3ZauBL1aKXebigbq3BB1RPWtE62UDILsjke\"}}}";
117 final InlineResponse2001 subscriptionResponse = new InlineResponse2001();
119 final InlineResponse201 createResponse = createCreateResponse();
120 mockRestServer.expect(requestTo("http://vnfm2:8080/vnf_instances"))
121 .andRespond(withSuccess(gson.toJson(createResponse), MediaType.APPLICATION_JSON));
123 mockRestServer.expect(requestTo("http://vnfm2:8080/subscriptions"))
124 .andExpect(content().json(expectedsubscriptionRequest))
125 .andRespond(withSuccess(gson.toJson(subscriptionResponse), MediaType.APPLICATION_JSON));
127 mockRestServer.expect(requestTo("http://vnfm2:8080/vnf_instances/vnfId/instantiate"))
128 .andRespond(withStatus(HttpStatus.ACCEPTED).contentType(MediaType.APPLICATION_JSON)
129 .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(2, genericVnfArgument.getValue().getRelationshipList().getRelationship().size());
159 final Relationship vnfmRelationship =
160 genericVnfArgument.getValue().getRelationshipList().getRelationship().get(0);
161 assertEquals("esr-vnfm", vnfmRelationship.getRelatedTo());
162 assertEquals("tosca.relationships.DependsOn", vnfmRelationship.getRelationshipLabel());
163 assertEquals("/aai/v15/external-system/esr-vnfm-list/esr-vnfm/vnfm2", vnfmRelationship.getRelatedLink());
165 final Relationship tenantRelationship =
166 genericVnfArgument.getValue().getRelationshipList().getRelationship().get(1);
167 assertEquals("tenant", tenantRelationship.getRelatedTo());
169 "/aai/v15/cloud-infrastructure/cloud-regions/cloud-region/myTestCloudOwner/myTestRegion/tenants/tenant/myTestTenantId",
170 tenantRelationship.getRelatedLink());
173 // check the job status
175 final ResponseEntity<QueryJobResponse> firstJobQueryResponse =
176 controller.jobQuery(createVnfResponse.getBody().getJobId(), "", "so", "1213");
177 assertEquals(OperationEnum.INSTANTIATE, firstJobQueryResponse.getBody().getOperation());
178 assertEquals(OperationStateEnum.PROCESSING, firstJobQueryResponse.getBody().getOperationState());
179 assertEquals(JAN_1_2019_12_00, firstJobQueryResponse.getBody().getStartTime());
180 assertEquals(JAN_1_2019_1_00, firstJobQueryResponse.getBody().getStateEnteredTime());
182 final ResponseEntity<QueryJobResponse> secondJobQueryResponse =
183 controller.jobQuery(createVnfResponse.getBody().getJobId(), "", "so", "1213");
184 assertEquals(OperationEnum.INSTANTIATE, secondJobQueryResponse.getBody().getOperation());
185 assertEquals(OperationStateEnum.COMPLETED, secondJobQueryResponse.getBody().getOperationState());
186 assertEquals(JAN_1_2019_12_00, secondJobQueryResponse.getBody().getStartTime());
187 assertEquals(JAN_1_2019_1_00, secondJobQueryResponse.getBody().getStateEnteredTime());
190 @Test(expected = IllegalArgumentException.class)
191 public void createVnf_VnfAlreadyExistsOnVnfm_ThrowsIllegalArgumentException() throws Exception {
192 final Tenant tenant = new Tenant().cloudOwner(CLOUD_OWNER).regionName(REGION).tenantId(TENANT_ID);
193 final CreateVnfRequest createVnfRequest = new CreateVnfRequest().name("myTestName").tenant(tenant);
195 final GenericVnf genericVnf = setUpGenericVnfInMockAai("vnfmType1");
196 addSelfLinkToGenericVnf(genericVnf);
198 final InlineResponse201 reponse = new InlineResponse201();
199 mockRestServer.expect(requestTo(new URI("http://vnfm:8080/vnfs/myTestVnfIdOnVnfm")))
200 .andRespond(withSuccess(gson.toJson(reponse), MediaType.APPLICATION_JSON));
202 controller.vnfCreate("myTestVnfId", createVnfRequest, "asadas", "so", "1213");
205 @Test(expected = VnfmNotFoundException.class)
206 public void createVnf_NoMatchingVnfmFound_ThrowsException() throws Exception {
207 final Tenant tenant = new Tenant().cloudOwner(CLOUD_OWNER).regionName(REGION).tenantId(TENANT_ID);
208 final CreateVnfRequest createVnfRequest = new CreateVnfRequest().name("myTestName").tenant(tenant);
210 setUpGenericVnfInMockAai("anotherType");
211 setUpVnfmsInMockAai();
213 controller.vnfCreate("myTestVnfId", createVnfRequest, "asadas", "so", "1213");
217 public void createVnf_VnfmAlreadyAssociatedWithVnf_Returns202AndJobId() throws Exception {
218 final Tenant tenant = new Tenant().cloudOwner(CLOUD_OWNER).regionName(REGION).tenantId(TENANT_ID);
219 final CreateVnfRequest createVnfRequest = new CreateVnfRequest().name("myTestName").tenant(tenant);
221 final GenericVnf genericVnf = setUpGenericVnfInMockAai("vnfmType2");
222 addRelationshipFromGenericVnfToVnfm(genericVnf, "vnfm1");
223 setUpVnfmsInMockAai();
226 final InlineResponse201 createResponse = createCreateResponse();
227 mockRestServer.expect(requestTo("http://vnfm2:8080/vnf_instances"))
228 .andRespond(withSuccess(gson.toJson(createResponse), MediaType.APPLICATION_JSON));
230 mockRestServer.expect(requestTo("http://vnfm2:8080/subscriptions")).andRespond(withBadRequest());
232 mockRestServer.expect(requestTo("http://vnfm2:8080/vnf_instances/vnfId/instantiate"))
233 .andRespond(withStatus(HttpStatus.ACCEPTED).contentType(MediaType.APPLICATION_JSON)
234 .location(new URI("http://vnfm2:8080/vnf_lcm_op_occs/123456")));
236 final ResponseEntity<CreateVnfResponse> response =
237 controller.vnfCreate("myTestVnfId", createVnfRequest, "asadas", "so", "1213");
238 assertEquals(HttpStatus.ACCEPTED, response.getStatusCode());
239 assertNotNull(response.getBody().getJobId());
243 public void createVnf_UnauthorizedUser_Returns401() throws Exception {
244 final TestRestTemplate restTemplateWrongPassword = new TestRestTemplate("test", "wrongPassword");
245 final Tenant tenant = new Tenant().cloudOwner(CLOUD_OWNER).regionName(REGION).tenantId(TENANT_ID);
246 final CreateVnfRequest createVnfRequest = new CreateVnfRequest().name("myTestName").tenant(tenant);
248 final RequestEntity<CreateVnfRequest> request =
249 RequestEntity.post(new URI("http://localhost:" + port + "/so/vnfm-adapter/v1/vnfs/myVnfId"))
250 .accept(MediaType.APPLICATION_JSON).contentType(MediaType.APPLICATION_JSON)
251 .header("X-ONAP-RequestId", "myRequestId").header("X-ONAP-InvocationID", "myInvocationId")
252 .body(createVnfRequest);
253 final ResponseEntity<CreateVnfResponse> response =
254 restTemplateWrongPassword.exchange(request, CreateVnfResponse.class);
255 assertEquals(401, response.getStatusCode().value());
259 public void deleteVnf_ValidRequest_Returns202AndJobId() throws Exception {
260 final TestRestTemplate restTemplate = new TestRestTemplate("test", "test");
262 final GenericVnf genericVnf = setUpGenericVnfInMockAai("vnfmType");
263 addSelfLinkToGenericVnf(genericVnf);
264 addRelationshipFromGenericVnfToVnfm(genericVnf, "vnfm");
266 mockRestServer.expect(requestTo("http://vnfm:8080/vnfs/myTestVnfIdOnVnfm/terminate"))
267 .andRespond(withStatus(HttpStatus.ACCEPTED).contentType(MediaType.APPLICATION_JSON)
268 .location(new URI("http://vnfm2:8080/vnf_lcm_op_occs/1234567")));
270 final InlineResponse200 firstOperationQueryResponse = createOperationQueryResponse(
271 org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse200.OperationEnum.TERMINATE,
272 org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse200.OperationStateEnum.PROCESSING);
273 mockRestServer.expect(requestTo("http://vnfm:8080/vnf_lcm_op_occs/1234567"))
274 .andRespond(withSuccess(gson.toJson(firstOperationQueryResponse), MediaType.APPLICATION_JSON));
276 final InlineResponse200 secondOperationQueryReponse = createOperationQueryResponse(
277 org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse200.OperationEnum.TERMINATE,
278 org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse200.OperationStateEnum.COMPLETED);
279 mockRestServer.expect(requestTo("http://vnfm:8080/vnf_lcm_op_occs/1234567"))
280 .andRespond(withSuccess(gson.toJson(secondOperationQueryReponse), MediaType.APPLICATION_JSON));
282 final RequestEntity<Void> request = RequestEntity
283 .delete(new URI("http://localhost:" + port + "/so/vnfm-adapter/v1/vnfs/myTestVnfId"))
284 .accept(MediaType.APPLICATION_JSON).header("X-ONAP-RequestId", "myRequestId")
285 .header("X-ONAP-InvocationID", "myInvocationId").header("Content-Type", "application/json").build();
286 final ResponseEntity<DeleteVnfResponse> deleteVnfResponse =
287 restTemplate.exchange(request, DeleteVnfResponse.class);
288 assertEquals(202, deleteVnfResponse.getStatusCode().value());
289 assertNotNull(deleteVnfResponse.getBody().getJobId());
291 final EsrSystemInfo esrSystemInfo = new EsrSystemInfo();
292 esrSystemInfo.setServiceUrl("http://vnfm:8080");
293 esrSystemInfo.setType("vnfmType");
294 esrSystemInfo.setSystemType("VNFM");
295 final EsrSystemInfoList esrSystemInfoList = new EsrSystemInfoList();
296 esrSystemInfoList.getEsrSystemInfo().add(esrSystemInfo);
298 doReturn(Optional.of(esrSystemInfoList)).when(aaiResourcesClient).get(eq(EsrSystemInfoList.class),
299 MockitoHamcrest.argThat(new AaiResourceUriMatcher("/external-system/esr-vnfm-list/esr-vnfm/...")));
301 final ResponseEntity<QueryJobResponse> firstJobQueryResponse =
302 controller.jobQuery(deleteVnfResponse.getBody().getJobId(), "", "so", "1213");
303 assertEquals(OperationEnum.TERMINATE, firstJobQueryResponse.getBody().getOperation());
304 assertEquals(OperationStateEnum.PROCESSING, firstJobQueryResponse.getBody().getOperationState());
305 assertEquals(JAN_1_2019_12_00, firstJobQueryResponse.getBody().getStartTime());
306 assertEquals(JAN_1_2019_1_00, firstJobQueryResponse.getBody().getStateEnteredTime());
308 final ResponseEntity<QueryJobResponse> secondJobQueryResponse =
309 controller.jobQuery(deleteVnfResponse.getBody().getJobId(), "", "so", "1213");
310 assertEquals(OperationEnum.TERMINATE, secondJobQueryResponse.getBody().getOperation());
311 assertEquals(OperationStateEnum.PROCESSING, secondJobQueryResponse.getBody().getOperationState());
312 assertEquals(JAN_1_2019_12_00, secondJobQueryResponse.getBody().getStartTime());
313 assertEquals(JAN_1_2019_1_00, secondJobQueryResponse.getBody().getStateEnteredTime());
317 public void deleteVnf_GenericVnfNotFound_Returns404() throws Exception {
318 final TestRestTemplate restTemplate = new TestRestTemplate("test", "test");
320 final RequestEntity<Void> request = RequestEntity
321 .delete(new URI("http://localhost:" + port + "/so/vnfm-adapter/v1/vnfs/myNonExistingVnfId"))
322 .accept(MediaType.APPLICATION_JSON).header("X-ONAP-RequestId", "myRequestId")
323 .header("X-ONAP-InvocationID", "myInvocationId").header("Content-Type", "application/json").build();
324 final ResponseEntity<DeleteVnfResponse> deleteVnfResponse =
325 restTemplate.exchange(request, DeleteVnfResponse.class);
326 assertEquals(404, deleteVnfResponse.getStatusCode().value());
327 assertNull(deleteVnfResponse.getBody().getJobId());
331 public void deleteVnf_NoAssignedVnfm_Returns400() throws Exception {
332 final TestRestTemplate restTemplate = new TestRestTemplate("test", "test");
334 setUpGenericVnfInMockAai("vnfmType");
336 final RequestEntity<Void> request = RequestEntity
337 .delete(new URI("http://localhost:" + port + "/so/vnfm-adapter/v1/vnfs/myTestVnfId"))
338 .accept(MediaType.APPLICATION_JSON).header("X-ONAP-RequestId", "myRequestId")
339 .header("X-ONAP-InvocationID", "myInvocationId").header("Content-Type", "application/json").build();
340 final ResponseEntity<DeleteVnfResponse> deleteVnfResponse =
341 restTemplate.exchange(request, DeleteVnfResponse.class);
342 assertEquals(400, deleteVnfResponse.getStatusCode().value());
343 assertNull(deleteVnfResponse.getBody().getJobId());
347 public void deleteVnf_ErrorStatusCodeFromVnfm_Returns500() throws Exception {
348 final TestRestTemplate restTemplate = new TestRestTemplate("test", "test");
350 final GenericVnf genericVnf = setUpGenericVnfInMockAai("vnfmType");
351 addSelfLinkToGenericVnf(genericVnf);
352 addRelationshipFromGenericVnfToVnfm(genericVnf, "vnfm");
354 mockRestServer.expect(requestTo("http://vnfm:8080/vnfs/myTestVnfIdOnVnfm/terminate"))
355 .andRespond(withStatus(HttpStatus.BAD_REQUEST).contentType(MediaType.APPLICATION_JSON));
357 final RequestEntity<Void> request = RequestEntity
358 .delete(new URI("http://localhost:" + port + "/so/vnfm-adapter/v1/vnfs/myTestVnfId"))
359 .accept(MediaType.APPLICATION_JSON).header("X-ONAP-RequestId", "myRequestId")
360 .header("X-ONAP-InvocationID", "myInvocationId").header("Content-Type", "application/json").build();
361 final ResponseEntity<DeleteVnfResponse> deleteVnfResponse =
362 restTemplate.exchange(request, DeleteVnfResponse.class);
363 assertEquals(500, deleteVnfResponse.getStatusCode().value());
364 assertNull(deleteVnfResponse.getBody().getJobId());
368 private InlineResponse200 createOperationQueryResponse(
369 final org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse200.OperationEnum operation,
370 final org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse200.OperationStateEnum operationState) {
371 final InlineResponse200 response = new InlineResponse200();
372 response.setId("9876");
373 response.setOperation(operation);
374 response.setOperationState(operationState);
375 response.setStartTime(JAN_1_2019_12_00);
376 response.setStateEnteredTime(JAN_1_2019_1_00);
377 response.setVnfInstanceId("myVnfInstanceId");
381 private GenericVnf createGenericVnf(final String type) {
382 final GenericVnf genericVnf = new GenericVnf();
383 genericVnf.setVnfId("myTestVnfId");
384 genericVnf.setNfType(type);
388 private GenericVnf setUpGenericVnfInMockAai(final String type) {
389 final GenericVnf genericVnf = createGenericVnf(type);
391 doReturn(Optional.of(genericVnf)).when(aaiResourcesClient).get(eq(GenericVnf.class),
392 MockitoHamcrest.argThat(new AaiResourceUriMatcher("/network/generic-vnfs/generic-vnf/myTestVnfId")));
396 private void addSelfLinkToGenericVnf(final GenericVnf vnf) {
397 vnf.setSelflink("http://vnfm:8080/vnfs/myTestVnfIdOnVnfm");
400 private void addRelationshipFromGenericVnfToVnfm(final GenericVnf genericVnf, final String vnfmId) {
401 final Relationship relationshipToVnfm = new Relationship();
402 relationshipToVnfm.setRelatedLink(
403 "/aai/v15/external-system/esr-vnfm-li// final InlineResponse201 vnfInstance = new InlineResponse201();\n"
404 + "// vnfInstance.setInstantiationState(InstantiationStateEnum.NOT_INSTANTIATED);\n"
405 + "// mockRestServer.expect(requestTo(\"http://dummy.value/until/create/implememted/vnfId\"))\n"
406 + "// .andRespond(withSuccess(gson.toJson(vnfInstance), MediaType.APPLICATION_JSON));st/esr-vnfm/"
408 relationshipToVnfm.setRelatedTo("esr-vnfm");
409 final RelationshipData relationshipData = new RelationshipData();
410 relationshipData.setRelationshipKey("esr-vnfm.vnfm-id");
411 relationshipData.setRelationshipValue(vnfmId);
412 relationshipToVnfm.getRelationshipData().add(relationshipData);
414 final RelationshipList relationshipList = new RelationshipList();
415 relationshipList.getRelationship().add(relationshipToVnfm);
416 genericVnf.setRelationshipList(relationshipList);
419 private void setUpVnfmsInMockAai() {
420 final EsrSystemInfo esrSystemInfo1 = new EsrSystemInfo();
421 esrSystemInfo1.setServiceUrl("http://vnfm1:8080");
422 esrSystemInfo1.setType("vnfmType1");
423 esrSystemInfo1.setSystemType("VNFM");
424 final EsrSystemInfoList esrSystemInfoList1 = new EsrSystemInfoList();
425 esrSystemInfoList1.getEsrSystemInfo().add(esrSystemInfo1);
427 final EsrVnfm esrVnfm1 = new EsrVnfm();
428 esrVnfm1.setVnfmId("vnfm1");
429 esrVnfm1.setEsrSystemInfoList(esrSystemInfoList1);
430 esrVnfm1.setResourceVersion("1234");
432 final EsrSystemInfo esrSystemInfo2 = new EsrSystemInfo();
433 esrSystemInfo2.setServiceUrl("http://vnfm2:8080");
434 esrSystemInfo2.setType("vnfmType2");
435 esrSystemInfo2.setSystemType("VNFM");
436 final EsrSystemInfoList esrSystemInfoList2 = new EsrSystemInfoList();
437 esrSystemInfoList2.getEsrSystemInfo().add(esrSystemInfo2);
439 final EsrVnfm esrVnfm2 = new EsrVnfm();
440 esrVnfm2.setVnfmId("vnfm2");
441 esrVnfm2.setEsrSystemInfoList(esrSystemInfoList2);
442 esrVnfm2.setResourceVersion("1234");
444 final EsrVnfmList esrVnfmList = new EsrVnfmList();
445 esrVnfmList.getEsrVnfm().add(esrVnfm1);
446 esrVnfmList.getEsrVnfm().add(esrVnfm2);
448 doReturn(Optional.of(esrVnfmList)).when(aaiResourcesClient).get(eq(EsrVnfmList.class),
449 MockitoHamcrest.argThat(new AaiResourceUriMatcher("/external-system/esr-vnfm-list")));
451 doReturn(Optional.of(esrSystemInfoList1)).when(aaiResourcesClient).get(eq(EsrSystemInfoList.class),
452 MockitoHamcrest.argThat(new AaiResourceUriMatcher(
453 "/external-system/esr-vnfm-list/esr-vnfm/vnfm1/esr-system-info-list")));
454 doReturn(Optional.of(esrSystemInfoList2)).when(aaiResourcesClient).get(eq(EsrSystemInfoList.class),
455 MockitoHamcrest.argThat(new AaiResourceUriMatcher(
456 "/external-system/esr-vnfm-list/esr-vnfm/vnfm2/esr-system-info-list")));
459 private void setUpVimInMockAai() {
460 final EsrSystemInfo esrSystemInfo = new EsrSystemInfo();
461 esrSystemInfo.setServiceUrl("http://myVim:8080");
462 esrSystemInfo.setType("openstack");
463 esrSystemInfo.setSystemType("VIM");
464 esrSystemInfo.setCloudDomain("myDomain");
465 esrSystemInfo.setUserName("myUser");
466 esrSystemInfo.setPassword("myPassword");
468 final EsrSystemInfoList esrSystemInfoList = new EsrSystemInfoList();
469 esrSystemInfoList.getEsrSystemInfo().add(esrSystemInfo);
471 doReturn(Optional.of(esrSystemInfoList)).when(aaiResourcesClient).get(eq(EsrSystemInfoList.class),
472 MockitoHamcrest.argThat(new AaiResourceUriMatcher("/cloud-infrastructure/cloud-regions/cloud-region/"
473 + CLOUD_OWNER + "/" + REGION + "/esr-system-info-list")));
476 private InlineResponse201 createCreateResponse() {
477 final InlineResponse201 createResponse = new InlineResponse201();
478 createResponse.setVnfdId("myTestVnfd");
479 final InlineResponse201Links links = new InlineResponse201Links();
480 final InlineResponse201LinksSelf self = new InlineResponse201LinksSelf();
481 self.setHref("http://vnfm2:8080/vnf_instances/vnfId");
483 createResponse.setLinks(links);
484 createResponse.setId("vnfId");
485 return createResponse;
489 private class AaiResourceUriMatcher extends BaseMatcher<AAIResourceUri> {
491 final String uriAsString;
493 public AaiResourceUriMatcher(final String uriAsString) {
494 this.uriAsString = uriAsString;
498 public boolean matches(final Object item) {
499 if (item instanceof AAIResourceUri) {
500 if (uriAsString.endsWith("...")) {
501 return ((AAIResourceUri) item).build().toString()
502 .startsWith(uriAsString.substring(0, uriAsString.indexOf("...")));
504 return ((AAIResourceUri) item).build().toString().equals(uriAsString);
510 public void describeTo(final Description description) {}