Unit test cases for iaas impl package
[appc.git] / appc-adapters / appc-iaas-adapter / appc-iaas-adapter-bundle / src / test / java / org / onap / appc / adapter / iaas / impl / TestProviderCache.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2016-2018 Ericsson. All rights reserved.
4  * ================================================================================
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  * 
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.appc.adapter.iaas.impl;
22
23 import static org.junit.Assert.assertNotNull;
24 import java.util.Arrays;
25 import java.util.HashMap;
26 import java.util.HashSet;
27 import java.util.Map;
28 import java.util.Properties;
29 import java.util.Set;
30 import org.junit.Before;
31 import org.junit.BeforeClass;
32 import org.junit.Test;
33 import org.junit.runner.RunWith;
34 import org.mockito.Mock;
35 import org.mockito.runners.MockitoJUnitRunner;
36 import org.onap.appc.Constants;
37 import org.onap.appc.configuration.Configuration;
38 import org.onap.appc.configuration.ConfigurationFactory;
39 import org.onap.appc.pool.Pool;
40 import com.att.cdp.zones.Context;
41 import com.google.common.collect.ImmutableMap;
42
43 /**
44  * This class is used to test methods and functions of the provider cache
45  */
46 @RunWith(MockitoJUnitRunner.class)
47 public class TestProviderCache {
48
49     private ProviderCache providerCache;
50
51     @Mock
52     private TenantCache tenantCache;
53
54     @Mock
55     private ServiceCatalog catalog;
56
57     @Mock
58     private Context context;
59
60     @Mock
61     Pool<Context> pool;
62
63     @SuppressWarnings("nls")
64     private static final String PROVIDER_NAME = "ILAB";
65
66     @SuppressWarnings("nls")
67     private static final String PROVIDER_TYPE = "OpenStackProvider";
68
69     private static String TENANT_ID;
70
71     protected Set<String> regions = new HashSet<>(Arrays.asList("RegionOne"));
72
73     private Map<String, TenantCache> tenants = new HashMap<String, TenantCache>();
74
75     @BeforeClass
76     public static void before() {
77         Properties props = ConfigurationFactory.getConfiguration().getProperties();
78         TENANT_ID = props.getProperty("provider1.tenant1.id",
79                 props.getProperty("test.tenantid", "abcde12345fghijk6789lmnopq123rst"));
80     }
81
82     /**
83      * Use reflection to locate fields and methods so that they can be manipulated during the test
84      * to change the internal state accordingly.
85      * 
86      */
87     @Before
88     public void setup() {
89         Configuration props = ConfigurationFactory.getConfiguration();
90         props.setProperty(Constants.PROPERTY_RETRY_LIMIT, "10");
91         providerCache = new ProviderCache();
92         providerCache.setIdentityURL("http://192.168.1.1:5000/v2.0/");
93         providerCache.setProviderName(PROVIDER_NAME);
94         providerCache.setProviderType(PROVIDER_TYPE);
95         tenantCache = new TenantCache(providerCache);
96         tenants.put(TENANT_ID, tenantCache);
97         Map<String, Object> privateFields = ImmutableMap.<String, Object>builder().put("tenants", tenants).build();
98         CommonUtility.injectMockObjects(privateFields, providerCache);
99     }
100
101     /**
102      * Ensure that we set up the Tenants property correctly
103      */
104     @Test
105     public void testTenantsProperty() {
106         assertNotNull(providerCache.getTenants());
107     }
108
109     /**
110      * Ensure that we set up the Tenant Id property correctly
111      */
112     @Test
113     public void testTenantIdProperty() {
114         assertNotNull(providerCache.getTenant(TENANT_ID));
115     }
116
117 }