Java Code Examples for org.dmfs.rfc5545.DateTime#addDuration()

The following examples show how to use org.dmfs.rfc5545.DateTime#addDuration() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TimeDataTest.java    From opentasks with Apache License 2.0 6 votes vote down vote up
@Test
public void test_whenStartAndDueAreProvided_setsThemAndNullsDuration()
{
    DateTime start = DateTime.now();
    DateTime due = start.addDuration(new Duration(1, 1, 0));

    assertThat(new TimeData<>(start, due),
            builds(
                    withValuesOnly(
                            containing(Tasks.DTSTART, start.getTimestamp()),
                            containing(Tasks.TZ, "UTC"),
                            containing(Tasks.IS_ALLDAY, 0),
                            containing(Tasks.DUE, due.getTimestamp()),
                            withNullValue(Tasks.DURATION)
                    )));
}
 
Example 2
Source File: TimeDataTest.java    From opentasks with Apache License 2.0 6 votes vote down vote up
@Test
public void test_whenStartHasAllDayFlag_correspondingValueIsOne()
{
    DateTime start = DateTime.now().toAllDay();
    DateTime due = start.addDuration(new Duration(1, 3, 0));

    assertThat(new TimeData<>(start, due),
            builds(
                    withValuesOnly(
                            containing(Tasks.DTSTART, start.getTimestamp()),
                            containing(Tasks.TZ, "UTC"),
                            containing(Tasks.IS_ALLDAY, 1),
                            containing(Tasks.DUE, due.getTimestamp()),
                            withNullValue(Tasks.DURATION)
                    )));
}
 
Example 3
Source File: InstanceTestDataTest.java    From opentasks with Apache License 2.0 6 votes vote down vote up
@Test
public void testWithDateAndOriginalTime()
{
    DateTime start = DateTime.now();
    DateTime due = start.addDuration(Duration.parse("P1DT1H"));
    DateTime original = start.addDuration(Duration.parse("P2DT2H"));
    assertThat(new InstanceTestData(start, due, new Present<>(original), 5),
            builds(
                    withValuesOnly(
                            containing(TaskContract.Instances.INSTANCE_START, start.getTimestamp()),
                            containing(TaskContract.Instances.INSTANCE_START_SORTING, start.shiftTimeZone(TimeZone.getDefault()).getInstance()),
                            containing(TaskContract.Instances.INSTANCE_DUE, due.getTimestamp()),
                            containing(TaskContract.Instances.INSTANCE_DUE_SORTING, due.shiftTimeZone(TimeZone.getDefault()).getInstance()),
                            containing(TaskContract.Instances.INSTANCE_DURATION, due.getTimestamp() - start.getTimestamp()),
                            containing(TaskContract.Instances.INSTANCE_ORIGINAL_TIME, original.getTimestamp()),
                            containing(TaskContract.Instances.DISTANCE_FROM_CURRENT, 5),
                            containing(TaskContract.Instances.DTSTART, start.getTimestamp()),
                            containing(TaskContract.Instances.DUE, due.getTimestamp()),
                            containing(TaskContract.Instances.ORIGINAL_INSTANCE_TIME, original.getTimestamp()),
                            withNullValue(TaskContract.Instances.DURATION),
                            withNullValue(TaskContract.Instances.RRULE),
                            withNullValue(TaskContract.Instances.RDATE),
                            withNullValue(TaskContract.Instances.EXDATE)
                    )
            ));
}
 
Example 4
Source File: InstanceTestDataTest.java    From opentasks with Apache License 2.0 6 votes vote down vote up
@Test
public void testWithDueDateAndOriginalTime()
{
    DateTime due = DateTime.now();
    DateTime original = due.addDuration(Duration.parse("P2DT2H"));
    assertThat(new InstanceTestData(absent(), new Present<>(due), new Present<>(original), 5),
            builds(
                    withValuesOnly(
                            withNullValue(TaskContract.Instances.INSTANCE_START),
                            withNullValue(TaskContract.Instances.INSTANCE_START_SORTING),
                            containing(TaskContract.Instances.INSTANCE_DUE, due.getTimestamp()),
                            containing(TaskContract.Instances.INSTANCE_DUE_SORTING, due.shiftTimeZone(TimeZone.getDefault()).getInstance()),
                            withNullValue(TaskContract.Instances.INSTANCE_DURATION),
                            containing(TaskContract.Instances.INSTANCE_ORIGINAL_TIME, original.getTimestamp()),
                            containing(TaskContract.Instances.DISTANCE_FROM_CURRENT, 5),
                            withNullValue(TaskContract.Instances.DTSTART),
                            containing(TaskContract.Instances.DUE, due.getTimestamp()),
                            containing(TaskContract.Instances.ORIGINAL_INSTANCE_TIME, original.getTimestamp()),
                            withNullValue(TaskContract.Instances.DURATION),
                            withNullValue(TaskContract.Instances.RRULE),
                            withNullValue(TaskContract.Instances.RDATE),
                            withNullValue(TaskContract.Instances.EXDATE)
                    )
            ));
}
 
Example 5
Source File: TaskProviderTest.java    From opentasks with Apache License 2.0 5 votes vote down vote up
/**
 * Create task with start and due, check datetime and INSTANCE_STATUS values after updating the task twice.
 */
@Test
public void testInsertTaskWithStartAndDueUpdateTwice()
{
    RowSnapshot<TaskLists> taskList = new VirtualRowSnapshot<>(new LocalTaskListsTable(mAuthority));
    RowSnapshot<Tasks> task = new VirtualRowSnapshot<>(new TaskListScoped(taskList, new TasksTable(mAuthority)));

    DateTime start = DateTime.now();
    DateTime due = start.addDuration(new Duration(1, 1, 0));

    assertThat(new Seq<>(
            new Put<>(taskList, new EmptyRowData<>()),
            new Put<>(task, new TimeData<>(start, due)),
            // update the status of the new task
            new Put<>(task, new StatusData<>(Tasks.STATUS_COMPLETED)),
            // update the title of the new task
            new Put<>(task, new TitleData("Task Title"))
    ), resultsIn(mClient,
            new Assert<>(task, new Composite<>(
                    new TimeData<>(start, due),
                    new TitleData("Task Title"),
                    new VersionData(2))), // task has been updated twice
            new AssertRelated<>(
                    new InstanceTable(mAuthority), Instances.TASK_ID, task,
                    new Composite<Instances>(
                            new InstanceTestData(
                                    start.shiftTimeZone(TimeZone.getDefault()),
                                    due.shiftTimeZone(TimeZone.getDefault()),
                                    absent(),
                                    -1),
                            new CharSequenceRowData<>(Tasks.TZ, "UTC"))
            )));
}
 
Example 6
Source File: TaskProviderTest.java    From opentasks with Apache License 2.0 5 votes vote down vote up
/**
 * Create task with start and due and update it with new values, check datetime values including generated duration.
 */
