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