Replaced all tabs with spaces in java and pom.xml
[so.git] / bpmn / so-bpmn-tasks / src / test / java / org / onap / so / bpmn / infrastructure / flowspecific / tasks / CloudSiteCatalogUtilsTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
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 package org.onap.so.bpmn.infrastructure.flowspecific.tasks;
21
22 import static org.junit.Assert.assertEquals;
23 import static org.mockito.Mockito.doReturn;
24 import java.util.Optional;
25 import org.junit.Test;
26 import org.mockito.InjectMocks;
27 import org.onap.so.bpmn.BaseTaskTest;
28 import org.onap.so.db.catalog.beans.CloudIdentity;
29 import org.onap.so.db.catalog.beans.CloudSite;
30
31 public class CloudSiteCatalogUtilsTest extends BaseTaskTest {
32
33     @InjectMocks
34     private CloudSiteCatalogUtils cloudSiteCatalogUtils = new CloudSiteCatalogUtils();
35
36     @Test
37     public void testGetCloudSiteGetVersion30Test() throws Exception {
38         CloudSite cloudSite = new CloudSite();
39         String testCloudSiteId = "testCloudSiteId";
40         cloudSite.setClli(testCloudSiteId);
41         doReturn(cloudSite).when(catalogDbClient).getCloudSite(testCloudSiteId);
42         Optional<CloudSite> actualCloudSite = cloudSiteCatalogUtils.getCloudSite(testCloudSiteId);
43         assertEquals(actualCloudSite.get().getClli(), testCloudSiteId);
44     }
45
46     @Test
47     public void testGetCloudSiteGetVersion25Test() throws Exception {
48         CloudSite cloudSite = new CloudSite();
49         String testCloudSiteId = "testCloudSiteId";
50         cloudSite.setClli(testCloudSiteId);
51         doReturn(null).when(catalogDbClient).getCloudSite(testCloudSiteId);
52         doReturn(cloudSite).when(catalogDbClient).getCloudSiteByClliAndAicVersion(testCloudSiteId, "2.5");
53         Optional<CloudSite> actualCloudSite = cloudSiteCatalogUtils.getCloudSite(testCloudSiteId);
54         assertEquals(actualCloudSite.get().getClli(), testCloudSiteId);
55     }
56
57     @Test
58     public void testGetIdentityUrlFromCloudSiteSuccessTest() throws Exception {
59         CloudSite cloudSite = new CloudSite();
60         String testCloudSiteId = "testCloudSiteId";
61         String testIdentityUrl = "testIdentityUrl";
62         delegateExecution.setVariable("lcpCloudRegionId", testCloudSiteId);
63         cloudSite.setClli(testCloudSiteId);
64         CloudIdentity cloudIdentity = new CloudIdentity();
65         cloudIdentity.setIdentityUrl(testIdentityUrl);
66         cloudSite.setIdentityService(cloudIdentity);
67         doReturn(cloudSite).when(catalogDbClient).getCloudSite(testCloudSiteId);
68         cloudSiteCatalogUtils.getIdentityUrlFromCloudSite(delegateExecution);
69         String actualIdentityUrl = (String) delegateExecution.getVariable("identityUrl");
70         assertEquals(testIdentityUrl, actualIdentityUrl);
71     }
72
73     @Test
74     public void testGetIdentityUrlFromCloudSiteNoCloudIdProvidedTest() throws Exception {
75         CloudSite cloudSite = new CloudSite();
76         String testCloudSiteId = "testCloudSiteId";
77         String testIdentityUrl = "testIdentityUrl";
78         cloudSite.setClli(testCloudSiteId);
79         CloudIdentity cloudIdentity = new CloudIdentity();
80         cloudIdentity.setIdentityUrl(testIdentityUrl);
81         cloudSite.setIdentityService(cloudIdentity);
82         doReturn(cloudSite).when(catalogDbClient).getCloudSite(testCloudSiteId);
83         cloudSiteCatalogUtils.getIdentityUrlFromCloudSite(delegateExecution);
84         String actualIdentityUrl = (String) delegateExecution.getVariable("identityUrl");
85         assertEquals(null, actualIdentityUrl);
86     }
87 }