2 * ============LICENSE_START=======================================================
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
13 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 * ============LICENSE_END=========================================================
27 package org.openecomp.appc.adapter.iaas.impl;
29 import static org.junit.Assert.assertEquals;
30 import static org.junit.Assert.assertNull;
32 import java.util.Properties;
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;
39 public class TestVMURL {
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;
48 public static void before() {
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);
57 * Test that we can parse and interpret valid URLs
60 public void testValidURLs() {
61 VMURL url = VMURL.parseURL(URL);
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());
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());
78 * Test that we ignore and return null for invalid URLs
81 public void testInvalidURLs() {
82 VMURL url = VMURL.parseURL(null);
85 url = VMURL.parseURL(String.format("%s:%s/v2/%s/servers/%s", IP, PORT, TENANTID, VMID));
88 url = VMURL.parseURL(String.format("http:/%s:%s/v2/%s/servers/%s", IP, PORT, TENANTID, VMID));
91 url = VMURL.parseURL(String.format("http:///%s:%s/v2/%s/servers/%s", IP, PORT, TENANTID, VMID));
94 url = VMURL.parseURL(String.format("http://v2/%s/servers/%s", TENANTID, VMID));
97 url = VMURL.parseURL(String.format("%s:%s/%s/servers/%s", IP, PORT, TENANTID, VMID));
100 url = VMURL.parseURL(String.format("%s:%s/v2/servers/%s", IP, PORT, VMID));
103 url = VMURL.parseURL(String.format("%s:%s/v2/%s/%s", IP, PORT, TENANTID, VMID));
106 url = VMURL.parseURL(String.format("%s:%s/v2/%s/servers", IP, PORT, TENANTID));