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 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.ws.rs.core.UriBuilder;
33 import javax.xml.bind.JAXBException;
35 import org.junit.BeforeClass;
36 import org.junit.Ignore;
37 import org.junit.Rule;
38 import org.junit.Test;
39 import org.junit.rules.ExpectedException;
41 import org.openecomp.aai.db.props.AAIProperties;
42 import org.openecomp.aai.exceptions.AAIException;
43 import org.openecomp.aai.introspection.Introspector;
44 import org.openecomp.aai.introspection.Loader;
45 import org.openecomp.aai.introspection.LoaderFactory;
46 import org.openecomp.aai.introspection.ModelType;
47 import org.openecomp.aai.introspection.Version;
50 public class URIToRelationshipObjectTest {
52 private Version latest = AAIProperties.LATEST;
53 private Loader loader = LoaderFactory.createLoaderForVersion(ModelType.MOXY, latest);
56 public ExpectedException thrown = ExpectedException.none();
62 public static void configure() {
63 System.setProperty("AJSC_HOME", ".");
64 System.setProperty("BUNDLECONFIG_DIR", "src/test/resources/bundleconfig-local");
70 * @throws JAXBException the JAXB exception
71 * @throws AAIException the AAI exception
72 * @throws IllegalArgumentException the illegal argument exception
73 * @throws UnsupportedEncodingException the unsupported encoding exception
74 * @throws URISyntaxException
75 * @throws MalformedURLException the malformed URL exception
78 public void uri() throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException, URISyntaxException {
79 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();
80 URIToRelationshipObject parse = new URIToRelationshipObject(loader, uri);
81 Introspector result = parse.getResult();
82 String expected = "\\{\"related-to\":\"l-interface\",\"related-link\":\".*?:8443/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\"\\}\\]\\}";
83 assertTrue("blah", result.marshal(false).matches(expected));
90 * @throws JAXBException the JAXB exception
91 * @throws AAIException the AAI exception
92 * @throws IllegalArgumentException the illegal argument exception
93 * @throws UnsupportedEncodingException the unsupported encoding exception
94 * @throws URISyntaxException
95 * @throws MalformedURLException the malformed URL exception
98 public void uriNoVersion() throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException, URISyntaxException {
99 URI uri = UriBuilder.fromPath("/cloud-infrastructure/cloud-regions/cloud-region/mycloudregionowner/mycloudregionid/tenants/tenant/key1/vservers/vserver/key2/l-interfaces/l-interface/key3").build();
100 URIToRelationshipObject parse = new URIToRelationshipObject(loader, uri);
101 Introspector result = parse.getResult();
102 String expected = "\\{\"related-to\":\"l-interface\",\"related-link\":\".*?:8443/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\"\\}\\]\\}";
103 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, UnsupportedEncodingException, URISyntaxException {
120 URI uri = UriBuilder.fromPath("/aai/" + latest + "/cloud-infrastructure/complexes/complex/key1/ctag-pools/ctag-pool/key2/key3/").build();
121 URIToRelationshipObject parse = new URIToRelationshipObject(loader, uri);
122 Introspector result = parse.getResult();
123 String expected = "\\{\"related-to\":\"ctag-pool\",\"related-link\":\".*?:8443/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\"\\}\\]\\}";
124 assertTrue("blah", result.marshal(false).matches(expected));
129 * Uri with non string key.
131 * @throws JAXBException the JAXB exception
132 * @throws AAIException the AAI exception
133 * @throws IllegalArgumentException the illegal argument exception
134 * @throws UnsupportedEncodingException the unsupported encoding exception
135 * @throws URISyntaxException
136 * @throws MalformedURLException the malformed URL exception
139 public void uriWithNonStringKey() throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException, URISyntaxException {
140 URI uri = UriBuilder.fromPath("/aai/" + latest + "/network/vces/vce/key1/port-groups/port-group/key2/cvlan-tags/cvlan-tag/144").build();
141 URIToRelationshipObject parse = new URIToRelationshipObject(loader, uri);
142 Introspector result = parse.getResult();
143 String expected = "\\{\"related-to\":\"cvlan-tag\",\"related-link\":\".*?:8443/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\"\\}\\]\\}";
144 assertTrue("blah", result.marshal(false).matches(expected));
149 * @throws JAXBException the JAXB exception
150 * @throws AAIException the AAI exception
151 * @throws IllegalArgumentException the illegal argument exception
152 * @throws UnsupportedEncodingException the unsupported encoding exception
155 public void badURI() throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException {
156 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();
158 thrown.expect(AAIException.class);
159 thrown.expect(hasProperty("code", is("AAI_3000")));
161 URIToObject parse = new URIToObject(loader, uri);