Sync up the changes for v15
[aai/aai-common.git] / aai-core / src / test / java / org / onap / aai / parsers / uri / URIToExtensionInformationTest.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
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
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 package org.onap.aai.parsers.uri;
21
22 import org.junit.Test;
23 import org.onap.aai.AAISetup;
24 import org.onap.aai.exceptions.AAIException;
25 import org.onap.aai.introspection.Loader;
26 import org.onap.aai.introspection.ModelType;
27 import org.onap.aai.restcore.HttpMethod;
28 import org.onap.aai.setup.SchemaVersion;
29
30 import javax.annotation.PostConstruct;
31 import javax.ws.rs.core.UriBuilder;
32 import javax.xml.bind.JAXBException;
33 import java.io.UnsupportedEncodingException;
34 import java.net.URI;
35
36 import static org.junit.Assert.assertEquals;
37
38 public class URIToExtensionInformationTest extends AAISetup {
39
40         
41         private Loader specificLoader ;
42         
43         /**
44          * Vservers V 7.
45          *
46          * @throws JAXBException the JAXB exception
47          * @throws AAIException the AAI exception
48          * @throws IllegalArgumentException the illegal argument exception
49          * @throws UnsupportedEncodingException the unsupported encoding exception
50          */
51         
52         @PostConstruct
53         public void createLoader(){
54                 specificLoader = loaderFactory.createLoaderForVersion(ModelType.MOXY, new SchemaVersion("v10"));
55         }
56         
57         @Test
58     public void vserversV8() throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException {
59                 URI uri = UriBuilder.fromPath("/aai/" + specificLoader.getVersion() + "/cloud-infrastructure/cloud-regions/cloud-region/testOwner1/testRegion1/tenants/tenant/key1/vservers/vserver/key2").build();
60                 URIToExtensionInformation parse = new URIToExtensionInformation(specificLoader, uri);
61                 
62                 String namespace = "cloudInfrastructure";
63                 String preMethodName = "DynamicAddCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserverPreProc";
64                 String postMethodName = "DynamicAddCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserverPostProc";
65                 String topLevel = "CloudRegion";
66                 testSpec(parse, HttpMethod.PUT, namespace, preMethodName, postMethodName, topLevel);
67
68         }
69
70         /**
71          * Test spec.
72          *
73          * @param info the info
74          * @param httpMethod the http method
75          * @param namespace the namespace
76          * @param preMethodName the pre method name
77          * @param postMethodName the post method name
78          * @param topLevel the top level
79          */
80         private void testSpec(URIToExtensionInformation info, HttpMethod httpMethod, String namespace, String preMethodName, String postMethodName, String topLevel) {
81                 
82
83                 String namespaceResult = info.getNamespace();
84                 String methodNameResult = info.getMethodName(httpMethod, true);
85                 
86                 assertEquals("namespace", namespace, namespaceResult);
87                 assertEquals("preprocess method name", preMethodName, methodNameResult);
88                 methodNameResult = info.getMethodName(httpMethod, false);
89
90                 assertEquals("postprocess method name", postMethodName, methodNameResult);
91
92                 String topLevelResult = info.getTopObject();
93                 
94                 assertEquals("topLevel", topLevel, topLevelResult);
95         }
96         
97         
98 }