@Test
public void testInsertTaskWithStartAndDueMovedForward()
{
    RowSnapshot<TaskLists> taskList = new VirtualRowSnapshot<>(new LocalTaskListsTable(mAuthority));
    RowSnapshot<Tasks> task = new VirtualRowSnapshot<>(new TaskListScoped(taskList, new TasksTable(mAuthority)));

    DateTime start = DateTime.now();
    DateTime due = start.addDuration(new Duration(1, 1, 0));
    Duration duration = new Duration(1, 2, 0);

    DateTime startNew = start.addDuration(duration);
    DateTime dueNew = due.addDuration(duration);

    assertThat(new Seq<>(
            new Put<>(taskList, new EmptyRowData<TaskLists>()),
            new Put<>(task, new TimeData<>(start, due)),
            new Put<>(task, new TimeData<>(startNew, dueNew))
    ), resultsIn(mClient,
            new Assert<>(task, new Composite<>(
                    new TimeData<>(startNew, dueNew),
                    new VersionData(1))),
            new AssertRelated<>(
                    new InstanceTable(mAuthority), Instances.TASK_ID, task,
                    new Composite<Instances>(
                            new InstanceTestData(
                                    startNew.shiftTimeZone(TimeZone.getDefault()),
                                    dueNew.shiftTimeZone(TimeZone.getDefault()),
                                    absent(),
                                    0),
                            new CharSequenceRowData<>(Tasks.TZ, "UTC"))
            )));
}
 
Example 7
Source File: TaskProviderTest.java    From opentasks with Apache License 2.0 5 votes vote down vote up
/**
 * Create task with start and due, check datetime values including generated duration.
 */
@Test
public void testInsertTaskWithStartAndDue()
{
    RowSnapshot<TaskLists> taskList = new VirtualRowSnapshot<>(new LocalTaskListsTable(mAuthority));
    RowSnapshot<Tasks> task = new VirtualRowSnapshot<>(new TaskListScoped(taskList, new TasksTable(mAuthority)));

    DateTime start = DateTime.now();
    DateTime due = start.addDuration(new Duration(1, 1, 0));

    assertThat(new Seq<>(
            new Put<>(taskList, new EmptyRowData<TaskLists>()),
            new Put<>(task, new TimeData<>(start, due))

    ), resultsIn(mClient,
            new Assert<>(task, new Composite<>(
                    new TimeData<>(start, due),
                    new VersionData(0))),
            new AssertRelated<>(
                    new InstanceTable(mAuthority), Instances.TASK_ID, task,
                    new Composite<Instances>(
                            new InstanceTestData(
                                    start.shiftTimeZone(TimeZone.getDefault()),
                                    due.shiftTimeZone(TimeZone.getDefault()),
                                    absent(),
                                    0),
                            new CharSequenceRowData<>(Tasks.TZ, "UTC"))
            )));
}
 
Example 8
Source File: TaskProviderTest.java    From opentasks with Apache License 2.0 5 votes vote down vote up
/**
 * Create task without dates and set start and due afterwards, check datetime values including generated duration.
 */
@Test
public void testInsertTaskWithStartAndDueAddedAfterwards()
{
    RowSnapshot<TaskLists> taskList = new VirtualRowSnapshot<>(new LocalTaskListsTable(mAuthority));
    RowSnapshot<Tasks> task = new VirtualRowSnapshot<>(new TaskListScoped(taskList, new TasksTable(mAuthority)));

    DateTime start = DateTime.now();
    DateTime due = start.addDuration(new Duration(1, 1, 0));

    assertThat(new Seq<>(
            new Put<>(taskList, new EmptyRowData<TaskLists>()),
            new Put<>(task, new TitleData("Test")),
            new Put<>(task, new TimeData<>(start, due))
    ), resultsIn(mClient,
            new Assert<>(task, new Composite<>(
                    new TimeData<>(start, due),
                    new VersionData(1))),
            new AssertRelated<>(
                    new InstanceTable(mAuthority), Instances.TASK_ID, task,
                    new Composite<Instances>(
                            new InstanceTestData(
                                    start.shiftTimeZone(TimeZone.getDefault()),
                                    due.shiftTimeZone(TimeZone.getDefault()),
                                    absent(),
                                    0),
                            new CharSequenceRowData<>(Tasks.TZ, "UTC"))
            )));
}
 
Example 9
Source File: TaskProviderTest.java    From opentasks with Apache License 2.0 5 votes vote down vote up
/**
 * Having a task with start and due.
 * Update it with different due, check datetime values correct in Tasks and Instances.
 */
@Test
public void testUpdateDue() throws Exception
{
    RowSnapshot<TaskLists> taskList = new VirtualRowSnapshot<>(new LocalTaskListsTable(mAuthority));
    RowSnapshot<Tasks> task = new VirtualRowSnapshot<>(new TaskListScoped(taskList, new TasksTable(mAuthority)));
    OperationsQueue queue = new BasicOperationsQueue(mClient);

    DateTime start = DateTime.now();
    DateTime due = start.addDuration(new Duration(1, 0, 1));

    queue.enqueue(new Seq<>(
            new Put<>(taskList, new NameData("list1")),
            new Put<>(task, new TimeData<>(start, due))
    ));
    queue.flush();

    DateTime due2 = due.addDuration(new Duration(1, 0, 2));

    assertThat(new SingletonIterable<>(
            new Put<>(task, new TimeData<>(start, due2))

    ), resultsIn(queue,
            new Assert<>(task, new Composite<>(
                    new TimeData<>(start, due2),
                    new VersionData(1))),
            new AssertRelated<>(
                    new InstanceTable(mAuthority), Instances.TASK_ID, task,
                    new Composite<Instances>(
                            new InstanceTestData(
                                    start.shiftTimeZone(TimeZone.getDefault()),
                                    due2.shiftTimeZone(TimeZone.getDefault()),
                                    absent(),
                                    0),
                            new CharSequenceRowData<>(Tasks.TZ, "UTC"))
            )));
}
 
Example 10
Source File: TaskProviderTest.java    From opentasks with Apache License 2.0 5 votes vote down vote up
/**
 * Create task with start and due, check datetime values including generated duration.
 */
@Test
public void testInsertTaskWithoutStartAndDueButRRULE() throws InvalidRecurrenceRuleException
{
    RowSnapshot<TaskLists> taskList = new VirtualRowSnapshot<>(new LocalTaskListsTable(mAuthority));
    RowSnapshot<Tasks> task = new VirtualRowSnapshot<>(new TaskListScoped(taskList, new TasksTable(mAuthority)));

    DateTime start = DateTime.now();
    DateTime due = start.addDuration(new Duration(1, 1, 0));

    assertThat(new Seq<>(
                    new Put<>(taskList, new EmptyRowData<>()),
                    new Put<>(task, new Composite<>(
                            new TitleData("test"),
                            new RRuleTaskData(new RecurrenceRule("FREQ=DAILY;COUNT=5", RecurrenceRule.RfcMode.RFC2445_LAX))))),
            resultsIn(mClient,
                    new Assert<>(task, new Composite<>(
                            new TitleData("test"),
                            new VersionData(0))),
                    new AssertRelated<>(
                            new InstanceTable(mAuthority), Instances.TASK_ID, task,
                            new Composite<>(
                                    new CharSequenceRowData<>(Tasks.TITLE, "test"),
                                    new InstanceTestData(
                                            absent(),
                                            absent(),
                                            absent(),
                                            0),
                                    new CharSequenceRowData<>(Tasks.TZ, null))
                    )));
}
 
