Skip to content
This repository has been archived by the owner on May 19, 2020. It is now read-only.

Commit

Permalink
Merge pull request #30 from Activiti/constantinc-1812-detele-task
Browse files Browse the repository at this point in the history
1812 handle task cancelled event
  • Loading branch information
salaboy committed Apr 23, 2018
2 parents 1683da3 + 1d74890 commit 1a2ee1d
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
@JsonSubTypes.Type(value = TaskCreatedEventEntity.class, name = TaskCreatedEventEntity.TASK_CREATED_EVENT),
@JsonSubTypes.Type(value = TaskAssignedEventEntity.class, name = TaskAssignedEventEntity.TASK_ASSIGNED_EVENT),
@JsonSubTypes.Type(value = TaskCompletedEventEntity.class, name = TaskCompletedEventEntity.TASK_COMPLETED_EVENT),
@JsonSubTypes.Type(value = TaskCancelledEventEntity.class, name = TaskCancelledEventEntity.TASK_CANCELLED_EVENT),
@JsonSubTypes.Type(value = VariableCreatedEventEntity.class, name = VariableCreatedEventEntity.VARIABLE_CREATED_EVENT),
@JsonSubTypes.Type(value = VariableUpdatedEventEntity.class, name = VariableUpdatedEventEntity.VARIABLE_UPDATED_EVENT),
@JsonSubTypes.Type(value = VariableDeletedEventEntity.class, name = VariableDeletedEventEntity.VARIABLE_DELETED_EVENT),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright 2018 Alfresco, Inc. and/or its affiliates.
*
* 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.
*/

package org.activiti.cloud.services.audit.events;

import javax.persistence.Column;
import javax.persistence.Convert;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.Lob;

import org.activiti.cloud.services.audit.converter.TaskJpaJsonConverter;
import org.activiti.cloud.services.audit.events.model.Task;

@Entity
@DiscriminatorValue(value = TaskCancelledEventEntity.TASK_CANCELLED_EVENT)
public class TaskCancelledEventEntity extends ProcessEngineEventEntity {

protected static final String TASK_CANCELLED_EVENT = "TaskCancelledEvent";

@Convert(converter = TaskJpaJsonConverter.class)
@Lob
@Column
private Task task;

public Task getTask() {
return task;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,19 @@

package org.activiti.cloud.services.audit.channel;

import org.activiti.cloud.services.audit.converter.TaskJpaJsonConverter;
import org.activiti.cloud.services.audit.events.IgnoredProcessEngineEvent;
import org.activiti.cloud.services.audit.repository.EventsRepository;
import org.activiti.cloud.services.audit.events.ProcessEngineEventEntity;
import org.activiti.cloud.services.audit.events.TaskCancelledEventEntity;
import org.activiti.cloud.services.audit.events.model.Task;
import org.activiti.cloud.services.audit.repository.EventsRepository;
import org.apache.commons.lang3.reflect.FieldUtils;
import org.junit.Before;
import org.junit.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;

import static org.assertj.core.api.Assertions.*;
import static org.mockito.Mockito.*;
import static org.mockito.MockitoAnnotations.initMocks;

Expand Down Expand Up @@ -56,4 +61,24 @@ public void receiveShouldStoreAllReceivedEventsThatAreNotIgnored() throws Except
verify(eventsRepository).save(secondEvent);
verify(eventsRepository, never()).save(ignoredProcessEngineEvent);
}

@Test
public void testReceiveTaskCancelledEvent() throws Exception {
//GIVEN

TaskCancelledEventEntity taskCancelledEventEntity = new TaskCancelledEventEntity();
Task task = new TaskJpaJsonConverter().convertToEntityAttribute(
"{\"id\":\"1\",\"createdDate\":1523945813114,\"priority\":50,\"status\":\"CANCELLED\"}");
FieldUtils.writeField(taskCancelledEventEntity, "task", task, true);
ProcessEngineEventEntity[] events = new ProcessEngineEventEntity[] {taskCancelledEventEntity};

//WHEN
handler.receive(events);

//THEN
assertThat(taskCancelledEventEntity.isIgnored()).isFalse();
assertThat(taskCancelledEventEntity.getTask()).isNotNull();
assertThat(taskCancelledEventEntity.getTask().getStatus()).isEqualTo("CANCELLED");
verify(eventsRepository).save(taskCancelledEventEntity);
}
}

0 comments on commit 1a2ee1d

Please sign in to comment.