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.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertNotEquals;
25 import java.io.ByteArrayInputStream;
26 import java.io.ByteArrayOutputStream;
27 import java.io.IOException;
28 import java.io.ObjectInputStream;
29 import java.io.ObjectOutputStream;
31 import org.junit.Test;
32 import org.onap.so.client.aai.AAIObjectPlurals;
33 import org.onap.so.client.aai.AAIObjectType;
34 import org.onap.so.client.graphinventory.entities.uri.Depth;
36 public class AAISimpleUriTest {
41 public void relatedToTestPlural() {
42 AAIPluralResourceUri uri =
43 AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test1").relatedTo(AAIObjectPlurals.PSERVER);
44 String uriOutput = uri.build().toString();
45 assertEquals("/network/generic-vnfs/generic-vnf/test1/related-to/pservers", uriOutput);
49 public void relatedToTestSingular() {
50 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test1")
51 .relatedTo(AAIObjectType.PSERVER, "test2");
52 String uriOutput = uri.build().toString();
53 assertEquals("/network/generic-vnfs/generic-vnf/test1/related-to/pservers/pserver/test2", uriOutput);
57 public void cloneTestSingular() {
58 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test1");
59 AAIResourceUri cloned = uri.clone();
60 assertEquals("/network/generic-vnfs/generic-vnf/test1", cloned.build().toString());
64 assertNotEquals(uri.build().toString(), cloned.build().toString());
68 public void cloneTestPlural() {
69 AAISimplePluralUri uri = AAIUriFactory.createResourceUri(AAIObjectPlurals.GENERIC_VNF);
70 AAISimplePluralUri cloned = uri.clone();
71 assertEquals("/network/generic-vnfs", cloned.build().toString());
75 public void cloneTestWithRelatedTo() {
76 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test1")
77 .relatedTo(AAIObjectType.PSERVER, "test2");
78 String uriOutput = uri.clone().build().toString();
79 assertEquals("/network/generic-vnfs/generic-vnf/test1/related-to/pservers/pserver/test2", uriOutput);
83 public void cloneTestPluralWithRelatedTo() {
84 AAIPluralResourceUri uri =
85 AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test1").relatedTo(AAIObjectPlurals.PSERVER);
86 String uriOutput = uri.clone().build().toString();
87 assertEquals("/network/generic-vnfs/generic-vnf/test1/related-to/pservers", uriOutput);
91 public void getKeysTest() {
93 AAIUriFactory.createResourceUri(AAIObjectType.VSERVER, "cloud1", "cloud2", "tenant1", "vserver1");
94 Map<String, String> keys = uri.getURIKeys();
95 System.out.println(keys);
96 System.out.println(uri.build());
97 assertEquals("vserver1", keys.get("vserver-id"));
101 public void getEncodedKeyTest() {
103 AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, "test1", "my value", "test3");
104 Map<String, String> keys = uri.getURIKeys();
106 assertEquals("my value", keys.get("service-type"));
110 public void serializeTest() throws IOException, ClassNotFoundException {
111 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test1");
113 uri.depth(Depth.ONE);
115 ByteArrayOutputStream bos = new ByteArrayOutputStream();
117 ObjectOutputStream objectOutputStream = new ObjectOutputStream(bos);
118 objectOutputStream.writeObject(uri);
119 objectOutputStream.flush();
120 objectOutputStream.close();
122 ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
124 ObjectInputStream objectInputStream = new ObjectInputStream(bis);
125 AAIResourceUri e2 = (AAIResourceUri) objectInputStream.readObject();
126 objectInputStream.close();
128 uri.queryParam("test", "value");
129 e2.queryParam("test", "value");
131 assertEquals(e2.build().toString(), uri.build().toString());