75dbd4aea2401aa5b2f1775be0c249fc456001c0
[so.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.onap.aaiclient.client.aai.entities;
22
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;
37
38 public class RelationshipsTest {
39
40     private final static String AAI_JSON_FILE_LOCATION = "src/test/resources/__files/aai/resources/";
41
42     @Test
43     public void run() throws IOException {
44         final String content = new String(Files.readAllBytes(Paths.get(AAI_JSON_FILE_LOCATION + "e2e-complex.json")));
45
46         AAIResultWrapper wrapper = new AAIResultWrapper(content);
47         Relationships relationships = wrapper.getRelationships().get();
48
49         List<AAIResourceUri> test = relationships.getRelatedUris(Types.VCE);
50         List<AAIResourceUri> uris = Arrays.asList(
51                 AAIUriFactory
52                         .createResourceUri(AAIFluentTypeBuilder.network().vce("a9fec18e-1ea3-40e4-a6c0-a89b3de07053")),
53                 AAIUriFactory
54                         .createResourceUri(AAIFluentTypeBuilder.network().vce("8ae1e5f8-61f1-4c71-913a-b40cc4593cb9")),
55                 AAIUriFactory
56                         .createResourceUri(AAIFluentTypeBuilder.network().vce("a2935fa9-b743-49f4-9813-a127f13c4e93")),
57                 AAIUriFactory
58                         .createResourceUri(AAIFluentTypeBuilder.network().vce("c7fe7698-8063-4e26-8bd3-ca3edde0b0d4")));
59
60         assertTrue(uris.containsAll(test) && test.containsAll(uris));
61
62     }
63
64     @Test
65     public void getByTypeTest() throws IOException {
66         final String content = new String(Files.readAllBytes(Paths.get(AAI_JSON_FILE_LOCATION + "e2e-complex.json")));
67
68         AAIResultWrapper wrapper = new AAIResultWrapper(content);
69         Relationships relationships = wrapper.getRelationships().get();
70
71         Relationships spy = Mockito.spy(relationships);
72         ArgumentCaptor<AAIResourceUri> argument = ArgumentCaptor.forClass(AAIResourceUri.class);
73         doReturn(new AAIResultWrapper("{}")).when(spy).get(argument.capture());
74
75         spy.getByType(Types.VCE, uri -> uri.nodesOnly(true));
76
77         assertTrue(argument.getAllValues().stream().allMatch(item -> item.build().toString().contains("nodes-only")));
78
79         argument = ArgumentCaptor.forClass(AAIResourceUri.class);
80
81         doReturn(new AAIResultWrapper("{}")).when(spy).get(argument.capture());
82         spy.getByType(Types.VCE);
83
84         assertTrue(argument.getAllValues().stream().allMatch(item -> !item.build().toString().contains("?")));
85
86     }
87 }