2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.aaiclient.client.aai.entities;
23 import static org.junit.Assert.assertTrue;
24 import static org.mockito.Mockito.doReturn;
25 import java.io.IOException;
26 import java.nio.file.Files;
27 import java.nio.file.Paths;
28 import java.util.Arrays;
29 import java.util.List;
30 import org.junit.Test;
31 import org.mockito.ArgumentCaptor;
32 import org.mockito.Mockito;
33 import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri;
34 import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory;
35 import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder;
36 import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types;
38 public class RelationshipsTest {
40 private final static String AAI_JSON_FILE_LOCATION = "src/test/resources/__files/aai/resources/";
43 public void run() throws IOException {
44 final String content = new String(Files.readAllBytes(Paths.get(AAI_JSON_FILE_LOCATION + "e2e-complex.json")));
46 AAIResultWrapper wrapper = new AAIResultWrapper(content);
47 Relationships relationships = wrapper.getRelationships().get();
49 List<AAIResourceUri> test = relationships.getRelatedUris(Types.VCE);
50 List<AAIResourceUri> uris = Arrays.asList(
52 .createResourceUri(AAIFluentTypeBuilder.network().vce("a9fec18e-1ea3-40e4-a6c0-a89b3de07053")),
54 .createResourceUri(AAIFluentTypeBuilder.network().vce("8ae1e5f8-61f1-4c71-913a-b40cc4593cb9")),
56 .createResourceUri(AAIFluentTypeBuilder.network().vce("a2935fa9-b743-49f4-9813-a127f13c4e93")),
58 .createResourceUri(AAIFluentTypeBuilder.network().vce("c7fe7698-8063-4e26-8bd3-ca3edde0b0d4")));
60 assertTrue(uris.containsAll(test) && test.containsAll(uris));
65 public void getByTypeTest() throws IOException {
66 final String content = new String(Files.readAllBytes(Paths.get(AAI_JSON_FILE_LOCATION + "e2e-complex.json")));
68 AAIResultWrapper wrapper = new AAIResultWrapper(content);
69 Relationships relationships = wrapper.getRelationships().get();
71 Relationships spy = Mockito.spy(relationships);
72 ArgumentCaptor<AAIResourceUri> argument = ArgumentCaptor.forClass(AAIResourceUri.class);
73 doReturn(new AAIResultWrapper("{}")).when(spy).get(argument.capture());
75 spy.getByType(Types.VCE, uri -> uri.nodesOnly(true));
77 assertTrue(argument.getAllValues().stream().allMatch(item -> item.build().toString().contains("nodes-only")));
79 argument = ArgumentCaptor.forClass(AAIResourceUri.class);
81 doReturn(new AAIResultWrapper("{}")).when(spy).get(argument.capture());
82 spy.getByType(Types.VCE);
84 assertTrue(argument.getAllValues().stream().allMatch(item -> !item.build().toString().contains("?")));