Example 11
Source File: TaskProviderRecurrenceTest.java    From opentasks with Apache License 2.0 4 votes vote down vote up
/**
     * Test if instances of a task with a DTSTART and RDATEs.
     */
    @Test
    public void testRDate() throws InvalidRecurrenceRuleException
    {
        RowSnapshot<TaskLists> taskList = new VirtualRowSnapshot<>(new LocalTaskListsTable(mAuthority));
        Table<Instances> instancesTable = new InstanceTable(mAuthority);
        RowSnapshot<Tasks> task = new VirtualRowSnapshot<>(new TaskListScoped(taskList, new TasksTable(mAuthority)));

        Duration hour = new Duration(1, 0, 3600 /* 1 hour */);
        DateTime start = DateTime.parse("20180104T123456Z");
        DateTime due = start.addDuration(hour);

        Duration day = new Duration(1, 1, 0);

        DateTime localStart = start.shiftTimeZone(TimeZone.getDefault());
        DateTime localDue = due.shiftTimeZone(TimeZone.getDefault());

        DateTime second = localStart.addDuration(day);
        DateTime third = second.addDuration(day);
        DateTime fourth = third.addDuration(day);
        DateTime fifth = fourth.addDuration(day);

        assertThat(new Seq<>(
                        new Put<>(taskList, new EmptyRowData<>()),
                        new Put<>(task,
                                new Composite<>(
                                        new TimeData<>(start, due),
                                        new RDatesTaskData(new Seq<>(start, second, third, fourth, fifth))))

                ), resultsIn(mClient,
                new Assert<>(task,
                        new Composite<>(
                                new TimeData<>(start, due),
                                new CharSequenceRowData<>(Tasks.RDATE,
                                        "20180104T123456Z," +
                                                "20180105T123456Z," +
                                                "20180106T123456Z," +
                                                "20180107T123456Z," +
                                                "20180108T123456Z"
                                ))),
//                new Counted<>(5, new AssertRelated<>(instancesTable, Instances.TASK_ID, task)),
                new Counted<>(1, new AssertRelated<>(instancesTable, Instances.TASK_ID, task)),
                // 1st instance:
                new AssertRelated<>(instancesTable, Instances.TASK_ID, task,
                        new InstanceTestData(localStart, localDue, new Present<>(start), 0),
                        new EqArg<>(Instances.INSTANCE_ORIGINAL_TIME, start.getTimestamp()))/*,
                // 2nd instance:
                new AssertRelated<>(instancesTable, Instances.TASK_ID, task,
                        new InstanceTestData(second, second.addDuration(hour), new Present<>(second), 1),
                        new EqArg<>(Instances.INSTANCE_ORIGINAL_TIME, second.getTimestamp())),
                // 3rd instance:
                new AssertRelated<>(instancesTable, Instances.TASK_ID, task,
                        new InstanceTestData(third, third.addDuration(hour), new Present<>(third), 2),
                        new EqArg<>(Instances.INSTANCE_ORIGINAL_TIME, third.getTimestamp())),
                // 4th instance:
                new AssertRelated<>(instancesTable, Instances.TASK_ID, task,
                        new InstanceTestData(fourth, fourth.addDuration(hour), new Present<>(fourth), 3),
                        new EqArg<>(Instances.INSTANCE_ORIGINAL_TIME, fourth.getTimestamp())),
                // 5th instance:
                new AssertRelated<>(instancesTable, Instances.TASK_ID, task,
                        new InstanceTestData(fifth, fifth.addDuration(hour), new Present<>(fifth), 4),
                        new EqArg<>(Instances.INSTANCE_ORIGINAL_TIME, fifth.getTimestamp()))*/)
        );
    }
 
Example 12
Source File: TaskInstancesProcessor.java    From opentasks-provider with Apache License 2.0 4 votes vote down vote up
/**
 * Create new {@link ContentValues} for insertion into the instances table.
 * 
 * @param task
 *            The {@link TaskAdapter} of the task that's about to be inserted.
 * @return {@link ContentValues} of the instance of this task.
 */
private ContentValues generateInstanceValues(TaskAdapter task)
{
	ContentValues instanceValues = new ContentValues();

	// get the relevant values from values
	DateTime dtstart = task.valueOf(TaskAdapter.DTSTART);
	DateTime due = task.valueOf(TaskAdapter.DUE);
	Duration duration = task.valueOf(TaskAdapter.DURATION);

	TimeZone localTz = TimeZone.getDefault();

	if (dtstart != null)
	{
		// copy dtstart as is
		instanceValues.put(Instances.INSTANCE_START, dtstart.getTimestamp());
		instanceValues.put(Instances.INSTANCE_START_SORTING, dtstart.isAllDay() ? dtstart.getInstance() : dtstart.shiftTimeZone(localTz).getInstance());
	}
	else
	{
		instanceValues.putNull(Instances.INSTANCE_START);
		instanceValues.putNull(Instances.INSTANCE_START_SORTING);
	}

	if (due != null)
	{
		// copy due and calculate the actual duration, if any
		instanceValues.put(Instances.INSTANCE_DUE, due.getTimestamp());
		instanceValues.put(Instances.INSTANCE_DUE_SORTING, due.isAllDay() ? due.getInstance() : due.shiftTimeZone(localTz).getInstance());
		if (dtstart != null)
		{
			instanceValues.put(Instances.INSTANCE_DURATION, due.getTimestamp() - dtstart.getTimestamp());
		}
		else
		{
			instanceValues.putNull(Instances.INSTANCE_DURATION);
		}
	}
	else if (duration != null)
	{
		if (dtstart != null)
		{
			// calculate the actual due value from dtstart and the duration string
			due = dtstart.addDuration(duration);
			instanceValues.put(Instances.INSTANCE_DUE, due.getTimestamp());
			instanceValues.put(Instances.INSTANCE_DUE_SORTING, due.isAllDay() ? due.getInstance() : due.shiftTimeZone(localTz).getInstance());
			instanceValues.put(Instances.INSTANCE_DURATION, due.getTimestamp() - dtstart.getTimestamp());
		}
		else
		{
			// this case should be filtered by TaskValidatorProcessor, since setting a DURATION without DTSTART is invalid
			instanceValues.putNull(Instances.INSTANCE_DURATION);
			instanceValues.putNull(Instances.INSTANCE_DUE);
			instanceValues.putNull(Instances.INSTANCE_DUE_SORTING);
		}
	}
	else
	{
		instanceValues.putNull(Instances.INSTANCE_DURATION);
		instanceValues.putNull(Instances.INSTANCE_DUE);
		instanceValues.putNull(Instances.INSTANCE_DUE_SORTING);
	}
	return instanceValues;
}
 
