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.openecomp.aai.parsers.uri;
23 import org.junit.Ignore;
24 import org.junit.Rule;
25 import org.junit.Test;
26 import org.junit.rules.ExpectedException;
27 import org.openecomp.aai.AAISetup;
28 import org.openecomp.aai.db.props.AAIProperties;
29 import org.openecomp.aai.exceptions.AAIException;
30 import org.openecomp.aai.introspection.*;
32 import javax.ws.rs.core.UriBuilder;
33 import javax.xml.bind.JAXBException;
34 import java.io.UnsupportedEncodingException;
35 import java.net.MalformedURLException;
37 import java.net.URISyntaxException;
39 import static org.hamcrest.Matchers.hasProperty;
40 import static org.hamcrest.Matchers.is;
41 import static org.junit.Assert.assertTrue;
44 public class URIToRelationshipObjectTest extends AAISetup {
46 private Version latest = Version.v10;
47 private Loader loader = LoaderFactory.createLoaderForVersion(ModelType.MOXY, latest);
50 public ExpectedException thrown = ExpectedException.none();
55 * @throws JAXBException the JAXB exception
56 * @throws AAIException the AAI exception
57 * @throws IllegalArgumentException the illegal argument exception
58 * @throws UnsupportedEncodingException the unsupported encoding exception
59 * @throws URISyntaxException
60 * @throws MalformedURLException the malformed URL exception
63 public void uri() throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException, URISyntaxException {
65 URI uri = UriBuilder.fromPath("/aai/" + loader.getVersion() + "/cloud-infrastructure/cloud-regions/cloud-region/mycloudregionowner/mycloudregionid/tenants/tenant/key1/vservers/vserver/key2/l-interfaces/l-interface/key3").build();
66 URIToRelationshipObject parse = new URIToRelationshipObject(loader, uri);
67 Introspector result = parse.getResult();
68 String expected = "\\{\"related-to\":\"l-interface\",\"related-link\":\"/aai/" + latest + "/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\"\\}\\]\\}";
69 assertTrue("blah", result.marshal(false).matches(expected));
76 * @throws JAXBException the JAXB exception
77 * @throws AAIException the AAI exception
78 * @throws IllegalArgumentException the illegal argument exception
79 * @throws UnsupportedEncodingException the unsupported encoding exception
80 * @throws URISyntaxException
81 * @throws MalformedURLException the malformed URL exception
84 public void uriNoVersion() throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException, URISyntaxException {
85 URI uri = UriBuilder.fromPath("/cloud-infrastructure/cloud-regions/cloud-region/mycloudregionowner/mycloudregionid/tenants/tenant/key1/vservers/vserver/key2/l-interfaces/l-interface/key3").build();
86 URIToRelationshipObject parse = new URIToRelationshipObject(loader, uri);
87 Introspector result = parse.getResult();
88 String expected = "\\{\"related-to\":\"l-interface\",\"related-link\":\"/aai/" + latest + "/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\"\\}\\]\\}";
89 assertTrue("blah", result.marshal(false).matches(expected));
95 * Double key relationship.
97 * @throws JAXBException the JAXB exception
98 * @throws AAIException the AAI exception
99 * @throws IllegalArgumentException the illegal argument exception
100 * @throws UnsupportedEncodingException the unsupported encoding exception
101 * @throws URISyntaxException
102 * @throws MalformedURLException the malformed URL exception
105 public void doubleKeyRelationship() throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException, URISyntaxException {
106 URI uri = UriBuilder.fromPath("/aai/" + latest + "/cloud-infrastructure/complexes/complex/key1/ctag-pools/ctag-pool/key2/key3/").build();
107 URIToRelationshipObject parse = new URIToRelationshipObject(loader, uri);
108 Introspector result = parse.getResult();
109 String expected = "\\{\"related-to\":\"ctag-pool\",\"related-link\":\"/aai/" + latest + "/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\"\\}\\]\\}";
110 assertTrue("blah", result.marshal(false).matches(expected));
115 * Uri with non string key.
117 * @throws JAXBException the JAXB exception
118 * @throws AAIException the AAI exception
119 * @throws IllegalArgumentException the illegal argument exception
120 * @throws UnsupportedEncodingException the unsupported encoding exception
121 * @throws URISyntaxException
122 * @throws MalformedURLException the malformed URL exception
125 public void uriWithNonStringKey() throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException, URISyntaxException {
126 URI uri = UriBuilder.fromPath("/aai/" + latest + "/network/vces/vce/key1/port-groups/port-group/key2/cvlan-tags/cvlan-tag/144").build();
127 URIToRelationshipObject parse = new URIToRelationshipObject(loader, uri);
128 Introspector result = parse.getResult();
129 String expected = "\\{\"related-to\":\"cvlan-tag\",\"related-link\":\"/aai/" + latest + "/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\"\\}\\]\\}";
130 assertTrue("blah", result.marshal(false).matches(expected));
135 * @throws JAXBException the JAXB exception
136 * @throws AAIException the AAI exception
137 * @throws IllegalArgumentException the illegal argument exception
138 * @throws UnsupportedEncodingException the unsupported encoding exception
141 public void badURI() throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException {
142 URI uri = UriBuilder.fromPath("/aai/" + loader.getVersion() + "/cloud-infrastructure/cloud-regions/cloud-region/mycloudregionowner/mycloudregionid/tenants/tenant/key1/vservers/vserver/key2/l-interadsfaces/l-interface/key3").build();
144 thrown.expect(AAIException.class);
145 thrown.expect(hasProperty("code", is("AAI_3000")));
147 URIToObject parse = new URIToObject(loader, uri);