aboutsummaryrefslogtreecommitdiffstats
path: root/so-etsi-sol003-adapter-lcm/so-etsi-sol003-adapter-lcm-service/src/test/java/org/onap/so/adapters/etsisol003adapter/lcm/rest/Sol003LcnControllerTest.java
blob: 0d5bcd257397e6b3953ef10298ee0cb1c1e590d3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
/*-
 * ============LICENSE_START=======================================================
 *  Copyright (C) 2019 Nordix Foundation.
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * SPDX-License-Identifier: Apache-2.0
 * ============LICENSE_END=========================================================
 */

package org.onap.so.adapters.etsisol003adapter.lcm.rest;

import static org.junit.Assert.assertEquals;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.timeout;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyZeroInteractions;
import org.onap.so.adapters.etsisol003adapter.lcm.extclients.vnfm.VnfmRestTemplateConfiguration;
import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo;
import static org.springframework.test.web.client.response.MockRestResponseCreators.withStatus;
import static org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import javax.inject.Inject;
import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.hamcrest.MockitoHamcrest;
import org.onap.aai.domain.yang.EsrSystemInfoList;
import org.onap.aai.domain.yang.EsrVnfm;
import org.onap.aai.domain.yang.GenericVnf;
import org.onap.aai.domain.yang.GenericVnfs;
import org.onap.aai.domain.yang.Relationship;
import org.onap.aai.domain.yang.RelationshipData;
import org.onap.aai.domain.yang.RelationshipList;
import org.onap.aai.domain.yang.Vserver;
import org.onap.aaiclient.client.aai.AAIResourcesClient;
import org.onap.aaiclient.client.aai.entities.uri.AAIBaseResourceUri;
import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri;
import org.onap.so.adapters.etsisol003adapter.lcm.extclients.aai.AaiHelper;
import org.onap.so.adapters.etsisol003adapter.lcm.extclients.aai.OamIpAddressSource;
import org.onap.so.adapters.etsisol003adapter.lcm.extclients.aai.OamIpAddressSource.OamIpAddressType;
import org.onap.so.adapters.etsisol003adapter.lcm.extclients.vim.model.AccessInfo;
import org.onap.so.adapters.etsisol003adapter.lcm.extclients.vnfm.model.InlineResponse201;
import org.onap.so.adapters.etsisol003adapter.lcm.extclients.vnfm.model.InlineResponse201Links;
import org.onap.so.adapters.etsisol003adapter.lcm.extclients.vnfm.model.InlineResponse201LinksSelf;
import org.onap.so.adapters.etsisol003adapter.lcm.extclients.vnfm.model.InlineResponse201VimConnectionInfo;
import org.onap.so.adapters.etsisol003adapter.lcm.lcn.model.LcnVnfLcmOperationOccurrenceNotificationAffectedVnfcs;
import org.onap.so.adapters.etsisol003adapter.lcm.lcn.model.LcnVnfLcmOperationOccurrenceNotificationAffectedVnfcs.ChangeTypeEnum;
import org.onap.so.adapters.etsisol003adapter.lcm.lcn.model.LcnVnfLcmOperationOccurrenceNotificationComputeResource;
import org.onap.so.adapters.etsisol003adapter.lcm.lcn.model.LcnVnfLcmOperationOccurrenceNotificationLinks;
import org.onap.so.adapters.etsisol003adapter.lcm.lcn.model.LcnVnfLcmOperationOccurrenceNotificationLinksVnfInstance;
import org.onap.so.adapters.etsisol003adapter.lcm.lcn.model.VnfIdentifierCreationNotification;
import org.onap.so.adapters.etsisol003adapter.lcm.lcn.model.VnfLcmOperationOccurrenceNotification;
import org.onap.so.adapters.etsisol003adapter.lcm.lcn.model.VnfLcmOperationOccurrenceNotification.OperationEnum;
import org.onap.so.adapters.etsisol003adapter.lcm.lcn.model.VnfLcmOperationOccurrenceNotification.OperationStateEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.boot.web.server.LocalServerPort;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.client.MockRestServiceServer;
import org.springframework.web.client.RestTemplate;
import com.google.gson.Gson;

