Search in sources :

Example 16 with InvalidEntityException

use of org.apache.syncope.core.persistence.api.attrvalue.validation.InvalidEntityException in project syncope by apache.

the class PlainAttrTest method saveWithEnum.

@Test
public void saveWithEnum() throws ClassNotFoundException {
    User user = userDAO.find("1417acbe-cbf6-4277-9372-e75e04f97000");
    assertNotNull(user);
    PlainSchema gender = plainSchemaDAO.find("gender");
    assertNotNull(gender);
    assertNotNull(gender.getType());
    assertNotNull(gender.getEnumerationValues());
    UPlainAttr attribute = entityFactory.newEntity(UPlainAttr.class);
    attribute.setOwner(user);
    attribute.setSchema(gender);
    user.add(attribute);
    Exception thrown = null;
    try {
        attribute.add("A", anyUtilsFactory.getInstance(AnyTypeKind.USER));
    } catch (ValidationException e) {
        thrown = e;
    }
    assertNotNull(thrown);
    attribute.add("M", anyUtilsFactory.getInstance(AnyTypeKind.USER));
    InvalidEntityException iee = null;
    try {
        userDAO.save(user);
    } catch (InvalidEntityException e) {
        iee = e;
    }
    assertNull(iee);
}
Also used : User(org.apache.syncope.core.persistence.api.entity.user.User) ValidationException(javax.validation.ValidationException) PlainSchema(org.apache.syncope.core.persistence.api.entity.PlainSchema) UPlainAttr(org.apache.syncope.core.persistence.api.entity.user.UPlainAttr) InvalidEntityException(org.apache.syncope.core.persistence.api.attrvalue.validation.InvalidEntityException) ValidationException(javax.validation.ValidationException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) InvalidEntityException(org.apache.syncope.core.persistence.api.attrvalue.validation.InvalidEntityException) Test(org.junit.jupiter.api.Test) AbstractTest(org.apache.syncope.core.persistence.jpa.AbstractTest)

Example 17 with InvalidEntityException

use of org.apache.syncope.core.persistence.api.attrvalue.validation.InvalidEntityException in project syncope by apache.

the class ResourceTest method issueSYNCOPE418.

@Test
public void issueSYNCOPE418() {
    ExternalResource resource = entityFactory.newEntity(ExternalResource.class);
    resource.setKey("http://schemas.examples.org/security/authorization/organizationUnit");
    try {
        resourceDAO.save(resource);
        fail("This should not happen");
    } catch (InvalidEntityException e) {
        assertTrue(e.hasViolation(EntityViolationType.InvalidKey));
    }
}
Also used : ExternalResource(org.apache.syncope.core.persistence.api.entity.resource.ExternalResource) InvalidEntityException(org.apache.syncope.core.persistence.api.attrvalue.validation.InvalidEntityException) Test(org.junit.jupiter.api.Test) AbstractTest(org.apache.syncope.core.persistence.jpa.AbstractTest)

Example 18 with InvalidEntityException

use of org.apache.syncope.core.persistence.api.attrvalue.validation.InvalidEntityException in project syncope by apache.

the class TaskTest method savePullTask.

@Test
public void savePullTask() {
    ExternalResource resource = resourceDAO.find("ws-target-resource-1");
    assertNotNull(resource);
    AnyTemplatePullTask template = entityFactory.newEntity(AnyTemplatePullTask.class);
    template.set(new UserTO());
    PullTask task = entityFactory.newEntity(PullTask.class);
    task.setName("savePullTask");
    task.setDescription("PullTask description");
    task.setActive(true);
    task.setPullMode(PullMode.FULL_RECONCILIATION);
    task.add(template);
    task.setCronExpression("BLA BLA");
    task.setMatchingRule(MatchingRule.UPDATE);
    task.setUnmatchingRule(UnmatchingRule.PROVISION);
    // this save() fails because of an invalid Cron Expression
    InvalidEntityException exception = null;
    try {
        taskDAO.save(task);
    } catch (InvalidEntityException e) {
        exception = e;
    }
    assertNotNull(exception);
    task.setCronExpression(null);
    // this save() fails because a PullTask requires a target resource
    exception = null;
    try {
        taskDAO.save(task);
    } catch (InvalidEntityException e) {
        exception = e;
    }
    assertNotNull(exception);
    task.setResource(resource);
    Implementation pullActions = entityFactory.newEntity(Implementation.class);
    pullActions.setKey("PullActions" + UUID.randomUUID().toString());
    pullActions.setEngine(ImplementationEngine.JAVA);
    pullActions.setType(ImplementationType.PULL_ACTIONS);
    pullActions.setBody(PullActions.class.getName());
    pullActions = implementationDAO.save(pullActions);
    task.add(pullActions);
    // this save() finally works
    task = taskDAO.save(task);
    assertNotNull(task);
    PullTask actual = taskDAO.find(task.getKey());
    assertEquals(task, actual);
}
Also used : UserTO(org.apache.syncope.common.lib.to.UserTO) PullTask(org.apache.syncope.core.persistence.api.entity.task.PullTask) AnyTemplatePullTask(org.apache.syncope.core.persistence.api.entity.task.AnyTemplatePullTask) AnyTemplatePullTask(org.apache.syncope.core.persistence.api.entity.task.AnyTemplatePullTask) PullActions(org.apache.syncope.core.provisioning.api.pushpull.PullActions) ExternalResource(org.apache.syncope.core.persistence.api.entity.resource.ExternalResource) InvalidEntityException(org.apache.syncope.core.persistence.api.attrvalue.validation.InvalidEntityException) Implementation(org.apache.syncope.core.persistence.api.entity.Implementation) Test(org.junit.jupiter.api.Test) AbstractTest(org.apache.syncope.core.persistence.jpa.AbstractTest)

Aggregations

InvalidEntityException (org.apache.syncope.core.persistence.api.attrvalue.validation.InvalidEntityException)18 AbstractTest (org.apache.syncope.core.persistence.jpa.AbstractTest)13 Test (org.junit.jupiter.api.Test)13 User (org.apache.syncope.core.persistence.api.entity.user.User)6 Set (java.util.Set)4 PlainSchema (org.apache.syncope.core.persistence.api.entity.PlainSchema)4 Date (java.util.Date)3 Map (java.util.Map)2 ClientExceptionType (org.apache.syncope.common.lib.types.ClientExceptionType)2 EntityViolationType (org.apache.syncope.common.lib.types.EntityViolationType)2 DerSchema (org.apache.syncope.core.persistence.api.entity.DerSchema)2 Implementation (org.apache.syncope.core.persistence.api.entity.Implementation)2 Realm (org.apache.syncope.core.persistence.api.entity.Realm)2 ExternalResource (org.apache.syncope.core.persistence.api.entity.resource.ExternalResource)2 UPlainAttr (org.apache.syncope.core.persistence.api.entity.user.UPlainAttr)2 JPAUser (org.apache.syncope.core.persistence.jpa.entity.user.JPAUser)2 Transactional (org.springframework.transaction.annotation.Transactional)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1