Search in sources :

Example 6 with PatchRequest

use of io.jans.scim.model.scim2.patch.PatchRequest in project jans by JanssenProject.

the class PatchUserExtTest method patchJson.

@Parameters({ "user_patch_ext" })
@Test(dependsOnMethods = "create")
public void patchJson(String patchRequest) {
    Response response = client.patchUser(patchRequest, user.getId(), null, null);
    assertEquals(response.getStatus(), OK.getStatusCode());
    UserResource other = response.readEntity(usrClass);
    // For help on usage of io.jans.scim.model.scim2.CustomAttributes class, read its api docs (oxtrust-scim maven project)
    CustomAttributes custAttrs = other.getCustomAttributes(USER_EXT_SCHEMA_ID);
    // Verify new items appeared in scimCustomSecond
    List<Date> scimCustomSecond = custAttrs.getValues("scimCustomSecond", Date.class);
    assertEquals(scimCustomSecond.size(), 6);
    // Verify change in value of scimCustomThird
    int scimCustomThird = custAttrs.getValue("scimCustomThird", Integer.class);
    assertEquals(1, scimCustomThird);
    // Verify scimCustomFirst disappeared
    assertNull(custAttrs.getValue("scimCustomFirst", String.class));
    // Verify some others disappeared too
    assertNull(other.getAddresses().get(0).getType());
    assertNull(other.getName().getGivenName());
    Stream<String> types = other.getPhoneNumbers().stream().map(PhoneNumber::getType);
    assertTrue(types.map(Optional::ofNullable).noneMatch(Optional::isPresent));
}
Also used : Response(javax.ws.rs.core.Response) CustomAttributes(io.jans.scim.model.scim2.CustomAttributes) UserResource(io.jans.scim.model.scim2.user.UserResource) PhoneNumber(io.jans.scim.model.scim2.user.PhoneNumber) Parameters(org.testng.annotations.Parameters) UserBaseTest(io.jans.scim2.client.UserBaseTest) Test(org.testng.annotations.Test)

Example 7 with PatchRequest

use of io.jans.scim.model.scim2.patch.PatchRequest in project jans by JanssenProject.

the class PatchDeleteUserTest method delete1.

@Parameters({ "user_patchdelete" })
@Test(dependsOnMethods = "createForDel")
public void delete1(String patchRequest) {
    Response response = client.patchUser(patchRequest, user.getId(), null, null);
    assertEquals(response.getStatus(), OK.getStatusCode());
    UserResource other = response.readEntity(usrClass);
    for (int i = 0; i < 2; i++) {
        assertNull(other.getName().getMiddleName());
        assertNull(other.getNickName());
        assertNull(other.getEntitlements());
        assertNull(other.getAddresses().get(0).getPostalCode());
        assertNull(other.getAddresses().get(0).getLocality());
        assertNotNull(other.getAddresses().get(0).getStreetAddress());
        // Double check
        response = client.getUserById(user.getId(), null, null);
        other = response.readEntity(usrClass);
    }
}
Also used : Response(javax.ws.rs.core.Response) UserResource(io.jans.scim.model.scim2.user.UserResource) Parameters(org.testng.annotations.Parameters) UserBaseTest(io.jans.scim2.client.UserBaseTest) Test(org.testng.annotations.Test)

Example 8 with PatchRequest

use of io.jans.scim.model.scim2.patch.PatchRequest in project jans by JanssenProject.

the class PatchReplaceUserTest method jsonPathPatch1.

