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