From 522bb0f585c7248a99c26cc10a5bbc0954e27e82 Mon Sep 17 00:00:00 2001 From: Joanna Jeremicz Date: Wed, 5 Dec 2018 10:38:39 +0100 Subject: Use UUID to fill pnf-id in PNF PnP Issue-ID: SO-1272 Change-Id: If516b7ec38dad3fbc7409aff42275a98ef2af76b Signed-off-by: Joanna Jeremicz --- .../CreateAaiEntryWithPnfIdDelegateTest.java | 50 ------------ .../delegate/CreatePnfEntryInAaiDelegateTest.java | 56 ++++++++++++++ .../pnf/delegate/GeneratePnfUuidDelegateTest.java | 41 ++++++++++ .../pnf/delegate/PnfCheckInputsTest.java | 89 ++++++++++++++-------- 4 files changed, 155 insertions(+), 81 deletions(-) delete mode 100644 bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/CreateAaiEntryWithPnfIdDelegateTest.java create mode 100644 bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/CreatePnfEntryInAaiDelegateTest.java create mode 100644 bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/GeneratePnfUuidDelegateTest.java (limited to 'bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap') 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/CreateAaiEntryWithPnfIdDelegateTest.java deleted file mode 100644 index 465dc085fc..0000000000 --- a/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/CreateAaiEntryWithPnfIdDelegateTest.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.delegate; - -import static org.assertj.core.api.Assertions.assertThat; -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 org.camunda.bpm.engine.delegate.DelegateExecution; -import org.junit.Test; -import org.onap.aai.domain.yang.Pnf; - -public class CreateAaiEntryWithPnfIdDelegateTest { - - @Test - public void shouldSetPnfIdAndPnfName() throws Exception { - // given - CreateAaiEntryWithPnfIdDelegate delegate = new CreateAaiEntryWithPnfIdDelegate(); - AaiConnectionTestImpl aaiConnection = new AaiConnectionTestImpl(); - delegate.setAaiConnection(aaiConnection); - DelegateExecution execution = mock(DelegateExecution.class); - when(execution.getVariable(eq(CORRELATION_ID))).thenReturn("testCorrelationId"); - // when - delegate.execute(execution); - // then - Pnf createdEntry = aaiConnection.getCreated().get("testCorrelationId"); - assertThat(createdEntry.getPnfId()).isEqualTo("testCorrelationId"); - assertThat(createdEntry.getPnfName()).isEqualTo("testCorrelationId"); - assertThat(createdEntry.isInMaint()).isTrue(); - } -} \ No newline at end of file diff --git a/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/CreatePnfEntryInAaiDelegateTest.java b/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/CreatePnfEntryInAaiDelegateTest.java new file mode 100644 index 0000000000..ce6b766fa2 --- /dev/null +++ b/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/CreatePnfEntryInAaiDelegateTest.java @@ -0,0 +1,56 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * 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 + * + * 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.mockito.BDDMockito.given; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.mock; +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 CreatePnfEntryInAaiDelegateTest { + + @Test + public void shouldSetPnfIdAndPnfName() throws Exception { + // given + String pnfUuid = UUID.nameUUIDFromBytes("testUuid".getBytes()).toString(); + CreatePnfEntryInAaiDelegate delegate = new CreatePnfEntryInAaiDelegate(); + AaiConnectionTestImpl aaiConnection = new AaiConnectionTestImpl(); + delegate.setAaiConnection(aaiConnection); + DelegateExecution execution = mock(DelegateExecution.class); + 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(pnfUuid); + assertThat(createdEntry.getPnfName()).isEqualTo("testCorrelationId"); + assertThat(createdEntry.isInMaint()).isTrue(); + } +} \ No newline at end of file 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..c351706aff --- /dev/null +++ b/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/GeneratePnfUuidDelegateTest.java @@ -0,0 +1,41 @@ +/*- + * ============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 { + @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(PnfCheckInputs.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 2e8fb4be78..3e146be3c2 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 @@ -20,62 +20,89 @@ package org.onap.so.bpmn.infrastructure.pnf.delegate; +import static org.assertj.core.api.Assertions.assertThat; 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.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.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake; +import org.junit.Before; import org.junit.Test; 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 mockDelegateExecution() { - new PnfCheckInputs(DEFAULT_TIMEOUT); - DelegateExecution delegateExecution = mock(DelegateExecution.class); - when(delegateExecution.getVariable("testProcessKey")).thenReturn("testProcessKeyValue"); - return delegateExecution; + private DelegateExecution 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 + public void shouldThrowException_whenCorrelationIdNotSet() { + PnfCheckInputs testedObject = prepareExecutionForCorrelationId(null); + assertThatThrownBy(() -> testedObject.execute(delegateExecution)).isInstanceOf(BpmnError.class); + } + + @Test + public void shouldThrowException_whenTimeoutIsEmptyStringAndDefaultIsNotDefined() { + PnfCheckInputs testedObject = prepareExecutionForTimeout(null, ""); 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 shouldSetDefaultTimeout_whenTimeoutIsNotSet() { + PnfCheckInputs testedObject = prepareExecutionForTimeout(DEFAULT_TIMEOUT, null); + testedObject.execute(delegateExecution); + assertThat(delegateExecution.getVariable(TIMEOUT_FOR_NOTIFICATION)).isEqualTo(DEFAULT_TIMEOUT); } @Test - public void shouldThrowException_whenTimeoutIsNotSetAndDefaultIsNotDefined() { - // given - PnfCheckInputs testedObject = new PnfCheckInputs(null); - DelegateExecution delegateExecution = mockDelegateExecutionWithCorrelationId(); - // when, then + public void shouldThrowException_whenPnfUuidIsNotSet() { + PnfCheckInputs testedObject = prepareExecutionForUuid(null); assertThatThrownBy(() -> testedObject.execute(delegateExecution)).isInstanceOf(BpmnError.class); } @Test - public void shouldSetDefaultTimeout_whenTimeoutIsNotSet() { - // given + 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; } } \ No newline at end of file -- cgit 1.2.3-korg