Search in sources :

Example 21 with TimeOfDay

use of de.avanux.smartapplianceenabler.schedule.TimeOfDay in project SmartApplianceEnabler by camueller.

the class ScheduleTest method getCurrentOrNextTimeframeInterval_timeFrameNotValidForDow.

@Test
public void getCurrentOrNextTimeframeInterval_timeFrameNotValidForDow() {
    LocalDateTime now = toToday(9, 0, 0);
    List<Schedule> schedules = new ArrayList<Schedule>();
    // Timeframe only valid yesterday
    schedules.add(new Schedule(true, 7200, null, new TimeOfDay(10, 0, 0), new TimeOfDay(14, 0, 0), Collections.singletonList(now.minusDays(1).get(DateTimeFieldType.dayOfWeek()))));
    // Timeframe only valid tomorrow
    schedules.add(new Schedule(true, 7200, null, new TimeOfDay(15, 0, 0), new TimeOfDay(18, 0, 0), Collections.singletonList(now.plusDays(1).get(DateTimeFieldType.dayOfWeek()))));
    Assert.assertEquals(new Interval(toDay(1, 15, 0, 0).toDateTime(), toDay(1, 18, 0, 0).toDateTime()), Schedule.getCurrentOrNextTimeframeInterval(now, schedules, false, false).getInterval());
}
Also used : LocalDateTime(org.joda.time.LocalDateTime) TimeOfDay(de.avanux.smartapplianceenabler.schedule.TimeOfDay) Schedule(de.avanux.smartapplianceenabler.schedule.Schedule) ArrayList(java.util.ArrayList) Interval(org.joda.time.Interval) Test(org.junit.Test)

Example 22 with TimeOfDay

use of de.avanux.smartapplianceenabler.schedule.TimeOfDay in project SmartApplianceEnabler by camueller.

the class DayTimeframeTest method buildMidnightAdjustedInterval_OverMidnight_BeforeInterval_BeforeMidnight.

@Test
public void buildMidnightAdjustedInterval_OverMidnight_BeforeInterval_BeforeMidnight() {
    DayTimeframe timeframe = new DayTimeframe(new TimeOfDay(22, 0, 0), new TimeOfDay(2, 0, 0));
    Interval interval = timeframe.buildMidnightAdjustedInterval(toToday(21, 0, 0));
    Assert.assertEquals(new Interval(toToday(22, 0, 0).toDateTime(), toDay(1, 2, 0, 0).toDateTime()), interval);
}
Also used : TimeOfDay(de.avanux.smartapplianceenabler.schedule.TimeOfDay) DayTimeframe(de.avanux.smartapplianceenabler.schedule.DayTimeframe) Interval(org.joda.time.Interval) TimeframeInterval(de.avanux.smartapplianceenabler.schedule.TimeframeInterval) Test(org.junit.Test)

Example 23 with TimeOfDay

use of de.avanux.smartapplianceenabler.schedule.TimeOfDay in project SmartApplianceEnabler by camueller.

the class DayTimeframeTest method buildMidnightAdjustedInterval_OverMidnight_WithinInterval_BeforeMidnight.

@Test
public void buildMidnightAdjustedInterval_OverMidnight_WithinInterval_BeforeMidnight() {
    DayTimeframe timeframe = new DayTimeframe(new TimeOfDay(22, 0, 0), new TimeOfDay(2, 0, 0));
    Interval interval = timeframe.buildMidnightAdjustedInterval(toToday(23, 0, 0));
    Assert.assertEquals(new Interval(toToday(22, 0, 0).toDateTime(), toDay(1, 2, 0, 0).toDateTime()), interval);
}
Also used : TimeOfDay(de.avanux.smartapplianceenabler.schedule.TimeOfDay) DayTimeframe(de.avanux.smartapplianceenabler.schedule.DayTimeframe) Interval(org.joda.time.Interval) TimeframeInterval(de.avanux.smartapplianceenabler.schedule.TimeframeInterval) Test(org.junit.Test)

Example 24 with TimeOfDay

use of de.avanux.smartapplianceenabler.schedule.TimeOfDay in project SmartApplianceEnabler by camueller.

the class DayTimeframeTest method getIntervals_AllDayOfWeek_AfterIntervalEnd.

