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=========================================================
21 package org.onap.aai.parsers.uri;
23 import static org.hamcrest.Matchers.hasProperty;
24 import static org.hamcrest.Matchers.is;
26 import java.io.UnsupportedEncodingException;
29 import javax.annotation.PostConstruct;
30 import javax.ws.rs.core.UriBuilder;
31 import javax.xml.bind.JAXBException;
33 import org.junit.Rule;
34 import org.junit.Test;
35 import org.junit.rules.ExpectedException;
36 import org.onap.aai.AAISetup;
37 import org.onap.aai.exceptions.AAIException;
38 import org.onap.aai.introspection.Loader;
39 import org.onap.aai.introspection.ModelType;
40 import org.onap.aai.setup.SchemaVersion;
42 public class URIParserTest extends AAISetup {
44 private Loader loader;
47 public ExpectedException thrown = ExpectedException.none();
52 * @throws JAXBException the JAXB exception
53 * @throws AAIException the AAI exception
54 * @throws IllegalArgumentException the illegal argument exception
55 * @throws UnsupportedEncodingException the unsupported encoding exception
58 public void createLoader() {
59 loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, new SchemaVersion("v10"));
63 public void invalidPath()
64 throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException {
67 .fromPath("/aai/" + loader.getVersion()
68 + "/network/tenants/tenant/key1/vservers/vserver/key2/l-interfaces/l-interface/key3")
71 thrown.expect(AAIException.class);
72 thrown.expect(hasProperty("code", is("AAI_3001")));
74 new URIToDBKey(loader, uri);
78 * Invalid path no name space.
80 * @throws JAXBException the JAXB exception
81 * @throws AAIException the AAI exception
82 * @throws IllegalArgumentException the illegal argument exception
83 * @throws UnsupportedEncodingException the unsupported encoding exception
86 public void invalidPathNoNameSpace()
87 throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException {
88 URI uri = UriBuilder.fromPath("/aai/" + loader.getVersion()
89 + "/tenants/tenant/key1/vservers/vserver/key2/l-interfaces/l-interface/key3").build();
91 thrown.expect(AAIException.class);
92 thrown.expect(hasProperty("code", is("AAI_3000")));
94 new URIToDBKey(loader, uri);
98 * Invalid path partial.
100 * @throws JAXBException the JAXB exception
101 * @throws AAIException the AAI exception
102 * @throws IllegalArgumentException the illegal argument exception
103 * @throws UnsupportedEncodingException the unsupported encoding exception
106 public void invalidPathPartial()
107 throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException {
108 URI uri = UriBuilder.fromPath("vservers/vserver/key2/l-interfaces/l-interface/key3").build();
110 thrown.expect(AAIException.class);
111 thrown.expect(hasProperty("code", is("AAI_3000")));
113 new URIToDBKey(loader, uri);