Skip to content

A free, open-source alternative to Burp Suite: an intercepting proxy and web app security testing suite with Repeater, Intruder, Collaborator and a built-in OWASP ZAP scanner. Linux, AGPL-3.0.

2.5 KB
Raw Blame
package opensuite.core;

import opensuite.testkit.Expect;
import opensuite.testkit.Harness;

import java.time.LocalDateTime;
import java.util.List;

/** Settings > Tasks > Schedule tasks: which rows fall due, and which are spent once run. */
public final class TaskScheduleTest {

    public void run() {
        Harness.suite("task schedule");

        Harness.test("rows are read from the stored table and written back the same", () -> {
            String stored = "09:30\tDaily\tPause tasks\n2026-12-01 14:00\tOnce\thttps://example.test/\n\t\t\nbad";
            List<TaskSchedule.Entry> e = TaskSchedule.parse(stored);
            Expect.equal(e.size(), 2, "blank and short rows dropped");
            Expect.isTrue(e.get(0).daily(), "daily");
            Expect.isFalse(e.get(1).daily(), "once");
            Expect.equal(TaskSchedule.format(e), "09:30\tDaily\tPause tasks\n2026-12-01 14:00\tOnce\thttps://example.test/", "round trip");
        });

        Harness.test("a row falls due once its time passes, and only then", () -> {
            List<TaskSchedule.Entry> e = TaskSchedule.parse("09:30\tDaily\tPause tasks\n2026-12-01 14:00\tOnce\tResume tasks\n25:99\tOnce\tPause tasks");
            LocalDateTime a = LocalDateTime.of(2026, 12, 1, 9, 29, 40), b = LocalDateTime.of(2026, 12, 1, 9, 30, 10);
            Expect.equal(TaskSchedule.due(e, a, b).size(), 1, "the 09:30 row");
            Expect.equal(TaskSchedule.due(e, a, b).get(0).task(), "Pause tasks", "which one");
            Expect.equal(TaskSchedule.due(e, b, b.plusSeconds(30)).size(), 0, "not twice");
            Expect.equal(TaskSchedule.due(e, LocalDateTime.of(2026, 12, 1, 13, 59, 50), LocalDateTime.of(2026, 12, 1, 14, 0, 20)).get(0).task(), "Resume tasks", "the dated row on its day");
            Expect.equal(TaskSchedule.due(e, LocalDateTime.of(2026, 12, 2, 13, 59, 50), LocalDateTime.of(2026, 12, 2, 14, 0, 20)).size(), 0, "not on another day");
            Expect.equal(TaskSchedule.due(e, LocalDateTime.of(2026, 12, 2, 23, 59, 50), LocalDateTime.of(2026, 12, 3, 9, 30, 0)).size(), 1, "a daily row across midnight");
        });

        Harness.test("a row that does not repeat is spent once it has run", () -> {
            List<TaskSchedule.Entry> e = TaskSchedule.parse("09:30\tDaily\tPause tasks\n10:00\tOnce\tResume tasks");
            List<TaskSchedule.Entry> left = TaskSchedule.remaining(e, e);
            Expect.equal(left.size(), 1, "one left");
            Expect.equal(left.get(0).repeat(), "Daily", "the daily one");
        });
    }
}