Initial commit with all the necessary files
[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 v6Loader = LoaderFactory.createLoaderForVersion(ModelType.MOXY, Version.v8);
45         private Loader v7Loader = LoaderFactory.createLoaderForVersion(ModelType.MOXY, Version.v8);
46         
47         /**
48          * Configure.
49          */
50         @BeforeClass
51         public static void configure() {
52                 System.setProperty("AJSC_HOME", "./src/test/resources/");
53                 System.setProperty("BUNDLECONFIG_DIR", "bundleconfig-local");
54         }
55         
56         /**
57          * Vservers V 7.
58          *
59          * @throws JAXBException the JAXB exception
60          * @throws AAIException the AAI exception
61          * @throws IllegalArgumentException the illegal argument exception
62          * @throws UnsupportedEncodingException the unsupported encoding exception
63          */
64         @Test
65     public void vserversV7() throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException {
66                 URI uri = UriBuilder.fromPath("/aai/" + v7Loader.getVersion() + "/cloud-infrastructure/cloud-regions/cloud-region/att-aic/AAIAIC25/tenants/tenant/key1/vservers/vserver/key2").build();
67                 URIToExtensionInformation parse = new URIToExtensionInformation(v7Loader, uri);
68                 
69                 String namespace = "cloudInfrastructure";
70                 String preMethodName = "DynamicAddCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserverPreProc";
71                 String postMethodName = "DynamicAddCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserverPostProc";
72                 String topLevel = "CloudRegion";
73                 testSpec(parse, HttpMethod.PUT, namespace, preMethodName, postMethodName, topLevel);
74                 
75         }
76         
77         /**
78          * New vce V 6.
79          *
80          * @throws JAXBException the JAXB exception
81          * @throws AAIException the AAI exception
82          * @throws IllegalArgumentException the illegal argument exception
83          * @throws UnsupportedEncodingException the unsupported encoding exception
84          */
85         @Test
86     public void newVceV6() throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException {
87                 URI uri = UriBuilder.fromPath("/aai/" + v6Loader.getVersion() + "/network/newvces/newvce/key1").build();
88                 URIToExtensionInformation parse = new URIToExtensionInformation(v6Loader, uri);
89                 
90                 String namespace = "network";
91                 String preMethodName = "DynamicDelNetworkNewvcesNewvcePreProc";
92                 String postMethodName = "DynamicDelNetworkNewvcesNewvcePostProc";
93                 String topLevel = "Newvce";
94                 testSpec(parse, HttpMethod.DELETE, namespace, preMethodName, postMethodName, topLevel);
95                 
96         }
97         
98         /**
99          * New vce V 7.
100          *
101          * @throws JAXBException the JAXB exception
102          * @throws AAIException the AAI exception
103          * @throws IllegalArgumentException the illegal argument exception
104          * @throws UnsupportedEncodingException the unsupported encoding exception
105          */
106         @Test
107     public void newVceV7() throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException {
108                 URI uri = UriBuilder.fromPath("/aai/" + v7Loader.getVersion() + "/network/newvces/newvce/key1").build();
109                 URIToExtensionInformation parse = new URIToExtensionInformation(v7Loader, uri);
110                 
111                 String namespace = "network";
112                 String preMethodName = "DynamicDelNetworkNewvcesNewvcePreProc";
113                 String postMethodName = "DynamicDelNetworkNewvcesNewvcePostProc";
114                 String topLevel = "Newvce";
115                 testSpec(parse, HttpMethod.DELETE, namespace, preMethodName, postMethodName, topLevel);
116                 
117         }
118         
119         /**
120          * Test spec.
121          *
122          * @param info the info
123          * @param httpMethod the http method
124          * @param namespace the namespace
125          * @param preMethodName the pre method name
126          * @param postMethodName the post method name
127          * @param topLevel the top level
128          */
129         private void testSpec(URIToExtensionInformation info, HttpMethod httpMethod, String namespace, String preMethodName, String postMethodName, String topLevel) {
130                 
131
132                 String namespaceResult = info.getNamespace();
133                 String methodNameResult = info.getMethodName(httpMethod, true);
134                 
135                 assertEquals("namespace", namespace, namespaceResult);
136                 assertEquals("preprocess method name", preMethodName, methodNameResult);
137                 methodNameResult = info.getMethodName(httpMethod, false);
138
139                 assertEquals("postprocess method name", postMethodName, methodNameResult);
140
141                 String topLevelResult = info.getTopObject();
142                 
143                 assertEquals("topLevel", topLevel, topLevelResult);
144         }
145         
146         
147 }