Search in sources :

Example 6 with TimeInterval

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

the class TimeIntervalSequenceTest method testRemoveOverlappingMany.

@Test
public void testRemoveOverlappingMany() 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));
    // remove a large interval
    seq.removeInterval(aug(19, 12, 21, 12));
    // expect a sequence containing non overlapping segments
    TimeInterval[] expected = { aug(18, 8, 17), aug(19, 8, 12), aug(21, 12, 17), aug(22, 8, 17) };
    assertTimeIntervalSequence(expected, seq);
}
Also used : TimeIntervalSequence(org.opennms.core.utils.TimeIntervalSequence) TimeInterval(org.opennms.core.utils.TimeInterval) Test(org.junit.Test)

Example 7 with TimeInterval

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

the class BasicScheduleUtilsTest method testWeeklyInterval.

@Test
public void testWeeklyInterval() throws Exception {
    String schedSpec = "           <schedule name=\"simple\" type=\"specific\">" + "               <time day=\"thursday\" 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 8 with TimeInterval

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

the class BasicScheduleUtilsTest method testSpecificInterval.

@Test
public void testSpecificInterval() throws Exception {
    String schedSpec = "           <schedule name=\"simple\" type=\"specific\">" + "               <time begins=\"18-Aug-2005 13:00:00\" ends=\"18-Aug-2005 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(new Date(), 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) 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