diff options
Diffstat (limited to 'bpmn/so-bpmn-infrastructure-common')
5 files changed, 29 insertions, 115 deletions
diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/CheckAaiForCorrelationIdDelegate.java b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/CheckAaiForCorrelationIdDelegate.java index b49c4211b1..9cd28a24f4 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/CheckAaiForCorrelationIdDelegate.java +++ b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/CheckAaiForCorrelationIdDelegate.java @@ -20,17 +20,16 @@ package org.onap.so.bpmn.infrastructure.pnf.delegate; +import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.AAI_CONTAINS_INFO_ABOUT_IP; import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.AAI_CONTAINS_INFO_ABOUT_PNF; import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.CORRELATION_ID; import java.io.IOException; + import org.camunda.bpm.engine.delegate.DelegateExecution; import org.camunda.bpm.engine.delegate.JavaDelegate; import org.onap.so.bpmn.common.scripts.ExceptionUtil; import org.onap.so.bpmn.infrastructure.pnf.implementation.AaiConnection; -import org.onap.so.bpmn.infrastructure.pnf.implementation.AaiResponse; -import org.onap.so.bpmn.infrastructure.pnf.implementation.CheckAaiForCorrelationIdImplementation; -import org.onap.so.logger.MsoLogger; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -41,14 +40,11 @@ import org.springframework.stereotype.Component; * - correlationId - String * * Outputs: - * - AAI_CONTAINS_INFO_ABOUT_PNF - local Boolean - * - aaiContainsInfoAboutIp - local Boolean + * - aaiContainsInfoAboutPnf - local Boolean */ @Component public class CheckAaiForCorrelationIdDelegate implements JavaDelegate { - private static MsoLogger LOGGER = MsoLogger.getMsoLogger(MsoLogger.Catalog.GENERAL, CheckAaiForCorrelationIdDelegate.class); - private CheckAaiForCorrelationIdImplementation implementation = new CheckAaiForCorrelationIdImplementation(); private AaiConnection aaiConnection; @Autowired @@ -57,18 +53,15 @@ public class CheckAaiForCorrelationIdDelegate implements JavaDelegate { } @Override - public void execute(DelegateExecution execution) throws Exception { + public void execute(DelegateExecution execution) { String correlationId = (String) execution.getVariable(CORRELATION_ID); if (correlationId == null) { new ExceptionUtil().buildAndThrowWorkflowException(execution, 500, CORRELATION_ID + " is not set"); } - try { - AaiResponse aaiResponse = implementation.check(correlationId, aaiConnection); - - execution.setVariableLocal(AAI_CONTAINS_INFO_ABOUT_PNF, aaiResponse.getContainsInfoAboutPnf()); + boolean isEntry = aaiConnection.getEntryFor(correlationId).isPresent(); + execution.setVariableLocal(AAI_CONTAINS_INFO_ABOUT_PNF, isEntry); } catch (IOException e) { - LOGGER.error("IOException",e); new ExceptionUtil().buildAndThrowWorkflowException(execution, 9999, e.getMessage()); } } 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 164f51f579..94fb6a8674 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 @@ -23,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.TIMEOUT_FOR_NOTIFICATION; +import com.google.common.base.Strings; import org.camunda.bpm.engine.delegate.DelegateExecution; import org.camunda.bpm.engine.delegate.JavaDelegate; import org.onap.so.bpmn.common.scripts.ExceptionUtil; @@ -46,11 +47,11 @@ public class PnfCheckInputs implements JavaDelegate { @Override public void execute(DelegateExecution execution) { String correlationId = (String) execution.getVariable(CORRELATION_ID); - if (correlationId == null) { + if (Strings.isNullOrEmpty(correlationId)) { new ExceptionUtil().buildAndThrowWorkflowException(execution, 9999, "correlationId variable not defined"); } String timeout = (String) execution.getVariable(TIMEOUT_FOR_NOTIFICATION); - if (timeout == null) { + if (Strings.isNullOrEmpty(timeout)) { LOGGER.debug("timeoutForPnfEntryNotification variable not found, setting default"); if (defaultTimeout == null) { new ExceptionUtil().buildAndThrowWorkflowException(execution, 9999, diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/implementation/AaiResponse.java b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/implementation/AaiResponse.java deleted file mode 100644 index 32ecff102f..0000000000 --- a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/implementation/AaiResponse.java +++ /dev/null @@ -1,48 +0,0 @@ -/*- - * ============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.pnf.implementation; - -import java.util.Optional; -import javax.annotation.Nullable; -import javax.validation.constraints.NotNull; - -public enum AaiResponse { - NO_ENTRY(false, false), - ENTRY_NO_IP(true, false), - ENTRY_WITH_IP(true, true); - - private boolean containsInfoAboutPnf; - private boolean containsInfoAboutIp; - - AaiResponse(boolean containsInfoAboutPnf, boolean containsInfoAboutIp) { - this.containsInfoAboutPnf = containsInfoAboutPnf; - this.containsInfoAboutIp = containsInfoAboutIp; - } - - public boolean getContainsInfoAboutPnf() { - return containsInfoAboutPnf; - } - - public boolean getContainsInfoAboutIp() { - return containsInfoAboutIp; - } - -} diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/implementation/CheckAaiForCorrelationIdImplementation.java b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/implementation/CheckAaiForCorrelationIdImplementation.java deleted file mode 100644 index e5fc87db91..0000000000 --- a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/implementation/CheckAaiForCorrelationIdImplementation.java +++ /dev/null @@ -1,50 +0,0 @@ -/*- - * ============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.pnf.implementation; - -import java.io.IOException; -import java.util.Optional; -import org.onap.aai.domain.yang.Pnf; - -public class CheckAaiForCorrelationIdImplementation { - - public AaiResponse check(String correlationId, AaiConnection aaiConnection) throws IOException { - Optional<Pnf> pnf = aaiConnection.getEntryFor(correlationId); - if (!pnf.isPresent()) { - return AaiResponse.NO_ENTRY; - } - - if(extractIp(pnf.get()).isPresent()) { - return AaiResponse.ENTRY_WITH_IP; - } else { - return AaiResponse.ENTRY_NO_IP; - } - } - - private Optional<String> extractIp(Pnf pnf) { - if (pnf.getIpaddressV4Oam() != null) { - return Optional.of(pnf.getIpaddressV4Oam()); - } else { - return Optional.ofNullable(pnf.getIpaddressV6Oam()); - } - } - -} 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 2e8fb4be78..9794a59534 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 @@ -37,7 +37,6 @@ public class PnfCheckInputsTest { private static final String DEFAULT_TIMEOUT = "P1D"; private DelegateExecution mockDelegateExecution() { - new PnfCheckInputs(DEFAULT_TIMEOUT); DelegateExecution delegateExecution = mock(DelegateExecution.class); when(delegateExecution.getVariable("testProcessKey")).thenReturn("testProcessKeyValue"); return delegateExecution; @@ -52,8 +51,17 @@ public class PnfCheckInputsTest { 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 + 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; @@ -69,6 +77,16 @@ public class PnfCheckInputsTest { } @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 + assertThatThrownBy(() -> testedObject.execute(delegateExecution)).isInstanceOf(BpmnError.class); + } + + @Test public void shouldSetDefaultTimeout_whenTimeoutIsNotSet() { // given PnfCheckInputs testedObject = new PnfCheckInputs(DEFAULT_TIMEOUT); |