Search in sources :

Example 1 with TimeInterval

use of org.opennms.core.utils.TimeInterval in project opennms by OpenNMS.

the class TimeIntervalSequenceTest method testPreceeds.

@Test
public void testPreceeds() throws Exception {
    TimeInterval first = new TimeInterval(new Date(0), date("18-08-2005 00:00:00"));
    TimeInterval second = aug(18);
    assertTrue(first.preceeds(second));
    assertFalse(second.preceeds(first));
}
Also used : TimeInterval(org.opennms.core.utils.TimeInterval) Date(java.util.Date) Test(org.junit.Test)

Example 2 with TimeInterval

use of org.opennms.core.utils.TimeInterval in project opennms by OpenNMS.

the class TimeIntervalSequenceTest method testAddOverlappingMany.

@Test
public void testAddOverlappingMany() throws Exception {
    // seg with three entryies 8-5 on aug 18, aug 19 and aug 20
    TimeIntervalSequence seq = new TimeIntervalSequence(aug(18, 8, 17));
    seq.addInterval(aug(19, 8, 17));
    seq.addInterval(aug(20, 8, 17));
    // now add interval from aug 18 0 to aug 20 24)
    seq.addInterval(aug(18, 0, 20, 24));
    // expect a sequence containing non overlapping segments
    TimeInterval[] expected = { aug(18, 0, 8), aug(18, 8, 17), aug(18, 17, 19, 8), aug(19, 8, 17), aug(19, 17, 20, 8), aug(20, 8, 17), aug(20, 17, 24) };
    assertTimeIntervalSequence(expected, seq);
}
Also used : TimeIntervalSequence(org.opennms.core.utils.TimeIntervalSequence) TimeInterval(org.opennms.core.utils.TimeInterval) Test(org.junit.Test)

Example 3 with TimeInterval

use of org.opennms.core.utils.TimeInterval in project opennms by OpenNMS.

the class TimeIntervalSequenceTest method testBound.

@Test
public void testBound() throws Exception {
    TimeIntervalSequence seq = new TimeIntervalSequence(aug(18, 8, 17));
    seq.addInterval(aug(19, 8, 17));
    seq.addInterval(aug(20, 8, 17));
    seq.addInterval(aug(21, 8, 17));
    seq.addInterval(aug(22, 8, 17));
    // bound the sequence to the interval aug19 noon to aug 21 noon
    seq.bound(aug(19, 12, 21, 12));
    // expect a sequence containing non overlapping segments
    TimeInterval[] expected = { aug(19, 12, 17), aug(20, 8, 17), aug(21, 8, 12) };
    assertTimeIntervalSequence(expected, seq);
}
Also used : TimeIntervalSequence(org.opennms.core.utils.TimeIntervalSequence) TimeInterval(org.opennms.core.utils.TimeInterval) Test(org.junit.Test)

Example 4 with TimeInterval

use of org.opennms.core.utils.TimeInterval in project opennms by OpenNMS.

the class BasicScheduleUtilsTest method testMonthlyInterval.

@Test
public void testMonthlyInterval() throws Exception {
    String schedSpec = "           <schedule name=\"simple\" type=\"specific\">" + "               <time day=\"18\" begins=\"13:00:00\" ends=\"14:00:00\"/>\n" + "           </schedule>";
    Schedule simpleSchedule = JaxbUtils.unmarshal(Schedule.class, schedSpec);
    BasicSchedule basicSchedule = BasicScheduleUtils.getGroupSchedule(simpleSchedule);
    Owner owner = new Owner("unnamed", "simple", 0, 0);
    TimeInterval interval = BasicScheduleUtils.getInterval(aug(18).getStart(), basicSchedule.getTime(0), owner);
    assertNotNull(interval);
    assertInterval(owned(owner, aug(18, 13, 14)), interval);
}
Also used : Owner(org.opennms.core.utils.Owner) TimeInterval(org.opennms.core.utils.TimeInterval) Schedule(org.opennms.netmgt.config.groups.Schedule) Test(org.junit.Test)

Example 5 with TimeInterval

use of org.opennms.core.utils.TimeInterval in project opennms by OpenNMS.

the class TimeIntervalSequenceTest method testFollows.

@Test
public void testFollows() throws Exception {
    TimeInterval first = new TimeInterval(new Date(0), date("18-08-2005 00:00:00"));
    TimeInterval second = aug(18);
    assertTrue(second.follows(first));
    assertFalse(first.follows(second));
}
Also used : TimeInterval(org.opennms.core.utils.TimeInterval) Date(java.util.Date) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)8 TimeInterval (org.opennms.core.utils.TimeInterval)8 Date (java.util.Date)3 Owner (org.opennms.core.utils.Owner)3 TimeIntervalSequence (org.opennms.core.utils.TimeIntervalSequence)3 Schedule (org.opennms.netmgt.config.groups.Schedule)3