use of io.gravitee.rest.api.model.UserEntity in project gravitee-management-rest-api by gravitee-io.
the class UserResourceTest method shouldGetCurrentUserWithManagementConfigWithUrl.
@Test
public void shouldGetCurrentUserWithManagementConfigWithUrl() {
when(userService.findByIdWithRoles(USER_NAME)).thenReturn(new UserEntity());
when(permissionService.hasManagementRights(USER_NAME)).thenReturn(Boolean.TRUE);
ConsoleSettingsEntity consoleConfigEntity = new ConsoleSettingsEntity();
Management managementConfig = new Management();
managementConfig.setUrl("URL");
consoleConfigEntity.setManagement(managementConfig);
when(configService.getConsoleSettings()).thenReturn(consoleConfigEntity);
final Response response = target().request().get();
assertEquals(HttpStatusCode.OK_200, response.getStatus());
ArgumentCaptor<String> userId = ArgumentCaptor.forClass(String.class);
Mockito.verify(userService).findByIdWithRoles(userId.capture());
assertEquals(USER_NAME, userId.getValue());
User user = response.readEntity(User.class);
assertNotNull(user);
UserConfig config = user.getConfig();
assertNotNull(config);
assertEquals("URL", config.getManagementUrl());
assertNotNull(user.getLinks());
}
use of io.gravitee.rest.api.model.UserEntity in project gravitee-management-rest-api by gravitee-io.
the class UserResourceTest method shouldGetUserAvatarRedirectUrl.
@Test
public void shouldGetUserAvatarRedirectUrl() throws IOException {
doReturn(new UserEntity()).when(userService).findById(any());
doReturn(new UserEntity()).when(userService).findByIdWithRoles(any());
doReturn(new UrlPictureEntity(target().getUri().toURL().toString())).when(userService).getPicture(any());
final Response response = target().path("avatar").request().get();
assertEquals(OK_200, response.getStatus());
}
use of io.gravitee.rest.api.model.UserEntity in project gravitee-management-rest-api by gravitee-io.
the class OAuth2AuthenticationResourceTest method shouldConnectUser.
@Test
public void shouldConnectUser() throws Exception {
// -- MOCK
// mock environment
mockDefaultEnvironment();
// mock oauth2 exchange authorisation code for access token
mockExchangeAuthorizationCodeForAccessToken();
// mock oauth2 user info call
mockUserInfo(okJson(IOUtils.toString(read("/oauth2/json/user_info_response_body.json"), Charset.defaultCharset())));
// mock DB find user by name
UserEntity userEntity = mockUserEntity();
userEntity.setId("janedoe@example.com");
userEntity.setSource(USER_SOURCE_OAUTH2);
userEntity.setSourceId("janedoe@example.com");
userEntity.setPicture("http://example.com/janedoe/me.jpg");
when(userService.createOrUpdateUserFromSocialIdentityProvider(eq(identityProvider), anyString())).thenReturn(userEntity);
// mock DB user connect
when(userService.connect(userEntity.getId())).thenReturn(userEntity);
// -- CALL
final MultivaluedMap<String, String> payload = createPayload("the_client_id", "http://localhost/callback", "CoDe");
Response response = target().request().post(form(payload));
// -- VERIFY
verify(userService, times(1)).createOrUpdateUserFromSocialIdentityProvider(eq(identityProvider), anyString());
verify(userService, times(1)).connect(userEntity.getSourceId());
assertEquals(HttpStatusCode.OK_200, response.getStatus());
// verify response body
// verifyUserInResponseBody(response);
// verify jwt token
verifyJwtToken(response);
}
use of io.gravitee.rest.api.model.UserEntity in project gravitee-management-rest-api by gravitee-io.
the class OAuth2AuthenticationResourceTest method mockUserEntity.
private UserEntity mockUserEntity() {
UserEntity createdUser = new UserEntity();
createdUser.setId("janedoe@example.com");
createdUser.setSource(USER_SOURCE_OAUTH2);
createdUser.setSourceId("janedoe@example.com");
createdUser.setLastname("Doe");
createdUser.setFirstname("Jane");
createdUser.setEmail("janedoe@example.com");
createdUser.setPicture("http://example.com/janedoe/me.jpg");
return createdUser;
}
use of io.gravitee.rest.api.model.UserEntity in project gravitee-management-rest-api by gravitee-io.
the class UsersResourceTest method shouldCreateRegistration.
@Test
public void shouldCreateRegistration() {
// init
RegisterUserInput input = new RegisterUserInput().email("test@example.com").firstname("Firstname").lastname("LASTNAME").confirmationPageUrl("HTTP://MY-CONFIRM-PAGE");
NewExternalUserEntity newExternalUserEntity = new NewExternalUserEntity();
doReturn(newExternalUserEntity).when(userMapper).convert(input);
doReturn(new UserEntity()).when(userService).register(newExternalUserEntity, "HTTP://MY-CONFIRM-PAGE");
// test
final Response response = target("registration").request().post(Entity.json(input));
assertEquals(HttpStatusCode.OK_200, response.getStatus());
Mockito.verify(userMapper).convert(input);
Mockito.verify(userService).register(newExternalUserEntity, "HTTP://MY-CONFIRM-PAGE");
}
Aggregations