Applying license changes to 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  * ONAP : APPC
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Copyright (C) 2017 Amdocs
8  * =============================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  * 
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  * 
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  * 
21  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22  * ============LICENSE_END=========================================================
23  */
24
25
26
27 package org.openecomp.appc.adapter.iaas.impl;
28
29 import static org.junit.Assert.assertEquals;
30 import static org.junit.Assert.assertFalse;
31 import static org.junit.Assert.assertNotNull;
32 import static org.junit.Assert.assertTrue;
33
34 import java.util.List;
35 import java.util.Properties;
36
37 import org.junit.Before;
38 import org.junit.BeforeClass;
39 import org.junit.Ignore;
40 import org.junit.Test;
41 import org.openecomp.appc.adapter.iaas.impl.ServiceCatalog;
42 import org.openecomp.appc.configuration.ConfigurationFactory;
43 import com.att.cdp.exceptions.ZoneException;
44
45 import com.woorea.openstack.keystone.model.Access.Service;
46
47 /**
48  * This class tests the service catalog against a known provider.
49  */
50 @Ignore
51 public class TestServiceCatalog {
52
53     // Number
54     private static int EXPECTED_REGIONS = 1;
55     private static int EXPECTED_ENDPOINTS = 1;
56
57     private static String PRINCIPAL;
58     private static String CREDENTIAL;
59     private static String TENANT_NAME;
60     private static String TENANT_ID;
61     private static String IDENTITY_URL;
62     private static String REGION_NAME;
63
64     private ServiceCatalog catalog;
65
66     private Properties properties;
67
68     @BeforeClass
69     public static void before() {
70         Properties props = ConfigurationFactory.getConfiguration().getProperties();
71         IDENTITY_URL = props.getProperty("provider1.identity");
72         PRINCIPAL = props.getProperty("provider1.tenant1.userid", "appc");
73         CREDENTIAL = props.getProperty("provider1.tenant1.password", "appc");
74         TENANT_NAME = props.getProperty("provider1.tenant1.name", "appc");
75         TENANT_ID =
76             props.getProperty("provider1.tenant1.id",
77                 props.getProperty("test.tenantid", "abcde12345fghijk6789lmnopq123rst"));
78         REGION_NAME = props.getProperty("provider1.tenant1.region", "RegionOne");
79
80         EXPECTED_REGIONS = Integer.valueOf(props.getProperty("test.expected-regions", "0"));
81         EXPECTED_ENDPOINTS = Integer.valueOf(props.getProperty("test.expected-endpoints", "0"));
82     }
83
84     /**
85      * Setup the test environment by loading a new service catalog for each test
86      * 
87      * @throws ZoneException
88      */
89     @Before
90     public void setup() throws ZoneException {
91         properties = new Properties();
92         catalog = new ServiceCatalog(IDENTITY_URL, TENANT_NAME, PRINCIPAL, CREDENTIAL, properties);
93     }
94
95     /**
96      * Test that the tenant name and ID are returned correctly
97      */
98     @Test
99     public void testKnownTenant() {
100         assertEquals(TENANT_NAME, catalog.getTenantName());
101         assertEquals(TENANT_ID, catalog.getTenantId());
102     }
103
104     /**
105      * Test that we find all of the expected region(s)
106      */
107     @Test
108     public void testKnownRegions() {
109         assertEquals(EXPECTED_REGIONS, catalog.getRegions().size());
110         // assertEquals(REGION_NAME, catalog.getRegions().toArray()[0]);
111     }
112
113     /**
114      * Test that we can check for published services correctly
115      */
116     @Test
117     public void testServiceTypesPublished() {
118         assertTrue(catalog.isServicePublished("compute"));
119         assertFalse(catalog.isServicePublished("bogus"));
120     }
121
122     /**
123      * Check that we can get the list of published services
124      */
125     @Test
126     public void testPublishedServicesList() {
127         List<String> services = catalog.getServiceTypes();
128
129         assertTrue(services.contains(ServiceCatalog.COMPUTE_SERVICE));
130         assertTrue(services.contains(ServiceCatalog.IDENTITY_SERVICE));
131         assertTrue(services.contains(ServiceCatalog.IMAGE_SERVICE));
132         assertTrue(services.contains(ServiceCatalog.NETWORK_SERVICE));
133         assertTrue(services.contains(ServiceCatalog.VOLUME_SERVICE));
134     }
135
136     /**
137      * Test that we can get the endpoint(s) for a service
138      */
139     @Test
140     public void testEndpointList() {
141         List<Service.Endpoint> endpoints = catalog.getEndpoints(ServiceCatalog.COMPUTE_SERVICE);
142
143         assertNotNull(endpoints);
144         assertFalse(endpoints.isEmpty());
145         assertEquals(EXPECTED_ENDPOINTS, endpoints.size());
146
147         Service.Endpoint endpoint = endpoints.get(0);
148         // assertEquals(REGION_NAME, endpoint.getRegion());
149     }
150 }