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.onap.appc.adapter.iaas.impl;
29 import static org.junit.Assert.assertEquals;
30 import static org.junit.Assert.assertNotNull;
31 import static org.junit.Assert.assertNull;
32 import java.util.Properties;
33 import org.junit.BeforeClass;
34 import org.junit.Test;
35 import org.onap.appc.adapter.iaas.impl.VMURL;
36 import org.onap.appc.configuration.ConfigurationFactory;
38 public class TestVMURL {
40 private static String IP;
41 private static String PORT;
42 private static String TENANTID;
43 private static String VMID;
44 private static String URL;
47 public static void before() {
48 Properties props = ConfigurationFactory.getConfiguration().getProperties();
49 IP = props.getProperty("test.ip");
50 PORT = props.getProperty("test.port");
51 TENANTID = props.getProperty("test.tenantid");
52 VMID = props.getProperty("test.vmid");
56 * Test that we can parse and interpret valid URLs
59 public void testValidURL1() {
60 URL = String.format("http://%s:%s/v2/%s/servers/%s", IP, PORT, TENANTID, VMID);
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());
68 assertEquals(url.toString(), URL);
72 public void testValidURL2() {
73 URL = String.format("http://%s/v2/%s/servers/%s", IP, TENANTID, VMID);
74 VMURL url = VMURL.parseURL(URL);
75 assertEquals("http", url.getScheme());
76 assertEquals(IP, url.getHost());
77 assertNull(url.getPort());
78 assertNull(url.getPath());
79 assertEquals(TENANTID, url.getTenantId());
80 assertEquals(VMID, url.getServerId());
81 assertEquals(url.toString(), URL);
85 public void testValidURL3() {
86 URL = "http://msb.onap.org:80/api/multicloud/v0/cloudowner_region/v2/abcde12345fghijk6789lmnopq123rst/servers/abc12345-1234-5678-890a-abcdefg12345";
87 VMURL url = VMURL.parseURL(URL);
89 assertEquals("http", url.getScheme());
90 assertEquals("msb.onap.org", url.getHost());
91 assertEquals("80", url.getPort());
92 assertEquals("/api/multicloud/v0/cloudowner_region", url.getPath());
93 assertEquals(TENANTID, url.getTenantId());
94 assertEquals(VMID, url.getServerId());
95 assertEquals(url.toString(), URL);
99 * Test that we ignore and return null for invalid URLs
102 public void testInvalidURLs() {
103 VMURL url = VMURL.parseURL(null);
106 url = VMURL.parseURL(String.format("%s:%s/v2/%s/servers/%s", IP, PORT, TENANTID, VMID));
109 url = VMURL.parseURL(String.format("http:/%s:%s/v2/%s/servers/%s", IP, PORT, TENANTID, VMID));
112 url = VMURL.parseURL(String.format("http:///%s:%s/v2/%s/servers/%s", IP, PORT, TENANTID, VMID));
115 url = VMURL.parseURL(String.format("http://v2/%s/servers/%s", TENANTID, VMID));
118 url = VMURL.parseURL(String.format("%s:%s/%s/servers/%s", IP, PORT, TENANTID, VMID));
121 url = VMURL.parseURL(String.format("%s:%s/v2/servers/%s", IP, PORT, VMID));
124 url = VMURL.parseURL(String.format("%s:%s/v2/%s/%s", IP, PORT, TENANTID, VMID));
127 url = VMURL.parseURL(String.format("%s:%s/v2/%s/servers", IP, PORT, TENANTID));