2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 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=========================================================
20 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 package org.onap.aai.parsers.uri;
24 import org.junit.Ignore;
25 import org.junit.Rule;
26 import org.junit.Test;
27 import org.junit.rules.ExpectedException;
28 import org.onap.aai.AAISetup;
29 import org.onap.aai.exceptions.AAIException;
30 import org.onap.aai.parsers.exceptions.DoesNotStartWithValidNamespaceException;
31 import org.onap.aai.db.props.AAIProperties;
32 import org.onap.aai.introspection.*;
33 import org.powermock.core.classloader.annotations.PrepareForTest;
35 import javax.ws.rs.core.UriBuilder;
36 import javax.xml.bind.JAXBException;
37 import java.io.UnsupportedEncodingException;
40 import static org.hamcrest.Matchers.hasProperty;
41 import static org.hamcrest.Matchers.is;
42 import static org.junit.Assert.assertEquals;
46 @PrepareForTest(ModelInjestor.class)
47 public class URIToDBKeyTest extends AAISetup {
49 private Loader loader = LoaderFactory.createLoaderForVersion(ModelType.MOXY, AAIProperties.LATEST);
52 public ExpectedException thrown = ExpectedException.none();
57 * @throws JAXBException the JAXB exception
58 * @throws AAIException the AAI exception
59 * @throws IllegalArgumentException the illegal argument exception
60 * @throws UnsupportedEncodingException the unsupported encoding exception
63 public void uri() throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException {
64 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();
65 URIToDBKey parse = new URIToDBKey(loader, uri);
66 Object result = parse.getResult();
68 String expected = "cloud-region/tenant/vserver/l-interface";
70 assertEquals("blah", expected, result);
77 * @throws JAXBException the JAXB exception
78 * @throws AAIException the AAI exception
79 * @throws IllegalArgumentException the illegal argument exception
80 * @throws UnsupportedEncodingException the unsupported encoding exception
83 public void uriNoVersion() throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException {
84 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();
85 URIToDBKey parse = new URIToDBKey(loader, uri);
86 Object result = parse.getResult();
88 String expected = "cloud-region/tenant/vserver/l-interface";
90 assertEquals("blah", expected, result);
98 * @throws JAXBException the JAXB exception
99 * @throws AAIException the AAI exception
100 * @throws IllegalArgumentException the illegal argument exception
101 * @throws UnsupportedEncodingException the unsupported encoding exception
104 public void badURI() throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException {
105 URI uri = UriBuilder.fromPath("/aai/" + loader.getVersion() + "/cloud-infrastructure/tenants/tenant/key1/vservers/vserver/key2/l-interadsfaces/l-interface/key3").build();
107 thrown.expect(AAIException.class);
108 thrown.expect(hasProperty("code", is("AAI_3001")));
110 new URIToDBKey(loader, uri);
114 * NotValid namespace.
116 * @throws JAXBException the JAXB exception
117 * @throws DoesNotStartWithValidNamespaceException the AAI exception
118 * @throws IllegalArgumentException the illegal argument exception
119 * @throws UnsupportedEncodingException the unsupported encoding exception
122 public void notValidNamespace() throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException {
123 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();
124 thrown.expect(DoesNotStartWithValidNamespaceException.class);
125 URIToDBKey parse = new URIToDBKey(loader, uri);
132 * @throws JAXBException the JAXB exception
133 * @throws AAIException the AAI exception
134 * @throws IllegalArgumentException the illegal argument exception
135 * @throws UnsupportedEncodingException the unsupported encoding exception
138 public void noValidTokens() throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException {
139 URI uri = UriBuilder.fromPath("/aai/" + loader.getVersion() + "/cloud/blah/blah").build();
141 thrown.expect(AAIException.class);
142 thrown.expect(hasProperty("code", is("AAI_3000")));
144 new URIToDBKey(loader, uri);
148 * Starts with valid namespace.
150 * @throws JAXBException the JAXB exception
151 * @throws AAIException the AAI exception
152 * @throws IllegalArgumentException the illegal argument exception
153 * @throws UnsupportedEncodingException the unsupported encoding exception
156 public void startsWithValidNamespace() throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException {
157 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();
159 URIToDBKey parse = new URIToDBKey(loader, uri);
160 Object result = parse.getResult();
162 String expected = "cloud-region/tenant/vserver/l-interface";
164 assertEquals("blah", expected, result);
170 * @throws IllegalArgumentException the illegal argument exception
171 * @throws AAIException the AAI exception
172 * @throws UnsupportedEncodingException the unsupported encoding exception
175 public void namingExceptions() throws IllegalArgumentException, AAIException, UnsupportedEncodingException {
176 URI uri = UriBuilder.fromPath("network/vces/vce/key1/port-groups/port-group/key2/cvlan-tags/cvlan-tag/655").build();
177 URIToDBKey parse = new URIToDBKey(loader, uri);
178 Object result = parse.getResult();
180 String expected = "vce/port-group/cvlan-tag";
182 assertEquals("blah", expected, result);