Search in sources :

Example 16 with GroupTO

use of org.apache.syncope.common.lib.to.GroupTO in project syncope by apache.

the class GroupITCase method issueSYNCOPE717.

@Test
public void issueSYNCOPE717() {
    String doubleSchemaName = "double" + getUUIDString();
    // 1. create double schema without conversion pattern
    PlainSchemaTO schema = new PlainSchemaTO();
    schema.setKey(doubleSchemaName);
    schema.setType(AttrSchemaType.Double);
    schema = createSchema(SchemaType.PLAIN, schema);
    assertNotNull(schema);
    assertNull(schema.getConversionPattern());
    AnyTypeClassTO minimalGroup = anyTypeClassService.read("minimal group");
    assertNotNull(minimalGroup);
    minimalGroup.getPlainSchemas().add(doubleSchemaName);
    anyTypeClassService.update(minimalGroup);
    // 2. create group, provide valid input value
    GroupTO groupTO = GroupITCase.getBasicSampleTO("syncope717");
    groupTO.getPlainAttrs().add(attrTO(doubleSchemaName, "11.23"));
    groupTO = createGroup(groupTO).getEntity();
    assertNotNull(groupTO);
    assertEquals("11.23", groupTO.getPlainAttr(doubleSchemaName).get().getValues().get(0));
    // 3. update schema, set conversion pattern
    schema = schemaService.read(SchemaType.PLAIN, schema.getKey());
    schema.setConversionPattern("0.000");
    schemaService.update(SchemaType.PLAIN, schema);
    // 4. re-read group, verify that pattern was applied
    groupTO = groupService.read(groupTO.getKey());
    assertNotNull(groupTO);
    assertEquals("11.230", groupTO.getPlainAttr(doubleSchemaName).get().getValues().get(0));
    // 5. modify group with new double value
    GroupPatch patch = new GroupPatch();
    patch.setKey(groupTO.getKey());
    patch.getPlainAttrs().add(new AttrPatch.Builder().attrTO(attrTO(doubleSchemaName, "11.257")).build());
    groupTO = updateGroup(patch).getEntity();
    assertNotNull(groupTO);
    assertEquals("11.257", groupTO.getPlainAttr(doubleSchemaName).get().getValues().get(0));
    // 6. update schema, unset conversion pattern
    schema.setConversionPattern(null);
    schemaService.update(SchemaType.PLAIN, schema);
    // 7. modify group with new double value, verify that no pattern is applied
    patch = new GroupPatch();
    patch.setKey(groupTO.getKey());
    patch.getPlainAttrs().add(new AttrPatch.Builder().attrTO(attrTO(doubleSchemaName, "11.23")).build());
    groupTO = updateGroup(patch).getEntity();
    assertNotNull(groupTO);
    assertEquals("11.23", groupTO.getPlainAttr(doubleSchemaName).get().getValues().get(0));
}
Also used : PlainSchemaTO(org.apache.syncope.common.lib.to.PlainSchemaTO) AnyTypeClassTO(org.apache.syncope.common.lib.to.AnyTypeClassTO) GroupPatch(org.apache.syncope.common.lib.patch.GroupPatch) AttrPatch(org.apache.syncope.common.lib.patch.AttrPatch) GroupTO(org.apache.syncope.common.lib.to.GroupTO) Test(org.junit.jupiter.api.Test)

Example 17 with GroupTO

use of org.apache.syncope.common.lib.to.GroupTO in project syncope by apache.

the class GroupITCase method deprovision.

