Search in sources :

Example 26 with PlainSchema

use of org.apache.syncope.core.persistence.api.entity.PlainSchema in project syncope by apache.

the class PlainSchemaTest method checkForEnumType.

@Test
public void checkForEnumType() {
    PlainSchema schema = entityFactory.newEntity(PlainSchema.class);
    schema.setType(AttrSchemaType.Enum);
    schema.setKey("color");
    try {
        plainSchemaDAO.save(schema);
        fail("This should not happen");
    } catch (Exception e) {
        assertNotNull(e);
    }
    schema.setEnumerationValues("red" + SyncopeConstants.ENUM_VALUES_SEPARATOR + "yellow");
    schema.setEnumerationKeys("1" + SyncopeConstants.ENUM_VALUES_SEPARATOR + "2");
    plainSchemaDAO.save(schema);
    PlainSchema actual = plainSchemaDAO.find(schema.getKey());
    assertNotNull(actual);
    assertNotNull(actual.getEnumerationKeys());
    assertFalse(actual.getEnumerationKeys().isEmpty());
}
Also used : PlainSchema(org.apache.syncope.core.persistence.api.entity.PlainSchema) 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 27 with PlainSchema

use of org.apache.syncope.core.persistence.api.entity.PlainSchema in project syncope by apache.

the class PlainSchemaTest method issueSYNCOPE418.

@Test
public void issueSYNCOPE418() {
    PlainSchema schema = entityFactory.newEntity(PlainSchema.class);
    schema.setKey("http://schemas.examples.org/security/authorization/organizationUnit");
    try {
        plainSchemaDAO.save(schema);
        fail("This should not happen");
    } catch (InvalidEntityException e) {
        assertTrue(e.hasViolation(EntityViolationType.InvalidKey));
    }
}
Also used : PlainSchema(org.apache.syncope.core.persistence.api.entity.PlainSchema) 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 28 with PlainSchema

use of org.apache.syncope.core.persistence.api.entity.PlainSchema in project syncope by apache.

the class PlainSchemaTest method saveInvalidSchema.

@Test
public void saveInvalidSchema() {
    assertThrows(InvalidEntityException.class, () -> {
        PlainSchema schema = entityFactory.newEntity(PlainSchema.class);
        schema.setKey("username");
        plainSchemaDAO.save(schema);
    });
}
Also used : PlainSchema(org.apache.syncope.core.persistence.api.entity.PlainSchema) Test(org.junit.jupiter.api.Test) AbstractTest(org.apache.syncope.core.persistence.jpa.AbstractTest)

Example 29 with PlainSchema

use of org.apache.syncope.core.persistence.api.entity.PlainSchema in project syncope by apache.

the class PlainAttrTest method saveWithBinary.

@Test
public void saveWithBinary() throws UnsupportedEncodingException {
    User user = userDAO.find("1417acbe-cbf6-4277-9372-e75e04f97000");
    PlainSchema photoSchema = plainSchemaDAO.find("photo");
    assertNotNull(photoSchema);
    assertNotNull(photoSchema.getMimeType());
    byte[] bytes = new byte[20];
    new Random().nextBytes(bytes);
    String photoB64Value = Base64.getEncoder().encodeToString(bytes);
    UPlainAttr attr = entityFactory.newEntity(UPlainAttr.class);
    attr.setOwner(user);
    attr.setSchema(photoSchema);
    attr.add(photoB64Value, anyUtilsFactory.getInstance(AnyTypeKind.USER));
    user.add(attr);
    userDAO.save(user);
    UPlainAttr photo = user.getPlainAttr("photo").get();
    assertNotNull(photo);
    assertEquals(1, photo.getValues().size());
    assertTrue(Arrays.equals(bytes, photo.getValues().get(0).getBinaryValue()));
}
Also used : User(org.apache.syncope.core.persistence.api.entity.user.User) Random(java.util.Random) PlainSchema(org.apache.syncope.core.persistence.api.entity.PlainSchema) UPlainAttr(org.apache.syncope.core.persistence.api.entity.user.UPlainAttr) Test(org.junit.jupiter.api.Test) AbstractTest(org.apache.syncope.core.persistence.jpa.AbstractTest)

Example 30 with PlainSchema

use of org.apache.syncope.core.persistence.api.entity.PlainSchema in project syncope by apache.

the class PlainAttrTest method save.

@Test
public void save() throws ClassNotFoundException {
    User user = userDAO.find("1417acbe-cbf6-4277-9372-e75e04f97000");
    PlainSchema emailSchema = plainSchemaDAO.find("email");
    assertNotNull(emailSchema);
    UPlainAttr attr = entityFactory.newEntity(UPlainAttr.class);
    attr.setOwner(user);
    attr.setSchema(emailSchema);
    Exception thrown = null;
    try {
        attr.add("john.doe@gmail.com", anyUtilsFactory.getInstance(AnyTypeKind.USER));
        attr.add("mario.rossi@gmail.com", anyUtilsFactory.getInstance(AnyTypeKind.USER));
    } catch (ValidationException e) {
        thrown = e;
    }
    assertNull(thrown);
    try {
        attr.add("http://www.apache.org", anyUtilsFactory.getInstance(AnyTypeKind.USER));
    } catch (ValidationException e) {
        thrown = e;
    }
    assertNotNull(thrown);
}
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) Test(org.junit.jupiter.api.Test) AbstractTest(org.apache.syncope.core.persistence.jpa.AbstractTest)

Aggregations

PlainSchema (org.apache.syncope.core.persistence.api.entity.PlainSchema)55 Test (org.junit.jupiter.api.Test)22 AbstractTest (org.apache.syncope.core.persistence.jpa.AbstractTest)21 AnyUtils (org.apache.syncope.core.persistence.api.entity.AnyUtils)15 VirSchema (org.apache.syncope.core.persistence.api.entity.VirSchema)14 User (org.apache.syncope.core.persistence.api.entity.user.User)13 DerSchema (org.apache.syncope.core.persistence.api.entity.DerSchema)12 UPlainAttr (org.apache.syncope.core.persistence.api.entity.user.UPlainAttr)11 ArrayList (java.util.ArrayList)10 PlainAttrValue (org.apache.syncope.core.persistence.api.entity.PlainAttrValue)10 Transactional (org.springframework.transaction.annotation.Transactional)10 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)9 AnyTypeClass (org.apache.syncope.core.persistence.api.entity.AnyTypeClass)9 MappingItem (org.apache.syncope.core.persistence.api.entity.resource.MappingItem)9 Collections (java.util.Collections)8 HashSet (java.util.HashSet)8 List (java.util.List)8 Optional (java.util.Optional)8 NotFoundException (org.apache.syncope.core.persistence.api.dao.NotFoundException)8 ExternalResource (org.apache.syncope.core.persistence.api.entity.resource.ExternalResource)8