Skip to content

Commit

Permalink
refactor(engine): introducing parametrized test
Browse files Browse the repository at this point in the history
  • Loading branch information
ana-vinogradova-camunda committed Jan 16, 2024
1 parent 9dca20b commit 5abd87e
Showing 1 changed file with 19 additions and 92 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,13 @@
import java.time.OffsetDateTime;
import java.time.ZoneOffset;
import java.util.Optional;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
import org.awaitility.Awaitility;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;

public abstract class AbstractTimerTest {

Expand All @@ -47,104 +50,28 @@ public abstract class AbstractTimerTest {
private ZeebeTestEngine engine;
private RecordStream recordStream;

private static Stream<Arguments> dates() {
return Stream.of(
Arguments.of(OffsetDateTime.of(2023, 10, 5, 15, 50, 0, 0, ZoneOffset.of("+02:00"))),
Arguments.of(OffsetDateTime.of(2023, 10, 31, 0, 0, 0, 0, ZoneOffset.of("+02:00"))),
Arguments.of(OffsetDateTime.of(2023, 10, 31, 23, 0, 0, 0, ZoneOffset.of("+02:00"))),
Arguments.of(OffsetDateTime.of(2023, 10, 31, 23, 59, 0, 0, ZoneOffset.of("+02:00"))),
Arguments.of(OffsetDateTime.of(2023, 10, 31, 23, 59, 59, 0, ZoneOffset.of("+02:00"))),
Arguments.of(OffsetDateTime.of(2023, 12, 31, 23, 59, 59, 0, ZoneOffset.of("+02:00"))));
}

@BeforeEach
void deployProcesses() {
final DeploymentEvent deploymentEvent = Utilities.deployResource(client, RESOURCE);
BpmnAssert.assertThat(deploymentEvent).containsProcessesByResourceName(RESOURCE);
}

@Test
void testDateContainingNegativeByte() throws Exception {

final OffsetDateTime darkDay =
OffsetDateTime.of(2023, 10, 5, 15, 50, 0, 0, ZoneOffset.of("+02:00"));

Utilities.increaseTime(engine, Duration.between(OffsetDateTime.now(), darkDay));

client.newCreateInstanceCommand().bpmnProcessId(PROCESS_ID).latestVersion().send().join();

final ActivateJobsResponse response = Utilities.activateSingleJob(client, "SimpleLog01");
final long key = response.getJobs().get(0).getKey();

client.newCompleteCommand(key).send().join();

waitForProcessInstanceCompleted();
}

@Test
void testLastDayOfTheMonth() throws Exception {
final OffsetDateTime heyDay =
OffsetDateTime.of(2023, 10, 31, 0, 0, 0, 0, ZoneOffset.of("+02:00"));

Utilities.increaseTime(engine, Duration.between(OffsetDateTime.now(), heyDay));

client.newCreateInstanceCommand().bpmnProcessId(PROCESS_ID).latestVersion().send().join();

final ActivateJobsResponse response = Utilities.activateSingleJob(client, "SimpleLog01");
final long key = response.getJobs().get(0).getKey();

client.newCompleteCommand(key).send().join();

waitForProcessInstanceCompleted();
}

@Test
void testLastHourOfTheMonth() throws Exception {
final OffsetDateTime heyDay =
OffsetDateTime.of(2023, 10, 31, 23, 0, 0, 0, ZoneOffset.of("+02:00"));

Utilities.increaseTime(engine, Duration.between(OffsetDateTime.now(), heyDay));

client.newCreateInstanceCommand().bpmnProcessId(PROCESS_ID).latestVersion().send().join();

final ActivateJobsResponse response = Utilities.activateSingleJob(client, "SimpleLog01");
final long key = response.getJobs().get(0).getKey();

client.newCompleteCommand(key).send().join();

waitForProcessInstanceCompleted();
}

@Test
void testLastMinuteOfTheMonth() throws Exception {
final OffsetDateTime heyDay =
OffsetDateTime.of(2023, 10, 31, 23, 59, 0, 0, ZoneOffset.of("+02:00"));

Utilities.increaseTime(engine, Duration.between(OffsetDateTime.now(), heyDay));

client.newCreateInstanceCommand().bpmnProcessId(PROCESS_ID).latestVersion().send().join();

final ActivateJobsResponse response = Utilities.activateSingleJob(client, "SimpleLog01");
final long key = response.getJobs().get(0).getKey();

client.newCompleteCommand(key).send().join();

waitForProcessInstanceCompleted();
}

@Test
void testLastSecondOfTheMonth() throws Exception {
final OffsetDateTime heyDay =
OffsetDateTime.of(2023, 10, 31, 23, 59, 59, 0, ZoneOffset.of("+02:00"));

Utilities.increaseTime(engine, Duration.between(OffsetDateTime.now(), heyDay));

client.newCreateInstanceCommand().bpmnProcessId(PROCESS_ID).latestVersion().send().join();

final ActivateJobsResponse response = Utilities.activateSingleJob(client, "SimpleLog01");
final long key = response.getJobs().get(0).getKey();

client.newCompleteCommand(key).send().join();

waitForProcessInstanceCompleted();
}

@Test
void testLastSecondOfTheYear() throws Exception {
final OffsetDateTime heyDay =
OffsetDateTime.of(2023, 12, 31, 23, 59, 59, 0, ZoneOffset.of("+02:00"));
@ParameterizedTest
@MethodSource("dates")
void shouldCompareTimersDueDatesCorrectlyForDifferentNowDates(final OffsetDateTime nowDate)
throws Exception {

Utilities.increaseTime(engine, Duration.between(OffsetDateTime.now(), heyDay));
Utilities.increaseTime(engine, Duration.between(OffsetDateTime.now(), nowDate));

client.newCreateInstanceCommand().bpmnProcessId(PROCESS_ID).latestVersion().send().join();

Expand Down

0 comments on commit 5abd87e

Please sign in to comment.