Example 13
Source File: TaskProviderRecurrenceTest.java    From opentasks with Apache License 2.0 4 votes vote down vote up
/**
     * Test if instances of a task with a DTSTART and RDATEs, complete first via instances table.
     */
    @Test
    public void testRDateFirstCompleteViaInstances() throws InvalidRecurrenceRuleException
    {
        RowSnapshot<TaskLists> taskList = new VirtualRowSnapshot<>(new LocalTaskListsTable(mAuthority));
        Table<Tasks> tasksTable = new TasksTable(mAuthority);
        Table<Instances> instancesTable = new InstanceTable(mAuthority);
        RowSnapshot<Tasks> task = new VirtualRowSnapshot<>(new TaskListScoped(taskList, tasksTable));

        Duration hour = new Duration(1, 0, 3600 /* 1 hour */);
        DateTime start = DateTime.parse("20180104T123456Z");
        DateTime due = start.addDuration(hour);

        Duration day = new Duration(1, 1, 0);

        DateTime localStart = start.shiftTimeZone(TimeZone.getDefault());
        DateTime localDue = due.shiftTimeZone(TimeZone.getDefault());

        DateTime second = localStart.addDuration(day);
        DateTime third = second.addDuration(day);
        DateTime fourth = third.addDuration(day);
        DateTime fifth = fourth.addDuration(day);

        assertThat(new Seq<>(
                        new Put<>(taskList, new EmptyRowData<>()),
                        // first insert the task
                        new Put<>(task,
                                new Composite<>(
                                        new TimeData<>(start, due),
                                        new RDatesTaskData(start, second, third, fourth, fifth))),
                        // then complete the first instance
                        new BulkUpdate<>(instancesTable, new CharSequenceRowData<>(Tasks.STATUS, String.valueOf(Tasks.STATUS_COMPLETED)),
                                new AllOf<>(
                                        new ReferringTo<>(Instances.TASK_ID, task),
                                        new EqArg<>(Instances.INSTANCE_ORIGINAL_TIME, start.getTimestamp())))),
                resultsIn(mClient,
                        // we've already closed the first instance which has been detached, the master now points to the second instance
                        new Counted<>(1,
                                new Assert<>(task,
                                        new Composite<>(
                                                new TimeData<>(DateTime.parse("20180105T123456Z"), DateTime.parse("20180105T133456Z")),
                                                new RDatesTaskData(
                                                        // "20180104T123456Z"  // the detached instance
                                                        DateTime.parse("20180105T123456Z"),
                                                        DateTime.parse("20180106T123456Z"),
                                                        DateTime.parse("20180107T123456Z"),
                                                        DateTime.parse("20180108T123456Z"))))),
                        // there must be one task which is not equal to the original task, it's the detached instance
                        new Counted<>(1,
                                new BulkAssert<>(tasksTable,
                                        new Composite<>(
                                                new TimeData<>(start, due),
                                                new StatusData<>(Tasks.STATUS_COMPLETED),
                                                new CharSequenceRowData<>(Tasks.ORIGINAL_INSTANCE_ID, null),
                                                new CharSequenceRowData<>(Tasks.ORIGINAL_INSTANCE_SYNC_ID, null),
                                                new CharSequenceRowData<>(Tasks.ORIGINAL_INSTANCE_TIME, null)),
                                        new Not<>(new ReferringTo<>(Tasks._ID, task)))),
                        // and one instance which doesn't refer to the original task
                        new Counted<>(1, new BulkAssert<>(instancesTable, new Not<>(new ReferringTo<>(Instances.TASK_ID, task)))),
                        // but 4 instances of that original task
//                new Counted<>(4, new AssertRelated<>(instancesTable, Instances.TASK_ID, task)),
                        new Counted<>(1, new AssertRelated<>(instancesTable, Instances.TASK_ID, task)),
                        // 1st instance, detached and completed
                        new Counted<>(1, new BulkAssert<>(instancesTable,
                                new Composite<>(
                                        new InstanceTestData(localStart, localDue, absent(), -1)),
                                new AllOf<>(
                                        new IsNull<>(Instances.INSTANCE_ORIGINAL_TIME),  // the detached instance has no INSTANCE_ORIGINAL_TIME
                                        new Not<>(new ReferringTo<>(Instances.TASK_ID, task))))),
                        // 2nd instance:
                        new Counted<>(1,
                                new AssertRelated<>(instancesTable, Instances.TASK_ID, task,
                                        new InstanceTestData(second, second.addDuration(hour), new Present<>(second), 0),
                                        new EqArg<>(Instances.INSTANCE_ORIGINAL_TIME, second.getTimestamp())))/*,
                // 3rd instance:
                new AssertRelated<>(instancesTable, Instances.TASK_ID, task,
                        new InstanceTestData(third, third.addDuration(hour), new Present<>(third), 1),
                        new EqArg<>(Instances.INSTANCE_ORIGINAL_TIME, third.getTimestamp())),
                // 4th instance:
                new AssertRelated<>(instancesTable, Instances.TASK_ID, task,
                        new InstanceTestData(fourth, fourth.addDuration(hour), new Present<>(fourth), 2),
                        new EqArg<>(Instances.INSTANCE_ORIGINAL_TIME, fourth.getTimestamp())),
                // 5th instance:
                new AssertRelated<>(instancesTable, Instances.TASK_ID, task,
                        new InstanceTestData(fifth, fifth.addDuration(hour), new Present<>(fifth), 3),
                        new EqArg<>(Instances.INSTANCE_ORIGINAL_TIME, fifth.getTimestamp()))*/)
        );
    }
 
Example 14
Source File: TaskProviderDetachInstancesTest.java    From opentasks with Apache License 2.0 4 votes vote down vote up
/**
 * Test if two all-day instances of a task with a DTSTART, DUE, RRULE, RDATE and EXDATE are detached correctly.
 */
