Update license files, sonar plugin and fix tests
[aai/aai-common.git] / aai-core / src / test / java / org / openecomp / aai / parsers / uri / URIToExtensionInformationTest.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.junit.Assert.assertEquals;
24
25 import java.io.UnsupportedEncodingException;
26 import java.net.URI;
27
28 import javax.ws.rs.core.UriBuilder;
29 import javax.xml.bind.JAXBException;
30
31 import org.junit.BeforeClass;
32 import org.junit.Test;
33
34 import org.openecomp.aai.exceptions.AAIException;
35 import org.openecomp.aai.introspection.Loader;
36 import org.openecomp.aai.introspection.LoaderFactory;
37 import org.openecomp.aai.introspection.ModelType;
38 import org.openecomp.aai.introspection.Version;
39 import org.openecomp.aai.restcore.HttpMethod;
40
41
42 public class URIToExtensionInformationTest {
43
44         private Loader v8Loader = LoaderFactory.createLoaderForVersion(ModelType.MOXY, Version.v8);
45         
46         /**
47          * Configure.
48          */
49         @BeforeClass
50         public static void configure() {
51                 System.setProperty("AJSC_HOME", "./src/test/resources/");
52                 System.setProperty("BUNDLECONFIG_DIR", "bundleconfig-local");
53         }
54         
55         /**
56          * Vservers V 7.
57          *
58          * @throws JAXBException the JAXB exception
59          * @throws AAIException the AAI exception
60          * @throws IllegalArgumentException the illegal argument exception
61          * @throws UnsupportedEncodingException the unsupported encoding exception
62          */
63         @Test
64     public void vserversV8() throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException {
65                 URI uri = UriBuilder.fromPath("/aai/" + v8Loader.getVersion() + "/cloud-infrastructure/cloud-regions/cloud-region/att-aic/AAIAIC25/tenants/tenant/key1/vservers/vserver/key2").build();
66                 URIToExtensionInformation parse = new URIToExtensionInformation(v8Loader, uri);
67                 
68                 String namespace = "cloudInfrastructure";
69                 String preMethodName = "DynamicAddCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserverPreProc";
70                 String postMethodName = "DynamicAddCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserverPostProc";
71                 String topLevel = "CloudRegion";
72                 testSpec(parse, HttpMethod.PUT, namespace, preMethodName, postMethodName, topLevel);
73
74         }
75
76         /**
77          * Test spec.
78          *
79          * @param info the info
80          * @param httpMethod the http method
81          * @param namespace the namespace
82          * @param preMethodName the pre method name
83          * @param postMethodName the post method name
84          * @param topLevel the top level
85          */
86         private void testSpec(URIToExtensionInformation info, HttpMethod httpMethod, String namespace, String preMethodName, String postMethodName, String topLevel) {
87                 
88
89                 String namespaceResult = info.getNamespace();
90                 String methodNameResult = info.getMethodName(httpMethod, true);
91                 
92                 assertEquals("namespace", namespace, namespaceResult);
93                 assertEquals("preprocess method name", preMethodName, methodNameResult);
94                 methodNameResult = info.getMethodName(httpMethod, false);
95
96                 assertEquals("postprocess method name", postMethodName, methodNameResult);
97
98                 String topLevelResult = info.getTopObject();
99                 
100                 assertEquals("topLevel", topLevel, topLevelResult);
101         }
102         
103         
104 }