c9fc559dadb48e27e87d179768a9bb6973d48b29
[appc.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * APPC
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * Copyright (C) 2017 Amdocs
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  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
21  */
22
23
24
25 package org.openecomp.appc.adapter.iaas.impl;
26
27 import static org.junit.Assert.assertEquals;
28 import static org.junit.Assert.assertNull;
29
30 import java.util.Properties;
31
32 import org.junit.BeforeClass;
33 import org.junit.Test;
34 import org.openecomp.appc.adapter.iaas.impl.VMURL;
35 import org.openecomp.appc.configuration.ConfigurationFactory;
36
37 public class TestVMURL {
38
39     private static String IP;
40     private static String PORT;
41     private static String TENANTID;
42     private static String VMID;
43     private static String URL;
44
45     @BeforeClass
46     public static void before() {
47         IP = "192.168.1.2";
48         PORT = "5000";
49         TENANTID = "abcde12345fghijk6789lmnopq123rst";
50         VMID = "abc12345-1234-5678-890a-abcdefg12345";
51         URL = String.format("http://%s:%s/v2/%s/servers/%s", IP, PORT, TENANTID, VMID);
52     }
53
54     /**
55      * Test that we can parse and interpret valid URLs
56      */
57     @Test
58     public void testValidURLs() {
59         VMURL url = VMURL.parseURL(URL);
60
61         assertEquals("http", url.getScheme());
62         assertEquals(IP, url.getHost());
63         assertEquals(PORT, url.getPort());
64         assertEquals(TENANTID, url.getTenantId());
65         assertEquals(VMID, url.getServerId());
66
67         url = VMURL.parseURL(String.format("http://%s/v2/%s/servers/%s", IP, TENANTID, VMID));
68         assertEquals("http", url.getScheme());
69         assertEquals(IP, url.getHost());
70         assertNull(url.getPort());
71         assertEquals(TENANTID, url.getTenantId());
72         assertEquals(VMID, url.getServerId());
73     }
74
75     /**
76      * Test that we ignore and return null for invalid URLs
77      */
78     @Test
79     public void testInvalidURLs() {
80         VMURL url = VMURL.parseURL(null);
81         assertNull(url);
82
83         url = VMURL.parseURL(String.format("%s:%s/v2/%s/servers/%s", IP, PORT, TENANTID, VMID));
84         assertNull(url);
85
86         url = VMURL.parseURL(String.format("http:/%s:%s/v2/%s/servers/%s", IP, PORT, TENANTID, VMID));
87         assertNull(url);
88
89         url = VMURL.parseURL(String.format("http:///%s:%s/v2/%s/servers/%s", IP, PORT, TENANTID, VMID));
90         assertNull(url);
91
92         url = VMURL.parseURL(String.format("http://v2/%s/servers/%s", TENANTID, VMID));
93         assertNull(url);
94
95         url = VMURL.parseURL(String.format("%s:%s/%s/servers/%s", IP, PORT, TENANTID, VMID));
96         assertNull(url);
97
98         url = VMURL.parseURL(String.format("%s:%s/v2/servers/%s", IP, PORT, VMID));
99         assertNull(url);
100
101         url = VMURL.parseURL(String.format("%s:%s/v2/%s/%s", IP, PORT, TENANTID, VMID));
102         assertNull(url);
103
104         url = VMURL.parseURL(String.format("%s:%s/v2/%s/servers", IP, PORT, TENANTID));
105         assertNull(url);
106     }
107 }