c1a41f209645ec8cd5a5aabeb8081b309ff2941b
[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.onap.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 import java.util.HashSet;
34 import java.util.List;
35 import java.util.Properties;
36 import java.util.Set;
37 import java.util.concurrent.locks.ReentrantReadWriteLock;
38 import org.junit.Before;
39 import org.junit.BeforeClass;
40 import org.junit.Ignore;
41 import org.junit.Test;
42 import org.mockito.Mockito;
43 import org.onap.appc.configuration.ConfigurationFactory;
44 import com.att.cdp.exceptions.ZoneException;
45 import com.woorea.openstack.keystone.model.Access.Service;
46
47 /**
48  * This class tests the service catalog against a known provider.
49  */
50 public class TestServiceCatalog {
51
52     // Number
53     private static int EXPECTED_REGIONS = 2;
54     private static int EXPECTED_ENDPOINTS = 1;
55
56     private static String PRINCIPAL;
57     private static String CREDENTIAL;
58     private static String TENANT_NAME;
59     private static String TENANT_ID;
60     private static String IDENTITY_URL;
61     private static String REGION_NAME;
62
63     private ServiceCatalog catalog;
64
65     private Properties properties;
66
67     @BeforeClass
68     public static void before() {
69         Properties props = ConfigurationFactory.getConfiguration().getProperties();
70         IDENTITY_URL = props.getProperty("provider1.identity");
71         PRINCIPAL = props.getProperty("provider1.tenant1.userid", "appc");
72         CREDENTIAL = props.getProperty("provider1.tenant1.password", "appc");
73         TENANT_NAME = props.getProperty("provider1.tenant1.name", "appc");
74         TENANT_ID = props.getProperty("provider1.tenant1.id",
75                 props.getProperty("test.tenantid", "abcde12345fghijk6789lmnopq123rst"));
76         REGION_NAME = props.getProperty("provider1.tenant1.region", "RegionOne");
77
78         EXPECTED_REGIONS = Integer.valueOf(props.getProperty("test.expected-regions", "2"));
79         EXPECTED_ENDPOINTS = Integer.valueOf(props.getProperty("test.expected-endpoints", "0"));
80     }
81
82     /**
83      * Setup the test environment by loading a new service catalog for each test
84      * 
85      * @throws ZoneException
86      */
87     @Before
88     public void setup() throws ZoneException {
89         properties = new Properties();
90         catalog = Mockito.mock(ServiceCatalog.class, Mockito.CALLS_REAL_METHODS);
91         catalog.rwLock = new ReentrantReadWriteLock();
92
93         Set<String> testdata = new HashSet<>();
94         testdata.add("RegionOne");
95         catalog.regions = testdata;
96     }
97
98     /**
99      * Test that we find all of the expected region(s)
100      */
101     @Test
102     public void testKnownRegions() {
103         assertEquals(EXPECTED_REGIONS, catalog.getRegions().size());
104     }
105 }