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
24 package org.onap.appc.adapter.iaas.impl;
\r
26 import static org.junit.Assert.assertEquals;
\r
27 import static org.junit.Assert.assertFalse;
\r
28 import static org.junit.Assert.assertNotNull;
\r
29 import static org.junit.Assert.assertTrue;
\r
30 import com.att.cdp.exceptions.ZoneException;
\r
31 import com.woorea.openstack.keystone.model.Access.Service;
\r
32 import java.util.List;
\r
33 import java.util.Properties;
\r
34 import org.junit.Before;
\r
35 import org.junit.BeforeClass;
\r
36 import org.junit.Ignore;
\r
37 import org.junit.Test;
\r
38 import org.onap.appc.configuration.ConfigurationFactory;
\r
41 * This class tests the service catalog against a known provider.
\r
44 public class TestServiceCatalogV2 {
\r
47 private static int EXPECTED_REGIONS = 1;
\r
48 private static int EXPECTED_ENDPOINTS = 1;
\r
50 private static String PRINCIPAL;
\r
51 private static String CREDENTIAL;
\r
52 private static String TENANT_NAME;
\r
53 private static String TENANT_ID;
\r
54 private static String IDENTITY_URL;
\r
55 private static String REGION_NAME;
\r
57 private ServiceCatalogV2 catalog;
\r
59 private Properties properties;
\r
62 public static void before() {
\r
63 Properties props = ConfigurationFactory.getConfiguration().getProperties();
\r
64 IDENTITY_URL = props.getProperty("provider1.identity", "appc");
\r
65 PRINCIPAL = props.getProperty("provider1.tenant1.userid", "appc");
\r
66 CREDENTIAL = props.getProperty("provider1.tenant1.password", "appc");
\r
67 TENANT_NAME = props.getProperty("provider1.tenant1.name", "appc");
\r
68 TENANT_ID = props.getProperty("provider1.tenant1.id",
\r
69 props.getProperty("test.tenantid", "abcde12345fghijk6789lmnopq123rst"));
\r
70 REGION_NAME = props.getProperty("provider1.tenant1.region", "RegionOne");
\r
72 EXPECTED_REGIONS = Integer.valueOf(props.getProperty("test.expected-regions", "0"));
\r
73 EXPECTED_ENDPOINTS = Integer.valueOf(props.getProperty("test.expected-endpoints", "0"));
\r
77 * Setup the test environment by loading a new service catalog for each test
\r
79 * @throws ZoneException
\r
82 public void setup() throws ZoneException {
\r
83 properties = new Properties();
\r
84 catalog = new ServiceCatalogV2(IDENTITY_URL, TENANT_NAME, PRINCIPAL, CREDENTIAL, properties);
\r
89 * Test that the tenant name and ID are returned correctly
\r
92 public void testKnownTenant() {
\r
93 assertEquals(TENANT_NAME, catalog.getProjectName());
\r
94 assertEquals(TENANT_ID, catalog.getProjectId());
\r
98 * Test that we find all of the expected region(s)
\r
101 public void testKnownRegions() {
\r
102 assertEquals(EXPECTED_REGIONS, catalog.getRegions().size());
\r
103 // assertEquals(REGION_NAME, catalog.getRegions().toArray()[0]);
\r
107 * Test that we can check for published services correctly
\r
110 public void testServiceTypesPublished() {
\r
111 assertTrue(catalog.isServicePublished("compute"));
\r
112 assertFalse(catalog.isServicePublished("bogus"));
\r
116 * Check that we can get the list of published services
\r
119 public void testPublishedServicesList() {
\r
120 // List<String> services = catalog.getServiceTypes();
\r
122 // assertTrue(services.contains(ServiceCatalog.COMPUTE_SERVICE));
\r
123 // assertTrue(services.contains(ServiceCatalog.IDENTITY_SERVICE));
\r
124 // assertTrue(services.contains(ServiceCatalog.IMAGE_SERVICE));
\r
125 // assertTrue(services.contains(ServiceCatalog.NETWORK_SERVICE));
\r
126 // assertTrue(services.contains(ServiceCatalog.VOLUME_SERVICE));
\r
130 * Test that we can get the endpoint(s) for a service
\r
133 public void testEndpointList() {
\r
134 List<Service.Endpoint> endpoints = catalog.getEndpoints(ServiceCatalog.COMPUTE_SERVICE);
\r
136 assertNotNull(endpoints);
\r
137 assertFalse(endpoints.isEmpty());
\r
138 assertEquals(EXPECTED_ENDPOINTS, endpoints.size());
\r
140 Service.Endpoint endpoint = endpoints.get(0);
\r
141 // assertEquals(REGION_NAME, endpoint.getRegion());
\r
145 public void testToString() {
\r
146 String testString = catalog.toString();
\r
147 assertNotNull(testString);
\r
152 public void liveConnectionTest() {
\r
153 // this test should only be used by developers when testing against a live Openstack
\r
154 // instance, otherwise it should be ignored
\r
155 properties = new Properties();
\r
156 String identity = "http://192.168.0.1:5000/v2.0";
\r
157 String tenantName = "Tenant";
\r
158 String user = "user";
\r
159 String pass = "pass";
\r
161 ServiceCatalogV2 catalog = new ServiceCatalogV2(identity, tenantName, user, pass, properties);
\r
165 } catch (ZoneException e) {
\r
166 // TODO Auto-generated catch block
\r
167 e.printStackTrace();
\r
170 String out = catalog.toString();
\r
171 System.out.println(out);
\r