Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/refactoring/1171-na…
Browse files Browse the repository at this point in the history
…ming-cleanup' into refactoring/1171-naming-cleanup
  • Loading branch information
nevio18324 committed Dec 19, 2024
2 parents 56f83aa + fe41dee commit 4d4d51c
Show file tree
Hide file tree
Showing 11 changed files with 259 additions and 160 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import ch.puzzle.okr.models.keyresult.KeyResult;
import ch.puzzle.okr.models.keyresult.KeyResultMetric;
import ch.puzzle.okr.service.business.ActionBusinessService;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.params.ParameterizedTest;
Expand Down Expand Up @@ -41,9 +42,9 @@ class ActionAuthorizationServiceTest {
.withPriority(1).withKeyResult(keyResult).build();
private final List<Action> actionList = List.of(action1, action2);

@ParameterizedTest
@ParameterizedTest(name = "Should return a list of actions when writable is {0}")
@ValueSource(booleans = { true, false })
void getActionsByKeyResultShouldReturnListOfActions(boolean isWriteable) {
void shouldReturnListOfActionsByKeyResultBasedOnWritable(boolean isWriteable) {
keyResult.setWriteable(isWriteable);
when(actionBusinessService.getActionsByKeyResultId(anyLong())).thenReturn(actionList);

Expand All @@ -53,8 +54,9 @@ void getActionsByKeyResultShouldReturnListOfActions(boolean isWriteable) {
foundActionList.forEach(action -> assertEquals(isWriteable, action.isWriteable()));
}

@DisplayName("Should return created action when authorized")
@Test
void createEntityShouldReturnCreatedActionWhenAuthorized() {
void shouldReturnCreatedActionWhenAuthorized() {
when(authorizationService.updateOrAddAuthorizationUser()).thenReturn(authorizationUser);

action1.setWriteable(false);
Expand All @@ -67,8 +69,9 @@ void createEntityShouldReturnCreatedActionWhenAuthorized() {
verify(actionBusinessService, times(1)).createEntities(receivedActionList);
}

@DisplayName("Should throw exception when creating entity without authorization")
@Test
void createEntityShouldThrowExceptionWhenNotAuthorized() {
void shouldThrowExceptionWhenCreatingEntityWithoutAuthorization() {
String reason = "junit test reason";
when(authorizationService.updateOrAddAuthorizationUser()).thenReturn(authorizationUser);
doThrow(new ResponseStatusException(HttpStatus.UNAUTHORIZED, reason)).when(authorizationService)
Expand All @@ -80,17 +83,19 @@ void createEntityShouldThrowExceptionWhenNotAuthorized() {
assertEquals(reason, exception.getReason());
}

@DisplayName("Should update actions when authorized")
@Test
void updateEntitiesShouldUpdateActionWhenAuthorized() {
void shouldUpdateActionsWhenAuthorized() {
when(authorizationService.updateOrAddAuthorizationUser()).thenReturn(authorizationUser);

actionAuthorizationService.updateEntities(actionList);

verify(actionBusinessService, times(1)).updateEntities(actionList);
}

@DisplayName("Should throw exception when updating entities without authorization")
@Test
void updateEntitiesShouldThrowExceptionWhenNotAuthorized() {
void shouldThrowExceptionWhenUpdatingEntitiesWithoutAuthorization() {
String reason = "junit test reason";
when(authorizationService.updateOrAddAuthorizationUser()).thenReturn(authorizationUser);
doThrow(new ResponseStatusException(HttpStatus.UNAUTHORIZED, reason)).when(authorizationService)
Expand All @@ -102,8 +107,9 @@ void updateEntitiesShouldThrowExceptionWhenNotAuthorized() {
assertEquals(reason, exception.getReason());
}

@DisplayName("Should delete entity by ID when authorized")
@Test
void deleteEntityByIdShouldPassThroughWhenAuthorized() {
void shouldDeleteEntityByIdWhenAuthorized() {
Long id = 5L;
when(authorizationService.updateOrAddAuthorizationUser()).thenReturn(authorizationUser);

Expand All @@ -112,8 +118,9 @@ void deleteEntityByIdShouldPassThroughWhenAuthorized() {
verify(actionBusinessService, times(1)).deleteEntityById(id);
}

@DisplayName("Should throw exception when deleting entity without authorization")
@Test
void deleteEntityByIdShouldThrowExceptionWhenNotAuthorized() {
void shouldThrowExceptionWhenDeletingEntityWithoutAuthorization() {
Long id = 8L;
String reason = "junit test reason";
when(authorizationService.updateOrAddAuthorizationUser()).thenReturn(authorizationUser);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,9 @@ private void assertOkrChampionStatusInDb(String email, boolean expectedOkrChampi
assertEquals(expectedOkrChampionStatus, userInDb.get().isOkrChampion());
}

@DisplayName("Should add the authorization-user to the cache")
@Test
void updateOrAddAuthorizationUserShouldAddAuthorizationUserToCache() {
void shouldAddAuthorizationUserToCache() {
// arrange
Cache cache = cacheManager.getCache(AUTHORIZATION_USER_CACHE);

Expand All @@ -82,9 +83,9 @@ void updateOrAddAuthorizationUserShouldAddAuthorizationUserToCache() {
userPersistenceService.deleteById(user.getId());
}

@DisplayName("updateOrAddAuthorizationUser for a user with an email not defined in the application-integration-test.properties should set isOkrChampion to false")
@DisplayName("Should set isOkrChampion to false for a user with an email not defined in the application-integration-test.properties")
@Test
void updateOrAddAuthorizationUserShouldSetIsOkrChampionToFalse() {
void shouldSetIsOkrChampionToFalseForUserWithEmailNotInProperties() {
// arrange
User user = User.Builder.builder() //
.withFirstName("Richard") //
Expand Down Expand Up @@ -115,9 +116,9 @@ void updateOrAddAuthorizationUserShouldSetIsOkrChampionToFalse() {
* 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>
*/
@DisplayName("Should set isOkrChampion to true for a user with an email defined in the application-integration-test.properties")
@Test
@DisplayName("updateOrAddAuthorizationUser for a user with an email defined in the application-integration-test.properties should set isOkrChampion to true")
void updateOrAddAuthorizationUserShouldSetIsOkrChampionToTrue() {
void shouldSetIsOkrChampionToTrueForUserWithEmailInProperties() {
// arrange
assertOkrChampionStatusInDb(EMAIL_WUNDERLAND, false); // pre-condition

Expand All @@ -129,16 +130,17 @@ void updateOrAddAuthorizationUserShouldSetIsOkrChampionToTrue() {
.withFirstName("Alice") //
.withLastName("Wunderland") //
.withEmail(EMAIL_WUNDERLAND) // user.champion.emails from
// application-integration-test.properties
// application-integration-test.properties
.build());

// assert
assertTrue(processedUser.user().isOkrChampion());
assertOkrChampionStatusInDb(processedUser.user().getEmail(), true);
}

@DisplayName("Should set firstname and lastname from the token")
@Test
void updateOrAddAuthorizationUserShouldSetFirstnameAndLastnameFromToken() {
void shouldSetFirstnameAndLastnameFromToken() {
// arrange
User user = User.Builder.builder() //
.withFirstName("Richard") //
Expand Down
Loading

0 comments on commit 4d4d51c

Please sign in to comment.