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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.appc.adapter.iaas.impl;
23 import static org.junit.Assert.assertNotNull;
24 import java.util.Arrays;
25 import java.util.HashMap;
26 import java.util.HashSet;
28 import java.util.Properties;
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;
44 * This class is used to test methods and functions of the provider cache
46 @RunWith(MockitoJUnitRunner.class)
47 public class TestProviderCache {
49 private ProviderCache providerCache;
52 private TenantCache tenantCache;
55 private ServiceCatalog catalog;
58 private Context context;
63 @SuppressWarnings("nls")
64 private static final String PROVIDER_NAME = "ILAB";
66 @SuppressWarnings("nls")
67 private static final String PROVIDER_TYPE = "OpenStackProvider";
69 private static String TENANT_ID;
71 protected Set<String> regions = new HashSet<>(Arrays.asList("RegionOne"));
73 private Map<String, TenantCache> tenants = new HashMap<String, TenantCache>();
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"));
83 * Use reflection to locate fields and methods so that they can be manipulated during the test
84 * to change the internal state accordingly.
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);
102 * Ensure that we set up the Tenants property correctly
105 public void testTenantsProperty() {
106 assertNotNull(providerCache.getTenants());
110 * Ensure that we set up the Tenant Id property correctly
113 public void testTenantIdProperty() {
114 assertNotNull(providerCache.getTenant(TENANT_ID));