@Test
public void testRRuleRDateCompleteWithExdatesAllDay() throws InvalidRecurrenceRuleException, RemoteException, OperationApplicationException
{
    RowSnapshot<TaskLists> taskList = new VirtualRowSnapshot<>(new Synced<>(mTestAccount, new TaskListsTable(mAuthority)));
    Table<Instances> instancesTable = new InstanceTable(mAuthority);
    RowSnapshot<Tasks> task = new VirtualRowSnapshot<>(new TaskListScoped(taskList, new TasksTable(mAuthority)));

    Duration hour = new Duration(1, 1, 0);
    DateTime start = DateTime.parse("20180104");
    DateTime due = start.addDuration(hour);

    Duration day = new Duration(1, 1, 0);

    OperationsQueue queue = new BasicOperationsQueue(mClient);
    queue.enqueue(new Seq<>(
            new Put<>(taskList, new EmptyRowData<>()),
            new Put<>(task,
                    new Composite<>(
                            new TitleData("Test-Task"),
                            new TimeData<>(start, due),
                            new RRuleTaskData(new RecurrenceRule("FREQ=DAILY;INTERVAL=2;COUNT=2", RecurrenceRule.RfcMode.RFC2445_LAX)),
                            new RDatesTaskData(
                                    new Seq<>(
                                            DateTime.parse("20180105"),
                                            DateTime.parse("20180107"))),
                            new ExDatesTaskData(
                                    new Seq<>(
                                            DateTime.parse("20180104"),
                                            DateTime.parse("20180105"))))),
            // update the first non-closed instance
            new BulkUpdate<>(instancesTable, new StatusData<>(Tasks.STATUS_COMPLETED),
                    new AllOf<>(new ReferringTo<>(Instances.TASK_ID, task),
                            new EqArg<>(Instances.DISTANCE_FROM_CURRENT, 0)))
    ));
    queue.flush();

    Synced<Tasks> tasksTable = new Synced<>(mTestAccount, new TasksTable(mAuthority));
    Synced<Instances> syncedInstances = new Synced<>(mTestAccount, instancesTable);
    assertThat(new Seq<>(
                    // update the second instance
                    new BulkUpdate<>(instancesTable, new StatusData<>(Tasks.STATUS_COMPLETED),
                            new AllOf<>(new ReferringTo<>(Instances.TASK_ID, task),
                                    new EqArg<>(Instances.DISTANCE_FROM_CURRENT, 0)))
            ),
            resultsIn(queue,
                    /*
                     * We expect five tasks:
                     * - the original master deleted
                     * - completed and deleted overrides for the first and second instance
                     * - detached first and second instances
                     */

                    // the first detached task instance:
                    new Counted<>(1, new BulkAssert<>(syncedInstances,
                            new Composite<>(
                                    new InstanceTestData(DateTime.parse("20180106"), DateTime.parse("20180107"), absent(), -1),
                                    new CharSequenceRowData<>(Tasks.STATUS, String.valueOf(Tasks.STATUS_COMPLETED))),
                            new AllOf<>(
                                    new EqArg<>(Instances.INSTANCE_START, DateTime.parse("20180106").getTimestamp()),
                                    new Not<>(new ReferringTo<>(Instances.TASK_ID, task))))),
                    // the original master has been deleted
                    new Counted<>(0, new Assert<>(task, new Composite<>(new EmptyRowData<>()))),
                    // there is no instance referring to the master
                    new Counted<>(0, new AssertRelated<>(instancesTable, Instances.TASK_ID, task)),
                    // the second detached task instance:
                    new Counted<>(1, new BulkAssert<>(syncedInstances,
                            new Composite<>(
                                    new InstanceTestData(DateTime.parse("20180107"), DateTime.parse("20180108"), absent(), -1),
                                    new CharSequenceRowData<>(Tasks.STATUS, String.valueOf(Tasks.STATUS_COMPLETED))),
                            new AllOf<>(
                                    new EqArg<>(Instances.INSTANCE_START, DateTime.parse("20180107").getTimestamp()),
                                    new Not<>(new ReferringTo<>(Instances.TASK_ID, task))))),
                    // two completed instances, neither of them referring to the master
                    new Counted<>(2,
                            new BulkAssert<>(
                                    syncedInstances,
                                    new CharSequenceRowData<>(Tasks.STATUS, String.valueOf(Tasks.STATUS_COMPLETED)),
                                    new AllOf<>(
                                            new EqArg<>(Instances.DISTANCE_FROM_CURRENT, -1),
                                            new Not<>(new ReferringTo<>(Instances.TASK_ID, task))))),
                    // five tasks in total (two deleted overrides, two detached ones and the old master)
                    new Counted<>(5,
                            new BulkAssert<>(
                                    tasksTable,
                                    new TitleData("Test-Task"),
                                    new AnyOf<>())),
                    // three deleted tasks in total (the old overrides and the old master)
                    new Counted<>(3,
                            new BulkAssert<>(
                                    tasksTable,
                                    new TitleData("Test-Task"),
                                    new EqArg<>(Tasks._DELETED, 1)))));
}
 
Example 15
Source File: TaskProviderRecurrenceTest.java    From opentasks with Apache License 2.0 4 votes vote down vote up
/**
 * Remove an instance from a task with an RRULE.
 */
@Ignore("Test tries to delete 3rd instance which has not been created because currently only 1 instance is expanded")
@Test
public void testRRuleRemoveInstance() throws InvalidRecurrenceRuleException
{
    RowSnapshot<TaskLists> taskList = new VirtualRowSnapshot<>(new LocalTaskListsTable(mAuthority));
    Table<Instances> instancesTable = new InstanceTable(mAuthority);
    RowSnapshot<Tasks> task = new VirtualRowSnapshot<>(new TaskListScoped(taskList, new TasksTable(mAuthority)));

    Duration hour = new Duration(1, 0, 3600 /* 1 hour */);
    DateTime start = DateTime.parse("20180104T123456Z");
    DateTime due = start.addDuration(hour);

    Duration day = new Duration(1, 1, 0);

    DateTime localStart = start.shiftTimeZone(TimeZone.getDefault());
    DateTime localDue = due.shiftTimeZone(TimeZone.getDefault());

    DateTime second = localStart.addDuration(day);
    DateTime third = second.addDuration(day);
    DateTime fourth = third.addDuration(day);
    DateTime fifth = fourth.addDuration(day);

    assertThat(new Seq<>(
                    new Put<>(taskList, new EmptyRowData<>()),
                    new Put<>(task,
                            new Composite<>(
                                    new TimeData<>(start, due),
                                    new RRuleTaskData(new RecurrenceRule("FREQ=DAILY;COUNT=5", RecurrenceRule.RfcMode.RFC2445_LAX)))),
                    // remove the third instance
                    new BulkDelete<>(instancesTable,
                            new AllOf<>(new ReferringTo<>(Instances.TASK_ID, task), new EqArg<>(Instances.INSTANCE_ORIGINAL_TIME, third.getTimestamp())))

            ), resultsIn(mClient,
            new Assert<>(task,
                    new Composite<>(
                            new TimeData<>(start, due),
                            new CharSequenceRowData<>(Tasks.RRULE, "FREQ=DAILY;COUNT=5"),
                            new CharSequenceRowData<>(Tasks.EXDATE, "20180106T123456Z"))),
            new Counted<>(4, new AssertRelated<>(instancesTable, Instances.TASK_ID, task)),
            // 1st instance:
            new AssertRelated<>(instancesTable, Instances.TASK_ID, task,
                    new InstanceTestData(localStart, localDue, new Present<>(start), 0),
                    new EqArg<>(Instances.INSTANCE_ORIGINAL_TIME, start.getTimestamp())),
            // 2nd instance:
            new AssertRelated<>(instancesTable, Instances.TASK_ID, task,
                    new InstanceTestData(second, second.addDuration(hour), new Present<>(second), 1),
                    new EqArg<>(Instances.INSTANCE_ORIGINAL_TIME, second.getTimestamp())),
            // 4th instance (now 3rd):
            new AssertRelated<>(instancesTable, Instances.TASK_ID, task,
                    new InstanceTestData(fourth, fourth.addDuration(hour), new Present<>(fourth), 2),
                    new EqArg<>(Instances.INSTANCE_ORIGINAL_TIME, fourth.getTimestamp())),
            // 5th instance (now 4th):
            new AssertRelated<>(instancesTable, Instances.TASK_ID, task,
                    new InstanceTestData(fifth, fifth.addDuration(hour), new Present<>(fifth), 3),
                    new EqArg<>(Instances.INSTANCE_ORIGINAL_TIME, fifth.getTimestamp())))
    );
}
 
