diff --git a/activiti-cloud-audit-service/activiti-cloud-services-audit-api/src/main/java/org/activiti/cloud/services/audit/api/controllers/AuditEventsController.java b/activiti-cloud-audit-service/activiti-cloud-services-audit-api/src/main/java/org/activiti/cloud/services/audit/api/controllers/AuditEventsController.java index 70ced78e6d1..c3e96ca5615 100644 --- a/activiti-cloud-audit-service/activiti-cloud-services-audit-api/src/main/java/org/activiti/cloud/services/audit/api/controllers/AuditEventsController.java +++ b/activiti-cloud-audit-service/activiti-cloud-services-audit-api/src/main/java/org/activiti/cloud/services/audit/api/controllers/AuditEventsController.java @@ -18,6 +18,7 @@ import org.activiti.cloud.api.model.shared.events.CloudRuntimeEvent; import org.activiti.cloud.services.audit.api.converters.CloudRuntimeEventType; import org.activiti.cloud.services.audit.api.resources.EventsLinkRelationProvider; +import org.activiti.cloud.services.audit.api.search.SearchParams; import org.springframework.data.domain.Pageable; import org.springframework.hateoas.EntityModel; import org.springframework.hateoas.MediaTypes; @@ -26,7 +27,6 @@ import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; @RestController @@ -39,8 +39,8 @@ public interface AuditEventsController { EntityModel> findById(@PathVariable String eventId); @RequestMapping(method = RequestMethod.GET) - PagedModel>> findAll( - @RequestParam(value = "search", required = false) String search, + PagedModel>> search( + SearchParams searchParams, Pageable pageable ); } diff --git a/activiti-cloud-audit-service/activiti-cloud-services-audit-api/src/main/java/org/activiti/cloud/services/audit/api/search/SearchParams.java b/activiti-cloud-audit-service/activiti-cloud-services-audit-api/src/main/java/org/activiti/cloud/services/audit/api/search/SearchParams.java new file mode 100644 index 00000000000..a79dbe90321 --- /dev/null +++ b/activiti-cloud-audit-service/activiti-cloud-services-audit-api/src/main/java/org/activiti/cloud/services/audit/api/search/SearchParams.java @@ -0,0 +1,20 @@ +/* + * Copyright 2017-2020 Alfresco Software, Ltd. + * + * 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.api.search; + +import java.util.Date; + +public record SearchParams(String search, Date eventTimeFrom, Date eventTimeTo) {} diff --git a/activiti-cloud-audit-service/activiti-cloud-services-audit-model/src/main/java/org/activiti/cloud/services/audit/jpa/repository/EventSpecification.java b/activiti-cloud-audit-service/activiti-cloud-services-audit-model/src/main/java/org/activiti/cloud/services/audit/jpa/repository/EventSpecification.java index 90cf2e1bce0..73f395a3323 100644 --- a/activiti-cloud-audit-service/activiti-cloud-services-audit-model/src/main/java/org/activiti/cloud/services/audit/jpa/repository/EventSpecification.java +++ b/activiti-cloud-audit-service/activiti-cloud-services-audit-model/src/main/java/org/activiti/cloud/services/audit/jpa/repository/EventSpecification.java @@ -48,8 +48,12 @@ public Predicate toPredicate( return builder.notEqual(root.get(criteria.getKey()), criteria.getValue()); case GREATER_THAN: return builder.greaterThan(root.get(criteria.getKey()), criteria.getValue().toString()); + case GREATER_THAN_EQUAL: + return builder.greaterThanOrEqualTo(root.get(criteria.getKey()), criteria.getValue().toString()); case LESS_THAN: return builder.lessThan(root.get(criteria.getKey()), criteria.getValue().toString()); + case LESS_THAN_EQUAL: + return builder.lessThanOrEqualTo(root.get(criteria.getKey()), criteria.getValue().toString()); case LIKE: return builder.like(root.get(criteria.getKey()), criteria.getValue().toString()); case STARTS_WITH: diff --git a/activiti-cloud-audit-service/activiti-cloud-services-audit-model/src/main/java/org/activiti/cloud/services/audit/jpa/repository/EventSpecificationsBuilder.java b/activiti-cloud-audit-service/activiti-cloud-services-audit-model/src/main/java/org/activiti/cloud/services/audit/jpa/repository/EventSpecificationsBuilder.java index 81bd549bce2..29440a77d62 100644 --- a/activiti-cloud-audit-service/activiti-cloud-services-audit-model/src/main/java/org/activiti/cloud/services/audit/jpa/repository/EventSpecificationsBuilder.java +++ b/activiti-cloud-audit-service/activiti-cloud-services-audit-model/src/main/java/org/activiti/cloud/services/audit/jpa/repository/EventSpecificationsBuilder.java @@ -46,7 +46,7 @@ public final EventSpecificationsBuilder with( final String prefix, final String suffix ) { - SearchOperation op = SearchOperation.getSimpleOperation(operation.charAt(0)); + SearchOperation op = SearchOperation.getSimpleOperation(operation); if (op != null) { if (op == SearchOperation.EQUALITY) { // the operation may be complex operation final boolean startWithAsterisk = prefix != null && prefix.contains(SearchOperation.ZERO_OR_MORE_REGEX); diff --git a/activiti-cloud-audit-service/activiti-cloud-services-audit-model/src/main/java/org/activiti/cloud/services/audit/jpa/repository/SearchOperation.java b/activiti-cloud-audit-service/activiti-cloud-services-audit-model/src/main/java/org/activiti/cloud/services/audit/jpa/repository/SearchOperation.java index 085211e6ab9..c1aeae3ac5d 100644 --- a/activiti-cloud-audit-service/activiti-cloud-services-audit-model/src/main/java/org/activiti/cloud/services/audit/jpa/repository/SearchOperation.java +++ b/activiti-cloud-audit-service/activiti-cloud-services-audit-model/src/main/java/org/activiti/cloud/services/audit/jpa/repository/SearchOperation.java @@ -19,7 +19,9 @@ public enum SearchOperation { EQUALITY, NEGATION, GREATER_THAN, + GREATER_THAN_EQUAL, LESS_THAN, + LESS_THAN_EQUAL, LIKE, STARTS_WITH, ENDS_WITH, @@ -39,16 +41,17 @@ public enum SearchOperation { public static final String RIGHT_PARANTHESIS = ")"; - public static SearchOperation getSimpleOperation(final char input) { + public static SearchOperation getSimpleOperation(final String operation) { + char input = operation.charAt(0); switch (input) { case ':': return EQUALITY; case '!': return NEGATION; case '>': - return GREATER_THAN; + return operation.length() > 1 && operation.charAt(1) == '=' ? GREATER_THAN_EQUAL : GREATER_THAN; case '<': - return LESS_THAN; + return operation.length() > 1 && operation.charAt(1) == '=' ? LESS_THAN_EQUAL : LESS_THAN; case '~': return LIKE; default: diff --git a/activiti-cloud-audit-service/activiti-cloud-services-audit-model/src/main/java/org/activiti/cloud/services/audit/jpa/repository/SpecSearchCriteria.java b/activiti-cloud-audit-service/activiti-cloud-services-audit-model/src/main/java/org/activiti/cloud/services/audit/jpa/repository/SpecSearchCriteria.java index e47ff47fc6d..508eee4de60 100644 --- a/activiti-cloud-audit-service/activiti-cloud-services-audit-model/src/main/java/org/activiti/cloud/services/audit/jpa/repository/SpecSearchCriteria.java +++ b/activiti-cloud-audit-service/activiti-cloud-services-audit-model/src/main/java/org/activiti/cloud/services/audit/jpa/repository/SpecSearchCriteria.java @@ -45,7 +45,7 @@ public SpecSearchCriteria( } public SpecSearchCriteria(String key, String operation, String prefix, String value, String suffix) { - SearchOperation op = SearchOperation.getSimpleOperation(operation.charAt(0)); + SearchOperation op = SearchOperation.getSimpleOperation(operation); if (op != null) { if (op == SearchOperation.EQUALITY) { // the operation may be complex operation final boolean startWithAsterisk = prefix != null && prefix.contains(SearchOperation.ZERO_OR_MORE_REGEX); diff --git a/activiti-cloud-audit-service/activiti-cloud-services-audit-rest/pom.xml b/activiti-cloud-audit-service/activiti-cloud-services-audit-rest/pom.xml index fdb4bd5a782..1254fd3d944 100644 --- a/activiti-cloud-audit-service/activiti-cloud-services-audit-rest/pom.xml +++ b/activiti-cloud-audit-service/activiti-cloud-services-audit-rest/pom.xml @@ -154,6 +154,11 @@ h2 test + + io.rest-assured + spring-mock-mvc + test + diff --git a/activiti-cloud-audit-service/activiti-cloud-services-audit-rest/src/main/java/org/activiti/cloud/services/audit/jpa/controllers/AuditEventsControllerImpl.java b/activiti-cloud-audit-service/activiti-cloud-services-audit-rest/src/main/java/org/activiti/cloud/services/audit/jpa/controllers/AuditEventsControllerImpl.java index 915560bbd2e..62e2ea00268 100644 --- a/activiti-cloud-audit-service/activiti-cloud-services-audit-rest/src/main/java/org/activiti/cloud/services/audit/jpa/controllers/AuditEventsControllerImpl.java +++ b/activiti-cloud-audit-service/activiti-cloud-services-audit-rest/src/main/java/org/activiti/cloud/services/audit/jpa/controllers/AuditEventsControllerImpl.java @@ -31,6 +31,7 @@ import org.activiti.cloud.services.audit.api.converters.CloudRuntimeEventType; import org.activiti.cloud.services.audit.api.converters.EventToEntityConverter; import org.activiti.cloud.services.audit.api.resources.EventsLinkRelationProvider; +import org.activiti.cloud.services.audit.api.search.SearchParams; import org.activiti.cloud.services.audit.jpa.assembler.EventRepresentationModelAssembler; import org.activiti.cloud.services.audit.jpa.events.AuditEventEntity; import org.activiti.cloud.services.audit.jpa.repository.EventSpecificationsBuilder; @@ -53,7 +54,6 @@ import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; @RestController @@ -115,11 +115,11 @@ public EntityModel> findById(@PathVa } @RequestMapping(method = RequestMethod.GET) - public PagedModel>> findAll( - @RequestParam(value = "search", required = false) String search, + public PagedModel>> search( + SearchParams searchParams, Pageable pageable ) { - Specification spec = createSearchSpec(search); + Specification spec = createSearchSpec(searchParams); spec = securityPoliciesApplicationService.createSpecWithSecurity(spec, SecurityPolicyAccess.READ); @@ -144,8 +144,9 @@ public PagedModel>> find ); } - private Specification createSearchSpec(String search) { + private Specification createSearchSpec(SearchParams searchParams) { EventSpecificationsBuilder builder = new EventSpecificationsBuilder(); + String search = searchParams.search(); if (search != null && !search.isEmpty()) { String operationSetExpr = Arrays .asList(SearchOperation.SIMPLE_OPERATION_SET) @@ -159,7 +160,12 @@ private Specification createSearchSpec(String search) { builder.with(matcher.group(1), matcher.group(2), matcher.group(4), matcher.group(3), matcher.group(5)); } } - + if (searchParams.eventTimeFrom() != null) { + builder.with("timestamp", ">=", searchParams.eventTimeFrom().getTime(), null, null); + } + if (searchParams.eventTimeTo() != null) { + builder.with("timestamp", "<=", searchParams.eventTimeTo().getTime(), null, null); + } return builder.build(); } } diff --git a/activiti-cloud-audit-service/activiti-cloud-services-audit-rest/src/test/java/org/activiti/cloud/services/audit/jpa/AuditTestConfiguration.java b/activiti-cloud-audit-service/activiti-cloud-services-audit-rest/src/test/java/org/activiti/cloud/services/audit/jpa/AuditTestConfiguration.java new file mode 100644 index 00000000000..aecb61f9ea1 --- /dev/null +++ b/activiti-cloud-audit-service/activiti-cloud-services-audit-rest/src/test/java/org/activiti/cloud/services/audit/jpa/AuditTestConfiguration.java @@ -0,0 +1,27 @@ +/* + * Copyright 2017-2020 Alfresco Software, Ltd. + * + * 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.jpa; + +import org.activiti.cloud.services.audit.jpa.util.TestConverter; +import org.springframework.context.annotation.Bean; + +public class AuditTestConfiguration { + + @Bean + public TestConverter getTestConverter() { + return new TestConverter(); + } +} diff --git a/activiti-cloud-audit-service/activiti-cloud-services-audit-rest/src/test/java/org/activiti/cloud/services/audit/jpa/controller/AuditEventsControllerImpIT.java b/activiti-cloud-audit-service/activiti-cloud-services-audit-rest/src/test/java/org/activiti/cloud/services/audit/jpa/controller/AuditEventsControllerImpIT.java new file mode 100644 index 00000000000..51c68f261ae --- /dev/null +++ b/activiti-cloud-audit-service/activiti-cloud-services-audit-rest/src/test/java/org/activiti/cloud/services/audit/jpa/controller/AuditEventsControllerImpIT.java @@ -0,0 +1,134 @@ +/* + * Copyright 2017-2020 Alfresco Software, Ltd. + * + * 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.jpa.controller; + +import static io.restassured.module.mockmvc.RestAssuredMockMvc.given; +import static io.restassured.module.mockmvc.RestAssuredMockMvc.webAppContextSetup; +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.hasSize; + +import java.time.Instant; +import java.time.ZoneOffset; +import java.time.format.DateTimeFormatter; +import java.util.List; +import org.activiti.api.runtime.shared.security.SecurityManager; +import org.activiti.cloud.alfresco.config.AlfrescoWebAutoConfiguration; +import org.activiti.cloud.services.audit.jpa.AuditTestConfiguration; +import org.activiti.cloud.services.audit.jpa.events.ActivityCompletedAuditEventEntity; +import org.activiti.cloud.services.audit.jpa.events.ActivityStartedAuditEventEntity; +import org.activiti.cloud.services.audit.jpa.events.AuditEventEntity; +import org.activiti.cloud.services.audit.jpa.events.ProcessStartedAuditEventEntity; +import org.activiti.cloud.services.audit.jpa.repository.EventsRepository; +import org.activiti.cloud.services.audit.jpa.util.TestConverter; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.context.annotation.Import; +import org.springframework.http.MediaType; +import org.springframework.security.core.userdetails.UserDetailsService; +import org.springframework.web.context.WebApplicationContext; + +@SpringBootTest(properties = { "spring.main.banner-mode=off" }) +@Import({ AlfrescoWebAutoConfiguration.class, AuditTestConfiguration.class }) +class AuditEventsControllerImpIT { + + @Autowired + private EventsRepository eventsRepository; + + @Autowired + private WebApplicationContext context; + + @MockBean + private UserDetailsService userDetailsService; + + @MockBean + private SecurityManager securityManager; + + private static final DateTimeFormatter dateTimeFormatter = DateTimeFormatter + .ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") + .withZone(ZoneOffset.UTC); + + private static final String ENTRIES_ROOT = "_embedded.events"; + private static final String EVENTS_ID_ROOT = ENTRIES_ROOT + ".id"; + + @BeforeEach + void setUp() { + webAppContextSetup(context); + } + + @AfterEach + void cleanUp() { + eventsRepository.deleteAll(); + } + + @Test + void should_returnAuditEvents_filteredByEventTimeFrom() { + AuditEventEntity audit1 = new ProcessStartedAuditEventEntity(); + audit1.setTimestamp(1000L); + audit1.setEventType(TestConverter.EVENT_TYPE); + + AuditEventEntity audit2 = new ActivityStartedAuditEventEntity(); + audit2.setTimestamp(2000L); + audit2.setEventType(TestConverter.EVENT_TYPE); + + AuditEventEntity audit3 = new ActivityCompletedAuditEventEntity(); + audit3.setTimestamp(3000L); + audit3.setEventType(TestConverter.EVENT_TYPE); + + eventsRepository.saveAll(List.of(audit1, audit2, audit3)); + + given() + .contentType(MediaType.APPLICATION_JSON_VALUE) + .param("eventTimeFrom", dateTimeFormatter.format(Instant.ofEpochMilli(2000L).atZone(ZoneOffset.UTC))) + .when() + .get("/v1/events") + .then() + .statusCode(200) + .body(ENTRIES_ROOT, hasSize(2)) + .body(EVENTS_ID_ROOT, contains(audit2.getId().toString(), audit3.getId().toString())); + eventsRepository.deleteAll(); + } + + @Test + void should_returnAuditEvents_filteredByEventTimeTo() { + AuditEventEntity audit1 = new ProcessStartedAuditEventEntity(); + audit1.setTimestamp(1000L); + audit1.setEventType(TestConverter.EVENT_TYPE); + + AuditEventEntity audit2 = new ActivityStartedAuditEventEntity(); + audit2.setTimestamp(2000L); + audit2.setEventType(TestConverter.EVENT_TYPE); + + AuditEventEntity audit3 = new ActivityCompletedAuditEventEntity(); + audit3.setTimestamp(3000L); + audit3.setEventType(TestConverter.EVENT_TYPE); + + eventsRepository.saveAll(List.of(audit1, audit2, audit3)); + + given() + .contentType(MediaType.APPLICATION_JSON_VALUE) + .param("eventTimeTo", dateTimeFormatter.format(Instant.ofEpochMilli(2000L).atZone(ZoneOffset.UTC))) + .when() + .get("/v1/events") + .then() + .statusCode(200) + .body(ENTRIES_ROOT, hasSize(2)) + .body(EVENTS_ID_ROOT, contains(audit1.getId().toString(), audit2.getId().toString())); + } +} diff --git a/activiti-cloud-audit-service/activiti-cloud-services-audit-rest/src/test/java/org/activiti/cloud/services/audit/jpa/controller/AuditEventsControllerImplIT.java b/activiti-cloud-audit-service/activiti-cloud-services-audit-rest/src/test/java/org/activiti/cloud/services/audit/jpa/controller/AuditEventsControllerImpWebMvcTest.java similarity index 94% rename from activiti-cloud-audit-service/activiti-cloud-services-audit-rest/src/test/java/org/activiti/cloud/services/audit/jpa/controller/AuditEventsControllerImplIT.java rename to activiti-cloud-audit-service/activiti-cloud-services-audit-rest/src/test/java/org/activiti/cloud/services/audit/jpa/controller/AuditEventsControllerImpWebMvcTest.java index 972b8c452de..906c6fefa37 100644 --- a/activiti-cloud-audit-service/activiti-cloud-services-audit-rest/src/test/java/org/activiti/cloud/services/audit/jpa/controller/AuditEventsControllerImplIT.java +++ b/activiti-cloud-audit-service/activiti-cloud-services-audit-rest/src/test/java/org/activiti/cloud/services/audit/jpa/controller/AuditEventsControllerImpWebMvcTest.java @@ -87,7 +87,7 @@ AlfrescoWebAutoConfiguration.class, } ) -public class AuditEventsControllerImplIT { +class AuditEventsControllerImpWebMvcTest { @MockBean private EventsRepository eventsRepository; @@ -105,12 +105,12 @@ public class AuditEventsControllerImplIT { private UserGroupManager userGroupManager; @BeforeEach - public void setUp() throws Exception { + void setUp() throws Exception { when(securityManager.getAuthenticatedUserId()).thenReturn("user"); } @Test - public void getEvents() throws Exception { + void getEvents() throws Exception { PageRequest pageable = PageRequest.of(1, 10); Page eventsPage = new PageImpl<>(buildEventsData(1), pageable, 11); @@ -152,7 +152,7 @@ private AuditEventEntity buildAuditEventEntity(long id) { } @Test - public void getEventsAlfresco() throws Exception { + void getEventsAlfresco() throws Exception { AlfrescoPageRequest pageRequest = new AlfrescoPageRequest(11, 10, PageRequest.of(0, 20)); List events = buildEventsData(1); @@ -179,7 +179,7 @@ public void getEventsAlfresco() throws Exception { } @Test - public void headEvents() throws Exception { + void headEvents() throws Exception { PageRequest pageable = PageRequest.of(1, 10); Page eventsPage = new PageImpl<>(buildEventsData(1), pageable, 10); @@ -189,7 +189,7 @@ public void headEvents() throws Exception { } @Test - public void headEventsAlfresco() throws Exception { + void headEventsAlfresco() throws Exception { AlfrescoPageRequest pageRequest = new AlfrescoPageRequest(11, 10, PageRequest.of(0, 20)); List events = buildEventsData(1); @@ -203,7 +203,7 @@ public void headEventsAlfresco() throws Exception { } @Test - public void getEventById() throws Exception { + void getEventById() throws Exception { AuditEventEntity eventEntity = buildAuditEventEntity(1); given(eventsRepository.findByEventId(anyString())).willReturn(Optional.of(eventEntity)); @@ -212,7 +212,7 @@ public void getEventById() throws Exception { } @Test - public void getEventByIdAlfresco() throws Exception { + void getEventByIdAlfresco() throws Exception { AuditEventEntity eventEntity = buildAuditEventEntity(1); given(eventsRepository.findByEventId(anyString())).willReturn(Optional.of(eventEntity)); @@ -223,7 +223,7 @@ public void getEventByIdAlfresco() throws Exception { } @Test - public void headEventById() throws Exception { + void headEventById() throws Exception { AuditEventEntity eventEntity = buildAuditEventEntity(1); given(eventsRepository.findByEventId(anyString())).willReturn(Optional.of(eventEntity)); @@ -236,7 +236,7 @@ public void headEventById() throws Exception { } @Test - public void getSignalEventById() throws Exception { + void getSignalEventById() throws Exception { BPMNSignalImpl signal = new BPMNSignalImpl("elementId"); signal.setSignalPayload(new SignalPayload("signal", null)); @@ -257,7 +257,7 @@ public void getSignalEventById() throws Exception { } @Test - public void shouldGetTimerEventById() throws Exception { + void shouldGetTimerEventById() throws Exception { BPMNTimerImpl timer = new BPMNTimerImpl("elementId"); timer.setProcessDefinitionId("processDefinitionId"); timer.setProcessInstanceId("processInstanceId"); @@ -284,7 +284,7 @@ public void shouldGetTimerEventById() throws Exception { } @Test - public void shouldGetMessageSentEventById() throws Exception { + void shouldGetMessageSentEventById() throws Exception { MessageAuditEventEntity eventEntity = messageAuditEventEntity( MessageSentAuditEventEntity.class, BPMNMessageEvent.MessageEvents.MESSAGE_SENT @@ -296,7 +296,7 @@ public void shouldGetMessageSentEventById() throws Exception { } @Test - public void shouldGetMessageWaitingEventById() throws Exception { + void shouldGetMessageWaitingEventById() throws Exception { MessageAuditEventEntity eventEntity = messageAuditEventEntity( MessageWaitingAuditEventEntity.class, BPMNMessageEvent.MessageEvents.MESSAGE_WAITING @@ -308,7 +308,7 @@ public void shouldGetMessageWaitingEventById() throws Exception { } @Test - public void shouldGetMessageReceivedEventById() throws Exception { + void shouldGetMessageReceivedEventById() throws Exception { MessageAuditEventEntity eventEntity = messageAuditEventEntity( MessageReceivedAuditEventEntity.class, BPMNMessageEvent.MessageEvents.MESSAGE_RECEIVED @@ -362,13 +362,11 @@ private BPMNMessage createBPMNMessage() { } private MessageEventPayload createMessagePayload() { - MessageEventPayload messageEventPayload = MessagePayloadBuilder + return MessagePayloadBuilder .event("messageName") .withBusinessKey("businessId") .withCorrelationKey("correlationId") .withVariable("name", "value") .build(); - - return messageEventPayload; } } diff --git a/activiti-cloud-audit-service/activiti-cloud-services-audit-rest/src/test/java/org/activiti/cloud/services/audit/jpa/util/TestConverter.java b/activiti-cloud-audit-service/activiti-cloud-services-audit-rest/src/test/java/org/activiti/cloud/services/audit/jpa/util/TestConverter.java new file mode 100644 index 00000000000..639cdfdcf16 --- /dev/null +++ b/activiti-cloud-audit-service/activiti-cloud-services-audit-rest/src/test/java/org/activiti/cloud/services/audit/jpa/util/TestConverter.java @@ -0,0 +1,145 @@ +/* + * Copyright 2017-2020 Alfresco Software, Ltd. + * + * 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.jpa.util; + +import org.activiti.cloud.api.model.shared.events.CloudRuntimeEvent; +import org.activiti.cloud.services.audit.api.converters.EventToEntityConverter; +import org.activiti.cloud.services.audit.jpa.events.AuditEventEntity; + +public class TestConverter implements EventToEntityConverter { + + public static final String EVENT_TYPE = "TestEvent"; + + @Override + public String getSupportedEvent() { + return EVENT_TYPE; + } + + @Override + public AuditEventEntity convertToEntity(CloudRuntimeEvent cloudRuntimeEvent) { + return new AuditEventEntity() { + @Override + public String getEventId() { + return cloudRuntimeEvent.getId(); + } + }; + } + + @Override + public CloudRuntimeEvent convertToAPI(AuditEventEntity eventEntity) { + return new CloudRuntimeEvent() { + @Override + public String getAppVersion() { + return eventEntity.getAppVersion(); + } + + @Override + public String getAppName() { + return eventEntity.getAppName(); + } + + @Override + public String getServiceName() { + return eventEntity.getServiceName(); + } + + @Override + public String getServiceFullName() { + return eventEntity.getServiceFullName(); + } + + @Override + public String getServiceType() { + return eventEntity.getServiceType(); + } + + @Override + public String getServiceVersion() { + return eventEntity.getServiceVersion(); + } + + @Override + public String getId() { + return String.valueOf(eventEntity.getId()); + } + + @Override + public Object getEntity() { + return eventEntity; + } + + @Override + public Long getTimestamp() { + return eventEntity.getTimestamp(); + } + + @Override + public Enum getEventType() { + return null; + } + + @Override + public String getProcessInstanceId() { + return eventEntity.getProcessInstanceId(); + } + + @Override + public String getParentProcessInstanceId() { + return eventEntity.getParentProcessInstanceId(); + } + + @Override + public String getProcessDefinitionId() { + return eventEntity.getProcessDefinitionId(); + } + + @Override + public String getProcessDefinitionKey() { + return eventEntity.getProcessDefinitionKey(); + } + + @Override + public Integer getProcessDefinitionVersion() { + return 1; + } + + @Override + public String getBusinessKey() { + return eventEntity.getBusinessKey(); + } + + @Override + public Integer getSequenceNumber() { + return eventEntity.getSequenceNumber(); + } + + @Override + public String getMessageId() { + return eventEntity.getMessageId(); + } + + @Override + public String getEntityId() { + return eventEntity.getEntityId(); + } + + @Override + public String getActor() { + return "actor"; + } + }; + } +}