automation dto should be tested

This commit is contained in:
Tommaso Rodolfo Masera 2020-05-14 19:00:07 +02:00
parent 0031fe38ea
commit 368530de97
2 changed files with 103 additions and 6 deletions

View file

@ -28,8 +28,8 @@ public class AutomationFastUpdateRequest {
}
public static class RangeTriggerDTO extends TriggerDTO {
@NotNull Operator operator;
@NotNull double range;
@NotNull public Operator operator;
@NotNull public double range;
@Override
public Trigger<?> toModel() {
@ -77,8 +77,8 @@ public class AutomationFastUpdateRequest {
public static class RangeConditionDTO extends ConditionDTO {
@NotNull Operator operator;
@NotNull double range;
@NotNull public Operator operator;
@NotNull public double range;
@Override
public Condition<?> toModel() {
@ -92,8 +92,8 @@ public class AutomationFastUpdateRequest {
public static class ThermostatConditionDTO extends ConditionDTO {
@NotNull ThermostatCondition.Operator operator;
@NotNull private Thermostat.Mode mode;
@NotNull public ThermostatCondition.Operator operator;
@NotNull public Thermostat.Mode mode;
@Override
public Condition<?> toModel() {

View file

@ -0,0 +1,97 @@
package ch.usi.inf.sa4.sanmarinoes.smarthut;
import static org.junit.jupiter.api.Assertions.*;
import ch.usi.inf.sa4.sanmarinoes.smarthut.dto.AutomationFastUpdateRequest;
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.*;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
@DisplayName("Automation Update DTO")
public class AutomationFastUpdateRequestTest {
AutomationFastUpdateRequest.BooleanTriggerDTO booleanTriggerDTO;
AutomationFastUpdateRequest.RangeTriggerDTO rangeTriggerDTO;
AutomationFastUpdateRequest.ScenePriorityDTO scenePriorityDTO;
AutomationFastUpdateRequest.BooleanConditionDTO booleanConditionDTO;
AutomationFastUpdateRequest.RangeConditionDTO rangeConditionDTO;
AutomationFastUpdateRequest.ThermostatConditionDTO thermostatConditionDTO;
@Test
@DisplayName(" checking boolean trigger ")
public void booleanTriggerDTOTest() {
booleanTriggerDTO = new AutomationFastUpdateRequest.BooleanTriggerDTO();
booleanTriggerDTO.on = true;
booleanTriggerDTO.deviceId = 42;
BooleanTrigger booleanTrigger = (BooleanTrigger) booleanTriggerDTO.toModel();
assertEquals(booleanTrigger.isOn(), booleanTriggerDTO.on);
assertEquals(booleanTrigger.getDeviceId(), booleanTriggerDTO.deviceId);
}
@Test
@DisplayName(" checking range trigger ")
public void rangeTriggerDTOTest() {
rangeTriggerDTO = new AutomationFastUpdateRequest.RangeTriggerDTO();
rangeTriggerDTO.operator = Operator.EQUAL;
rangeTriggerDTO.deviceId = 420;
rangeTriggerDTO.range = 12;
RangeTrigger rangeTrigger = (RangeTrigger) rangeTriggerDTO.toModel();
assertEquals(rangeTrigger.getOperator(), rangeTriggerDTO.operator);
assertEquals(rangeTrigger.getRange(), rangeTriggerDTO.range);
assertEquals(rangeTrigger.getDeviceId(), rangeTriggerDTO.deviceId);
}
@Test
@DisplayName(" checking scene priority ")
public void scenePriorityDTOTest() {
scenePriorityDTO = new AutomationFastUpdateRequest.ScenePriorityDTO();
scenePriorityDTO.priority = 67;
scenePriorityDTO.sceneId = 21;
ScenePriority scenePriority = scenePriorityDTO.toModel();
assertEquals(scenePriority.getPriority(), scenePriorityDTO.priority);
assertEquals(scenePriority.getSceneId(), scenePriorityDTO.priority);
}
@Test
@DisplayName(" checking boolean condition ")
public void booleanConditionDTOTest() {
booleanConditionDTO = new AutomationFastUpdateRequest.BooleanConditionDTO();
booleanConditionDTO.on = true;
booleanConditionDTO.deviceId = 17;
BooleanCondition booleanCondition = (BooleanCondition) booleanConditionDTO.toModel();
assertEquals(booleanCondition.isOn(), booleanConditionDTO.on);
assertEquals(booleanCondition.getDeviceId(), booleanConditionDTO.deviceId);
}
@Test
@DisplayName(" checking range condition ")
public void rangeConditionDTOTest() {
rangeConditionDTO = new AutomationFastUpdateRequest.RangeConditionDTO();
rangeConditionDTO.operator = Operator.LESS;
rangeConditionDTO.range = 82.01;
rangeConditionDTO.deviceId = 13;
RangeCondition rangeCondition = (RangeCondition) rangeConditionDTO.toModel();
assertEquals(rangeCondition.getOperator(), rangeConditionDTO.operator);
assertEquals(rangeCondition.getRange(), rangeConditionDTO.range);
assertEquals(rangeCondition.getDeviceId(), rangeConditionDTO.deviceId);
}
@Test
@DisplayName(" checking thermostat condition ")
public void thermostatConditionDTOTest() {
thermostatConditionDTO = new AutomationFastUpdateRequest.ThermostatConditionDTO();
thermostatConditionDTO.deviceId = 25;
thermostatConditionDTO.operator = ThermostatCondition.Operator.EQUAL;
thermostatConditionDTO.mode = Thermostat.Mode.HEATING;
ThermostatCondition thermostatCondition =
(ThermostatCondition) thermostatConditionDTO.toModel();
assertEquals(thermostatCondition.getMode(), thermostatConditionDTO.mode);
assertEquals(thermostatCondition.getOperator(), thermostatConditionDTO.operator);
assertEquals(thermostatCondition.getDeviceId(), thermostatConditionDTO.deviceId);
}
}