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());
}
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));
}
}
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);
});
}
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()));
}
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);
}
Aggregations