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