2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 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=========================================================
21 package org.openecomp.aai.parsers.uri;
23 import org.junit.Rule;
24 import org.junit.Test;
25 import org.junit.rules.ExpectedException;
26 import org.openecomp.aai.AAISetup;
27 import org.openecomp.aai.exceptions.AAIException;
28 import org.openecomp.aai.introspection.Loader;
29 import org.openecomp.aai.introspection.LoaderFactory;
30 import org.openecomp.aai.introspection.ModelType;
31 import org.openecomp.aai.introspection.Version;
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;
41 public class URIParserTest extends AAISetup {
43 private Loader loader = LoaderFactory.createLoaderForVersion(ModelType.MOXY, Version.v8);
46 public ExpectedException thrown = ExpectedException.none();
51 * @throws JAXBException the JAXB exception
52 * @throws AAIException the AAI exception
53 * @throws IllegalArgumentException the illegal argument exception
54 * @throws UnsupportedEncodingException the unsupported encoding exception
57 public void invalidPath() throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException {
58 URI uri = UriBuilder.fromPath("/aai/" + loader.getVersion() + "/network/tenants/tenant/key1/vservers/vserver/key2/l-interfaces/l-interface/key3").build();
60 thrown.expect(AAIException.class);
61 thrown.expect(hasProperty("code", is("AAI_3000")));
63 new URIToDBKey(loader, uri);
67 * Invalid path no name space.
69 * @throws JAXBException the JAXB exception
70 * @throws AAIException the AAI exception
71 * @throws IllegalArgumentException the illegal argument exception
72 * @throws UnsupportedEncodingException the unsupported encoding exception
75 public void invalidPathNoNameSpace() throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException {
76 URI uri = UriBuilder.fromPath("/aai/" + loader.getVersion() + "/tenants/tenant/key1/vservers/vserver/key2/l-interfaces/l-interface/key3").build();
78 thrown.expect(AAIException.class);
79 thrown.expect(hasProperty("code", is("AAI_3000")));
81 new URIToDBKey(loader, uri);
85 * Invalid path partial.
87 * @throws JAXBException the JAXB exception
88 * @throws AAIException the AAI exception
89 * @throws IllegalArgumentException the illegal argument exception
90 * @throws UnsupportedEncodingException the unsupported encoding exception
93 public void invalidPathPartial() throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException {
94 URI uri = UriBuilder.fromPath("vservers/vserver/key2/l-interfaces/l-interface/key3").build();
96 thrown.expect(AAIException.class);
97 thrown.expect(hasProperty("code", is("AAI_3000")));
99 new URIToDBKey(loader, uri);