Example 16
Source File: TaskProviderRecurrenceTest.java    From opentasks with Apache License 2.0 4 votes vote down vote up
/**
     * Test if instances of a task with a DTSTART and an RRULE but no DUE
     */
    @Test
    public void testRRuleNoDue() throws InvalidRecurrenceRuleException
    {
        RowSnapshot<TaskLists> taskList = new VirtualRowSnapshot<>(new LocalTaskListsTable(mAuthority));
        Table<Instances> instancesTable = new InstanceTable(mAuthority);
        RowSnapshot<Tasks> task = new VirtualRowSnapshot<>(new TaskListScoped(taskList, new TasksTable(mAuthority)));

        DateTime start = DateTime.parse("20180104T123456Z");

        Duration day = new Duration(1, 1, 0);

        DateTime localStart = start.shiftTimeZone(TimeZone.getDefault());

        DateTime second = localStart.addDuration(day);
        DateTime third = second.addDuration(day);
        DateTime fourth = third.addDuration(day);
        DateTime fifth = fourth.addDuration(day);

        assertThat(new Seq<>(
                        new Put<>(taskList, new EmptyRowData<>()),
                        new Put<>(task,
                                new Composite<>(
                                        new TimeData<>(start),
                                        new RRuleTaskData(new RecurrenceRule("FREQ=DAILY;COUNT=5", RecurrenceRule.RfcMode.RFC2445_LAX))))

                ), resultsIn(mClient,
                new Assert<>(task,
                        new Composite<>(
                                new TimeData<>(start),
                                new CharSequenceRowData<>(Tasks.RRULE, "FREQ=DAILY;COUNT=5"))),
//                new Counted<>(5, new AssertRelated<>(instancesTable, Instances.TASK_ID, task)),
                new Counted<>(1, new AssertRelated<>(instancesTable, Instances.TASK_ID, task)),
                // 1st instance:
                new AssertRelated<>(instancesTable, Instances.TASK_ID, task,
                        new InstanceTestData(new Present<>(localStart), absent(), new Present<>(start), 0),
                        new EqArg<>(Instances.INSTANCE_ORIGINAL_TIME, start.getTimestamp()))/*,
                // 2nd instance:
                new AssertRelated<>(instancesTable, Instances.TASK_ID, task,
                        new InstanceTestData(new Present<>(second), absent(), new Present<>(second), 1),
                        new EqArg<>(Instances.INSTANCE_ORIGINAL_TIME, second.getTimestamp())),
                // 3rd instance:
                new AssertRelated<>(instancesTable, Instances.TASK_ID, task,
                        new InstanceTestData(new Present<>(third), absent(), new Present<>(third), 2),
                        new EqArg<>(Instances.INSTANCE_ORIGINAL_TIME, third.getTimestamp())),
                // 4th instance:
                new AssertRelated<>(instancesTable, Instances.TASK_ID, task,
                        new InstanceTestData(new Present<>(fourth), absent(), new Present<>(fourth), 3),
                        new EqArg<>(Instances.INSTANCE_ORIGINAL_TIME, fourth.getTimestamp())),
                // 5th instance:
                new AssertRelated<>(instancesTable, Instances.TASK_ID, task,
                        new InstanceTestData(new Present<>(fifth), absent(), new Present<>(fifth), 4),
                        new EqArg<>(Instances.INSTANCE_ORIGINAL_TIME, fifth.getTimestamp()))*/)
        );
    }
 
Example 17
Source File: TaskProviderDetachInstancesTest.java    From opentasks with Apache License 2.0 4 votes vote down vote up
/**
 * Test if two instances of a task with a DTSTART, DUE and an RRULE are detached correctly.
 */
@Test
public void testRRuleCompleteAll() throws InvalidRecurrenceRuleException, RemoteException, OperationApplicationException
{
    RowSnapshot<TaskLists> taskList = new VirtualRowSnapshot<>(new Synced<>(mTestAccount, new TaskListsTable(mAuthority)));
    Table<Instances> instancesTable = new InstanceTable(mAuthority);
    RowSnapshot<Tasks> task = new VirtualRowSnapshot<>(new TaskListScoped(taskList, new TasksTable(mAuthority)));

    Duration hour = new Duration(1, 0, 3600 /* 1 hour */);
    DateTime start = DateTime.parse("20180104T123456Z");
    DateTime due = start.addDuration(hour);
    DateTime localStart = start.shiftTimeZone(TimeZone.getDefault());

    Duration day = new Duration(1, 1, 0);

    DateTime second = localStart.addDuration(day);
    DateTime third = second.addDuration(day);
    DateTime fourth = third.addDuration(day);
    DateTime fifth = fourth.addDuration(day);

    DateTime localDue = due.shiftTimeZone(TimeZone.getDefault());

    OperationsQueue queue = new BasicOperationsQueue(mClient);
    queue.enqueue(new Seq<>(
            new Put<>(taskList, new EmptyRowData<>()),
            new Put<>(task,
                    new Composite<>(
                            new TitleData("Test-Task"),
                            new TimeData<>(start, due),
                            new RRuleTaskData(new RecurrenceRule("FREQ=DAILY;COUNT=2", RecurrenceRule.RfcMode.RFC2445_LAX)))),
            // complete the first non-closed instance
            new BulkUpdate<>(instancesTable, new StatusData<>(Tasks.STATUS_COMPLETED),
                    new AllOf<>(new ReferringTo<>(Instances.TASK_ID, task),
                            new EqArg<>(Instances.DISTANCE_FROM_CURRENT, 0)))
    ));
    queue.flush();

    Synced<Tasks> tasksTable = new Synced<>(mTestAccount, new TasksTable(mAuthority));
    Synced<Instances> syncedInstances = new Synced<>(mTestAccount, instancesTable);
    assertThat(new Seq<>(
                    // update the second instance
                    new BulkUpdate<>(instancesTable, new StatusData<>(Tasks.STATUS_COMPLETED),
                            new AllOf<>(new ReferringTo<>(Instances.TASK_ID, task),
                                    new EqArg<>(Instances.DISTANCE_FROM_CURRENT, 0)))
            ),
            resultsIn(queue,
                    /*
                     * We expect five tasks:
                     * - the original master with updated RRULE, DTSTART and DUE, deleted
                     * - a completed and deleted overrides for the first and second instance
                     * - a detached first and second instance
                     */

                    // the original master
                    new Assert<>(task,
                            new Composite<>(
                                    // points to former second instance before being deleted
                                    new TimeData<>(start.addDuration(day), due.addDuration(day)),
                                    new CharSequenceRowData<>(Tasks.RRULE, "FREQ=DAILY;COUNT=1"),
                                    new CharSequenceRowData<>(Tasks._DELETED, "1"))),
                    // there is no instance referring to the master because it has been fully completed (and deleted)
                    new Counted<>(0, new AssertRelated<>(instancesTable, Instances.TASK_ID, task)),
                    // the first detached task instance:
                    new Counted<>(1, new BulkAssert<>(syncedInstances,
                            new Composite<>(
                                    new InstanceTestData(localStart, localDue, absent(), -1),
                                    new CharSequenceRowData<>(Tasks.STATUS, String.valueOf(Tasks.STATUS_COMPLETED))),
                            new AllOf<>(
                                    new EqArg<>(Instances.INSTANCE_START, start.getTimestamp()),
                                    new Not<>(new ReferringTo<>(Instances.TASK_ID, task))))),
                    // the second detached task instance:
                    new Counted<>(1, new BulkAssert<>(syncedInstances,
                            new Composite<>(
                                    new InstanceTestData(second, second.addDuration(new Duration(1, 0, 3600)), absent(), -1),
                                    new CharSequenceRowData<>(Tasks.STATUS, String.valueOf(Tasks.STATUS_COMPLETED))),
                            new AllOf<>(
                                    new EqArg<>(Instances.INSTANCE_START, second.getTimestamp()),
                                    new Not<>(new ReferringTo<>(Instances.TASK_ID, task))))),
                    // two instances total, both completed
                    new Counted<>(2,
                            new BulkAssert<>(
                                    syncedInstances,
                                    new CharSequenceRowData<>(Tasks.STATUS, String.valueOf(Tasks.STATUS_COMPLETED)),
                                    new AnyOf<>())),
                    // five tasks in total
                    new Counted<>(5,
                            new BulkAssert<>(
                                    tasksTable,
                                    new TitleData("Test-Task"),
                                    new AnyOf<>())),
                    // three deleted tasks in total
                    new Counted<>(3,
                            new BulkAssert<>(
                                    tasksTable,
                                    new TitleData("Test-Task"),
                                    new EqArg<>(Tasks._DELETED, 1)))));
}
 
