2 * ============LICENSE_START=======================================================
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
13 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 * ============LICENSE_END=========================================================
24 package org.onap.appc.adapter.iaas.impl;
26 import static org.junit.Assert.assertEquals;
27 import static org.mockito.Mockito.CALLS_REAL_METHODS;
28 import static org.mockito.Mockito.times;
29 import static org.mockito.Mockito.verify;
30 import java.util.HashSet;
31 import java.util.Properties;
33 import java.util.concurrent.locks.ReentrantReadWriteLock;
34 import org.junit.Before;
35 import org.junit.BeforeClass;
36 import org.junit.Test;
37 import org.junit.runner.RunWith;
38 import org.mockito.Mockito;
39 import org.mockito.runners.MockitoJUnitRunner;
40 import org.onap.appc.configuration.ConfigurationFactory;
41 import com.att.cdp.exceptions.ZoneException;
44 * This class tests the service catalog against a known provider.
46 @RunWith(MockitoJUnitRunner.class)
47 public class TestServiceCatalog {
50 private static int EXPECTED_REGIONS = 2;
52 private ServiceCatalog catalog;
56 public static void before() {
57 Properties props = ConfigurationFactory.getConfiguration().getProperties();
59 EXPECTED_REGIONS = Integer.valueOf(props.getProperty("test.expected-regions", "2"));
63 * Setup the test environment by loading a new service catalog for each test
65 * @throws ZoneException
68 public void setup() throws ZoneException {
69 catalog = Mockito.mock(ServiceCatalog.class, CALLS_REAL_METHODS);
70 Mockito.doCallRealMethod().when(catalog).trackRequest();
71 catalog.rwLock = new ReentrantReadWriteLock();
72 Set<String> testdata = new HashSet<>();
73 testdata.add("RegionOne");
74 catalog.regions = testdata;
78 * Ensure that we set up the Region property correctly
81 public void testKnownRegions() {
82 assertEquals(EXPECTED_REGIONS, catalog.getRegions().size());
86 * Ensure that we invoke the track request method
89 public void testTrackRequest() {
90 catalog.trackRequest();
91 verify(catalog,times(1)).trackRequest();