Search in sources :

Example 96 with LocalDateTime

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());
}
Also used : LocalDateTime(org.joda.time.LocalDateTime) TimeOfDay(de.avanux.smartapplianceenabler.schedule.TimeOfDay) Schedule(de.avanux.smartapplianceenabler.schedule.Schedule) Interval(org.joda.time.Interval) TimeframeInterval(de.avanux.smartapplianceenabler.schedule.TimeframeInterval) Test(org.junit.Test)

Example 97 with LocalDateTime

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());
}
Also used : LocalDateTime(org.joda.time.LocalDateTime) TimeOfDay(de.avanux.smartapplianceenabler.schedule.TimeOfDay) Schedule(de.avanux.smartapplianceenabler.schedule.Schedule) Interval(org.joda.time.Interval) TimeframeInterval(de.avanux.smartapplianceenabler.schedule.TimeframeInterval) Test(org.junit.Test)

Example 98 with LocalDateTime

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());
}
Also used : LocalDateTime(org.joda.time.LocalDateTime) TimeOfDay(de.avanux.smartapplianceenabler.schedule.TimeOfDay) Schedule(de.avanux.smartapplianceenabler.schedule.Schedule) Interval(org.joda.time.Interval) TimeframeInterval(de.avanux.smartapplianceenabler.schedule.TimeframeInterval) Test(org.junit.Test)

Example 99 with LocalDateTime

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());
}
Also used : LocalDateTime(org.joda.time.LocalDateTime) TimeOfDay(de.avanux.smartapplianceenabler.schedule.TimeOfDay) Schedule(de.avanux.smartapplianceenabler.schedule.Schedule) Interval(org.joda.time.Interval) TimeframeInterval(de.avanux.smartapplianceenabler.schedule.TimeframeInterval) Test(org.junit.Test)

Example 100 with LocalDateTime

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();
}
Also used : LocalDateTime(org.joda.time.LocalDateTime) Test(org.junit.Test)

Aggregations

LocalDateTime (org.joda.time.LocalDateTime)120 Test (org.junit.Test)73 Interval (org.joda.time.Interval)27 TimeframeInterval (de.avanux.smartapplianceenabler.schedule.TimeframeInterval)21 DateTime (org.joda.time.DateTime)18 TimeOfDay (de.avanux.smartapplianceenabler.schedule.TimeOfDay)17 Schedule (de.avanux.smartapplianceenabler.schedule.Schedule)12 LocalDate (org.joda.time.LocalDate)12 ArrayList (java.util.ArrayList)8 ConsecutiveDaysTimeframe (de.avanux.smartapplianceenabler.schedule.ConsecutiveDaysTimeframe)6 DayTimeframe (de.avanux.smartapplianceenabler.schedule.DayTimeframe)6 TimeOfDayOfWeek (de.avanux.smartapplianceenabler.schedule.TimeOfDayOfWeek)6 Date (java.util.Date)6 TestBuilder (de.avanux.smartapplianceenabler.test.TestBuilder)4 AccAccountDto (eu.bcvsolutions.idm.acc.dto.AccAccountDto)4 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)4 AccAccount (eu.bcvsolutions.idm.acc.entity.AccAccount)4 IdmAuthorizationPolicyDto (eu.bcvsolutions.idm.core.api.dto.IdmAuthorizationPolicyDto)4 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)4 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)4