aboutsummaryrefslogtreecommitdiffstats
path: root/bpmn/so-bpmn-infrastructure-common/src
diff options
context:
space:
mode:
authorJoanna Jeremicz <joanna.jeremicz@nokia.com>2018-12-05 10:38:39 +0100
committerJoanna Jeremicz <joanna.jeremicz@nokia.com>2018-12-19 15:08:37 +0100
commit0ac8defd70bcc6e8aeef190390e8880174bc4168 (patch)
tree943e956418fa91c078d2cdda2e68f0232186c51f /bpmn/so-bpmn-infrastructure-common/src
parentea20186bc58d26c3a51439f9b75fc13bd79ed410 (diff)
Use UUID to fill pnf-id in PNF PnP
Issue-ID: SO-1272 Change-Id: If516b7ec38dad3fbc7409aff42275a98ef2af76a Signed-off-by: Joanna Jeremicz <joanna.jeremicz@nokia.com>
Diffstat (limited to 'bpmn/so-bpmn-infrastructure-common/src')
-rw-r--r--bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/CreatePnfEntryInAaiDelegate.java (renamed from bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/CreateAaiEntryWithPnfIdDelegate.java)15
-rw-r--r--bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/ExecutionVariableNames.java3
-rw-r--r--bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/GeneratePnfUuidDelegate.java43
-rw-r--r--bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/PnfCheckInputs.java28
-rw-r--r--bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/CreatePnfEntryInAaiDelegateTest.java (renamed from bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/CreateAaiEntryWithPnfIdDelegateTest.java)16
-rw-r--r--bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/GeneratePnfUuidDelegateTest.java43
-rw-r--r--bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/PnfCheckInputsTest.java123
7 files changed, 204 insertions, 67 deletions
diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/CreateAaiEntryWithPnfIdDelegate.java b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/CreatePnfEntryInAaiDelegate.java
index 849308e0ee..2268d22bd2 100644
--- a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/CreateAaiEntryWithPnfIdDelegate.java
+++ b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/CreatePnfEntryInAaiDelegate.java
@@ -4,6 +4,8 @@
* ================================================================================
* Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
* ================================================================================
+ * Modifications Copyright 2018 Nokia
+ * ================================================================================
* 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
@@ -21,6 +23,7 @@
package org.onap.so.bpmn.infrastructure.pnf.delegate;
import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.CORRELATION_ID;
+import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.PNF_UUID;
import org.camunda.bpm.engine.delegate.DelegateExecution;
import org.camunda.bpm.engine.delegate.JavaDelegate;
@@ -32,15 +35,16 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
- * Implementation of "Create AAI entry with pnf-id = correlation_id" task in CreateAndActivatePnfResource.bpmn
+ * Implementation of "Create Pnf entry in AAI" task in CreateAndActivatePnfResource.bpmn
*
* Inputs:
* - correlationId - String
+ * - pnfUuid - String
*/
@Component
-public class CreateAaiEntryWithPnfIdDelegate implements JavaDelegate {
+public class CreatePnfEntryInAaiDelegate implements JavaDelegate {
- private static final Logger logger = LoggerFactory.getLogger(CreateAaiEntryWithPnfIdDelegate.class);
+ private static final Logger logger = LoggerFactory.getLogger(CreatePnfEntryInAaiDelegate.class);
private AaiConnection aaiConnection;
@Autowired
@@ -51,10 +55,11 @@ public class CreateAaiEntryWithPnfIdDelegate implements JavaDelegate {
@Override
public void execute(DelegateExecution execution) throws Exception {
String correlationId = (String) execution.getVariable(CORRELATION_ID);
+ String pnfUuid = (String) execution.getVariable(PNF_UUID);
Pnf pnf = new Pnf();
- pnf.setPnfId(correlationId);
+ pnf.setPnfId(pnfUuid);
pnf.setPnfName(correlationId);
aaiConnection.createEntry(correlationId, pnf);
- logger.debug("AAI entry is created for pnf correlation id: {}", correlationId);
+ logger.debug("AAI entry is created for pnf correlation id: {}, pnf uuid: {}", correlationId, pnfUuid);
}
}
diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/ExecutionVariableNames.java b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/ExecutionVariableNames.java
index b3f2f726a0..1407cb9211 100644
--- a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/ExecutionVariableNames.java
+++ b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/ExecutionVariableNames.java
@@ -4,6 +4,8 @@
* ================================================================================
* Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
* ================================================================================
+ * Modifications Copyright 2018 Nokia
+ * ================================================================================
* 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
@@ -30,4 +32,5 @@ public class ExecutionVariableNames {
public final static String AAI_CONTAINS_INFO_ABOUT_IP = "aaiContainsInfoAboutIp";
public final static String DMAAP_MESSAGE = "dmaapMessage";
public final static String TIMEOUT_FOR_NOTIFICATION = "timeoutForPnfEntryNotification";
+ public final static String PNF_UUID = "pnfUuid";
}
diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/GeneratePnfUuidDelegate.java b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/GeneratePnfUuidDelegate.java
new file mode 100644
index 0000000000..f5483e489e
--- /dev/null
+++ b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/GeneratePnfUuidDelegate.java
@@ -0,0 +1,43 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2018 Nokia.
+ * ================================================================================
+ * 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.pnf.delegate;
+
+import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.PNF_UUID;
+
+import java.util.UUID;
+import org.camunda.bpm.engine.delegate.DelegateExecution;
+import org.camunda.bpm.engine.delegate.JavaDelegate;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+
+@Component
+public class GeneratePnfUuidDelegate implements JavaDelegate {
+
+ private static final Logger logger = LoggerFactory.getLogger(GeneratePnfUuidDelegate.class);
+
+ @Override
+ public void execute(DelegateExecution delegateExecution){
+ UUID uuid = UUID.randomUUID();
+ logger.debug("Generated UUID for pnf: {}, version: {}, variant: {}", uuid, uuid.version(), uuid.variant());
+ delegateExecution.setVariable(PNF_UUID, uuid.toString());
+ }
+}
diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/PnfCheckInputs.java b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/PnfCheckInputs.java
index 94fb6a8674..e9b0bc77b2 100644
--- a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/PnfCheckInputs.java
+++ b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/PnfCheckInputs.java
@@ -4,6 +4,8 @@
* ================================================================================
* Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
* ================================================================================
+ * Modifications Copyright 2018 Nokia
+ * ================================================================================
* 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
@@ -21,9 +23,11 @@
package org.onap.so.bpmn.infrastructure.pnf.delegate;
import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.CORRELATION_ID;
+import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.PNF_UUID;
import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.TIMEOUT_FOR_NOTIFICATION;
import com.google.common.base.Strings;
+import java.util.regex.Pattern;
import org.camunda.bpm.engine.delegate.DelegateExecution;
import org.camunda.bpm.engine.delegate.JavaDelegate;
import org.onap.so.bpmn.common.scripts.ExceptionUtil;
@@ -35,6 +39,8 @@ import org.springframework.stereotype.Component;
@Component
public class PnfCheckInputs implements JavaDelegate {
+ private static final Pattern UUID_PATTERN = Pattern
+ .compile("(?i)^[0-9a-f]{8}-[0-9a-f]{4}-[1-5]{1}[0-9a-f]{3}-[89ab]{1}[0-9a-f]{3}-[0-9a-f]{12}$");
private static MsoLogger LOGGER = MsoLogger.getMsoLogger(MsoLogger.Catalog.GENERAL, PnfCheckInputs.class);
private String defaultTimeout;
@@ -46,19 +52,37 @@ public class PnfCheckInputs implements JavaDelegate {
@Override
public void execute(DelegateExecution execution) {
+ validateCorrelationId(execution);
+ validatePnfUuid(execution);
+ validateTimeout(execution);
+ }
+
+ private void validateCorrelationId(DelegateExecution execution) {
String correlationId = (String) execution.getVariable(CORRELATION_ID);
if (Strings.isNullOrEmpty(correlationId)) {
new ExceptionUtil().buildAndThrowWorkflowException(execution, 9999, "correlationId variable not defined");
}
+ }
+
+ private void validatePnfUuid(DelegateExecution execution) {
+ String pnfUuid = (String) execution.getVariable(PNF_UUID);
+ if (Strings.isNullOrEmpty(pnfUuid)) {
+ new ExceptionUtil().buildAndThrowWorkflowException(execution, 9999, "pnfUuid variable not defined");
+ }
+ if (!UUID_PATTERN.matcher(pnfUuid).matches()) {
+ new ExceptionUtil().buildAndThrowWorkflowException(execution, 9999, "pnfUuid is not a valid UUID");
+ }
+ }
+
+ private void validateTimeout(DelegateExecution execution) {
String timeout = (String) execution.getVariable(TIMEOUT_FOR_NOTIFICATION);
if (Strings.isNullOrEmpty(timeout)) {
LOGGER.debug("timeoutForPnfEntryNotification variable not found, setting default");
if (defaultTimeout == null) {
new ExceptionUtil().buildAndThrowWorkflowException(execution, 9999,
- "default timeoutForPnfEntryNotification value not defined");
+ "default timeoutForPnfEntryNotification value not defined");
}
execution.setVariable(TIMEOUT_FOR_NOTIFICATION, defaultTimeout);
}
}
-
}
diff --git a/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/CreateAaiEntryWithPnfIdDelegateTest.java b/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/CreatePnfEntryInAaiDelegateTest.java
index e328c0c7b1..0872060d55 100644
--- a/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/CreateAaiEntryWithPnfIdDelegateTest.java
+++ b/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/CreatePnfEntryInAaiDelegateTest.java
@@ -4,6 +4,8 @@
* ================================================================================
* Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
* ================================================================================
+ * Modifications Copyright 2018 Nokia
+ * ================================================================================
* 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
@@ -20,30 +22,34 @@
package org.onap.so.bpmn.infrastructure.pnf.delegate;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.BDDMockito.given;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.CORRELATION_ID;
+import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.PNF_UUID;
+import java.util.UUID;
import org.camunda.bpm.engine.delegate.DelegateExecution;
import org.junit.Test;
import org.onap.aai.domain.yang.Pnf;
-public class CreateAaiEntryWithPnfIdDelegateTest {
+public class CreatePnfEntryInAaiDelegateTest {
@Test
public void shouldSetPnfIdAndPnfName() throws Exception {
// given
- CreateAaiEntryWithPnfIdDelegate delegate = new CreateAaiEntryWithPnfIdDelegate();
+ String pnfUuid = UUID.nameUUIDFromBytes("testUuid".getBytes()).toString();
+ CreatePnfEntryInAaiDelegate delegate = new CreatePnfEntryInAaiDelegate();
AaiConnectionTestImpl aaiConnection = new AaiConnectionTestImpl();
delegate.setAaiConnection(aaiConnection);
DelegateExecution execution = mock(DelegateExecution.class);
- when(execution.getVariable(eq(CORRELATION_ID))).thenReturn("testCorrelationId");
+ given(execution.getVariable(eq(CORRELATION_ID))).willReturn("testCorrelationId");
+ given(execution.getVariable(eq(PNF_UUID))).willReturn(pnfUuid);
// when
delegate.execute(execution);
// then
Pnf createdEntry = aaiConnection.getCreated().get("testCorrelationId");
- assertThat(createdEntry.getPnfId()).isEqualTo("testCorrelationId");
+ assertThat(createdEntry.getPnfId()).isEqualTo(pnfUuid);
assertThat(createdEntry.getPnfName()).isEqualTo("testCorrelationId");
assertThat(createdEntry.isInMaint()).isNull();
}
diff --git a/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/GeneratePnfUuidDelegateTest.java b/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/GeneratePnfUuidDelegateTest.java
new file mode 100644
index 0000000000..763a4546e8
--- /dev/null
+++ b/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/GeneratePnfUuidDelegateTest.java
@@ -0,0 +1,43 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2018 Nokia.
+ * ================================================================================
+ * 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.pnf.delegate;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.PNF_UUID;
+
+import org.camunda.bpm.engine.delegate.DelegateExecution;
+import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake;
+import org.junit.Test;
+
+public class GeneratePnfUuidDelegateTest {
+ private static final String UUID_REGEX = "(?i)^[0-9a-f]{8}-[0-9a-f]{4}-[1-5]{1}[0-9a-f]{3}-[89ab]{1}[0-9a-f]{3}-[0-9a-f]{12}$";
+
+ @Test
+ public void execute_shouldSetValidUuidAsPnfUuid() {
+ // given
+ GeneratePnfUuidDelegate delegate = new GeneratePnfUuidDelegate();
+ DelegateExecution execution = new DelegateExecutionFake();
+ // when
+ delegate.execute(execution);
+ // then
+ assertThat((String) execution.getVariable(PNF_UUID)).matches(UUID_REGEX);
+ }
+} \ No newline at end of file
diff --git a/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/PnfCheckInputsTest.java b/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/PnfCheckInputsTest.java
index ab8d206a62..d670305a9a 100644
--- a/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/PnfCheckInputsTest.java
+++ b/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/PnfCheckInputsTest.java
@@ -4,6 +4,8 @@
* ================================================================================
* Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
* ================================================================================
+ * Modifications Copyright 2018 Nokia
+ * ================================================================================
* 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
@@ -20,90 +22,101 @@
package org.onap.so.bpmn.infrastructure.pnf.delegate;
-import static org.mockito.ArgumentMatchers.eq;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy;
import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.CORRELATION_ID;
+import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.PNF_UUID;
import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.TIMEOUT_FOR_NOTIFICATION;
+import java.util.UUID;
import org.camunda.bpm.engine.delegate.BpmnError;
import org.camunda.bpm.engine.delegate.DelegateExecution;
-import org.junit.Rule;
+import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake;
+import org.junit.Before;
import org.junit.Test;
-import org.junit.rules.ExpectedException;
public class PnfCheckInputsTest {
private static final String DEFAULT_TIMEOUT = "P1D";
+ private static final String VALID_UUID = UUID.nameUUIDFromBytes("testUuid".getBytes()).toString();
+ private static final String RESERVED_UUID = new UUID(0, 0).toString();
+
+ private DelegateExecution delegateExecution;
- @Rule
- public ExpectedException expectedException = ExpectedException.none();
-
- private DelegateExecution mockDelegateExecution() {
- new PnfCheckInputs(DEFAULT_TIMEOUT);
- DelegateExecution delegateExecution = mock(DelegateExecution.class);
- when(delegateExecution.getVariable("testProcessKey")).thenReturn("testProcessKeyValue");
- return delegateExecution;
+ @Before
+ public void setUp() {
+ delegateExecution = new DelegateExecutionFake();
+ delegateExecution.setVariable("testProcessKey", "testProcessKeyValue");
}
@Test
- public void shouldThrowException_whenPnfIdNotSet() {
- // given
- PnfCheckInputs testedObject = new PnfCheckInputs(DEFAULT_TIMEOUT);
- DelegateExecution delegateExecution = mockDelegateExecution();
- // when, then
- expectedException.expect(BpmnError.class);
- testedObject.execute(delegateExecution);
+ public void shouldThrowException_whenCorrelationIdNotSet() {
+ PnfCheckInputs testedObject = prepareExecutionForCorrelationId(null);
+ assertThatThrownBy(() -> testedObject.execute(delegateExecution)).isInstanceOf(BpmnError.class);
}
@Test
- public void shouldThrowException_whenPnfIdIsEmptyString() throws Exception {
- // given
- PnfCheckInputs testedObject = new PnfCheckInputs(DEFAULT_TIMEOUT);
- DelegateExecution delegateExecution = mockDelegateExecution();
- when(delegateExecution.getVariable(CORRELATION_ID)).thenReturn("");
- // when, then
- expectedException.expect(BpmnError.class);
- testedObject.execute(delegateExecution);
+ public void shouldThrowException_whenCorrelationIdIsEmptyString() {
+ PnfCheckInputs testedObject = prepareExecutionForCorrelationId("");
+ assertThatThrownBy(() -> testedObject.execute(delegateExecution)).isInstanceOf(BpmnError.class);
}
- private DelegateExecution mockDelegateExecutionWithCorrelationId() {
- new PnfCheckInputs(DEFAULT_TIMEOUT);
- DelegateExecution delegateExecution = mockDelegateExecution();
- when(delegateExecution.getVariable(CORRELATION_ID)).thenReturn("testCorrelationId");
- return delegateExecution;
+ @Test
+ public void shouldThrowException_whenTimeoutIsNotSetAndDefaultIsNotDefined() {
+ PnfCheckInputs testedObject = prepareExecutionForTimeout(null, null);
+ assertThatThrownBy(() -> testedObject.execute(delegateExecution)).isInstanceOf(BpmnError.class);
}
@Test
- public void shouldThrowException_whenTimeoutIsNotSetAndDefaultIsNotDefined() {
- // given
- PnfCheckInputs testedObject = new PnfCheckInputs(null);
- DelegateExecution delegateExecution = mockDelegateExecutionWithCorrelationId();
- // when, then
- expectedException.expect(BpmnError.class);
- testedObject.execute(delegateExecution);
+ public void shouldThrowException_whenTimeoutIsEmptyStringAndDefaultIsNotDefined() {
+ PnfCheckInputs testedObject = prepareExecutionForTimeout(null, "");
+ assertThatThrownBy(() -> testedObject.execute(delegateExecution)).isInstanceOf(BpmnError.class);
}
@Test
- public void shouldThrowException_whenTimeoutIsEmptyStringAndDefaultIsNotDefined() throws Exception {
- // given
- PnfCheckInputs testedObject = new PnfCheckInputs(null);
- DelegateExecution delegateExecution = mockDelegateExecutionWithCorrelationId();
- when(delegateExecution.getVariable(TIMEOUT_FOR_NOTIFICATION)).thenReturn("");
- // when, then
- expectedException.expect(BpmnError.class);
+ public void shouldSetDefaultTimeout_whenTimeoutIsNotSet() {
+ PnfCheckInputs testedObject = prepareExecutionForTimeout(DEFAULT_TIMEOUT, null);
testedObject.execute(delegateExecution);
+ assertThat(delegateExecution.getVariable(TIMEOUT_FOR_NOTIFICATION)).isEqualTo(DEFAULT_TIMEOUT);
}
@Test
- public void shouldSetDefaultTimeout_whenTimeoutIsNotSet() {
- // given
+ public void shouldThrowException_whenPnfUuidIsNotSet() {
+ PnfCheckInputs testedObject = prepareExecutionForUuid(null);
+ assertThatThrownBy(() -> testedObject.execute(delegateExecution)).isInstanceOf(BpmnError.class);
+ }
+
+ @Test
+ public void shouldThrowException_whenPnfUuidIsEmptyString() {
+ PnfCheckInputs testedObject = prepareExecutionForUuid("");
+ assertThatThrownBy(() -> testedObject.execute(delegateExecution)).isInstanceOf(BpmnError.class);
+ }
+
+ @Test
+ public void shouldThrowException_whenPnfUuidIsReservedUuid() {
+ PnfCheckInputs testedObject = prepareExecutionForUuid(RESERVED_UUID);
+ assertThatThrownBy(() -> testedObject.execute(delegateExecution)).isInstanceOf(BpmnError.class);
+ }
+
+ private PnfCheckInputs prepareExecutionForCorrelationId(String correlationId) {
PnfCheckInputs testedObject = new PnfCheckInputs(DEFAULT_TIMEOUT);
- DelegateExecution delegateExecution = mockDelegateExecutionWithCorrelationId();
- // when
- testedObject.execute(delegateExecution);
- // then
- verify(delegateExecution).setVariable(eq(TIMEOUT_FOR_NOTIFICATION), eq(DEFAULT_TIMEOUT));
+ delegateExecution.setVariable(CORRELATION_ID, correlationId);
+ delegateExecution.setVariable(PNF_UUID, VALID_UUID);
+ return testedObject;
+ }
+
+ private PnfCheckInputs prepareExecutionForTimeout(String defaultTimeout, String timeout) {
+ PnfCheckInputs testedObject = new PnfCheckInputs(defaultTimeout);
+ delegateExecution.setVariable(CORRELATION_ID, "testCorrelationId");
+ delegateExecution.setVariable(PNF_UUID, VALID_UUID);
+ delegateExecution.setVariable(TIMEOUT_FOR_NOTIFICATION, timeout);
+ return testedObject;
+ }
+
+ private PnfCheckInputs prepareExecutionForUuid(String uuid) {
+ PnfCheckInputs testedObject = new PnfCheckInputs(DEFAULT_TIMEOUT);
+ delegateExecution.setVariable(CORRELATION_ID, "testCorrelationId");
+ delegateExecution.setVariable(PNF_UUID, uuid);
+ return testedObject;
}
}