2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2018 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.onap.aai.parsers.uri;
23 import static org.junit.Assert.assertEquals;
25 import java.io.UnsupportedEncodingException;
28 import javax.annotation.PostConstruct;
29 import javax.ws.rs.core.UriBuilder;
30 import javax.xml.bind.JAXBException;
32 import org.junit.Test;
33 import org.springframework.test.annotation.DirtiesContext;
35 import org.onap.aai.AAISetup;
36 import org.onap.aai.exceptions.AAIException;
37 import org.onap.aai.introspection.Loader;
38 import org.onap.aai.introspection.ModelType;
39 import org.onap.aai.restcore.HttpMethod;
40 import org.onap.aai.setup.SchemaVersion;
42 @DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS)
43 public class URIToExtensionInformationTest extends AAISetup {
45 private Loader specificLoader;
50 * @throws JAXBException the JAXB exception
51 * @throws AAIException the AAI exception
52 * @throws IllegalArgumentException the illegal argument exception
53 * @throws UnsupportedEncodingException the unsupported encoding exception
57 public void createLoader() {
58 specificLoader = loaderFactory.createLoaderForVersion(ModelType.MOXY, new SchemaVersion("v10"));
62 public void vserversV8()
63 throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException {
64 URI uri = UriBuilder.fromPath("/aai/" + specificLoader.getVersion()
65 + "/cloud-infrastructure/cloud-regions/cloud-region/testOwner1/testRegion1/tenants/tenant/key1/vservers/vserver/key2")
67 URIToExtensionInformation parse = new URIToExtensionInformation(specificLoader, uri);
69 String namespace = "cloudInfrastructure";
70 String preMethodName =
71 "DynamicAddCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserverPreProc";
72 String postMethodName =
73 "DynamicAddCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserverPostProc";
74 String topLevel = "CloudRegion";
75 testSpec(parse, HttpMethod.PUT, namespace, preMethodName, postMethodName, topLevel);
82 * @param info the info
83 * @param httpMethod the http method
84 * @param namespace the namespace
85 * @param preMethodName the pre method name
86 * @param postMethodName the post method name
87 * @param topLevel the top level
89 private void testSpec(URIToExtensionInformation info, HttpMethod httpMethod, String namespace, String preMethodName,
90 String postMethodName, String topLevel) {
92 String namespaceResult = info.getNamespace();
93 String methodNameResult = info.getMethodName(httpMethod, true);
95 assertEquals("namespace", namespace, namespaceResult);
96 assertEquals("preprocess method name", preMethodName, methodNameResult);
97 methodNameResult = info.getMethodName(httpMethod, false);
99 assertEquals("postprocess method name", postMethodName, methodNameResult);
101 String topLevelResult = info.getTopObject();
103 assertEquals("topLevel", topLevel, topLevelResult);