Merge branch '75-backend-unit-testing-tommaso' into 'dev'
Resolve "backend-unit-testing" Closes #75 See merge request sa4-2020/the-sanmarinoes/backend!143
This commit is contained in:
commit
7b606307df
2 changed files with 116 additions and 17 deletions
|
@ -6,35 +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
|
||||
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 Operator operator;
|
||||
@NotNull 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;
|
||||
|
@ -42,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();
|
||||
|
@ -57,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;
|
||||
}
|
||||
|
@ -77,13 +79,13 @@ public class AutomationFastUpdateRequest {
|
|||
|
||||
public static class RangeConditionDTO extends ConditionDTO {
|
||||
|
||||
@NotNull Operator operator;
|
||||
@NotNull 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;
|
||||
|
@ -92,13 +94,13 @@ public class AutomationFastUpdateRequest {
|
|||
|
||||
public static class ThermostatConditionDTO extends ConditionDTO {
|
||||
|
||||
@NotNull 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;
|
||||
|
|
|
@ -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.setOn(true);
|
||||
booleanTriggerDTO.setDeviceId(42);
|
||||
BooleanTrigger booleanTrigger = (BooleanTrigger) booleanTriggerDTO.toModel();
|
||||
assertEquals(booleanTrigger.isOn(), booleanTriggerDTO.isOn());
|
||||
assertEquals(booleanTrigger.getDeviceId(), booleanTriggerDTO.getDeviceId());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName(" checking range trigger ")
|
||||
public void rangeTriggerDTOTest() {
|
||||
rangeTriggerDTO = new AutomationFastUpdateRequest.RangeTriggerDTO();
|
||||
rangeTriggerDTO.setOperator(Operator.EQUAL);
|
||||
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.getDeviceId());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName(" checking scene priority ")
|
||||
public void scenePriorityDTOTest() {
|
||||
scenePriorityDTO = new AutomationFastUpdateRequest.ScenePriorityDTO();
|
||||
scenePriorityDTO.setPriority(67);
|
||||
scenePriorityDTO.setSceneId(21);
|
||||
|
||||
ScenePriority scenePriority = scenePriorityDTO.toModel();
|
||||
assertEquals(scenePriority.getPriority(), scenePriorityDTO.getPriority());
|
||||
assertEquals(scenePriority.getSceneId(), scenePriorityDTO.getSceneId());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName(" checking boolean condition ")
|
||||
public void booleanConditionDTOTest() {
|
||||
booleanConditionDTO = new AutomationFastUpdateRequest.BooleanConditionDTO();
|
||||
booleanConditionDTO.setOn(true);
|
||||
booleanConditionDTO.setDeviceId(17);
|
||||
|
||||
BooleanCondition booleanCondition = (BooleanCondition) booleanConditionDTO.toModel();
|
||||
assertEquals(booleanCondition.isOn(), booleanConditionDTO.isOn());
|
||||
assertEquals(booleanCondition.getDeviceId(), booleanConditionDTO.getDeviceId());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName(" checking range condition ")
|
||||
public void rangeConditionDTOTest() {
|
||||
rangeConditionDTO = new AutomationFastUpdateRequest.RangeConditionDTO();
|
||||
rangeConditionDTO.setOperator(Operator.LESS);
|
||||
rangeConditionDTO.setRange(82.01);
|
||||
rangeConditionDTO.setDeviceId(13);
|
||||
|
||||
RangeCondition rangeCondition = (RangeCondition) rangeConditionDTO.toModel();
|
||||
assertEquals(rangeCondition.getOperator(), rangeConditionDTO.getOperator());
|
||||
assertEquals(rangeCondition.getRange(), rangeConditionDTO.getRange());
|
||||
assertEquals(rangeCondition.getDeviceId(), rangeConditionDTO.getDeviceId());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName(" checking thermostat condition ")
|
||||
public void thermostatConditionDTOTest() {
|
||||
thermostatConditionDTO = new AutomationFastUpdateRequest.ThermostatConditionDTO();
|
||||
thermostatConditionDTO.setDeviceId(25);
|
||||
thermostatConditionDTO.setOperator(ThermostatCondition.Operator.EQUAL);
|
||||
thermostatConditionDTO.setMode(Thermostat.Mode.HEATING);
|
||||
|
||||
ThermostatCondition thermostatCondition =
|
||||
(ThermostatCondition) thermostatConditionDTO.toModel();
|
||||
assertEquals(thermostatCondition.getMode(), thermostatConditionDTO.getMode());
|
||||
assertEquals(thermostatCondition.getOperator(), thermostatConditionDTO.getOperator());
|
||||
assertEquals(thermostatCondition.getDeviceId(), thermostatConditionDTO.getDeviceId());
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue