Search in sources :

Example 1 with Profile

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());
}
Also used : Response(com.jayway.restassured.response.Response) ProfileImpl(org.eclipse.che.api.user.server.model.impl.ProfileImpl) Profile(org.eclipse.che.api.core.model.user.Profile) Test(org.testng.annotations.Test)

Example 2 with Profile

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);
}
Also used : Profile(org.eclipse.che.api.core.model.user.Profile) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) Consumes(javax.ws.rs.Consumes) ApiOperation(io.swagger.annotations.ApiOperation) GenerateLink(org.eclipse.che.api.core.rest.annotations.GenerateLink) ApiResponses(io.swagger.annotations.ApiResponses)

Example 3 with 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);
}
Also used : Response(com.jayway.restassured.response.Response) Profile(org.eclipse.che.api.core.model.user.Profile) Test(org.testng.annotations.Test)

Example 4 with Profile

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);
}
Also used : Response(com.jayway.restassured.response.Response) Profile(org.eclipse.che.api.core.model.user.Profile) Test(org.testng.annotations.Test)

Example 5 with Profile

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"));
}
Also used : Response(com.jayway.restassured.response.Response) ProfileImpl(org.eclipse.che.api.user.server.model.impl.ProfileImpl) Profile(org.eclipse.che.api.core.model.user.Profile) Test(org.testng.annotations.Test)

Aggregations

Profile (org.eclipse.che.api.core.model.user.Profile)5 Response (com.jayway.restassured.response.Response)4 Test (org.testng.annotations.Test)4 ProfileImpl (org.eclipse.che.api.user.server.model.impl.ProfileImpl)2 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponses (io.swagger.annotations.ApiResponses)1 Consumes (javax.ws.rs.Consumes)1 DELETE (javax.ws.rs.DELETE)1 Path (javax.ws.rs.Path)1 GenerateLink (org.eclipse.che.api.core.rest.annotations.GenerateLink)1