Updating licenses in all files
[appc.git] / appc-adapters / appc-iaas-adapter / appc-iaas-adapter-bundle / src / test / java / org / openecomp / appc / adapter / iaas / impl / TestServiceCatalog.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * APPC
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
11  * 
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  * 
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.
21  */
22
23
24
25 package org.openecomp.appc.adapter.iaas.impl;
26
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;
31
32 import java.util.List;
33 import java.util.Properties;
34
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;
42
43 import com.woorea.openstack.keystone.model.Access.Service;
44
45 /**
46  * This class tests the service catalog against a known provider.
47  */
48 @Ignore
49 public class TestServiceCatalog {
50
51     // Number
52     private static int EXPECTED_REGIONS = 1;
53     private static int EXPECTED_ENDPOINTS = 1;
54
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;
61
62     private ServiceCatalog catalog;
63
64     private Properties properties;
65
66     @BeforeClass
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");
73         TENANT_ID =
74             props.getProperty("provider1.tenant1.id",
75                 props.getProperty("test.tenantid", "abcde12345fghijk6789lmnopq123rst"));
76         REGION_NAME = props.getProperty("provider1.tenant1.region", "RegionOne");
77
78         EXPECTED_REGIONS = Integer.valueOf(props.getProperty("test.expected-regions", "0"));
79         EXPECTED_ENDPOINTS = Integer.valueOf(props.getProperty("test.expected-endpoints", "0"));
80     }
81
82     /**
83      * Setup the test environment by loading a new service catalog for each test
84      * 
85      * @throws ZoneException
86      */
87     @Before
88     public void setup() throws ZoneException {
89         properties = new Properties();
90         catalog = new ServiceCatalog(IDENTITY_URL, TENANT_NAME, PRINCIPAL, CREDENTIAL, properties);
91     }
92
93     /**
94      * Test that the tenant name and ID are returned correctly
95      */
96     @Test
97     public void testKnownTenant() {
98         assertEquals(TENANT_NAME, catalog.getTenantName());
99         assertEquals(TENANT_ID, catalog.getTenantId());
100     }
101
102     /**
103      * Test that we find all of the expected region(s)
104      */
105     @Test
106     public void testKnownRegions() {
107         assertEquals(EXPECTED_REGIONS, catalog.getRegions().size());
108         // assertEquals(REGION_NAME, catalog.getRegions().toArray()[0]);
109     }
110
111     /**
112      * Test that we can check for published services correctly
113      */
114     @Test
115     public void testServiceTypesPublished() {
116         assertTrue(catalog.isServicePublished("compute"));
117         assertFalse(catalog.isServicePublished("bogus"));
118     }
119
120     /**
121      * Check that we can get the list of published services
122      */
123     @Test
124     public void testPublishedServicesList() {
125         List<String> services = catalog.getServiceTypes();
126
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));
132     }
133
134     /**
135      * Test that we can get the endpoint(s) for a service
136      */
137     @Test
138     public void testEndpointList() {
139         List<Service.Endpoint> endpoints = catalog.getEndpoints(ServiceCatalog.COMPUTE_SERVICE);
140
141         assertNotNull(endpoints);
142         assertFalse(endpoints.isEmpty());
143         assertEquals(EXPECTED_ENDPOINTS, endpoints.size());
144
145         Service.Endpoint endpoint = endpoints.get(0);
146         // assertEquals(REGION_NAME, endpoint.getRegion());
147     }
148 }