@Test
public void deprovision() {
    GroupTO groupTO = null;
    try {
        groupTO = createGroup(getSampleTO("deprovision")).getEntity();
        assertNotNull(groupTO);
        assertNotNull(groupTO.getKey());
        assertNotNull(resourceService.readConnObject(RESOURCE_NAME_LDAP, AnyTypeKind.GROUP.name(), groupTO.getKey()));
        DeassociationPatch deassociationPatch = new DeassociationPatch.Builder().key(groupTO.getKey()).action(ResourceDeassociationAction.DEPROVISION).resource(RESOURCE_NAME_LDAP).build();
        assertNotNull(groupService.deassociate(deassociationPatch).readEntity(BulkActionResult.class));
        groupTO = groupService.read(groupTO.getKey());
        assertNotNull(groupTO);
        assertFalse(groupTO.getResources().isEmpty());
        try {
            resourceService.readConnObject(RESOURCE_NAME_LDAP, AnyTypeKind.GROUP.name(), groupTO.getKey());
            fail("This should not happen");
        } catch (Exception e) {
            assertNotNull(e);
        }
    } finally {
        if (groupTO != null) {
            groupService.delete(groupTO.getKey());
        }
    }
}
Also used : DeassociationPatch(org.apache.syncope.common.lib.patch.DeassociationPatch) BulkActionResult(org.apache.syncope.common.lib.to.BulkActionResult) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) NamingException(javax.naming.NamingException) AccessControlException(java.security.AccessControlException) ForbiddenException(javax.ws.rs.ForbiddenException) GroupTO(org.apache.syncope.common.lib.to.GroupTO) Test(org.junit.jupiter.api.Test)

Example 18 with GroupTO

use of org.apache.syncope.common.lib.to.GroupTO in project syncope by apache.

the class GroupITCase method update.

@Test
public void update() {
    GroupTO groupTO = getSampleTO("latestGroup" + getUUIDString());
    groupTO = createGroup(groupTO).getEntity();
    assertEquals(1, groupTO.getPlainAttrs().size());
    GroupPatch groupPatch = new GroupPatch();
    groupPatch.setKey(groupTO.getKey());
    String modName = "finalGroup" + getUUIDString();
    groupPatch.setName(new StringReplacePatchItem.Builder().value(modName).build());
    groupPatch.getPlainAttrs().add(attrAddReplacePatch("show", "FALSE"));
    groupTO = updateGroup(groupPatch).getEntity();
    assertEquals(modName, groupTO.getName());
    assertEquals(2, groupTO.getPlainAttrs().size());
    groupTO.getPlainAttr("show").get().getValues().clear();
    groupTO = groupService.update(groupTO).readEntity(new GenericType<ProvisioningResult<GroupTO>>() {
    }).getEntity();
    assertFalse(groupTO.getPlainAttr("show").isPresent());
}
Also used : StringReplacePatchItem(org.apache.syncope.common.lib.patch.StringReplacePatchItem) ProvisioningResult(org.apache.syncope.common.lib.to.ProvisioningResult) GroupPatch(org.apache.syncope.common.lib.patch.GroupPatch) GroupTO(org.apache.syncope.common.lib.to.GroupTO) Test(org.junit.jupiter.api.Test)

Example 19 with GroupTO

use of org.apache.syncope.common.lib.to.GroupTO in project syncope by apache.

the class GroupITCase method aStaticMembershipCount.

@Test
public void aStaticMembershipCount() {
    // Create a new printer as a static member of a new group
    GroupTO group = getBasicSampleTO("aStaticMembership");
    group = createGroup(group).getEntity();
    AnyObjectTO printer = new AnyObjectTO();
    printer.setRealm(SyncopeConstants.ROOT_REALM);
    printer.setName("Printer_" + getUUIDString());
    printer.setType("PRINTER");
    MembershipTO membership = new MembershipTO();
    membership.setGroupKey(group.getKey());
    printer.getMemberships().add(membership);
    printer = createAnyObject(printer).getEntity();
    group = groupService.read(group.getKey());
    assertEquals(0, group.getDynamicAnyObjectMembershipCount());
    assertEquals(1, group.getStaticAnyObjectMembershipCount());
    anyObjectService.delete(printer.getKey());
    groupService.delete(group.getKey());
}
Also used : AnyObjectTO(org.apache.syncope.common.lib.to.AnyObjectTO) MembershipTO(org.apache.syncope.common.lib.to.MembershipTO) GroupTO(org.apache.syncope.common.lib.to.GroupTO) Test(org.junit.jupiter.api.Test)

