From 368530de97160059bf9aedcda9cf5a7e64b1e9b2 Mon Sep 17 00:00:00 2001 From: tommi27 Date: Thu, 14 May 2020 19:00:07 +0200 Subject: [PATCH 1/3] automation dto should be tested --- .../dto/AutomationFastUpdateRequest.java | 12 +-- .../AutomationFastUpdateRequestTest.java | 97 +++++++++++++++++++ 2 files changed, 103 insertions(+), 6 deletions(-) create mode 100644 src/test/java/ch/usi/inf/sa4/sanmarinoes/smarthut/AutomationFastUpdateRequestTest.java 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 4217761..ada8906 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 @@ -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() { 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 new file mode 100644 index 0000000..70e1f99 --- /dev/null +++ b/src/test/java/ch/usi/inf/sa4/sanmarinoes/smarthut/AutomationFastUpdateRequestTest.java @@ -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); + } +} From 3dcfa584f070e6ab11a182fb073983611f306fa6 Mon Sep 17 00:00:00 2001 From: tommi27 Date: Thu, 14 May 2020 21:02:49 +0200 Subject: [PATCH 2/3] made some fields private --- .../dto/AutomationFastUpdateRequest.java | 14 ++++++----- .../AutomationFastUpdateRequestTest.java | 24 +++++++++---------- 2 files changed, 20 insertions(+), 18 deletions(-) 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 ada8906..f086fef 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 @@ -8,6 +8,8 @@ import javax.validation.constraints.NotNull; import lombok.Data; @Data +@Getter +@Setter public class AutomationFastUpdateRequest { public abstract static class TriggerDTO { @NotNull public long deviceId; @@ -28,8 +30,8 @@ public class AutomationFastUpdateRequest { } public static class RangeTriggerDTO extends TriggerDTO { - @NotNull public Operator operator; - @NotNull public double range; + @NotNull private Operator operator; + @NotNull private double range; @Override public Trigger toModel() { @@ -77,8 +79,8 @@ public class AutomationFastUpdateRequest { public static class RangeConditionDTO extends ConditionDTO { - @NotNull public Operator operator; - @NotNull public double range; + @NotNull private Operator operator; + @NotNull private double range; @Override public Condition toModel() { @@ -92,8 +94,8 @@ public class AutomationFastUpdateRequest { public static class ThermostatConditionDTO extends ConditionDTO { - @NotNull public ThermostatCondition.Operator operator; - @NotNull public Thermostat.Mode mode; + @NotNull private ThermostatCondition.Operator operator; + @NotNull private Thermostat.Mode mode; @Override public Condition toModel() { 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 70e1f99..013f067 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 @@ -32,13 +32,13 @@ public class AutomationFastUpdateRequestTest { @DisplayName(" checking range trigger ") public void rangeTriggerDTOTest() { rangeTriggerDTO = new AutomationFastUpdateRequest.RangeTriggerDTO(); - rangeTriggerDTO.operator = Operator.EQUAL; + rangeTriggerDTO.setOperator(Operator.EQUAL); rangeTriggerDTO.deviceId = 420; - rangeTriggerDTO.range = 12; + rangeTriggerDTO.setRange(12); RangeTrigger rangeTrigger = (RangeTrigger) rangeTriggerDTO.toModel(); - assertEquals(rangeTrigger.getOperator(), rangeTriggerDTO.operator); - assertEquals(rangeTrigger.getRange(), rangeTriggerDTO.range); + assertEquals(rangeTrigger.getOperator(), rangeTriggerDTO.getOperator()); + assertEquals(rangeTrigger.getRange(), rangeTriggerDTO.getRange()); assertEquals(rangeTrigger.getDeviceId(), rangeTriggerDTO.deviceId); } @@ -70,13 +70,13 @@ public class AutomationFastUpdateRequestTest { @DisplayName(" checking range condition ") public void rangeConditionDTOTest() { rangeConditionDTO = new AutomationFastUpdateRequest.RangeConditionDTO(); - rangeConditionDTO.operator = Operator.LESS; - rangeConditionDTO.range = 82.01; + rangeConditionDTO.setOperator(Operator.LESS); + rangeConditionDTO.setRange(82.01); rangeConditionDTO.deviceId = 13; RangeCondition rangeCondition = (RangeCondition) rangeConditionDTO.toModel(); - assertEquals(rangeCondition.getOperator(), rangeConditionDTO.operator); - assertEquals(rangeCondition.getRange(), rangeConditionDTO.range); + assertEquals(rangeCondition.getOperator(), rangeConditionDTO.getOperator()); + assertEquals(rangeCondition.getRange(), rangeConditionDTO.getRange()); assertEquals(rangeCondition.getDeviceId(), rangeConditionDTO.deviceId); } @@ -85,13 +85,13 @@ public class AutomationFastUpdateRequestTest { public void thermostatConditionDTOTest() { thermostatConditionDTO = new AutomationFastUpdateRequest.ThermostatConditionDTO(); thermostatConditionDTO.deviceId = 25; - thermostatConditionDTO.operator = ThermostatCondition.Operator.EQUAL; - thermostatConditionDTO.mode = Thermostat.Mode.HEATING; + thermostatConditionDTO.setOperator(ThermostatCondition.Operator.EQUAL); + thermostatConditionDTO.setMode(Thermostat.Mode.HEATING); ThermostatCondition thermostatCondition = (ThermostatCondition) thermostatConditionDTO.toModel(); - assertEquals(thermostatCondition.getMode(), thermostatConditionDTO.mode); - assertEquals(thermostatCondition.getOperator(), thermostatConditionDTO.operator); + assertEquals(thermostatCondition.getMode(), thermostatConditionDTO.getMode()); + assertEquals(thermostatCondition.getOperator(), thermostatConditionDTO.getOperator()); assertEquals(thermostatCondition.getDeviceId(), thermostatConditionDTO.deviceId); } } From bc7b30f3eae67af3f2a7b01e9438bdf4cf35c49f Mon Sep 17 00:00:00 2001 From: "Claudio Maggioni (maggicl)" Date: Sun, 17 May 2020 12:49:40 +0200 Subject: [PATCH 3/3] Fixed lombok in AutomationFastUpdateRequest --- .../dto/AutomationFastUpdateRequest.java | 38 +++++++++---------- .../AutomationFastUpdateRequestTest.java | 36 +++++++++--------- 2 files changed, 37 insertions(+), 37 deletions(-) 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()); } }