Search in sources :

Example 41 with UserResource

use of io.jans.scim.model.scim2.user.UserResource in project jans by JanssenProject.

the class UpdatedUsersTest method updatingUsers.

@Test(dependsOnMethods = "creatingUsers")
public void updatingUsers() throws Exception {
    // pick 2 rand inums
    String A = inums.get(randInt(N));
    String B = inums.get(randInt(N));
    UserResource u = new UserResource();
    u.setActive(true);
    // Update active attribute for the chosen users
    Response response = client.updateUser(u, A, "meta.lastModified", null);
    assertEquals(response.getStatus(), OK.getStatusCode());
    String isoDate = response.readEntity(usrClass).getMeta().getLastModified();
    logger.info("User {} updated at '{}'", A, isoDate);
    response = client.updateUser(u, B, "id", null);
    assertEquals(response.getStatus(), OK.getStatusCode());
    logger.info("Querying updated users after '{}'", isoDate);
    response = client.usersChangedAfter(isoDate, 0, N);
    assertEquals(response.getStatus(), OK.getStatusCode());
    String json = response.readEntity(String.class);
    // Convert response into an opaque map
    Map<String, Object> map = mapper.readValue(json, new TypeReference<Map<String, Object>>() {
    });
    Set<String> foundInums = getFoundInums(map);
    assertTrue(foundInums.remove(A));
    assertTrue(A.equals(B) || foundInums.remove(B));
    // Ensure there are no false positives
    assertTrue(foundInums.isEmpty());
}
Also used : Response(javax.ws.rs.core.Response) UserResource(io.jans.scim.model.scim2.user.UserResource) UserBaseTest(io.jans.scim2.client.UserBaseTest) BeforeTest(org.testng.annotations.BeforeTest) Test(org.testng.annotations.Test)

Example 42 with UserResource

use of io.jans.scim.model.scim2.user.UserResource in project jans by JanssenProject.

the class UpdatedUsersTest method getDummyPatient.

private UserResource getDummyPatient() {
    UserResource user = new UserResource();
    user.setUserName("test-" + Math.random());
    user.setDisplayName(user.getUserName());
    return user;
}
Also used : UserResource(io.jans.scim.model.scim2.user.UserResource)

Example 43 with UserResource

use of io.jans.scim.model.scim2.user.UserResource 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 44 with UserResource

use of io.jans.scim.model.scim2.user.UserResource 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 45 with UserResource

use of io.jans.scim.model.scim2.user.UserResource 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

UserResource (io.jans.scim.model.scim2.user.UserResource)49 Response (javax.ws.rs.core.Response)47 Test (org.testng.annotations.Test)37 UserBaseTest (io.jans.scim2.client.UserBaseTest)34 ListResponse (io.jans.scim.model.scim2.ListResponse)21 SearchRequest (io.jans.scim.model.scim2.SearchRequest)14 Parameters (org.testng.annotations.Parameters)11 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)7 Path (javax.ws.rs.Path)7 BaseScimResource (io.jans.scim.model.scim2.BaseScimResource)6 CustomAttributes (io.jans.scim.model.scim2.CustomAttributes)6 SkipTest (io.jans.scim2.listener.SkipTest)6 URI (java.net.URI)6 DefaultValue (javax.ws.rs.DefaultValue)6 HeaderParam (javax.ws.rs.HeaderParam)6 Status (javax.ws.rs.core.Response.Status)6 BeforeTest (org.testng.annotations.BeforeTest)6 ScimCustomPerson (io.jans.scim.model.scim.ScimCustomPerson)5 GroupResource (io.jans.scim.model.scim2.group.GroupResource)5 PatchRequest (io.jans.scim.model.scim2.patch.PatchRequest)5