From 59e4171c755943b1ac7e16d80980e8736045e5aa Mon Sep 17 00:00:00 2001 From: biniek Date: Thu, 17 May 2018 12:11:50 +0200 Subject: Added checking input variables in pnf-pnp Change-Id: I1a4f4b9704385a17995e76d4b87484c2f588b889 Issue-ID: SO-506 Signed-off-by: biniek --- .../pnf/delegate/ExecutionVariableNames.java | 1 + .../pnf/delegate/PnfCheckInputs.java | 57 ++++++ .../src/main/resources/pnf.properties | 1 + .../process/CreateAndActivatePnfResource.bpmn | 219 +++++++++++---------- .../src/main/webapp/WEB-INF/applicationContext.xml | 8 + .../pnf/delegate/PnfCheckInputsTest.java | 84 ++++++++ .../resources/applicationContext_forPnfTesting.xml | 5 + 7 files changed, 271 insertions(+), 104 deletions(-) create mode 100644 bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/PnfCheckInputs.java create mode 100644 bpmn/MSOInfrastructureBPMN/src/main/resources/pnf.properties create mode 100644 bpmn/MSOInfrastructureBPMN/src/test/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/PnfCheckInputsTest.java (limited to 'bpmn/MSOInfrastructureBPMN') diff --git a/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/ExecutionVariableNames.java b/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/ExecutionVariableNames.java index 94d221a054..361313e932 100644 --- a/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/ExecutionVariableNames.java +++ b/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/ExecutionVariableNames.java @@ -29,4 +29,5 @@ public class ExecutionVariableNames { public final static String AAI_CONTAINS_INFO_ABOUT_PNF = "aaiContainsInfoAboutPnf"; 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"; } diff --git a/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/PnfCheckInputs.java b/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/PnfCheckInputs.java new file mode 100644 index 0000000000..268113d28f --- /dev/null +++ b/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/PnfCheckInputs.java @@ -0,0 +1,57 @@ +/*- + * ============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.openecomp.mso.bpmn.infrastructure.pnf.delegate; + +import static org.openecomp.mso.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.CORRELATION_ID; +import static org.openecomp.mso.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.TIMEOUT_FOR_NOTIFICATION; + +import org.camunda.bpm.engine.delegate.DelegateExecution; +import org.camunda.bpm.engine.delegate.JavaDelegate; +import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil; +import org.openecomp.mso.logger.MsoLogger; + +public class PnfCheckInputs implements JavaDelegate { + + private static MsoLogger LOGGER = MsoLogger.getMsoLogger(MsoLogger.Catalog.GENERAL); + + private String defaultTimeout; + + @Override + public void execute(DelegateExecution execution) throws Exception { + String correlationId = (String) execution.getVariable(CORRELATION_ID); + if (correlationId == null) { + new ExceptionUtil().buildAndThrowWorkflowException(execution, 9999, "correlationId variable not defined"); + } + String timeout = (String) execution.getVariable(TIMEOUT_FOR_NOTIFICATION); + if (timeout == null) { + LOGGER.debug("timeoutForPnfEntryNotification variable not found, setting default"); + if (defaultTimeout == null) { + new ExceptionUtil().buildAndThrowWorkflowException(execution, 9999, + "default timeoutForPnfEntryNotification value not defined"); + } + execution.setVariable(TIMEOUT_FOR_NOTIFICATION, defaultTimeout); + } + } + + public void setDefaultTimeout(String defaultTimeout) { + this.defaultTimeout = defaultTimeout; + } +} diff --git a/bpmn/MSOInfrastructureBPMN/src/main/resources/pnf.properties b/bpmn/MSOInfrastructureBPMN/src/main/resources/pnf.properties new file mode 100644 index 0000000000..81637fa66e --- /dev/null +++ b/bpmn/MSOInfrastructureBPMN/src/main/resources/pnf.properties @@ -0,0 +1 @@ +defaultTimeout=P14D \ No newline at end of file diff --git a/bpmn/MSOInfrastructureBPMN/src/main/resources/process/CreateAndActivatePnfResource.bpmn b/bpmn/MSOInfrastructureBPMN/src/main/resources/process/CreateAndActivatePnfResource.bpmn index c118105e35..8f2bf67b71 100644 --- a/bpmn/MSOInfrastructureBPMN/src/main/resources/process/CreateAndActivatePnfResource.bpmn +++ b/bpmn/MSOInfrastructureBPMN/src/main/resources/process/CreateAndActivatePnfResource.bpmn @@ -14,51 +14,42 @@ + + #{!aaiContainsInfoAboutPnf} + + + + + + #{!aaiContainsInfoAboutIp} - - - #{!aaiContainsInfoAboutPnf} - #{aaiContainsInfoAboutPnf} - - - #{aaiContainsInfoAboutIp} - - SequenceFlow_1h6yz62 + + SequenceFlow_0p09qgm - - SequenceFlow_1l1t6ak - SequenceFlow_1h6yz62 - SequenceFlow_1ls8pua - SequenceFlow_1miyzfe - - - SequenceFlow_0j5ksz1 - SequenceFlow_1j4r3zt - + + SequenceFlow_1h6yz62 + SequenceFlow_0j5ksz1 - - SequenceFlow_1qr6cmf - SequenceFlow_1ls8pua - SequenceFlow_17s9025 - - - SequenceFlow_0p09qgm - + + + SequenceFlow_0967g8p + SequenceFlow_1j4r3zt + SequenceFlow_1j4r3zt SequenceFlow_1l1t6ak @@ -68,6 +59,16 @@ SequenceFlow_0v5ffpe SequenceFlow_1qr6cmf + + SequenceFlow_1l1t6ak + SequenceFlow_1h6yz62 + SequenceFlow_1ls8pua + + + SequenceFlow_1qr6cmf + SequenceFlow_1ls8pua + SequenceFlow_17s9025 + SequenceFlow_17s9025 SequenceFlow_1o8od8e @@ -86,31 +87,35 @@ SequenceFlow_1kc34bc SequenceFlow_1miyzfe - + + SequenceFlow_0j5ksz1 + SequenceFlow_0967g8p + + - + - + - + - + - + @@ -120,93 +125,89 @@ - + - + - + - + - - + + - + - - - + + + - + - - + + - + - + - + - - - - + + - + - - + + - + - - - - + + - + - - + + - + - - + + - + - - + + - + @@ -225,89 +226,99 @@ - + - + - + - - + + - - + + - + - - + + - + - + - + - - - + + + - + - + - + - + - - + + - + - - + + - + - + - + - + - - + + - + - + + + + + + + + + + + diff --git a/bpmn/MSOInfrastructureBPMN/src/main/webapp/WEB-INF/applicationContext.xml b/bpmn/MSOInfrastructureBPMN/src/main/webapp/WEB-INF/applicationContext.xml index 13ab4f8f17..1273b30f0a 100644 --- a/bpmn/MSOInfrastructureBPMN/src/main/webapp/WEB-INF/applicationContext.xml +++ b/bpmn/MSOInfrastructureBPMN/src/main/webapp/WEB-INF/applicationContext.xml @@ -38,4 +38,12 @@ + + + + + + + + diff --git a/bpmn/MSOInfrastructureBPMN/src/test/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/PnfCheckInputsTest.java b/bpmn/MSOInfrastructureBPMN/src/test/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/PnfCheckInputsTest.java new file mode 100644 index 0000000000..1799e7fcbc --- /dev/null +++ b/bpmn/MSOInfrastructureBPMN/src/test/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/PnfCheckInputsTest.java @@ -0,0 +1,84 @@ +/*- + * ============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.openecomp.mso.bpmn.infrastructure.pnf.delegate; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; +import static org.openecomp.mso.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.CORRELATION_ID; +import static org.openecomp.mso.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.TIMEOUT_FOR_NOTIFICATION; + +import org.camunda.bpm.engine.delegate.BpmnError; +import org.camunda.bpm.engine.delegate.DelegateExecution; +import org.junit.Before; +import org.junit.Test; + +public class PnfCheckInputsTest { + + private PnfCheckInputs delegate; + + @Before + public void setUp() throws Exception { + delegate = new PnfCheckInputs(); + } + + private DelegateExecution mockDelegateExecution() { + DelegateExecution delegateExecution = mock(DelegateExecution.class); + when(delegateExecution.getVariable("testProcessKey")).thenReturn("testProcessKeyValue"); + return delegateExecution; + } + + @Test + public void shouldThrowException_whenPnfIdNotSet() throws Exception { + // given + DelegateExecution delegateExecution = mockDelegateExecution(); + // when, then + assertThatThrownBy(() -> delegate.execute(delegateExecution)).isInstanceOf(BpmnError.class); + } + + private DelegateExecution mockDelegateExecutionWithCorrelationId() { + DelegateExecution delegateExecution = mockDelegateExecution(); + when(delegateExecution.getVariable(CORRELATION_ID)).thenReturn("testCorrelationId"); + return delegateExecution; + } + + @Test + public void shouldThrowException_whenTimeoutIsNotSetAndDefaultIsNotDefined() throws Exception { + // given + DelegateExecution delegateExecution = mockDelegateExecutionWithCorrelationId(); + // when, then + assertThatThrownBy(() -> delegate.execute(delegateExecution)).isInstanceOf(BpmnError.class); + } + + @Test + public void shouldSetDefaultTimeout_whenTimeoutIsNotSet() throws Exception { + // given + String defaultTimeout = "T1D"; + delegate.setDefaultTimeout(defaultTimeout); + DelegateExecution delegateExecution = mockDelegateExecutionWithCorrelationId(); + // when + delegate.execute(delegateExecution); + // then + verify(delegateExecution).setVariable(eq(TIMEOUT_FOR_NOTIFICATION), eq(defaultTimeout)); + } +} \ No newline at end of file diff --git a/bpmn/MSOInfrastructureBPMN/src/test/resources/applicationContext_forPnfTesting.xml b/bpmn/MSOInfrastructureBPMN/src/test/resources/applicationContext_forPnfTesting.xml index 6dc3bbf880..980a0b1186 100644 --- a/bpmn/MSOInfrastructureBPMN/src/test/resources/applicationContext_forPnfTesting.xml +++ b/bpmn/MSOInfrastructureBPMN/src/test/resources/applicationContext_forPnfTesting.xml @@ -62,4 +62,9 @@ + + + + + -- cgit 1.2.3-korg