1fa3aea20169d4e585db17f4c8f344476f77eee7
[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 static org.hamcrest.Matchers.hasProperty;
24 import static org.hamcrest.Matchers.is;
25
26 import java.io.UnsupportedEncodingException;
27 import java.net.URI;
28
29 import javax.ws.rs.core.UriBuilder;
30 import javax.xml.bind.JAXBException;
31
32 import org.junit.BeforeClass;
33 import org.junit.Ignore;
34 import org.junit.Rule;
35 import org.junit.Test;
36 import org.junit.rules.ExpectedException;
37
38 import org.openecomp.aai.exceptions.AAIException;
39 import org.openecomp.aai.introspection.Loader;
40 import org.openecomp.aai.introspection.LoaderFactory;
41 import org.openecomp.aai.introspection.ModelType;
42 import org.openecomp.aai.introspection.Version;
43
44 @Ignore
45 public class URIParserTest {
46
47         private Loader loader = LoaderFactory.createLoaderForVersion(ModelType.MOXY, Version.v8);
48
49         @Rule
50         public ExpectedException thrown = ExpectedException.none();
51         
52         /**
53          * Configure.
54          */
55         @BeforeClass
56         public static void configure() {
57                 System.setProperty("AJSC_HOME", ".");
58                 System.setProperty("BUNDLECONFIG_DIR", "src/test/resources/bundleconfig-local");
59         }
60         
61         /**
62          * Invalid path.
63          *
64          * @throws JAXBException the JAXB exception
65          * @throws AAIException the AAI exception
66          * @throws IllegalArgumentException the illegal argument exception
67          * @throws UnsupportedEncodingException the unsupported encoding exception
68          */
69         @Test
70     public void invalidPath() throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException {
71                 URI uri = UriBuilder.fromPath("/aai/" + loader.getVersion() + "/network/tenants/tenant/key1/vservers/vserver/key2/l-interfaces/l-interface/key3").build();
72                 
73                 thrown.expect(AAIException.class);
74                 thrown.expect(hasProperty("code",  is("AAI_3001")));
75                 
76                 new URIToDBKey(loader, uri);
77         }
78         
79         /**
80          * Invalid path no name space.
81          *
82          * @throws JAXBException the JAXB exception
83          * @throws AAIException the AAI exception
84          * @throws IllegalArgumentException the illegal argument exception
85          * @throws UnsupportedEncodingException the unsupported encoding exception
86          */
87         @Test
88     public void invalidPathNoNameSpace() throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException {
89                 URI uri = UriBuilder.fromPath("/aai/" + loader.getVersion() + "/tenants/tenant/key1/vservers/vserver/key2/l-interfaces/l-interface/key3").build();
90                 
91                 thrown.expect(AAIException.class);
92                 thrown.expect(hasProperty("code",  is("AAI_3000")));
93                 
94                 new URIToDBKey(loader, uri);
95         }
96         
97         /**
98          * Invalid path partial.
99          *
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
104          */
105         @Test
106     public void invalidPathPartial() throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException {
107                 URI uri = UriBuilder.fromPath("vservers/vserver/key2/l-interfaces/l-interface/key3").build();
108                 
109                 thrown.expect(AAIException.class);
110                 thrown.expect(hasProperty("code", is("AAI_3000")));
111                 
112                 new URIToDBKey(loader, uri);
113         }
114 }