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.assertFalse;
31 import static org.junit.Assert.assertNotNull;
32 import static org.junit.Assert.assertTrue;
34 import java.util.List;
35 import java.util.Properties;
37 import org.junit.Before;
38 import org.junit.BeforeClass;
39 import org.junit.Ignore;
40 import org.junit.Test;
41 import org.openecomp.appc.adapter.iaas.impl.ServiceCatalog;
42 import org.openecomp.appc.configuration.ConfigurationFactory;
43 import com.att.cdp.exceptions.ZoneException;
45 import com.woorea.openstack.keystone.model.Access.Service;
48 * This class tests the service catalog against a known provider.
51 public class TestServiceCatalog {
54 private static int EXPECTED_REGIONS = 1;
55 private static int EXPECTED_ENDPOINTS = 1;
57 private static String PRINCIPAL;
58 private static String CREDENTIAL;
59 private static String TENANT_NAME;
60 private static String TENANT_ID;
61 private static String IDENTITY_URL;
62 private static String REGION_NAME;
64 private ServiceCatalog catalog;
66 private Properties properties;
69 public static void before() {
70 Properties props = ConfigurationFactory.getConfiguration().getProperties();
71 IDENTITY_URL = props.getProperty("provider1.identity");
72 PRINCIPAL = props.getProperty("provider1.tenant1.userid", "appc");
73 CREDENTIAL = props.getProperty("provider1.tenant1.password", "appc");
74 TENANT_NAME = props.getProperty("provider1.tenant1.name", "appc");
76 props.getProperty("provider1.tenant1.id",
77 props.getProperty("test.tenantid", "abcde12345fghijk6789lmnopq123rst"));
78 REGION_NAME = props.getProperty("provider1.tenant1.region", "RegionOne");
80 EXPECTED_REGIONS = Integer.valueOf(props.getProperty("test.expected-regions", "0"));
81 EXPECTED_ENDPOINTS = Integer.valueOf(props.getProperty("test.expected-endpoints", "0"));
85 * Setup the test environment by loading a new service catalog for each test
87 * @throws ZoneException
90 public void setup() throws ZoneException {
91 properties = new Properties();
92 catalog = new ServiceCatalog(IDENTITY_URL, TENANT_NAME, PRINCIPAL, CREDENTIAL, properties);
96 * Test that the tenant name and ID are returned correctly
99 public void testKnownTenant() {
100 assertEquals(TENANT_NAME, catalog.getTenantName());
101 assertEquals(TENANT_ID, catalog.getTenantId());
105 * Test that we find all of the expected region(s)
108 public void testKnownRegions() {
109 assertEquals(EXPECTED_REGIONS, catalog.getRegions().size());
110 // assertEquals(REGION_NAME, catalog.getRegions().toArray()[0]);
114 * Test that we can check for published services correctly
117 public void testServiceTypesPublished() {
118 assertTrue(catalog.isServicePublished("compute"));
119 assertFalse(catalog.isServicePublished("bogus"));
123 * Check that we can get the list of published services
126 public void testPublishedServicesList() {
127 List<String> services = catalog.getServiceTypes();
129 assertTrue(services.contains(ServiceCatalog.COMPUTE_SERVICE));
130 assertTrue(services.contains(ServiceCatalog.IDENTITY_SERVICE));
131 assertTrue(services.contains(ServiceCatalog.IMAGE_SERVICE));
132 assertTrue(services.contains(ServiceCatalog.NETWORK_SERVICE));
133 assertTrue(services.contains(ServiceCatalog.VOLUME_SERVICE));
137 * Test that we can get the endpoint(s) for a service
140 public void testEndpointList() {
141 List<Service.Endpoint> endpoints = catalog.getEndpoints(ServiceCatalog.COMPUTE_SERVICE);
143 assertNotNull(endpoints);
144 assertFalse(endpoints.isEmpty());
145 assertEquals(EXPECTED_ENDPOINTS, endpoints.size());
147 Service.Endpoint endpoint = endpoints.get(0);
148 // assertEquals(REGION_NAME, endpoint.getRegion());