summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMateusz Gołuchowski <mateusz.goluchowski@nokia.com>2020-09-21 14:45:29 +0200
committerMateusz Gołuchowski <mateusz.goluchowski@nokia.com>2020-09-21 14:45:29 +0200
commit2e66d01a3a75439ab077fe15b1830ba4bc2a1d6b (patch)
treeea8da3a87e7f607c980ad40f340cd8f5b7154bfb
parent0015e69bcb8bc7e1f72b85c5e260513620084026 (diff)
Sonar fixes
New test for createOwningEntity method. Issue-ID: SO-1841 Change-Id: I96f7793ee74d7871908f8dbbc1e4cd3a028498d5 Signed-off-by: Mateusz Goluchowski <mateusz.goluchowski@nokia.com>
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAICreateTasks.java20
-rw-r--r--bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAICreateTasksTest.java21
2 files changed, 31 insertions, 10 deletions
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAICreateTasks.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAICreateTasks.java
index 55edf0bb6c..806d4b5151 100644
--- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAICreateTasks.java
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAICreateTasks.java
@@ -85,6 +85,11 @@ public class AAICreateTasks {
private static String CONTRAIL_NETWORK_POLICY_FQDN_LIST = "contrailNetworkPolicyFqdnList";
private static String HEAT_STACK_ID = "heatStackId";
private static String NETWORK_POLICY_FQDN_PARAM = "network-policy-fqdn";
+ protected static final String EXCEPTION_NAME_EXISTS_WITH_DIFFERENT_ID =
+ "Exception in AAICreateOwningEntity. Can't create OwningEntity as name already exists in AAI associated with a different owning-entity-id (name must be unique)";
+ protected static final String EXCEPTION_NAME_AND_ID_ARE_NULL =
+ "Exception in AAICreateOwningEntity. OwningEntityId and Name are null.";
+
@Autowired
private AAIServiceInstanceResources aaiSIResources;
@Autowired
@@ -192,9 +197,8 @@ public class AAICreateTasks {
OwningEntity owningEntity = serviceInstance.getOwningEntity();
if (Strings.isNullOrEmpty(owningEntity.getOwningEntityId())
&& Strings.isNullOrEmpty(owningEntity.getOwningEntityName())) {
- String msg = "Exception in AAICreateOwningEntity. OwningEntityId and Name are null.";
- execution.setVariable("ErrorCreateOEAAI", msg);
- exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg);
+ execution.setVariable("ErrorCreateOEAAI", EXCEPTION_NAME_AND_ID_ARE_NULL);
+ exceptionUtil.buildAndThrowWorkflowException(execution, 7000, "EXCEPTION_NAME_AND_ID_ARE_NULL");
} else if (Strings.isNullOrEmpty(owningEntity.getOwningEntityId())
&& !Strings.isNullOrEmpty(owningEntity.getOwningEntityName())) {
if (aaiSIResources.existsOwningEntityName(owningEntity.getOwningEntityName())) {
@@ -219,11 +223,11 @@ public class AAICreateTasks {
exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg);
} else {
if (aaiSIResources.existsOwningEntityName(owningEntity.getOwningEntityName())) {
- String msg =
- "Exception in AAICreateOwningEntity. Can't create OwningEntity as name already exists in AAI associated with a different owning-entity-id (name must be unique)";
- logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), msg,
- "BPMN", ErrorCode.UnknownError.getValue(), msg);
- exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg);
+ logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
+ EXCEPTION_NAME_EXISTS_WITH_DIFFERENT_ID, "BPMN", ErrorCode.UnknownError.getValue(),
+ EXCEPTION_NAME_EXISTS_WITH_DIFFERENT_ID);
+ exceptionUtil.buildAndThrowWorkflowException(execution, 7000,
+ EXCEPTION_NAME_EXISTS_WITH_DIFFERENT_ID);
} else {
aaiSIResources.createOwningEntityandConnectServiceInstance(owningEntity, serviceInstance);
}
diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAICreateTasksTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAICreateTasksTest.java
index f09e792cf4..e1d3a7cbc4 100644
--- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAICreateTasksTest.java
+++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAICreateTasksTest.java
@@ -9,9 +9,9 @@
* 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.
@@ -37,6 +37,7 @@ import java.util.List;
import java.util.Optional;
import java.util.TreeSet;
import java.util.stream.Collectors;
+import com.google.common.base.Strings;
import org.camunda.bpm.engine.delegate.BpmnError;
import org.junit.Before;
import org.junit.Rule;
@@ -303,6 +304,22 @@ public class AAICreateTasksTest extends BaseTaskTest {
}
@Test
+ public void createOwningEntityShouldThrowExceptionWhenNameAndIDAreNull() {
+ boolean catchedBpmnError = false;
+ serviceInstance.getOwningEntity().setOwningEntityName(null);
+ serviceInstance.getOwningEntity().setOwningEntityId(null);
+
+ try {
+ aaiCreateTasks.createOwningEntity(execution);
+ } catch (BpmnError err) {
+ catchedBpmnError = true;
+ }
+
+ assertTrue(catchedBpmnError);
+ assertEquals(execution.getVariable("ErrorCreateOEAAI"), aaiCreateTasks.EXCEPTION_NAME_AND_ID_ARE_NULL);
+ }
+
+ @Test
public void createOwningEntityNullOwningEntityNameTest() throws Exception {
expectedException.expect(BpmnError.class);