2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * Copyright (C) 2017 Amdocs
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
20 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
25 package org.openecomp.appc.adapter.iaas.impl;
27 import static org.junit.Assert.assertEquals;
28 import static org.junit.Assert.assertFalse;
29 import static org.junit.Assert.assertNotNull;
30 import static org.junit.Assert.assertTrue;
32 import java.util.List;
33 import java.util.Properties;
35 import org.junit.Before;
36 import org.junit.BeforeClass;
37 import org.junit.Ignore;
38 import org.junit.Test;
39 import org.openecomp.appc.adapter.iaas.impl.ServiceCatalog;
40 import org.openecomp.appc.configuration.ConfigurationFactory;
41 import com.att.cdp.exceptions.ZoneException;
43 import com.woorea.openstack.keystone.model.Access.Service;
46 * This class tests the service catalog against a known provider.
49 public class TestServiceCatalog {
52 private static int EXPECTED_REGIONS = 1;
53 private static int EXPECTED_ENDPOINTS = 1;
55 private static String PRINCIPAL;
56 private static String CREDENTIAL;
57 private static String TENANT_NAME;
58 private static String TENANT_ID;
59 private static String IDENTITY_URL;
60 private static String REGION_NAME;
62 private ServiceCatalog catalog;
64 private Properties properties;
67 public static void before() {
68 Properties props = ConfigurationFactory.getConfiguration().getProperties();
69 IDENTITY_URL = props.getProperty("provider1.identity");
70 PRINCIPAL = props.getProperty("provider1.tenant1.userid", "appc");
71 CREDENTIAL = props.getProperty("provider1.tenant1.password", "appc");
72 TENANT_NAME = props.getProperty("provider1.tenant1.name", "appc");
74 props.getProperty("provider1.tenant1.id",
75 props.getProperty("test.tenantid", "abcde12345fghijk6789lmnopq123rst"));
76 REGION_NAME = props.getProperty("provider1.tenant1.region", "RegionOne");
78 EXPECTED_REGIONS = Integer.valueOf(props.getProperty("test.expected-regions", "0"));
79 EXPECTED_ENDPOINTS = Integer.valueOf(props.getProperty("test.expected-endpoints", "0"));
83 * Setup the test environment by loading a new service catalog for each test
85 * @throws ZoneException
88 public void setup() throws ZoneException {
89 properties = new Properties();
90 catalog = new ServiceCatalog(IDENTITY_URL, TENANT_NAME, PRINCIPAL, CREDENTIAL, properties);
94 * Test that the tenant name and ID are returned correctly
97 public void testKnownTenant() {
98 assertEquals(TENANT_NAME, catalog.getTenantName());
99 assertEquals(TENANT_ID, catalog.getTenantId());
103 * Test that we find all of the expected region(s)
106 public void testKnownRegions() {
107 assertEquals(EXPECTED_REGIONS, catalog.getRegions().size());
108 // assertEquals(REGION_NAME, catalog.getRegions().toArray()[0]);
112 * Test that we can check for published services correctly
115 public void testServiceTypesPublished() {
116 assertTrue(catalog.isServicePublished("compute"));
117 assertFalse(catalog.isServicePublished("bogus"));
121 * Check that we can get the list of published services
124 public void testPublishedServicesList() {
125 List<String> services = catalog.getServiceTypes();
127 assertTrue(services.contains(ServiceCatalog.COMPUTE_SERVICE));
128 assertTrue(services.contains(ServiceCatalog.IDENTITY_SERVICE));
129 assertTrue(services.contains(ServiceCatalog.IMAGE_SERVICE));
130 assertTrue(services.contains(ServiceCatalog.NETWORK_SERVICE));
131 assertTrue(services.contains(ServiceCatalog.VOLUME_SERVICE));
135 * Test that we can get the endpoint(s) for a service
138 public void testEndpointList() {
139 List<Service.Endpoint> endpoints = catalog.getEndpoints(ServiceCatalog.COMPUTE_SERVICE);
141 assertNotNull(endpoints);
142 assertFalse(endpoints.isEmpty());
143 assertEquals(EXPECTED_ENDPOINTS, endpoints.size());
145 Service.Endpoint endpoint = endpoints.get(0);
146 // assertEquals(REGION_NAME, endpoint.getRegion());