add junit coverage for MsoCloudClientFactoryImpl
[so.git] / adapters / mso-openstack-adapters / src / test / java / org / onap / so / heatbridge / factory / MsoCloudClientFactoryImplTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2019 Nokia.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.so.heatbridge.factory;
22
23 import static org.mockito.ArgumentMatchers.any;
24 import static org.mockito.Mockito.mock;
25 import static org.mockito.Mockito.verify;
26 import org.junit.Before;
27 import org.junit.Test;
28 import org.onap.so.heatbridge.HeatBridgeException;
29 import org.onap.so.heatbridge.openstack.api.OpenstackAccess;
30 import org.onap.so.heatbridge.openstack.factory.OpenstackClientFactory;
31 import org.onap.so.utils.CryptoUtils;
32
33 public class MsoCloudClientFactoryImplTest {
34
35     private static final String URL_V2 = "http://localhost:8080/v2.0";
36     private static final String URL_V3 = "http://localhost:8080/v3";
37     private static final String URL_WITH_UNSUPPORTED_VERSION = "http://localhost:8080/v4";
38
39     private static final String MSO_ID = "testMsoId";
40     private static final String ENCRYPTED_PASSWORD = CryptoUtils.encryptCloudConfigPassword("testPassword");
41     private static final String CLOUD_REGION_ID = "testCloudRegionId";
42     private static final String TENANT_ID = "testTenantId";
43
44     private MsoCloudClientFactoryImpl testedObject;
45     private OpenstackClientFactory openstackClientFactoryMock;
46
47     @Before
48     public void setup() {
49         openstackClientFactoryMock = mock(OpenstackClientFactory.class);
50         testedObject = new MsoCloudClientFactoryImpl(openstackClientFactoryMock);
51     }
52
53     @Test
54     public void getOpenstackClientWithVersion2() throws Exception {
55         testedObject.getOpenstackClient(URL_V2, MSO_ID, ENCRYPTED_PASSWORD, CLOUD_REGION_ID, TENANT_ID);
56         verify(openstackClientFactoryMock).createOpenstackV2Client(any(OpenstackAccess.class));
57     }
58
59     @Test
60     public void getOpenstackClientWithVersion3() throws Exception {
61         testedObject.getOpenstackClient(URL_V3, MSO_ID, ENCRYPTED_PASSWORD, CLOUD_REGION_ID, TENANT_ID);
62         verify(openstackClientFactoryMock).createOpenstackV3Client(any(OpenstackAccess.class));
63     }
64
65     @Test(expected = HeatBridgeException.class)
66     public void getOpenstackClient_unsupportedVersion() throws Exception {
67         testedObject.getOpenstackClient(URL_WITH_UNSUPPORTED_VERSION, MSO_ID, ENCRYPTED_PASSWORD, CLOUD_REGION_ID,
68                 TENANT_ID);
69     }
70
71 }