@Test
public void getIntervals_AllDayOfWeek_AfterIntervalEnd() {
    DayTimeframe timeframe = new DayTimeframe(new TimeOfDay(10, 0, 0), new TimeOfDay(12, 0, 0));
    List<TimeframeInterval> intervals = timeframe.getIntervals(toToday(13, 0, 0));
    Assert.assertEquals(7, intervals.size());
    Assert.assertEquals(new Interval(toDay(1, 10, 0, 0).toDateTime(), toDay(1, 12, 0, 0).toDateTime()), intervals.get(0).getInterval());
    Assert.assertEquals(new Interval(toDay(2, 10, 0, 0).toDateTime(), toDay(2, 12, 0, 0).toDateTime()), intervals.get(1).getInterval());
    Assert.assertEquals(new Interval(toDay(3, 10, 0, 0).toDateTime(), toDay(3, 12, 0, 0).toDateTime()), intervals.get(2).getInterval());
    Assert.assertEquals(new Interval(toDay(4, 10, 0, 0).toDateTime(), toDay(4, 12, 0, 0).toDateTime()), intervals.get(3).getInterval());
    Assert.assertEquals(new Interval(toDay(5, 10, 0, 0).toDateTime(), toDay(5, 12, 0, 0).toDateTime()), intervals.get(4).getInterval());
    Assert.assertEquals(new Interval(toDay(6, 10, 0, 0).toDateTime(), toDay(6, 12, 0, 0).toDateTime()), intervals.get(5).getInterval());
    Assert.assertEquals(new Interval(toDay(7, 10, 0, 0).toDateTime(), toDay(7, 12, 0, 0).toDateTime()), intervals.get(6).getInterval());
}
Also used : TimeOfDay(de.avanux.smartapplianceenabler.schedule.TimeOfDay) TimeframeInterval(de.avanux.smartapplianceenabler.schedule.TimeframeInterval) DayTimeframe(de.avanux.smartapplianceenabler.schedule.DayTimeframe) Interval(org.joda.time.Interval) TimeframeInterval(de.avanux.smartapplianceenabler.schedule.TimeframeInterval) Test(org.junit.Test)

Example 25 with TimeOfDay

use of de.avanux.smartapplianceenabler.schedule.TimeOfDay in project SmartApplianceEnabler by camueller.

the class SempControllerTest method getPlanningRequest_startingCurrentDetected.

@Test
public void getPlanningRequest_startingCurrentDetected() {
    Identification identification = new Identification();
    identification.setDeviceId(DEVICE_ID);
    DeviceInfo deviceInfo = new DeviceInfo();
    deviceInfo.setIdentification(identification);
    setDeviceInfo(deviceInfo);
    Appliance appliance = new Appliance();
    appliance.setId(DEVICE_ID);
    LocalDateTime now = toToday(9, 0, 0);
    Schedule schedule = new Schedule(3600, null, new TimeOfDay(11, 0, 0), new TimeOfDay(13, 0, 0));
    de.avanux.smartapplianceenabler.schedule.Timeframe timeframe = schedule.getTimeframe();
    timeframe.setSchedule(schedule);
    RunningTimeMonitor runningTimeMonitor = mock(RunningTimeMonitor.class);
    when(runningTimeMonitor.getActiveTimeframeInterval()).thenReturn(timeframe.getIntervals(now).get(0));
    when(runningTimeMonitor.getRemainingMinRunningTimeOfCurrentTimeFrame(now)).thenReturn(schedule.getMinRunningTime());
    when(runningTimeMonitor.getRemainingMaxRunningTimeOfCurrentTimeFrame(now)).thenReturn(schedule.getMaxRunningTime());
    appliance.setRunningTimeMonitor(runningTimeMonitor);
    Appliances appliances = new Appliances();
    appliances.setAppliances(Collections.singletonList(appliance));
    ApplianceManager.getInstanceWithoutTimer().setAppliances(appliances);
    appliance.startingCurrentDetected(now);
    // check timeframes for the first time after activation
    Device2EM device2EM = sempController.createDevice2EM(now);
    List<PlanningRequest> planningRequests = device2EM.getPlanningRequest();
    Assert.assertEquals(1, planningRequests.size());
    List<Timeframe> timeframes = planningRequests.get(0).getTimeframes();
    Assert.assertEquals(1, timeframes.size());
    // check again in order to make sure that the timeframe remains active
    device2EM = sempController.createDevice2EM(now);
    planningRequests = device2EM.getPlanningRequest();
    Assert.assertEquals(1, planningRequests.size());
    timeframes = planningRequests.get(0).getTimeframes();
    Assert.assertEquals(1, timeframes.size());
    appliance.finishedCurrentDetected();
    when(runningTimeMonitor.getActiveTimeframeInterval()).thenReturn(null);
    // check timeframes for the first time after deactivation
    device2EM = sempController.createDevice2EM(now);
    planningRequests = device2EM.getPlanningRequest();
    Assert.assertEquals(0, planningRequests.size());
    // check again in order to make sure that the timeframe remains inactive
    device2EM = sempController.createDevice2EM(now);
    planningRequests = device2EM.getPlanningRequest();
    Assert.assertEquals(0, planningRequests.size());
}
Also used : LocalDateTime(org.joda.time.LocalDateTime) TimeOfDay(de.avanux.smartapplianceenabler.schedule.TimeOfDay) Schedule(de.avanux.smartapplianceenabler.schedule.Schedule) Test(org.junit.Test)

Aggregations

TimeOfDay (de.avanux.smartapplianceenabler.schedule.TimeOfDay)25 Test (org.junit.Test)23 Schedule (de.avanux.smartapplianceenabler.schedule.Schedule)17 TimeframeInterval (de.avanux.smartapplianceenabler.schedule.TimeframeInterval)16 Interval (org.joda.time.Interval)15 LocalDateTime (org.joda.time.LocalDateTime)11 DayTimeframe (de.avanux.smartapplianceenabler.schedule.DayTimeframe)8 ArrayList (java.util.ArrayList)2 Timeframe (de.avanux.smartapplianceenabler.schedule.Timeframe)1