Example 20 with GroupTO

use of org.apache.syncope.common.lib.to.GroupTO in project syncope by apache.

the class GroupITCase method deprovisionUnlinked.

@Test
public void deprovisionUnlinked() {
    GroupTO groupTO = getSampleTO("deprovision");
    groupTO.getResources().clear();
    try {
        groupTO = createGroup(groupTO).getEntity();
        assertNotNull(groupTO);
        try {
            resourceService.readConnObject(RESOURCE_NAME_LDAP, AnyTypeKind.GROUP.name(), groupTO.getKey());
            fail("This should not happen");
        } catch (Exception e) {
            assertNotNull(e);
        }
        AssociationPatch associationPatch = new AssociationPatch.Builder().key(groupTO.getKey()).action(ResourceAssociationAction.PROVISION).resource(RESOURCE_NAME_LDAP).build();
        assertNotNull(groupService.associate(associationPatch).readEntity(BulkActionResult.class));
        groupTO = groupService.read(groupTO.getKey());
        assertTrue(groupTO.getResources().isEmpty());
        assertNotNull(resourceService.readConnObject(RESOURCE_NAME_LDAP, AnyTypeKind.GROUP.name(), groupTO.getKey()));
        DeassociationPatch deassociationPatch = new DeassociationPatch.Builder().key(groupTO.getKey()).action(ResourceDeassociationAction.DEPROVISION).resource(RESOURCE_NAME_LDAP).build();
        assertNotNull(groupService.deassociate(deassociationPatch).readEntity(BulkActionResult.class));
        groupTO = groupService.read(groupTO.getKey());
        assertNotNull(groupTO);
        assertTrue(groupTO.getResources().isEmpty());
        try {
            resourceService.readConnObject(RESOURCE_NAME_LDAP, AnyTypeKind.GROUP.name(), groupTO.getKey());
            fail("This should not happen");
        } catch (Exception e) {
            assertNotNull(e);
        }
    } finally {
        if (groupTO.getKey() != null) {
            groupService.delete(groupTO.getKey());
        }
    }
}
Also used : DeassociationPatch(org.apache.syncope.common.lib.patch.DeassociationPatch) BulkActionResult(org.apache.syncope.common.lib.to.BulkActionResult) AssociationPatch(org.apache.syncope.common.lib.patch.AssociationPatch) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) NamingException(javax.naming.NamingException) AccessControlException(java.security.AccessControlException) ForbiddenException(javax.ws.rs.ForbiddenException) GroupTO(org.apache.syncope.common.lib.to.GroupTO) Test(org.junit.jupiter.api.Test)

Aggregations

GroupTO (org.apache.syncope.common.lib.to.GroupTO)90 Test (org.junit.jupiter.api.Test)47 UserTO (org.apache.syncope.common.lib.to.UserTO)34 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)27 GroupPatch (org.apache.syncope.common.lib.patch.GroupPatch)23 MembershipTO (org.apache.syncope.common.lib.to.MembershipTO)17 AnyObjectTO (org.apache.syncope.common.lib.to.AnyObjectTO)16 List (java.util.List)15 AttrTO (org.apache.syncope.common.lib.to.AttrTO)15 ConnObjectTO (org.apache.syncope.common.lib.to.ConnObjectTO)14 ProvisioningResult (org.apache.syncope.common.lib.to.ProvisioningResult)14 Response (javax.ws.rs.core.Response)13 NamingException (javax.naming.NamingException)12 PropagationStatus (org.apache.syncope.common.lib.to.PropagationStatus)12 Map (java.util.Map)11 ForbiddenException (javax.ws.rs.ForbiddenException)11 AccessControlException (java.security.AccessControlException)10 BulkActionResult (org.apache.syncope.common.lib.to.BulkActionResult)10 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)10 Collections (java.util.Collections)9