Merge branch '93-miscellaneous-tests' into 'dev'
Resolve "miscellaneous tests" Closes #93 See merge request sa4-2020/the-sanmarinoes/backend!194
This commit is contained in:
commit
86c87ece65
7 changed files with 89 additions and 6 deletions
|
@ -44,8 +44,6 @@ public class SensorController {
|
|||
newSensor.setName(s.getName());
|
||||
newSensor.setRoomId(s.getRoomId());
|
||||
newSensor.setValue(s.getValue());
|
||||
// newSensor.setError(s.getError());
|
||||
// newSensor.setTypical(s.getTypical());
|
||||
|
||||
return deviceService.saveAsOwner(newSensor, principal.getName());
|
||||
}
|
||||
|
|
|
@ -87,10 +87,6 @@ public class Sensor extends InputDevice implements RangeTriggerable {
|
|||
this.typical = typical;
|
||||
}
|
||||
|
||||
public void setTypicalNull() {
|
||||
this.typical = null;
|
||||
}
|
||||
|
||||
public Sensor() {
|
||||
super("sensor");
|
||||
}
|
||||
|
|
|
@ -108,4 +108,25 @@ public class SensorControllerTests {
|
|||
assertThat(sensorController.updateValue(1L, BigDecimal.valueOf(30), mockPrincipal))
|
||||
.isSameAs(s);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateSimulation() throws NotFoundException {
|
||||
final Sensor s = new Sensor();
|
||||
when(sensorRepository.findByIdAndUsername(1L, "user")).thenReturn(Optional.of(s));
|
||||
when(sensorRepository.findByIdAndUsername(2L, "user")).thenReturn(Optional.empty());
|
||||
when(sensorService.updateSimulationFromSensor(
|
||||
s, BigDecimal.valueOf(30), BigDecimal.valueOf(10)))
|
||||
.thenAnswer(
|
||||
i -> {
|
||||
s.setError(i.getArgument(1));
|
||||
s.setTypical(i.getArgument(2));
|
||||
return s;
|
||||
});
|
||||
assertThatThrownBy(() -> sensorController.updateValue(2L, BigDecimal.ZERO, mockPrincipal))
|
||||
.isInstanceOf(NotFoundException.class);
|
||||
assertThat(
|
||||
sensorController.updateSimulation(
|
||||
1L, BigDecimal.valueOf(30), BigDecimal.valueOf(10), mockPrincipal))
|
||||
.isSameAs(s);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -63,6 +63,13 @@ public class ThermostatControllerTests {
|
|||
assertThat(toCheck.isUseExternalSensors()).isEqualTo(request.isUseExternalSensors());
|
||||
assertThat(toCheck.getName()).isEqualTo(request.getName());
|
||||
assertThat(toCheck.getRoomId()).isEqualTo(request.getRoomId());
|
||||
if (request.getErr() != null) {
|
||||
assertThat(toCheck.getErr()).isEqualTo(request.getErr());
|
||||
}
|
||||
|
||||
if (request.getTypical() != null) {
|
||||
assertThat(toCheck.getTypical()).isEqualTo(request.getTypical());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -83,6 +90,8 @@ public class ThermostatControllerTests {
|
|||
toSend.setTargetTemperature(new BigDecimal(40));
|
||||
toSend.setName("Thermostat Test");
|
||||
toSend.setUseExternalSensors(true);
|
||||
toSend.setErr(BigDecimal.valueOf(10));
|
||||
toSend.setTypical(BigDecimal.valueOf(15));
|
||||
|
||||
final Thermostat thermostat = thermostatController.create(toSend, mockPrincipal);
|
||||
|
||||
|
|
|
@ -26,6 +26,22 @@ public class SensorTests {
|
|||
assertEquals(SensorType.LIGHT, sensor.getSensor());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("get and set err")
|
||||
public void getAndSetError() {
|
||||
sensor.setError(BigDecimal.valueOf(10));
|
||||
|
||||
assertEquals(BigDecimal.valueOf(10), sensor.getError());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("get and set typical")
|
||||
public void getAndSetTypical() {
|
||||
sensor.setTypical(BigDecimal.valueOf(10));
|
||||
|
||||
assertEquals(BigDecimal.valueOf(10), sensor.getTypical());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("get and set value")
|
||||
public void getAndSetValue() {
|
||||
|
|
|
@ -2,6 +2,7 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
|
|||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.Thermostat.Mode;
|
||||
import java.math.BigDecimal;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
|
@ -85,12 +86,34 @@ public class ThermostatTests {
|
|||
assertEquals(new BigDecimal(42), thermostat.getInternalSensorTemperature());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("test err ")
|
||||
public void errTest() {
|
||||
thermostat.setErr(BigDecimal.valueOf(10));
|
||||
assertEquals(BigDecimal.valueOf(10), thermostat.getErr());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("test typical ")
|
||||
public void typicalTest() {
|
||||
thermostat.setTypical(BigDecimal.valueOf(10));
|
||||
assertEquals(BigDecimal.valueOf(10), thermostat.getTypical());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("test triggerState")
|
||||
public void testTriggerState() {
|
||||
assertFalse(thermostat.readTriggerState());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("test triggerState")
|
||||
public void testTriggerStateTrue() {
|
||||
thermostat.setMode(Mode.COOLING);
|
||||
|
||||
assertTrue(thermostat.readTriggerState());
|
||||
}
|
||||
|
||||
// for obvious reasons I am not gonna check all the possible combinations of toString()
|
||||
@Test
|
||||
@DisplayName("test to string")
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
package ch.usi.inf.sa4.sanmarinoes.smarthut.service;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.mockito.ArgumentMatchers.*;
|
||||
import static org.mockito.Mockito.doNothing;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.*;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
@ -22,6 +24,8 @@ public class SceneServiceTests {
|
|||
|
||||
@Mock private SceneRepository sceneRepository;
|
||||
|
||||
@Mock private StateRepository<State> stateRepository;
|
||||
|
||||
@Mock private DevicePropagationService deviceService;
|
||||
|
||||
@Mock private DevicePopulationService devicePopulationService;
|
||||
|
@ -56,4 +60,20 @@ public class SceneServiceTests {
|
|||
assertThat(sceneService.applyAsGuest(s, "user", 42L)).containsExactly(d);
|
||||
assertThat(d.getIntensity()).isEqualTo(40);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCopyStates() {
|
||||
|
||||
final State state = new DimmableState();
|
||||
|
||||
final Scene sceneFrom = new Scene();
|
||||
sceneFrom.getStates().add(state);
|
||||
final Scene sceneTo = new Scene();
|
||||
|
||||
when(stateRepository.save(any(State.class))).thenReturn(state);
|
||||
|
||||
List<State> s = sceneService.copyStates(sceneTo, sceneFrom);
|
||||
|
||||
assertEquals(s.get(0), state);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue