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 = AAIProperties.LATEST;
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 {
64 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();
65 URIToRelationshipObject parse = new URIToRelationshipObject(loader, uri);
66 Introspector result = parse.getResult();
67 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\"\\}\\]\\}";
68 assertTrue("blah", result.marshal(false).matches(expected));
75 * @throws JAXBException the JAXB exception
76 * @throws AAIException the AAI exception
77 * @throws IllegalArgumentException the illegal argument exception
78 * @throws UnsupportedEncodingException the unsupported encoding exception
79 * @throws URISyntaxException
80 * @throws MalformedURLException the malformed URL exception
83 public void uriNoVersion() throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException, URISyntaxException {
84 URI uri = UriBuilder.fromPath("/cloud-infrastructure/cloud-regions/cloud-region/mycloudregionowner/mycloudregionid/tenants/tenant/key1/vservers/vserver/key2/l-interfaces/l-interface/key3").build();
85 URIToRelationshipObject parse = new URIToRelationshipObject(loader, uri);
86 Introspector result = parse.getResult();
87 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\"\\}\\]\\}";
88 assertTrue("blah", result.marshal(false).matches(expected));
94 * Double key relationship.
96 * @throws JAXBException the JAXB exception
97 * @throws AAIException the AAI exception
98 * @throws IllegalArgumentException the illegal argument exception
99 * @throws UnsupportedEncodingException the unsupported encoding exception
100 * @throws URISyntaxException
101 * @throws MalformedURLException the malformed URL exception
104 public void doubleKeyRelationship() throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException, URISyntaxException {
105 URI uri = UriBuilder.fromPath("/aai/" + latest + "/cloud-infrastructure/complexes/complex/key1/ctag-pools/ctag-pool/key2/key3/").build();
106 URIToRelationshipObject parse = new URIToRelationshipObject(loader, uri);
107 Introspector result = parse.getResult();
108 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\"\\}\\]\\}";
109 assertTrue("blah", result.marshal(false).matches(expected));
114 * Uri with non string key.
116 * @throws JAXBException the JAXB exception
117 * @throws AAIException the AAI exception
118 * @throws IllegalArgumentException the illegal argument exception
119 * @throws UnsupportedEncodingException the unsupported encoding exception
120 * @throws URISyntaxException
121 * @throws MalformedURLException the malformed URL exception
124 public void uriWithNonStringKey() throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException, URISyntaxException {
125 URI uri = UriBuilder.fromPath("/aai/" + latest + "/network/vces/vce/key1/port-groups/port-group/key2/cvlan-tags/cvlan-tag/144").build();
126 URIToRelationshipObject parse = new URIToRelationshipObject(loader, uri);
127 Introspector result = parse.getResult();
128 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\"\\}\\]\\}";
129 assertTrue("blah", result.marshal(false).matches(expected));
134 * @throws JAXBException the JAXB exception
135 * @throws AAIException the AAI exception
136 * @throws IllegalArgumentException the illegal argument exception
137 * @throws UnsupportedEncodingException the unsupported encoding exception
140 public void badURI() throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException {
141 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();
143 thrown.expect(AAIException.class);
144 thrown.expect(hasProperty("code", is("AAI_3000")));
146 URIToObject parse = new URIToObject(loader, uri);