2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.openecomp.aai.parsers.uri;
23 import static org.hamcrest.Matchers.hasProperty;
24 import static org.hamcrest.Matchers.is;
25 import static org.junit.Assert.assertEquals;
27 import java.io.UnsupportedEncodingException;
30 import javax.ws.rs.core.UriBuilder;
31 import javax.xml.bind.JAXBException;
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;
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;
49 @PrepareForTest(ModelInjestor.class)
50 public class URIToDBKeyTest {
52 private Loader loader = LoaderFactory.createLoaderForVersion(ModelType.MOXY, Version.v8);
55 public ExpectedException thrown = ExpectedException.none();
61 public static void configure() {
62 System.setProperty("AJSC_HOME", ".");
63 System.setProperty("BUNDLECONFIG_DIR", "src/test/resources/bundleconfig-local");
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
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();
78 thrown.expect(AAIException.class);
79 thrown.expect(hasProperty("code", is("AAI_3001")));
81 new URIToDBKey(loader, uri);
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
93 public void noValidTokens() throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException {
94 URI uri = UriBuilder.fromPath("/aai/" + loader.getVersion() + "/cloud/blah/blah").build();
96 thrown.expect(AAIException.class);
97 thrown.expect(hasProperty("code", is("AAI_3001")));
99 new URIToDBKey(loader, uri);
103 * Starts with valid namespace.
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
114 * @throws IllegalArgumentException the illegal argument exception
115 * @throws AAIException the AAI exception
116 * @throws UnsupportedEncodingException the unsupported encoding exception
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();
124 String expected = "vce/key1/port-group/key2/cvlan-tag/655";
126 assertEquals("blah", expected, result);