2 * ============LICENSE_START=======================================================
\r
4 * ================================================================================
\r
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
\r
6 * ================================================================================
\r
7 * Copyright (C) 2017 Amdocs
\r
8 * =============================================================================
\r
9 * Licensed under the Apache License, Version 2.0 (the "License");
\r
10 * you may not use this file except in compliance with the License.
\r
11 * You may obtain a copy of the License at
\r
13 * http://www.apache.org/licenses/LICENSE-2.0
\r
15 * Unless required by applicable law or agreed to in writing, software
\r
16 * distributed under the License is distributed on an "AS IS" BASIS,
\r
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
18 * See the License for the specific language governing permissions and
\r
19 * limitations under the License.
\r
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
\r
22 * ============LICENSE_END=========================================================
\r
25 package org.onap.appc.adapter.iaas.impl;
\r
27 import static org.junit.Assert.assertEquals;
\r
28 import static org.junit.Assert.assertFalse;
\r
29 import static org.junit.Assert.assertNotNull;
\r
30 import static org.junit.Assert.assertTrue;
\r
31 import com.att.cdp.exceptions.ZoneException;
\r
32 import com.woorea.openstack.keystone.model.Access.Service;
\r
33 import java.util.List;
\r
34 import java.util.Properties;
\r
35 import org.junit.Before;
\r
36 import org.junit.BeforeClass;
\r
37 import org.junit.Ignore;
\r
38 import org.junit.Test;
\r
39 import org.onap.appc.configuration.ConfigurationFactory;
\r
42 * This class tests the service catalog against a known provider.
\r
45 public class TestServiceCatalogV2 {
\r
48 private static int EXPECTED_REGIONS = 1;
\r
49 private static int EXPECTED_ENDPOINTS = 1;
\r
51 private static String PRINCIPAL;
\r
52 private static String CREDENTIAL;
\r
53 private static String TENANT_NAME;
\r
54 private static String TENANT_ID;
\r
55 private static String IDENTITY_URL;
\r
56 private static String REGION_NAME;
\r
58 private ServiceCatalogV2 catalog;
\r
60 private Properties properties;
\r
63 public static void before() {
\r
64 Properties props = ConfigurationFactory.getConfiguration().getProperties();
\r
65 IDENTITY_URL = props.getProperty("provider1.identity", "appc");
\r
66 PRINCIPAL = props.getProperty("provider1.tenant1.userid", "appc");
\r
67 CREDENTIAL = props.getProperty("provider1.tenant1.password", "appc");
\r
68 TENANT_NAME = props.getProperty("provider1.tenant1.name", "appc");
\r
69 TENANT_ID = props.getProperty("provider1.tenant1.id",
\r
70 props.getProperty("test.tenantid", "abcde12345fghijk6789lmnopq123rst"));
\r
71 REGION_NAME = props.getProperty("provider1.tenant1.region", "RegionOne");
\r
73 EXPECTED_REGIONS = Integer.valueOf(props.getProperty("test.expected-regions", "0"));
\r
74 EXPECTED_ENDPOINTS = Integer.valueOf(props.getProperty("test.expected-endpoints", "0"));
\r
78 * Setup the test environment by loading a new service catalog for each test
\r
80 * @throws ZoneException
\r
83 public void setup() throws ZoneException {
\r
84 properties = new Properties();
\r
85 catalog = new ServiceCatalogV2(IDENTITY_URL, TENANT_NAME, PRINCIPAL, CREDENTIAL, properties);
\r
90 * Test that the tenant name and ID are returned correctly
\r
93 public void testKnownTenant() {
\r
94 assertEquals(TENANT_NAME, catalog.getProjectName());
\r
95 assertEquals(TENANT_ID, catalog.getProjectId());
\r
99 * Test that we find all of the expected region(s)
\r
102 public void testKnownRegions() {
\r
103 assertEquals(EXPECTED_REGIONS, catalog.getRegions().size());
\r
104 // assertEquals(REGION_NAME, catalog.getRegions().toArray()[0]);
\r
108 * Test that we can check for published services correctly
\r
111 public void testServiceTypesPublished() {
\r
112 assertTrue(catalog.isServicePublished("compute"));
\r
113 assertFalse(catalog.isServicePublished("bogus"));
\r
117 * Check that we can get the list of published services
\r
120 public void testPublishedServicesList() {
\r
121 // List<String> services = catalog.getServiceTypes();
\r
123 // assertTrue(services.contains(ServiceCatalog.COMPUTE_SERVICE));
\r
124 // assertTrue(services.contains(ServiceCatalog.IDENTITY_SERVICE));
\r
125 // assertTrue(services.contains(ServiceCatalog.IMAGE_SERVICE));
\r
126 // assertTrue(services.contains(ServiceCatalog.NETWORK_SERVICE));
\r
127 // assertTrue(services.contains(ServiceCatalog.VOLUME_SERVICE));
\r
131 * Test that we can get the endpoint(s) for a service
\r
134 public void testEndpointList() {
\r
135 List<Service.Endpoint> endpoints = catalog.getEndpoints(ServiceCatalog.COMPUTE_SERVICE);
\r
137 assertNotNull(endpoints);
\r
138 assertFalse(endpoints.isEmpty());
\r
139 assertEquals(EXPECTED_ENDPOINTS, endpoints.size());
\r
141 Service.Endpoint endpoint = endpoints.get(0);
\r
142 // assertEquals(REGION_NAME, endpoint.getRegion());
\r
146 public void testToString() {
\r
147 String testString = catalog.toString();
\r
148 assertNotNull(testString);
\r
153 public void liveConnectionTest() {
\r
154 // this test should only be used by developers when testing against a live Openstack
\r
155 // instance, otherwise it should be ignored
\r
156 properties = new Properties();
\r
157 String identity = "http://192.168.0.1:5000/v2.0";
\r
158 String tenantName = "Tenant";
\r
159 String user = "user";
\r
160 String pass = "pass";
\r
162 ServiceCatalogV2 catalog = new ServiceCatalogV2(identity, tenantName, user, pass, properties);
\r
166 } catch (ZoneException e) {
\r
167 // TODO Auto-generated catch block
\r
168 e.printStackTrace();
\r
171 String out = catalog.toString();
\r
172 System.out.println(out);
\r