diff options
author | Rob Daugherty <rd472p@att.com> | 2018-03-28 18:00:39 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2018-03-28 18:00:39 +0000 |
commit | 21241fb1244e2554a55b4fad999e55ecf2e8e38c (patch) | |
tree | 7fc155f0cdcc7ced86c3d46ed91a0f074da76a3b /bpmn/MSOInfrastructureBPMN/src/test | |
parent | 8f394febaf7423e6ea66007565f8aeebe23991e6 (diff) | |
parent | 5c788af30b182a75979ea30c76eb83511f5c944d (diff) |
Merge "Added subworkflow for Pnf pnp"
Diffstat (limited to 'bpmn/MSOInfrastructureBPMN/src/test')
6 files changed, 447 insertions, 0 deletions
diff --git a/bpmn/MSOInfrastructureBPMN/src/test/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/AaiConnectionTestImpl.java b/bpmn/MSOInfrastructureBPMN/src/test/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/AaiConnectionTestImpl.java new file mode 100644 index 0000000000..1ad1f9e5a4 --- /dev/null +++ b/bpmn/MSOInfrastructureBPMN/src/test/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/AaiConnectionTestImpl.java @@ -0,0 +1,71 @@ +/*- + * ============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 java.io.IOException; +import java.util.LinkedList; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import org.onap.aai.domain.yang.Pnf; +import org.openecomp.mso.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"; + + private List<String> created = new LinkedList<>(); + + @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)) { + return Optional.of(new Pnf()); + } else { + return Optional.empty(); + } + } + + @Override + public void createEntry(String correlationId, Pnf entry) throws IOException { + created.add(correlationId); + } + + public List<String> getCreated() { + return created; + } + + public void reset() { + created.clear(); + } +} diff --git a/bpmn/MSOInfrastructureBPMN/src/test/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/AaiConnectionThrowingException.java b/bpmn/MSOInfrastructureBPMN/src/test/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/AaiConnectionThrowingException.java new file mode 100644 index 0000000000..9a8dd5df24 --- /dev/null +++ b/bpmn/MSOInfrastructureBPMN/src/test/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/AaiConnectionThrowingException.java @@ -0,0 +1,39 @@ +/*- + * ============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 java.io.IOException; +import java.util.Optional; +import org.onap.aai.domain.yang.Pnf; +import org.openecomp.mso.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/MSOInfrastructureBPMN/src/test/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/CheckAaiForCorrelationIdDelegateTest.java b/bpmn/MSOInfrastructureBPMN/src/test/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/CheckAaiForCorrelationIdDelegateTest.java new file mode 100644 index 0000000000..d98a395838 --- /dev/null +++ b/bpmn/MSOInfrastructureBPMN/src/test/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/CheckAaiForCorrelationIdDelegateTest.java @@ -0,0 +1,129 @@ +/*- + * ============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.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; +import static org.openecomp.mso.bpmn.infrastructure.pnf.delegate.AaiConnectionTestImpl.DEFAULT_IP; +import static org.openecomp.mso.bpmn.infrastructure.pnf.delegate.AaiConnectionTestImpl.ID_WITHOUT_ENTRY; +import static org.openecomp.mso.bpmn.infrastructure.pnf.delegate.AaiConnectionTestImpl.ID_WITH_ENTRY_AND_IP; +import static org.openecomp.mso.bpmn.infrastructure.pnf.delegate.AaiConnectionTestImpl.ID_WITH_ENTRY_NO_IP; +import static org.openecomp.mso.bpmn.infrastructure.pnf.delegate.AaiConnectionTestImpl.ID_WITH_IP_V6; +import static org.openecomp.mso.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.AAI_CONTAINS_INFO_ABOUT_IP; +import static org.openecomp.mso.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.AAI_CONTAINS_INFO_ABOUT_PNF; +import static org.openecomp.mso.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.CORRELATION_ID; + +import org.camunda.bpm.engine.delegate.BpmnError; +import org.camunda.bpm.engine.delegate.DelegateExecution; +import org.junit.Test; +import org.junit.experimental.runners.Enclosed; +import org.junit.runner.RunWith; +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 { + + @RunWith(SpringRunner.class) + @SpringBootTest(classes = {CheckAaiForCorrelationIdDelegate.class, AaiConnectionTestImpl.class}) + public static class ConnectionOkTests { + + @Autowired + private CheckAaiForCorrelationIdDelegate delegate; + + @Test + public void shouldThrowExceptionWhenCorrelationIdIsNotSet() throws Exception { + // 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); + // todo: uncomment line below after fixing Execution -> DelecateExecution in groovy scripts +// 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); + } + } + + + @RunWith(SpringRunner.class) + @SpringBootTest(classes = {CheckAaiForCorrelationIdDelegate.class, AaiConnectionThrowingException.class}) + public static class NoConnectionTests { + + @Autowired + private CheckAaiForCorrelationIdDelegate delegate; + + @Test + public void shouldThrowExceptionWhenSSADFDSADSFDS() throws Exception { + // given + DelegateExecution execution = mock(DelegateExecution.class); + when(execution.getVariable(CORRELATION_ID)).thenReturn(ID_WITH_ENTRY_NO_IP); + // when, then + assertThatThrownBy(() -> delegate.execute(execution)).isInstanceOf(BpmnError.class); + } + } +}
\ No newline at end of file diff --git a/bpmn/MSOInfrastructureBPMN/src/test/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/bpmn/CreateAndActivatePnfResourceTest.java b/bpmn/MSOInfrastructureBPMN/src/test/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/bpmn/CreateAndActivatePnfResourceTest.java new file mode 100644 index 0000000000..88e7d2f4b3 --- /dev/null +++ b/bpmn/MSOInfrastructureBPMN/src/test/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/bpmn/CreateAndActivatePnfResourceTest.java @@ -0,0 +1,141 @@ +/*- + * ============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.bpmn; + +import static org.camunda.bpm.engine.test.assertions.ProcessEngineAssertions.assertThat; +import static org.openecomp.mso.bpmn.infrastructure.pnf.delegate.AaiConnectionTestImpl.ID_WITHOUT_ENTRY; +import static org.openecomp.mso.bpmn.infrastructure.pnf.delegate.AaiConnectionTestImpl.ID_WITH_ENTRY_AND_IP; +import static org.openecomp.mso.bpmn.infrastructure.pnf.delegate.AaiConnectionTestImpl.ID_WITH_ENTRY_NO_IP; +import static org.openecomp.mso.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.CORRELATION_ID; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +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.BpmnAwareTests; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.openecomp.mso.bpmn.infrastructure.pnf.delegate.AaiConnectionTestImpl; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@ContextConfiguration(locations = "/applicationContext_forPnfTesting.xml") +public class CreateAndActivatePnfResourceTest { + + private static final String TIMEOUT_10_S = "PT10S"; + @Autowired + private RuntimeService runtimeService; + + @Autowired + @Rule + public ProcessEngineRule processEngineRule; + + @Autowired + private AaiConnectionTestImpl aaiConnection; + + @Test + @Deployment(resources = {"process/CreateAndActivatePnfResource.bpmn"}) + public void shouldSaveCurrentIpToVariableIfItAlreadyExistsInAai() 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_AND_IP); + // when + ProcessInstance instance = runtimeService + .startProcessInstanceByKey("CreateAndActivatePnfResource", variables); + // then + assertThat(instance).isEnded().hasPassedInOrder( + "CreateAndActivatePnf_StartEvent", + "CheckAiiForCorrelationId", + "DoesAaiContainInfoAboutPnf", + "DoesAaiContainInfoAboutIp" + ); + } + + @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); + // when + ProcessInstance instance = runtimeService + .startProcessInstanceByKey("CreateAndActivatePnfResource", "businessKey", variables); + assertThat(instance).isWaitingAt("WaitForDmaapPnfReadyNotification").isWaitingFor("WorkflowMessage"); + runtimeService.createMessageCorrelation("WorkflowMessage") + .processInstanceBusinessKey("businessKey") + .correlateWithResult(); + // then + assertThat(instance).isEnded().hasPassedInOrder( + "CreateAndActivatePnf_StartEvent", + "CheckAiiForCorrelationId", + "DoesAaiContainInfoAboutPnf", + "DoesAaiContainInfoAboutIp", + "AaiEntryExists", + "WaitForDmaapPnfReadyNotification" + ); + } + + @Test + @Deployment(resources = {"process/CreateAndActivatePnfResource.bpmn"}) + public void shouldCreateAaiEntryWaitForMessageFromDmaapAndUpdateAaiEntryWhenNoAaiEntry() 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_WITHOUT_ENTRY); + // when + ProcessInstance instance = runtimeService + .startProcessInstanceByKey("CreateAndActivatePnfResource", "businessKey", variables); + assertThat(instance).isWaitingAt("WaitForDmaapPnfReadyNotification").isWaitingFor("WorkflowMessage"); + runtimeService.createMessageCorrelation("WorkflowMessage") + .processInstanceBusinessKey("businessKey") + .correlateWithResult(); + // then + assertThat(instance).isEnded().hasPassedInOrder( + "CreateAndActivatePnf_StartEvent", + "CheckAiiForCorrelationId", + "DoesAaiContainInfoAboutPnf", + "CreateAndActivatePnf_CreateAaiEntry", + "AaiEntryExists", + "WaitForDmaapPnfReadyNotification" + ); + assertThat(aaiConnection.getCreated()).containsExactly(ID_WITHOUT_ENTRY); + } + + private List<HistoricVariableInstance> getVariables(ProcessInstance instance) { + return processEngineRule.getHistoryService().createHistoricVariableInstanceQuery() + .processInstanceId(instance.getProcessInstanceId()).taskIdIn().list(); + } +} diff --git a/bpmn/MSOInfrastructureBPMN/src/test/resources/applicationContext_forPnfTesting.xml b/bpmn/MSOInfrastructureBPMN/src/test/resources/applicationContext_forPnfTesting.xml new file mode 100644 index 0000000000..b222383c82 --- /dev/null +++ b/bpmn/MSOInfrastructureBPMN/src/test/resources/applicationContext_forPnfTesting.xml @@ -0,0 +1,59 @@ +<beans xmlns="http://www.springframework.org/schema/beans" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:context="http://www.springframework.org/schema/context" + xsi:schemaLocation="http://www.springframework.org/schema/beans + http://www.springframework.org/schema/beans/spring-beans.xsd + http://www.springframework.org/schema/context + http://www.springframework.org/schema/context/spring-context-2.5.xsd" > + + <bean id="dataSource" class="org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy"> + <property name="targetDataSource"> + <bean class="org.springframework.jdbc.datasource.SimpleDriverDataSource"> + <property name="driverClass" value="org.h2.Driver" /> + <property name="url" + value="jdbc:h2:mem:process-engine;DB_CLOSE_DELAY=1000" /> + <property name="username" value="sa" /> + <property name="password" value="" /> + </bean> + </property> + </bean> + + <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> + <property name="dataSource" ref="dataSource" /> + </bean> + + <bean id="processEngineConfiguration" class="org.camunda.bpm.engine.spring.SpringProcessEngineConfiguration"> + <property name="processEngineName" value="engine" /> + <property name="dataSource" ref="dataSource" /> + <property name="transactionManager" ref="transactionManager" /> + <property name="databaseSchemaUpdate" value="true" /> + <property name="jobExecutorActivate" value="false" /> + <!--<property name="deploymentResources" value="classpath*:*.bpmn" />--> + </bean> + + <bean id="processEngine" class="org.camunda.bpm.engine.spring.ProcessEngineFactoryBean"> + <property name="processEngineConfiguration" ref="processEngineConfiguration" /> + </bean> + + <bean id="repositoryService" factory-bean="processEngine" factory-method="getRepositoryService" /> + <bean id="runtimeService" factory-bean="processEngine" factory-method="getRuntimeService" /> + <bean id="taskService" factory-bean="processEngine" factory-method="getTaskService" /> + <bean id="historyService" factory-bean="processEngine" factory-method="getHistoryService" /> + <bean id="managementService" factory-bean="processEngine" factory-method="getManagementService" /> + + <context:annotation-config /> + + <bean id="processEngineRule" class="org.camunda.bpm.engine.test.ProcessEngineRule"> + <property name="processEngine" ref="processEngine" /> + </bean> + + <bean id="aaiConnection" class="org.openecomp.mso.bpmn.infrastructure.pnf.delegate.AaiConnectionTestImpl"/> + + <bean id="checkAaiForCorrelationIdDelegate" class="org.openecomp.mso.bpmn.infrastructure.pnf.delegate.CheckAaiForCorrelationIdDelegate"> + <property name="aaiConnection" ref="aaiConnection"/> + </bean> + + <bean id="createAaiEntryWithPnfIdDelegate" class="org.openecomp.mso.bpmn.infrastructure.pnf.delegate.CreateAaiEntryWithPnfIdDelegate"> + <property name="aaiConnection" ref="aaiConnection"/> + </bean> +</beans> diff --git a/bpmn/MSOInfrastructureBPMN/src/test/resources/log4j.properties b/bpmn/MSOInfrastructureBPMN/src/test/resources/log4j.properties new file mode 100644 index 0000000000..393e0877ec --- /dev/null +++ b/bpmn/MSOInfrastructureBPMN/src/test/resources/log4j.properties @@ -0,0 +1,8 @@ +# Root logger option +log4j.rootLogger=INFO, stdout + +# Direct log messages to stdout +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.Target=System.out +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
\ No newline at end of file |