Example 18
Source File: TaskProviderRecurrenceTest.java    From opentasks with Apache License 2.0 4 votes vote down vote up
/**
     * Test if instances of a task with an all-day DTSTART, DUE and an RRULE.
     */
    @Test
    public void testAllDayRRule() throws InvalidRecurrenceRuleException
    {
        RowSnapshot<TaskLists> taskList = new VirtualRowSnapshot<>(new LocalTaskListsTable(mAuthority));
        Table<Instances> instancesTable = new InstanceTable(mAuthority);
        RowSnapshot<Tasks> task = new VirtualRowSnapshot<>(new TaskListScoped(taskList, new TasksTable(mAuthority)));

        Duration days = new Duration(1, 2, 0);
        DateTime start = DateTime.parse("20180104");
        DateTime due = start.addDuration(days);
        DateTime localStart = start;

        Duration day = new Duration(1, 1, 0);

        DateTime second = localStart.addDuration(day);
        DateTime third = second.addDuration(day);
        DateTime fourth = third.addDuration(day);
        DateTime fifth = fourth.addDuration(day);

        DateTime localDue = due;

        assertThat(new Seq<>(
                        new Put<>(taskList, new EmptyRowData<>()),
                        new Put<>(task,
                                new Composite<>(
                                        new TimeData<>(start, due),
                                        new RRuleTaskData(new RecurrenceRule("FREQ=DAILY;COUNT=5", RecurrenceRule.RfcMode.RFC2445_LAX))))

                ), resultsIn(mClient,
                new Assert<>(task,
                        new Composite<>(
                                new TimeData<>(start, due),
                                new CharSequenceRowData<>(Tasks.RRULE, "FREQ=DAILY;COUNT=5"))),
//                new Counted<>(5, new AssertRelated<>(instancesTable, Instances.TASK_ID, task)),
                new Counted<>(1, new AssertRelated<>(instancesTable, Instances.TASK_ID, task)),
                // 1st instance:
                new AssertRelated<>(instancesTable, Instances.TASK_ID, task,
                        new InstanceTestData(localStart, localDue, new Present<>(start), 0),
                        new EqArg<>(Instances.INSTANCE_ORIGINAL_TIME, start.getTimestamp()))/*,
                // 2nd instance:
                new AssertRelated<>(instancesTable, Instances.TASK_ID, task,
                        new InstanceTestData(second, second.addDuration(hour), new Present<>(second), 1),
                        new EqArg<>(Instances.INSTANCE_ORIGINAL_TIME, second.getTimestamp())),
                // 3rd instance:
                new AssertRelated<>(instancesTable, Instances.TASK_ID, task,
                        new InstanceTestData(third, third.addDuration(hour), new Present<>(third), 2),
                        new EqArg<>(Instances.INSTANCE_ORIGINAL_TIME, third.getTimestamp())),
                // 4th instance:
                new AssertRelated<>(instancesTable, Instances.TASK_ID, task,
                        new InstanceTestData(fourth, fourth.addDuration(hour), new Present<>(fourth), 3),
                        new EqArg<>(Instances.INSTANCE_ORIGINAL_TIME, fourth.getTimestamp())),
                // 5th instance:
                new AssertRelated<>(instancesTable, Instances.TASK_ID, task,
                        new InstanceTestData(fifth, fifth.addDuration(hour), new Present<>(fifth), 4),
                        new EqArg<>(Instances.INSTANCE_ORIGINAL_TIME, fifth.getTimestamp())) */)
        );
    }
 
