Added proxy args in the haproxy Dockerfile
[aai/aai-common.git] / aai-core / src / test / java / org / onap / aai / parsers / uri / URIToRelationshipObjectTest.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
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
10  *
11  *    http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20
21 package org.onap.aai.parsers.uri;
22
23 import static org.hamcrest.Matchers.hasProperty;
24 import static org.hamcrest.Matchers.is;
25 import static org.junit.Assert.assertTrue;
26
27 import java.io.UnsupportedEncodingException;
28 import java.net.MalformedURLException;
29 import java.net.URI;
30 import java.net.URISyntaxException;
31
32 import javax.annotation.PostConstruct;
33 import javax.ws.rs.core.UriBuilder;
34 import javax.xml.bind.JAXBException;
35
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;
43 import org.springframework.test.annotation.DirtiesContext;
44
45 @DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS)
46 public class URIToRelationshipObjectTest extends AAISetup {
47
48     private SchemaVersion latest;
49     private Loader loader;
50
51     @Rule
52     public ExpectedException thrown = ExpectedException.none();
53
54     @PostConstruct
55     public void createLoader() {
56         latest = schemaVersions.getDefaultVersion();
57         loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, latest);
58     }
59
60     /**
61      * Uri.
62      *
63      * @throws JAXBException the JAXB exception
64      * @throws AAIException the AAI exception
65      * @throws IllegalArgumentException the illegal argument exception
66      * @throws UnsupportedEncodingException the unsupported encoding exception
67      * @throws URISyntaxException
68      * @throws MalformedURLException the malformed URL exception
69      */
70     @Test
71     public void uri() throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException,
72             URISyntaxException {
73
74         URI uri = UriBuilder.fromPath("/aai/" + loader.getVersion()
75                 + "/cloud-infrastructure/cloud-regions/cloud-region/mycloudregionowner/mycloudregionid/tenants/tenant/key1/vservers/vserver/key2/l-interfaces/l-interface/key3")
76                 .build();
77         URIToRelationshipObject parse = new URIToRelationshipObject(loader, uri);
78         Introspector result = parse.getResult();
79         String expected = "\\{\"related-to\":\"l-interface\",\"related-link\":\"/aai/" + latest
80                 + "/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\"\\}\\]\\}";
81         assertTrue("blah", result.marshal(false).matches(expected));
82
83     }
84
85     /**
86      * Uri no version.
87      *
88      * @throws JAXBException the JAXB exception
89      * @throws AAIException the AAI exception
90      * @throws IllegalArgumentException the illegal argument exception
91      * @throws UnsupportedEncodingException the unsupported encoding exception
92      * @throws URISyntaxException
93      * @throws MalformedURLException the malformed URL exception
94      */
95     @Test
96     public void uriNoVersion() throws JAXBException, AAIException, IllegalArgumentException,
97             UnsupportedEncodingException, URISyntaxException {
98         URI uri = UriBuilder.fromPath(
99                 "/cloud-infrastructure/cloud-regions/cloud-region/mycloudregionowner/mycloudregionid/tenants/tenant/key1/vservers/vserver/key2/l-interfaces/l-interface/key3")
100                 .build();
101         URIToRelationshipObject parse = new URIToRelationshipObject(loader, uri);
102         Introspector result = parse.getResult();
103         String expected = "\\{\"related-to\":\"l-interface\",\"related-link\":\"/aai/" + latest
104                 + "/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\"\\}\\]\\}";
105         assertTrue("blah", result.marshal(false).matches(expected));
106
107     }
108
109     /**
110      * Double key relationship.
111      *
112      * @throws JAXBException the JAXB exception
113      * @throws AAIException the AAI exception
114      * @throws IllegalArgumentException the illegal argument exception
115      * @throws UnsupportedEncodingException the unsupported encoding exception
116      * @throws URISyntaxException
117      * @throws MalformedURLException the malformed URL exception
118      */
119     @Test
120     public void doubleKeyRelationship() throws JAXBException, AAIException, IllegalArgumentException,
121             UnsupportedEncodingException, URISyntaxException {
122         URI uri =
123                 UriBuilder
124                         .fromPath("/aai/" + latest
125                                 + "/cloud-infrastructure/complexes/complex/key1/ctag-pools/ctag-pool/key2/key3/")
126                         .build();
127         URIToRelationshipObject parse = new URIToRelationshipObject(loader, uri);
128         Introspector result = parse.getResult();
129         String expected = "\\{\"related-to\":\"ctag-pool\",\"related-link\":\"/aai/" + latest
130                 + "/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\"\\}\\]\\}";
131         assertTrue("blah", result.marshal(false).matches(expected));
132
133     }
134
135     /**
136      * Uri with non string key.
137      *
138      * @throws JAXBException the JAXB exception
139      * @throws AAIException the AAI exception
140      * @throws IllegalArgumentException the illegal argument exception
141      * @throws UnsupportedEncodingException the unsupported encoding exception
142      * @throws URISyntaxException
143      * @throws MalformedURLException the malformed URL exception
144      */
145     @Test
146     public void uriWithNonStringKey() throws JAXBException, AAIException, IllegalArgumentException,
147             UnsupportedEncodingException, URISyntaxException {
148         URI uri =
149                 UriBuilder
150                         .fromPath("/aai/" + latest
151                                 + "/network/vces/vce/key1/port-groups/port-group/key2/cvlan-tags/cvlan-tag/144")
152                         .build();
153         URIToRelationshipObject parse = new URIToRelationshipObject(loader, uri);
154         Introspector result = parse.getResult();
155         String expected = "\\{\"related-to\":\"cvlan-tag\",\"related-link\":\"/aai/" + latest
156                 + "/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\"\\}\\]\\}";
157         assertTrue("blah", result.marshal(false).matches(expected));
158     }
159
160     /**
161      * Bad URI.
162      *
163      * @throws JAXBException the JAXB exception
164      * @throws AAIException the AAI exception
165      * @throws IllegalArgumentException the illegal argument exception
166      * @throws UnsupportedEncodingException the unsupported encoding exception
167      */
168     @Test
169     public void badURI() throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException {
170         URI uri = UriBuilder.fromPath("/aai/" + loader.getVersion()
171                 + "/cloud-infrastructure/cloud-regions/cloud-region/mycloudregionowner/mycloudregionid/tenants/tenant/key1/vservers/vserver/key2/l-interadsfaces/l-interface/key3")
172                 .build();
173
174         thrown.expect(AAIException.class);
175         thrown.expect(hasProperty("code", is("AAI_3000")));
176
177         URIToObject parse = new URIToObject(loader, uri);
178
179     }
180 }