summaryrefslogtreecommitdiffstats
path: root/bpmn/so-bpmn-tasks/src
diff options
context:
space:
mode:
authorSteve Smokowski <ss835w@att.com>2019-03-01 21:00:00 +0000
committerGerrit Code Review <gerrit@onap.org>2019-03-01 21:00:00 +0000
commitbe1a6ddb97550e8d03869f112edb88d67c025da1 (patch)
tree7a4ce99ad524b5a48b1a9212088016f8cc261a40 /bpmn/so-bpmn-tasks/src
parent47635df0c6d799fb59ef9cf4ad17899e17ccd34d (diff)
parent9c0c4279c0fd4e195af7a79449b356fd8e86856c (diff)
Merge "Implement a separate task to query CatalogDB for"
Diffstat (limited to 'bpmn/so-bpmn-tasks/src')
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/CloudSiteCatalogUtils.java76
-rw-r--r--bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/CloudSiteCatalogUtilsTest.java88
2 files changed, 164 insertions, 0 deletions
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/CloudSiteCatalogUtils.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/CloudSiteCatalogUtils.java
new file mode 100644
index 0000000000..bba883e727
--- /dev/null
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/CloudSiteCatalogUtils.java
@@ -0,0 +1,76 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.so.bpmn.infrastructure.flowspecific.tasks;
+
+import java.util.Optional;
+
+import org.camunda.bpm.engine.delegate.DelegateExecution;
+import org.onap.so.client.exception.ExceptionBuilder;
+import org.onap.so.db.catalog.client.CatalogDbClient;
+import org.onap.so.db.catalog.beans.CloudSite;
+import org.onap.so.logger.MsoLogger;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+@Component
+public class CloudSiteCatalogUtils {
+
+ private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, CloudSiteCatalogUtils.class);
+ @Autowired
+ private ExceptionBuilder exceptionUtil;
+
+ @Autowired
+ private CatalogDbClient catalogDbClient;
+
+
+ public void getIdentityUrlFromCloudSite(DelegateExecution execution) {
+ String cloudRegionId = (String) execution.getVariable("lcpCloudRegionId");
+
+ if (cloudRegionId != null) {
+ Optional<CloudSite> cloudSite = getCloudSite(cloudRegionId);
+ if (!cloudSite.isPresent()) {
+ msoLogger.debug("Cloud Region with cloudRegionId " + cloudRegionId + " not found in Catalog DB");
+ exceptionUtil.buildAndThrowWorkflowException(execution, 404, "Cloud Region with cloudRegionId " + cloudRegionId + " not found in Catalog DB");
+ }
+
+ if (cloudSite.get().getIdentityService() == null) {
+ msoLogger.debug("No identityService found for Cloud Region with cloudRegionId " + cloudRegionId + " in Catalog DB");
+ exceptionUtil.buildAndThrowWorkflowException(execution, 404, "No identityService found for Cloud Region with cloudRegionId " + cloudRegionId + " in Catalog DB");
+ }
+ String identityUrl = cloudSite.get().getIdentityService().getIdentityUrl();
+
+ msoLogger.debug("identityUrl from Catalog DB is: " + identityUrl);
+ execution.setVariable("identityUrl", identityUrl);
+ }
+ }
+
+ protected Optional<CloudSite> getCloudSite(String id) {
+ if (id == null) {
+ return Optional.empty();
+ }
+ CloudSite cloudSite = catalogDbClient.getCloudSite(id);
+
+ if (cloudSite != null) {
+ return Optional.of(cloudSite);
+ } else {
+ return(Optional.of(catalogDbClient.getCloudSiteByClliAndAicVersion(id,"2.5")));
+ }
+ }
+} \ No newline at end of file
diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/CloudSiteCatalogUtilsTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/CloudSiteCatalogUtilsTest.java
new file mode 100644
index 0000000000..125c97109c
--- /dev/null
+++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/CloudSiteCatalogUtilsTest.java
@@ -0,0 +1,88 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.so.bpmn.infrastructure.flowspecific.tasks;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.doReturn;
+import java.util.Optional;
+import org.junit.Test;
+import org.mockito.InjectMocks;
+import org.onap.so.bpmn.BaseTaskTest;
+
+import org.onap.so.db.catalog.beans.CloudIdentity;
+import org.onap.so.db.catalog.beans.CloudSite;
+
+public class CloudSiteCatalogUtilsTest extends BaseTaskTest {
+
+ @InjectMocks
+ private CloudSiteCatalogUtils cloudSiteCatalogUtils = new CloudSiteCatalogUtils();
+
+ @Test
+ public void testGetCloudSiteGetVersion30Test() throws Exception {
+ CloudSite cloudSite = new CloudSite();
+ String testCloudSiteId = "testCloudSiteId";
+ cloudSite.setClli(testCloudSiteId);
+ doReturn(cloudSite).when(catalogDbClient).getCloudSite(testCloudSiteId);
+ Optional<CloudSite> actualCloudSite = cloudSiteCatalogUtils.getCloudSite(testCloudSiteId);
+ assertEquals(actualCloudSite.get().getClli(), testCloudSiteId);
+ }
+
+ @Test
+ public void testGetCloudSiteGetVersion25Test() throws Exception {
+ CloudSite cloudSite = new CloudSite();
+ String testCloudSiteId = "testCloudSiteId";
+ cloudSite.setClli(testCloudSiteId);
+ doReturn(null).when(catalogDbClient).getCloudSite(testCloudSiteId);
+ doReturn(cloudSite).when(catalogDbClient).getCloudSiteByClliAndAicVersion(testCloudSiteId, "2.5");
+ Optional<CloudSite> actualCloudSite = cloudSiteCatalogUtils.getCloudSite(testCloudSiteId);
+ assertEquals(actualCloudSite.get().getClli(), testCloudSiteId);
+ }
+
+ @Test
+ public void testGetIdentityUrlFromCloudSiteSuccessTest() throws Exception {
+ CloudSite cloudSite = new CloudSite();
+ String testCloudSiteId = "testCloudSiteId";
+ String testIdentityUrl = "testIdentityUrl";
+ delegateExecution.setVariable("lcpCloudRegionId", testCloudSiteId);
+ cloudSite.setClli(testCloudSiteId);
+ CloudIdentity cloudIdentity = new CloudIdentity();
+ cloudIdentity.setIdentityUrl(testIdentityUrl);
+ cloudSite.setIdentityService(cloudIdentity);
+ doReturn(cloudSite).when(catalogDbClient).getCloudSite(testCloudSiteId);
+ cloudSiteCatalogUtils.getIdentityUrlFromCloudSite(delegateExecution);
+ String actualIdentityUrl = (String) delegateExecution.getVariable("identityUrl");
+ assertEquals(testIdentityUrl, actualIdentityUrl);
+ }
+
+ @Test
+ public void testGetIdentityUrlFromCloudSiteNoCloudIdProvidedTest() throws Exception {
+ CloudSite cloudSite = new CloudSite();
+ String testCloudSiteId = "testCloudSiteId";
+ String testIdentityUrl = "testIdentityUrl";
+ cloudSite.setClli(testCloudSiteId);
+ CloudIdentity cloudIdentity = new CloudIdentity();
+ cloudIdentity.setIdentityUrl(testIdentityUrl);
+ cloudSite.setIdentityService(cloudIdentity);
+ doReturn(cloudSite).when(catalogDbClient).getCloudSite(testCloudSiteId);
+ cloudSiteCatalogUtils.getIdentityUrlFromCloudSite(delegateExecution);
+ String actualIdentityUrl = (String) delegateExecution.getVariable("identityUrl");
+ assertEquals(null, actualIdentityUrl);
+ }
+}