@RunWith(SpringRunner.class)
@SpringBootTest(classes = TestApplication.class, webEnvironment = WebEnvironment.RANDOM_PORT)
@ActiveProfiles("test")
public class Sol003LcnControllerTest {

    private static final String CLOUD_OWNER = "myTestCloudOwner";
    private static final String REGION = "myTestRegion";
    private static final String TENANT_ID = "myTestTenantId";

    @LocalServerPort
    private int port;
    @Autowired
    @Qualifier(VnfmRestTemplateConfiguration.SOL003_LCM_REST_TEMPLATE)
    private RestTemplate testRestTemplate;
    private MockRestServiceServer mockRestServer;

    @MockBean
    private AAIResourcesClient aaiResourcesClient;

    @Autowired
    private Sol003LcnContoller controller;
    private final Gson gson = new Gson();

    @Inject
    private AaiHelper aaiHelper;

    @Before
    public void setUp() throws Exception {
        mockRestServer = MockRestServiceServer.bindTo(testRestTemplate).build();
    }

    @Test
    public void lcnNotification_IdentifierCreated_Returns204() throws URISyntaxException, InterruptedException {
        final VnfIdentifierCreationNotification vnfIdentifierCreationNotification =
                new VnfIdentifierCreationNotification();
        final ResponseEntity<Void> response =
                controller.lcnVnfIdentifierCreationNotificationPost(vnfIdentifierCreationNotification);
        assertEquals(HttpStatus.NO_CONTENT, response.getStatusCode());
    }

    @Test
    public void lcnNotification_IdentifierDeleted_Returns204() throws URISyntaxException, InterruptedException {
        final VnfIdentifierCreationNotification vnfIdentifierCreationNotification =
                new VnfIdentifierCreationNotification();
        final ResponseEntity<Void> response =
                controller.lcnVnfIdentifierCreationNotificationPost(vnfIdentifierCreationNotification);
        assertEquals(HttpStatus.NO_CONTENT, response.getStatusCode());
    }

    @Test
    public void lcnNotification_InstantiateStartingOrProcessing_NoAction()
            throws URISyntaxException, InterruptedException {
        final VnfLcmOperationOccurrenceNotification startingNotification = new VnfLcmOperationOccurrenceNotification();
        startingNotification.setOperation(OperationEnum.INSTANTIATE);
        startingNotification.setOperationState(OperationStateEnum.STARTING);

        ResponseEntity<Void> response = controller.lcnVnfLcmOperationOccurrenceNotificationPost(startingNotification);
        assertEquals(HttpStatus.NO_CONTENT, response.getStatusCode());

        verifyZeroInteractions(aaiResourcesClient);

        final VnfLcmOperationOccurrenceNotification processingNotification =
                new VnfLcmOperationOccurrenceNotification();
        processingNotification.setOperation(OperationEnum.INSTANTIATE);
        processingNotification.setOperationState(OperationStateEnum.STARTING);

        response = controller.lcnVnfLcmOperationOccurrenceNotificationPost(processingNotification);
        assertEquals(HttpStatus.NO_CONTENT, response.getStatusCode());

        verifyZeroInteractions(aaiResourcesClient);
    }

