Merge "add fluent type builder support to A&AI client"
[so.git] / adapters / etsi-sol003-adapter / etsi-sol003-lcm / etsi-sol003-lcm-adapter / src / test / java / org / onap / so / adapters / etsisol003adapter / lcm / rest / Sol003LcnControllerTest.java
1 /*-
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
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.so.adapters.etsisol003adapter.lcm.rest;
22
23 import static org.junit.Assert.assertEquals;
24 import static org.mockito.ArgumentMatchers.eq;
25 import static org.mockito.Mockito.doReturn;
26 import static org.mockito.Mockito.timeout;
27 import static org.mockito.Mockito.verify;
28 import static org.mockito.Mockito.verifyZeroInteractions;
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 java.net.URI;
34 import java.net.URISyntaxException;
35 import java.util.ArrayList;
36 import java.util.HashMap;
37 import java.util.List;
38 import java.util.Map;
39 import java.util.Optional;
40 import javax.inject.Inject;
41 import org.hamcrest.BaseMatcher;
42 import org.hamcrest.Description;
43 import org.junit.Before;
44 import org.junit.Test;
45 import org.junit.runner.RunWith;
46 import org.mockito.ArgumentCaptor;
47 import org.mockito.hamcrest.MockitoHamcrest;
48 import org.onap.aai.domain.yang.EsrSystemInfoList;
49 import org.onap.aai.domain.yang.EsrVnfm;
50 import org.onap.aai.domain.yang.GenericVnf;
51 import org.onap.aai.domain.yang.GenericVnfs;
52 import org.onap.aai.domain.yang.Relationship;
53 import org.onap.aai.domain.yang.RelationshipData;
54 import org.onap.aai.domain.yang.RelationshipList;
55 import org.onap.aai.domain.yang.Vserver;
56 import org.onap.aaiclient.client.aai.AAIResourcesClient;
57 import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri;
58 import org.onap.so.adapters.etsisol003adapter.lcm.extclients.aai.AaiHelper;
59 import org.onap.so.adapters.etsisol003adapter.lcm.extclients.aai.OamIpAddressSource;
60 import org.onap.so.adapters.etsisol003adapter.lcm.extclients.aai.OamIpAddressSource.OamIpAddressType;
61 import org.onap.so.adapters.etsisol003adapter.lcm.extclients.vim.model.AccessInfo;
62 import org.onap.so.adapters.etsisol003adapter.lcm.extclients.vnfm.model.InlineResponse201;
63 import org.onap.so.adapters.etsisol003adapter.lcm.extclients.vnfm.model.InlineResponse201Links;
64 import org.onap.so.adapters.etsisol003adapter.lcm.extclients.vnfm.model.InlineResponse201LinksSelf;
65 import org.onap.so.adapters.etsisol003adapter.lcm.extclients.vnfm.model.InlineResponse201VimConnectionInfo;
66 import org.onap.so.adapters.etsisol003adapter.lcm.lcn.model.LcnVnfLcmOperationOccurrenceNotificationAffectedVnfcs;
67 import org.onap.so.adapters.etsisol003adapter.lcm.lcn.model.LcnVnfLcmOperationOccurrenceNotificationAffectedVnfcs.ChangeTypeEnum;
68 import org.onap.so.adapters.etsisol003adapter.lcm.lcn.model.LcnVnfLcmOperationOccurrenceNotificationComputeResource;
69 import org.onap.so.adapters.etsisol003adapter.lcm.lcn.model.LcnVnfLcmOperationOccurrenceNotificationLinks;
70 import org.onap.so.adapters.etsisol003adapter.lcm.lcn.model.LcnVnfLcmOperationOccurrenceNotificationLinksVnfInstance;
71 import org.onap.so.adapters.etsisol003adapter.lcm.lcn.model.VnfIdentifierCreationNotification;
72 import org.onap.so.adapters.etsisol003adapter.lcm.lcn.model.VnfLcmOperationOccurrenceNotification;
73 import org.onap.so.adapters.etsisol003adapter.lcm.lcn.model.VnfLcmOperationOccurrenceNotification.OperationEnum;
74 import org.onap.so.adapters.etsisol003adapter.lcm.lcn.model.VnfLcmOperationOccurrenceNotification.OperationStateEnum;
75 import org.springframework.beans.factory.annotation.Autowired;
76 import org.springframework.beans.factory.annotation.Qualifier;
77 import org.springframework.boot.test.context.SpringBootTest;
78 import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
79 import org.springframework.boot.test.mock.mockito.MockBean;
80 import org.springframework.boot.web.server.LocalServerPort;
81 import org.springframework.http.HttpStatus;
82 import org.springframework.http.MediaType;
83 import org.springframework.http.ResponseEntity;
84 import org.springframework.test.context.ActiveProfiles;
85 import org.springframework.test.context.junit4.SpringRunner;
86 import org.springframework.test.web.client.MockRestServiceServer;
87 import org.springframework.web.client.RestTemplate;
88 import com.google.gson.Gson;
89
90 @RunWith(SpringRunner.class)
91 @SpringBootTest(classes = TestApplication.class, webEnvironment = WebEnvironment.RANDOM_PORT)
92 @ActiveProfiles("test")
93 public class Sol003LcnControllerTest {
94
95     private static final String CLOUD_OWNER = "myTestCloudOwner";
96     private static final String REGION = "myTestRegion";
97     private static final String TENANT_ID = "myTestTenantId";
98
99     @LocalServerPort
100     private int port;
101     @Autowired
102     @Qualifier(CONFIGURABLE_REST_TEMPLATE)
103     private RestTemplate testRestTemplate;
104     private MockRestServiceServer mockRestServer;
105
106     @MockBean
107     private AAIResourcesClient aaiResourcesClient;
108
109     @Autowired
110     private Sol003LcnContoller controller;
111     private final Gson gson = new Gson();
112
113     @Inject
114     private AaiHelper aaiHelper;
115
116     @Before
117     public void setUp() throws Exception {
118         mockRestServer = MockRestServiceServer.bindTo(testRestTemplate).build();
119     }
120
121     @Test
122     public void lcnNotification_IdentifierCreated_Returns204() throws URISyntaxException, InterruptedException {
123         final VnfIdentifierCreationNotification vnfIdentifierCreationNotification =
124                 new VnfIdentifierCreationNotification();
125         final ResponseEntity<Void> response =
126                 controller.lcnVnfIdentifierCreationNotificationPost(vnfIdentifierCreationNotification);
127         assertEquals(HttpStatus.NO_CONTENT, response.getStatusCode());
128     }
129
130     @Test
131     public void lcnNotification_IdentifierDeleted_Returns204() throws URISyntaxException, InterruptedException {
132         final VnfIdentifierCreationNotification vnfIdentifierCreationNotification =
133                 new VnfIdentifierCreationNotification();
134         final ResponseEntity<Void> response =
135                 controller.lcnVnfIdentifierCreationNotificationPost(vnfIdentifierCreationNotification);
136         assertEquals(HttpStatus.NO_CONTENT, response.getStatusCode());
137     }
138
139     @Test
140     public void lcnNotification_InstantiateStartingOrProcessing_NoAction()
141             throws URISyntaxException, InterruptedException {
142         final VnfLcmOperationOccurrenceNotification startingNotification = new VnfLcmOperationOccurrenceNotification();
143         startingNotification.setOperation(OperationEnum.INSTANTIATE);
144         startingNotification.setOperationState(OperationStateEnum.STARTING);
145
146         ResponseEntity<Void> response = controller.lcnVnfLcmOperationOccurrenceNotificationPost(startingNotification);
147         assertEquals(HttpStatus.NO_CONTENT, response.getStatusCode());
148
149         verifyZeroInteractions(aaiResourcesClient);
150
151         final VnfLcmOperationOccurrenceNotification processingNotification =
152                 new VnfLcmOperationOccurrenceNotification();
153         processingNotification.setOperation(OperationEnum.INSTANTIATE);
154         processingNotification.setOperationState(OperationStateEnum.STARTING);
155
156         response = controller.lcnVnfLcmOperationOccurrenceNotificationPost(processingNotification);
157         assertEquals(HttpStatus.NO_CONTENT, response.getStatusCode());
158
159         verifyZeroInteractions(aaiResourcesClient);
160     }
161
162     @Test
163     public void lcnNotification_InstantiateCompleted_AaiUpdated() throws URISyntaxException, InterruptedException {
164         final VnfLcmOperationOccurrenceNotification vnfLcmOperationOccurrenceNotification =
165                 createNotification(OperationEnum.INSTANTIATE);
166         addVnfcsToNotification(vnfLcmOperationOccurrenceNotification, ChangeTypeEnum.ADDED);
167         final InlineResponse201 vnfInstance = createVnfInstance();
168
169         mockRestServer.expect(requestTo(new URI("http://vnfm:8080/vnfs/myTestVnfIdOnVnfm")))
170                 .andRespond(withSuccess(gson.toJson(vnfInstance), MediaType.APPLICATION_JSON));
171
172         final GenericVnf genericVnf = createGenericVnf("vnfmType1");
173         addRelationshipFromGenericVnfToVnfm(genericVnf, "vnfm1");
174         final List<GenericVnf> listOfGenericVnfs = new ArrayList<>();
175         listOfGenericVnfs.add(genericVnf);
176         final GenericVnfs genericVnfs = new GenericVnfs();
177         genericVnfs.getGenericVnf().addAll(listOfGenericVnfs);
178         doReturn(Optional.of(genericVnfs)).when(aaiResourcesClient).get(eq(GenericVnfs.class),
179                 MockitoHamcrest.argThat(new AaiResourceUriMatcher(
180                         "/network/generic-vnfs?selflink=http%3A%2F%2Fvnfm%3A8080%2Fvnfs%2FmyTestVnfIdOnVnfm")));
181         final EsrVnfm vnfm = new EsrVnfm();
182         vnfm.setVnfmId("vnfm1");
183         final EsrSystemInfoList esrSystemInfoList = new EsrSystemInfoList();
184         vnfm.setEsrSystemInfoList(esrSystemInfoList);
185         doReturn(Optional.of(vnfm)).when(aaiResourcesClient).get(eq(EsrVnfm.class), MockitoHamcrest
186                 .argThat(new AaiResourceUriMatcher("/external-system/esr-vnfm-list/esr-vnfm/vnfm1?depth=1")));
187
188         final ResponseEntity<Void> response =
189                 controller.lcnVnfLcmOperationOccurrenceNotificationPost(vnfLcmOperationOccurrenceNotification);
190         assertEquals(HttpStatus.NO_CONTENT, response.getStatusCode());
191
192         final ArgumentCaptor<Object> bodyArgument1 = ArgumentCaptor.forClass(Object.class);
193         final ArgumentCaptor<AAIResourceUri> uriArgument1 = ArgumentCaptor.forClass(AAIResourceUri.class);
194
195         verify(aaiResourcesClient, timeout(1000)).update(uriArgument1.capture(), bodyArgument1.capture());
196
197         assertEquals("/network/generic-vnfs/generic-vnf/myTestVnfId",
198                 uriArgument1.getAllValues().get(0).build().toString());
199         final GenericVnf updatedGenericVnf = (GenericVnf) bodyArgument1.getAllValues().get(0);
200         assertEquals("10.10.10.10", updatedGenericVnf.getIpv4OamAddress());
201         assertEquals("Created", updatedGenericVnf.getOrchestrationStatus());
202
203         final ArgumentCaptor<Object> bodyArgument2 = ArgumentCaptor.forClass(Object.class);
204         final ArgumentCaptor<AAIResourceUri> uriArgument2 = ArgumentCaptor.forClass(AAIResourceUri.class);
205         verify(aaiResourcesClient, timeout(1000)).create(uriArgument2.capture(), bodyArgument2.capture());
206
207         assertEquals(
208                 "/cloud-infrastructure/cloud-regions/cloud-region/" + CLOUD_OWNER + "/" + REGION + "/tenants/tenant/"
209                         + TENANT_ID + "/vservers/vserver/myVnfc1",
210                 uriArgument2.getAllValues().get(0).build().toString());
211
212         final Vserver vserver = (Vserver) bodyArgument2.getAllValues().get(0);
213         assertEquals("myVnfc1", vserver.getVserverId());
214
215         final ArgumentCaptor<AAIResourceUri> uriArgument1Connect = ArgumentCaptor.forClass(AAIResourceUri.class);
216         final ArgumentCaptor<AAIResourceUri> uriArgument2Connect = ArgumentCaptor.forClass(AAIResourceUri.class);
217         verify(aaiResourcesClient, timeout(1000)).connect(uriArgument1Connect.capture(), uriArgument2Connect.capture());
218         assertEquals(
219                 "/cloud-infrastructure/cloud-regions/cloud-region/" + CLOUD_OWNER + "/" + REGION + "/tenants/tenant/"
220                         + TENANT_ID + "/vservers/vserver/myVnfc1",
221                 uriArgument1Connect.getAllValues().get(0).build().toString());
222         assertEquals("/network/generic-vnfs/generic-vnf/myTestVnfId",
223                 uriArgument2Connect.getAllValues().get(0).build().toString());
224     }
225
226     @Test
227     public void lcnNotification_TerminateCompleted_AaiUpdated() throws URISyntaxException, InterruptedException {
228         final VnfLcmOperationOccurrenceNotification vnfLcmOperationOccurrenceNotification =
229                 createNotification(OperationEnum.TERMINATE);
230         addVnfcsToNotification(vnfLcmOperationOccurrenceNotification, ChangeTypeEnum.REMOVED);
231
232         final InlineResponse201 vnfInstance = createVnfInstance();
233
234         mockRestServer.expect(requestTo(new URI("http://vnfm:8080/vnfs/myTestVnfIdOnVnfm")))
235                 .andRespond(withSuccess(gson.toJson(vnfInstance), MediaType.APPLICATION_JSON));
236
237         mockRestServer.expect(requestTo(new URI("http://vnfm:8080/vnfs/myTestVnfIdOnVnfm")))
238                 .andRespond(withStatus(HttpStatus.NO_CONTENT).contentType(MediaType.APPLICATION_JSON));
239
240         final GenericVnf genericVnf = createGenericVnf("vnfmType1");
241         addRelationshipFromGenericVnfToVnfm(genericVnf, "vnfm1");
242         genericVnf.setSelflink("http://vnfm:8080/vnfs/myTestVnfIdOnVnfm");
243         final List<GenericVnf> listOfGenericVnfs = new ArrayList<>();
244         listOfGenericVnfs.add(genericVnf);
245         final GenericVnfs genericVnfs = new GenericVnfs();
246         genericVnfs.getGenericVnf().addAll(listOfGenericVnfs);
247         addRelationshipFromGenericVnfToVserver(genericVnf, "myVnfc1");
248
249         doReturn(Optional.of(genericVnfs)).when(aaiResourcesClient).get(eq(GenericVnfs.class),
250                 MockitoHamcrest.argThat(new AaiResourceUriMatcher(
251                         "/network/generic-vnfs?selflink=http%3A%2F%2Fvnfm%3A8080%2Fvnfs%2FmyTestVnfIdOnVnfm")));
252         final EsrVnfm vnfm = new EsrVnfm();
253         vnfm.setVnfmId("vnfm1");
254         final EsrSystemInfoList esrSystemInfoList = new EsrSystemInfoList();
255         vnfm.setEsrSystemInfoList(esrSystemInfoList);
256         doReturn(Optional.of(vnfm)).when(aaiResourcesClient).get(eq(EsrVnfm.class), MockitoHamcrest
257                 .argThat(new AaiResourceUriMatcher("/external-system/esr-vnfm-list/esr-vnfm/vnfm1?depth=1")));
258
259         final ResponseEntity<Void> response =
260                 controller.lcnVnfLcmOperationOccurrenceNotificationPost(vnfLcmOperationOccurrenceNotification);
261         assertEquals(HttpStatus.NO_CONTENT, response.getStatusCode());
262
263         final ArgumentCaptor<GenericVnf> genericVnfArgument = ArgumentCaptor.forClass(GenericVnf.class);
264         final ArgumentCaptor<AAIResourceUri> updateUriArgument = ArgumentCaptor.forClass(AAIResourceUri.class);
265         verify(aaiResourcesClient, timeout(10000000)).update(updateUriArgument.capture(), genericVnfArgument.capture());
266         assertEquals("/network/generic-vnfs/generic-vnf/myTestVnfId", updateUriArgument.getValue().build().toString());
267         assertEquals("Assigned", genericVnfArgument.getValue().getOrchestrationStatus());
268
269         final ArgumentCaptor<AAIResourceUri> deleteUriArgument = ArgumentCaptor.forClass(AAIResourceUri.class);
270
271         verify(aaiResourcesClient, timeout(10000000)).delete(deleteUriArgument.capture());
272
273         assertEquals(
274                 "/cloud-infrastructure/cloud-regions/cloud-region/" + CLOUD_OWNER + "/" + REGION + "/tenants/tenant/"
275                         + TENANT_ID + "/vservers/vserver/myVnfc1",
276                 deleteUriArgument.getAllValues().get(0).build().toString());
277     }
278
279     private VnfLcmOperationOccurrenceNotification createNotification(final OperationEnum operation) {
280         final VnfLcmOperationOccurrenceNotification notification = new VnfLcmOperationOccurrenceNotification();
281         notification.setOperation(operation);
282         notification.setOperationState(OperationStateEnum.COMPLETED);
283
284         final LcnVnfLcmOperationOccurrenceNotificationLinksVnfInstance linkToVnfInstance =
285                 new LcnVnfLcmOperationOccurrenceNotificationLinksVnfInstance()
286                         .href("http://vnfm:8080/vnfs/myTestVnfIdOnVnfm");
287         final LcnVnfLcmOperationOccurrenceNotificationLinks operationLinks =
288                 new LcnVnfLcmOperationOccurrenceNotificationLinks().vnfInstance(linkToVnfInstance);
289         notification.setLinks(operationLinks);
290
291         return notification;
292     }
293
294     private void addVnfcsToNotification(final VnfLcmOperationOccurrenceNotification notification,
295             final ChangeTypeEnum changeType) {
296         final List<LcnVnfLcmOperationOccurrenceNotificationAffectedVnfcs> affectedVnfcs = new ArrayList<>();;
297         final LcnVnfLcmOperationOccurrenceNotificationAffectedVnfcs vnfc =
298                 new LcnVnfLcmOperationOccurrenceNotificationAffectedVnfcs();
299         vnfc.changeType(changeType);
300         final LcnVnfLcmOperationOccurrenceNotificationComputeResource computeResource =
301                 new LcnVnfLcmOperationOccurrenceNotificationComputeResource();
302         computeResource.setResourceId("myVnfc1");
303         computeResource.setVimConnectionId(CLOUD_OWNER + "_" + REGION);
304         vnfc.setComputeResource(computeResource);
305         affectedVnfcs.add(vnfc);
306         notification.setAffectedVnfcs(affectedVnfcs);
307     }
308
309     private InlineResponse201 createVnfInstance() {
310         final InlineResponse201 vnfInstance = new InlineResponse201();
311         vnfInstance.setId("myTestVnfIdOnVnfm");
312         final InlineResponse201LinksSelf selfLink = new InlineResponse201LinksSelf();
313         selfLink.setHref("http://vnfm:8080/vnfs/myTestVnfIdOnVnfm");
314         final InlineResponse201Links VnfInstancelinks = new InlineResponse201Links();
315         VnfInstancelinks.setSelf(selfLink);
316         vnfInstance.setLinks(VnfInstancelinks);
317
318         final Map<String, String> vnfConfigurableProperties = new HashMap<>();
319         vnfConfigurableProperties.put("vnfIpAddress", "10.10.10.10");
320         vnfInstance.setVnfConfigurableProperties(vnfConfigurableProperties);
321
322         final List<InlineResponse201VimConnectionInfo> vimConnectionInfo = new ArrayList<>();;
323         final InlineResponse201VimConnectionInfo vimConnection = new InlineResponse201VimConnectionInfo();
324         vimConnection.setVimId(CLOUD_OWNER + "_" + REGION);
325         vimConnection.setId(CLOUD_OWNER + "_" + REGION);
326         final AccessInfo accessInfo = new AccessInfo();
327         accessInfo.setProjectId(TENANT_ID);
328         vimConnection.setAccessInfo(accessInfo);
329         vimConnectionInfo.add(vimConnection);
330         vnfInstance.setVimConnectionInfo(vimConnectionInfo);
331
332         final OamIpAddressSource oamIpAddressSource =
333                 new OamIpAddressSource(OamIpAddressType.CONFIGURABLE_PROPERTY, "vnfIpAddress");
334         aaiHelper.setOamIpAddressSource("myTestVnfIdOnVnfm", oamIpAddressSource);
335         return vnfInstance;
336     }
337
338     private GenericVnf createGenericVnf(final String type) {
339         final GenericVnf genericVnf = new GenericVnf();
340         genericVnf.setVnfId("myTestVnfId");
341         genericVnf.setNfType(type);
342         return genericVnf;
343     }
344
345     private void addRelationshipFromGenericVnfToVnfm(final GenericVnf genericVnf, final String vnfmId) {
346         final Relationship relationshipToVnfm = new Relationship();
347         relationshipToVnfm.setRelatedLink("/aai/v15/external-system/esr-vnfm-list/esr-vnfm/" + vnfmId);
348         relationshipToVnfm.setRelatedTo("esr-vnfm");
349         final RelationshipData relationshipData = new RelationshipData();
350         relationshipData.setRelationshipKey("esr-vnfm.vnfm-id");
351         relationshipData.setRelationshipValue(vnfmId);
352         relationshipToVnfm.getRelationshipData().add(relationshipData);
353
354         if (genericVnf.getRelationshipList() == null) {
355             final RelationshipList relationshipList = new RelationshipList();
356             genericVnf.setRelationshipList(relationshipList);
357         }
358         genericVnf.getRelationshipList().getRelationship().add(relationshipToVnfm);
359     }
360
361     private void addRelationshipFromGenericVnfToVserver(final GenericVnf genericVnf, final String vserverId) {
362         final Relationship relationshipToVserver = new Relationship();
363         relationshipToVserver.setRelatedTo("vserver");
364         final RelationshipData relationshipData1 = new RelationshipData();
365         relationshipData1.setRelationshipKey("vserver.vserver-id");
366         relationshipData1.setRelationshipValue(vserverId);
367         relationshipToVserver.getRelationshipData().add(relationshipData1);
368         final RelationshipData relationshipData2 = new RelationshipData();
369         relationshipData2.setRelationshipKey("cloud-region.cloud-owner");
370         relationshipData2.setRelationshipValue(CLOUD_OWNER);
371         relationshipToVserver.getRelationshipData().add(relationshipData2);
372         final RelationshipData relationshipData3 = new RelationshipData();
373         relationshipData3.setRelationshipKey("cloud-region.cloud-region-id");
374         relationshipData3.setRelationshipValue(REGION);
375         relationshipToVserver.getRelationshipData().add(relationshipData3);
376         final RelationshipData relationshipData4 = new RelationshipData();
377         relationshipData4.setRelationshipKey("tenant.tenant-id");
378         relationshipData4.setRelationshipValue(TENANT_ID);
379         relationshipToVserver.getRelationshipData().add(relationshipData4);
380
381         if (genericVnf.getRelationshipList() == null) {
382             final RelationshipList relationshipList = new RelationshipList();
383             genericVnf.setRelationshipList(relationshipList);
384         }
385         genericVnf.getRelationshipList().getRelationship().add(relationshipToVserver);
386     }
387
388     private class AaiResourceUriMatcher extends BaseMatcher<AAIResourceUri> {
389
390         final String uriAsString;
391
392         public AaiResourceUriMatcher(final String uriAsString) {
393             this.uriAsString = uriAsString;
394         }
395
396         @Override
397         public boolean matches(final Object item) {
398             if (item instanceof AAIResourceUri) {
399                 if (uriAsString.endsWith("...")) {
400                     return ((AAIResourceUri) item).build().toString()
401                             .startsWith(uriAsString.substring(0, uriAsString.indexOf("...")));
402                 }
403                 return ((AAIResourceUri) item).build().toString().equals(uriAsString);
404             }
405             return false;
406         }
407
408         @Override
409         public void describeTo(final Description description) {}
410
411     }
412
413 }