5ba471190128e15afe168240bc0bae712bb9bb54
[aai/aai-common.git] / aai-core / src / test / java / org / openecomp / aai / parsers / uri / URIToDBKeyTest.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 import static org.junit.Assert.assertEquals;
26
27 import java.io.UnsupportedEncodingException;
28 import java.net.URI;
29
30 import javax.ws.rs.core.UriBuilder;
31 import javax.xml.bind.JAXBException;
32
33 import org.junit.BeforeClass;
34 import org.junit.Ignore;
35 import org.junit.Rule;
36 import org.junit.Test;
37 import org.junit.rules.ExpectedException;
38 import org.powermock.core.classloader.annotations.PrepareForTest;
39
40 import org.openecomp.aai.exceptions.AAIException;
41 import org.openecomp.aai.introspection.Loader;
42 import org.openecomp.aai.introspection.LoaderFactory;
43 import org.openecomp.aai.introspection.ModelInjestor;
44 import org.openecomp.aai.introspection.ModelType;
45 import org.openecomp.aai.introspection.Version;
46
47
48 @Ignore
49 @PrepareForTest(ModelInjestor.class)
50 public class URIToDBKeyTest {
51
52         private Loader loader = LoaderFactory.createLoaderForVersion(ModelType.MOXY, Version.v8);
53
54         @Rule
55         public ExpectedException thrown = ExpectedException.none();
56         
57         /**
58          * Configure.
59          */
60         @BeforeClass
61         public static void configure() {
62                 System.setProperty("AJSC_HOME", ".");
63                 System.setProperty("BUNDLECONFIG_DIR", "src/test/resources/bundleconfig-local");
64         }
65
66         /**
67          * Bad URI.
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 badURI() throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException {
76                 URI uri = UriBuilder.fromPath("/aai/" + loader.getVersion() + "/cloud-infrastructure/tenants/tenant/key1/vservers/vserver/key2/l-interadsfaces/l-interface/key3").build();
77                 
78                 thrown.expect(AAIException.class);
79                 thrown.expect(hasProperty("code",  is("AAI_3001")));
80                 
81                 new URIToDBKey(loader, uri);
82         }
83         
84         /**
85          * No valid tokens.
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 noValidTokens() throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException {
94                 URI uri = UriBuilder.fromPath("/aai/" + loader.getVersion() + "/cloud/blah/blah").build();
95                 
96                 thrown.expect(AAIException.class);
97                 thrown.expect(hasProperty("code",  is("AAI_3001")));
98                 
99                 new URIToDBKey(loader, uri);
100         }
101         
102         /**
103          * Starts with valid namespace.
104          *
105          * @throws JAXBException the JAXB exception
106          * @throws AAIException the AAI exception
107          * @throws IllegalArgumentException the illegal argument exception
108          * @throws UnsupportedEncodingException the unsupported encoding exception
109          */
110         
111         /**
112          * Naming exceptions.
113          *
114          * @throws IllegalArgumentException the illegal argument exception
115          * @throws AAIException the AAI exception
116          * @throws UnsupportedEncodingException the unsupported encoding exception
117          */
118         @Test
119     public void namingExceptions() throws IllegalArgumentException, AAIException, UnsupportedEncodingException {
120                 URI uri = UriBuilder.fromPath("network/vces/vce/key1/port-groups/port-group/key2/cvlan-tags/cvlan-tag/655").build();
121                 URIToDBKey parse = new URIToDBKey(loader, uri);
122                 Object result = parse.getResult();
123
124                 String expected = "vce/key1/port-group/key2/cvlan-tag/655";
125                 
126                 assertEquals("blah", expected, result);
127                 
128     }
129                 
130 }