@Parameters({ "user_patchreplace_3" })
@Test(dependsOnMethods = "jsonNoPathPatch2")
public void jsonPathPatch1(String patchRequest) {
    Response response = client.patchUser(patchRequest, user.getId(), null, null);
    assertEquals(response.getStatus(), OK.getStatusCode());
    UserResource other = response.readEntity(usrClass);
    // Verify display name changed
    assertNotEquals(user.getDisplayName(), other.getDisplayName());
    // Verify some name components changed
    assertNotEquals(user.getName().getFamilyName(), other.getName().getFamilyName());
    assertNotEquals(user.getName().getMiddleName(), other.getName().getMiddleName());
    assertNotEquals(user.getName().getGivenName(), other.getName().getGivenName());
    assertEquals(user.getName().getHonorificPrefix(), other.getName().getHonorificPrefix());
    assertEquals(user.getName().getHonorificSuffix(), other.getName().getHonorificSuffix());
    // Verify is now active
    assertTrue(other.getActive());
    user = other;
}
Also used : Response(javax.ws.rs.core.Response) UserResource(io.jans.scim.model.scim2.user.UserResource) Parameters(org.testng.annotations.Parameters) UserBaseTest(io.jans.scim2.client.UserBaseTest) Test(org.testng.annotations.Test)

Example 9 with PatchRequest

use of io.jans.scim.model.scim2.patch.PatchRequest in project jans by JanssenProject.

the class PatchValueFilterUserTest method objectPatch.

@Test(dependsOnMethods = "patch")
public void objectPatch() {
    PatchRequest request = new PatchRequest();
    request.setOperations(new ArrayList<>());
    PatchOperation del = new PatchOperation();
    del.setOperation("remove");
    del.setPath("emails[type sw \"hobby\"]");
    request.getOperations().add(del);
    del = new PatchOperation();
    del.setOperation("remove");
    del.setPath("phoneNumbers[primary pr or value co \" \"].type");
    request.getOperations().add(del);
    del = new PatchOperation();
    del.setOperation("remove");
    del.setPath("addresses[region eq \"somewhere\" and primary ne true].locality");
    request.getOperations().add(del);
    Response response = client.patchUser(request, user.getId(), null, null);
    assertEquals(response.getStatus(), OK.getStatusCode());
    user = response.readEntity(usrClass);
    assertNull(user.getEmails());
    assertTrue(user.getPhoneNumbers().stream().allMatch(ph -> ph.getType() == null));
    // No change in addresses
    assertEquals(user.getAddresses().size(), 1);
    assertNull(user.getAddresses().get(0).getLocality());
}
Also used : Response(javax.ws.rs.core.Response) UserBaseTest(io.jans.scim2.client.UserBaseTest) UserResource(io.jans.scim.model.scim2.user.UserResource) PatchRequest(io.jans.scim.model.scim2.patch.PatchRequest) Email(io.jans.scim.model.scim2.user.Email) Address(io.jans.scim.model.scim2.user.Address) PhoneNumber(io.jans.scim.model.scim2.user.PhoneNumber) Test(org.testng.annotations.Test) ArrayList(java.util.ArrayList) Response(javax.ws.rs.core.Response) Assert(org.testng.Assert) Parameters(org.testng.annotations.Parameters) PatchOperation(io.jans.scim.model.scim2.patch.PatchOperation) Collections(java.util.Collections) Status(javax.ws.rs.core.Response.Status) PatchOperation(io.jans.scim.model.scim2.patch.PatchOperation) PatchRequest(io.jans.scim.model.scim2.patch.PatchRequest) UserBaseTest(io.jans.scim2.client.UserBaseTest) Test(org.testng.annotations.Test)

Example 10 with PatchRequest

use of io.jans.scim.model.scim2.patch.PatchRequest in project oxTrust by GluuFederation.

the class BulkWebService method execute.

