-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
1 parent
5af1b1a
commit 304ff9a
Showing
18 changed files
with
1,054 additions
and
505 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 0 additions & 9 deletions
9
backend/src/main/java/ch/puzzle/okr/repository/TeamRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,11 @@ | ||
package ch.puzzle.okr.repository; | ||
|
||
import ch.puzzle.okr.models.Team; | ||
import org.springframework.data.jpa.repository.Query; | ||
import org.springframework.data.repository.CrudRepository; | ||
import org.springframework.data.repository.query.Param; | ||
|
||
import java.util.List; | ||
|
||
public interface TeamRepository extends CrudRepository<Team, Long> { | ||
|
||
@Query(value = """ | ||
select distinct teamOrg.team_id from team_organisation teamOrg | ||
inner join organisation o on o.id = teamOrg.organisation_id | ||
where o.org_name in (:organisationNames) | ||
""", nativeQuery = true) | ||
List<Long> findTeamIdsByOrganisationNames(@Param("organisationNames") List<String> organisationNames); | ||
|
||
List<Team> findTeamsByName(String name); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
backend/src/main/java/ch/puzzle/okr/util/CollectionUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package ch.puzzle.okr.util; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.StreamSupport; | ||
|
||
public class CollectionUtils { | ||
|
||
public static <T> List<T> iterableToList(Iterable<T> iterable) { | ||
return StreamSupport // | ||
.stream(iterable.spliterator(), false) // | ||
.collect(Collectors.toList()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,10 +6,7 @@ | |
import ch.puzzle.okr.multitenancy.TenantContext; | ||
import ch.puzzle.okr.service.persistence.UserPersistenceService; | ||
import ch.puzzle.okr.test.SpringIntegrationTest; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.*; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.cache.Cache; | ||
import org.springframework.cache.CacheManager; | ||
|
@@ -34,17 +31,39 @@ class AuthorizationRegistrationServiceIT { | |
private final String tenant = TestHelper.SCHEMA_PITC; | ||
private final String key = tenant + "_" + user.getEmail(); | ||
|
||
private static final String EMAIL_WUNDERLAND = "[email protected]"; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
TenantContext.setCurrentTenant(tenant); | ||
} | ||
|
||
@AfterEach | ||
void tearDown() { | ||
resetOkrChampionStatus(); | ||
clearCache(); | ||
TenantContext.setCurrentTenant(null); | ||
} | ||
|
||
private void resetOkrChampionStatus() { | ||
Optional<User> userFromDb = userPersistenceService.findByEmail(EMAIL_WUNDERLAND); | ||
assertTrue(userFromDb.isPresent()); | ||
|
||
userFromDb.get().setOkrChampion(false); | ||
userPersistenceService.save(userFromDb.get()); | ||
assertOkrChampionStatusInDb(userFromDb.get().getEmail(), false); | ||
} | ||
|
||
private void clearCache() { | ||
Cache cache = cacheManager.getCache(AUTHORIZATION_USER_CACHE); | ||
assertNotNull(cache); | ||
cache.clear(); | ||
TenantContext.setCurrentTenant(null); | ||
} | ||
|
||
private void assertOkrChampionStatusInDb(String email, boolean expectedOkrChampionStatus) { | ||
var userInDb = userPersistenceService.findByEmail(email); | ||
assertTrue(userInDb.isPresent()); | ||
assertEquals(expectedOkrChampionStatus, userInDb.get().isOkrChampion()); | ||
} | ||
|
||
@Test | ||
|
@@ -81,6 +100,8 @@ void registerAuthorizationUser_shouldSetOkrChampionsToFalse() { | |
// assert | ||
assertFalse(processedUser.user().isOkrChampion()); | ||
Optional<User> userFromDB = userPersistenceService.findByEmail(user.getEmail()); | ||
|
||
assertTrue(userFromDB.isPresent()); | ||
assertFalse(userFromDB.get().isOkrChampion()); | ||
|
||
// cleanup | ||
|
@@ -89,30 +110,31 @@ void registerAuthorizationUser_shouldSetOkrChampionsToFalse() { | |
|
||
/* | ||
* Special test setup. <pre> - the user [email protected] is an existing user in the H2 db (created via | ||
* X_TestData.sql) - the user [email protected] is also defined in application-integration-test.properties as | ||
* user champion - with this combination we can test, that the user in the db (which has initial isOkrChampion == | ||
* false) is after calling updateOrAddAuthorizationUser() a user champion. - because the user [email protected] | ||
* exists before the test, we make no clean in db (we don't remove it) </pre> | ||
* V100_0_0__TestData.sql) - the user [email protected] is also defined in | ||
* application-integration-test.properties as user champion - with this combination we can test, that the user in | ||
* the db (which has initial isOkrChampion == false) is after calling updateOrAddAuthorizationUser() a user | ||
* champion. - the OkrChampion status must manually be reset (in the tearDown method) </pre> | ||
*/ | ||
@Test | ||
@DisplayName("registerAuthorizationUser for a user with an email defined in the application-integration-test.properties should set OkrChampions to true") | ||
void registerAuthorizationUserShouldSetOkrChampionsToTrue() { | ||
// arrange | ||
User user = User.Builder.builder() // | ||
.withFirstname("Alice") // | ||
.withLastname("Wunderland") // | ||
.withEmail("[email protected]") // user.champion.emails from application-integration-test.properties | ||
.build(); | ||
|
||
userPersistenceService.getOrCreateUser(user); // updates input user with id from DB !!! | ||
assertOkrChampionStatusInDb(EMAIL_WUNDERLAND, false); // pre-condition | ||
|
||
// act | ||
AuthorizationUser processedUser = authorizationRegistrationService.updateOrAddAuthorizationUser(user); | ||
// load user from db (by email) and set OkrChampion status based on property | ||
// "okr.tenants.pitc.user.champion.emails" from application-integration-test.properties file | ||
AuthorizationUser processedUser = authorizationRegistrationService | ||
.updateOrAddAuthorizationUser(User.Builder.builder() // | ||
.withFirstname("Alice") // | ||
.withLastname("Wunderland") // | ||
.withEmail(EMAIL_WUNDERLAND) // user.champion.emails from | ||
// application-integration-test.properties | ||
.build()); | ||
|
||
// assert | ||
assertTrue(processedUser.user().isOkrChampion()); | ||
Optional<User> userFromDB = userPersistenceService.findByEmail(user.getEmail()); | ||
assertTrue(userFromDB.get().isOkrChampion()); | ||
assertOkrChampionStatusInDb(processedUser.user().getEmail(), true); | ||
} | ||
|
||
@Test | ||
|
@@ -138,6 +160,7 @@ void registerAuthorizationUser_shouldSetFirstnameAndLastnameFromToken() { | |
|
||
// assert | ||
Optional<User> userFromDB = userPersistenceService.findByEmail(user.getEmail()); | ||
assertTrue(userFromDB.isPresent()); | ||
assertEquals(userFromDB.get().getFirstname(), firstNameFromToken); | ||
assertEquals(userFromDB.get().getLastname(), lastNameFromToken); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.