Replaced all tabs with spaces in java and pom.xml
[so.git] / common / src / test / java / org / onap / so / client / aai / entities / uri / AAISimpleUriTest.java
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.so.client.aai.entities.uri;
22
23 import static org.hamcrest.MatcherAssert.assertThat;
24 import static org.hamcrest.collection.IsEmptyCollection.empty;
25 import static org.hamcrest.collection.IsIterableContainingInOrder.contains;
26 import static org.junit.Assert.assertEquals;
27 import java.io.ByteArrayInputStream;
28 import java.io.ByteArrayOutputStream;
29 import java.io.FileInputStream;
30 import java.io.FileOutputStream;
31 import java.io.IOException;
32 import java.io.ObjectInputStream;
33 import java.io.ObjectOutputStream;
34 import java.util.Map;
35 import org.junit.Test;
36 import org.onap.so.client.aai.AAIObjectPlurals;
37 import org.onap.so.client.aai.AAIObjectType;
38 import org.onap.so.client.graphinventory.entities.uri.Depth;
39 import org.onap.so.client.graphinventory.entities.uri.SimpleUri;
40
41 public class AAISimpleUriTest {
42
43
44
45     @Test
46     public void relatedToTestPlural() {
47         AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test1");
48         uri.relatedTo(AAIObjectPlurals.PSERVER);
49         String uriOutput = uri.build().toString();
50         assertEquals(true, uriOutput.contains("related-to"));
51     }
52
53     @Test
54     public void relatedToTestSingular() {
55         AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test1");
56         uri.relatedTo(AAIObjectType.PSERVER, "test2");
57         String uriOutput = uri.build().toString();
58         assertEquals(true, uriOutput.contains("related-to"));
59     }
60
61     @Test
62     public void cloneTestSingular() {
63         AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test1");
64         AAIResourceUri cloned = uri.clone();
65         Map<String, String> keys = cloned.getURIKeys();
66         assertThat(keys.values(), contains("test1"));
67     }
68
69     @Test
70     public void cloneTestPlural() {
71         AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectPlurals.GENERIC_VNF);
72         AAIResourceUri cloned = uri.clone();
73         Map<String, String> keys = cloned.getURIKeys();
74         assertThat(keys.values(), empty());
75     }
76
77     @Test
78     public void getKeysTest() {
79         AAIResourceUri uri =
80                 AAIUriFactory.createResourceUri(AAIObjectType.VSERVER, "cloud1", "cloud2", "tenant1", "vserver1");
81         Map<String, String> keys = uri.getURIKeys();
82         System.out.println(keys);
83         System.out.println(uri.build());
84         assertEquals("vserver1", keys.get("vserver-id"));
85     }
86
87     @Test
88     public void getEncodedKeyTest() {
89         AAIResourceUri uri =
90                 AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, "test1", "my value", "test3");
91         Map<String, String> keys = uri.getURIKeys();
92
93         assertEquals("my value", keys.get("service-type"));
94     }
95
96     @Test
97     public void serializeTest() throws IOException, ClassNotFoundException {
98         AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test1");
99
100         uri.depth(Depth.ONE);
101         uri.limit(1);
102         ByteArrayOutputStream bos = new ByteArrayOutputStream();
103
104         ObjectOutputStream objectOutputStream = new ObjectOutputStream(bos);
105         objectOutputStream.writeObject(uri);
106         objectOutputStream.flush();
107         objectOutputStream.close();
108
109         ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
110
111         ObjectInputStream objectInputStream = new ObjectInputStream(bis);
112         AAIResourceUri e2 = (AAIResourceUri) objectInputStream.readObject();
113         objectInputStream.close();
114
115         uri.queryParam("test", "value");
116         e2.queryParam("test", "value");
117
118         assertEquals(e2.build().toString(), uri.build().toString());
119     }
120 }