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