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.Ignore;
37 import org.junit.Rule;
38 import org.junit.Test;
39 import org.junit.rules.ExpectedException;
40 import org.onap.aai.AAISetup;
41 import org.onap.aai.exceptions.AAIException;
42 import org.onap.aai.introspection.*;
43 import org.onap.aai.setup.SchemaVersion;
45 @Ignore public class URIToRelationshipObjectTest extends AAISetup {
47 private SchemaVersion latest;
48 private Loader loader;
51 public ExpectedException thrown = ExpectedException.none();
54 public void createLoader() {
55 latest = schemaVersions.getDefaultVersion();
56 loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, latest);
62 * @throws JAXBException the JAXB exception
63 * @throws AAIException the AAI exception
64 * @throws IllegalArgumentException the illegal argument exception
65 * @throws UnsupportedEncodingException the unsupported encoding exception
66 * @throws URISyntaxException
67 * @throws MalformedURLException the malformed URL exception
70 public void uri() throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException,
73 URI uri = UriBuilder.fromPath("/aai/" + loader.getVersion()
74 + "/cloud-infrastructure/cloud-regions/cloud-region/mycloudregionowner/mycloudregionid/tenants/tenant/key1/vservers/vserver/key2/l-interfaces/l-interface/key3")
76 URIToRelationshipObject parse = new URIToRelationshipObject(loader, uri);
77 Introspector result = parse.getResult();
78 String expected = "\\{\"related-to\":\"l-interface\",\"related-link\":\"/aai/" + latest
79 + "/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\"\\}\\]\\}";
80 assertTrue("blah", result.marshal(false).matches(expected));
87 * @throws JAXBException the JAXB exception
88 * @throws AAIException the AAI exception
89 * @throws IllegalArgumentException the illegal argument exception
90 * @throws UnsupportedEncodingException the unsupported encoding exception
91 * @throws URISyntaxException
92 * @throws MalformedURLException the malformed URL exception
95 public void uriNoVersion() throws JAXBException, AAIException, IllegalArgumentException,
96 UnsupportedEncodingException, URISyntaxException {
97 URI uri = UriBuilder.fromPath(
98 "/cloud-infrastructure/cloud-regions/cloud-region/mycloudregionowner/mycloudregionid/tenants/tenant/key1/vservers/vserver/key2/l-interfaces/l-interface/key3")
100 URIToRelationshipObject parse = new URIToRelationshipObject(loader, uri);
101 Introspector result = parse.getResult();
102 String expected = "\\{\"related-to\":\"l-interface\",\"related-link\":\"/aai/" + latest
103 + "/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\"\\}\\]\\}";
104 assertTrue("blah", result.marshal(false).matches(expected));
109 * Double key relationship.
111 * @throws JAXBException the JAXB exception
112 * @throws AAIException the AAI exception
113 * @throws IllegalArgumentException the illegal argument exception
114 * @throws UnsupportedEncodingException the unsupported encoding exception
115 * @throws URISyntaxException
116 * @throws MalformedURLException the malformed URL exception
119 public void doubleKeyRelationship() throws JAXBException, AAIException, IllegalArgumentException,
120 UnsupportedEncodingException, URISyntaxException {
123 .fromPath("/aai/" + latest
124 + "/cloud-infrastructure/complexes/complex/key1/ctag-pools/ctag-pool/key2/key3/")
126 URIToRelationshipObject parse = new URIToRelationshipObject(loader, uri);
127 Introspector result = parse.getResult();
128 String expected = "\\{\"related-to\":\"ctag-pool\",\"related-link\":\"/aai/" + latest
129 + "/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\"\\}\\]\\}";
130 assertTrue("blah", result.marshal(false).matches(expected));
135 * Uri with non string key.
137 * @throws JAXBException the JAXB exception
138 * @throws AAIException the AAI exception
139 * @throws IllegalArgumentException the illegal argument exception
140 * @throws UnsupportedEncodingException the unsupported encoding exception
141 * @throws URISyntaxException
142 * @throws MalformedURLException the malformed URL exception
145 public void uriWithNonStringKey() throws JAXBException, AAIException, IllegalArgumentException,
146 UnsupportedEncodingException, URISyntaxException {
149 .fromPath("/aai/" + latest
150 + "/network/vces/vce/key1/port-groups/port-group/key2/cvlan-tags/cvlan-tag/144")
152 URIToRelationshipObject parse = new URIToRelationshipObject(loader, uri);
153 Introspector result = parse.getResult();
154 String expected = "\\{\"related-to\":\"cvlan-tag\",\"related-link\":\"/aai/" + latest
155 + "/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\"\\}\\]\\}";
156 assertTrue("blah", result.marshal(false).matches(expected));
162 * @throws JAXBException the JAXB exception
163 * @throws AAIException the AAI exception
164 * @throws IllegalArgumentException the illegal argument exception
165 * @throws UnsupportedEncodingException the unsupported encoding exception
168 public void badURI() throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException {
169 URI uri = UriBuilder.fromPath("/aai/" + loader.getVersion()
170 + "/cloud-infrastructure/cloud-regions/cloud-region/mycloudregionowner/mycloudregionid/tenants/tenant/key1/vservers/vserver/key2/l-interadsfaces/l-interface/key3")
173 thrown.expect(AAIException.class);
174 thrown.expect(hasProperty("code", is("AAI_3000")));
176 URIToObject parse = new URIToObject(loader, uri);