2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2018 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.aai.parsers.uri;
23 import static org.hamcrest.Matchers.hasProperty;
24 import static org.hamcrest.Matchers.is;
25 import static org.junit.Assert.assertTrue;
27 import java.io.UnsupportedEncodingException;
28 import java.net.MalformedURLException;
30 import java.net.URISyntaxException;
32 import javax.annotation.PostConstruct;
33 import javax.ws.rs.core.UriBuilder;
34 import javax.xml.bind.JAXBException;
36 import org.junit.Rule;
37 import org.junit.Test;
38 import org.junit.rules.ExpectedException;
39 import org.onap.aai.AAISetup;
40 import org.onap.aai.exceptions.AAIException;
41 import org.onap.aai.introspection.*;
42 import org.onap.aai.setup.SchemaVersion;
44 public class URIToRelationshipObjectTest extends AAISetup {
46 private SchemaVersion latest;
47 private Loader loader;
50 public ExpectedException thrown = ExpectedException.none();
53 public void createLoader() {
54 latest = schemaVersions.getDefaultVersion();
55 loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, latest);
61 * @throws JAXBException the JAXB exception
62 * @throws AAIException the AAI exception
63 * @throws IllegalArgumentException the illegal argument exception
64 * @throws UnsupportedEncodingException the unsupported encoding exception
65 * @throws URISyntaxException
66 * @throws MalformedURLException the malformed URL exception
69 public void uri() throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException,
72 URI uri = UriBuilder.fromPath("/aai/" + loader.getVersion()
73 + "/cloud-infrastructure/cloud-regions/cloud-region/mycloudregionowner/mycloudregionid/tenants/tenant/key1/vservers/vserver/key2/l-interfaces/l-interface/key3")
75 URIToRelationshipObject parse = new URIToRelationshipObject(loader, uri);
76 Introspector result = parse.getResult();
77 String expected = "\\{\"related-to\":\"l-interface\",\"related-link\":\"/aai/" + latest
78 + "/cloud-infrastructure/cloud-regions/cloud-region/mycloudregionowner/mycloudregionid/tenants/tenant/key1/vservers/vserver/key2/l-interfaces/l-interface/key3\",\"relationship-data\":\\[\\{\"relationship-key\":\"cloud-region.cloud-owner\",\"relationship-value\":\"mycloudregionowner\"\\},\\{\"relationship-key\":\"cloud-region.cloud-region-id\",\"relationship-value\":\"mycloudregionid\"\\},\\{\"relationship-key\":\"tenant.tenant-id\",\"relationship-value\":\"key1\"\\},\\{\"relationship-key\":\"vserver.vserver-id\",\"relationship-value\":\"key2\"\\},\\{\"relationship-key\":\"l-interface.interface-name\",\"relationship-value\":\"key3\"\\}\\]\\}";
79 assertTrue("blah", result.marshal(false).matches(expected));
86 * @throws JAXBException the JAXB exception
87 * @throws AAIException the AAI exception
88 * @throws IllegalArgumentException the illegal argument exception
89 * @throws UnsupportedEncodingException the unsupported encoding exception
90 * @throws URISyntaxException
91 * @throws MalformedURLException the malformed URL exception
94 public void uriNoVersion() throws JAXBException, AAIException, IllegalArgumentException,
95 UnsupportedEncodingException, URISyntaxException {
96 URI uri = UriBuilder.fromPath(
97 "/cloud-infrastructure/cloud-regions/cloud-region/mycloudregionowner/mycloudregionid/tenants/tenant/key1/vservers/vserver/key2/l-interfaces/l-interface/key3")
99 URIToRelationshipObject parse = new URIToRelationshipObject(loader, uri);
100 Introspector result = parse.getResult();
101 String expected = "\\{\"related-to\":\"l-interface\",\"related-link\":\"/aai/" + latest
102 + "/cloud-infrastructure/cloud-regions/cloud-region/mycloudregionowner/mycloudregionid/tenants/tenant/key1/vservers/vserver/key2/l-interfaces/l-interface/key3\",\"relationship-data\":\\[\\{\"relationship-key\":\"cloud-region.cloud-owner\",\"relationship-value\":\"mycloudregionowner\"\\},\\{\"relationship-key\":\"cloud-region.cloud-region-id\",\"relationship-value\":\"mycloudregionid\"\\},\\{\"relationship-key\":\"tenant.tenant-id\",\"relationship-value\":\"key1\"\\},\\{\"relationship-key\":\"vserver.vserver-id\",\"relationship-value\":\"key2\"\\},\\{\"relationship-key\":\"l-interface.interface-name\",\"relationship-value\":\"key3\"\\}\\]\\}";
103 assertTrue("blah", result.marshal(false).matches(expected));
108 * Double key relationship.
110 * @throws JAXBException the JAXB exception
111 * @throws AAIException the AAI exception
112 * @throws IllegalArgumentException the illegal argument exception
113 * @throws UnsupportedEncodingException the unsupported encoding exception
114 * @throws URISyntaxException
115 * @throws MalformedURLException the malformed URL exception
118 public void doubleKeyRelationship() throws JAXBException, AAIException, IllegalArgumentException,
119 UnsupportedEncodingException, URISyntaxException {
122 .fromPath("/aai/" + latest
123 + "/cloud-infrastructure/complexes/complex/key1/ctag-pools/ctag-pool/key2/key3/")
125 URIToRelationshipObject parse = new URIToRelationshipObject(loader, uri);
126 Introspector result = parse.getResult();
127 String expected = "\\{\"related-to\":\"ctag-pool\",\"related-link\":\"/aai/" + latest
128 + "/cloud-infrastructure/complexes/complex/key1/ctag-pools/ctag-pool/key2/key3\",\"relationship-data\":\\[\\{\"relationship-key\":\"complex.physical-location-id\",\"relationship-value\":\"key1\"\\},\\{\"relationship-key\":\"ctag-pool.target-pe\",\"relationship-value\":\"key2\"\\},\\{\"relationship-key\":\"ctag-pool.availability-zone-name\",\"relationship-value\":\"key3\"\\}\\]\\}";
129 assertTrue("blah", result.marshal(false).matches(expected));
134 * Uri with non string key.
136 * @throws JAXBException the JAXB exception
137 * @throws AAIException the AAI exception
138 * @throws IllegalArgumentException the illegal argument exception
139 * @throws UnsupportedEncodingException the unsupported encoding exception
140 * @throws URISyntaxException
141 * @throws MalformedURLException the malformed URL exception
144 public void uriWithNonStringKey() throws JAXBException, AAIException, IllegalArgumentException,
145 UnsupportedEncodingException, URISyntaxException {
148 .fromPath("/aai/" + latest
149 + "/network/vces/vce/key1/port-groups/port-group/key2/cvlan-tags/cvlan-tag/144")
151 URIToRelationshipObject parse = new URIToRelationshipObject(loader, uri);
152 Introspector result = parse.getResult();
153 String expected = "\\{\"related-to\":\"cvlan-tag\",\"related-link\":\"/aai/" + latest
154 + "/network/vces/vce/key1/port-groups/port-group/key2/cvlan-tags/cvlan-tag/144\",\"relationship-data\":\\[\\{\"relationship-key\":\"vce.vnf-id\",\"relationship-value\":\"key1\"\\},\\{\"relationship-key\":\"port-group.interface-id\",\"relationship-value\":\"key2\"\\},\\{\"relationship-key\":\"cvlan-tag.cvlan-tag\",\"relationship-value\":\"144\"\\}\\]\\}";
155 assertTrue("blah", result.marshal(false).matches(expected));
161 * @throws JAXBException the JAXB exception
162 * @throws AAIException the AAI exception
163 * @throws IllegalArgumentException the illegal argument exception
164 * @throws UnsupportedEncodingException the unsupported encoding exception
167 public void badURI() throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException {
168 URI uri = UriBuilder.fromPath("/aai/" + loader.getVersion()
169 + "/cloud-infrastructure/cloud-regions/cloud-region/mycloudregionowner/mycloudregionid/tenants/tenant/key1/vservers/vserver/key2/l-interadsfaces/l-interface/key3")
172 thrown.expect(AAIException.class);
173 thrown.expect(hasProperty("code", is("AAI_3000")));
175 URIToObject parse = new URIToObject(loader, uri);