42d26f99a9d5ab188ae685b093b8571f9ffc03fd
[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 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  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
21  */
22 package org.onap.aai.parsers.uri;
23
24 import org.junit.Rule;
25 import org.junit.Test;
26 import org.junit.rules.ExpectedException;
27 import org.onap.aai.AAISetup;
28 import org.onap.aai.exceptions.AAIException;
29 import org.onap.aai.introspection.Loader;
30 import org.onap.aai.introspection.LoaderFactory;
31 import org.onap.aai.introspection.ModelType;
32 import org.onap.aai.introspection.Version;
33
34 import javax.ws.rs.core.UriBuilder;
35 import javax.xml.bind.JAXBException;
36 import java.io.UnsupportedEncodingException;
37 import java.net.URI;
38
39 import static org.hamcrest.Matchers.hasProperty;
40 import static org.hamcrest.Matchers.is;
41
42 public class URIParserTest extends AAISetup {
43
44         private Loader loader = LoaderFactory.createLoaderForVersion(ModelType.MOXY, Version.v8);
45
46         @Rule
47         public ExpectedException thrown = ExpectedException.none();
48         
49         /**
50          * Invalid path.
51          *
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
56          */
57         @Test
58     public void invalidPath() throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException {
59                 URI uri = UriBuilder.fromPath("/aai/" + loader.getVersion() + "/network/tenants/tenant/key1/vservers/vserver/key2/l-interfaces/l-interface/key3").build();
60                 
61                 thrown.expect(AAIException.class);
62                 thrown.expect(hasProperty("code",  is("AAI_3001")));
63                 
64                 new URIToDBKey(loader, uri);
65         }
66         
67         /**
68          * Invalid path no name space.
69          *
70          * @throws JAXBException the JAXB exception
71          * @throws AAIException the AAI exception
72          * @throws IllegalArgumentException the illegal argument exception
73          * @throws UnsupportedEncodingException the unsupported encoding exception
74          */
75         @Test
76     public void invalidPathNoNameSpace() throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException {
77                 URI uri = UriBuilder.fromPath("/aai/" + loader.getVersion() + "/tenants/tenant/key1/vservers/vserver/key2/l-interfaces/l-interface/key3").build();
78                 
79                 thrown.expect(AAIException.class);
80                 thrown.expect(hasProperty("code",  is("AAI_3000")));
81                 
82                 new URIToDBKey(loader, uri);
83         }
84         
85         /**
86          * Invalid path partial.
87          *
88          * @throws JAXBException the JAXB exception
89          * @throws AAIException the AAI exception
90          * @throws IllegalArgumentException the illegal argument exception
91          * @throws UnsupportedEncodingException the unsupported encoding exception
92          */
93         @Test
94     public void invalidPathPartial() throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException {
95                 URI uri = UriBuilder.fromPath("vservers/vserver/key2/l-interfaces/l-interface/key3").build();
96                 
97                 thrown.expect(AAIException.class);
98                 thrown.expect(hasProperty("code", is("AAI_3000")));
99                 
100                 new URIToDBKey(loader, uri);
101         }
102 }