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;
28 import java.io.ByteArrayInputStream;
29 import java.io.ByteArrayOutputStream;
30 import java.io.FileInputStream;
31 import java.io.FileOutputStream;
32 import java.io.IOException;
33 import java.io.ObjectInputStream;
34 import java.io.ObjectOutputStream;
37 import org.junit.Test;
38 import org.onap.so.client.aai.AAIObjectPlurals;
39 import org.onap.so.client.aai.AAIObjectType;
40 import org.onap.so.client.graphinventory.entities.uri.Depth;
41 import org.onap.so.client.graphinventory.entities.uri.SimpleUri;
43 public class AAISimpleUriTest {
48 public void relatedToTestPlural() {
49 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test1");
50 uri.relatedTo(AAIObjectPlurals.PSERVER);
51 String uriOutput = uri.build().toString();
52 assertEquals(true, uriOutput.contains("related-to"));
56 public void relatedToTestSingular() {
57 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test1");
58 uri.relatedTo(AAIObjectType.PSERVER, "test2");
59 String uriOutput = uri.build().toString();
60 assertEquals(true, uriOutput.contains("related-to"));
64 public void cloneTestSingular() {
65 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test1");
66 AAIResourceUri cloned = uri.clone();
67 Map<String,String> keys = cloned.getURIKeys();
68 assertThat(keys.values(), contains("test1"));
72 public void cloneTestPlural() {
73 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectPlurals.GENERIC_VNF);
74 AAIResourceUri cloned = uri.clone();
75 Map<String,String> keys = cloned.getURIKeys();
76 assertThat(keys.values(), empty());
80 public void getKeysTest() {
81 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.VSERVER, "cloud1", "cloud2", "tenant1", "vserver1");
82 Map<String,String> keys = uri.getURIKeys();
83 System.out.println(keys);
84 System.out.println(uri.build());
85 assertEquals("vserver1", keys.get("vserver-id"));
89 public void getEncodedKeyTest() {
90 AAIResourceUri uri = 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
105 = new ObjectOutputStream(bos);
106 objectOutputStream.writeObject(uri);
107 objectOutputStream.flush();
108 objectOutputStream.close();
110 ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
112 ObjectInputStream objectInputStream
113 = new ObjectInputStream(bis);
114 AAIResourceUri e2 = (AAIResourceUri) objectInputStream.readObject();
115 objectInputStream.close();
117 uri.queryParam("test", "value");
118 e2.queryParam("test", "value");
120 assertEquals(e2.build().toString(), uri.build().toString());