diff options
author | biniek <lukasz.biniek@nokia.com> | 2018-09-04 16:27:25 +0200 |
---|---|---|
committer | Lukasz Biniek <lukasz.biniek@nokia.com> | 2018-09-05 14:54:30 +0000 |
commit | 68dbf00111b5a27329b1136fd7150d3bf39116c2 (patch) | |
tree | e8cb2b76d9188b92cf5ec6b9dfc780e8ffa9b047 /bpmn/mso-infrastructure-bpmn/src/test/java | |
parent | 43e02724c56abd460e41a1715ff5057b036e6270 (diff) |
PNF PnP now always waits
Issue-ID: SO-797
Change-Id: I717b987e78680157c4a2c0bf8d497855d1890077
Signed-off-by: biniek <lukasz.biniek@nokia.com>
Diffstat (limited to 'bpmn/mso-infrastructure-bpmn/src/test/java')
10 files changed, 27 insertions, 716 deletions
diff --git a/bpmn/mso-infrastructure-bpmn/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/AaiConnectionTestImpl.java b/bpmn/mso-infrastructure-bpmn/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/AaiConnectionTestImpl.java index 7cb649d66e..201e791a24 100644 --- a/bpmn/mso-infrastructure-bpmn/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/AaiConnectionTestImpl.java +++ b/bpmn/mso-infrastructure-bpmn/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/AaiConnectionTestImpl.java @@ -20,38 +20,25 @@ package org.onap.so.bpmn.infrastructure.pnf.delegate; +import org.onap.aai.domain.yang.Pnf; +import org.onap.so.bpmn.infrastructure.pnf.implementation.AaiConnection; + import java.io.IOException; import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; import java.util.Map; import java.util.Objects; import java.util.Optional; -import org.onap.aai.domain.yang.Pnf; -import org.onap.so.bpmn.infrastructure.pnf.implementation.AaiConnection; public class AaiConnectionTestImpl implements AaiConnection { - public static final String ID_WITH_ENTRY_AND_IP = "idWithEntryAndIp"; - public static final String ID_WITH_IP_V6 = "idWithIpV6"; public static final String ID_WITHOUT_ENTRY = "IdWithoutEntry"; - public static final String ID_WITH_ENTRY_NO_IP = "idWithEntryNoIp"; - public static final String DEFAULT_IP = "1.2.3.4"; - public static final String DEFAULT_IP_V6 = "2001:db8::ff00:42:8329"; + public static final String ID_WITH_ENTRY = "idWithEntryNoIp"; private Map<String, Pnf> created = new HashMap<>(); @Override public Optional<Pnf> getEntryFor(String correlationId) throws IOException { - if (Objects.equals(correlationId, ID_WITH_ENTRY_AND_IP)) { - Pnf pnf = new Pnf(); - pnf.setIpaddressV4Oam(DEFAULT_IP); - return Optional.of(pnf); - } else if (Objects.equals(correlationId, ID_WITH_IP_V6)) { - Pnf pnf = new Pnf(); - pnf.setIpaddressV6Oam(DEFAULT_IP_V6); - return Optional.of(pnf); - } else if (Objects.equals(correlationId, ID_WITH_ENTRY_NO_IP)) { + if (Objects.equals(correlationId, ID_WITH_ENTRY)) { return Optional.of(new Pnf()); } else { return Optional.empty(); diff --git a/bpmn/mso-infrastructure-bpmn/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/AaiConnectionThrowingException.java b/bpmn/mso-infrastructure-bpmn/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/AaiConnectionThrowingException.java deleted file mode 100644 index 7df6757817..0000000000 --- a/bpmn/mso-infrastructure-bpmn/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/AaiConnectionThrowingException.java +++ /dev/null @@ -1,39 +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 java.io.IOException; -import java.util.Optional; -import org.onap.aai.domain.yang.Pnf; -import org.onap.so.bpmn.infrastructure.pnf.implementation.AaiConnection; - -public class AaiConnectionThrowingException implements AaiConnection { - - @Override - public Optional<Pnf> getEntryFor(String correlationId) throws IOException { - throw new IOException(); - } - - @Override - public void createEntry(String correlationId, Pnf entry) throws IOException { - throw new IOException(); - } -} diff --git a/bpmn/mso-infrastructure-bpmn/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/CancelDmaapSubscriptionTest.java b/bpmn/mso-infrastructure-bpmn/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/CancelDmaapSubscriptionTest.java deleted file mode 100644 index 4282b0f2bb..0000000000 --- a/bpmn/mso-infrastructure-bpmn/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/CancelDmaapSubscriptionTest.java +++ /dev/null @@ -1,49 +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 org.camunda.bpm.engine.delegate.DelegateExecution; -import org.junit.Test; - -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; - -public class CancelDmaapSubscriptionTest { - - @Test - public void shouldCancelSubscription() throws Exception { - // given - CancelDmaapSubscription delegate = new CancelDmaapSubscription(); - DmaapClientTestImpl dmaapClientTest = new DmaapClientTestImpl(); - delegate.setDmaapClient(dmaapClientTest); - DelegateExecution delegateExecution = mock(DelegateExecution.class); - when(delegateExecution.getVariable(eq(ExecutionVariableNames.CORRELATION_ID))).thenReturn("testCorrelationId"); - when(delegateExecution.getProcessBusinessKey()).thenReturn("testBusinessKey"); - dmaapClientTest.registerForUpdate("testCorrelationId", () -> { - }); - // when - delegate.execute(delegateExecution); - // then - assertThat(dmaapClientTest.haveRegisteredConsumer()).isFalse(); - } -}
\ No newline at end of file diff --git a/bpmn/mso-infrastructure-bpmn/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/CheckAaiForCorrelationIdDelegateTest.java b/bpmn/mso-infrastructure-bpmn/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/CheckAaiForCorrelationIdDelegateTest.java deleted file mode 100644 index 627e57bfb8..0000000000 --- a/bpmn/mso-infrastructure-bpmn/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/CheckAaiForCorrelationIdDelegateTest.java +++ /dev/null @@ -1,138 +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.assertThatThrownBy; -import static org.mockito.Matchers.any; -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.AaiConnectionTestImpl.ID_WITHOUT_ENTRY; -import static org.onap.so.bpmn.infrastructure.pnf.delegate.AaiConnectionTestImpl.ID_WITH_ENTRY_AND_IP; -import static org.onap.so.bpmn.infrastructure.pnf.delegate.AaiConnectionTestImpl.ID_WITH_ENTRY_NO_IP; -import static org.onap.so.bpmn.infrastructure.pnf.delegate.AaiConnectionTestImpl.ID_WITH_IP_V6; -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 org.camunda.bpm.engine.delegate.BpmnError; -import org.camunda.bpm.engine.delegate.DelegateExecution; -import org.junit.Before; -import org.junit.Test; -import org.junit.experimental.runners.Enclosed; -import org.junit.runner.RunWith; -import org.onap.so.bpmn.core.WorkflowException; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; - -@RunWith(Enclosed.class) -public class CheckAaiForCorrelationIdDelegateTest { - - public static class ConnectionOkTests { - - private CheckAaiForCorrelationIdDelegate delegate; - - @Before - public void setUp() { - delegate = new CheckAaiForCorrelationIdDelegate(); - delegate.setAaiConnection(new AaiConnectionTestImpl()); - } - - @Test - public void shouldThrowExceptionWhenCorrelationIdIsNotSet() { - // given - DelegateExecution execution = mock(DelegateExecution.class); - when(execution.getVariable(CORRELATION_ID)).thenReturn(null); - when(execution.getVariable("testProcessKey")).thenReturn("testProcessKeyValue"); - // when, then - assertThatThrownBy(() -> delegate.execute(execution)).isInstanceOf(BpmnError.class); - verify(execution).setVariable(eq("WorkflowException"), any(WorkflowException.class)); - } - - @Test - public void shouldSetCorrectVariablesWhenAaiDoesNotContainInfoAboutPnf() throws Exception { - // given - DelegateExecution execution = mock(DelegateExecution.class); - when(execution.getVariable(CORRELATION_ID)).thenReturn(ID_WITHOUT_ENTRY); - // when - delegate.execute(execution); - // then - verify(execution).setVariableLocal(AAI_CONTAINS_INFO_ABOUT_PNF, false); - } - - @Test - public void shouldSetCorrectVariablesWhenAaiContainsInfoAboutPnf() throws Exception { - shouldSetCorrectVariablesWhenAaiContainsInfoAboutPnf(ID_WITH_ENTRY_AND_IP); - } - - @Test - public void shouldSetCorrectVariablesWhenAaiContainsInfoAboutPnfWithIpV6() throws Exception { - shouldSetCorrectVariablesWhenAaiContainsInfoAboutPnf(ID_WITH_IP_V6); - } - - private void shouldSetCorrectVariablesWhenAaiContainsInfoAboutPnf(String id) throws Exception { - // given - DelegateExecution execution = mock(DelegateExecution.class); - when(execution.getVariable(CORRELATION_ID)).thenReturn(id); - // when - delegate.execute(execution); - // then - verify(execution).setVariableLocal(AAI_CONTAINS_INFO_ABOUT_PNF, true); - verify(execution).setVariableLocal(AAI_CONTAINS_INFO_ABOUT_IP, true); - } - - @Test - public void shouldSetCorrectVariablesWhenAaiContainsInfoAboutPnfWithoutIp() throws Exception { - // given - DelegateExecution execution = mock(DelegateExecution.class); - when(execution.getVariable(CORRELATION_ID)).thenReturn(ID_WITH_ENTRY_NO_IP); - // when - delegate.execute(execution); - // then - verify(execution).setVariableLocal(AAI_CONTAINS_INFO_ABOUT_PNF, true); - verify(execution).setVariableLocal(AAI_CONTAINS_INFO_ABOUT_IP, false); - } - } - - public static class NoConnectionTests { - - private CheckAaiForCorrelationIdDelegate delegate; - - @Before - public void setUp() { - delegate = new CheckAaiForCorrelationIdDelegate(); - delegate.setAaiConnection(new AaiConnectionThrowingException()); - } - - @Test - public void shouldThrowExceptionWhenIoExceptionOnConnectionToAai() { - // given - DelegateExecution execution = mock(DelegateExecution.class); - when(execution.getVariable(CORRELATION_ID)).thenReturn(ID_WITH_ENTRY_NO_IP); - when(execution.getVariable("testProcessKey")).thenReturn("testProcessKey"); - // when, then - assertThatThrownBy(() -> delegate.execute(execution)).isInstanceOf(BpmnError.class); - verify(execution).setVariable(eq("WorkflowException"), any(WorkflowException.class)); - } - } -}
\ No newline at end of file diff --git a/bpmn/mso-infrastructure-bpmn/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/CreateAaiEntryWithPnfIdDelegateTest.java b/bpmn/mso-infrastructure-bpmn/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/CreateAaiEntryWithPnfIdDelegateTest.java deleted file mode 100644 index 465dc085fc..0000000000 --- a/bpmn/mso-infrastructure-bpmn/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/mso-infrastructure-bpmn/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/bpmn/CreateAndActivatePnfResourceTest.java b/bpmn/mso-infrastructure-bpmn/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/CreateAndActivatePnfResourceTest.java index b514c38d47..2348af5dec 100644 --- a/bpmn/mso-infrastructure-bpmn/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/bpmn/CreateAndActivatePnfResourceTest.java +++ b/bpmn/mso-infrastructure-bpmn/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/CreateAndActivatePnfResourceTest.java @@ -7,9 +7,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. @@ -18,33 +18,27 @@ * ============LICENSE_END========================================================= */ -package org.onap.so.bpmn.infrastructure.pnf.delegate.bpmn; +package org.onap.so.bpmn.infrastructure.pnf.delegate; -import static org.assertj.core.api.Assertions.assertThat; -import static org.camunda.bpm.engine.test.assertions.ProcessEngineAssertions.assertThat; -import static org.onap.so.bpmn.infrastructure.pnf.delegate.AaiConnectionTestImpl.ID_WITHOUT_ENTRY; -import static org.onap.so.bpmn.infrastructure.pnf.delegate.AaiConnectionTestImpl.ID_WITH_ENTRY_AND_IP; -import static org.onap.so.bpmn.infrastructure.pnf.delegate.AaiConnectionTestImpl.ID_WITH_ENTRY_NO_IP; -import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.CORRELATION_ID; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import org.assertj.core.api.Assertions; import org.camunda.bpm.engine.RuntimeService; -import org.camunda.bpm.engine.history.HistoricVariableInstance; import org.camunda.bpm.engine.runtime.ProcessInstance; import org.camunda.bpm.engine.test.Deployment; import org.camunda.bpm.engine.test.ProcessEngineRule; +import org.camunda.bpm.engine.test.assertions.bpmn.BpmnAwareAssertions; import org.camunda.bpm.engine.test.assertions.bpmn.BpmnAwareTests; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; -import org.onap.so.bpmn.infrastructure.pnf.delegate.AaiConnectionTestImpl; -import org.onap.so.bpmn.infrastructure.pnf.delegate.DmaapClientTestImpl; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; +import java.util.HashMap; +import java.util.Map; + +import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.CORRELATION_ID; + @RunWith(SpringRunner.class) @ContextConfiguration(locations = "/applicationContext_forPnfTesting.xml") public class CreateAndActivatePnfResourceTest { @@ -65,47 +59,25 @@ public class CreateAndActivatePnfResourceTest { @Test @Deployment(resources = {"process/CreateAndActivatePnfResource.bpmn"}) - public void shouldSaveCurrentIpToVariableIfItAlreadyExistsInAai() throws Exception { + public void shouldWaitForMessageFromDmaapAndUpdateAaiEntryWhenAaiEntryExists() { // given aaiConnection.reset(); BpmnAwareTests.init(processEngineRule.getProcessEngine()); Map<String, Object> variables = new HashMap<>(); variables.put("timeoutForPnfEntryNotification", TIMEOUT_10_S); - variables.put(CORRELATION_ID, ID_WITH_ENTRY_AND_IP); - // when - ProcessInstance instance = runtimeService - .startProcessInstanceByKey("CreateAndActivatePnfResource", variables); - // then - assertThat(instance).isEnded().hasPassedInOrder( - "CreateAndActivatePnf_StartEvent", - "CheckAiiForCorrelationId", - "DoesAaiContainInfoAboutPnf", - "DoesAaiContainInfoAboutIp", - "AaiEntryAlreadyUpToDate" - ); - } - - @Test - @Deployment(resources = {"process/CreateAndActivatePnfResource.bpmn"}) - public void shouldWaitForMessageFromDmaapAndUpdateAaiEntryWhenIpIsMissingInAaiEntry() throws Exception { - // given - aaiConnection.reset(); - BpmnAwareTests.init(processEngineRule.getProcessEngine()); - Map<String, Object> variables = new HashMap<>(); - variables.put("timeoutForPnfEntryNotification", TIMEOUT_10_S); - variables.put(CORRELATION_ID, ID_WITH_ENTRY_NO_IP); + variables.put(CORRELATION_ID, AaiConnectionTestImpl.ID_WITH_ENTRY); // when ProcessInstance instance = runtimeService .startProcessInstanceByKey("CreateAndActivatePnfResource", "businessKey", variables); - assertThat(instance).isWaitingAt("WaitForDmaapPnfReadyNotification").isWaitingFor("WorkflowMessage"); + BpmnAwareAssertions.assertThat(instance).isWaitingAt("WaitForDmaapPnfReadyNotification").isWaitingFor("WorkflowMessage"); dmaapClientTestImpl.sendMessage(); // then - assertThat(instance).isEnded().hasPassedInOrder( + BpmnAwareAssertions.assertThat(instance).isEnded().hasPassedInOrder( "CreateAndActivatePnf_StartEvent", + "CheckInputs", "CheckAiiForCorrelationId", "DoesAaiContainInfoAboutPnf", - "DoesAaiContainInfoAboutIp", "AaiEntryExists", "InformDmaapClient", "WaitForDmaapPnfReadyNotification", @@ -115,22 +87,23 @@ public class CreateAndActivatePnfResourceTest { @Test @Deployment(resources = {"process/CreateAndActivatePnfResource.bpmn"}) - public void shouldCreateAaiEntryWaitForMessageFromDmaapAndUpdateAaiEntryWhenNoAaiEntry() throws Exception { + public void shouldCreateAaiEntryWaitForMessageFromDmaapAndUpdateAaiEntryWhenNoAaiEntryExists() { // given aaiConnection.reset(); BpmnAwareTests.init(processEngineRule.getProcessEngine()); Map<String, Object> variables = new HashMap<>(); variables.put("timeoutForPnfEntryNotification", TIMEOUT_10_S); - variables.put(CORRELATION_ID, ID_WITHOUT_ENTRY); + variables.put(CORRELATION_ID, AaiConnectionTestImpl.ID_WITHOUT_ENTRY); // when ProcessInstance instance = runtimeService .startProcessInstanceByKey("CreateAndActivatePnfResource", "businessKey", variables); - assertThat(instance).isWaitingAt("WaitForDmaapPnfReadyNotification").isWaitingFor("WorkflowMessage"); + BpmnAwareAssertions.assertThat(instance).isWaitingAt("WaitForDmaapPnfReadyNotification").isWaitingFor("WorkflowMessage"); dmaapClientTestImpl.sendMessage(); // then - assertThat(instance).isEnded().hasPassedInOrder( + BpmnAwareAssertions.assertThat(instance).isEnded().hasPassedInOrder( "CreateAndActivatePnf_StartEvent", + "CheckInputs", "CheckAiiForCorrelationId", "DoesAaiContainInfoAboutPnf", "CreateAndActivatePnf_CreateAaiEntry", @@ -139,11 +112,6 @@ public class CreateAndActivatePnfResourceTest { "WaitForDmaapPnfReadyNotification", "AaiEntryUpdated" ); - assertThat(aaiConnection.getCreated()).containsOnlyKeys(ID_WITHOUT_ENTRY); - } - - private List<HistoricVariableInstance> getVariables(ProcessInstance instance) { - return processEngineRule.getHistoryService().createHistoricVariableInstanceQuery() - .processInstanceId(instance.getProcessInstanceId()).taskIdIn().list(); + Assertions.assertThat(aaiConnection.getCreated()).containsOnlyKeys(AaiConnectionTestImpl.ID_WITHOUT_ENTRY); } } diff --git a/bpmn/mso-infrastructure-bpmn/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/DmaapClientTestImpl.java b/bpmn/mso-infrastructure-bpmn/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/DmaapClientTestImpl.java index f2a4205ebd..09fb2d4cd7 100644 --- a/bpmn/mso-infrastructure-bpmn/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/DmaapClientTestImpl.java +++ b/bpmn/mso-infrastructure-bpmn/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/DmaapClientTestImpl.java @@ -21,6 +21,7 @@ package org.onap.so.bpmn.infrastructure.pnf.delegate; import org.onap.so.bpmn.infrastructure.pnf.dmaap.DmaapClient; + import java.util.Objects; public class DmaapClientTestImpl implements DmaapClient { diff --git a/bpmn/mso-infrastructure-bpmn/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/InformDmaapClientTest.java b/bpmn/mso-infrastructure-bpmn/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/InformDmaapClientTest.java deleted file mode 100644 index ddf33a1d77..0000000000 --- a/bpmn/mso-infrastructure-bpmn/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/InformDmaapClientTest.java +++ /dev/null @@ -1,88 +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 org.camunda.bpm.engine.ProcessEngineServices; -import org.camunda.bpm.engine.RuntimeService; -import org.camunda.bpm.engine.delegate.DelegateExecution; -import org.camunda.bpm.engine.runtime.MessageCorrelationBuilder; -import org.junit.Before; -import org.junit.Test; -import org.mockito.InOrder; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.eq; -import static org.mockito.Mockito.*; - -public class InformDmaapClientTest { - @Before - public void setUp() throws Exception { - informDmaapClient = new InformDmaapClient(); - dmaapClientTest = new DmaapClientTestImpl(); - informDmaapClient.setDmaapClient(dmaapClientTest); - delegateExecution = mockDelegateExecution(); - } - - private InformDmaapClient informDmaapClient; - - private DmaapClientTestImpl dmaapClientTest; - - private DelegateExecution delegateExecution; - - private MessageCorrelationBuilder messageCorrelationBuilder; - - @Test - public void shouldSendListenerToDmaapClient() throws Exception { - // when - informDmaapClient.execute(delegateExecution); - // then - assertThat(dmaapClientTest.getCorrelationId()).isEqualTo("testCorrelationId"); - assertThat(dmaapClientTest.getInformConsumer()).isNotNull(); - verifyZeroInteractions(messageCorrelationBuilder); - } - - @Test - public void shouldSendListenerToDmaapClientAndSendMessageToCamunda() throws Exception { - // when - informDmaapClient.execute(delegateExecution); - dmaapClientTest.getInformConsumer().run(); - // then - assertThat(dmaapClientTest.getCorrelationId()).isEqualTo("testCorrelationId"); - InOrder inOrder = inOrder(messageCorrelationBuilder); - inOrder.verify(messageCorrelationBuilder).processInstanceBusinessKey("testBusinessKey"); - inOrder.verify(messageCorrelationBuilder).correlateWithResult(); - } - - private DelegateExecution mockDelegateExecution() { - DelegateExecution delegateExecution = mock(DelegateExecution.class); - when(delegateExecution.getVariable(eq(ExecutionVariableNames.CORRELATION_ID))).thenReturn("testCorrelationId"); - when(delegateExecution.getProcessBusinessKey()).thenReturn("testBusinessKey"); - ProcessEngineServices processEngineServices = mock(ProcessEngineServices.class); - when(delegateExecution.getProcessEngineServices()).thenReturn(processEngineServices); - RuntimeService runtimeService = mock(RuntimeService.class); - when(processEngineServices.getRuntimeService()).thenReturn(runtimeService); - messageCorrelationBuilder = mock(MessageCorrelationBuilder.class); - when(runtimeService.createMessageCorrelation(any())).thenReturn(messageCorrelationBuilder); - when(messageCorrelationBuilder.processInstanceBusinessKey(any())).thenReturn(messageCorrelationBuilder); - return delegateExecution; - } -}
\ No newline at end of file diff --git a/bpmn/mso-infrastructure-bpmn/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/PnfCheckInputsTest.java b/bpmn/mso-infrastructure-bpmn/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/PnfCheckInputsTest.java deleted file mode 100644 index aab289fd90..0000000000 --- a/bpmn/mso-infrastructure-bpmn/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/PnfCheckInputsTest.java +++ /dev/null @@ -1,84 +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.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.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/mso-infrastructure-bpmn/src/test/java/org/onap/so/bpmn/infrastructure/pnf/dmaap/PnfEventReadyDmaapClientTest.java b/bpmn/mso-infrastructure-bpmn/src/test/java/org/onap/so/bpmn/infrastructure/pnf/dmaap/PnfEventReadyDmaapClientTest.java deleted file mode 100644 index 08ac9b6948..0000000000 --- a/bpmn/mso-infrastructure-bpmn/src/test/java/org/onap/so/bpmn/infrastructure/pnf/dmaap/PnfEventReadyDmaapClientTest.java +++ /dev/null @@ -1,197 +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.dmaap; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.eq; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyZeroInteractions; -import static org.mockito.Mockito.when; - -import java.io.IOException; -import java.io.UnsupportedEncodingException; -import java.lang.reflect.Field; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ScheduledExecutorService; - -import org.apache.http.HttpEntity; -import org.apache.http.HttpResponse; -import org.apache.http.ProtocolVersion; -import org.apache.http.client.HttpClient; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.entity.StringEntity; -import org.apache.http.message.BasicHttpResponse; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.ArgumentCaptor; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; -import org.onap.so.bpmn.infrastructure.pnf.dmaap.PnfEventReadyDmaapClient.DmaapTopicListenerThread; -import org.springframework.core.env.Environment; -@RunWith(MockitoJUnitRunner.class) -public class PnfEventReadyDmaapClientTest { - - private static final String CORRELATION_ID = "corrTestId"; - private static final String CORRELATION_ID_NOT_FOUND_IN_MAP = "otherCorrId"; - private static final String JSON_EXAMPLE_WITH_CORRELATION_ID = "[\n" - + " {\n" - + " \"pnfRegistrationFields\" : {\n" - + " \"correlationId\" : \"%s\",\n" - + " \"value\" : \"value1\"\n" - + " }\n" - + " },\n" - + " {\n" - + " \"pnfRegistrationFields\" : {\n" - + " \"correlationId\" : \"corr\",\n" - + " \"value\" : \"value2\"\n" - + " }\n" - + " }\n" - + "]"; - private static final String JSON_EXAMPLE_WITH_NO_CORRELATION_ID = - "{\"pnfRegistrationFields\":{\"field\":\"value\"}}"; - - private static final String HOST = "hostTest"; - private static final int PORT = 1234; - private static final String PROTOCOL = "http"; - private static final String URI_PATH_PREFIX = "eventsForTesting"; - private static final String EVENT_TOPIC_TEST = "eventTopicTest"; - private static final String CONSUMER_ID = "consumerTestId"; - private static final String CONSUMER_GROUP = "consumerGroupTest"; - @Mock - private Environment env; - @InjectMocks - private PnfEventReadyDmaapClient testedObject = new PnfEventReadyDmaapClient(); -; - private DmaapTopicListenerThread testedObjectInnerClassThread; - private HttpClient httpClientMock; - private Runnable threadMockToNotifyCamundaFlow; - private ScheduledExecutorService executorMock; - - @Before - public void init() throws NoSuchFieldException, IllegalAccessException { - when(env.getProperty(eq("pnf.dmaap.port"), eq(Integer.class))).thenReturn(PORT); - when(env.getProperty(eq("pnf.dmaap.host"))).thenReturn(HOST); - testedObject.setDmaapProtocol(PROTOCOL); - testedObject.setDmaapUriPathPrefix(URI_PATH_PREFIX); - testedObject.setDmaapTopicName(EVENT_TOPIC_TEST); - testedObject.setConsumerId(CONSUMER_ID); - testedObject.setConsumerGroup(CONSUMER_GROUP); - testedObject.setDmaapClientDelayInSeconds(1); - testedObject.init(); - testedObjectInnerClassThread = testedObject.new DmaapTopicListenerThread(); - httpClientMock = mock(HttpClient.class); - threadMockToNotifyCamundaFlow = mock(Runnable.class); - executorMock = mock(ScheduledExecutorService.class); - setPrivateField(); - } - - /** - * Test run method, where the are following conditions: - * <p> - DmaapThreadListener is running, flag is set to true - * <p> - map is filled with one entry with the key that we get from response - * <p> run method should invoke thread from map to notify camunda process, remove element from the map (map is - * empty) and shutdown the executor because of empty map - */ - @Test - public void correlationIdIsFoundInHttpResponse_notifyAboutPnfReady() - throws IOException { - when(httpClientMock.execute(any(HttpGet.class))). - thenReturn(createResponse(String.format(JSON_EXAMPLE_WITH_CORRELATION_ID, CORRELATION_ID))); - testedObjectInnerClassThread.run(); - ArgumentCaptor<HttpGet> captor1 = ArgumentCaptor.forClass(HttpGet.class); - verify(httpClientMock).execute(captor1.capture()); - assertThat(captor1.getValue().getURI()).hasHost(HOST).hasPort(PORT).hasScheme(PROTOCOL) - .hasPath( - "/" + URI_PATH_PREFIX + "/" + EVENT_TOPIC_TEST + "/" + CONSUMER_GROUP + "/" + CONSUMER_ID + ""); - verify(threadMockToNotifyCamundaFlow).run(); - verify(executorMock).shutdownNow(); - } - - /** - * Test run method, where the are following conditions: - * <p> - DmaapThreadListener is running, flag is set to true - * <p> - map is filled with one entry with the correlationId that does not match to correlationId - * taken from http response. run method should not do anything with the map not run any thread to notify camunda - * process - */ - @Test - public void correlationIdIsFoundInHttpResponse_NotFoundInMap() - throws IOException { - when(httpClientMock.execute(any(HttpGet.class))). - thenReturn(createResponse( - String.format(JSON_EXAMPLE_WITH_CORRELATION_ID, CORRELATION_ID_NOT_FOUND_IN_MAP))); - testedObjectInnerClassThread.run(); - verifyZeroInteractions(threadMockToNotifyCamundaFlow, executorMock); - } - - /** - * Test run method, where the are following conditions: - * <p> - DmaapThreadListener is running, flag is set to true - * <p> - map is filled with one entry with the correlationId but no correlation id is taken from HttpResponse - * run method should not do anything with the map and not run any thread to notify camunda process - */ - @Test - public void correlationIdIsNotFoundInHttpResponse() throws IOException { - when(httpClientMock.execute(any(HttpGet.class))). - thenReturn(createResponse(JSON_EXAMPLE_WITH_NO_CORRELATION_ID)); - testedObjectInnerClassThread.run(); - verifyZeroInteractions(threadMockToNotifyCamundaFlow, executorMock); - } - - private void setPrivateField() throws NoSuchFieldException, IllegalAccessException { - Field httpClientField = testedObject.getClass().getDeclaredField("httpClient"); - httpClientField.setAccessible(true); - httpClientField.set(testedObject, httpClientMock); - httpClientField.setAccessible(false); - - Field executorField = testedObject.getClass().getDeclaredField("executor"); - executorField.setAccessible(true); - executorField.set(testedObject, executorMock); - executorField.setAccessible(false); - - Field pnfCorrelationToThreadMapField = testedObject.getClass() - .getDeclaredField("pnfCorrelationIdToThreadMap"); - pnfCorrelationToThreadMapField.setAccessible(true); - Map<String, Runnable> pnfCorrelationToThreadMap = new ConcurrentHashMap<>(); - pnfCorrelationToThreadMap.put(CORRELATION_ID, threadMockToNotifyCamundaFlow); - pnfCorrelationToThreadMapField.set(testedObject, pnfCorrelationToThreadMap); - - Field threadRunFlag = testedObject.getClass().getDeclaredField("dmaapThreadListenerIsRunning"); - threadRunFlag.setAccessible(true); - threadRunFlag.set(testedObject, true); - threadRunFlag.setAccessible(false); - } - - private HttpResponse createResponse(String json) throws UnsupportedEncodingException { - HttpEntity entity = new StringEntity(json); - ProtocolVersion protocolVersion = new ProtocolVersion("", 1, 1); - HttpResponse response = new BasicHttpResponse(protocolVersion, 1, ""); - response.setEntity(entity); - response.setStatusCode(200); - return response; - } - -} |