    @Test
    public void lcnNotification_InstantiateCompleted_AaiUpdated() throws URISyntaxException, InterruptedException {
        final VnfLcmOperationOccurrenceNotification vnfLcmOperationOccurrenceNotification =
                createNotification(OperationEnum.INSTANTIATE);
        addVnfcsToNotification(vnfLcmOperationOccurrenceNotification, ChangeTypeEnum.ADDED);
        final InlineResponse201 vnfInstance = createVnfInstance();

        mockRestServer.expect(requestTo(new URI("http://vnfm:8080/vnfs/myTestVnfIdOnVnfm")))
                .andRespond(withSuccess(gson.toJson(vnfInstance), MediaType.APPLICATION_JSON));

        final GenericVnf genericVnf = createGenericVnf("vnfmType1");
        addRelationshipFromGenericVnfToVnfm(genericVnf, "vnfm1");
        final List<GenericVnf> listOfGenericVnfs = new ArrayList<>();
        listOfGenericVnfs.add(genericVnf);
        final GenericVnfs genericVnfs = new GenericVnfs();
        genericVnfs.getGenericVnf().addAll(listOfGenericVnfs);
        doReturn(Optional.of(genericVnfs)).when(aaiResourcesClient).get(eq(GenericVnfs.class),
                MockitoHamcrest.argThat(new AaiResourceUriMatcher(
                        "/network/generic-vnfs?selflink=http%3A%2F%2Fvnfm%3A8080%2Fvnfs%2FmyTestVnfIdOnVnfm")));
        final EsrVnfm vnfm = new EsrVnfm();
        vnfm.setVnfmId("vnfm1");
        final EsrSystemInfoList esrSystemInfoList = new EsrSystemInfoList();
        vnfm.setEsrSystemInfoList(esrSystemInfoList);
        doReturn(Optional.of(vnfm)).when(aaiResourcesClient).get(eq(EsrVnfm.class), MockitoHamcrest
                .argThat(new AaiResourceUriMatcher("/external-system/esr-vnfm-list/esr-vnfm/vnfm1?depth=1")));

        final ResponseEntity<Void> response =
                controller.lcnVnfLcmOperationOccurrenceNotificationPost(vnfLcmOperationOccurrenceNotification);
        assertEquals(HttpStatus.NO_CONTENT, response.getStatusCode());

        final ArgumentCaptor<Object> bodyArgument1 = ArgumentCaptor.forClass(Object.class);
        final ArgumentCaptor<AAIResourceUri> uriArgument1 = ArgumentCaptor.forClass(AAIResourceUri.class);

        verify(aaiResourcesClient, timeout(1000)).update(uriArgument1.capture(), bodyArgument1.capture());

        assertEquals("/network/generic-vnfs/generic-vnf/myTestVnfId",
                uriArgument1.getAllValues().get(0).build().toString());
        final GenericVnf updatedGenericVnf = (GenericVnf) bodyArgument1.getAllValues().get(0);
        assertEquals("10.10.10.10", updatedGenericVnf.getIpv4OamAddress());
        assertEquals("Created", updatedGenericVnf.getOrchestrationStatus());

        final ArgumentCaptor<Object> bodyArgument2 = ArgumentCaptor.forClass(Object.class);
        final ArgumentCaptor<AAIResourceUri> uriArgument2 = ArgumentCaptor.forClass(AAIResourceUri.class);
        verify(aaiResourcesClient, timeout(1000)).create(uriArgument2.capture(), bodyArgument2.capture());

        assertEquals(
                "/cloud-infrastructure/cloud-regions/cloud-region/" + CLOUD_OWNER + "/" + REGION + "/tenants/tenant/"
                        + TENANT_ID + "/vservers/vserver/myVnfc1",
                uriArgument2.getAllValues().get(0).build().toString());

        final Vserver vserver = (Vserver) bodyArgument2.getAllValues().get(0);
        assertEquals("myVnfc1", vserver.getVserverId());

        final ArgumentCaptor<AAIResourceUri> uriArgument1Connect = ArgumentCaptor.forClass(AAIResourceUri.class);
        final ArgumentCaptor<AAIResourceUri> uriArgument2Connect = ArgumentCaptor.forClass(AAIResourceUri.class);
        verify(aaiResourcesClient, timeout(1000)).connect(uriArgument1Connect.capture(), uriArgument2Connect.capture());
        assertEquals(
                "/cloud-infrastructure/cloud-regions/cloud-region/" + CLOUD_OWNER + "/" + REGION + "/tenants/tenant/"
                        + TENANT_ID + "/vservers/vserver/myVnfc1",
                uriArgument1Connect.getAllValues().get(0).build().toString());
        assertEquals("/network/generic-vnfs/generic-vnf/myTestVnfId",
                uriArgument2Connect.getAllValues().get(0).build().toString());
    }

