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.Rule;
23 import org.junit.Test;
24 import org.junit.rules.ExpectedException;
25 import org.onap.aai.AAISetup;
26 import org.onap.aai.exceptions.AAIException;
27 import org.onap.aai.introspection.Loader;
28 import org.onap.aai.introspection.LoaderFactory;
29 import org.onap.aai.introspection.ModelType;
30 import org.onap.aai.introspection.Version;
32 import javax.ws.rs.core.UriBuilder;
33 import javax.xml.bind.JAXBException;
34 import java.io.UnsupportedEncodingException;
37 import static org.hamcrest.Matchers.hasProperty;
38 import static org.hamcrest.Matchers.is;
40 public class URIParserTest extends AAISetup {
42 private Loader loader = LoaderFactory.createLoaderForVersion(ModelType.MOXY, Version.v8);
45 public ExpectedException thrown = ExpectedException.none();
50 * @throws JAXBException the JAXB exception
51 * @throws AAIException the AAI exception
52 * @throws IllegalArgumentException the illegal argument exception
53 * @throws UnsupportedEncodingException the unsupported encoding exception
56 public void invalidPath() throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException {
57 URI uri = UriBuilder.fromPath("/aai/" + loader.getVersion() + "/network/tenants/tenant/key1/vservers/vserver/key2/l-interfaces/l-interface/key3").build();
59 thrown.expect(AAIException.class);
60 thrown.expect(hasProperty("code", is("AAI_3001")));
62 new URIToDBKey(loader, uri);
66 * Invalid path no name space.
68 * @throws JAXBException the JAXB exception
69 * @throws AAIException the AAI exception
70 * @throws IllegalArgumentException the illegal argument exception
71 * @throws UnsupportedEncodingException the unsupported encoding exception
74 public void invalidPathNoNameSpace() throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException {
75 URI uri = UriBuilder.fromPath("/aai/" + loader.getVersion() + "/tenants/tenant/key1/vservers/vserver/key2/l-interfaces/l-interface/key3").build();
77 thrown.expect(AAIException.class);
78 thrown.expect(hasProperty("code", is("AAI_3000")));
80 new URIToDBKey(loader, uri);
84 * Invalid path partial.
86 * @throws JAXBException the JAXB exception
87 * @throws AAIException the AAI exception
88 * @throws IllegalArgumentException the illegal argument exception
89 * @throws UnsupportedEncodingException the unsupported encoding exception
92 public void invalidPathPartial() throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException {
93 URI uri = UriBuilder.fromPath("vservers/vserver/key2/l-interfaces/l-interface/key3").build();
95 thrown.expect(AAIException.class);
96 thrown.expect(hasProperty("code", is("AAI_3000")));
98 new URIToDBKey(loader, uri);