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