    @Test
    public void lcnNotification_TerminateCompleted_AaiUpdated() throws URISyntaxException, InterruptedException {
        final VnfLcmOperationOccurrenceNotification vnfLcmOperationOccurrenceNotification =
                createNotification(OperationEnum.TERMINATE);
        addVnfcsToNotification(vnfLcmOperationOccurrenceNotification, ChangeTypeEnum.REMOVED);

        final InlineResponse201 vnfInstance = createVnfInstance();

        mockRestServer.expect(requestTo(new URI("http://vnfm:8080/vnfs/myTestVnfIdOnVnfm")))
                .andRespond(withSuccess(gson.toJson(vnfInstance), MediaType.APPLICATION_JSON));

        mockRestServer.expect(requestTo(new URI("http://vnfm:8080/vnfs/myTestVnfIdOnVnfm")))
                .andRespond(withStatus(HttpStatus.NO_CONTENT).contentType(MediaType.APPLICATION_JSON));

        final GenericVnf genericVnf = createGenericVnf("vnfmType1");
        addRelationshipFromGenericVnfToVnfm(genericVnf, "vnfm1");
        genericVnf.setSelflink("http://vnfm:8080/vnfs/myTestVnfIdOnVnfm");
        final List<GenericVnf> listOfGenericVnfs = new ArrayList<>();
        listOfGenericVnfs.add(genericVnf);
        final GenericVnfs genericVnfs = new GenericVnfs();
        genericVnfs.getGenericVnf().addAll(listOfGenericVnfs);
        addRelationshipFromGenericVnfToVserver(genericVnf, "myVnfc1");

        doReturn(Optional.of(genericVnfs)).when(aaiResourcesClient).get(eq(GenericVnfs.class),
                MockitoHamcrest.argThat(new AaiResourceUriMatcher(
                        "/network/generic-vnfs?selflink=http%3A%2F%2Fvnfm%3A8080%2Fvnfs%2FmyTestVnfIdOnVnfm")));
        final EsrVnfm vnfm = new EsrVnfm();
        vnfm.setVnfmId("vnfm1");
        final EsrSystemInfoList esrSystemInfoList = new EsrSystemInfoList();
        vnfm.setEsrSystemInfoList(esrSystemInfoList);
        doReturn(Optional.of(vnfm)).when(aaiResourcesClient).get(eq(EsrVnfm.class), MockitoHamcrest
                .argThat(new AaiResourceUriMatcher("/external-system/esr-vnfm-list/esr-vnfm/vnfm1?depth=1")));

        final ResponseEntity<Void> response =
                controller.lcnVnfLcmOperationOccurrenceNotificationPost(vnfLcmOperationOccurrenceNotification);
        assertEquals(HttpStatus.NO_CONTENT, response.getStatusCode());

        final ArgumentCaptor<GenericVnf> genericVnfArgument = ArgumentCaptor.forClass(GenericVnf.class);
        final ArgumentCaptor<AAIResourceUri> updateUriArgument = ArgumentCaptor.forClass(AAIResourceUri.class);
        verify(aaiResourcesClient, timeout(10000000)).update(updateUriArgument.capture(), genericVnfArgument.capture());
        assertEquals("/network/generic-vnfs/generic-vnf/myTestVnfId", updateUriArgument.getValue().build().toString());
        assertEquals("Assigned", genericVnfArgument.getValue().getOrchestrationStatus());

        final ArgumentCaptor<AAIResourceUri> deleteUriArgument = ArgumentCaptor.forClass(AAIResourceUri.class);

        verify(aaiResourcesClient, timeout(10000000)).delete(deleteUriArgument.capture());

        assertEquals(
                "/cloud-infrastructure/cloud-regions/cloud-region/" + CLOUD_OWNER + "/" + REGION + "/tenants/tenant/"
                        + TENANT_ID + "/vservers/vserver/myVnfc1",
                deleteUriArgument.getAllValues().get(0).build().toString());
    }

