Skip to content

Commit

Permalink
Test/1012 service (#1050)
Browse files Browse the repository at this point in the history
* tests for PersistenceBase class

* remove tests from QuarterPersistenceServiceIT which are already covered in PersistenceBaseTestIT

* remove no longer used OrganisationXXX() methods

* remove tests from TeamPersistenceServiceIT which are already covered in PersistenceBaseTestIT

* remove tests from UserPersistenceServiceIT which are already covered in PersistenceBaseTestIT and add additional tests

* remove tests from CheckInPersistenceServiceIT which are already covered in PersistenceBaseTestIT and add additional test

* umbau ObjectivePersistenceServiceIT: remove tests which are already covered in PersistenceBaseTestIT, add additional test, make the tests readable

* tests for AuthorizationCriteria

* tests for AuthorizationCriteria

* tests for AuthorizationCriteria

* enable debug trace

* debug found okr-champions in test

* add logging in findAllOkrChampionsShouldReturnAllOkrChampions() test

* disable tests which call setOkrChampion()

* enable some disabled tests

* enable some disabled tests

* enable last disabled test .. should fail

* ugly temp fix

* cleanup

* cleanup

* cleanup

* cleanup

* cleanup

* cleanup

---------

Co-authored-by: peggimann <[email protected]>
  • Loading branch information
2 people authored and kcinay055679 committed Nov 21, 2024
1 parent 6a1421d commit b71f536
Showing 1 changed file with 2 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.http.HttpStatus;

import java.util.List;
import java.util.Optional;
Expand Down Expand Up @@ -92,7 +90,7 @@ void saveAllShouldSaveAllUsersInTheInputList() {

// assert
assertEquals(1, createdUsers.size());
createdUser = createdUsers.getFirst();
createdUser = createdUsers.get(0);

assertNotNull(createdUser.getId());
assertUser("Hans", "Muster", "[email protected]", createdUser);
Expand Down Expand Up @@ -162,7 +160,7 @@ void findAllOkrChampionsShouldReturnAllOkrChampions() {

// assert
assertEquals(1, allOkrChampions.size());
assertUser(61L, "Jaya", "Norris", "[email protected]", allOkrChampions.getFirst());
assertUser(61L, "Jaya", "Norris", "[email protected]", allOkrChampions.get(0));
}

@DisplayName("getModelName() should return user")
Expand All @@ -181,41 +179,4 @@ private void assertUser(String firstName, String lastName, String email, User cu
assertEquals(lastName, currentUser.getLastname());
assertEquals(email, currentUser.getEmail());
}

@DisplayName("deleteById() should delete user when user found")
@Test
void deleteByIdShouldDeleteUserWhenUserFound() {
// arrange
User user = createUser();

// act
userPersistenceService.deleteById(user.getId());

// assert
OkrResponseStatusException exception = assertThrows(OkrResponseStatusException.class, //
() -> userPersistenceService.findById(createdUser.getId()));

assertEquals(HttpStatus.NOT_FOUND, exception.getStatusCode());
}

private User createUser() {
User newUser = User.Builder.builder() //
.withId(null) //
.withFirstname("firstname") //
.withLastname("lastname") //
.withEmail("[email protected]") //
.build();
createdUser = userPersistenceService.getOrCreateUser(newUser);
assertNotNull(createdUser.getId());
return createdUser;
}

@DisplayName("deleteById() should throw exception when Id is null")
@Test
void deleteByIdShouldThrowExceptionWhenIdIsNull() {
InvalidDataAccessApiUsageException exception = assertThrows(InvalidDataAccessApiUsageException.class, //
() -> userPersistenceService.deleteById(null));

assertEquals("The given id must not be null", exception.getMessage());
}
}

0 comments on commit b71f536

Please sign in to comment.