Search in sources :

Example 11 with PatchRequest

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

the class PatchAddUserTest method jsonPatch.

@Parameters({ "user_patchadd" })
@Test(dependsOnMethods = "createForAdd")
public void jsonPatch(String patchRequest) {
    Response response = client.patchUser(patchRequest, user.getId(), null, null);
    assertEquals(response.getStatus(), OK.getStatusCode());
    UserResource other = response.readEntity(usrClass);
    assertNotNull(other.getNickName());
    assertNotNull(other.getUserType());
    assertTrue(user.getEmails().size() < other.getEmails().size());
    assertTrue(user.getPhoneNumbers().size() < other.getPhoneNumbers().size());
    assertTrue(other.getIms().size() > 0);
    assertTrue(other.getRoles().size() > 0);
}
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 12 with PatchRequest

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

the class PatchUserExtTest method patchObject.

@Test(dependsOnMethods = "patchJson")
public void patchObject() {
    PatchOperation operation = new PatchOperation();
    operation.setOperation("replace");
    operation.setPath("urn:ietf:params:scim:schemas:extension:gluu:2.0:User:scimCustomSecond");
    long now = System.currentTimeMillis();
    List<String> someDates = Arrays.asList(now, now + 1000, now + 2000, now + 3000).stream().map(DateUtil::millisToISOString).collect(Collectors.toList());
    operation.setValue(someDates);
    PatchRequest pr = new PatchRequest();
    pr.setOperations(Collections.singletonList(operation));
    Response response = client.patchUser(pr, user.getId(), null, null);
    assertEquals(response.getStatus(), OK.getStatusCode());
    UserResource other = response.readEntity(usrClass);
    CustomAttributes custAttrs = other.getCustomAttributes(USER_EXT_SCHEMA_ID);
    // Verify different dates appeared in scimCustomSecond
    List<Date> scimCustomSecond = custAttrs.getValues("scimCustomSecond", Date.class);
    assertEquals(scimCustomSecond.size(), someDates.size());
    assertEquals(now, scimCustomSecond.get(0).getTime());
}
Also used : Response(javax.ws.rs.core.Response) CustomAttributes(io.jans.scim.model.scim2.CustomAttributes) PatchOperation(io.jans.scim.model.scim2.patch.PatchOperation) UserResource(io.jans.scim.model.scim2.user.UserResource) PatchRequest(io.jans.scim.model.scim2.patch.PatchRequest) UserBaseTest(io.jans.scim2.client.UserBaseTest) Test(org.testng.annotations.Test)

Example 13 with PatchRequest

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

the class PatchReplaceUserTest method jsonNoPathPatch1.

@Parameters({ "user_patchreplace_1" })
@Test(dependsOnMethods = "createForReplace")
public void jsonNoPathPatch1(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 not active
    assertFalse(other.getActive());
    // Verify title changed
    assertNotEquals(user.getTitle(), other.getTitle());
    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 14 with PatchRequest

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

the class PatchReplaceUserTest method jsonPathPatch2.

@Parameters({ "user_patchreplace_4" })
@Test(dependsOnMethods = "jsonPathPatch1")
public void jsonPathPatch2(String patchRequest) {
    Response response = client.patchUser(patchRequest, user.getId(), null, null);
    assertEquals(response.getStatus(), OK.getStatusCode());
    UserResource other = response.readEntity(usrClass);
    assertNotEquals(user.getName().getHonorificPrefix(), other.getName().getHonorificPrefix());
    assertNotEquals(user.getName().getHonorificSuffix(), other.getName().getHonorificSuffix());
    assertNotEquals(user.getName().getFormatted(), other.getName().getFormatted());
    // Verify change in the streetAddress
    Address adr = other.getAddresses().get(0);
    assertNotEquals(user.getAddresses().get(0).getStreetAddress(), adr.getStreetAddress());
    // Verify postal code is there
    assertNotNull(adr.getPostalCode());
    // Verify change in phone number values
    int num = user.getPhoneNumbers().size();
    assertEquals(num, other.getPhoneNumbers().size());
    Set<String> set1 = user.getPhoneNumbers().stream().map(PhoneNumber::getValue).collect(Collectors.toSet());
    Set<String> set2 = other.getPhoneNumbers().stream().map(PhoneNumber::getValue).collect(Collectors.toSet());
    assertFalse(set2.removeAll(set1));
    // Verify x509Certs disappeared
    assertNotNull(other.getX509Certificates());
    user = other;
}
Also used : Response(javax.ws.rs.core.Response) Address(io.jans.scim.model.scim2.user.Address) InstantMessagingAddress(io.jans.scim.model.scim2.user.InstantMessagingAddress) 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 15 with PatchRequest

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

the class PatchReplaceUserTest method objectPatch.

@Test(dependsOnMethods = "jsonPathPatch2")
public void objectPatch() {
    // Create a patch request by supplying a singleton list with one IMS object
    InstantMessagingAddress ims = new InstantMessagingAddress();
    ims.setDisplay("barbas");
    ims.setPrimary(true);
    ims.setType("escape");
    ims.setValue("bjensen");
    PatchOperation op = new PatchOperation();
    op.setOperation("replace");
    op.setPath("ims");
    op.setValue(Collections.singleton(ims));
    PatchRequest pr = new PatchRequest();
    pr.setOperations(Collections.singletonList(op));
    Response response = client.patchUser(pr, user.getId(), null, null);
    assertEquals(response.getStatus(), OK.getStatusCode());
    UserResource other = response.readEntity(usrClass);
    for (int i = 0; i < 2; i++) {
        // Verify different info appeared
        InstantMessagingAddress newIms = other.getIms().get(0);
        assertEquals(newIms.getDisplay(), ims.getDisplay());
        assertEquals(newIms.getValue(), ims.getValue());
        assertEquals(newIms.getType(), ims.getType());
        assertEquals(newIms.getPrimary(), ims.getPrimary());
        // Double check
        response = client.getUserById(user.getId(), "ims", null);
        other = response.readEntity(usrClass);
    }
}
Also used : Response(javax.ws.rs.core.Response) PatchOperation(io.jans.scim.model.scim2.patch.PatchOperation) UserResource(io.jans.scim.model.scim2.user.UserResource) PatchRequest(io.jans.scim.model.scim2.patch.PatchRequest) InstantMessagingAddress(io.jans.scim.model.scim2.user.InstantMessagingAddress) UserBaseTest(io.jans.scim2.client.UserBaseTest) Test(org.testng.annotations.Test)

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