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