You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@syncope.apache.org by il...@apache.org on 2015/02/12 10:14:33 UTC
[28/54] [abbrv] [partial] syncope git commit: [SYNCOPE-620] Renaming
'server' after 'core',
to provide continuity with older releases (especially for archetype)
http://git-wip-us.apache.org/repos/asf/syncope/blob/d30c8526/syncope620/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/entity/AttrTest.java
----------------------------------------------------------------------
diff --git a/syncope620/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/entity/AttrTest.java b/syncope620/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/entity/AttrTest.java
new file mode 100644
index 0000000..39e4cd2
--- /dev/null
+++ b/syncope620/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/entity/AttrTest.java
@@ -0,0 +1,235 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.syncope.core.persistence.jpa.entity;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.io.UnsupportedEncodingException;
+import java.util.Arrays;
+import java.util.Random;
+import javax.validation.ValidationException;
+import org.apache.syncope.common.lib.SyncopeConstants;
+import org.apache.syncope.common.lib.types.AttributableType;
+import org.apache.syncope.common.lib.types.EntityViolationType;
+import org.apache.syncope.core.persistence.api.attrvalue.validation.InvalidEntityException;
+import org.apache.syncope.core.persistence.api.dao.PlainAttrDAO;
+import org.apache.syncope.core.persistence.api.dao.PlainSchemaDAO;
+import org.apache.syncope.core.persistence.api.dao.UserDAO;
+import org.apache.syncope.core.persistence.api.entity.user.UPlainAttr;
+import org.apache.syncope.core.persistence.api.entity.user.UPlainAttrUniqueValue;
+import org.apache.syncope.core.persistence.api.entity.user.UPlainSchema;
+import org.apache.syncope.core.persistence.api.entity.user.User;
+import org.apache.syncope.core.persistence.jpa.AbstractTest;
+import org.apache.syncope.core.misc.security.Encryptor;
+import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.security.crypto.codec.Base64;
+import org.springframework.transaction.annotation.Transactional;
+
+@Transactional
+public class AttrTest extends AbstractTest {
+
+ @Autowired
+ private UserDAO userDAO;
+
+ @Autowired
+ private PlainAttrDAO plainAttrDAO;
+
+ @Autowired
+ private PlainSchemaDAO userSchemaDAO;
+
+ @Test
+ public void findById() {
+ UPlainAttr attribute = plainAttrDAO.find(100L, UPlainAttr.class);
+ assertNotNull("did not find expected attribute schema", attribute);
+ attribute = plainAttrDAO.find(104L, UPlainAttr.class);
+ assertNotNull("did not find expected attribute schema", attribute);
+ }
+
+ @Test
+ public void read() {
+ UPlainAttr attribute = plainAttrDAO.find(100L, UPlainAttr.class);
+ assertNotNull(attribute);
+ assertTrue(attribute.getValues().isEmpty());
+ assertNotNull(attribute.getUniqueValue());
+ }
+
+ @Test
+ public void save() throws ClassNotFoundException {
+ User user = userDAO.find(1L);
+
+ UPlainSchema emailSchema = userSchemaDAO.find("email", UPlainSchema.class);
+ assertNotNull(emailSchema);
+
+ UPlainAttr attribute = entityFactory.newEntity(UPlainAttr.class);
+ attribute.setSchema(emailSchema);
+ attribute.setOwner(user);
+
+ Exception thrown = null;
+ try {
+ attribute.addValue("john.doe@gmail.com", attrUtilFactory.getInstance(AttributableType.USER));
+ attribute.addValue("mario.rossi@gmail.com", attrUtilFactory.getInstance(AttributableType.USER));
+ } catch (ValidationException e) {
+ thrown = e;
+ }
+ assertNull("no validation exception expected here ", thrown);
+
+ try {
+ attribute.addValue("http://www.apache.org", attrUtilFactory.getInstance(AttributableType.USER));
+ } catch (ValidationException e) {
+ thrown = e;
+ }
+ assertNotNull("validation exception expected here ", thrown);
+ }
+
+ @Test
+ public void saveWithEnum() throws ClassNotFoundException {
+ User user = userDAO.find(1L);
+
+ UPlainSchema gender = userSchemaDAO.find("gender", UPlainSchema.class);
+ assertNotNull(gender);
+ assertNotNull(gender.getType());
+ assertNotNull(gender.getEnumerationValues());
+
+ UPlainAttr attribute = entityFactory.newEntity(UPlainAttr.class);
+ attribute.setSchema(gender);
+ attribute.setOwner(user);
+ user.addPlainAttr(attribute);
+
+ Exception thrown = null;
+
+ try {
+ attribute.addValue("A", attrUtilFactory.getInstance(AttributableType.USER));
+ } catch (ValidationException e) {
+ thrown = e;
+ }
+ assertNotNull("validation exception expected here ", thrown);
+
+ attribute.addValue("M", attrUtilFactory.getInstance(AttributableType.USER));
+
+ InvalidEntityException iee = null;
+ try {
+ userDAO.save(user);
+ } catch (InvalidEntityException e) {
+ iee = e;
+ }
+ assertNull(iee);
+ }
+
+ @Test
+ public void validateAndSave() {
+ User user = userDAO.find(1L);
+
+ final UPlainSchema emailSchema = userSchemaDAO.find("email", UPlainSchema.class);
+ assertNotNull(emailSchema);
+
+ final UPlainSchema fullnameSchema = userSchemaDAO.find("fullname", UPlainSchema.class);
+ assertNotNull(fullnameSchema);
+
+ UPlainAttr attribute = entityFactory.newEntity(UPlainAttr.class);
+ attribute.setSchema(emailSchema);
+
+ UPlainAttrUniqueValue uauv = entityFactory.newEntity(UPlainAttrUniqueValue.class);
+ uauv.setAttr(attribute);
+ uauv.setSchema(fullnameSchema);
+ uauv.setStringValue("a value");
+
+ attribute.setUniqueValue(uauv);
+
+ user.addPlainAttr(attribute);
+
+ InvalidEntityException iee = null;
+ try {
+ userDAO.save(user);
+ fail();
+ } catch (InvalidEntityException e) {
+ iee = e;
+ }
+ assertNotNull(iee);
+ // for attribute
+ assertTrue(iee.hasViolation(EntityViolationType.InvalidValueList));
+ // for uauv
+ assertTrue(iee.hasViolation(EntityViolationType.InvalidUPlainSchema));
+ }
+
+ @Test
+ public void saveWithEncrypted() throws Exception {
+ User user = userDAO.find(1L);
+
+ final UPlainSchema obscureSchema = userSchemaDAO.find("obscure", UPlainSchema.class);
+ assertNotNull(obscureSchema);
+ assertNotNull(obscureSchema.getSecretKey());
+ assertNotNull(obscureSchema.getCipherAlgorithm());
+
+ UPlainAttr attribute = entityFactory.newEntity(UPlainAttr.class);
+ attribute.setSchema(obscureSchema);
+ attribute.addValue("testvalue", attrUtilFactory.getInstance(AttributableType.USER));
+ attribute.setOwner(user);
+ user.addPlainAttr(attribute);
+
+ userDAO.save(user);
+
+ UPlainAttr obscure = user.getPlainAttr("obscure");
+ assertNotNull(obscure);
+ assertEquals(1, obscure.getValues().size());
+ assertEquals(Encryptor.getInstance(obscureSchema.getSecretKey()).
+ encode("testvalue", obscureSchema.getCipherAlgorithm()), obscure.getValues().get(0).getStringValue());
+ }
+
+ @Test
+ public void saveWithBinary() throws UnsupportedEncodingException {
+ User user = userDAO.find(1L);
+
+ final UPlainSchema photoSchema = userSchemaDAO.find("photo", UPlainSchema.class);
+ assertNotNull(photoSchema);
+ assertNotNull(photoSchema.getMimeType());
+
+ final byte[] bytes = new byte[20];
+ new Random().nextBytes(bytes);
+ final String photoB64Value = new String(Base64.encode(bytes), SyncopeConstants.DEFAULT_ENCODING);
+
+ UPlainAttr attribute = entityFactory.newEntity(UPlainAttr.class);
+ attribute.setSchema(photoSchema);
+ attribute.addValue(photoB64Value, attrUtilFactory.getInstance(AttributableType.USER));
+ attribute.setOwner(user);
+ user.addPlainAttr(attribute);
+
+ userDAO.save(user);
+
+ UPlainAttr obscure = user.getPlainAttr("photo");
+ assertNotNull(obscure);
+ assertEquals(1, obscure.getValues().size());
+ assertTrue(Arrays.equals(bytes, obscure.getValues().get(0).getBinaryValue()));
+ }
+
+ @Test
+ public void delete() {
+ UPlainAttr attribute = plainAttrDAO.find(104L, UPlainAttr.class);
+ String attrSchemaName = attribute.getSchema().getKey();
+
+ plainAttrDAO.delete(attribute.getKey(), UPlainAttr.class);
+
+ UPlainSchema schema = userSchemaDAO.find(attrSchemaName, UPlainSchema.class);
+ assertNotNull("user attribute schema deleted when deleting values", schema);
+ }
+}
http://git-wip-us.apache.org/repos/asf/syncope/blob/d30c8526/syncope620/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/entity/AttributableSearchTest.java
----------------------------------------------------------------------
diff --git a/syncope620/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/entity/AttributableSearchTest.java b/syncope620/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/entity/AttributableSearchTest.java
new file mode 100644
index 0000000..052143f
--- /dev/null
+++ b/syncope620/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/entity/AttributableSearchTest.java
@@ -0,0 +1,494 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.syncope.core.persistence.jpa.entity;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import org.apache.syncope.common.lib.types.SubjectType;
+import org.apache.syncope.core.persistence.api.RoleEntitlementUtil;
+import org.apache.syncope.core.persistence.api.dao.EntitlementDAO;
+import org.apache.syncope.core.persistence.api.dao.RoleDAO;
+import org.apache.syncope.core.persistence.api.dao.SubjectSearchDAO;
+import org.apache.syncope.core.persistence.api.dao.UserDAO;
+import org.apache.syncope.core.persistence.api.dao.search.AttributeCond;
+import org.apache.syncope.core.persistence.api.dao.search.MembershipCond;
+import org.apache.syncope.core.persistence.api.dao.search.OrderByClause;
+import org.apache.syncope.core.persistence.api.dao.search.ResourceCond;
+import org.apache.syncope.core.persistence.api.dao.search.SearchCond;
+import org.apache.syncope.core.persistence.api.dao.search.SubjectCond;
+import org.apache.syncope.core.persistence.api.entity.role.Role;
+import org.apache.syncope.core.persistence.api.entity.user.User;
+import org.apache.syncope.core.persistence.jpa.AbstractTest;
+import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.transaction.annotation.Transactional;
+
+@Transactional
+public class AttributableSearchTest extends AbstractTest {
+
+ @Autowired
+ private UserDAO userDAO;
+
+ @Autowired
+ private RoleDAO roleDAO;
+
+ @Autowired
+ private SubjectSearchDAO searchDAO;
+
+ @Autowired
+ private EntitlementDAO entitlementDAO;
+
+ @Test
+ public void userMatch() {
+ User user = userDAO.find(1L);
+ assertNotNull(user);
+
+ MembershipCond membershipCond = new MembershipCond();
+ membershipCond.setRoleId(5L);
+
+ assertFalse(searchDAO.matches(user, SearchCond.getLeafCond(membershipCond), SubjectType.USER));
+
+ membershipCond.setRoleId(1L);
+
+ assertTrue(searchDAO.matches(user, SearchCond.getLeafCond(membershipCond), SubjectType.USER));
+ }
+
+ @Test
+ public void roleMatch() {
+ Role role = roleDAO.find(1L);
+ assertNotNull(role);
+
+ AttributeCond attrCond = new AttributeCond();
+ attrCond.setSchema("show");
+ attrCond.setType(AttributeCond.Type.ISNOTNULL);
+
+ assertTrue(searchDAO.matches(role, SearchCond.getLeafCond(attrCond), SubjectType.ROLE));
+ }
+
+ @Test
+ public void searchWithLikeCondition() {
+ AttributeCond fullnameLeafCond = new AttributeCond(AttributeCond.Type.LIKE);
+ fullnameLeafCond.setSchema("fullname");
+ fullnameLeafCond.setExpression("%o%");
+
+ MembershipCond membershipCond = new MembershipCond();
+ membershipCond.setRoleId(1L);
+
+ AttributeCond loginDateCond = new AttributeCond(AttributeCond.Type.EQ);
+ loginDateCond.setSchema("loginDate");
+ loginDateCond.setExpression("2009-05-26");
+
+ SearchCond subCond = SearchCond.getAndCond(SearchCond.getLeafCond(fullnameLeafCond), SearchCond.getLeafCond(
+ membershipCond));
+
+ assertTrue(subCond.isValid());
+
+ SearchCond cond = SearchCond.getAndCond(subCond, SearchCond.getLeafCond(loginDateCond));
+
+ assertTrue(cond.isValid());
+
+ List<User> users =
+ searchDAO.search(RoleEntitlementUtil.getRoleKeys(entitlementDAO.findAll()), cond, SubjectType.USER);
+ assertNotNull(users);
+ assertEquals(1, users.size());
+ }
+
+ @Test
+ public void searchWithNotCondition() {
+ AttributeCond fullnameLeafCond = new AttributeCond(AttributeCond.Type.EQ);
+ fullnameLeafCond.setSchema("fullname");
+ fullnameLeafCond.setExpression("Giuseppe Verdi");
+
+ SearchCond cond = SearchCond.getNotLeafCond(fullnameLeafCond);
+ assertTrue(cond.isValid());
+
+ List<User> users =
+ searchDAO.search(RoleEntitlementUtil.getRoleKeys(entitlementDAO.findAll()), cond, SubjectType.USER);
+ assertNotNull(users);
+ assertEquals(4, users.size());
+
+ Set<Long> ids = new HashSet<>(users.size());
+ for (User user : users) {
+ ids.add(user.getKey());
+ }
+ assertTrue(ids.contains(1L));
+ assertTrue(ids.contains(3L));
+ }
+
+ @Test
+ public void searchByBoolean() {
+ AttributeCond coolLeafCond = new AttributeCond(AttributeCond.Type.EQ);
+ coolLeafCond.setSchema("cool");
+ coolLeafCond.setExpression("true");
+
+ SearchCond cond = SearchCond.getLeafCond(coolLeafCond);
+ assertTrue(cond.isValid());
+
+ List<User> users =
+ searchDAO.search(RoleEntitlementUtil.getRoleKeys(entitlementDAO.findAll()), cond, SubjectType.USER);
+ assertNotNull(users);
+ assertEquals(1, users.size());
+
+ assertEquals(Long.valueOf(4L), users.get(0).getKey());
+ }
+
+ @Test
+ public void searchByPageAndSize() {
+ AttributeCond fullnameLeafCond = new AttributeCond(AttributeCond.Type.LIKE);
+ fullnameLeafCond.setSchema("fullname");
+ fullnameLeafCond.setExpression("%o%");
+
+ MembershipCond membershipCond = new MembershipCond();
+ membershipCond.setRoleId(1L);
+
+ AttributeCond loginDateCond = new AttributeCond(AttributeCond.Type.EQ);
+ loginDateCond.setSchema("loginDate");
+ loginDateCond.setExpression("2009-05-26");
+
+ SearchCond subCond = SearchCond.getAndCond(SearchCond.getLeafCond(fullnameLeafCond), SearchCond.getLeafCond(
+ membershipCond));
+
+ assertTrue(subCond.isValid());
+
+ SearchCond cond = SearchCond.getAndCond(subCond, SearchCond.getLeafCond(loginDateCond));
+
+ assertTrue(cond.isValid());
+
+ List<User> users = searchDAO.search(RoleEntitlementUtil.getRoleKeys(entitlementDAO.findAll()),
+ cond, 1, 2, Collections.<OrderByClause>emptyList(),
+ SubjectType.USER);
+ assertNotNull(users);
+ assertEquals(1, users.size());
+
+ users = searchDAO.search(RoleEntitlementUtil.getRoleKeys(entitlementDAO.findAll()),
+ cond, 2, 2, Collections.<OrderByClause>emptyList(),
+ SubjectType.USER);
+ assertNotNull(users);
+ assertTrue(users.isEmpty());
+ }
+
+ @Test
+ public void searchByMembership() {
+ MembershipCond membershipCond = new MembershipCond();
+ membershipCond.setRoleId(1L);
+
+ List<User> users = searchDAO.search(
+ RoleEntitlementUtil.getRoleKeys(entitlementDAO.findAll()), SearchCond.getLeafCond(membershipCond),
+ SubjectType.USER);
+ assertNotNull(users);
+ assertEquals(2, users.size());
+
+ membershipCond = new MembershipCond();
+ membershipCond.setRoleId(5L);
+
+ users = searchDAO.search(
+ RoleEntitlementUtil.getRoleKeys(entitlementDAO.findAll()), SearchCond.getNotLeafCond(membershipCond),
+ SubjectType.USER);
+ assertNotNull(users);
+ assertEquals(5, users.size());
+ }
+
+ @Test
+ public void searchByIsNull() {
+ AttributeCond coolLeafCond = new AttributeCond(AttributeCond.Type.ISNULL);
+ coolLeafCond.setSchema("cool");
+
+ List<User> users = searchDAO.search(
+ RoleEntitlementUtil.getRoleKeys(entitlementDAO.findAll()), SearchCond.getLeafCond(coolLeafCond),
+ SubjectType.USER);
+ assertNotNull(users);
+ assertEquals(4, users.size());
+
+ coolLeafCond = new AttributeCond(AttributeCond.Type.ISNOTNULL);
+ coolLeafCond.setSchema("cool");
+
+ users = searchDAO.search(
+ RoleEntitlementUtil.getRoleKeys(entitlementDAO.findAll()), SearchCond.getLeafCond(coolLeafCond),
+ SubjectType.USER);
+ assertNotNull(users);
+ assertEquals(1, users.size());
+ }
+
+ @Test
+ public void searchByResource() {
+ ResourceCond ws2 = new ResourceCond();
+ ws2.setResourceName("ws-target-resource-2");
+
+ ResourceCond ws1 = new ResourceCond();
+ ws1.setResourceName("ws-target-resource-list-mappings-2");
+
+ SearchCond searchCondition = SearchCond.getAndCond(SearchCond.getNotLeafCond(ws2), SearchCond.getLeafCond(ws1));
+
+ assertTrue(searchCondition.isValid());
+
+ List<User> users = searchDAO.search(
+ RoleEntitlementUtil.getRoleKeys(entitlementDAO.findAll()), searchCondition,
+ SubjectType.USER);
+
+ assertNotNull(users);
+ assertEquals(1, users.size());
+ }
+
+ @Test
+ public void searchByBooleanSubjectCond() {
+ SubjectCond booleanCond = new SubjectCond(SubjectCond.Type.EQ);
+ booleanCond.setSchema("inheritPlainAttrs");
+ booleanCond.setExpression("true");
+
+ SearchCond searchCondition = SearchCond.getLeafCond(booleanCond);
+
+ List<Role> matchingRoles = searchDAO.search(RoleEntitlementUtil.getRoleKeys(entitlementDAO.findAll()),
+ searchCondition, SubjectType.ROLE);
+ assertNotNull(matchingRoles);
+ assertFalse(matchingRoles.isEmpty());
+ }
+
+ @Test
+ public void searchByUsernameAndKey() {
+ SubjectCond usernameLeafCond = new SubjectCond(SubjectCond.Type.LIKE);
+ usernameLeafCond.setSchema("username");
+ usernameLeafCond.setExpression("%ini");
+
+ SubjectCond idRightCond = new SubjectCond(SubjectCond.Type.LT);
+ idRightCond.setSchema("key");
+ idRightCond.setExpression("2");
+
+ SearchCond searchCondition = SearchCond.getAndCond(SearchCond.getLeafCond(usernameLeafCond),
+ SearchCond.getLeafCond(idRightCond));
+
+ List<User> matchingUsers = searchDAO.search(RoleEntitlementUtil.getRoleKeys(entitlementDAO.findAll()),
+ searchCondition, SubjectType.USER);
+
+ assertNotNull(matchingUsers);
+ assertEquals(1, matchingUsers.size());
+ assertEquals("rossini", matchingUsers.iterator().next().getUsername());
+ assertEquals(1L, matchingUsers.iterator().next().getKey().longValue());
+ }
+
+ @Test
+ public void searchByRolenameAndKey() {
+ SubjectCond rolenameLeafCond = new SubjectCond(SubjectCond.Type.EQ);
+ rolenameLeafCond.setSchema("name");
+ rolenameLeafCond.setExpression("root");
+
+ SubjectCond idRightCond = new SubjectCond(SubjectCond.Type.LT);
+ idRightCond.setSchema("key");
+ idRightCond.setExpression("2");
+
+ SearchCond searchCondition = SearchCond.getAndCond(SearchCond.getLeafCond(rolenameLeafCond),
+ SearchCond.getLeafCond(idRightCond));
+
+ assertTrue(searchCondition.isValid());
+
+ List<Role> matchingRoles = searchDAO.search(RoleEntitlementUtil.getRoleKeys(entitlementDAO.findAll()),
+ searchCondition, SubjectType.ROLE);
+
+ assertNotNull(matchingRoles);
+ assertEquals(1, matchingRoles.size());
+ assertEquals("root", matchingRoles.iterator().next().getName());
+ assertEquals(1L, matchingRoles.iterator().next().getKey().longValue());
+ }
+
+ @Test
+ public void searchByUsernameAndFullname() {
+ SubjectCond usernameLeafCond = new SubjectCond(SubjectCond.Type.EQ);
+ usernameLeafCond.setSchema("username");
+ usernameLeafCond.setExpression("rossini");
+
+ AttributeCond idRightCond = new AttributeCond(AttributeCond.Type.LIKE);
+ idRightCond.setSchema("fullname");
+ idRightCond.setExpression("Giuseppe V%");
+
+ SearchCond searchCondition = SearchCond.getOrCond(SearchCond.getLeafCond(usernameLeafCond),
+ SearchCond.getLeafCond(idRightCond));
+
+ List<User> matchingUsers =
+ searchDAO.search(RoleEntitlementUtil.getRoleKeys(entitlementDAO.findAll()), searchCondition,
+ SubjectType.USER);
+
+ assertNotNull(matchingUsers);
+ assertEquals(2, matchingUsers.size());
+ }
+
+ @Test
+ public void searchById() {
+ SubjectCond idLeafCond = new SubjectCond(SubjectCond.Type.LT);
+ idLeafCond.setSchema("id");
+ idLeafCond.setExpression("2");
+
+ SearchCond searchCondition = SearchCond.getLeafCond(idLeafCond);
+ assertTrue(searchCondition.isValid());
+
+ List<User> users =
+ searchDAO.search(RoleEntitlementUtil.getRoleKeys(entitlementDAO.findAll()), searchCondition,
+ SubjectType.USER);
+
+ assertNotNull(users);
+ assertEquals(1, users.size());
+ assertEquals(1L, users.iterator().next().getKey().longValue());
+
+ idLeafCond = new SubjectCond(SubjectCond.Type.LT);
+ idLeafCond.setSchema("id");
+ idLeafCond.setExpression("4");
+
+ searchCondition = SearchCond.getNotLeafCond(idLeafCond);
+ assertTrue(searchCondition.isValid());
+
+ users = searchDAO.search(RoleEntitlementUtil.getRoleKeys(entitlementDAO.findAll()), searchCondition,
+ SubjectType.USER);
+
+ assertNotNull(users);
+ assertEquals(2, users.size());
+ boolean found = false;
+ for (User user : users) {
+ if (user.getKey() == 4) {
+ found = true;
+ }
+ }
+ assertTrue(found);
+ }
+
+ @Test
+ public void userOrderBy() {
+ SubjectCond usernameLeafCond = new SubjectCond(SubjectCond.Type.EQ);
+ usernameLeafCond.setSchema("username");
+ usernameLeafCond.setExpression("rossini");
+ AttributeCond idRightCond = new AttributeCond(AttributeCond.Type.LIKE);
+ idRightCond.setSchema("fullname");
+ idRightCond.setExpression("Giuseppe V%");
+ SearchCond searchCondition = SearchCond.getOrCond(
+ SearchCond.getLeafCond(usernameLeafCond), SearchCond.getLeafCond(idRightCond));
+
+ List<OrderByClause> orderByClauses = new ArrayList<OrderByClause>();
+ OrderByClause orderByClause = new OrderByClause();
+ orderByClause.setField("username");
+ orderByClause.setDirection(OrderByClause.Direction.DESC);
+ orderByClauses.add(orderByClause);
+ orderByClause = new OrderByClause();
+ orderByClause.setField("fullname");
+ orderByClause.setDirection(OrderByClause.Direction.ASC);
+ orderByClauses.add(orderByClause);
+
+ List<User> users = searchDAO.search(RoleEntitlementUtil.getRoleKeys(entitlementDAO.findAll()),
+ searchCondition, Collections.singletonList(orderByClause),
+ SubjectType.USER);
+ assertEquals(searchDAO.count(RoleEntitlementUtil.getRoleKeys(entitlementDAO.findAll()),
+ searchCondition, SubjectType.USER),
+ users.size());
+ }
+
+ @Test
+ public void roleOrderBy() {
+ SubjectCond idLeafCond = new SubjectCond(SubjectCond.Type.LIKE);
+ idLeafCond.setSchema("name");
+ idLeafCond.setExpression("%r");
+ SearchCond searchCondition = SearchCond.getLeafCond(idLeafCond);
+ assertTrue(searchCondition.isValid());
+
+ OrderByClause orderByClause = new OrderByClause();
+ orderByClause.setField("name");
+
+ List<Role> roles = searchDAO.search(RoleEntitlementUtil.getRoleKeys(entitlementDAO.findAll()),
+ searchCondition, Collections.singletonList(orderByClause), SubjectType.ROLE);
+ assertEquals(searchDAO.count(RoleEntitlementUtil.getRoleKeys(entitlementDAO.findAll()),
+ searchCondition, SubjectType.ROLE),
+ roles.size());
+ }
+
+ @Test
+ public void issue202() {
+ ResourceCond ws2 = new ResourceCond();
+ ws2.setResourceName("ws-target-resource-2");
+
+ ResourceCond ws1 = new ResourceCond();
+ ws1.setResourceName("ws-target-resource-list-mappings-1");
+
+ SearchCond searchCondition =
+ SearchCond.getAndCond(SearchCond.getNotLeafCond(ws2), SearchCond.getNotLeafCond(ws1));
+ assertTrue(searchCondition.isValid());
+
+ List<User> users = searchDAO.search(RoleEntitlementUtil.getRoleKeys(entitlementDAO.findAll()),
+ searchCondition, SubjectType.USER);
+ assertNotNull(users);
+ assertEquals(2, users.size());
+ boolean found = false;
+ for (User user : users) {
+ if (user.getKey() == 4) {
+ found = true;
+ }
+ }
+ assertTrue(found);
+ }
+
+ @Test
+ public void issue242() {
+ SubjectCond cond = new SubjectCond(AttributeCond.Type.LIKE);
+ cond.setSchema("id");
+ cond.setExpression("test%");
+
+ SearchCond searchCondition = SearchCond.getLeafCond(cond);
+ assertTrue(searchCondition.isValid());
+
+ List<User> users = searchDAO.search(RoleEntitlementUtil.getRoleKeys(entitlementDAO.findAll()),
+ searchCondition, SubjectType.USER);
+ assertNotNull(users);
+ assertTrue(users.isEmpty());
+ }
+
+ @Test
+ public void issueSYNCOPE46() {
+ SubjectCond cond = new SubjectCond(AttributeCond.Type.LIKE);
+ cond.setSchema("username");
+ cond.setExpression("%ossin%");
+
+ SearchCond searchCondition = SearchCond.getLeafCond(cond);
+ assertTrue(searchCondition.isValid());
+
+ List<User> users = searchDAO.search(RoleEntitlementUtil.getRoleKeys(entitlementDAO.findAll()),
+ searchCondition, SubjectType.USER);
+ assertNotNull(users);
+ assertEquals(1, users.size());
+ }
+
+ @Test
+ public void issueSYNCOPE433() {
+ AttributeCond isNullCond = new AttributeCond(AttributeCond.Type.ISNULL);
+ isNullCond.setSchema("loginDate");
+
+ SubjectCond likeCond = new SubjectCond(AttributeCond.Type.LIKE);
+ likeCond.setSchema("username");
+ likeCond.setExpression("%ossin%");
+
+ SearchCond searchCond = SearchCond.getOrCond(
+ SearchCond.getLeafCond(isNullCond), SearchCond.getLeafCond(likeCond));
+
+ Integer count = searchDAO.count(RoleEntitlementUtil.getRoleKeys(entitlementDAO.findAll()), searchCond,
+ SubjectType.USER);
+ assertNotNull(count);
+ assertTrue(count > 0);
+ }
+}
http://git-wip-us.apache.org/repos/asf/syncope/blob/d30c8526/syncope620/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/entity/ConfTest.java
----------------------------------------------------------------------
diff --git a/syncope620/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/entity/ConfTest.java b/syncope620/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/entity/ConfTest.java
new file mode 100644
index 0000000..e5e1ecc
--- /dev/null
+++ b/syncope620/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/entity/ConfTest.java
@@ -0,0 +1,107 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.syncope.core.persistence.jpa.entity;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import org.apache.syncope.common.lib.types.AttrSchemaType;
+import org.apache.syncope.common.lib.types.AttributableType;
+import org.apache.syncope.common.lib.types.EntityViolationType;
+import org.apache.syncope.core.persistence.api.attrvalue.validation.InvalidEntityException;
+import org.apache.syncope.core.persistence.api.dao.ConfDAO;
+import org.apache.syncope.core.persistence.api.dao.PlainSchemaDAO;
+import org.apache.syncope.core.persistence.api.entity.conf.CPlainAttr;
+import org.apache.syncope.core.persistence.api.entity.conf.CPlainSchema;
+import org.apache.syncope.core.persistence.jpa.AbstractTest;
+import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.transaction.annotation.Transactional;
+
+@Transactional
+public class ConfTest extends AbstractTest {
+
+ @Autowired
+ private ConfDAO confDAO;
+
+ @Autowired
+ private PlainSchemaDAO plainSchemaDAO;
+
+ @Test
+ public void read() {
+ CPlainAttr conf = confDAO.find("selfRegistration.allowed");
+ assertNotNull(conf);
+ assertTrue(conf.getValues().get(0).getBooleanValue());
+
+ conf = confDAO.find("authentication.statuses");
+ assertNotNull(conf);
+ assertEquals(2, conf.getValues().size());
+
+ conf = confDAO.find("non.existing");
+ assertNull(conf);
+ }
+
+ @Test
+ public void setAndDelete() {
+ // 1. create CSChema
+ CPlainSchema useless = entityFactory.newEntity(CPlainSchema.class);
+ useless.setKey("useless");
+ useless.setType(AttrSchemaType.Date);
+ useless.setConversionPattern("yyyy-MM-dd");
+ useless = plainSchemaDAO.save(useless);
+
+ // 2. create conf
+ CPlainAttr newConf = entityFactory.newEntity(CPlainAttr.class);
+ newConf.setSchema(useless);
+ newConf.addValue("2014-06-20", attrUtilFactory.getInstance(AttributableType.CONFIGURATION));
+ confDAO.save(newConf);
+
+ CPlainAttr actual = confDAO.find("useless");
+ assertEquals(actual.getValuesAsStrings(), newConf.getValuesAsStrings());
+
+ // 3. update conf
+ newConf.getValues().clear();
+ newConf.addValue("2014-06-20", attrUtilFactory.getInstance(AttributableType.CONFIGURATION));
+ confDAO.save(newConf);
+
+ actual = confDAO.find("useless");
+ assertEquals(actual.getValuesAsStrings(), newConf.getValuesAsStrings());
+
+ // 4. delete conf
+ confDAO.delete("useless");
+ assertNull(confDAO.find("useless"));
+ }
+
+ @Test
+ public void issueSYNCOPE418() {
+ try {
+ CPlainSchema failing = entityFactory.newEntity(CPlainSchema.class);
+ failing.setKey("http://schemas.examples.org/security/authorization/organizationUnit");
+ failing.setType(AttrSchemaType.String);
+ plainSchemaDAO.save(failing);
+
+ fail();
+ } catch (InvalidEntityException e) {
+ assertTrue(e.hasViolation(EntityViolationType.InvalidName));
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/syncope/blob/d30c8526/syncope620/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/entity/ConnInstanceTest.java
----------------------------------------------------------------------
diff --git a/syncope620/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/entity/ConnInstanceTest.java b/syncope620/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/entity/ConnInstanceTest.java
new file mode 100644
index 0000000..03b7c5d
--- /dev/null
+++ b/syncope620/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/entity/ConnInstanceTest.java
@@ -0,0 +1,145 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.syncope.core.persistence.jpa.entity;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import org.apache.syncope.common.lib.types.ConnConfPropSchema;
+import org.apache.syncope.common.lib.types.ConnConfProperty;
+import org.apache.syncope.core.persistence.api.dao.ConnInstanceDAO;
+import org.apache.syncope.core.persistence.api.entity.ConnInstance;
+import org.apache.syncope.core.persistence.jpa.AbstractTest;
+import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.transaction.annotation.Transactional;
+
+@Transactional
+public class ConnInstanceTest extends AbstractTest {
+
+ @Autowired
+ private ConnInstanceDAO connInstanceDAO;
+
+ @Test
+ public void findAll() {
+ List<ConnInstance> connectors = connInstanceDAO.findAll();
+ assertNotNull(connectors);
+ assertFalse(connectors.isEmpty());
+ }
+
+ @Test
+ public void findById() {
+ ConnInstance connectorInstance = connInstanceDAO.find(100L);
+
+ assertNotNull("findById did not work", connectorInstance);
+
+ assertEquals("invalid connector name",
+ "net.tirasa.connid.bundles.soap.WebServiceConnector", connectorInstance.getConnectorName());
+
+ assertEquals("invalid bundle name", "net.tirasa.connid.bundles.soap", connectorInstance.getBundleName());
+ }
+
+ @Test
+ public void save() throws ClassNotFoundException {
+ ConnInstance connInstance = entityFactory.newEntity(ConnInstance.class);
+
+ connInstance.setLocation(new File(System.getProperty("java.io.tmpdir")).toURI().toString());
+
+ // set connector version
+ connInstance.setVersion("1.0");
+
+ // set connector name
+ connInstance.setConnectorName("WebService");
+
+ // set bundle name
+ connInstance.setBundleName("org.apache.syncope.core.persistence.test.util");
+
+ connInstance.setDisplayName("New");
+
+ connInstance.setConnRequestTimeout(60);
+
+ // set the connector configuration using PropertyTO
+ Set<ConnConfProperty> conf = new HashSet<ConnConfProperty>();
+
+ ConnConfPropSchema endpointSchema = new ConnConfPropSchema();
+ endpointSchema.setName("endpoint");
+ endpointSchema.setType(String.class.getName());
+ endpointSchema.setRequired(true);
+ ConnConfProperty endpoint = new ConnConfProperty();
+ endpoint.setSchema(endpointSchema);
+ endpoint.getValues().add("http://host.domain");
+
+ ConnConfPropSchema servicenameSchema = new ConnConfPropSchema();
+ servicenameSchema.setName("servicename");
+ servicenameSchema.setType(String.class.getName());
+ servicenameSchema.setRequired(true);
+ ConnConfProperty servicename = new ConnConfProperty();
+ servicename.setSchema(servicenameSchema);
+ endpoint.getValues().add("Provisioning");
+
+ conf.add(endpoint);
+ conf.add(servicename);
+
+ // set connector configuration
+ connInstance.setConfiguration(conf);
+ assertFalse(connInstance.getConfiguration().isEmpty());
+
+ // perform save operation
+ ConnInstance actual = connInstanceDAO.save(connInstance);
+
+ assertNotNull("save did not work", actual.getKey());
+
+ assertTrue("save did not work", actual.getKey() > 100L);
+
+ assertEquals("save did not work for \"name\" attribute", "WebService", actual.getConnectorName());
+
+ assertEquals("save did not work for \"bundle name\" attribute", "org.apache.syncope.core.persistence.test.util",
+ actual.getBundleName());
+
+ assertEquals("save did not work for \"majorVersion\" attribute", "1.0", connInstance.getVersion());
+
+ assertEquals("New", actual.getDisplayName());
+
+ assertEquals(new Integer(60), actual.getConnRequestTimeout());
+
+ conf = connInstance.getConfiguration();
+ assertFalse(conf.isEmpty());
+
+ assertNotNull("configuration retrieving failed", conf);
+ assertTrue(conf.size() == 2);
+ }
+
+ @Test
+ public void delete() {
+ ConnInstance connectorInstance = connInstanceDAO.find(100L);
+ assertNotNull("find to delete did not work", connectorInstance);
+
+ connInstanceDAO.delete(connectorInstance.getKey());
+
+ ConnInstance actual = connInstanceDAO.find(100L);
+ assertNull("delete did not work", actual);
+ }
+}
http://git-wip-us.apache.org/repos/asf/syncope/blob/d30c8526/syncope620/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/entity/DerAttrTest.java
----------------------------------------------------------------------
diff --git a/syncope620/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/entity/DerAttrTest.java b/syncope620/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/entity/DerAttrTest.java
new file mode 100644
index 0000000..b1c6c91
--- /dev/null
+++ b/syncope620/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/entity/DerAttrTest.java
@@ -0,0 +1,272 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.syncope.core.persistence.jpa.entity;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.List;
+import org.apache.syncope.core.persistence.api.dao.DerAttrDAO;
+import org.apache.syncope.core.persistence.api.dao.DerSchemaDAO;
+import org.apache.syncope.core.persistence.api.dao.MembershipDAO;
+import org.apache.syncope.core.persistence.api.dao.RoleDAO;
+import org.apache.syncope.core.persistence.api.dao.UserDAO;
+import org.apache.syncope.core.persistence.api.entity.membership.MDerAttr;
+import org.apache.syncope.core.persistence.api.entity.membership.MDerAttrTemplate;
+import org.apache.syncope.core.persistence.api.entity.membership.MDerSchema;
+import org.apache.syncope.core.persistence.api.entity.membership.MPlainAttrValue;
+import org.apache.syncope.core.persistence.api.entity.membership.Membership;
+import org.apache.syncope.core.persistence.api.entity.role.RDerAttr;
+import org.apache.syncope.core.persistence.api.entity.role.RDerAttrTemplate;
+import org.apache.syncope.core.persistence.api.entity.role.RDerSchema;
+import org.apache.syncope.core.persistence.api.entity.role.RPlainAttrValue;
+import org.apache.syncope.core.persistence.api.entity.role.Role;
+import org.apache.syncope.core.persistence.api.entity.user.UDerAttr;
+import org.apache.syncope.core.persistence.api.entity.user.UDerSchema;
+import org.apache.syncope.core.persistence.api.entity.user.UPlainAttrValue;
+import org.apache.syncope.core.persistence.api.entity.user.User;
+import org.apache.syncope.core.persistence.jpa.AbstractTest;
+import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.transaction.annotation.Transactional;
+
+@Transactional
+public class DerAttrTest extends AbstractTest {
+
+ @Autowired
+ private DerAttrDAO derAttrDAO;
+
+ @Autowired
+ private UserDAO userDAO;
+
+ @Autowired
+ private MembershipDAO membershipDAO;
+
+ @Autowired
+ private RoleDAO roleDAO;
+
+ @Autowired
+ private DerSchemaDAO derSchemaDAO;
+
+ @Test
+ public void findAll() {
+ List<UDerAttr> list = derAttrDAO.findAll(UDerAttr.class);
+ assertEquals("did not get expected number of derived attributes ", 2, list.size());
+ }
+
+ @Test
+ public void findById() {
+ UDerAttr attribute = derAttrDAO.find(100L, UDerAttr.class);
+ assertNotNull("did not find expected attribute schema", attribute);
+ }
+
+ @Test
+ public void saveUDerAttribute() {
+ UDerSchema cnSchema = derSchemaDAO.find("cn", UDerSchema.class);
+ assertNotNull(cnSchema);
+
+ User owner = userDAO.find(3L);
+ assertNotNull("did not get expected user", owner);
+
+ UDerAttr derAttr = entityFactory.newEntity(UDerAttr.class);
+ derAttr.setOwner(owner);
+ derAttr.setSchema(cnSchema);
+
+ derAttr = derAttrDAO.save(derAttr);
+
+ UDerAttr actual = derAttrDAO.find(derAttr.getKey(), UDerAttr.class);
+ assertNotNull("expected save to work", actual);
+ assertEquals(derAttr, actual);
+
+ UPlainAttrValue firstname = owner.getPlainAttr("firstname").getValues().iterator().next();
+ UPlainAttrValue surname = owner.getPlainAttr("surname").getValues().iterator().next();
+
+ assertEquals(surname.getValue() + ", " + firstname.getValue(), derAttr.getValue(owner.getPlainAttrs()));
+ }
+
+ @Test
+ public void saveMDerAttribute() {
+ Membership owner = membershipDAO.find(1L);
+ assertNotNull("did not get expected user", owner);
+
+ MDerAttr derAttr = entityFactory.newEntity(MDerAttr.class);
+ derAttr.setOwner(owner);
+ derAttr.setTemplate(owner.getRole().getAttrTemplate(MDerAttrTemplate.class, "mderiveddata"));
+
+ derAttr = derAttrDAO.save(derAttr);
+ assertNotNull(derAttr.getTemplate());
+
+ MDerAttr actual = derAttrDAO.find(derAttr.getKey(), MDerAttr.class);
+ assertNotNull("expected save to work", actual);
+ assertEquals(derAttr, actual);
+
+ MPlainAttrValue sx = owner.getPlainAttr("mderived_sx").getValues().iterator().next();
+ MPlainAttrValue dx = owner.getPlainAttr("mderived_dx").getValues().iterator().next();
+
+ assertEquals(sx.getValue() + "-" + dx.getValue(), derAttr.getValue(owner.getPlainAttrs()));
+ }
+
+ @Test
+ public void saveRDerAttribute() {
+ Role owner = roleDAO.find(1L);
+ assertNotNull("did not get expected user", owner);
+
+ RDerAttr derAttr = entityFactory.newEntity(RDerAttr.class);
+ derAttr.setOwner(owner);
+ derAttr.setTemplate(owner.getAttrTemplate(RDerAttrTemplate.class, "rderiveddata"));
+
+ derAttr = derAttrDAO.save(derAttr);
+ assertNotNull(derAttr.getTemplate());
+
+ RDerAttr actual = derAttrDAO.find(derAttr.getKey(), RDerAttr.class);
+ assertNotNull("expected save to work", actual);
+ assertEquals(derAttr, actual);
+
+ RPlainAttrValue sx = owner.getPlainAttr("rderived_sx").getValues().iterator().next();
+ RPlainAttrValue dx = owner.getPlainAttr("rderived_dx").getValues().iterator().next();
+
+ assertEquals(sx.getValue() + "-" + dx.getValue(), derAttr.getValue(owner.getPlainAttrs()));
+ }
+
+ @Test
+ public void delete() {
+ UDerAttr attribute = derAttrDAO.find(100L, UDerAttr.class);
+ String attributeSchemaName = attribute.getSchema().getKey();
+
+ derAttrDAO.delete(attribute.getKey(), UDerAttr.class);
+
+ UDerAttr actual = derAttrDAO.find(100L, UDerAttr.class);
+ assertNull("delete did not work", actual);
+
+ UDerSchema attributeSchema = derSchemaDAO.find(attributeSchemaName, UDerSchema.class);
+ assertNotNull("user derived attribute schema deleted " + "when deleting values", attributeSchema);
+ }
+
+ @Test
+ public void issueSYNCOPE134User() {
+ UDerSchema sderived = entityFactory.newEntity(UDerSchema.class);
+ sderived.setKey("sderived");
+ sderived.setExpression("status + ' - ' + username + ' - ' + creationDate + '[' + failedLogins + ']'");
+
+ sderived = derSchemaDAO.save(sderived);
+ derSchemaDAO.flush();
+
+ UDerSchema actual = derSchemaDAO.find("sderived", UDerSchema.class);
+ assertNotNull("expected save to work", actual);
+ assertEquals(sderived, actual);
+
+ User owner = userDAO.find(3L);
+ assertNotNull("did not get expected user", owner);
+
+ UDerAttr derAttr = entityFactory.newEntity(UDerAttr.class);
+ derAttr.setOwner(owner);
+ derAttr.setSchema(sderived);
+
+ derAttr = derAttrDAO.save(derAttr);
+ derAttrDAO.flush();
+
+ derAttr = derAttrDAO.find(derAttr.getKey(), UDerAttr.class);
+ assertNotNull("expected save to work", derAttr);
+
+ String value = derAttr.getValue(owner.getPlainAttrs());
+ assertNotNull(value);
+ assertFalse(value.isEmpty());
+ assertTrue(value.startsWith("active - vivaldi - 2010-10-20"));
+ assertTrue(value.endsWith("[0]"));
+ }
+
+ @Test
+ public void issueSYNCOPE134Role() {
+ RDerSchema sderived = entityFactory.newEntity(RDerSchema.class);
+ sderived.setKey("sderived");
+ sderived.setExpression("name");
+
+ sderived = derSchemaDAO.save(sderived);
+ derSchemaDAO.flush();
+
+ RDerSchema actual = derSchemaDAO.find("sderived", RDerSchema.class);
+ assertNotNull("expected save to work", actual);
+ assertEquals(sderived, actual);
+
+ Role owner = roleDAO.find(7L);
+ assertNotNull("did not get expected role", owner);
+
+ RDerAttrTemplate template = entityFactory.newEntity(RDerAttrTemplate.class);
+ template.setSchema(sderived);
+ owner.getAttrTemplates(RDerAttrTemplate.class).add(template);
+
+ RDerAttr derAttr = entityFactory.newEntity(RDerAttr.class);
+ derAttr.setOwner(owner);
+ derAttr.setTemplate(owner.getAttrTemplate(RDerAttrTemplate.class, sderived.getKey()));
+
+ derAttr = derAttrDAO.save(derAttr);
+ assertNotNull(derAttr.getTemplate());
+ derAttrDAO.flush();
+
+ derAttr = derAttrDAO.find(derAttr.getKey(), RDerAttr.class);
+ assertNotNull("expected save to work", derAttr);
+
+ String value = derAttr.getValue(owner.getPlainAttrs());
+ assertNotNull(value);
+ assertFalse(value.isEmpty());
+ assertTrue(value.startsWith("managingDirector"));
+ }
+
+ @Test
+ public void issueSYNCOPE134Memb() {
+ MDerSchema mderived = entityFactory.newEntity(MDerSchema.class);
+ mderived.setKey("mderived");
+ mderived.setExpression("key");
+
+ mderived = derSchemaDAO.save(mderived);
+ derSchemaDAO.flush();
+
+ MDerSchema actual = derSchemaDAO.find("mderived", MDerSchema.class);
+ assertNotNull("expected save to work", actual);
+ assertEquals(mderived, actual);
+
+ Membership owner = membershipDAO.find(4L);
+ assertNotNull("did not get expected membership", owner);
+
+ MDerAttrTemplate template = entityFactory.newEntity(MDerAttrTemplate.class);
+ template.setSchema(mderived);
+ owner.getRole().getAttrTemplates(MDerAttrTemplate.class).add(template);
+
+ derSchemaDAO.flush();
+
+ MDerAttr derAttr = entityFactory.newEntity(MDerAttr.class);
+ derAttr.setOwner(owner);
+ derAttr.setTemplate(owner.getRole().getAttrTemplate(MDerAttrTemplate.class, mderived.getKey()));
+
+ derAttr = derAttrDAO.save(derAttr);
+ assertNotNull(derAttr.getTemplate());
+ derAttrDAO.flush();
+
+ derAttr = derAttrDAO.find(derAttr.getKey(), MDerAttr.class);
+ assertNotNull("expected save to work", derAttr);
+
+ String value = derAttr.getValue(owner.getPlainAttrs());
+ assertNotNull(value);
+ assertFalse(value.isEmpty());
+ assertTrue(value.equalsIgnoreCase("4"));
+ }
+}
http://git-wip-us.apache.org/repos/asf/syncope/blob/d30c8526/syncope620/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/entity/DerSchemaTest.java
----------------------------------------------------------------------
diff --git a/syncope620/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/entity/DerSchemaTest.java b/syncope620/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/entity/DerSchemaTest.java
new file mode 100644
index 0000000..5a65f13
--- /dev/null
+++ b/syncope620/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/entity/DerSchemaTest.java
@@ -0,0 +1,103 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.syncope.core.persistence.jpa.entity;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.util.List;
+import org.apache.syncope.common.lib.types.AttributableType;
+import org.apache.syncope.common.lib.types.EntityViolationType;
+import org.apache.syncope.core.persistence.api.attrvalue.validation.InvalidEntityException;
+import org.apache.syncope.core.persistence.api.dao.DerSchemaDAO;
+import org.apache.syncope.core.persistence.api.entity.DerSchema;
+import org.apache.syncope.core.persistence.api.entity.role.RDerSchema;
+import org.apache.syncope.core.persistence.api.entity.user.UDerSchema;
+import org.apache.syncope.core.persistence.jpa.AbstractTest;
+import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.transaction.annotation.Transactional;
+
+@Transactional
+public class DerSchemaTest extends AbstractTest {
+
+ @Autowired
+ private DerSchemaDAO derSchemaDAO;
+
+ @Test
+ public void findAll() {
+ List<UDerSchema> list = derSchemaDAO.findAll(UDerSchema.class);
+ assertEquals(3, list.size());
+ }
+
+ @Test
+ public void findByName() {
+ UDerSchema attributeSchema = derSchemaDAO.find("cn", UDerSchema.class);
+ assertNotNull("did not find expected derived attribute schema", attributeSchema);
+ }
+
+ @Test
+ public void save() {
+ UDerSchema derivedAttributeSchema = entityFactory.newEntity(UDerSchema.class);
+ derivedAttributeSchema.setKey("cn2");
+ derivedAttributeSchema.setExpression("firstname surname");
+
+ derSchemaDAO.save(derivedAttributeSchema);
+
+ UDerSchema actual = derSchemaDAO.find("cn2", UDerSchema.class);
+ assertNotNull("expected save to work", actual);
+ assertEquals(derivedAttributeSchema, actual);
+ }
+
+ @Test
+ public void delete() {
+ UDerSchema cn = derSchemaDAO.find("cn", UDerSchema.class);
+ assertNotNull(cn);
+
+ derSchemaDAO.delete(cn.getKey(), attrUtilFactory.getInstance(AttributableType.USER));
+
+ DerSchema actual = derSchemaDAO.find("cn", UDerSchema.class);
+ assertNull("delete did not work", actual);
+
+ // ------------- //
+ RDerSchema rderiveddata = derSchemaDAO.find("rderiveddata", RDerSchema.class);
+ assertNotNull(rderiveddata);
+
+ derSchemaDAO.delete(rderiveddata.getKey(), attrUtilFactory.getInstance(AttributableType.ROLE));
+
+ actual = derSchemaDAO.find("rderiveddata", RDerSchema.class);
+ assertNull("delete did not work", actual);
+ }
+
+ @Test
+ public void issueSYNCOPE418() {
+ UDerSchema schema = entityFactory.newEntity(UDerSchema.class);
+ schema.setKey("http://schemas.examples.org/security/authorization/organizationUnit");
+
+ try {
+ derSchemaDAO.save(schema);
+ fail();
+ } catch (InvalidEntityException e) {
+ assertTrue(e.hasViolation(EntityViolationType.InvalidName));
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/syncope/blob/d30c8526/syncope620/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/entity/EntitlementTest.java
----------------------------------------------------------------------
diff --git a/syncope620/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/entity/EntitlementTest.java b/syncope620/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/entity/EntitlementTest.java
new file mode 100644
index 0000000..dd59873
--- /dev/null
+++ b/syncope620/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/entity/EntitlementTest.java
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.syncope.core.persistence.jpa.entity;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+import java.util.List;
+import org.apache.syncope.core.persistence.api.dao.EntitlementDAO;
+import org.apache.syncope.core.persistence.api.entity.Entitlement;
+import org.apache.syncope.core.persistence.jpa.AbstractTest;
+import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.transaction.annotation.Transactional;
+
+@Transactional
+public class EntitlementTest extends AbstractTest {
+
+ @Autowired
+ private EntitlementDAO entitlementDAO;
+
+ @Test
+ public void findAll() {
+ List<Entitlement> list = entitlementDAO.findAll();
+ assertEquals("did not get expected number of entitlements ", 86, list.size());
+ }
+
+ @Test
+ public void findByName() {
+ Entitlement entitlement = entitlementDAO.find("base");
+ assertNotNull("did not find expected entitlement", entitlement);
+ }
+
+ @Test
+ public void save() {
+ Entitlement entitlement = entityFactory.newEntity(Entitlement.class);
+ entitlement.setKey("another");
+
+ entitlementDAO.save(entitlement);
+
+ Entitlement actual = entitlementDAO.find("another");
+ assertNotNull("expected save to work", actual);
+ assertEquals(entitlement, actual);
+ }
+
+ @Test
+ public void delete() {
+ Entitlement entitlement = entitlementDAO.find("base");
+ assertNotNull("did not find expected entitlement", entitlement);
+
+ entitlementDAO.delete("base");
+
+ assertNull(entitlementDAO.find("base"));
+ }
+}
http://git-wip-us.apache.org/repos/asf/syncope/blob/d30c8526/syncope620/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/entity/MembershipTest.java
----------------------------------------------------------------------
diff --git a/syncope620/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/entity/MembershipTest.java b/syncope620/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/entity/MembershipTest.java
new file mode 100644
index 0000000..c5693c8
--- /dev/null
+++ b/syncope620/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/entity/MembershipTest.java
@@ -0,0 +1,84 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.syncope.core.persistence.jpa.entity;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+import java.util.List;
+import org.apache.syncope.core.persistence.api.dao.MembershipDAO;
+import org.apache.syncope.core.persistence.api.dao.RoleDAO;
+import org.apache.syncope.core.persistence.api.dao.UserDAO;
+import org.apache.syncope.core.persistence.api.entity.membership.Membership;
+import org.apache.syncope.core.persistence.api.entity.role.Role;
+import org.apache.syncope.core.persistence.api.entity.user.User;
+import org.apache.syncope.core.persistence.jpa.AbstractTest;
+import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.transaction.annotation.Transactional;
+
+@Transactional
+public class MembershipTest extends AbstractTest {
+
+ @Autowired
+ private MembershipDAO membershipDAO;
+
+ @Autowired
+ private UserDAO userDAO;
+
+ @Autowired
+ private RoleDAO roleDAO;
+
+ @Test
+ public void findAll() {
+ List<Membership> list = membershipDAO.findAll();
+ assertEquals(7, list.size());
+ }
+
+ @Test
+ public void find() {
+ Membership membership = membershipDAO.find(1L);
+ assertNotNull("did not find expected membership", membership);
+ }
+
+ @Test
+ public void save() {
+ User user = userDAO.find(4L);
+ Role role = roleDAO.find(1L);
+
+ Membership membership = entityFactory.newEntity(Membership.class);
+ membership.setUser(user);
+ membership.setRole(role);
+
+ membership = membershipDAO.save(membership);
+
+ Membership actual = membershipDAO.find(membership.getKey());
+ assertNotNull("expected save to work", actual);
+ }
+
+ @Test
+ public void delete() {
+ Membership membership = membershipDAO.find(4L);
+ membershipDAO.delete(membership.getKey());
+
+ Membership actual = membershipDAO.find(4L);
+ assertNull("delete did not work", actual);
+ }
+}
http://git-wip-us.apache.org/repos/asf/syncope/blob/d30c8526/syncope620/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/entity/NotificationTest.java
----------------------------------------------------------------------
diff --git a/syncope620/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/entity/NotificationTest.java b/syncope620/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/entity/NotificationTest.java
new file mode 100644
index 0000000..8da3c21
--- /dev/null
+++ b/syncope620/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/entity/NotificationTest.java
@@ -0,0 +1,132 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.syncope.core.persistence.jpa.entity;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+import java.util.List;
+import org.apache.syncope.common.lib.types.IntMappingType;
+import org.apache.syncope.core.persistence.api.dao.NotificationDAO;
+import org.apache.syncope.core.persistence.api.entity.Notification;
+import org.apache.syncope.core.persistence.jpa.AbstractTest;
+import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.transaction.annotation.Transactional;
+
+@Transactional
+public class NotificationTest extends AbstractTest {
+
+ @Autowired
+ private NotificationDAO notificationDAO;
+
+ @Test
+ public void find() {
+ Notification notification = notificationDAO.find(10L);
+ assertNotNull(notification);
+ assertNotNull(notification.getEvents());
+ assertFalse(notification.getEvents().isEmpty());
+ assertNotNull(notification.getUserAbout());
+ assertNotNull(notification.getRecipients());
+
+ }
+
+ @Test
+ public void findAll() {
+ List<Notification> notifications = notificationDAO.findAll();
+ assertNotNull(notifications);
+ assertFalse(notifications.isEmpty());
+ }
+
+ @Test
+ public void save() {
+ Notification notification = entityFactory.newEntity(Notification.class);
+ notification.addEvent("save");
+
+ notification.setUserAbout("fake search condition");
+
+ notification.setRecipients("fake search condition");
+
+ notification.setRecipientAttrName("email");
+ notification.setRecipientAttrType(IntMappingType.UserPlainSchema);
+
+ notification.setSender("syncope@syncope.apache.org");
+ notification.setSubject("Test notification");
+ notification.setTemplate("test");
+
+ Notification actual = notificationDAO.save(notification);
+ assertNotNull(actual);
+ assertNotNull(actual.getKey());
+ }
+
+ @Test
+ public void delete() {
+ notificationDAO.delete(10L);
+ assertNull(notificationDAO.find(10L));
+ }
+
+ @Test
+ public void issueSYNCOPE445() {
+ Notification notification = entityFactory.newEntity(Notification.class);
+ notification.addEvent("save");
+
+ notification.setUserAbout("fake search condition");
+
+ notification.setRecipients("fake search condition");
+
+ notification.setRecipientAttrName("email");
+ notification.setRecipientAttrType(IntMappingType.UserPlainSchema);
+
+ notification.addStaticRecipient("syncope445@syncope.apache.org");
+
+ notification.setSender("syncope@syncope.apache.org");
+ notification.setSubject("Test notification");
+ notification.setTemplate("test");
+
+ Notification actual = notificationDAO.save(notification);
+ assertNotNull(actual);
+ assertNotNull(actual.getKey());
+ assertNotNull(actual.getStaticRecipients());
+ assertFalse(actual.getStaticRecipients().isEmpty());
+ }
+
+ @Test
+ public void issueSYNCOPE446() {
+ Notification notification = entityFactory.newEntity(Notification.class);
+ notification.addEvent("[REST]:[RoleController]:[]:[create]:[SUCCESS]");
+
+ notification.setRoleAbout("fake search condition");
+
+ notification.setRecipientAttrName("email");
+ notification.setRecipientAttrType(IntMappingType.UserPlainSchema);
+
+ notification.addStaticRecipient("syncope446@syncope.apache.org");
+
+ notification.setSender("syncope@syncope.apache.org");
+ notification.setSubject("Test notification");
+ notification.setTemplate("test");
+
+ Notification actual = notificationDAO.save(notification);
+ assertNotNull(actual);
+ assertNotNull(actual.getKey());
+ assertNotNull(actual.getStaticRecipients());
+ assertFalse(actual.getStaticRecipients().isEmpty());
+ }
+}
http://git-wip-us.apache.org/repos/asf/syncope/blob/d30c8526/syncope620/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/entity/PlainSchemaTest.java
----------------------------------------------------------------------
diff --git a/syncope620/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/entity/PlainSchemaTest.java b/syncope620/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/entity/PlainSchemaTest.java
new file mode 100644
index 0000000..ece0825
--- /dev/null
+++ b/syncope620/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/entity/PlainSchemaTest.java
@@ -0,0 +1,160 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.syncope.core.persistence.jpa.entity;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.util.List;
+import org.apache.syncope.common.lib.SyncopeConstants;
+import org.apache.syncope.common.lib.types.AttrSchemaType;
+import org.apache.syncope.common.lib.types.AttributableType;
+import org.apache.syncope.common.lib.types.EntityViolationType;
+import org.apache.syncope.core.persistence.api.attrvalue.validation.InvalidEntityException;
+import org.apache.syncope.core.persistence.api.dao.PlainSchemaDAO;
+import org.apache.syncope.core.persistence.api.entity.role.RPlainAttr;
+import org.apache.syncope.core.persistence.api.entity.role.RPlainSchema;
+import org.apache.syncope.core.persistence.api.entity.user.UPlainSchema;
+import org.apache.syncope.core.persistence.jpa.AbstractTest;
+import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.transaction.annotation.Transactional;
+
+@Transactional
+public class PlainSchemaTest extends AbstractTest {
+
+ @Autowired
+ private PlainSchemaDAO plainSchemaDAO;
+
+ @Test
+ public void findAll() {
+ List<UPlainSchema> userList = plainSchemaDAO.findAll(UPlainSchema.class);
+ assertEquals(15, userList.size());
+
+ List<RPlainSchema> roleList = plainSchemaDAO.findAll(RPlainSchema.class);
+ assertEquals(5, roleList.size());
+ }
+
+ @Test
+ public void findByName() {
+ UPlainSchema schema = plainSchemaDAO.find("fullname", UPlainSchema.class);
+ assertNotNull("did not find expected attribute schema", schema);
+ }
+
+ @Test
+ public void findAttrs() {
+ List<RPlainSchema> schemas = plainSchemaDAO.findAll(RPlainSchema.class);
+ assertNotNull(schemas);
+ assertFalse(schemas.isEmpty());
+
+ for (RPlainSchema schema : schemas) {
+ List<RPlainAttr> attrs = plainSchemaDAO.findAttrs(schema, RPlainAttr.class);
+ assertNotNull(attrs);
+ assertFalse(attrs.isEmpty());
+ }
+ }
+
+ @Test
+ public void save() {
+ UPlainSchema schema = entityFactory.newEntity(UPlainSchema.class);
+ schema.setKey("secondaryEmail");
+ schema.setType(AttrSchemaType.String);
+ schema.setValidatorClass("org.apache.syncope.core.validation.EmailAddressValidator");
+ schema.setMandatoryCondition("false");
+ schema.setMultivalue(true);
+
+ plainSchemaDAO.save(schema);
+
+ UPlainSchema actual = plainSchemaDAO.find("secondaryEmail", UPlainSchema.class);
+ assertNotNull("expected save to work", actual);
+ assertEquals(schema, actual);
+ }
+
+ @Test(expected = InvalidEntityException.class)
+ public void saveNonValid() {
+ UPlainSchema schema = entityFactory.newEntity(UPlainSchema.class);
+ schema.setKey("secondaryEmail");
+ schema.setType(AttrSchemaType.String);
+ schema.setValidatorClass("org.apache.syncope.core.validation.EmailAddressValidator");
+ schema.setMandatoryCondition("false");
+ schema.setMultivalue(true);
+ schema.setUniqueConstraint(true);
+
+ plainSchemaDAO.save(schema);
+ }
+
+ @Test
+ public void checkForEnumType() {
+ RPlainSchema schema = entityFactory.newEntity(RPlainSchema.class);
+ schema.setType(AttrSchemaType.Enum);
+ schema.setKey("color");
+
+ Exception ex = null;
+ try {
+ plainSchemaDAO.save(schema);
+ } catch (Exception e) {
+ ex = e;
+ }
+ assertNotNull(ex);
+
+ schema.setEnumerationValues("red" + SyncopeConstants.ENUM_VALUES_SEPARATOR + "yellow");
+ schema.setEnumerationKeys("1" + SyncopeConstants.ENUM_VALUES_SEPARATOR + "2");
+
+ plainSchemaDAO.save(schema);
+
+ RPlainSchema actual = plainSchemaDAO.find(schema.getKey(), RPlainSchema.class);
+ assertNotNull(actual);
+ assertNotNull(actual.getEnumerationKeys());
+ assertFalse(actual.getEnumerationKeys().isEmpty());
+ }
+
+ @Test(expected = InvalidEntityException.class)
+ public void saveInvalidSchema() {
+ UPlainSchema schema = entityFactory.newEntity(UPlainSchema.class);
+ schema.setKey("username");
+ plainSchemaDAO.save(schema);
+ }
+
+ @Test
+ public void delete() {
+ UPlainSchema fullnam = plainSchemaDAO.find("fullname", UPlainSchema.class);
+
+ plainSchemaDAO.delete(fullnam.getKey(), attrUtilFactory.getInstance(AttributableType.USER));
+
+ UPlainSchema actual = plainSchemaDAO.find("fullname", UPlainSchema.class);
+ assertNull("delete did not work", actual);
+ }
+
+ @Test
+ public void issueSYNCOPE418() {
+ UPlainSchema schema = entityFactory.newEntity(UPlainSchema.class);
+ schema.setKey("http://schemas.examples.org/security/authorization/organizationUnit");
+
+ try {
+ plainSchemaDAO.save(schema);
+ fail();
+ } catch (InvalidEntityException e) {
+ assertTrue(e.hasViolation(EntityViolationType.InvalidName));
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/syncope/blob/d30c8526/syncope620/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/entity/PolicyTest.java
----------------------------------------------------------------------
diff --git a/syncope620/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/entity/PolicyTest.java b/syncope620/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/entity/PolicyTest.java
new file mode 100644
index 0000000..304fde0
--- /dev/null
+++ b/syncope620/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/entity/PolicyTest.java
@@ -0,0 +1,152 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.syncope.core.persistence.jpa.entity;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+import java.util.List;
+import org.apache.syncope.common.lib.types.PasswordPolicySpec;
+import org.apache.syncope.common.lib.types.PolicyType;
+import org.apache.syncope.common.lib.types.SyncPolicySpec;
+import org.apache.syncope.core.persistence.api.attrvalue.validation.InvalidEntityException;
+import org.apache.syncope.core.persistence.api.dao.PolicyDAO;
+import org.apache.syncope.core.persistence.api.entity.PasswordPolicy;
+import org.apache.syncope.core.persistence.api.entity.Policy;
+import org.apache.syncope.core.persistence.api.entity.SyncPolicy;
+import org.apache.syncope.core.persistence.jpa.AbstractTest;
+import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.transaction.annotation.Transactional;
+
+@Transactional
+public class PolicyTest extends AbstractTest {
+
+ @Autowired
+ private PolicyDAO policyDAO;
+
+ @Test
+ public void findAll() {
+ List<Policy> policies = policyDAO.findAll();
+ assertNotNull(policies);
+ assertFalse(policies.isEmpty());
+ }
+
+ @Test
+ public void findById() {
+ Policy policy = policyDAO.find(1L);
+ assertNotNull("findById did not work", policy);
+ }
+
+ @Test
+ public void findByType() {
+ List<? extends Policy> policies = policyDAO.find(PolicyType.SYNC);
+ assertNotNull("findById did not work", policies);
+ assertFalse(policies.isEmpty());
+ }
+
+ @Test
+ public void findGlobalPasswordPolicy() {
+ PasswordPolicy policy = policyDAO.getGlobalPasswordPolicy();
+ assertNotNull("findById did not work", policy);
+
+ assertEquals(PolicyType.GLOBAL_PASSWORD, policy.getType());
+
+ assertEquals("invalid policy values", 8, (policy.getSpecification(PasswordPolicySpec.class)).getMinLength());
+ }
+
+ @Test(expected = InvalidEntityException.class)
+ public void saveInvalidPolicy() {
+ PasswordPolicySpec passwordPolicy = new PasswordPolicySpec();
+ passwordPolicy.setMaxLength(8);
+ passwordPolicy.setMinLength(6);
+
+ SyncPolicy policy = entityFactory.newPolicy(SyncPolicy.class, false);
+ policy.setSpecification(passwordPolicy);
+ policy.setDescription("sync policy");
+
+ policyDAO.save(policy);
+ }
+
+ @Test(expected = InvalidEntityException.class)
+ public void saveSecondPasswordPolicy() {
+ PasswordPolicySpec passwordPolicy = new PasswordPolicySpec();
+ passwordPolicy.setMaxLength(8);
+ passwordPolicy.setMinLength(6);
+
+ PasswordPolicy policy = entityFactory.newPolicy(PasswordPolicy.class, true);
+ policy.setSpecification(passwordPolicy);
+ policy.setDescription("global password policy");
+
+ policyDAO.save(policy);
+ }
+
+ @Test
+ public void create() {
+ SyncPolicy policy = entityFactory.newPolicy(SyncPolicy.class, false);
+
+ final String syncURuleName = "net.tirasa.sync.correlation.TirasaURule";
+ final String syncRRuleName = "net.tirasa.sync.correlation.TirasaRRule";
+
+ SyncPolicySpec syncPolicySpec = new SyncPolicySpec();
+ syncPolicySpec.setUserJavaRule(syncURuleName);
+ syncPolicySpec.setRoleJavaRule(syncRRuleName);
+
+ policy.setSpecification(syncPolicySpec);
+ policy.setDescription("Sync policy");
+
+ policy = policyDAO.save(policy);
+
+ assertNotNull(policy);
+ assertEquals(PolicyType.SYNC, policy.getType());
+ assertEquals(syncURuleName, (policy.getSpecification(SyncPolicySpec.class)).getUserJavaRule());
+ assertEquals(syncRRuleName, (policy.getSpecification(SyncPolicySpec.class)).getRoleJavaRule());
+ }
+
+ @Test
+ public void update() {
+ PasswordPolicySpec specification = new PasswordPolicySpec();
+ specification.setMaxLength(8);
+ specification.setMinLength(6);
+
+ Policy policy = policyDAO.getGlobalPasswordPolicy();
+ assertNotNull(policy);
+ policy.setSpecification(specification);
+
+ policy = policyDAO.save(policy);
+
+ assertNotNull(policy);
+ assertEquals(PolicyType.GLOBAL_PASSWORD, policy.getType());
+ assertEquals((policy.getSpecification(PasswordPolicySpec.class)).getMaxLength(), 8);
+ assertEquals((policy.getSpecification(PasswordPolicySpec.class)).getMinLength(), 6);
+ }
+
+ @Test
+ public void delete() {
+ Policy policy = policyDAO.find(1L);
+ assertNotNull("find to delete did not work", policy);
+
+ policyDAO.delete(policy);
+
+ Policy actual = policyDAO.find(1L);
+ assertNull("delete did not work", actual);
+ }
+}
http://git-wip-us.apache.org/repos/asf/syncope/blob/d30c8526/syncope620/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/entity/ReportTest.java
----------------------------------------------------------------------
diff --git a/syncope620/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/entity/ReportTest.java b/syncope620/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/entity/ReportTest.java
new file mode 100644
index 0000000..4521a48
--- /dev/null
+++ b/syncope620/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/entity/ReportTest.java
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.syncope.core.persistence.jpa.entity;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+import java.util.List;
+import org.apache.syncope.common.lib.report.UserReportletConf;
+import org.apache.syncope.core.persistence.api.dao.ReportDAO;
+import org.apache.syncope.core.persistence.api.entity.Report;
+import org.apache.syncope.core.persistence.jpa.AbstractTest;
+import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.transaction.annotation.Transactional;
+
+@Transactional
+public class ReportTest extends AbstractTest {
+
+ @Autowired
+ private ReportDAO reportDAO;
+
+ @Test
+ public void find() {
+ Report report = reportDAO.find(1L);
+ assertNotNull(report);
+
+ report = reportDAO.find(10L);
+ assertNull(report);
+ }
+
+ @Test
+ public void findAll() {
+ List<Report> reports = reportDAO.findAll();
+ assertNotNull(reports);
+ assertEquals(1, reports.size());
+ }
+
+ @Test
+ public void save() {
+ int beforeCount = reportDAO.count();
+
+ Report report = entityFactory.newEntity(Report.class);
+ report.setName("new report");
+ report.addReportletConf(new UserReportletConf("first"));
+ report.addReportletConf(new UserReportletConf("second"));
+
+ report = reportDAO.save(report);
+ assertNotNull(report);
+ assertNotNull(report.getKey());
+
+ int afterCount = reportDAO.count();
+ assertEquals(afterCount, beforeCount + 1);
+ }
+
+ @Test
+ public void delete() {
+ Report report = reportDAO.find(1L);
+ assertNotNull(report);
+
+ reportDAO.delete(1L);
+
+ report = reportDAO.find(1L);
+ assertNull(report);
+ }
+}