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
27 package org.onap.appc.adapter.iaas.impl;
\r
29 import static org.junit.Assert.assertEquals;
\r
30 import static org.junit.Assert.assertFalse;
\r
31 import static org.junit.Assert.assertNotNull;
\r
32 import static org.junit.Assert.assertTrue;
\r
33 import com.att.cdp.exceptions.ZoneException;
\r
34 import com.woorea.openstack.keystone.v3.model.Token.Service.Endpoint;
\r
35 import java.util.List;
\r
36 import java.util.Properties;
\r
37 import org.junit.Before;
\r
38 import org.junit.BeforeClass;
\r
39 import org.junit.Ignore;
\r
40 import org.junit.Test;
\r
41 import org.onap.appc.configuration.ConfigurationFactory;
\r
44 * This class tests the service catalog against a known provider.
\r
47 public class TestServiceCatalogV3 {
\r
50 private static int EXPECTED_REGIONS = 1;
\r
51 private static int EXPECTED_ENDPOINTS = 1;
\r
53 private static String PRINCIPAL;
\r
54 private static String CREDENTIAL;
\r
55 private static String DOMAIN;
\r
56 private static String TENANT_NAME;
\r
57 private static String TENANT_ID;
\r
58 private static String IDENTITY_URL;
\r
59 private static String REGION_NAME;
\r
61 private ServiceCatalogV3 catalog;
\r
63 private Properties properties;
\r
66 public static void before() {
\r
67 Properties props = ConfigurationFactory.getConfiguration().getProperties();
\r
68 IDENTITY_URL = props.getProperty("provider1.identity");
\r
69 PRINCIPAL = props.getProperty("provider1.tenant1.userid", "appc");
\r
70 CREDENTIAL = props.getProperty("provider1.tenant1.password", "appc");
\r
71 DOMAIN = props.getProperty("provider1.tenant1.domain", "Default");
\r
72 TENANT_NAME = props.getProperty("provider1.tenant1.name", "appc");
\r
73 TENANT_ID = props.getProperty("provider1.tenant1.id",
\r
74 props.getProperty("test.tenantid", "abcde12345fghijk6789lmnopq123rst"));
\r
75 REGION_NAME = props.getProperty("provider1.tenant1.region", "RegionOne");
\r
77 EXPECTED_REGIONS = Integer.valueOf(props.getProperty("test.expected-regions", "0"));
\r
78 EXPECTED_ENDPOINTS = Integer.valueOf(props.getProperty("test.expected-endpoints", "0"));
\r
82 * Setup the test environment by loading a new service catalog for each test
\r
84 * @throws ZoneException
\r
87 public void setup() throws ZoneException {
\r
88 properties = new Properties();
\r
89 catalog = new ServiceCatalogV3(IDENTITY_URL, TENANT_NAME, PRINCIPAL, CREDENTIAL, DOMAIN, properties);
\r
93 * Test that the tenant name and ID are returned correctly
\r
96 public void testKnownTenant() {
\r
97 assertEquals(TENANT_NAME, catalog.getProjectName());
\r
98 assertEquals(TENANT_ID, catalog.getProjectId());
\r
102 * Test that we find all of the expected region(s)
\r
105 public void testKnownRegions() {
\r
106 assertEquals(EXPECTED_REGIONS, catalog.getRegions().size());
\r
107 // assertEquals(REGION_NAME, catalog.getRegions().toArray()[0]);
\r
111 * Test that we can check for published services correctly
\r
114 public void testServiceTypesPublished() {
\r
115 assertTrue(catalog.isServicePublished("compute"));
\r
116 assertFalse(catalog.isServicePublished("bogus"));
\r
120 * Check that we can get the list of published services
\r
123 public void testPublishedServicesList() {
\r
124 List<String> services = catalog.getServiceTypes();
\r
126 assertTrue(services.contains(ServiceCatalog.COMPUTE_SERVICE));
\r
127 assertTrue(services.contains(ServiceCatalog.IDENTITY_SERVICE));
\r
128 assertTrue(services.contains(ServiceCatalog.IMAGE_SERVICE));
\r
129 assertTrue(services.contains(ServiceCatalog.NETWORK_SERVICE));
\r
130 assertTrue(services.contains(ServiceCatalog.VOLUME_SERVICE));
\r
134 * Test that we can get the endpoint(s) for a service
\r
137 public void testEndpointList() {
\r
138 List<Endpoint> endpoints = catalog.getEndpoints(ServiceCatalog.COMPUTE_SERVICE);
\r
140 assertNotNull(endpoints);
\r
141 assertFalse(endpoints.isEmpty());
\r
142 assertEquals(EXPECTED_ENDPOINTS, endpoints.size());
\r
144 Endpoint endpoint = endpoints.get(0);
\r
145 // assertEquals(REGION_NAME, endpoint.getRegion());
\r
149 public void testToString() {
\r
150 String testString = catalog.toString();
\r
151 assertNotNull(testString);
\r
156 public void liveConnectionTest() {
\r
157 // this test should only be used by developers when testing against a live Openstack
\r
158 // instance, otherwise it should be ignored
\r
159 properties = new Properties();
\r
160 String identity = "";
\r
161 String tenantName = "";
\r
165 catalog = new ServiceCatalogV3(IDENTITY_URL, TENANT_NAME, PRINCIPAL, CREDENTIAL, DOMAIN, properties);
\r