Search in sources :

Example 6 with IntervalBase

use of nl.tudelft.watchdog.core.logic.interval.intervaltypes.IntervalBase in project watchdog by TestRoots.

the class IntervalJsonConverterTest method testJsonDebugIntervalRepresentation.

@Test
public void testJsonDebugIntervalRepresentation() {
    IntervalBase interval = new DebugInterval(new Date());
    ArrayList<WatchDogItem> intervals = createSampleIntervals(interval);
    assertEquals("[{\"it\":\"db\",\"ts\":1,\"te\":2,\"ss\":\"\"," + pasteWDVAndClient() + "}]", transferer.toJson(intervals));
}
Also used : IntervalBase(nl.tudelft.watchdog.core.logic.interval.intervaltypes.IntervalBase) EditorIntervalBase(nl.tudelft.watchdog.core.logic.interval.intervaltypes.EditorIntervalBase) DebugInterval(nl.tudelft.watchdog.core.logic.interval.intervaltypes.DebugInterval) Date(java.util.Date) WatchDogItem(nl.tudelft.watchdog.core.logic.storage.WatchDogItem) Test(org.junit.Test)

Example 7 with IntervalBase

use of nl.tudelft.watchdog.core.logic.interval.intervaltypes.IntervalBase in project watchdog by TestRoots.

the class IntervalJsonConverterTest method testJsonSessionIntervalRepresentation.

/**
 * Tests the format of the returned Json representation.
 */
@Test
public void testJsonSessionIntervalRepresentation() {
    IntervalBase interval = new IDEOpenInterval(new Date());
    ArrayList<WatchDogItem> intervals = createSampleIntervals(interval);
    assertEquals("[{\"it\":\"eo\",\"ts\":1,\"te\":2,\"ss\":\"\"," + pasteWDVAndClient() + "}]", transferer.toJson(intervals));
}
Also used : IntervalBase(nl.tudelft.watchdog.core.logic.interval.intervaltypes.IntervalBase) EditorIntervalBase(nl.tudelft.watchdog.core.logic.interval.intervaltypes.EditorIntervalBase) IDEOpenInterval(nl.tudelft.watchdog.core.logic.interval.intervaltypes.IDEOpenInterval) Date(java.util.Date) WatchDogItem(nl.tudelft.watchdog.core.logic.storage.WatchDogItem) Test(org.junit.Test)

Example 8 with IntervalBase

use of nl.tudelft.watchdog.core.logic.interval.intervaltypes.IntervalBase in project watchdog by TestRoots.

the class IntervalPersisterTest method createRandomInterval.

public static IntervalBase createRandomInterval() {
    IntervalBase interval = new IDEOpenInterval(new Date());
    interval.setSessionSeed("444");
    interval.setStartTime(new Date(interval.getStart().getTime() + (new Random()).nextInt(100000)));
    interval.setEndTime(new Date(interval.getStart().getTime() + (new Random()).nextInt(100000)));
    return interval;
}
Also used : Random(java.util.Random) IntervalBase(nl.tudelft.watchdog.core.logic.interval.intervaltypes.IntervalBase) IDEOpenInterval(nl.tudelft.watchdog.core.logic.interval.intervaltypes.IDEOpenInterval) Date(java.util.Date)

Example 9 with IntervalBase

use of nl.tudelft.watchdog.core.logic.interval.intervaltypes.IntervalBase in project watchdog by TestRoots.

the class IntervalPersisterTest method testInteraction.

private void testInteraction(int items) {
    List<IntervalBase> generatedIntervals = generateIntervalList(items);
    // Shuffle the generated intervals to test for
    // correct ordering of returned values
    Collections.shuffle(generatedIntervals);
    Collections.sort(generatedIntervals);
    for (IntervalBase intervalBase : generatedIntervals) {
        persister.save(intervalBase);
    }
    List<WatchDogItem> readIntervals = new ArrayList<WatchDogItem>(persister.readItems());
    assertEquals(readIntervals.size(), items);
    // Test order of returned results
    assertEquals(readIntervals, generatedIntervals);
}
Also used : IntervalBase(nl.tudelft.watchdog.core.logic.interval.intervaltypes.IntervalBase) ArrayList(java.util.ArrayList) WatchDogItem(nl.tudelft.watchdog.core.logic.storage.WatchDogItem)

Example 10 with IntervalBase

use of nl.tudelft.watchdog.core.logic.interval.intervaltypes.IntervalBase in project watchdog by TestRoots.

the class IntervalPersisterTestSingleInterval method test1WriteInterval.

@Test
public void test1WriteInterval() {
    interval = IntervalPersisterTest.createRandomInterval();
    interval.close();
    persister.save(interval);
    WatchDogItem savedItem = new ArrayList<>(persister.readItems()).get(0);
    assertTrue(savedItem instanceof IntervalBase);
    IntervalBase savedInterval = (IntervalBase) savedItem;
    assertEquals(interval.getType(), savedInterval.getType());
    assertEquals(interval.getStart(), savedInterval.getStart());
    assertEquals(interval.getEnd(), savedInterval.getEnd());
    assertEquals(interval.getDuration(), savedInterval.getDuration());
    assertEquals(interval.isClosed(), savedInterval.isClosed());
}
Also used : IntervalBase(nl.tudelft.watchdog.core.logic.interval.intervaltypes.IntervalBase) WatchDogItem(nl.tudelft.watchdog.core.logic.storage.WatchDogItem) Test(org.junit.Test)

Aggregations

IntervalBase (nl.tudelft.watchdog.core.logic.interval.intervaltypes.IntervalBase)12 WatchDogItem (nl.tudelft.watchdog.core.logic.storage.WatchDogItem)10 Test (org.junit.Test)7 EditorIntervalBase (nl.tudelft.watchdog.core.logic.interval.intervaltypes.EditorIntervalBase)6 Date (java.util.Date)5 IDEOpenInterval (nl.tudelft.watchdog.core.logic.interval.intervaltypes.IDEOpenInterval)4 ArrayList (java.util.ArrayList)3 Random (java.util.Random)1 DebugInterval (nl.tudelft.watchdog.core.logic.interval.intervaltypes.DebugInterval)1 JsonTransferer (nl.tudelft.watchdog.core.logic.network.JsonTransferer)1 ServerCommunicationException (nl.tudelft.watchdog.core.logic.network.ServerCommunicationException)1 ServerReturnCodeException (nl.tudelft.watchdog.core.logic.network.ServerReturnCodeException)1 DateTime (org.joda.time.DateTime)1 Ignore (org.junit.Ignore)1