    private VnfLcmOperationOccurrenceNotification createNotification(final OperationEnum operation) {
        final VnfLcmOperationOccurrenceNotification notification = new VnfLcmOperationOccurrenceNotification();
        notification.setOperation(operation);
        notification.setOperationState(OperationStateEnum.COMPLETED);

        final LcnVnfLcmOperationOccurrenceNotificationLinksVnfInstance linkToVnfInstance =
                new LcnVnfLcmOperationOccurrenceNotificationLinksVnfInstance()
                        .href("http://vnfm:8080/vnfs/myTestVnfIdOnVnfm");
        final LcnVnfLcmOperationOccurrenceNotificationLinks operationLinks =
                new LcnVnfLcmOperationOccurrenceNotificationLinks().vnfInstance(linkToVnfInstance);
        notification.setLinks(operationLinks);

        return notification;
    }

    private void addVnfcsToNotification(final VnfLcmOperationOccurrenceNotification notification,
            final ChangeTypeEnum changeType) {
        final List<LcnVnfLcmOperationOccurrenceNotificationAffectedVnfcs> affectedVnfcs = new ArrayList<>();;
        final LcnVnfLcmOperationOccurrenceNotificationAffectedVnfcs vnfc =
                new LcnVnfLcmOperationOccurrenceNotificationAffectedVnfcs();
        vnfc.changeType(changeType);
        final LcnVnfLcmOperationOccurrenceNotificationComputeResource computeResource =
                new LcnVnfLcmOperationOccurrenceNotificationComputeResource();
        computeResource.setResourceId("myVnfc1");
        computeResource.setVimConnectionId(CLOUD_OWNER + "_" + REGION);
        vnfc.setComputeResource(computeResource);
        affectedVnfcs.add(vnfc);
        notification.setAffectedVnfcs(affectedVnfcs);
    }

    private InlineResponse201 createVnfInstance() {
        final InlineResponse201 vnfInstance = new InlineResponse201();
        vnfInstance.setId("myTestVnfIdOnVnfm");
        final InlineResponse201LinksSelf selfLink = new InlineResponse201LinksSelf();
        selfLink.setHref("http://vnfm:8080/vnfs/myTestVnfIdOnVnfm");
        final InlineResponse201Links VnfInstancelinks = new InlineResponse201Links();
        VnfInstancelinks.setSelf(selfLink);
        vnfInstance.setLinks(VnfInstancelinks);

        final Map<String, String> vnfConfigurableProperties = new HashMap<>();
        vnfConfigurableProperties.put("vnfIpAddress", "10.10.10.10");
        vnfInstance.setVnfConfigurableProperties(vnfConfigurableProperties);

        final List<InlineResponse201VimConnectionInfo> vimConnectionInfo = new ArrayList<>();;
        final InlineResponse201VimConnectionInfo vimConnection = new InlineResponse201VimConnectionInfo();
        vimConnection.setVimId(CLOUD_OWNER + "_" + REGION);
        vimConnection.setId(CLOUD_OWNER + "_" + REGION);
        final AccessInfo accessInfo = new AccessInfo();
        accessInfo.setProjectId(TENANT_ID);
        vimConnection.setAccessInfo(accessInfo);
        vimConnectionInfo.add(vimConnection);
        vnfInstance.setVimConnectionInfo(vimConnectionInfo);

        final OamIpAddressSource oamIpAddressSource =
                new OamIpAddressSource(OamIpAddressType.CONFIGURABLE_PROPERTY, "vnfIpAddress");
        aaiHelper.setOamIpAddressSource("myTestVnfIdOnVnfm", oamIpAddressSource);
        return vnfInstance;
    }

