Search in sources :

Example 11 with OwnedIntervalSequence

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

the class BasicScheduleUtilsTest method testGetIntervalsDaily.

@Test
public void testGetIntervalsDaily() throws Exception {
    String schedSpec = "           <schedule name=\"simple\" type=\"daily\">" + "               <time begins=\"11:00:00\" ends=\"14:00:00\"/>\n" + "           </schedule>";
    Schedule simpleSchedule = JaxbUtils.unmarshal(Schedule.class, schedSpec);
    assertEquals("simple", simpleSchedule.getName());
    assertEquals("daily", simpleSchedule.getType());
    assertEquals(1, simpleSchedule.getTimes().size());
    final Time simpleScheduleTime = simpleSchedule.getTimes().get(0);
    assertEquals("11:00:00", simpleScheduleTime.getBegins());
    assertEquals("14:00:00", simpleScheduleTime.getEnds());
    assertEquals(false, simpleScheduleTime.getDay().isPresent());
    assertEquals(false, simpleScheduleTime.getId().isPresent());
    BasicSchedule basicSchedule = BasicScheduleUtils.getGroupSchedule(simpleSchedule);
    Owner owner = new Owner("unnamed", "simple", 0, 0);
    OwnedIntervalSequence intervals = BasicScheduleUtils.getIntervals(interval(6, 1, 0, 7, 1, 0), basicSchedule.getTime(0), owner);
    assertNotNull(intervals);
    List<OwnedInterval> expected = new ArrayList<>();
    for (int i = 1; i < 31; i++) {
        expected.add(owned(owner, jun(i, 11, i, 14)));
    }
    assertTimeIntervalSequence(expected.toArray(new OwnedInterval[] {}), intervals);
}
Also used : Owner(org.opennms.core.utils.Owner) Schedule(org.opennms.netmgt.config.groups.Schedule) ArrayList(java.util.ArrayList) Time(org.opennms.netmgt.config.groups.Time) OwnedIntervalSequence(org.opennms.core.utils.OwnedIntervalSequence) OwnedInterval(org.opennms.core.utils.OwnedInterval) Test(org.junit.Test)

Example 12 with OwnedIntervalSequence

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

the class BasicScheduleUtilsTest method testSimpleScheduleExcluded.

@Test
public void testSimpleScheduleExcluded() throws Exception {
    String schedSpec = "           <schedule name=\"simple\" type=\"specific\">" + "               <time begins=\"20-Aug-2005 13:00:00\" ends=\"20-Aug-2005 14:00:00\"/>\n" + "           </schedule>";
    Schedule simpleSchedule = JaxbUtils.unmarshal(Schedule.class, schedSpec);
    Owner owner = new Owner("unnamed", "simple", 0);
    OwnedIntervalSequence intervals = BasicScheduleUtils.getIntervalsCovering(aug(18), BasicScheduleUtils.getGroupSchedule(simpleSchedule), owner);
    assertNotNull(intervals);
    assertTimeIntervalSequence(new OwnedInterval[0], intervals);
}
Also used : Owner(org.opennms.core.utils.Owner) Schedule(org.opennms.netmgt.config.groups.Schedule) OwnedIntervalSequence(org.opennms.core.utils.OwnedIntervalSequence) Test(org.junit.Test)

Example 13 with OwnedIntervalSequence

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

the class BasicScheduleUtilsTest method testGetIntervalsWeekly.

@Test
public void testGetIntervalsWeekly() throws Exception {
    String schedSpec = "           <schedule name=\"simple\" type=\"weekly\">" + "               <time day=\"thursday\" begins=\"11: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);
    OwnedIntervalSequence intervals = BasicScheduleUtils.getIntervals(aug(4, 13, 25, 12), basicSchedule.getTime(0), owner);
    assertNotNull(intervals);
    OwnedInterval[] expected = { // start of requested interval overlaps this one
    owned(owner, aug(4, 13, 14)), owned(owner, aug(11, 11, 14)), owned(owner, aug(18, 11, 14)), // end of requested interval overlaps this one
    owned(owner, aug(25, 11, 12)) };
    assertTimeIntervalSequence(expected, intervals);
}
Also used : Owner(org.opennms.core.utils.Owner) Schedule(org.opennms.netmgt.config.groups.Schedule) OwnedIntervalSequence(org.opennms.core.utils.OwnedIntervalSequence) OwnedInterval(org.opennms.core.utils.OwnedInterval) Test(org.junit.Test)

Example 14 with OwnedIntervalSequence

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

the class RolesTest method testTimeIntervals.

@Test
public void testTimeIntervals() throws Exception {
    OwnedIntervalSequence intervals = m_groupManager.getRoleScheduleEntries("oncall", getDate("2005-08-18"), getDate("2005-08-19"));
    assertNotNull(intervals);
    Owner brozow = new Owner("oncall", "brozow", 1, 1);
    Owner admin = new Owner("oncall", "admin", 1, 1);
    Owner david = new Owner("oncall", "david", 1, 1);
    OwnedIntervalSequence before = new OwnedIntervalSequence();
    before.addInterval(owned(david, aug(18, 0, 9)));
    before.addInterval(owned(admin, aug(18, 9, 17)));
    before.addInterval(owned(david, aug(18, 17, 23)));
    before.addInterval(owned(brozow, aug(18, 23, 24)));
    OwnedInterval[] expected = { owned(david, aug(18, 0, 9)), owned(admin, aug(18, 9, 17)), owned(david, aug(18, 17, 23)), // brozow is the supervisor and this period is unscheduled
    owned(brozow, aug(18, 23, 24)) };
    assertTimeIntervalSequence(expected, intervals);
}
Also used : Owner(org.opennms.core.utils.Owner) OwnedIntervalSequence(org.opennms.core.utils.OwnedIntervalSequence) OwnedInterval(org.opennms.core.utils.OwnedInterval) Test(org.junit.Test)

Example 15 with OwnedIntervalSequence

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

the class TimeIntervalSequenceTest method testExtensionRemoveOneOwner.

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

Aggregations

OwnedIntervalSequence (org.opennms.core.utils.OwnedIntervalSequence)17 Test (org.junit.Test)13 OwnedInterval (org.opennms.core.utils.OwnedInterval)12 Owner (org.opennms.core.utils.Owner)10 Schedule (org.opennms.netmgt.config.groups.Schedule)8 ArrayList (java.util.ArrayList)2 Date (java.util.Date)1 Role (org.opennms.netmgt.config.groups.Role)1 Time (org.opennms.netmgt.config.groups.Time)1 DutySchedule (org.opennms.netmgt.config.users.DutySchedule)1