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=========================================================
20 package org.onap.aai.parsers.uri;
22 import org.junit.Ignore;
23 import org.junit.Rule;
24 import org.junit.Test;
25 import org.junit.rules.ExpectedException;
26 import org.onap.aai.AAISetup;
27 import org.onap.aai.exceptions.AAIException;
28 import org.onap.aai.parsers.exceptions.DoesNotStartWithValidNamespaceException;
29 import org.onap.aai.db.props.AAIProperties;
30 import org.onap.aai.introspection.*;
31 import org.powermock.core.classloader.annotations.PrepareForTest;
33 import javax.ws.rs.core.UriBuilder;
34 import javax.xml.bind.JAXBException;
35 import java.io.UnsupportedEncodingException;
38 import static org.hamcrest.Matchers.hasProperty;
39 import static org.hamcrest.Matchers.is;
40 import static org.junit.Assert.assertEquals;
44 @PrepareForTest(ModelInjestor.class)
45 public class URIToDBKeyTest extends AAISetup {
47 private Loader loader = LoaderFactory.createLoaderForVersion(ModelType.MOXY, AAIProperties.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
61 public void uri() throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException {
62 URI uri = UriBuilder.fromPath("/aai/" + loader.getVersion() + "/cloud-infrastructure/cloud-regions/cloud-region/cloudOwner-key/cloudRegion-key/tenants/tenant/tenantId-key/vservers/vserver/vserverId-key/l-interfaces/l-interface/key3").build();
63 URIToDBKey parse = new URIToDBKey(loader, uri);
64 Object result = parse.getResult();
66 String expected = "cloud-region/tenant/vserver/l-interface";
68 assertEquals("blah", expected, result);
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
81 public void uriNoVersion() throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException {
82 URI uri = UriBuilder.fromPath("/cloud-infrastructure/cloud-regions/cloud-region/cloudOwner-key/cloudRegion-key/tenants/tenant/tenantId-key/vservers/vserver/vserverId-key/l-interfaces/l-interface/key3").build();
83 URIToDBKey parse = new URIToDBKey(loader, uri);
84 Object result = parse.getResult();
86 String expected = "cloud-region/tenant/vserver/l-interface";
88 assertEquals("blah", expected, result);
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
102 public void badURI() throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException {
103 URI uri = UriBuilder.fromPath("/aai/" + loader.getVersion() + "/cloud-infrastructure/tenants/tenant/key1/vservers/vserver/key2/l-interadsfaces/l-interface/key3").build();
105 thrown.expect(AAIException.class);
106 thrown.expect(hasProperty("code", is("AAI_3001")));
108 new URIToDBKey(loader, uri);
112 * NotValid namespace.
114 * @throws JAXBException the JAXB exception
115 * @throws DoesNotStartWithValidNamespaceException the AAI exception
116 * @throws IllegalArgumentException the illegal argument exception
117 * @throws UnsupportedEncodingException the unsupported encoding exception
120 public void notValidNamespace() throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException {
121 URI uri = UriBuilder.fromPath("/cloud-region/cloud-regions/cloud-region/cloudOwner-key/cloudRegion-key/tenants/tenant/tenantId-key/vservers/vserver/vserverId-key/l-interfaces/l-interface/key3").build();
122 thrown.expect(DoesNotStartWithValidNamespaceException.class);
123 URIToDBKey parse = new URIToDBKey(loader, uri);
130 * @throws JAXBException the JAXB exception
131 * @throws AAIException the AAI exception
132 * @throws IllegalArgumentException the illegal argument exception
133 * @throws UnsupportedEncodingException the unsupported encoding exception
136 public void noValidTokens() throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException {
137 URI uri = UriBuilder.fromPath("/aai/" + loader.getVersion() + "/cloud/blah/blah").build();
139 thrown.expect(AAIException.class);
140 thrown.expect(hasProperty("code", is("AAI_3000")));
142 new URIToDBKey(loader, uri);
146 * Starts with valid namespace.
148 * @throws JAXBException the JAXB exception
149 * @throws AAIException the AAI exception
150 * @throws IllegalArgumentException the illegal argument exception
151 * @throws UnsupportedEncodingException the unsupported encoding exception
154 public void startsWithValidNamespace() throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException {
155 URI uri = UriBuilder.fromPath("/aai/" + loader.getVersion() + "/cloud-infrastructure/cloud-regions/cloud-region/cloudOwner-key/cloudRegion-key/tenants/tenant/tenantId-key/vservers/vserver/vserverId-key/l-interfaces/l-interface/key3").build();
157 URIToDBKey parse = new URIToDBKey(loader, uri);
158 Object result = parse.getResult();
160 String expected = "cloud-region/tenant/vserver/l-interface";
162 assertEquals("blah", expected, result);
168 * @throws IllegalArgumentException the illegal argument exception
169 * @throws AAIException the AAI exception
170 * @throws UnsupportedEncodingException the unsupported encoding exception
173 public void namingExceptions() throws IllegalArgumentException, AAIException, UnsupportedEncodingException {
174 URI uri = UriBuilder.fromPath("network/vces/vce/key1/port-groups/port-group/key2/cvlan-tags/cvlan-tag/655").build();
175 URIToDBKey parse = new URIToDBKey(loader, uri);
176 Object result = parse.getResult();
178 String expected = "vce/port-group/cvlan-tag";
180 assertEquals("blah", expected, result);