2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
20 package org.onap.so.bpmn.infrastructure.flowspecific.tasks;
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;
29 import org.onap.so.db.catalog.beans.CloudIdentity;
30 import org.onap.so.db.catalog.beans.CloudSite;
32 public class CloudSiteCatalogUtilsTest extends BaseTaskTest {
35 private CloudSiteCatalogUtils cloudSiteCatalogUtils = new CloudSiteCatalogUtils();
38 public void testGetCloudSiteGetVersion30Test() throws Exception {
39 CloudSite cloudSite = new CloudSite();
40 String testCloudSiteId = "testCloudSiteId";
41 cloudSite.setClli(testCloudSiteId);
42 doReturn(cloudSite).when(catalogDbClient).getCloudSite(testCloudSiteId);
43 Optional<CloudSite> actualCloudSite = cloudSiteCatalogUtils.getCloudSite(testCloudSiteId);
44 assertEquals(actualCloudSite.get().getClli(), testCloudSiteId);
48 public void testGetCloudSiteGetVersion25Test() throws Exception {
49 CloudSite cloudSite = new CloudSite();
50 String testCloudSiteId = "testCloudSiteId";
51 cloudSite.setClli(testCloudSiteId);
52 doReturn(null).when(catalogDbClient).getCloudSite(testCloudSiteId);
53 doReturn(cloudSite).when(catalogDbClient).getCloudSiteByClliAndAicVersion(testCloudSiteId, "2.5");
54 Optional<CloudSite> actualCloudSite = cloudSiteCatalogUtils.getCloudSite(testCloudSiteId);
55 assertEquals(actualCloudSite.get().getClli(), testCloudSiteId);
59 public void testGetIdentityUrlFromCloudSiteSuccessTest() throws Exception {
60 CloudSite cloudSite = new CloudSite();
61 String testCloudSiteId = "testCloudSiteId";
62 String testIdentityUrl = "testIdentityUrl";
63 delegateExecution.setVariable("lcpCloudRegionId", testCloudSiteId);
64 cloudSite.setClli(testCloudSiteId);
65 CloudIdentity cloudIdentity = new CloudIdentity();
66 cloudIdentity.setIdentityUrl(testIdentityUrl);
67 cloudSite.setIdentityService(cloudIdentity);
68 doReturn(cloudSite).when(catalogDbClient).getCloudSite(testCloudSiteId);
69 cloudSiteCatalogUtils.getIdentityUrlFromCloudSite(delegateExecution);
70 String actualIdentityUrl = (String) delegateExecution.getVariable("identityUrl");
71 assertEquals(testIdentityUrl, actualIdentityUrl);
75 public void testGetIdentityUrlFromCloudSiteNoCloudIdProvidedTest() throws Exception {
76 CloudSite cloudSite = new CloudSite();
77 String testCloudSiteId = "testCloudSiteId";
78 String testIdentityUrl = "testIdentityUrl";
79 cloudSite.setClli(testCloudSiteId);
80 CloudIdentity cloudIdentity = new CloudIdentity();
81 cloudIdentity.setIdentityUrl(testIdentityUrl);
82 cloudSite.setIdentityService(cloudIdentity);
83 doReturn(cloudSite).when(catalogDbClient).getCloudSite(testCloudSiteId);
84 cloudSiteCatalogUtils.getIdentityUrlFromCloudSite(delegateExecution);
85 String actualIdentityUrl = (String) delegateExecution.getVariable("identityUrl");
86 assertEquals(null, actualIdentityUrl);