private Pair<Response, String> execute(Verb verb, BaseScimWebService ws, String data, String fragment) {
    Response response = null;
    String idCreated = null;
    try {
        if (ws == userWS)
            switch(verb) {
                case PUT:
                    UserResource user = mapper.readValue(data, UserResource.class);
                    response = userWS.updateUser(user, fragment, "id", null);
                    break;
                case DELETE:
                    response = userWS.deleteUser(fragment);
                    break;
                case PATCH:
                    PatchRequest pr = mapper.readValue(data, PatchRequest.class);
                    response = userWS.patchUser(pr, fragment, "id", null);
                    break;
                case POST:
                    user = mapper.readValue(data, UserResource.class);
                    response = userWS.createUser(user, "id", null);
                    if (CREATED.getStatusCode() == response.getStatus()) {
                        user = mapper.readValue(response.getEntity().toString(), UserResource.class);
                        idCreated = user.getId();
                    }
                    break;
            }
        else if (ws == groupWS)
            switch(verb) {
                case PUT:
                    GroupResource group = mapper.readValue(data, GroupResource.class);
                    response = groupWS.updateGroup(group, fragment, "id", null);
                    break;
                case DELETE:
                    response = groupWS.deleteGroup(fragment);
                    break;
                case PATCH:
                    PatchRequest pr = mapper.readValue(data, PatchRequest.class);
                    response = groupWS.patchGroup(pr, fragment, "id", null);
                    break;
                case POST:
                    group = mapper.readValue(data, GroupResource.class);
                    response = groupWS.createGroup(group, "id", null);
                    if (CREATED.getStatusCode() == response.getStatus()) {
                        group = mapper.readValue(response.getEntity().toString(), GroupResource.class);
                        idCreated = group.getId();
                    }
                    break;
            }
        else if (ws == fidoDeviceWS)
            switch(verb) {
                case PUT:
                    FidoDeviceResource dev = mapper.readValue(data, FidoDeviceResource.class);
                    response = fidoDeviceWS.updateDevice(dev, fragment, "id", null);
                    break;
                case DELETE:
                    response = fidoDeviceWS.deleteDevice(fragment);
                    break;
                case PATCH:
                    PatchRequest pr = mapper.readValue(data, PatchRequest.class);
                    response = fidoDeviceWS.patchDevice(pr, fragment, "id", null);
                    break;
                case POST:
                    response = fidoDeviceWS.createDevice();
                    break;
            }
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        response = getErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, "Unexpected error: " + e.getMessage());
    }
    return new Pair<Response, String>(response, idCreated);
}
Also used : Response(javax.ws.rs.core.Response) BulkResponse(org.gluu.oxtrust.model.scim2.bulk.BulkResponse) FidoDeviceResource(org.gluu.oxtrust.model.scim2.fido.FidoDeviceResource) UserResource(org.gluu.oxtrust.model.scim2.user.UserResource) PatchRequest(org.gluu.oxtrust.model.scim2.patch.PatchRequest) GroupResource(org.gluu.oxtrust.model.scim2.group.GroupResource) Pair(org.xdi.util.Pair)

Aggregations

Response (javax.ws.rs.core.Response)19 UserResource (io.jans.scim.model.scim2.user.UserResource)14 Test (org.testng.annotations.Test)14 PatchOperation (io.jans.scim.model.scim2.patch.PatchOperation)10 UserBaseTest (io.jans.scim2.client.UserBaseTest)10 PatchRequest (io.jans.scim.model.scim2.patch.PatchRequest)9 Parameters (org.testng.annotations.Parameters)9 GroupResource (io.jans.scim.model.scim2.group.GroupResource)4 BaseTest (io.jans.scim2.client.BaseTest)4 ListResponse (io.jans.scim.model.scim2.ListResponse)3 InstantMessagingAddress (io.jans.scim.model.scim2.user.InstantMessagingAddress)3 PhoneNumber (io.jans.scim.model.scim2.user.PhoneNumber)3 DuplicateEntryException (io.jans.orm.exception.operation.DuplicateEntryException)2 SCIMException (io.jans.scim.model.exception.SCIMException)2 CustomAttributes (io.jans.scim.model.scim2.CustomAttributes)2 BulkResponse (io.jans.scim.model.scim2.bulk.BulkResponse)2 Member (io.jans.scim.model.scim2.group.Member)2 Address (io.jans.scim.model.scim2.user.Address)2 ScimResourceUtil (io.jans.scim.model.scim2.util.ScimResourceUtil)2 ArrayList (java.util.ArrayList)2