Merge of new rebased code
[appc.git] / appc-adapters / appc-iaas-adapter / appc-iaas-adapter-bundle / src / test / java / org / openecomp / appc / adapter / iaas / impl / TestVMURL.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * openECOMP : APP-C
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights
6  *                                              reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  * 
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  * 
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21
22
23
24 package org.openecomp.appc.adapter.iaas.impl;
25
26 import static org.junit.Assert.assertEquals;
27 import static org.junit.Assert.assertNull;
28
29 import java.util.Properties;
30
31 import org.junit.BeforeClass;
32 import org.junit.Test;
33 import org.openecomp.appc.adapter.iaas.impl.VMURL;
34 import org.openecomp.appc.configuration.ConfigurationFactory;
35
36 public class TestVMURL {
37
38     private static String IP;
39     private static String PORT;
40     private static String TENANTID;
41     private static String VMID;
42     private static String URL;
43
44     @BeforeClass
45     public static void before() {
46         IP = "192.168.1.2";
47         PORT = "5000";
48         TENANTID = "abcde12345fghijk6789lmnopq123rst";
49         VMID = "abc12345-1234-5678-890a-abcdefg12345";
50         URL = String.format("http://%s:%s/v2/%s/servers/%s", IP, PORT, TENANTID, VMID);
51     }
52
53     /**
54      * Test that we can parse and interpret valid URLs
55      */
56     @Test
57     public void testValidURLs() {
58         VMURL url = VMURL.parseURL(URL);
59
60         assertEquals("http", url.getScheme());
61         assertEquals(IP, url.getHost());
62         assertEquals(PORT, url.getPort());
63         assertEquals(TENANTID, url.getTenantId());
64         assertEquals(VMID, url.getServerId());
65
66         url = VMURL.parseURL(String.format("http://%s/v2/%s/servers/%s", IP, TENANTID, VMID));
67         assertEquals("http", url.getScheme());
68         assertEquals(IP, url.getHost());
69         assertNull(url.getPort());
70         assertEquals(TENANTID, url.getTenantId());
71         assertEquals(VMID, url.getServerId());
72     }
73
74     /**
75      * Test that we ignore and return null for invalid URLs
76      */
77     @Test
78     public void testInvalidURLs() {
79         VMURL url = VMURL.parseURL(null);
80         assertNull(url);
81
82         url = VMURL.parseURL(String.format("%s:%s/v2/%s/servers/%s", IP, PORT, TENANTID, VMID));
83         assertNull(url);
84
85         url = VMURL.parseURL(String.format("http:/%s:%s/v2/%s/servers/%s", IP, PORT, TENANTID, VMID));
86         assertNull(url);
87
88         url = VMURL.parseURL(String.format("http:///%s:%s/v2/%s/servers/%s", IP, PORT, TENANTID, VMID));
89         assertNull(url);
90
91         url = VMURL.parseURL(String.format("http://v2/%s/servers/%s", TENANTID, VMID));
92         assertNull(url);
93
94         url = VMURL.parseURL(String.format("%s:%s/%s/servers/%s", IP, PORT, TENANTID, VMID));
95         assertNull(url);
96
97         url = VMURL.parseURL(String.format("%s:%s/v2/servers/%s", IP, PORT, VMID));
98         assertNull(url);
99
100         url = VMURL.parseURL(String.format("%s:%s/v2/%s/%s", IP, PORT, TENANTID, VMID));
101         assertNull(url);
102
103         url = VMURL.parseURL(String.format("%s:%s/v2/%s/servers", IP, PORT, TENANTID));
104         assertNull(url);
105     }
106 }