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