PAN-48 Added dependency on utilities to the persistence project
This commit is contained in:
@@ -45,6 +45,7 @@ allprojects {
|
|||||||
}
|
}
|
||||||
|
|
||||||
subprojects {
|
subprojects {
|
||||||
|
apply plugin: 'java'
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
}
|
}
|
||||||
@@ -108,6 +109,12 @@ dependencies {
|
|||||||
apt 'org.projectlombok:lombok:1.18.4'
|
apt 'org.projectlombok:lombok:1.18.4'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
project(':persistence') {
|
||||||
|
dependencies {
|
||||||
|
compile project(':utilities')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
test {
|
test {
|
||||||
if (System.properties['test.profile'] != 'integrationTest') {
|
if (System.properties['test.profile'] != 'integrationTest') {
|
||||||
exclude '**/*integrationTest*'
|
exclude '**/*integrationTest*'
|
||||||
|
|||||||
+12
-12
@@ -1,6 +1,6 @@
|
|||||||
package edu.msudenver.tsp.persistence;
|
package edu.msudenver.tsp.persistence;
|
||||||
|
|
||||||
import edu.msudenver.tsp.persistence.dto.AccountsDto;
|
import edu.msudenver.tsp.persistence.dto.AccountDto;
|
||||||
import edu.msudenver.tsp.persistence.repository.AccountsRepository;
|
import edu.msudenver.tsp.persistence.repository.AccountsRepository;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
@@ -19,8 +19,8 @@ public class AccountsIntegrationTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCRUDFunctionality() {
|
public void testCRUDFunctionality() {
|
||||||
final AccountsDto accountsDto = createAccount();
|
final AccountDto accountDto = createAccount();
|
||||||
final AccountsDto savedAccount = accountsRepository.save(accountsDto);
|
final AccountDto savedAccount = accountsRepository.save(accountDto);
|
||||||
|
|
||||||
assertNotNull(savedAccount);
|
assertNotNull(savedAccount);
|
||||||
assertEquals(Integer.valueOf(0), savedAccount.getVersion());
|
assertEquals(Integer.valueOf(0), savedAccount.getVersion());
|
||||||
@@ -33,25 +33,25 @@ public class AccountsIntegrationTest {
|
|||||||
|
|
||||||
savedAccount.setPassword("Test Update");
|
savedAccount.setPassword("Test Update");
|
||||||
|
|
||||||
final AccountsDto updatedAccount = accountsRepository.save(savedAccount);
|
final AccountDto updatedAccount = accountsRepository.save(savedAccount);
|
||||||
|
|
||||||
assertEquals("Test username", savedAccount.getUsername());
|
assertEquals("Test username", savedAccount.getUsername());
|
||||||
assertEquals("Test Update", savedAccount.getPassword());
|
assertEquals("Test Update", savedAccount.getPassword());
|
||||||
assertTrue(savedAccount.isAdministratorStatus());
|
assertTrue(savedAccount.isAdministratorStatus());
|
||||||
assertEquals(updatedAccount.getId(), id);
|
assertEquals(updatedAccount.getId(), id);
|
||||||
|
|
||||||
accountsRepository.delete(accountsDto);
|
accountsRepository.delete(accountDto);
|
||||||
final Optional<AccountsDto> deletedAccount = accountsRepository.findById(id);
|
final Optional<AccountDto> deletedAccount = accountsRepository.findById(id);
|
||||||
assertFalse(deletedAccount.isPresent());
|
assertFalse(deletedAccount.isPresent());
|
||||||
}
|
}
|
||||||
|
|
||||||
private AccountsDto createAccount() {
|
private AccountDto createAccount() {
|
||||||
final AccountsDto accountsDto = new AccountsDto();
|
final AccountDto accountDto = new AccountDto();
|
||||||
accountsDto.setUsername("Test username");
|
accountDto.setUsername("Test username");
|
||||||
accountsDto.setPassword("test password");
|
accountDto.setPassword("test password");
|
||||||
accountsDto.setAdministratorStatus(true);
|
accountDto.setAdministratorStatus(true);
|
||||||
|
|
||||||
return accountsDto;
|
return accountDto;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+16
-16
@@ -1,6 +1,6 @@
|
|||||||
package edu.msudenver.tsp.persistence.controller;
|
package edu.msudenver.tsp.persistence.controller;
|
||||||
|
|
||||||
import edu.msudenver.tsp.persistence.dto.AccountsDto;
|
import edu.msudenver.tsp.persistence.dto.AccountDto;
|
||||||
import edu.msudenver.tsp.persistence.repository.AccountsRepository;
|
import edu.msudenver.tsp.persistence.repository.AccountsRepository;
|
||||||
import edu.msudenver.tsp.utilities.PersistenceUtilities;
|
import edu.msudenver.tsp.utilities.PersistenceUtilities;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
@@ -26,7 +26,7 @@ public class AccountController {
|
|||||||
|
|
||||||
@GetMapping("/")
|
@GetMapping("/")
|
||||||
public @ResponseBody
|
public @ResponseBody
|
||||||
ResponseEntity<Iterable<AccountsDto>> getListOfAccounts() {
|
ResponseEntity<Iterable<AccountDto>> getListOfAccounts() {
|
||||||
LOG.info("Received request to list all accounts");
|
LOG.info("Received request to list all accounts");
|
||||||
|
|
||||||
LOG.debug("Querying for list of accounts");
|
LOG.debug("Querying for list of accounts");
|
||||||
@@ -34,7 +34,7 @@ public class AccountController {
|
|||||||
final StopWatch stopWatch = new StopWatch();
|
final StopWatch stopWatch = new StopWatch();
|
||||||
stopWatch.start();
|
stopWatch.start();
|
||||||
|
|
||||||
final List<AccountsDto> listOfAccounts = (List<AccountsDto>) accountsRepository.findAll();
|
final List<AccountDto> listOfAccounts = (List<AccountDto>) accountsRepository.findAll();
|
||||||
|
|
||||||
stopWatch.stop();
|
stopWatch.stop();
|
||||||
|
|
||||||
@@ -46,7 +46,7 @@ public class AccountController {
|
|||||||
|
|
||||||
@GetMapping("/{id}")
|
@GetMapping("/{id}")
|
||||||
public @ResponseBody
|
public @ResponseBody
|
||||||
ResponseEntity<AccountsDto> getAccountById(@PathVariable("id") final Integer id) {
|
ResponseEntity<AccountDto> getAccountById(@PathVariable("id") final Integer id) {
|
||||||
LOG.info("Received request to query for account with id " + id);
|
LOG.info("Received request to query for account with id " + id);
|
||||||
if (id == null) {
|
if (id == null) {
|
||||||
LOG.error("ERROR: ID was null");
|
LOG.error("ERROR: ID was null");
|
||||||
@@ -57,7 +57,7 @@ public class AccountController {
|
|||||||
final StopWatch stopWatch = new StopWatch();
|
final StopWatch stopWatch = new StopWatch();
|
||||||
stopWatch.start();
|
stopWatch.start();
|
||||||
|
|
||||||
final Optional<AccountsDto> account = accountsRepository.findById(id);
|
final Optional<AccountDto> account = accountsRepository.findById(id);
|
||||||
|
|
||||||
stopWatch.stop();
|
stopWatch.stop();
|
||||||
|
|
||||||
@@ -74,9 +74,9 @@ public class AccountController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/")
|
@PostMapping("/")
|
||||||
@Validated({AccountsDto.Insert.class, Default.class})
|
@Validated({AccountDto.Insert.class, Default.class})
|
||||||
public @ResponseBody ResponseEntity<AccountsDto> insertAccount(
|
public @ResponseBody ResponseEntity<AccountDto> insertAccount(
|
||||||
@Valid @RequestBody final AccountsDto accountsDto, final BindingResult bindingResult) {
|
@Valid @RequestBody final AccountDto accountDto, final BindingResult bindingResult) {
|
||||||
|
|
||||||
LOG.info("Received request to insert a new account");
|
LOG.info("Received request to insert a new account");
|
||||||
if (bindingResult.hasErrors()) {
|
if (bindingResult.hasErrors()) {
|
||||||
@@ -84,7 +84,7 @@ public class AccountController {
|
|||||||
return new ResponseEntity<>(HttpStatus.UNPROCESSABLE_ENTITY);
|
return new ResponseEntity<>(HttpStatus.UNPROCESSABLE_ENTITY);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (accountsDto == null) {
|
if (accountDto == null) {
|
||||||
LOG.error("Passed account is unprocessable");
|
LOG.error("Passed account is unprocessable");
|
||||||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||||
}
|
}
|
||||||
@@ -94,7 +94,7 @@ public class AccountController {
|
|||||||
final StopWatch stopWatch = new StopWatch();
|
final StopWatch stopWatch = new StopWatch();
|
||||||
stopWatch.start();
|
stopWatch.start();
|
||||||
|
|
||||||
final AccountsDto savedAccount = accountsRepository.save(accountsDto);
|
final AccountDto savedAccount = accountsRepository.save(accountDto);
|
||||||
|
|
||||||
stopWatch.stop();
|
stopWatch.stop();
|
||||||
|
|
||||||
@@ -104,9 +104,9 @@ public class AccountController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PatchMapping("/{id}")
|
@PatchMapping("/{id}")
|
||||||
public @ResponseBody ResponseEntity<AccountsDto> updateAccount(
|
public @ResponseBody ResponseEntity<AccountDto> updateAccount(
|
||||||
@PathVariable("id") final Integer id,
|
@PathVariable("id") final Integer id,
|
||||||
@RequestBody final AccountsDto accountsDto, final BindingResult bindingResult) {
|
@RequestBody final AccountDto accountDto, final BindingResult bindingResult) {
|
||||||
|
|
||||||
LOG.info("Received request to update an account");
|
LOG.info("Received request to update an account");
|
||||||
if (bindingResult.hasErrors()) {
|
if (bindingResult.hasErrors()) {
|
||||||
@@ -114,7 +114,7 @@ public class AccountController {
|
|||||||
return new ResponseEntity<>(HttpStatus.UNPROCESSABLE_ENTITY);
|
return new ResponseEntity<>(HttpStatus.UNPROCESSABLE_ENTITY);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (accountsDto == null) {
|
if (accountDto == null) {
|
||||||
LOG.error("Passed entity is null");
|
LOG.error("Passed entity is null");
|
||||||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||||
}
|
}
|
||||||
@@ -129,7 +129,7 @@ public class AccountController {
|
|||||||
final StopWatch stopWatch = new StopWatch();
|
final StopWatch stopWatch = new StopWatch();
|
||||||
stopWatch.start();
|
stopWatch.start();
|
||||||
|
|
||||||
final Optional<AccountsDto> existingAccount = accountsRepository.findById(id);
|
final Optional<AccountDto> existingAccount = accountsRepository.findById(id);
|
||||||
|
|
||||||
stopWatch.stop();
|
stopWatch.stop();
|
||||||
|
|
||||||
@@ -140,7 +140,7 @@ public class AccountController {
|
|||||||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||||
}
|
}
|
||||||
|
|
||||||
PersistenceUtilities.copyNonNullProperties(accountsDto, existingAccount.get());
|
PersistenceUtilities.copyNonNullProperties(accountDto, existingAccount.get());
|
||||||
existingAccount.get().setVersion(existingAccount.get().getVersion()+ 1);
|
existingAccount.get().setVersion(existingAccount.get().getVersion()+ 1);
|
||||||
|
|
||||||
LOG.info("Updating account with id " + id);
|
LOG.info("Updating account with id " + id);
|
||||||
@@ -148,7 +148,7 @@ public class AccountController {
|
|||||||
|
|
||||||
stopWatch.start();
|
stopWatch.start();
|
||||||
|
|
||||||
final AccountsDto updatedAccount = accountsRepository.save(existingAccount.get());
|
final AccountDto updatedAccount = accountsRepository.save(existingAccount.get());
|
||||||
|
|
||||||
stopWatch.stop();
|
stopWatch.stop();
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -19,7 +19,7 @@ import java.util.Date;
|
|||||||
@EntityListeners(AuditingEntityListener.class)
|
@EntityListeners(AuditingEntityListener.class)
|
||||||
@Data
|
@Data
|
||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode(callSuper = true)
|
||||||
public class AccountsDto extends BaseDto implements Serializable {
|
public class AccountDto extends BaseDto implements Serializable {
|
||||||
@NotBlank(groups = Insert.class, message = "A username must be specified") @Size(max = 50) private String username;
|
@NotBlank(groups = Insert.class, message = "A username must be specified") @Size(max = 50) private String username;
|
||||||
@NotBlank(groups = Insert.class, message = "A password must be specified") @Size(max = 256) private String password;
|
@NotBlank(groups = Insert.class, message = "A password must be specified") @Size(max = 256) private String password;
|
||||||
@NotNull @JsonProperty("administrator_status") private boolean administratorStatus;
|
@NotNull @JsonProperty("administrator_status") private boolean administratorStatus;
|
||||||
+2
-2
@@ -1,9 +1,9 @@
|
|||||||
package edu.msudenver.tsp.persistence.repository;
|
package edu.msudenver.tsp.persistence.repository;
|
||||||
|
|
||||||
import edu.msudenver.tsp.persistence.dto.AccountsDto;
|
import edu.msudenver.tsp.persistence.dto.AccountDto;
|
||||||
import org.springframework.data.repository.CrudRepository;
|
import org.springframework.data.repository.CrudRepository;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
public interface AccountsRepository extends CrudRepository<AccountsDto, Integer> {
|
public interface AccountsRepository extends CrudRepository<AccountDto, Integer> {
|
||||||
}
|
}
|
||||||
|
|||||||
+35
-35
@@ -1,6 +1,6 @@
|
|||||||
package edu.msudenver.tsp.persistence.controller;
|
package edu.msudenver.tsp.persistence.controller;
|
||||||
|
|
||||||
import edu.msudenver.tsp.persistence.dto.AccountsDto;
|
import edu.msudenver.tsp.persistence.dto.AccountDto;
|
||||||
import edu.msudenver.tsp.persistence.repository.AccountsRepository;
|
import edu.msudenver.tsp.persistence.repository.AccountsRepository;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
@@ -33,35 +33,35 @@ public class AccountControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetAllAccounts() {
|
public void testGetAllAccounts() {
|
||||||
final AccountsDto accountsDto = createAccount();
|
final AccountDto accountDto = createAccount();
|
||||||
final List<AccountsDto> accountsDtoList = new ArrayList<>();
|
final List<AccountDto> accountDtoList = new ArrayList<>();
|
||||||
accountsDtoList.add(accountsDto);
|
accountDtoList.add(accountDto);
|
||||||
accountsDtoList.add(accountsDto);
|
accountDtoList.add(accountDto);
|
||||||
|
|
||||||
when(accountsRepository.findAll()).thenReturn(accountsDtoList);
|
when(accountsRepository.findAll()).thenReturn(accountDtoList);
|
||||||
|
|
||||||
final ResponseEntity<Iterable<AccountsDto>> responseEntity = accountController.getListOfAccounts();
|
final ResponseEntity<Iterable<AccountDto>> responseEntity = accountController.getListOfAccounts();
|
||||||
|
|
||||||
assertNotNull(responseEntity);
|
assertNotNull(responseEntity);
|
||||||
assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
|
assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
|
||||||
assertTrue(responseEntity.hasBody());
|
assertTrue(responseEntity.hasBody());
|
||||||
assertNotNull(responseEntity.getBody());
|
assertNotNull(responseEntity.getBody());
|
||||||
|
|
||||||
responseEntity.getBody().forEach(account -> assertEquals(account, accountsDto));
|
responseEntity.getBody().forEach(account -> assertEquals(account, accountDto));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetAccountById() {
|
public void testGetAccountById() {
|
||||||
final AccountsDto accountsDto = createAccount();
|
final AccountDto accountDto = createAccount();
|
||||||
when(accountsRepository.findById(anyInt())).thenReturn(Optional.ofNullable(accountsDto));
|
when(accountsRepository.findById(anyInt())).thenReturn(Optional.ofNullable(accountDto));
|
||||||
|
|
||||||
final ResponseEntity<AccountsDto> responseEntity = accountController.getAccountById(1);
|
final ResponseEntity<AccountDto> responseEntity = accountController.getAccountById(1);
|
||||||
|
|
||||||
assertNotNull(responseEntity);
|
assertNotNull(responseEntity);
|
||||||
assertTrue(responseEntity.hasBody());
|
assertTrue(responseEntity.hasBody());
|
||||||
assertNotNull(responseEntity.getBody());
|
assertNotNull(responseEntity.getBody());
|
||||||
assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
|
assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
|
||||||
assertEquals(accountsDto, responseEntity.getBody());
|
assertEquals(accountDto, responseEntity.getBody());
|
||||||
verify(accountsRepository).findById(anyInt());
|
verify(accountsRepository).findById(anyInt());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,17 +89,17 @@ public class AccountControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testInsertAccount() {
|
public void testInsertAccount() {
|
||||||
final AccountsDto accountsDto = createAccount();
|
final AccountDto accountDto = createAccount();
|
||||||
when(accountsRepository.save(any(AccountsDto.class))).thenReturn(accountsDto);
|
when(accountsRepository.save(any(AccountDto.class))).thenReturn(accountDto);
|
||||||
|
|
||||||
final ResponseEntity<AccountsDto> responseEntity = accountController.insertAccount(accountsDto, bindingResult);
|
final ResponseEntity<AccountDto> responseEntity = accountController.insertAccount(accountDto, bindingResult);
|
||||||
|
|
||||||
assertNotNull(responseEntity);
|
assertNotNull(responseEntity);
|
||||||
assertTrue(responseEntity.hasBody());
|
assertTrue(responseEntity.hasBody());
|
||||||
assertNotNull(responseEntity.getBody());
|
assertNotNull(responseEntity.getBody());
|
||||||
assertEquals(HttpStatus.CREATED, responseEntity.getStatusCode());
|
assertEquals(HttpStatus.CREATED, responseEntity.getStatusCode());
|
||||||
assertEquals(accountsDto, responseEntity.getBody());
|
assertEquals(accountDto, responseEntity.getBody());
|
||||||
verify(accountsRepository).save(any(AccountsDto.class));
|
verify(accountsRepository).save(any(AccountDto.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -114,7 +114,7 @@ public class AccountControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testInsertAccount_bindingResultHasErrors() {
|
public void testInsertAccount_bindingResultHasErrors() {
|
||||||
final AccountsDto definitionDto = createAccount();
|
final AccountDto definitionDto = createAccount();
|
||||||
when(bindingResult.hasErrors()).thenReturn(true);
|
when(bindingResult.hasErrors()).thenReturn(true);
|
||||||
|
|
||||||
final ResponseEntity responseEntity = accountController.insertAccount(definitionDto, bindingResult);
|
final ResponseEntity responseEntity = accountController.insertAccount(definitionDto, bindingResult);
|
||||||
@@ -127,31 +127,31 @@ public class AccountControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUpdateAccount() {
|
public void testUpdateAccount() {
|
||||||
final AccountsDto existingAccount = createAccount();
|
final AccountDto existingAccount = createAccount();
|
||||||
existingAccount.setId(1);
|
existingAccount.setId(1);
|
||||||
existingAccount.setVersion(1);
|
existingAccount.setVersion(1);
|
||||||
final AccountsDto accountUpdate = new AccountsDto();
|
final AccountDto accountUpdate = new AccountDto();
|
||||||
accountUpdate.setUsername("Test Update");
|
accountUpdate.setUsername("Test Update");
|
||||||
final AccountsDto updatedAccount = existingAccount;
|
final AccountDto updatedAccount = existingAccount;
|
||||||
updatedAccount.setUsername("Test Update");
|
updatedAccount.setUsername("Test Update");
|
||||||
when(accountsRepository.findById(anyInt())).thenReturn(Optional.of(existingAccount));
|
when(accountsRepository.findById(anyInt())).thenReturn(Optional.of(existingAccount));
|
||||||
when(accountsRepository.save(any(AccountsDto.class))).thenReturn(updatedAccount);
|
when(accountsRepository.save(any(AccountDto.class))).thenReturn(updatedAccount);
|
||||||
|
|
||||||
final ResponseEntity<AccountsDto> responseEntity = accountController.updateAccount(1, accountUpdate, bindingResult);
|
final ResponseEntity<AccountDto> responseEntity = accountController.updateAccount(1, accountUpdate, bindingResult);
|
||||||
|
|
||||||
assertNotNull(responseEntity);
|
assertNotNull(responseEntity);
|
||||||
assertTrue(responseEntity.hasBody());
|
assertTrue(responseEntity.hasBody());
|
||||||
assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
|
assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
|
||||||
assertEquals(updatedAccount, responseEntity.getBody());
|
assertEquals(updatedAccount, responseEntity.getBody());
|
||||||
verify(accountsRepository).findById(anyInt());
|
verify(accountsRepository).findById(anyInt());
|
||||||
verify(accountsRepository).save(any(AccountsDto.class));
|
verify(accountsRepository).save(any(AccountDto.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUpdateAccount_bindingResultHasErrors() {
|
public void testUpdateAccount_bindingResultHasErrors() {
|
||||||
when(bindingResult.hasErrors()).thenReturn(true);
|
when(bindingResult.hasErrors()).thenReturn(true);
|
||||||
|
|
||||||
final ResponseEntity<AccountsDto> responseEntity = accountController.updateAccount(1, createAccount(), bindingResult);
|
final ResponseEntity<AccountDto> responseEntity = accountController.updateAccount(1, createAccount(), bindingResult);
|
||||||
|
|
||||||
assertNotNull(responseEntity);
|
assertNotNull(responseEntity);
|
||||||
assertFalse(responseEntity.hasBody());
|
assertFalse(responseEntity.hasBody());
|
||||||
@@ -161,7 +161,7 @@ public class AccountControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUpdateAccount_accountsDtoIsNull() {
|
public void testUpdateAccount_accountsDtoIsNull() {
|
||||||
final ResponseEntity<AccountsDto> responseEntity = accountController.updateAccount(1, null, bindingResult);
|
final ResponseEntity<AccountDto> responseEntity = accountController.updateAccount(1, null, bindingResult);
|
||||||
|
|
||||||
assertNotNull(responseEntity);
|
assertNotNull(responseEntity);
|
||||||
assertFalse(responseEntity.hasBody());
|
assertFalse(responseEntity.hasBody());
|
||||||
@@ -171,7 +171,7 @@ public class AccountControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUpdateAccount_idIsNull() {
|
public void testUpdateAccount_idIsNull() {
|
||||||
final ResponseEntity<AccountsDto> responseEntity = accountController.updateAccount(null, createAccount(), bindingResult);
|
final ResponseEntity<AccountDto> responseEntity = accountController.updateAccount(null, createAccount(), bindingResult);
|
||||||
|
|
||||||
assertNotNull(responseEntity);
|
assertNotNull(responseEntity);
|
||||||
assertFalse(responseEntity.hasBody());
|
assertFalse(responseEntity.hasBody());
|
||||||
@@ -183,12 +183,12 @@ public class AccountControllerTest {
|
|||||||
public void testUpdateAccount_accountDoesNotExist() {
|
public void testUpdateAccount_accountDoesNotExist() {
|
||||||
when(accountsRepository.findById(anyInt())).thenReturn(Optional.empty());
|
when(accountsRepository.findById(anyInt())).thenReturn(Optional.empty());
|
||||||
|
|
||||||
final ResponseEntity<AccountsDto> responseEntity = accountController.updateAccount(1, createAccount(), bindingResult);
|
final ResponseEntity<AccountDto> responseEntity = accountController.updateAccount(1, createAccount(), bindingResult);
|
||||||
|
|
||||||
assertNotNull(responseEntity);
|
assertNotNull(responseEntity);
|
||||||
assertFalse(responseEntity.hasBody());
|
assertFalse(responseEntity.hasBody());
|
||||||
assertEquals(HttpStatus.BAD_REQUEST, responseEntity.getStatusCode());
|
assertEquals(HttpStatus.BAD_REQUEST, responseEntity.getStatusCode());
|
||||||
verify(accountsRepository, times(0)).save(any(AccountsDto.class));
|
verify(accountsRepository, times(0)).save(any(AccountDto.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -213,12 +213,12 @@ public class AccountControllerTest {
|
|||||||
verifyZeroInteractions(accountsRepository);
|
verifyZeroInteractions(accountsRepository);
|
||||||
}
|
}
|
||||||
|
|
||||||
private AccountsDto createAccount() {
|
private AccountDto createAccount() {
|
||||||
final AccountsDto accountsDto = new AccountsDto();
|
final AccountDto accountDto = new AccountDto();
|
||||||
accountsDto.setUsername("Test username");
|
accountDto.setUsername("Test username");
|
||||||
accountsDto.setPassword("test password");
|
accountDto.setPassword("test password");
|
||||||
accountsDto.setAdministratorStatus(true);
|
accountDto.setAdministratorStatus(true);
|
||||||
|
|
||||||
return accountsDto;
|
return accountDto;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user