Skip to content

Commit

Permalink
Oracle and SQL Server test adjustments
Browse files Browse the repository at this point in the history
* Split event registry DeploymentCollectionResourceTest to test sorting and querying separately
* Use truncated time for CMMN TaskResourceTest to avoid the differences that SQL server has in the milliseconds
* Make sure that surefire reports are uploaded when tests fail
  • Loading branch information
filiphr committed Aug 1, 2024
1 parent a289991 commit 5f5f5ba
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 12 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/oracle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ jobs:
distribution: 'zulu'
java-version: 17
- name: Test
id: test
# use oracle for the host here because we have specified a container for the job.
# If we were running the job on the VM this would be localhost
# '>-' is a special YAML syntax and means that new lines would be replaced with spaces
Expand All @@ -71,6 +72,7 @@ jobs:
-Dmaven.test.redirectTestOutputToFile=false
- name: Upload test artifacts
uses: actions/upload-artifact@v4
if: ${{ failure() && steps.test.conclusion == 'failure' }}
with:
name: surefire-test-reports
path: '**/target/surefire-reports/*'
2 changes: 2 additions & 0 deletions .github/workflows/sql-server.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ jobs:
distribution: 'zulu'
java-version: 17
- name: Test
id: test
# use localhost for the host here because we have specified a vm for the job.
# If we were running the job on a container this would be mssql
# '>-' is a special YAML syntax and means that new lines would be replaced with spaces
Expand All @@ -68,6 +69,7 @@ jobs:
-Dmaven.test.redirectTestOutputToFile=false
- name: Upload test artifacts
uses: actions/upload-artifact@v4
if: ${{ failure() && steps.test.conclusion == 'failure' }}
with:
name: surefire-test-reports
path: '**/target/surefire-reports/*'
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
import static org.assertj.core.api.Assertions.tuple;
import static org.mockito.Mockito.when;

import java.util.Calendar;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -77,12 +79,12 @@ public class TaskResourceTest extends BaseSpringRestTestCase {
*/
@CmmnDeployment(resources = { "org/flowable/cmmn/rest/service/api/repository/oneHumanTaskCase.cmmn" })
public void testGetCaseTask() throws Exception {
Calendar now = Calendar.getInstance();
cmmnEngineConfiguration.getClock().setCurrentTime(now.getTime());
Instant now = Instant.now().truncatedTo(ChronoUnit.SECONDS);
cmmnEngineConfiguration.getClock().setCurrentTime(Date.from(now));

CaseInstance caseInstance = runtimeService.createCaseInstanceBuilder().caseDefinitionKey("oneHumanTaskCase").start();
Task task = taskService.createTaskQuery().caseInstanceId(caseInstance.getId()).singleResult();
taskService.setDueDate(task.getId(), now.getTime());
taskService.setDueDate(task.getId(), Date.from(now));
taskService.setOwner(task.getId(), "owner");
task = taskService.createTaskQuery().caseInstanceId(caseInstance.getId()).singleResult();
assertThat(task).isNotNull();
Expand Down Expand Up @@ -120,8 +122,8 @@ public void testGetCaseTask() throws Exception {
public void testGetProcessAdhoc() throws Exception {
try {

Calendar now = Calendar.getInstance();
cmmnEngineConfiguration.getClock().setCurrentTime(now.getTime());
Instant now = Instant.now().truncatedTo(ChronoUnit.SECONDS);
cmmnEngineConfiguration.getClock().setCurrentTime(Date.from(now));

Task parentTask = taskService.newTask();
taskService.saveTask(parentTask);
Expand All @@ -133,7 +135,7 @@ public void testGetProcessAdhoc() throws Exception {
task.setAssignee("kermit");
task.setDelegationState(DelegationState.RESOLVED);
task.setDescription("Description");
task.setDueDate(now.getTime());
task.setDueDate(Date.from(now));
task.setOwner("owner");
task.setPriority(20);
taskService.saveTask(task);
Expand Down Expand Up @@ -177,7 +179,7 @@ public void testGetProcessAdhoc() throws Exception {
*/
public void testUpdateTaskNoOverrides() throws Exception {
try {
Calendar now = Calendar.getInstance();
Instant now = Instant.now();
Task parentTask = taskService.newTask();
taskService.saveTask(parentTask);

Expand All @@ -188,7 +190,7 @@ public void testUpdateTaskNoOverrides() throws Exception {
task.setAssignee("kermit");
task.setDelegationState(DelegationState.RESOLVED);
task.setDescription("Description");
task.setDueDate(now.getTime());
task.setDueDate(Date.from(now));
task.setOwner("owner");
task.setPriority(20);
taskService.saveTask(task);
Expand All @@ -207,7 +209,7 @@ public void testUpdateTaskNoOverrides() throws Exception {
assertThat(task.getOwner()).isEqualTo("owner");
assertThat(task.getPriority()).isEqualTo(20);
assertThat(task.getDelegationState()).isEqualTo(DelegationState.RESOLVED);
assertThat(task.getDueDate()).isEqualTo(now.getTime());
assertThat(task.getDueDate()).isEqualTo(now);
assertThat(task.getParentTaskId()).isEqualTo(parentTask.getId());

} finally {
Expand All @@ -232,8 +234,8 @@ public void testUpdateTask() throws Exception {

ObjectNode requestNode = objectMapper.createObjectNode();

Calendar dueDate = Calendar.getInstance();
String dueDateString = getISODateString(dueDate.getTime());
Instant dueDate = Instant.now();
String dueDateString = getISODateString(Date.from(dueDate));

requestNode.put("name", "New task name");
requestNode.put("description", "New task description");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,37 @@ public void testGetDeployments() throws Exception {
url = baseUrl + "?withoutTenantId=true";
assertResultsPresentInDataResponse(url, firstDeployment.getId());

} finally {
// Always cleanup any created deployments, even if the test failed
List<EventDeployment> deployments = repositoryService.createDeploymentQuery().list();
for (EventDeployment deployment : deployments) {
repositoryService.deleteDeployment(deployment.getId());
}
}
}

public void testGetDeploymentsSorting() throws Exception {

try {
// Alter time to ensure different deployTimes
Calendar yesterday = Calendar.getInstance();
yesterday.add(Calendar.DAY_OF_MONTH, -1);
eventRegistryEngineConfiguration.getClock().setCurrentTime(yesterday.getTime());

EventDeployment firstDeployment = repositoryService.createDeployment().name("Deployment 1").category("DEF")
.addClasspathResource("org/flowable/eventregistry/rest/service/api/repository/simpleEvent.event")
.tenantId("acme")
.deploy();

eventRegistryEngineConfiguration.getClock().setCurrentTime(Calendar.getInstance().getTime());
EventDeployment secondDeployment = repositoryService.createDeployment().name("Deployment 2").category("ABC")
.addClasspathResource("org/flowable/eventregistry/rest/service/api/repository/simpleEvent.event")
.tenantId("myTenant")
.deploy();

String baseUrl = EventRestUrls.createRelativeResourceUrl(EventRestUrls.URL_DEPLOYMENT_COLLECTION);
assertResultsPresentInDataResponse(baseUrl, firstDeployment.getId(), secondDeployment.getId());

// Check ordering by name
CloseableHttpResponse response = executeRequest(
new HttpGet(SERVER_URL_PREFIX + EventRestUrls.createRelativeResourceUrl(EventRestUrls.URL_DEPLOYMENT_COLLECTION) + "?sort=name&order=asc"),
Expand Down

0 comments on commit 5f5f5ba

Please sign in to comment.