2  * ============LICENSE_START=======================================================
 
   4  * ================================================================================
 
   5  * Copyright (C) 2017 AT&T Intellectual Property. All rights
 
   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=========================================================
 
  24 package org.openecomp.appc.adapter.iaas.impl;
 
  26 import static org.junit.Assert.assertEquals;
 
  27 import static org.junit.Assert.assertFalse;
 
  28 import static org.junit.Assert.assertNotNull;
 
  29 import static org.junit.Assert.assertTrue;
 
  31 import java.util.List;
 
  32 import java.util.Properties;
 
  34 import org.junit.Before;
 
  35 import org.junit.BeforeClass;
 
  36 import org.junit.Ignore;
 
  37 import org.junit.Test;
 
  38 import org.openecomp.appc.adapter.iaas.impl.ServiceCatalog;
 
  39 import org.openecomp.appc.configuration.ConfigurationFactory;
 
  40 import com.att.cdp.exceptions.ZoneException;
 
  42 import com.woorea.openstack.keystone.model.Access.Service;
 
  45  * This class tests the service catalog against a known provider.
 
  48 public class TestServiceCatalog {
 
  51     private static int EXPECTED_REGIONS = 1;
 
  52     private static int EXPECTED_ENDPOINTS = 1;
 
  54     private static String PRINCIPAL;
 
  55     private static String CREDENTIAL;
 
  56     private static String TENANT_NAME;
 
  57     private static String TENANT_ID;
 
  58     private static String IDENTITY_URL;
 
  59     private static String REGION_NAME;
 
  61     private ServiceCatalog catalog;
 
  63     private Properties properties;
 
  66     public static void before() {
 
  67         Properties props = ConfigurationFactory.getConfiguration().getProperties();
 
  68         IDENTITY_URL = props.getProperty("provider1.identity");
 
  69         PRINCIPAL = props.getProperty("provider1.tenant1.userid", "appc");
 
  70         CREDENTIAL = props.getProperty("provider1.tenant1.password", "appc");
 
  71         TENANT_NAME = props.getProperty("provider1.tenant1.name", "appc");
 
  73             props.getProperty("provider1.tenant1.id",
 
  74                 props.getProperty("test.tenantid", "abcde12345fghijk6789lmnopq123rst"));
 
  75         REGION_NAME = props.getProperty("provider1.tenant1.region", "RegionOne");
 
  77         EXPECTED_REGIONS = Integer.valueOf(props.getProperty("test.expected-regions", "0"));
 
  78         EXPECTED_ENDPOINTS = Integer.valueOf(props.getProperty("test.expected-endpoints", "0"));
 
  82      * Setup the test environment by loading a new service catalog for each test
 
  84      * @throws ZoneException
 
  87     public void setup() throws ZoneException {
 
  88         properties = new Properties();
 
  89         catalog = new ServiceCatalog(IDENTITY_URL, TENANT_NAME, PRINCIPAL, CREDENTIAL, properties);
 
  93      * Test that the tenant name and ID are returned correctly
 
  96     public void testKnownTenant() {
 
  97         assertEquals(TENANT_NAME, catalog.getTenantName());
 
  98         assertEquals(TENANT_ID, catalog.getTenantId());
 
 102      * Test that we find all of the expected region(s)
 
 105     public void testKnownRegions() {
 
 106         assertEquals(EXPECTED_REGIONS, catalog.getRegions().size());
 
 107         // assertEquals(REGION_NAME, catalog.getRegions().toArray()[0]);
 
 111      * Test that we can check for published services correctly
 
 114     public void testServiceTypesPublished() {
 
 115         assertTrue(catalog.isServicePublished("compute"));
 
 116         assertFalse(catalog.isServicePublished("bogus"));
 
 120      * Check that we can get the list of published services
 
 123     public void testPublishedServicesList() {
 
 124         List<String> services = catalog.getServiceTypes();
 
 126         assertTrue(services.contains(ServiceCatalog.COMPUTE_SERVICE));
 
 127         assertTrue(services.contains(ServiceCatalog.IDENTITY_SERVICE));
 
 128         assertTrue(services.contains(ServiceCatalog.IMAGE_SERVICE));
 
 129         assertTrue(services.contains(ServiceCatalog.NETWORK_SERVICE));
 
 130         assertTrue(services.contains(ServiceCatalog.VOLUME_SERVICE));
 
 134      * Test that we can get the endpoint(s) for a service
 
 137     public void testEndpointList() {
 
 138         List<Service.Endpoint> endpoints = catalog.getEndpoints(ServiceCatalog.COMPUTE_SERVICE);
 
 140         assertNotNull(endpoints);
 
 141         assertFalse(endpoints.isEmpty());
 
 142         assertEquals(EXPECTED_ENDPOINTS, endpoints.size());
 
 144         Service.Endpoint endpoint = endpoints.get(0);
 
 145         // assertEquals(REGION_NAME, endpoint.getRegion());