EdgeRules throws descriptive error on invalid rule
[aai/aai-common.git] / aai-core / src / test / java / org / openecomp / aai / parsers / uri / URIParserTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * org.openecomp.aai
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
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
21 package org.openecomp.aai.parsers.uri;
22
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;
32
33 import javax.ws.rs.core.UriBuilder;
34 import javax.xml.bind.JAXBException;
35 import java.io.UnsupportedEncodingException;
36 import java.net.URI;
37
38 import static org.hamcrest.Matchers.hasProperty;
39 import static org.hamcrest.Matchers.is;
40
41 public class URIParserTest extends AAISetup {
42
43         private Loader loader = LoaderFactory.createLoaderForVersion(ModelType.MOXY, Version.v8);
44
45         @Rule
46         public ExpectedException thrown = ExpectedException.none();
47         
48         /**
49          * Invalid path.
50          *
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
55          */
56         @Test
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();
59                 
60                 thrown.expect(AAIException.class);
61                 thrown.expect(hasProperty("code",  is("AAI_3000")));
62                 
63                 new URIToDBKey(loader, uri);
64         }
65         
66         /**
67          * Invalid path no name space.
68          *
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
73          */
74         @Test
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();
77                 
78                 thrown.expect(AAIException.class);
79                 thrown.expect(hasProperty("code",  is("AAI_3000")));
80                 
81                 new URIToDBKey(loader, uri);
82         }
83         
84         /**
85          * Invalid path partial.
86          *
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
91          */
92         @Test
93     public void invalidPathPartial() throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException {
94                 URI uri = UriBuilder.fromPath("vservers/vserver/key2/l-interfaces/l-interface/key3").build();
95                 
96                 thrown.expect(AAIException.class);
97                 thrown.expect(hasProperty("code", is("AAI_3000")));
98                 
99                 new URIToDBKey(loader, uri);
100         }
101 }