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