Fixed tests
This commit is contained in:
parent
a843786759
commit
c3b91cd1d1
5 changed files with 17 additions and 22 deletions
|
@ -29,7 +29,7 @@ public class ButtonDimmerController
|
||||||
ButtonDimmerRepository inputRepository,
|
ButtonDimmerRepository inputRepository,
|
||||||
DimmableRepository<Dimmable> outputRepository,
|
DimmableRepository<Dimmable> outputRepository,
|
||||||
DeviceService deviceService) {
|
DeviceService deviceService) {
|
||||||
super(inputRepository, outputRepository);
|
super(inputRepository, outputRepository, deviceService);
|
||||||
this.deviceService = deviceService;
|
this.deviceService = deviceService;
|
||||||
this.buttonDimmerRepository = inputRepository;
|
this.buttonDimmerRepository = inputRepository;
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,6 @@ import java.security.Principal;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
@ -54,7 +53,7 @@ public abstract class InputDeviceConnectionController<
|
||||||
return outputReposiory;
|
return outputReposiory;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Autowired private DeviceService deviceService;
|
private final DeviceService deviceService;
|
||||||
|
|
||||||
private final DeviceRepository<I> inputRepository;
|
private final DeviceRepository<I> inputRepository;
|
||||||
|
|
||||||
|
@ -67,9 +66,12 @@ public abstract class InputDeviceConnectionController<
|
||||||
* @param outputRepository the output device repository
|
* @param outputRepository the output device repository
|
||||||
*/
|
*/
|
||||||
protected InputDeviceConnectionController(
|
protected InputDeviceConnectionController(
|
||||||
DeviceRepository<I> inputRepository, DeviceRepository<O> outputRepository) {
|
DeviceRepository<I> inputRepository,
|
||||||
|
DeviceRepository<O> outputRepository,
|
||||||
|
DeviceService deviceService) {
|
||||||
this.inputRepository = inputRepository;
|
this.inputRepository = inputRepository;
|
||||||
this.outputReposiory = outputRepository;
|
this.outputReposiory = outputRepository;
|
||||||
|
this.deviceService = deviceService;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Connection checkConnectionIDs(Long inputId, List<Long> outputs, String username)
|
private Connection checkConnectionIDs(Long inputId, List<Long> outputs, String username)
|
||||||
|
|
|
@ -28,7 +28,7 @@ public class KnobDimmerController extends InputDeviceConnectionController<KnobDi
|
||||||
KnobDimmerRepository inputRepository,
|
KnobDimmerRepository inputRepository,
|
||||||
DimmableRepository<Dimmable> outputRepository,
|
DimmableRepository<Dimmable> outputRepository,
|
||||||
DeviceService deviceService) {
|
DeviceService deviceService) {
|
||||||
super(inputRepository, outputRepository);
|
super(inputRepository, outputRepository, deviceService);
|
||||||
this.knobDimmerRepository = inputRepository;
|
this.knobDimmerRepository = inputRepository;
|
||||||
this.deviceService = deviceService;
|
this.deviceService = deviceService;
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,7 @@ public class SwitchController extends InputDeviceConnectionController<Switch, Sw
|
||||||
SwitchRepository inputRepository,
|
SwitchRepository inputRepository,
|
||||||
SwitchableRepository<Switchable> outputRepository,
|
SwitchableRepository<Switchable> outputRepository,
|
||||||
DeviceService deviceService) {
|
DeviceService deviceService) {
|
||||||
super(inputRepository, outputRepository);
|
super(inputRepository, outputRepository, deviceService);
|
||||||
this.deviceService = deviceService;
|
this.deviceService = deviceService;
|
||||||
this.switchRepository = inputRepository;
|
this.switchRepository = inputRepository;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,18 +1,13 @@
|
||||||
package ch.usi.inf.sa4.sanmarinoes.smarthut.controller;
|
package ch.usi.inf.sa4.sanmarinoes.smarthut.controller;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||||
import static org.mockito.ArgumentMatchers.anyIterable;
|
import static org.mockito.ArgumentMatchers.anyIterable;
|
||||||
import static org.mockito.ArgumentMatchers.anyLong;
|
import static org.mockito.ArgumentMatchers.anyLong;
|
||||||
import static org.mockito.ArgumentMatchers.anyString;
|
import static org.mockito.ArgumentMatchers.anyString;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import ch.usi.inf.sa4.sanmarinoes.smarthut.error.NotFoundException;
|
import ch.usi.inf.sa4.sanmarinoes.smarthut.error.NotFoundException;
|
||||||
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.DeviceRepository;
|
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.*;
|
||||||
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.Dimmable;
|
|
||||||
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.DimmableLight;
|
|
||||||
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.KnobDimmer;
|
|
||||||
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.KnobDimmerRepository;
|
|
||||||
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.OutputDevice;
|
|
||||||
import ch.usi.inf.sa4.sanmarinoes.smarthut.service.DeviceService;
|
import ch.usi.inf.sa4.sanmarinoes.smarthut.service.DeviceService;
|
||||||
import java.security.Principal;
|
import java.security.Principal;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -20,7 +15,6 @@ import java.util.List;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.api.extension.ExtendWith;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.mockito.InjectMocks;
|
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.junit.jupiter.MockitoExtension;
|
import org.mockito.junit.jupiter.MockitoExtension;
|
||||||
import org.springframework.security.test.context.support.WithMockUser;
|
import org.springframework.security.test.context.support.WithMockUser;
|
||||||
|
@ -29,15 +23,13 @@ import org.springframework.security.test.context.support.WithMockUser;
|
||||||
@WithMockUser(username = "user")
|
@WithMockUser(username = "user")
|
||||||
public class InputDeviceConnectionControllerTests {
|
public class InputDeviceConnectionControllerTests {
|
||||||
|
|
||||||
@InjectMocks KnobDimmerController knobDimmerController;
|
@Mock private DeviceService deviceService;
|
||||||
|
|
||||||
@Mock DeviceService deviceService;
|
@Mock private KnobDimmerRepository inputRepository;
|
||||||
|
|
||||||
@Mock KnobDimmerRepository knobDimmerRepository;
|
@Mock private DimmableRepository<Dimmable> outputRepository;
|
||||||
|
|
||||||
@Mock DeviceRepository<KnobDimmer> inputRepository;
|
private KnobDimmerController knobDimmerController;
|
||||||
|
|
||||||
@Mock DeviceRepository<Dimmable> outputRepository;
|
|
||||||
|
|
||||||
@Mock private Principal mockPrincipal;
|
@Mock private Principal mockPrincipal;
|
||||||
|
|
||||||
|
@ -64,8 +56,9 @@ public class InputDeviceConnectionControllerTests {
|
||||||
List<Long> l = new ArrayList<>();
|
List<Long> l = new ArrayList<>();
|
||||||
l.add(10L);
|
l.add(10L);
|
||||||
|
|
||||||
List<OutputDevice> toCheck = knobDimmerController.addLight(1L, l, mockPrincipal);
|
knobDimmerController =
|
||||||
|
new KnobDimmerController(inputRepository, outputRepository, deviceService);
|
||||||
|
|
||||||
assertEquals(l.get(0), toCheck.get(0));
|
assertDoesNotThrow(() -> knobDimmerController.addLight(1L, l, mockPrincipal));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue