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 / TestServiceCatalog.java
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 package org.onap.appc.adapter.iaas.impl;
25
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;
32 import java.util.Set;
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;
42
43 /**
44  * This class tests the service catalog against a known provider.
45  */
46 @RunWith(MockitoJUnitRunner.class)
47 public class TestServiceCatalog {
48
49     // Number
50     private static int EXPECTED_REGIONS = 2;
51
52     private ServiceCatalog catalog;
53
54
55     @BeforeClass
56     public static void before() {
57         Properties props = ConfigurationFactory.getConfiguration().getProperties();
58
59         EXPECTED_REGIONS = Integer.valueOf(props.getProperty("test.expected-regions", "2"));
60     }
61
62     /**
63      * Setup the test environment by loading a new service catalog for each test
64      * 
65      * @throws ZoneException
66      */
67     @Before
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;
75     }
76
77     /**
78      * Ensure that we set up the Region property correctly
79      */
80     @Test
81     public void testKnownRegions() {
82         assertEquals(EXPECTED_REGIONS, catalog.getRegions().size());
83     }
84     
85     /**
86      * Ensure that we invoke the track request method
87      */
88     @Test
89     public void testTrackRequest() {
90         catalog.trackRequest();
91         verify(catalog,times(1)).trackRequest();
92     }
93 }