Example 19
Source File: TaskProviderRecurrenceTest.java    From opentasks with Apache License 2.0 4 votes vote down vote up
/**
     * Test if instances of a task with a timed DTSTART, DUE and a floating RRULE UNTIL.
     * <p>
     * Note, this combination should not be accepted by the provider. For the time being, however, it should be tolerated instead of causing a crash.
     */
    @Test
    public void testRRuleWithFloatingMismatch() throws InvalidRecurrenceRuleException
    {
        RowSnapshot<TaskLists> taskList = new VirtualRowSnapshot<>(new LocalTaskListsTable(mAuthority));
        Table<Instances> instancesTable = new InstanceTable(mAuthority);
        RowSnapshot<Tasks> task = new VirtualRowSnapshot<>(new TaskListScoped(taskList, new TasksTable(mAuthority)));

        Duration hour = new Duration(1, 0, 3600 /* 1 hour */);
        DateTime start = DateTime.parse("20180104T123456Z");
        DateTime due = start.addDuration(hour);
        DateTime localStart = start.shiftTimeZone(TimeZone.getDefault());

        Duration day = new Duration(1, 1, 0);

        DateTime second = localStart.addDuration(day);
        DateTime third = second.addDuration(day);
        DateTime fourth = third.addDuration(day);
        DateTime fifth = fourth.addDuration(day);

        DateTime localDue = due.shiftTimeZone(TimeZone.getDefault());

        assertThat(new Seq<>(
                        new Put<>(taskList, new EmptyRowData<>()),
                        new Put<>(task,
                                new Composite<>(
                                        new TimeData<>(start, due),
                                        new RRuleTaskData(new RecurrenceRule("FREQ=DAILY;UNTIL=20180106", RecurrenceRule.RfcMode.RFC2445_LAX))))

                ), resultsIn(mClient,
                new Assert<>(task,
                        new Composite<>(
                                new TimeData<>(start, due),
                                new CharSequenceRowData<>(Tasks.RRULE, "FREQ=DAILY;UNTIL=20180106"))),
//                new Counted<>(5, new AssertRelated<>(instancesTable, Instances.TASK_ID, task)),
                new Counted<>(1, new AssertRelated<>(instancesTable, Instances.TASK_ID, task)),
                // 1st instance:
                new AssertRelated<>(instancesTable, Instances.TASK_ID, task,
                        new InstanceTestData(localStart, localDue, new Present<>(start), 0),
                        new EqArg<>(Instances.INSTANCE_ORIGINAL_TIME, start.getTimestamp()))/*,
                // 2nd instance:
                new AssertRelated<>(instancesTable, Instances.TASK_ID, task,
                        new InstanceTestData(second, second.addDuration(hour), new Present<>(second), 1),
                        new EqArg<>(Instances.INSTANCE_ORIGINAL_TIME, second.getTimestamp())),
                // 3rd instance:
                new AssertRelated<>(instancesTable, Instances.TASK_ID, task,
                        new InstanceTestData(third, third.addDuration(hour), new Present<>(third), 2),
                        new EqArg<>(Instances.INSTANCE_ORIGINAL_TIME, third.getTimestamp())),
                // 4th instance:
                new AssertRelated<>(instancesTable, Instances.TASK_ID, task,
                        new InstanceTestData(fourth, fourth.addDuration(hour), new Present<>(fourth), 3),
                        new EqArg<>(Instances.INSTANCE_ORIGINAL_TIME, fourth.getTimestamp())),
                // 5th instance:
                new AssertRelated<>(instancesTable, Instances.TASK_ID, task,
                        new InstanceTestData(fifth, fifth.addDuration(hour), new Present<>(fifth), 4),
                        new EqArg<>(Instances.INSTANCE_ORIGINAL_TIME, fifth.getTimestamp())) */)
        );
    }
 
Example 20
Source File: TaskProviderRecurrenceTest.java    From opentasks with Apache License 2.0 4 votes vote down vote up
/**
     * Test if instances of a task with a DTSTART and RDATEs, complete first inserted first.
     */
    @Test
    public void testRDateFirstCompleteFirstInserted() throws InvalidRecurrenceRuleException
    {
        RowSnapshot<TaskLists> taskList = new VirtualRowSnapshot<>(new LocalTaskListsTable(mAuthority));
        Table<Instances> instancesTable = new InstanceTable(mAuthority);
        RowSnapshot<Tasks> task = new VirtualRowSnapshot<>(new TaskListScoped(taskList, new TasksTable(mAuthority)));
        RowSnapshot<Tasks> override = new VirtualRowSnapshot<>(new TaskListScoped(taskList, new TasksTable(mAuthority)));

        Duration hour = new Duration(1, 0, 3600 /* 1 hour */);
        DateTime start = DateTime.parse("20180104T123456Z");
        DateTime due = start.addDuration(hour);

        Duration day = new Duration(1, 1, 0);

        DateTime localStart = start.shiftTimeZone(TimeZone.getDefault());
        DateTime localDue = due.shiftTimeZone(TimeZone.getDefault());

        DateTime second = localStart.addDuration(day);
        DateTime third = second.addDuration(day);
        DateTime fourth = third.addDuration(day);
        DateTime fifth = fourth.addDuration(day);

        assertThat(new Seq<>(
                        new Put<>(taskList, new EmptyRowData<>()),
                        // first insert override
                        new Put<>(override,
                                new Composite<>(
                                        new TimeData<>(start, due),
                                        new OriginalInstanceSyncIdData("xyz", start),
                                        new StatusData<>(Tasks.STATUS_COMPLETED))),
                        // then insert task
                        new Put<>(task,
                                new Composite<>(
                                        new SyncIdData("xyz"),
                                        new TimeData<>(start, due),
                                        new RDatesTaskData(new Seq<>(start, second, third, fourth, fifth))))

                ), resultsIn(mClient,
                new Assert<>(task,
                        new Composite<>(
                                new TimeData<>(start, due),
                                new SyncIdData("xyz"),
                                new CharSequenceRowData<>(Tasks.RDATE,
                                        "20180104T123456Z," +
                                                "20180105T123456Z," +
                                                "20180106T123456Z," +
                                                "20180107T123456Z," +
                                                "20180108T123456Z"
                                ))),
                new Assert<>(override,
                        new Composite<>(
                                new TimeData<>(start, due),
                                new OriginalInstanceSyncIdData("xyz", start),
                                new StatusData<>(Tasks.STATUS_COMPLETED))),
                new Counted<>(1, new AssertRelated<>(instancesTable, Instances.TASK_ID, override)),
//                new Counted<>(4, new AssertRelated<>(instancesTable, Instances.TASK_ID, task)),
                new Counted<>(1, new AssertRelated<>(instancesTable, Instances.TASK_ID, task)),
                // 1st instance, overridden and completed
                new AssertRelated<>(instancesTable, Instances.TASK_ID, override,
                        new InstanceTestData(localStart, localDue, new Present<>(start), -1),
                        new EqArg<>(Instances.INSTANCE_ORIGINAL_TIME, start.getTimestamp())),
                // 2nd instance:
                new AssertRelated<>(instancesTable, Instances.TASK_ID, task,
                        new InstanceTestData(second, second.addDuration(hour), new Present<>(second), 0),
                        new EqArg<>(Instances.INSTANCE_ORIGINAL_TIME, second.getTimestamp()))/*,
                // 3rd instance:
                new AssertRelated<>(instancesTable, Instances.TASK_ID, task,
                        new InstanceTestData(third, third.addDuration(hour), new Present<>(third), 1),
                        new EqArg<>(Instances.INSTANCE_ORIGINAL_TIME, third.getTimestamp())),
                // 4th instance:
                new AssertRelated<>(instancesTable, Instances.TASK_ID, task,
                        new InstanceTestData(fourth, fourth.addDuration(hour), new Present<>(fourth), 2),
                        new EqArg<>(Instances.INSTANCE_ORIGINAL_TIME, fourth.getTimestamp())),
                // 5th instance:
                new AssertRelated<>(instancesTable, Instances.TASK_ID, task,
                        new InstanceTestData(fifth, fifth.addDuration(hour), new Present<>(fifth), 3),
                        new EqArg<>(Instances.INSTANCE_ORIGINAL_TIME, fifth.getTimestamp()))*/)
        );
    }