26a4d7dbfdb830e68f4fd6b3af15ccc9770fe36a
[appc.git] / appc-adapters / appc-iaas-adapter / appc-iaas-adapter-bundle / src / test / java / org / openecomp / appc / adapter / iaas / impl / TestServiceCatalogV3.java
1 /*-\r
2  * ============LICENSE_START=======================================================\r
3  * ONAP : APPC\r
4  * ================================================================================\r
5  * Copyright (C) 2017 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
12  * \r
13  *      http://www.apache.org/licenses/LICENSE-2.0\r
14  * \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
20  * \r
21  * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
22  * ============LICENSE_END=========================================================\r
23  */\r
24 \r
25 \r
26 \r
27 package org.onap.appc.adapter.iaas.impl;\r
28 \r
29 import static org.junit.Assert.assertEquals;\r
30 import static org.junit.Assert.assertFalse;\r
31 import static org.junit.Assert.assertNotNull;\r
32 import static org.junit.Assert.assertTrue;\r
33 import com.att.cdp.exceptions.ZoneException;\r
34 import com.woorea.openstack.keystone.v3.model.Token.Service.Endpoint;\r
35 import java.util.List;\r
36 import java.util.Properties;\r
37 import org.junit.Before;\r
38 import org.junit.BeforeClass;\r
39 import org.junit.Ignore;\r
40 import org.junit.Test;\r
41 import org.onap.appc.configuration.ConfigurationFactory;\r
42 \r
43 /**\r
44  * This class tests the service catalog against a known provider.\r
45  */\r
46 @Ignore\r
47 public class TestServiceCatalogV3 {\r
48 \r
49     // Number\r
50     private static int EXPECTED_REGIONS = 1;\r
51     private static int EXPECTED_ENDPOINTS = 1;\r
52 \r
53     private static String PRINCIPAL;\r
54     private static String CREDENTIAL;\r
55     private static String DOMAIN;\r
56     private static String TENANT_NAME;\r
57     private static String TENANT_ID;\r
58     private static String IDENTITY_URL;\r
59     private static String REGION_NAME;\r
60 \r
61     private ServiceCatalogV3 catalog;\r
62 \r
63     private Properties properties;\r
64 \r
65     @BeforeClass\r
66     public static void before() {\r
67         Properties props = ConfigurationFactory.getConfiguration().getProperties();\r
68         IDENTITY_URL = props.getProperty("provider1.identity");\r
69         PRINCIPAL = props.getProperty("provider1.tenant1.userid", "appc");\r
70         CREDENTIAL = props.getProperty("provider1.tenant1.password", "appc");\r
71         DOMAIN = props.getProperty("provider1.tenant1.domain", "Default");\r
72         TENANT_NAME = props.getProperty("provider1.tenant1.name", "appc");\r
73         TENANT_ID = props.getProperty("provider1.tenant1.id",\r
74                 props.getProperty("test.tenantid", "abcde12345fghijk6789lmnopq123rst"));\r
75         REGION_NAME = props.getProperty("provider1.tenant1.region", "RegionOne");\r
76 \r
77         EXPECTED_REGIONS = Integer.valueOf(props.getProperty("test.expected-regions", "0"));\r
78         EXPECTED_ENDPOINTS = Integer.valueOf(props.getProperty("test.expected-endpoints", "0"));\r
79     }\r
80 \r
81     /**\r
82      * Setup the test environment by loading a new service catalog for each test\r
83      * \r
84      * @throws ZoneException\r
85      */\r
86     @Before\r
87     public void setup() throws ZoneException {\r
88         properties = new Properties();\r
89         catalog = new ServiceCatalogV3(IDENTITY_URL, TENANT_NAME, PRINCIPAL, CREDENTIAL, DOMAIN, properties);\r
90     }\r
91 \r
92     /**\r
93      * Test that the tenant name and ID are returned correctly\r
94      */\r
95     @Test\r
96     public void testKnownTenant() {\r
97         assertEquals(TENANT_NAME, catalog.getProjectName());\r
98         assertEquals(TENANT_ID, catalog.getProjectId());\r
99     }\r
100 \r
101     /**\r
102      * Test that we find all of the expected region(s)\r
103      */\r
104     @Test\r
105     public void testKnownRegions() {\r
106         assertEquals(EXPECTED_REGIONS, catalog.getRegions().size());\r
107         // assertEquals(REGION_NAME, catalog.getRegions().toArray()[0]);\r
108     }\r
109 \r
110     /**\r
111      * Test that we can check for published services correctly\r
112      */\r
113     @Test\r
114     public void testServiceTypesPublished() {\r
115         assertTrue(catalog.isServicePublished("compute"));\r
116         assertFalse(catalog.isServicePublished("bogus"));\r
117     }\r
118 \r
119     /**\r
120      * Check that we can get the list of published services\r
121      */\r
122     @Test\r
123     public void testPublishedServicesList() {\r
124         List<String> services = catalog.getServiceTypes();\r
125 \r
126         assertTrue(services.contains(ServiceCatalog.COMPUTE_SERVICE));\r
127         assertTrue(services.contains(ServiceCatalog.IDENTITY_SERVICE));\r
128         assertTrue(services.contains(ServiceCatalog.IMAGE_SERVICE));\r
129         assertTrue(services.contains(ServiceCatalog.NETWORK_SERVICE));\r
130         assertTrue(services.contains(ServiceCatalog.VOLUME_SERVICE));\r
131     }\r
132 \r
133     /**\r
134      * Test that we can get the endpoint(s) for a service\r
135      */\r
136     @Test\r
137     public void testEndpointList() {\r
138         List<Endpoint> endpoints = catalog.getEndpoints(ServiceCatalog.COMPUTE_SERVICE);\r
139 \r
140         assertNotNull(endpoints);\r
141         assertFalse(endpoints.isEmpty());\r
142         assertEquals(EXPECTED_ENDPOINTS, endpoints.size());\r
143 \r
144         Endpoint endpoint = endpoints.get(0);\r
145         // assertEquals(REGION_NAME, endpoint.getRegion());\r
146     }\r
147 \r
148     @Test\r
149     public void testToString() {\r
150         String testString = catalog.toString();\r
151         assertNotNull(testString);\r
152     }\r
153 \r
154     @Ignore\r
155     @Test\r
156     public void liveConnectionTest() {\r
157         // this test should only be used by developers when testing against a live Openstack\r
158         // instance, otherwise it should be ignored\r
159         properties = new Properties();\r
160         String identity = "";\r
161         String tenantName = "";\r
162         String user = "";\r
163         String pass = "";\r
164 \r
165         catalog = new ServiceCatalogV3(IDENTITY_URL, TENANT_NAME, PRINCIPAL, CREDENTIAL, DOMAIN, properties);\r
166     }\r
167 }\r