use of org.joda.time.LocalDateTime in project SmartApplianceEnabler by camueller.
the class ApplianceTest method createRuntimeRequest_TimeFrameOverMidnight_AfterMidnight.
@Test
public void createRuntimeRequest_TimeFrameOverMidnight_AfterMidnight() {
LocalDateTime now = toToday(0, 30, 0);
Schedule schedule = new Schedule(7200, null, new TimeOfDay(20, 0, 0), new TimeOfDay(4, 0, 0));
Interval interval = schedule.getTimeframe().getIntervals(now).get(0).getInterval();
RuntimeRequest runtimeRequest = this.appliance.createRuntimeRequest(interval, schedule.getMinRunningTime(), null, now);
Assert.assertEquals(0, (int) runtimeRequest.getEarliestStart());
Assert.assertEquals(12600, (int) runtimeRequest.getLatestEnd());
Assert.assertEquals(7200, (int) runtimeRequest.getMinRunningTime());
Assert.assertNull(runtimeRequest.getMaxRunningTime());
}
use of org.joda.time.LocalDateTime in project SmartApplianceEnabler by camueller.
the class ApplianceTest method createRuntimeRequest.
@Test
public void createRuntimeRequest() {
LocalDateTime now = toToday(0, 30, 0);
Schedule schedule = new Schedule(7200, null, new TimeOfDay(1, 0, 0), new TimeOfDay(9, 0, 0));
Interval interval = schedule.getTimeframe().getIntervals(now).get(0).getInterval();
schedule.getTimeframe().setSchedule(schedule);
RuntimeRequest runtimeRequest = this.appliance.createRuntimeRequest(interval, schedule.getMinRunningTime(), null, now);
Assert.assertEquals(1800, (int) runtimeRequest.getEarliestStart());
Assert.assertEquals(30600, (int) runtimeRequest.getLatestEnd());
Assert.assertEquals(7200, (int) runtimeRequest.getMinRunningTime());
Assert.assertNull(runtimeRequest.getMaxRunningTime());
}
use of org.joda.time.LocalDateTime in project SmartApplianceEnabler by camueller.
the class ApplianceTest method createRuntimeRequest_MaxRunningTime.
@Test
public void createRuntimeRequest_MaxRunningTime() {
LocalDateTime now = toToday(0, 30, 0);
Schedule schedule = new Schedule(3600, 7200, new TimeOfDay(1, 0, 0), new TimeOfDay(9, 0, 0));
Interval interval = schedule.getTimeframe().getIntervals(now).get(0).getInterval();
schedule.getTimeframe().setSchedule(schedule);
RuntimeRequest runtimeRequest = this.appliance.createRuntimeRequest(interval, schedule.getMinRunningTime(), schedule.getMaxRunningTime(), now);
Assert.assertEquals(1800, (int) runtimeRequest.getEarliestStart());
Assert.assertEquals(30600, (int) runtimeRequest.getLatestEnd());
Assert.assertEquals(3600, (int) runtimeRequest.getMinRunningTime());
Assert.assertEquals(7200, (int) runtimeRequest.getMaxRunningTime());
}
use of org.joda.time.LocalDateTime in project SmartApplianceEnabler by camueller.
the class ApplianceTest method createRuntimeRequest_MaxRunningTimeExceedsLatestEnd.
@Test
public void createRuntimeRequest_MaxRunningTimeExceedsLatestEnd() {
LocalDateTime now = toToday(8, 0, 0);
Schedule schedule = new Schedule(3600, 7200, new TimeOfDay(1, 0, 0), new TimeOfDay(9, 0, 0));
Interval interval = schedule.getTimeframe().getIntervals(now).get(0).getInterval();
schedule.getTimeframe().setSchedule(schedule);
RuntimeRequest runtimeRequest = this.appliance.createRuntimeRequest(interval, schedule.getMinRunningTime(), schedule.getMaxRunningTime(), now);
Assert.assertEquals(0, (int) runtimeRequest.getEarliestStart());
Assert.assertEquals(3600, (int) runtimeRequest.getLatestEnd());
Assert.assertEquals(3600, (int) runtimeRequest.getMinRunningTime());
Assert.assertEquals(3600, (int) runtimeRequest.getMaxRunningTime());
}
use of org.joda.time.LocalDateTime in project SmartApplianceEnabler by camueller.
the class StartingCurrentSwitchTest method test.
@Test
public void test() throws Exception {
LocalDateTime now = new LocalDateTime();
startingCurrentSwitch.start(now, meter, null);
// right after start
// ... the appliance should be switched on
when(control.isOn()).thenReturn(true);
Assert.assertTrue(startingCurrentSwitch.isApplianceOn());
// ... but from the outside perspective the control is switched off
Assert.assertFalse(startingCurrentSwitch.isOn());
// averagePower=0 lastAveragePowerOfPowerOnDetection=null
startingCurrentSwitch.detectStartingCurrent(now, meter);
verify(startingCurrentSwitchListener, never()).startingCurrentDetected(now);
// averagePower=0 lastAveragePowerOfPowerOnDetection=0
startingCurrentSwitch.detectStartingCurrent(now, meter);
verify(startingCurrentSwitchListener, never()).startingCurrentDetected(now);
// averagePower=10 lastAveragePowerOfPowerOnDetection=0
when(meter.getAveragePower()).thenReturn(10);
startingCurrentSwitch.detectStartingCurrent(now, meter);
verify(startingCurrentSwitchListener, never()).startingCurrentDetected(now);
// averagePower=10 lastAveragePowerOfPowerOnDetection=10
startingCurrentSwitch.detectStartingCurrent(now, meter);
verify(startingCurrentSwitchListener, never()).startingCurrentDetected(now);
// averagePower=30 lastAveragePowerOfPowerOnDetection=0
when(meter.getAveragePower()).thenReturn(30);
startingCurrentSwitch.detectStartingCurrent(now, meter);
verify(startingCurrentSwitchListener, never()).startingCurrentDetected(now);
// averagePower=30 lastAveragePowerOfPowerOnDetection=30
startingCurrentSwitch.detectStartingCurrent(now, meter);
// power threshold exceeded for more than configured starting current detection duration
// (2 consecutive calls to detectStartingCurrent())
// ... causing appliance power off
verify(control).on(now, false);
when(control.isOn()).thenReturn(false);
Assert.assertFalse(startingCurrentSwitch.isApplianceOn());
// ... and also from the outside perspective the control is switched off
Assert.assertFalse(startingCurrentSwitch.isOn());
// ... listeners are notified of starting current detection
verify(startingCurrentSwitchListener).startingCurrentDetected(now);
// power on recommendation received by energy manager
reset(control);
startingCurrentSwitch.on(now, true);
// ... causing appliance power on
verify(control).on(now, true);
when(control.isOn()).thenReturn(true);
Assert.assertTrue(startingCurrentSwitch.isApplianceOn());
// ... and also from the outside perspective the control is switched on
Assert.assertTrue(startingCurrentSwitch.isOn());
// averagePower=30 lastAveragePower=30
when(meter.getAveragePower()).thenReturn(30);
// power threshold still exceeds power threshold
startingCurrentSwitch.detectStartingCurrent(now, meter);
// the minimum running time has been exceeded now
when(startingCurrentSwitch.isMinRunningTimeExceeded()).thenReturn(true);
// averagePower=10 lastAveragePower=30
when(meter.getAveragePower()).thenReturn(10);
startingCurrentSwitch.detectFinishedCurrent(now, meter);
verify(startingCurrentSwitchListener, never()).finishedCurrentDetected();
// averagePower=10 lastAveragePower=10
startingCurrentSwitch.detectFinishedCurrent(now, meter);
// power consumption fell below threshold for more than configured finished current detection duration
// (2 consecutive calls to detectFinishedCurrent())
// ... causing power off from the outside perspective
Assert.assertFalse(startingCurrentSwitch.isOn());
// ... but appliance remaining powered on
verify(control).on(now, true);
when(control.isOn()).thenReturn(true);
Assert.assertTrue(startingCurrentSwitch.isApplianceOn());
// ... listeners are notified of finish current detection
verify(startingCurrentSwitchListener).finishedCurrentDetected();
}
Aggregations