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