Merge branch '75-backend-unit-testing' into 'dev'
a couple of tests Closes #75 See merge request sa4-2020/the-sanmarinoes/backend!146
This commit is contained in:
commit
b34ba85cb7
17 changed files with 904 additions and 11 deletions
|
@ -7,9 +7,11 @@ import javax.persistence.Enumerated;
|
|||
import javax.validation.constraints.NotNull;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class SensorSaveRequest {
|
||||
/** The type of this sensor */
|
||||
@NotNull
|
||||
|
|
|
@ -0,0 +1,88 @@
|
|||
package ch.usi.inf.sa4.sanmarinoes.smarthut;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.*;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@DisplayName("automation tests")
|
||||
public class AutomationTests {
|
||||
private Automation automation;
|
||||
|
||||
@BeforeEach
|
||||
private void createAutomation() {
|
||||
this.automation = new Automation();
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("test setName")
|
||||
public void testSetName() {
|
||||
automation.setName("Automation1");
|
||||
assertEquals("Automation1", automation.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("test setId")
|
||||
public void testSetId() {
|
||||
automation.setId(34l);
|
||||
assertEquals(34l, automation.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("test setUserId")
|
||||
public void testSetUserId() {
|
||||
automation.setUserId(43l);
|
||||
assertEquals(43l, automation.getUserId());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("test setUser")
|
||||
public void testSetUser() {
|
||||
User user = new User();
|
||||
automation.setUser(user);
|
||||
user.setUsername("xXcoolNameXx");
|
||||
user.setId(42l);
|
||||
user.setName("John RealName");
|
||||
assertTrue(user.equals(automation.getUser()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("test setTriggers")
|
||||
public void testSetTrigger() {
|
||||
BooleanTrigger trigger1 = new BooleanTrigger();
|
||||
BooleanTrigger trigger2 = new BooleanTrigger();
|
||||
automation.getTriggers().add(trigger1);
|
||||
automation.getTriggers().add(trigger2);
|
||||
assertEquals(2, automation.getTriggers().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("test setScene")
|
||||
public void testSetScene() {
|
||||
ScenePriority priority1 = new ScenePriority();
|
||||
priority1.setPriority(1);
|
||||
ScenePriority priority2 = new ScenePriority();
|
||||
priority2.setPriority(2);
|
||||
ScenePriority priority3 = new ScenePriority();
|
||||
priority3.setPriority(3);
|
||||
automation.getScenes().add(priority1);
|
||||
automation.getScenes().add(priority2);
|
||||
automation.getScenes().add(priority3);
|
||||
assertEquals(3, automation.getScenes().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("test setCondition")
|
||||
public void testSetCondition() {
|
||||
BooleanCondition bool = new BooleanCondition();
|
||||
RangeCondition range = new RangeCondition();
|
||||
bool.setOn(true);
|
||||
range.setRange(10l);
|
||||
automation.getConditions().add(bool);
|
||||
automation.getConditions().add(range);
|
||||
assertEquals(2, automation.getConditions().size());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
package ch.usi.inf.sa4.sanmarinoes.smarthut;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.BooleanCondition;
|
||||
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.Switch;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@DisplayName("BooleanCondition tests")
|
||||
public class BooleanConditionTests {
|
||||
private BooleanCondition condition;
|
||||
|
||||
@BeforeEach
|
||||
private void createCondition() {
|
||||
condition = new BooleanCondition();
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("test setOnFalse")
|
||||
public void testSetOnFalse() {
|
||||
condition.setOn(false);
|
||||
assertFalse(condition.isOn());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("test setOnTrue")
|
||||
public void testSetOnTrue() {
|
||||
condition.setOn(true);
|
||||
assertTrue(condition.isOn());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("test triggeredTrue")
|
||||
public void testTriggeredTrue() {
|
||||
Switch a = new Switch();
|
||||
a.setOn(true);
|
||||
condition.setOn(true);
|
||||
condition.setDevice(a);
|
||||
assertTrue(condition.triggered());
|
||||
condition.setOn(false);
|
||||
assertFalse(condition.triggered());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("test triggeredFalse")
|
||||
public void testTriggeredFalse() {
|
||||
Switch a = new Switch();
|
||||
a.setOn(false);
|
||||
condition.setOn(false);
|
||||
condition.setDevice(a);
|
||||
assertTrue(condition.triggered());
|
||||
condition.setOn(true);
|
||||
assertFalse(condition.triggered());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
package ch.usi.inf.sa4.sanmarinoes.smarthut;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.BooleanTrigger;
|
||||
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.Switch;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@DisplayName("booleantrigger test")
|
||||
public class BooleanTriggerTests {
|
||||
private BooleanTrigger trigger;
|
||||
|
||||
@BeforeEach
|
||||
private void createTrigger() {
|
||||
trigger = new BooleanTrigger();
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("test setOnFalse")
|
||||
public void testSetOnFalse() {
|
||||
trigger.setOn(false);
|
||||
assertFalse(trigger.isOn());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("test setOnTrue")
|
||||
public void testSetOnTrue() {
|
||||
trigger.setOn(true);
|
||||
assertTrue(trigger.isOn());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("test triggeredTrue")
|
||||
public void testTriggeredTrue() {
|
||||
Switch a = new Switch();
|
||||
a.setOn(true);
|
||||
trigger.setOn(true);
|
||||
trigger.setDevice(a);
|
||||
assertTrue(trigger.triggered());
|
||||
trigger.setOn(false);
|
||||
assertFalse(trigger.triggered());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("test triggeredFalse")
|
||||
public void testTriggeredFalse() {
|
||||
Switch a = new Switch();
|
||||
a.setOn(false);
|
||||
trigger.setOn(false);
|
||||
trigger.setDevice(a);
|
||||
assertTrue(trigger.triggered());
|
||||
trigger.setOn(true);
|
||||
assertFalse(trigger.triggered());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
package ch.usi.inf.sa4.sanmarinoes.smarthut;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.BooleanCondition;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@DisplayName("Condition tests")
|
||||
public class ConditionTests {
|
||||
private BooleanCondition condition;
|
||||
|
||||
@BeforeEach
|
||||
private void createCondition() {
|
||||
this.condition = new BooleanCondition();
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("test automationId")
|
||||
public void testSetAutomationId() {
|
||||
condition.setAutomationId(32l);
|
||||
assertEquals(32l, condition.getAutomationId());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("test getKind")
|
||||
public void testGetKind() {
|
||||
assertEquals("booleanCondition", condition.getKind());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("test setId")
|
||||
public void testSetId() {
|
||||
condition.setId(11);
|
||||
assertEquals(11, condition.getId());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
package ch.usi.inf.sa4.sanmarinoes.smarthut;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.ConfirmationToken;
|
||||
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.User;
|
||||
import java.util.Date;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@DisplayName("ConfirmationToken tests")
|
||||
public class ConfirmationTokenTests {
|
||||
private ConfirmationToken token;
|
||||
|
||||
@BeforeEach
|
||||
private void createToke() {
|
||||
User user = new User();
|
||||
user.setName("Tizio Sempronio");
|
||||
user.setId(42l);
|
||||
user.setUsername("xXCoolUserNameXx");
|
||||
user.setEmail("realMail@service.ext");
|
||||
user.setPassword("alpaca");
|
||||
this.token = new ConfirmationToken(user);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("test setId")
|
||||
public void testSetId() {
|
||||
this.token.setId(34l);
|
||||
assertEquals(34l, token.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("test getUSerId")
|
||||
public void testGetUserId() {
|
||||
assertEquals(42l, token.getUser().getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("test setResetPassword")
|
||||
public void testSetResetPassword() {
|
||||
assertFalse(token.isResetPassword());
|
||||
token.setResetPassword(true);
|
||||
assertTrue(token.isResetPassword());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("test setTimeStamp")
|
||||
public void testSetTimeStamp() {
|
||||
Date date = new Date();
|
||||
date.setTime(86400000l);
|
||||
token.setCreatedDate(date);
|
||||
assertEquals(date, token.getCreatedDate());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("test setConfirmToken")
|
||||
public void testSetConfirmTOken() {
|
||||
assertNotEquals(null, token.getConfirmToken());
|
||||
String newToken = "newConfirmationToken";
|
||||
token.setConfirmToken(newToken);
|
||||
assertEquals(newToken, token.getConfirmToken());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,82 @@
|
|||
package ch.usi.inf.sa4.sanmarinoes.smarthut;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.*;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@DisplayName("Dimmable tests")
|
||||
public class DimmableTests {
|
||||
private DimmableLight dimmable;
|
||||
|
||||
@BeforeEach
|
||||
private void createDimmable() {
|
||||
dimmable = new DimmableLight();
|
||||
dimmable.setId(42l);
|
||||
KnobDimmer dimmer1 = new KnobDimmer();
|
||||
dimmer1.setLightIntensity(75);
|
||||
ButtonDimmer dimmer2 = new ButtonDimmer();
|
||||
dimmer2.setName("button");
|
||||
Set<Dimmer> set = new HashSet<Dimmer>();
|
||||
set.add(dimmer1);
|
||||
set.add(dimmer2);
|
||||
dimmable.setDimmers(set);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("test getDimmers")
|
||||
public void testGetDimmers() {
|
||||
assertEquals(2, dimmable.getDimmers().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("test intensity and old Intensity")
|
||||
public void testIntensities() {
|
||||
assertEquals(0, dimmable.getIntensity());
|
||||
dimmable.setIntensity(13);
|
||||
dimmable.setIntensity(24);
|
||||
assertEquals(24, dimmable.getIntensity());
|
||||
assertEquals(24, dimmable.getOldIntensity());
|
||||
dimmable.setOldIntensity(99);
|
||||
assertEquals(99, dimmable.getOldIntensity());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("test setOn")
|
||||
public void testIsOn() {
|
||||
assertFalse(dimmable.isOn());
|
||||
dimmable.setOn(true);
|
||||
assertTrue(dimmable.isOn());
|
||||
assertNotEquals(0, dimmable.getIntensity());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("test readStateAndSet")
|
||||
public void testReadStateAndSet() {
|
||||
DimmableState state = new DimmableState();
|
||||
state.setIntensity(78);
|
||||
dimmable.readStateAndSet(state);
|
||||
assertEquals(78, dimmable.getIntensity());
|
||||
assertEquals(78, dimmable.getOldIntensity());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("test cloneState")
|
||||
public void testCloneState() {
|
||||
dimmable.setId(27);
|
||||
DimmableState state = (DimmableState) dimmable.cloneState();
|
||||
assertEquals(state.getDeviceId(), dimmable.getId());
|
||||
assertEquals(state.getIntensity(), dimmable.getIntensity());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("test readTriggerState")
|
||||
public void testReadTriggerState() {
|
||||
dimmable.setIntensity(84);
|
||||
assertEquals(84, dimmable.readTriggerState());
|
||||
}
|
||||
}
|
|
@ -3,6 +3,7 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut;
|
|||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.DimmableLight;
|
||||
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.Icon;
|
||||
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.Room;
|
||||
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.User;
|
||||
import javax.swing.*;
|
||||
|
@ -75,7 +76,7 @@ public class RoomTests {
|
|||
@DisplayName("test Icon")
|
||||
public void testIcon() {
|
||||
// ImageIcon image = new ImageIcon("file","description");
|
||||
room.setIcon(null);
|
||||
assertEquals(null, room.getIcon());
|
||||
room.setIcon(Icon.FEMALE);
|
||||
assertEquals("female", room.getIcon().toString());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
package ch.usi.inf.sa4.sanmarinoes.smarthut;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import ch.usi.inf.sa4.sanmarinoes.smarthut.dto.SceneSaveRequest;
|
||||
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.Icon;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@DisplayName("SceneSaveRequest tests")
|
||||
public class SceneSaveRequestTests {
|
||||
|
||||
private SceneSaveRequest scene;
|
||||
|
||||
@BeforeEach
|
||||
private void createSceneSaveRequest() {
|
||||
scene = new SceneSaveRequest();
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("guestAccessEnable")
|
||||
public void testGuestAccess() {
|
||||
assertFalse(scene.isGuestAccessEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("set guestAccess")
|
||||
public void testSetGuestAccess() {
|
||||
scene.setGuestAccessEnabled(true);
|
||||
assertTrue(scene.isGuestAccessEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("test getId")
|
||||
public void testGetId() {
|
||||
assertEquals(0l, scene.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("test getName")
|
||||
public void testGetName() {
|
||||
scene.setName("Roberto");
|
||||
assertEquals("Roberto", scene.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("test getIcon")
|
||||
public void testGetIcon() {
|
||||
scene.setIcon(Icon.FEMALE);
|
||||
assertEquals("female", scene.getIcon().toString());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,83 @@
|
|||
package ch.usi.inf.sa4.sanmarinoes.smarthut;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
||||
import ch.usi.inf.sa4.sanmarinoes.smarthut.dto.SensorSaveRequest;
|
||||
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.Sensor;
|
||||
import java.math.BigDecimal;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@DisplayName("SensorSaveRequest tests")
|
||||
public class SensorSaveRequestTests {
|
||||
|
||||
private SensorSaveRequest sensor;
|
||||
|
||||
@BeforeEach
|
||||
public void createSensorSaveRequest() {
|
||||
this.sensor = new SensorSaveRequest();
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("test setRoomId")
|
||||
public void testSetRoomId() {
|
||||
sensor.setRoomId(42L);
|
||||
assertEquals(42L, sensor.getRoomId());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("test constructor")
|
||||
public void testConstructorNotEmpty() {
|
||||
SensorSaveRequest newSaveRequest =
|
||||
new SensorSaveRequest(Sensor.SensorType.HUMIDITY, new BigDecimal(12), 12L, "name");
|
||||
assertNotNull(newSaveRequest.getSensor());
|
||||
assertNotNull(newSaveRequest.getName());
|
||||
assertNotNull(newSaveRequest.getRoomId());
|
||||
assertNotNull(newSaveRequest.getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("test setName")
|
||||
public void testSetName() {
|
||||
sensor.setName("Giovanni");
|
||||
assertEquals("Giovanni", sensor.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("test setValue")
|
||||
public void testSetValue() {
|
||||
sensor.setValue(new BigDecimal(42));
|
||||
assertEquals(new BigDecimal(42), sensor.getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("test set to TEMPERATURE")
|
||||
public void testSetToTemperature() {
|
||||
sensor.setSensor(Sensor.SensorType.TEMPERATURE);
|
||||
assertEquals(Sensor.SensorType.TEMPERATURE, sensor.getSensor());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("test set to HUMIDITY")
|
||||
public void testSetToHumidity() {
|
||||
sensor.setSensor(Sensor.SensorType.HUMIDITY);
|
||||
assertEquals(Sensor.SensorType.HUMIDITY, sensor.getSensor());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("test set to LIGHT")
|
||||
public void testSetToLight() {
|
||||
sensor.setSensor(Sensor.SensorType.LIGHT);
|
||||
assertEquals(Sensor.SensorType.LIGHT, sensor.getSensor());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("test SensorType")
|
||||
public void testSetSensorType() {
|
||||
assertEquals("TEMPERATURE", Sensor.SensorType.TEMPERATURE.name());
|
||||
assertEquals("HUMIDITY", Sensor.SensorType.HUMIDITY.name());
|
||||
assertEquals("LIGHT", Sensor.SensorType.LIGHT.name());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
package ch.usi.inf.sa4.sanmarinoes.smarthut;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import ch.usi.inf.sa4.sanmarinoes.smarthut.dto.SwitchOperationRequest;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@DisplayName("switchOperationRequest tests")
|
||||
public class SwitchOperationRequestTests {
|
||||
private SwitchOperationRequest request;
|
||||
|
||||
@BeforeEach
|
||||
private void createRequest() {
|
||||
this.request = new SwitchOperationRequest();
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("test setId")
|
||||
public void testSetId() {
|
||||
request.setId(42l);
|
||||
assertEquals(42l, request.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("test setType")
|
||||
public void testSetTypeOFF() {
|
||||
request.setType(SwitchOperationRequest.OperationType.OFF);
|
||||
assertEquals(SwitchOperationRequest.OperationType.OFF, request.getType());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("test setType")
|
||||
public void testSetTypeON() {
|
||||
request.setType(SwitchOperationRequest.OperationType.ON);
|
||||
assertEquals(SwitchOperationRequest.OperationType.ON, request.getType());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("test setType")
|
||||
public void testSetTypeTOGGLE() {
|
||||
request.setType(SwitchOperationRequest.OperationType.TOGGLE);
|
||||
assertEquals(SwitchOperationRequest.OperationType.TOGGLE, request.getType());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
package ch.usi.inf.sa4.sanmarinoes.smarthut;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import ch.usi.inf.sa4.sanmarinoes.smarthut.dto.SwitchableSaveRequest;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@DisplayName("SwitchableSaveRequest tests")
|
||||
public class SwitchableSaveRequestTests {
|
||||
|
||||
private SwitchableSaveRequest saveRequest;
|
||||
|
||||
@BeforeEach
|
||||
private void createSaveRequest() {
|
||||
this.saveRequest = new SwitchableSaveRequest();
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("test setRoomId")
|
||||
public void testSetRoomId() {
|
||||
saveRequest.setRoomId(42l);
|
||||
assertEquals(42l, saveRequest.getRoomId());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("test setName")
|
||||
public void testSetName() {
|
||||
saveRequest.setName("Giovanni");
|
||||
assertEquals("Giovanni", saveRequest.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("test isOn()")
|
||||
public void inOnTest() {
|
||||
assertFalse(saveRequest.isOn());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("test setOn(true) ")
|
||||
public void setOnTestTrue() {
|
||||
saveRequest.setOn(true);
|
||||
assertTrue(saveRequest.isOn());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("test setOn(false) ")
|
||||
public void setOnTestFalse() {
|
||||
saveRequest.setOn(false);
|
||||
assertFalse(saveRequest.isOn());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("test setId")
|
||||
public void testSetId() {
|
||||
saveRequest.setId(300771l);
|
||||
assertEquals(300771l, saveRequest.getId());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
package ch.usi.inf.sa4.sanmarinoes.smarthut;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import ch.usi.inf.sa4.sanmarinoes.smarthut.dto.SwitchableStateSaveRequest;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@DisplayName("switchableStateSaveRequest tests")
|
||||
public class SwitchableStateSaveRequestTests {
|
||||
private SwitchableStateSaveRequest saveRequest;
|
||||
|
||||
@BeforeEach
|
||||
public void createSwitchableStateSaveRequest() {
|
||||
this.saveRequest = new SwitchableStateSaveRequest();
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("test isOn()")
|
||||
public void isOnTest() {
|
||||
assertFalse(saveRequest.isOn());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("test setOn(true) ")
|
||||
public void setOnTestTrue() {
|
||||
saveRequest.setOn(true);
|
||||
assertTrue(saveRequest.isOn());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("test setOn(false) ")
|
||||
public void setOnTestFalse() {
|
||||
saveRequest.setOn(false);
|
||||
assertFalse(saveRequest.isOn());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("test setId")
|
||||
public void testSetId() {
|
||||
assertEquals(null, saveRequest.getId());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
package ch.usi.inf.sa4.sanmarinoes.smarthut;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import ch.usi.inf.sa4.sanmarinoes.smarthut.dto.ThermostatConditionSaveRequest;
|
||||
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.Thermostat;
|
||||
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.ThermostatCondition;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@DisplayName("ThermostatConditionSaveRequest tests")
|
||||
public class ThermostatConditionSaveRequestTests {
|
||||
|
||||
private ThermostatConditionSaveRequest saveRequest;
|
||||
|
||||
@BeforeEach
|
||||
private void createSaveRequest() {
|
||||
this.saveRequest = new ThermostatConditionSaveRequest();
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("test setDeviceId")
|
||||
public void testSetDeviceId() {
|
||||
this.saveRequest.setDeviceId(42l);
|
||||
assertEquals(42l, saveRequest.getDeviceId());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("test setAutomationId")
|
||||
public void testSetAutomationId() {
|
||||
this.saveRequest.setAutomationId(42l);
|
||||
assertEquals(42l, saveRequest.getAutomationId());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("test setOperator")
|
||||
public void testSetOperatorEqual() {
|
||||
saveRequest.setOperator(ThermostatCondition.Operator.EQUAL);
|
||||
assertEquals(ThermostatCondition.Operator.EQUAL, saveRequest.getOperator());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("test setOperator")
|
||||
public void testSetOperatorNotEqual() {
|
||||
saveRequest.setOperator(ThermostatCondition.Operator.NOTEQUAL);
|
||||
assertEquals(ThermostatCondition.Operator.NOTEQUAL, saveRequest.getOperator());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("test setMode")
|
||||
public void testSetMode() {
|
||||
saveRequest.setMode(Thermostat.Mode.HEATING);
|
||||
assertEquals(Thermostat.Mode.HEATING, saveRequest.getMode());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("test getId")
|
||||
public void testGetId() {
|
||||
assertEquals(0l, saveRequest.getId());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,82 @@
|
|||
package ch.usi.inf.sa4.sanmarinoes.smarthut;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
|
||||
import ch.usi.inf.sa4.sanmarinoes.smarthut.dto.ThermostatSaveRequest;
|
||||
import java.math.BigDecimal;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@DisplayName("ThermostatSaveRequest tests")
|
||||
public class ThermostatSaveRequestTests {
|
||||
private ThermostatSaveRequest saveRequest;
|
||||
|
||||
@BeforeEach
|
||||
private void createSaveRequest() {
|
||||
saveRequest = new ThermostatSaveRequest();
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("test setRoomId")
|
||||
public void testSetRoomId() {
|
||||
saveRequest.setRoomId(42l);
|
||||
assertEquals(42l, saveRequest.getRoomId());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("test setName")
|
||||
public void testSetName() {
|
||||
saveRequest.setName("Giovanni");
|
||||
assertEquals("Giovanni", saveRequest.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("test isOn()")
|
||||
public void inOnTest() {
|
||||
assertFalse(saveRequest.isTurnOn());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("test setOn(true) ")
|
||||
public void setOnTestTrue() {
|
||||
saveRequest.setTurnOn(true);
|
||||
assertTrue(saveRequest.isTurnOn());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("test setOn(false) ")
|
||||
public void setOnTestFalse() {
|
||||
saveRequest.setTurnOn(false);
|
||||
assertFalse(saveRequest.isTurnOn());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("test setId")
|
||||
public void testSetId() {
|
||||
saveRequest.setId(17l);
|
||||
assertEquals(17l, saveRequest.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("test setExternalSensor true")
|
||||
public void testExternalSensorTrue() {
|
||||
saveRequest.setUseExternalSensors(true);
|
||||
assertTrue(saveRequest.isUseExternalSensors());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("test setExternalSensor false")
|
||||
public void testExternalSensorFalse() {
|
||||
saveRequest.setUseExternalSensors(false);
|
||||
assertFalse(saveRequest.isUseExternalSensors());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("test targetTemperature")
|
||||
public void testTargetTemperature() {
|
||||
saveRequest.setTargetTemperature(new BigDecimal(23));
|
||||
assertEquals(new BigDecimal(23), saveRequest.getTargetTemperature());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
package ch.usi.inf.sa4.sanmarinoes.smarthut;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import ch.usi.inf.sa4.sanmarinoes.smarthut.dto.UserRegistrationRequest;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@DisplayName("userRegistrationRequest tests")
|
||||
public class UserRegistrationRequestTests {
|
||||
private UserRegistrationRequest request;
|
||||
|
||||
@BeforeEach
|
||||
private void createRequest() {
|
||||
request = new UserRegistrationRequest();
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("test setName")
|
||||
public void testSetName() {
|
||||
request.setName("Tizio Sempronio");
|
||||
assertEquals("Tizio Sempronio", request.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("test setUserName")
|
||||
public void testUserName() {
|
||||
request.setUsername("xXDarkAngelCraftXx");
|
||||
assertEquals("xXDarkAngelCraftXx", request.getUsername());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("test setPassword")
|
||||
public void testPassword() {
|
||||
request.setPassword("password123");
|
||||
assertEquals("password123", request.getPassword());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("test setEmail")
|
||||
public void testEmail() {
|
||||
request.setEmail("fakemail@service.ussr");
|
||||
assertEquals("fakemail@service.ussr", request.getEmail());
|
||||
}
|
||||
}
|
|
@ -4,18 +4,39 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
|||
|
||||
import ch.usi.inf.sa4.sanmarinoes.smarthut.dto.UserResponse;
|
||||
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.User;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@DisplayName("test UserResponse")
|
||||
public class UserResponseTests {
|
||||
private UserResponse response;
|
||||
private User user;
|
||||
|
||||
@BeforeEach
|
||||
private void createUser() {
|
||||
user = new User();
|
||||
user.setName("John RealName");
|
||||
user.setId(29l);
|
||||
user.setUsername("pseudonym");
|
||||
response = response.fromUser(user);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUserResponse() {
|
||||
User u = new User();
|
||||
u.setEmail("email@example.com");
|
||||
u.setId(42L);
|
||||
u.setUsername("username");
|
||||
UserResponse us = UserResponse.fromUser(u);
|
||||
assertEquals(us.getName(), u.getName());
|
||||
assertEquals(us.getId(), u.getId());
|
||||
assertEquals(us.getUsername(), u.getUsername());
|
||||
@DisplayName("test getId")
|
||||
public void testGetId() {
|
||||
assertEquals(29l, response.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("test getUsername")
|
||||
public void testGetUsername() {
|
||||
assertEquals("pseudonym", response.getUsername());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("test getName")
|
||||
public void testGetaName() {
|
||||
assertEquals("John RealName", response.getName());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue