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