diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/AutomationFastUpdateRequest.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/AutomationFastUpdateRequest.java index f086fef..667645e 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/AutomationFastUpdateRequest.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/AutomationFastUpdateRequest.java @@ -6,37 +6,37 @@ import javax.validation.constraints.Min; import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotNull; import lombok.Data; +import lombok.Getter; +import lombok.Setter; @Data -@Getter -@Setter public class AutomationFastUpdateRequest { public abstract static class TriggerDTO { - @NotNull public long deviceId; + @NotNull @Getter @Setter private long deviceId; public abstract Trigger toModel(); } public static class BooleanTriggerDTO extends TriggerDTO { - @NotNull public boolean on; + @NotNull @Getter @Setter private boolean on; @Override public Trigger toModel() { BooleanTrigger t = new BooleanTrigger(); - t.setDeviceId(this.deviceId); + t.setDeviceId(this.getDeviceId()); t.setOn(this.on); return t; } } public static class RangeTriggerDTO extends TriggerDTO { - @NotNull private Operator operator; - @NotNull private double range; + @NotNull @Getter @Setter private Operator operator; + @NotNull @Getter @Setter private double range; @Override public Trigger toModel() { RangeTrigger t = new RangeTrigger(); - t.setDeviceId(this.deviceId); + t.setDeviceId(this.getDeviceId()); t.setOperator(this.operator); t.setRange(this.range); return t; @@ -44,11 +44,11 @@ public class AutomationFastUpdateRequest { } public static class ScenePriorityDTO { - @NotNull public long sceneId; + @NotNull @Getter @Setter private long sceneId; @NotNull @Min(0) - public Integer priority; + private @Getter @Setter Integer priority; public ScenePriority toModel() { ScenePriority s = new ScenePriority(); @@ -59,19 +59,19 @@ public class AutomationFastUpdateRequest { } public abstract static class ConditionDTO { - @NotNull public long deviceId; + @NotNull @Getter @Setter private long deviceId; public abstract Condition toModel(); } public static class BooleanConditionDTO extends ConditionDTO { - @NotNull public boolean on; + @NotNull @Getter @Setter private boolean on; @Override public Condition toModel() { BooleanCondition t = new BooleanCondition(); - t.setDeviceId(this.deviceId); + t.setDeviceId(this.getDeviceId()); t.setOn(this.on); return t; } @@ -79,13 +79,13 @@ public class AutomationFastUpdateRequest { public static class RangeConditionDTO extends ConditionDTO { - @NotNull private Operator operator; - @NotNull private double range; + @NotNull @Getter @Setter private Operator operator; + @NotNull @Getter @Setter private double range; @Override public Condition toModel() { RangeCondition t = new RangeCondition(); - t.setDeviceId(this.deviceId); + t.setDeviceId(this.getDeviceId()); t.setOperator(this.operator); t.setRange(this.range); return t; @@ -94,13 +94,13 @@ public class AutomationFastUpdateRequest { public static class ThermostatConditionDTO extends ConditionDTO { - @NotNull private ThermostatCondition.Operator operator; - @NotNull private Thermostat.Mode mode; + @NotNull @Getter @Setter private ThermostatCondition.Operator operator; + @NotNull @Getter @Setter private Thermostat.Mode mode; @Override public Condition toModel() { ThermostatCondition t = new ThermostatCondition(); - t.setDeviceId(this.deviceId); + t.setDeviceId(this.getDeviceId()); t.setOperator(this.operator); t.setMode(this.mode); return t; diff --git a/src/test/java/ch/usi/inf/sa4/sanmarinoes/smarthut/AutomationFastUpdateRequestTest.java b/src/test/java/ch/usi/inf/sa4/sanmarinoes/smarthut/AutomationFastUpdateRequestTest.java index 013f067..4f10fc6 100644 --- a/src/test/java/ch/usi/inf/sa4/sanmarinoes/smarthut/AutomationFastUpdateRequestTest.java +++ b/src/test/java/ch/usi/inf/sa4/sanmarinoes/smarthut/AutomationFastUpdateRequestTest.java @@ -21,11 +21,11 @@ public class AutomationFastUpdateRequestTest { @DisplayName(" checking boolean trigger ") public void booleanTriggerDTOTest() { booleanTriggerDTO = new AutomationFastUpdateRequest.BooleanTriggerDTO(); - booleanTriggerDTO.on = true; - booleanTriggerDTO.deviceId = 42; + booleanTriggerDTO.setOn(true); + booleanTriggerDTO.setDeviceId(42); BooleanTrigger booleanTrigger = (BooleanTrigger) booleanTriggerDTO.toModel(); - assertEquals(booleanTrigger.isOn(), booleanTriggerDTO.on); - assertEquals(booleanTrigger.getDeviceId(), booleanTriggerDTO.deviceId); + assertEquals(booleanTrigger.isOn(), booleanTriggerDTO.isOn()); + assertEquals(booleanTrigger.getDeviceId(), booleanTriggerDTO.getDeviceId()); } @Test @@ -33,37 +33,37 @@ public class AutomationFastUpdateRequestTest { public void rangeTriggerDTOTest() { rangeTriggerDTO = new AutomationFastUpdateRequest.RangeTriggerDTO(); rangeTriggerDTO.setOperator(Operator.EQUAL); - rangeTriggerDTO.deviceId = 420; + rangeTriggerDTO.setDeviceId(420); rangeTriggerDTO.setRange(12); RangeTrigger rangeTrigger = (RangeTrigger) rangeTriggerDTO.toModel(); assertEquals(rangeTrigger.getOperator(), rangeTriggerDTO.getOperator()); assertEquals(rangeTrigger.getRange(), rangeTriggerDTO.getRange()); - assertEquals(rangeTrigger.getDeviceId(), rangeTriggerDTO.deviceId); + assertEquals(rangeTrigger.getDeviceId(), rangeTriggerDTO.getDeviceId()); } @Test @DisplayName(" checking scene priority ") public void scenePriorityDTOTest() { scenePriorityDTO = new AutomationFastUpdateRequest.ScenePriorityDTO(); - scenePriorityDTO.priority = 67; - scenePriorityDTO.sceneId = 21; + scenePriorityDTO.setPriority(67); + scenePriorityDTO.setSceneId(21); ScenePriority scenePriority = scenePriorityDTO.toModel(); - assertEquals(scenePriority.getPriority(), scenePriorityDTO.priority); - assertEquals(scenePriority.getSceneId(), scenePriorityDTO.priority); + assertEquals(scenePriority.getPriority(), scenePriorityDTO.getPriority()); + assertEquals(scenePriority.getSceneId(), scenePriorityDTO.getSceneId()); } @Test @DisplayName(" checking boolean condition ") public void booleanConditionDTOTest() { booleanConditionDTO = new AutomationFastUpdateRequest.BooleanConditionDTO(); - booleanConditionDTO.on = true; - booleanConditionDTO.deviceId = 17; + booleanConditionDTO.setOn(true); + booleanConditionDTO.setDeviceId(17); BooleanCondition booleanCondition = (BooleanCondition) booleanConditionDTO.toModel(); - assertEquals(booleanCondition.isOn(), booleanConditionDTO.on); - assertEquals(booleanCondition.getDeviceId(), booleanConditionDTO.deviceId); + assertEquals(booleanCondition.isOn(), booleanConditionDTO.isOn()); + assertEquals(booleanCondition.getDeviceId(), booleanConditionDTO.getDeviceId()); } @Test @@ -72,19 +72,19 @@ public class AutomationFastUpdateRequestTest { rangeConditionDTO = new AutomationFastUpdateRequest.RangeConditionDTO(); rangeConditionDTO.setOperator(Operator.LESS); rangeConditionDTO.setRange(82.01); - rangeConditionDTO.deviceId = 13; + rangeConditionDTO.setDeviceId(13); RangeCondition rangeCondition = (RangeCondition) rangeConditionDTO.toModel(); assertEquals(rangeCondition.getOperator(), rangeConditionDTO.getOperator()); assertEquals(rangeCondition.getRange(), rangeConditionDTO.getRange()); - assertEquals(rangeCondition.getDeviceId(), rangeConditionDTO.deviceId); + assertEquals(rangeCondition.getDeviceId(), rangeConditionDTO.getDeviceId()); } @Test @DisplayName(" checking thermostat condition ") public void thermostatConditionDTOTest() { thermostatConditionDTO = new AutomationFastUpdateRequest.ThermostatConditionDTO(); - thermostatConditionDTO.deviceId = 25; + thermostatConditionDTO.setDeviceId(25); thermostatConditionDTO.setOperator(ThermostatCondition.Operator.EQUAL); thermostatConditionDTO.setMode(Thermostat.Mode.HEATING); @@ -92,6 +92,6 @@ public class AutomationFastUpdateRequestTest { (ThermostatCondition) thermostatConditionDTO.toModel(); assertEquals(thermostatCondition.getMode(), thermostatConditionDTO.getMode()); assertEquals(thermostatCondition.getOperator(), thermostatConditionDTO.getOperator()); - assertEquals(thermostatCondition.getDeviceId(), thermostatConditionDTO.deviceId); + assertEquals(thermostatCondition.getDeviceId(), thermostatConditionDTO.getDeviceId()); } }