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