Search in sources :

Example 21 with Schedule

use of de.avanux.smartapplianceenabler.schedule.Schedule 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

Schedule (de.avanux.smartapplianceenabler.schedule.Schedule)21 TimeOfDay (de.avanux.smartapplianceenabler.schedule.TimeOfDay)17 Test (org.junit.Test)17 LocalDateTime (org.joda.time.LocalDateTime)12 TimeframeInterval (de.avanux.smartapplianceenabler.schedule.TimeframeInterval)9 Interval (org.joda.time.Interval)8 ArrayList (java.util.ArrayList)4 Timeframe (de.avanux.smartapplianceenabler.schedule.Timeframe)1