2 * ============LICENSE_START=======================================================
\r
4 * ================================================================================
\r
5 * Copyright (C) 2017-2018 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 * ============LICENSE_END=========================================================
\r
26 package org.onap.appc.adapter.iaas.impl;
\r
28 import static org.junit.Assert.assertEquals;
\r
29 import static org.junit.Assert.assertFalse;
\r
30 import static org.junit.Assert.assertNotNull;
\r
31 import static org.junit.Assert.assertTrue;
\r
32 import com.att.cdp.exceptions.ZoneException;
\r
33 import com.woorea.openstack.keystone.v3.model.Token.Service.Endpoint;
\r
34 import java.util.List;
\r
35 import java.util.Properties;
\r
36 import org.junit.Before;
\r
37 import org.junit.BeforeClass;
\r
38 import org.junit.Ignore;
\r
39 import org.junit.Test;
\r
40 import org.onap.appc.configuration.ConfigurationFactory;
\r
43 * This class tests the service catalog against a known provider.
\r
46 public class TestServiceCatalogV3 {
\r
49 private static int EXPECTED_REGIONS = 1;
\r
50 private static int EXPECTED_ENDPOINTS = 1;
\r
52 private static String PRINCIPAL;
\r
53 private static String CREDENTIAL;
\r
54 private static String DOMAIN;
\r
55 private static String TENANT_NAME;
\r
56 private static String TENANT_ID;
\r
57 private static String IDENTITY_URL;
\r
58 private static String REGION_NAME;
\r
60 private ServiceCatalogV3 catalog;
\r
62 private Properties properties;
\r
65 public static void before() {
\r
66 Properties props = ConfigurationFactory.getConfiguration().getProperties();
\r
67 IDENTITY_URL = props.getProperty("provider1.identity");
\r
68 PRINCIPAL = props.getProperty("provider1.tenant1.userid", "appc");
\r
69 CREDENTIAL = props.getProperty("provider1.tenant1.password", "appc");
\r
70 DOMAIN = props.getProperty("provider1.tenant1.domain", "Default");
\r
71 TENANT_NAME = props.getProperty("provider1.tenant1.name", "appc");
\r
72 TENANT_ID = props.getProperty("provider1.tenant1.id",
\r
73 props.getProperty("test.tenantid", "abcde12345fghijk6789lmnopq123rst"));
\r
74 REGION_NAME = props.getProperty("provider1.tenant1.region", "RegionOne");
\r
76 EXPECTED_REGIONS = Integer.valueOf(props.getProperty("test.expected-regions", "0"));
\r
77 EXPECTED_ENDPOINTS = Integer.valueOf(props.getProperty("test.expected-endpoints", "0"));
\r
81 * Setup the test environment by loading a new service catalog for each test
\r
83 * @throws ZoneException
\r
86 public void setup() throws ZoneException {
\r
87 properties = new Properties();
\r
88 catalog = new ServiceCatalogV3(IDENTITY_URL, TENANT_NAME, PRINCIPAL, CREDENTIAL, DOMAIN, properties);
\r
92 * Test that the tenant name and ID are returned correctly
\r
95 public void testKnownTenant() {
\r
96 assertEquals(TENANT_NAME, catalog.getProjectName());
\r
97 assertEquals(TENANT_ID, catalog.getProjectId());
\r
101 * Test that we find all of the expected region(s)
\r
104 public void testKnownRegions() {
\r
105 assertEquals(EXPECTED_REGIONS, catalog.getRegions().size());
\r
106 // assertEquals(REGION_NAME, catalog.getRegions().toArray()[0]);
\r
110 * Test that we can check for published services correctly
\r
113 public void testServiceTypesPublished() {
\r
114 assertTrue(catalog.isServicePublished("compute"));
\r
115 assertFalse(catalog.isServicePublished("bogus"));
\r
119 * Check that we can get the list of published services
\r
122 public void testPublishedServicesList() {
\r
123 List<String> services = catalog.getServiceTypes();
\r
125 assertTrue(services.contains(ServiceCatalog.COMPUTE_SERVICE));
\r
126 assertTrue(services.contains(ServiceCatalog.IDENTITY_SERVICE));
\r
127 assertTrue(services.contains(ServiceCatalog.IMAGE_SERVICE));
\r
128 assertTrue(services.contains(ServiceCatalog.NETWORK_SERVICE));
\r
129 assertTrue(services.contains(ServiceCatalog.VOLUME_SERVICE));
\r
133 * Test that we can get the endpoint(s) for a service
\r
136 public void testEndpointList() {
\r
137 List<Endpoint> endpoints = catalog.getEndpoints(ServiceCatalog.COMPUTE_SERVICE);
\r
139 assertNotNull(endpoints);
\r
140 assertFalse(endpoints.isEmpty());
\r
141 assertEquals(EXPECTED_ENDPOINTS, endpoints.size());
\r
143 Endpoint endpoint = endpoints.get(0);
\r
144 // assertEquals(REGION_NAME, endpoint.getRegion());
\r
148 public void testToString() {
\r
149 String testString = catalog.toString();
\r
150 assertNotNull(testString);
\r
155 public void liveConnectionTest() {
\r
156 // this test should only be used by developers when testing against a live Openstack
\r
157 // instance, otherwise it should be ignored
\r
158 properties = new Properties();
\r
159 String identity = "";
\r
160 String tenantName = "";
\r
164 catalog = new ServiceCatalogV3(IDENTITY_URL, TENANT_NAME, PRINCIPAL, CREDENTIAL, DOMAIN, properties);
\r