未验证 提交 d7033f57 编写于 作者: D Davide Cerbo 提交者: GitHub

AAE-12142 use a project version in events starting from 1 (#4216)

上级 624eafde
......@@ -17,18 +17,20 @@ package org.activiti.spring;
import java.util.List;
import java.util.stream.Collectors;
import org.activiti.api.process.model.Deployment;
import org.activiti.api.process.model.events.ApplicationDeployedEvent;
import org.activiti.api.process.model.events.ApplicationEvent.ApplicationEvents;
import org.activiti.api.process.runtime.events.listener.ProcessRuntimeEventListener;
import org.activiti.api.runtime.event.impl.ApplicationDeployedEventImpl;
import org.activiti.api.runtime.event.impl.ApplicationDeployedEvents;
import org.activiti.api.runtime.model.impl.DeploymentImpl;
import org.activiti.engine.RepositoryService;
import org.activiti.runtime.api.model.impl.APIDeploymentConverter;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.util.CollectionUtils;
public class ApplicationDeployedEventProducer extends AbstractActivitiSmartLifeCycle {
......@@ -76,10 +78,27 @@ public class ApplicationDeployedEventProducer extends AbstractActivitiSmartLifeC
.latestVersion()
.list())
.stream()
.map(this::withProjectVersion1Based)
.map(deployment -> new ApplicationDeployedEventImpl(deployment, eventType))
.collect(Collectors.toList());
}
private Deployment withProjectVersion1Based(Deployment deployment) {
String projectReleaseVersion = deployment.getProjectReleaseVersion();
if(StringUtils.isNumeric(projectReleaseVersion)) {
//The project version in the database is 0 based while in the devops section is 1 based
DeploymentImpl result = new DeploymentImpl();
result.setVersion(deployment.getVersion());
result.setId(deployment.getId());
result.setName(deployment.getName());
int projectReleaseVersionInt = Integer.valueOf(projectReleaseVersion) + 1;
result.setProjectReleaseVersion(String.valueOf(projectReleaseVersionInt));
return result;
} else {
return deployment;
}
}
private ApplicationEvents getEventType() {
ApplicationEvents eventType;
if(afterRollback) {
......
......@@ -22,6 +22,7 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import java.util.List;
import org.activiti.api.process.model.events.ApplicationDeployedEvent;
......@@ -95,8 +96,10 @@ public class ApplicationDeployedEventProducerTest {
given(deploymentQuery.latestVersion()).willReturn(deploymentQuery);
given(deploymentQuery.list()).willReturn(internalDeployment);
List<org.activiti.api.process.model.Deployment> apiDeployments= asList(
mock(org.activiti.api.process.model.Deployment.class));
org.activiti.api.process.model.Deployment deployment = mock(org.activiti.api.process.model.Deployment.class);
when(deployment.getProjectReleaseVersion()).thenReturn("1");
when(deployment.getId()).thenReturn("123");
List<org.activiti.api.process.model.Deployment> apiDeployments = asList(deployment);
given(converter.from(internalDeployment)).willReturn(apiDeployments);
producer.start();
......@@ -108,8 +111,16 @@ public class ApplicationDeployedEventProducerTest {
List<ApplicationDeployedEvent> allValues = captor.getAllValues();
assertThat(allValues)
.extracting(ApplicationDeployedEvent::getEntity)
.extracting(org.activiti.api.process.model.Deployment::getId)
.hasSize(2)
.containsOnly(apiDeployments.get(0));
.containsOnly("123");
assertThat(allValues)
.extracting(ApplicationDeployedEvent::getEntity)
.extracting(org.activiti.api.process.model.Deployment::getProjectReleaseVersion)
.hasSize(2)
.containsOnly("2");
ArgumentCaptor<ApplicationDeployedEvents> captorPublisher = ArgumentCaptor.forClass(ApplicationDeployedEvents.class);
verify(eventPublisher).publishEvent(captorPublisher.capture());
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册