    private GenericVnf createGenericVnf(final String type) {
        final GenericVnf genericVnf = new GenericVnf();
        genericVnf.setVnfId("myTestVnfId");
        genericVnf.setNfType(type);
        return genericVnf;
    }

    private void addRelationshipFromGenericVnfToVnfm(final GenericVnf genericVnf, final String vnfmId) {
        final Relationship relationshipToVnfm = new Relationship();
        relationshipToVnfm.setRelatedLink("/aai/v15/external-system/esr-vnfm-list/esr-vnfm/" + vnfmId);
        relationshipToVnfm.setRelatedTo("esr-vnfm");
        final RelationshipData relationshipData = new RelationshipData();
        relationshipData.setRelationshipKey("esr-vnfm.vnfm-id");
        relationshipData.setRelationshipValue(vnfmId);
        relationshipToVnfm.getRelationshipData().add(relationshipData);

        if (genericVnf.getRelationshipList() == null) {
            final RelationshipList relationshipList = new RelationshipList();
            genericVnf.setRelationshipList(relationshipList);
        }
        genericVnf.getRelationshipList().getRelationship().add(relationshipToVnfm);
    }

    private void addRelationshipFromGenericVnfToVserver(final GenericVnf genericVnf, final String vserverId) {
        final Relationship relationshipToVserver = new Relationship();
        relationshipToVserver.setRelatedTo("vserver");
        final RelationshipData relationshipData1 = new RelationshipData();
        relationshipData1.setRelationshipKey("vserver.vserver-id");
        relationshipData1.setRelationshipValue(vserverId);
        relationshipToVserver.getRelationshipData().add(relationshipData1);
        final RelationshipData relationshipData2 = new RelationshipData();
        relationshipData2.setRelationshipKey("cloud-region.cloud-owner");
        relationshipData2.setRelationshipValue(CLOUD_OWNER);
        relationshipToVserver.getRelationshipData().add(relationshipData2);
        final RelationshipData relationshipData3 = new RelationshipData();
        relationshipData3.setRelationshipKey("cloud-region.cloud-region-id");
        relationshipData3.setRelationshipValue(REGION);
        relationshipToVserver.getRelationshipData().add(relationshipData3);
        final RelationshipData relationshipData4 = new RelationshipData();
        relationshipData4.setRelationshipKey("tenant.tenant-id");
        relationshipData4.setRelationshipValue(TENANT_ID);
        relationshipToVserver.getRelationshipData().add(relationshipData4);

        if (genericVnf.getRelationshipList() == null) {
            final RelationshipList relationshipList = new RelationshipList();
            genericVnf.setRelationshipList(relationshipList);
        }
        genericVnf.getRelationshipList().getRelationship().add(relationshipToVserver);
    }

    private class AaiResourceUriMatcher extends BaseMatcher<AAIBaseResourceUri<?, ?>> {

        final String uriAsString;

        public AaiResourceUriMatcher(final String uriAsString) {
            this.uriAsString = uriAsString;
        }

        @Override
        public boolean matches(final Object item) {
            if (item instanceof AAIBaseResourceUri<?, ?>) {
                if (uriAsString.endsWith("...")) {
                    return ((AAIBaseResourceUri<?, ?>) item).build().toString()
                            .startsWith(uriAsString.substring(0, uriAsString.indexOf("...")));
                }
                return ((AAIBaseResourceUri<?, ?>) item).build().toString().equals(uriAsString);
            }
            return false;
        }

        @Override
        public void describeTo(final Description description) {}

    }

}