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.so.client.aai.entities.uri;
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;
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;
41 public class AAISimpleUriTest {
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"));
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"));
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"));
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());
78 public void getKeysTest() {
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"));
88 public void getEncodedKeyTest() {
90 AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, "test1", "my value", "test3");
91 Map<String, String> keys = uri.getURIKeys();
93 assertEquals("my value", keys.get("service-type"));
97 public void serializeTest() throws IOException, ClassNotFoundException {
98 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test1");
100 uri.depth(Depth.ONE);
102 ByteArrayOutputStream bos = new ByteArrayOutputStream();
104 ObjectOutputStream objectOutputStream = new ObjectOutputStream(bos);
105 objectOutputStream.writeObject(uri);
106 objectOutputStream.flush();
107 objectOutputStream.close();
109 ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
111 ObjectInputStream objectInputStream = new ObjectInputStream(bis);
112 AAIResourceUri e2 = (AAIResourceUri) objectInputStream.readObject();
113 objectInputStream.close();
115 uri.queryParam("test", "value");
116 e2.queryParam("test", "value");
118 assertEquals(e2.build().toString(), uri.build().toString());