ebcaf750fb20c4e4c1de5178b0a7a0a7c0c13f67
[aai/aai-common.git] / aai-core / src / test / java / org / onap / aai / workarounds / LegacyURITransformerTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * org.onap.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.onap.aai.workarounds;
22
23 import org.junit.Test;
24 import org.onap.aai.AAISetup;
25 import org.onap.aai.introspection.Version;
26
27 import java.net.MalformedURLException;
28 import java.net.URI;
29 import java.net.URISyntaxException;
30
31 import static org.junit.Assert.assertEquals;
32
33
34 public class LegacyURITransformerTest extends AAISetup {
35
36         private LegacyURITransformer uriTransformer = LegacyURITransformer.getInstance();
37         private String fromSuccess = "http://myhostname.com:8443/aai/{version}/cloud-infrastructure/tenants/tenant/key1/vservers/vserver/key2";
38         private String toSuccess = "http://myhostname.com:8443/aai/servers/{version}/key1/vservers/key2";
39
40
41         /**
42          * V 5.
43          * @throws URISyntaxException 
44          *
45          * @throws MalformedURLException the malformed URL exception
46          */
47         @Test
48         public void v5() throws URISyntaxException {
49                 testSpec(Version.v8, fromSuccess, fromSuccess);
50         }
51         
52
53         /**
54          * Test spec.
55          *
56          * @param version the version
57          * @param toExpected the to expected
58          * @param fromExpected the from expected
59          * @throws URISyntaxException 
60          * @throws MalformedURLException the malformed URL exception
61          */
62         public void testSpec(Version version, String toExpected, String fromExpected) throws URISyntaxException   {
63                 
64                 URI toExpectedUri = new URI(toExpected.replace("{version}",version.toString()));
65                 URI fromExpectedUri = new URI(fromExpected.replace("{version}",version.toString()));
66                 
67                 URI result = toLegacyURISpec(version, fromExpectedUri);
68
69                 assertEquals("to", toExpectedUri, result);
70                 
71                 result = fromLegacyURISpec(version, toExpectedUri);
72
73                 assertEquals("from", fromExpectedUri, result);
74         }
75         
76         
77     /**
78      * To legacy URL spec.
79      *
80      * @param version the version
81      * @param url the url
82      * @return the url
83      * @throws URISyntaxException 
84      * @throws MalformedURLException the malformed URL exception
85      */
86     public URI toLegacyURISpec(Version version, URI uri) throws URISyntaxException  {
87         return uri;
88         } 
89     
90     /**
91      * From legacy URL spec.
92      *
93      * @param version the version
94      * @param url the url
95      * @return the url
96      * @throws URISyntaxException 
97      * @throws MalformedURLException the malformed URL exception
98      */
99     public URI fromLegacyURISpec(Version version, URI uri) throws URISyntaxException  {
100                 return uri;
101     }
102         
103         
104 }