Merge branch 'tests' into 'dev'
Started tests on UserAccountController See merge request sa4-2020/the-sanmarinoes/backend!163
This commit is contained in:
commit
7161760f1f
4 changed files with 48 additions and 6 deletions
|
@ -101,11 +101,7 @@ public class UserAccountController {
|
||||||
toSave.setEmail(registrationData.getEmail());
|
toSave.setEmail(registrationData.getEmail());
|
||||||
userRepository.save(toSave);
|
userRepository.save(toSave);
|
||||||
|
|
||||||
ConfirmationToken token;
|
ConfirmationToken token = new ConfirmationToken(toSave);
|
||||||
do {
|
|
||||||
token = new ConfirmationToken(toSave);
|
|
||||||
} while (confirmationTokenRepository.findByConfirmToken(token.getConfirmToken())
|
|
||||||
!= null);
|
|
||||||
|
|
||||||
confirmationTokenRepository.save(token);
|
confirmationTokenRepository.save(token);
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@ public class Switch extends InputDevice implements BooleanTriggerable, Connectab
|
||||||
})
|
})
|
||||||
@GsonExclude
|
@GsonExclude
|
||||||
@SocketGsonExclude
|
@SocketGsonExclude
|
||||||
|
@EqualsAndHashCode.Exclude
|
||||||
@JoinTable(
|
@JoinTable(
|
||||||
name = "switch_switchable",
|
name = "switch_switchable",
|
||||||
joinColumns = @JoinColumn(name = "switch_id"),
|
joinColumns = @JoinColumn(name = "switch_id"),
|
||||||
|
|
|
@ -9,7 +9,6 @@ import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
/** A device that can be turned either on or off */
|
/** A device that can be turned either on or off */
|
||||||
@Entity
|
@Entity
|
||||||
@EqualsAndHashCode(callSuper = true)
|
|
||||||
@Inheritance(strategy = InheritanceType.JOINED)
|
@Inheritance(strategy = InheritanceType.JOINED)
|
||||||
public abstract class Switchable extends OutputDevice {
|
public abstract class Switchable extends OutputDevice {
|
||||||
|
|
||||||
|
@ -23,6 +22,7 @@ public abstract class Switchable extends OutputDevice {
|
||||||
})
|
})
|
||||||
@GsonExclude
|
@GsonExclude
|
||||||
@SocketGsonExclude
|
@SocketGsonExclude
|
||||||
|
@EqualsAndHashCode.Exclude
|
||||||
private Set<Switch> inputs = new HashSet<>();
|
private Set<Switch> inputs = new HashSet<>();
|
||||||
|
|
||||||
protected Switchable(String kind) {
|
protected Switchable(String kind) {
|
||||||
|
|
|
@ -0,0 +1,45 @@
|
||||||
|
package ch.usi.inf.sa4.sanmarinoes.smarthut.controller;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
import ch.usi.inf.sa4.sanmarinoes.smarthut.dto.UserRegistrationRequest;
|
||||||
|
import ch.usi.inf.sa4.sanmarinoes.smarthut.error.DuplicateRegistrationException;
|
||||||
|
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.User;
|
||||||
|
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.UserRepository;
|
||||||
|
import org.assertj.core.api.Assertions;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
|
import org.mockito.InjectMocks;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.junit.jupiter.MockitoExtension;
|
||||||
|
import org.springframework.security.test.context.support.WithMockUser;
|
||||||
|
|
||||||
|
@ExtendWith(MockitoExtension.class)
|
||||||
|
@WithMockUser(username = "user")
|
||||||
|
public class UserAccountControllerTests {
|
||||||
|
|
||||||
|
@InjectMocks private UserAccountController userAccountController;
|
||||||
|
|
||||||
|
@Mock private UserRepository userRepository;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testRegisterUser() {
|
||||||
|
final UserRegistrationRequest registrationRequest = new UserRegistrationRequest();
|
||||||
|
registrationRequest.setEmail("info@theshell.ch");
|
||||||
|
registrationRequest.setUsername("username");
|
||||||
|
|
||||||
|
when(userRepository.findByEmailIgnoreCase("info@theshell.ch")).thenReturn(null);
|
||||||
|
when(userRepository.findByEmailIgnoreCase("info@vimtok.com")).thenReturn(new User());
|
||||||
|
when(userRepository.findByUsername("username")).thenReturn(new User());
|
||||||
|
when(userRepository.findByUsername("simoneriva")).thenReturn(null);
|
||||||
|
|
||||||
|
Assertions.assertThatThrownBy(() -> userAccountController.registerUser(registrationRequest))
|
||||||
|
.isInstanceOf(DuplicateRegistrationException.class);
|
||||||
|
|
||||||
|
registrationRequest.setUsername("simoneriva");
|
||||||
|
registrationRequest.setEmail("info@vimtok.com");
|
||||||
|
|
||||||
|
Assertions.assertThatThrownBy(() -> userAccountController.registerUser(registrationRequest))
|
||||||
|
.isInstanceOf(DuplicateRegistrationException.class);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue