use of org.eclipse.che.api.core.model.user.Profile in project che by eclipse.
the class ProfileServiceTest method shouldRemoveAllAttributeIfNoSpecified.
@Test
public void shouldRemoveAllAttributeIfNoSpecified() throws Exception {
when(profileManager.getById(SUBJECT.getUserId())).thenReturn(new ProfileImpl(SUBJECT.getUserId(), ImmutableMap.of("attr1", "value1", "attr2", "value2", "attr3", "value3")));
final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).when().contentType("application/json").delete(SECURE_PATH + "/profile/attributes");
assertEquals(response.getStatusCode(), 204);
verify(profileManager).update(profileCaptor.capture());
final Profile profile = profileCaptor.getValue();
assertTrue(profile.getAttributes().isEmpty());
}
use of org.eclipse.che.api.core.model.user.Profile in project che by eclipse.
the class ProfileService method removeAttributes.
@DELETE
@Path("/attributes")
@GenerateLink(rel = LINK_REL_CURRENT_PROFILE_ATTRIBUTES)
@Consumes(APPLICATION_JSON)
@ApiOperation(value = "Remove profile attributes which names are equal to given", notes = "If names list is not send, all the attributes will be removed, " + "if there are no attributes which names equal to some of the given names, " + "then those names are skipped.")
@ApiResponses({ @ApiResponse(code = 204, message = "Attributes successfully removed"), @ApiResponse(code = 500, message = "Couldn't remove attributes due to internal server error") })
public void removeAttributes(@ApiParam("The names of the profile attributes to remove") List<String> names) throws NotFoundException, ServerException {
final Profile profile = profileManager.getById(userId());
final Map<String, String> attributes = profile.getAttributes();
if (names == null) {
attributes.clear();
} else {
names.forEach(attributes::remove);
}
profileManager.update(profile);
}
use of org.eclipse.che.api.core.model.user.Profile in project che by eclipse.
the class ProfileServiceTest method shouldBeAbleToUpdateAttributesOfSpecifiedProfile.
@Test
public void shouldBeAbleToUpdateAttributesOfSpecifiedProfile() throws Exception {
final ImmutableMap<String, String> attributes = ImmutableMap.of("attr1", "value1", "attr2", "value2", "attr3", "value3");
final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).when().contentType("application/json").body(attributes).put(SECURE_PATH + "/profile/" + SUBJECT.getUserId() + "/attributes/");
assertEquals(response.getStatusCode(), 200);
verify(profileManager).update(profileCaptor.capture());
final Profile profile = profileCaptor.getValue();
assertEquals(profile.getAttributes(), attributes);
}
use of org.eclipse.che.api.core.model.user.Profile in project che by eclipse.
the class ProfileServiceTest method shouldBeAbleToUpdateCurrentProfileAttributes.
@Test
public void shouldBeAbleToUpdateCurrentProfileAttributes() throws Exception {
final ImmutableMap<String, String> attributes = ImmutableMap.of("attr1", "value1", "attr2", "value2", "attr3", "value3");
final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).when().contentType("application/json").body(attributes).put(SECURE_PATH + "/profile/attributes");
assertEquals(response.getStatusCode(), 200);
verify(profileManager).update(profileCaptor.capture());
final Profile profile = profileCaptor.getValue();
assertEquals(profile.getAttributes(), attributes);
}
use of org.eclipse.che.api.core.model.user.Profile in project che by eclipse.
the class ProfileServiceTest method shouldBeAbleToRemoveSpecifiedAttributes.
@Test
public void shouldBeAbleToRemoveSpecifiedAttributes() throws Exception {
when(profileManager.getById(SUBJECT.getUserId())).thenReturn(new ProfileImpl(SUBJECT.getUserId(), ImmutableMap.of("attr1", "value1", "attr2", "value2", "attr3", "value3")));
final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).when().contentType("application/json").body(asList("attr1", "attr3")).delete(SECURE_PATH + "/profile/attributes");
assertEquals(response.getStatusCode(), 204);
verify(profileManager).update(profileCaptor.capture());
final Profile profile = profileCaptor.getValue();
assertEquals(profile.getAttributes(), ImmutableMap.of("attr2", "value2"));
}
Aggregations