use of io.gravitee.am.repository.management.api.UserRepository in project gravitee-access-management by gravitee-io.
the class EnrichProfilePolicy method enrichProfile.
protected Single<User> enrichProfile(ExecutionContext context) {
UserRepository userRepository = context.getComponent(UserRepository.class);
User user = (User) context.getAttribute("user");
return userRepository.update(user);
}
use of io.gravitee.am.repository.management.api.UserRepository in project gravitee-access-management by gravitee-io.
the class EnrichProfilePolicyTest method shouldUpdateUser.
@Test
public void shouldUpdateUser() throws Exception {
final CountDownLatch lock = new CountDownLatch(1);
this.policyChain = spy(new CountDownPolicyChain(lock));
when(configuration.getProperties()).thenReturn(Arrays.asList(new Property("myclaim", "myclaimValue"), new Property("myclaim-tpl", "{#request.params['" + REQUEST_PARAM + "']}")));
User user = mock(User.class);
Map<String, Object> additionalInformation = new HashMap<>();
when(user.getAdditionalInformation()).thenReturn(additionalInformation);
when(executionContext.getAttribute("user")).thenReturn(user);
when(userRepository.update(any())).thenReturn(Single.just(user));
EnrichProfilePolicy enrichProfilePolicy = new EnrichProfilePolicy(configuration);
enrichProfilePolicy.onRequest(request, response, executionContext, policyChain);
lock.await(1, TimeUnit.SECONDS);
verify(policyChain, never()).failWith(any());
verify(policyChain).doNext(any(), any());
verify(userRepository).update(argThat(u -> u.getAdditionalInformation() != null && u.getAdditionalInformation().containsKey("myclaim") && "myclaimValue".equals(u.getAdditionalInformation().get("myclaim")) && u.getAdditionalInformation().containsKey("myclaim-tpl") && PARAM_VALUE.equals(u.getAdditionalInformation().get("myclaim-tpl"))));
}
Aggregations