@Test public void testModificationIfUserCrnIsInternalButResourceCrnParameterIsNotCrn() { when(reflectionUtil.getParameter(any(), any(), eq(AccountId.class))).thenReturn(Optional.empty()); when(reflectionUtil.getParameter(any(), any(), eq(TenantAwareParam.class))).thenReturn(Optional.of("not_crn")); AtomicBoolean assertationHappened = new AtomicBoolean(false); when(reflectionUtil.proceed(any())).thenAnswer(invocation -> { assertEquals(INTERNAL_CRN, ThreadBasedUserCrnProvider.getUserCrn()); assertationHappened.set(true); return null; }); ThreadBasedUserCrnProvider.doAs(INTERNAL_CRN, () -> { underTest.changeInternalCrn(proceedingJoinPoint); }); verify(reflectionUtil, times(1)).proceed(any()); assertTrue(assertationHappened.get()); }
public Object changeInternalCrn(ProceedingJoinPoint proceedingJoinPoint) { String userCrnString = ThreadBasedUserCrnProvider.getUserCrn(); MethodSignature methodSignature = (MethodSignature) proceedingJoinPoint.getSignature(); if (userCrnString != null && InternalCrnBuilder.isInternalCrn(userCrnString)) { return ThreadBasedUserCrnProvider.doAs(getNewUserCrnIfAccountIdParamDefined(proceedingJoinPoint, methodSignature, userCrnString) .or(() -> getNewUserCrnIfTenantAwareParamDefined(proceedingJoinPoint, methodSignature, userCrnString)) .orElse(userCrnString), () -> reflectionUtil.proceed(proceedingJoinPoint)); } return reflectionUtil.proceed(proceedingJoinPoint); }
InternalCrnModifier { public Object changeInternalCrn(ProceedingJoinPoint proceedingJoinPoint) { String userCrnString = ThreadBasedUserCrnProvider.getUserCrn(); MethodSignature methodSignature = (MethodSignature) proceedingJoinPoint.getSignature(); if (userCrnString != null && InternalCrnBuilder.isInternalCrn(userCrnString)) { return ThreadBasedUserCrnProvider.doAs(getNewUserCrnIfAccountIdParamDefined(proceedingJoinPoint, methodSignature, userCrnString) .or(() -> getNewUserCrnIfTenantAwareParamDefined(proceedingJoinPoint, methodSignature, userCrnString)) .orElse(userCrnString), () -> reflectionUtil.proceed(proceedingJoinPoint)); } return reflectionUtil.proceed(proceedingJoinPoint); } }
InternalCrnModifier { public Object changeInternalCrn(ProceedingJoinPoint proceedingJoinPoint) { String userCrnString = ThreadBasedUserCrnProvider.getUserCrn(); MethodSignature methodSignature = (MethodSignature) proceedingJoinPoint.getSignature(); if (userCrnString != null && InternalCrnBuilder.isInternalCrn(userCrnString)) { return ThreadBasedUserCrnProvider.doAs(getNewUserCrnIfAccountIdParamDefined(proceedingJoinPoint, methodSignature, userCrnString) .or(() -> getNewUserCrnIfTenantAwareParamDefined(proceedingJoinPoint, methodSignature, userCrnString)) .orElse(userCrnString), () -> reflectionUtil.proceed(proceedingJoinPoint)); } return reflectionUtil.proceed(proceedingJoinPoint); }  }
InternalCrnModifier { public Object changeInternalCrn(ProceedingJoinPoint proceedingJoinPoint) { String userCrnString = ThreadBasedUserCrnProvider.getUserCrn(); MethodSignature methodSignature = (MethodSignature) proceedingJoinPoint.getSignature(); if (userCrnString != null && InternalCrnBuilder.isInternalCrn(userCrnString)) { return ThreadBasedUserCrnProvider.doAs(getNewUserCrnIfAccountIdParamDefined(proceedingJoinPoint, methodSignature, userCrnString) .or(() -> getNewUserCrnIfTenantAwareParamDefined(proceedingJoinPoint, methodSignature, userCrnString)) .orElse(userCrnString), () -> reflectionUtil.proceed(proceedingJoinPoint)); } return reflectionUtil.proceed(proceedingJoinPoint); }  Object changeInternalCrn(ProceedingJoinPoint proceedingJoinPoint); }
InternalCrnModifier { public Object changeInternalCrn(ProceedingJoinPoint proceedingJoinPoint) { String userCrnString = ThreadBasedUserCrnProvider.getUserCrn(); MethodSignature methodSignature = (MethodSignature) proceedingJoinPoint.getSignature(); if (userCrnString != null && InternalCrnBuilder.isInternalCrn(userCrnString)) { return ThreadBasedUserCrnProvider.doAs(getNewUserCrnIfAccountIdParamDefined(proceedingJoinPoint, methodSignature, userCrnString) .or(() -> getNewUserCrnIfTenantAwareParamDefined(proceedingJoinPoint, methodSignature, userCrnString)) .orElse(userCrnString), () -> reflectionUtil.proceed(proceedingJoinPoint)); } return reflectionUtil.proceed(proceedingJoinPoint); }  Object changeInternalCrn(ProceedingJoinPoint proceedingJoinPoint);  }