AAI-1523 checkstyle warnings for aai-core parsers
[aai/aai-common.git] / aai-core / src / test / java / org / onap / aai / parsers / uri / URIParserTest.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
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
10  *
11  *    http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20 package org.onap.aai.parsers.uri;
21
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.ModelType;
29 import org.onap.aai.setup.SchemaVersion;
30
31 import javax.annotation.PostConstruct;
32 import javax.ws.rs.core.UriBuilder;
33 import javax.xml.bind.JAXBException;
34 import java.io.UnsupportedEncodingException;
35 import java.net.URI;
36
37 import static org.hamcrest.Matchers.hasProperty;
38 import static org.hamcrest.Matchers.is;
39
40 public class URIParserTest extends AAISetup {
41
42     private Loader loader ;
43
44     @Rule
45     public ExpectedException thrown = ExpectedException.none();
46     
47     /**
48      * Invalid path.
49      *
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
54      */
55     @PostConstruct
56     public void createLoader(){
57         loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, new SchemaVersion("v10"));
58     }
59
60     @Test
61     public void invalidPath() throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException {
62         URI uri = UriBuilder.fromPath("/aai/" + loader.getVersion() + "/network/tenants/tenant/key1/vservers/vserver/key2/l-interfaces/l-interface/key3").build();
63         
64         thrown.expect(AAIException.class);
65         thrown.expect(hasProperty("code",  is("AAI_3001")));
66         
67         new URIToDBKey(loader, uri);
68     }
69     
70     /**
71      * Invalid path no name space.
72      *
73      * @throws JAXBException the JAXB exception
74      * @throws AAIException the AAI exception
75      * @throws IllegalArgumentException the illegal argument exception
76      * @throws UnsupportedEncodingException the unsupported encoding exception
77      */
78     @Test
79     public void invalidPathNoNameSpace() throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException {
80         URI uri = UriBuilder.fromPath("/aai/" + loader.getVersion() + "/tenants/tenant/key1/vservers/vserver/key2/l-interfaces/l-interface/key3").build();
81         
82         thrown.expect(AAIException.class);
83         thrown.expect(hasProperty("code",  is("AAI_3000")));
84         
85         new URIToDBKey(loader, uri);
86     }
87     
88     /**
89      * Invalid path partial.
90      *
91      * @throws JAXBException the JAXB exception
92      * @throws AAIException the AAI exception
93      * @throws IllegalArgumentException the illegal argument exception
94      * @throws UnsupportedEncodingException the unsupported encoding exception
95      */
96     @Test
97     public void invalidPathPartial() throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException {
98         URI uri = UriBuilder.fromPath("vservers/vserver/key2/l-interfaces/l-interface/key3").build();
99         
100         thrown.expect(AAIException.class);
101         thrown.expect(hasProperty("code", is("AAI_3000")));
102         
103         new URIToDBKey(loader, uri);
104     }
105 }