http://git-wip-us.apache.org/repos/asf/syncope/blob/d30c8526/syncope620/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/relationship/ResourceTest.java ---------------------------------------------------------------------- diff --git a/syncope620/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/relationship/ResourceTest.java b/syncope620/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/relationship/ResourceTest.java new file mode 100644 index 0000000..9139804 --- /dev/null +++ b/syncope620/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/relationship/ResourceTest.java @@ -0,0 +1,298 @@ +/* + * 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.relationship; + +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.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import javax.persistence.EntityManager; +import org.apache.syncope.common.lib.types.IntMappingType; +import org.apache.syncope.common.lib.types.MappingPurpose; +import org.apache.syncope.common.lib.types.TaskType; +import org.apache.syncope.core.persistence.api.dao.ConnInstanceDAO; +import org.apache.syncope.core.persistence.api.dao.ExternalResourceDAO; +import org.apache.syncope.core.persistence.api.dao.PolicyDAO; +import org.apache.syncope.core.persistence.api.dao.TaskDAO; +import org.apache.syncope.core.persistence.api.dao.UserDAO; +import org.apache.syncope.core.persistence.api.entity.ConnInstance; +import org.apache.syncope.core.persistence.api.entity.ExternalResource; +import org.apache.syncope.core.persistence.api.entity.PasswordPolicy; +import org.apache.syncope.core.persistence.api.entity.role.RMappingItem; +import org.apache.syncope.core.persistence.api.entity.task.PropagationTask; +import org.apache.syncope.core.persistence.api.entity.user.UMapping; +import org.apache.syncope.core.persistence.api.entity.user.UMappingItem; +import org.apache.syncope.core.persistence.api.entity.user.User; +import org.apache.syncope.core.persistence.jpa.AbstractTest; +import org.apache.syncope.core.persistence.jpa.entity.role.JPARMappingItem; +import org.junit.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.transaction.annotation.Transactional; + +@Transactional +public class ResourceTest extends AbstractTest { + + @Autowired + private EntityManager entityManager; + + @Autowired + private ExternalResourceDAO resourceDAO; + + @Autowired + private ConnInstanceDAO connInstanceDAO; + + @Autowired + private UserDAO userDAO; + + @Autowired + private TaskDAO taskDAO; + + @Autowired + private PolicyDAO policyDAO; + + @Test + public void createWithPasswordPolicy() { + final String resourceName = "resourceWithPasswordPolicy"; + + PasswordPolicy policy = (PasswordPolicy) policyDAO.find(4L); + ExternalResource resource = entityFactory.newEntity(ExternalResource.class); + resource.setKey(resourceName); + resource.setPasswordPolicy(policy); + + ConnInstance connector = connInstanceDAO.find(100L); + assertNotNull("connector not found", connector); + resource.setConnector(connector); + + ExternalResource actual = resourceDAO.save(resource); + assertNotNull(actual); + + actual = resourceDAO.find(actual.getKey()); + assertNotNull(actual); + assertNotNull(actual.getPasswordPolicy()); + + resourceDAO.delete(resourceName); + assertNull(resourceDAO.find(resourceName)); + + assertNotNull(policyDAO.find(4L)); + } + + @Test + public void save() { + ExternalResource resource = entityFactory.newEntity(ExternalResource.class); + resource.setKey("ws-target-resource-save"); + + // specify the connector + ConnInstance connector = connInstanceDAO.find(100L); + assertNotNull("connector not found", connector); + + resource.setConnector(connector); + + UMapping mapping = entityFactory.newEntity(UMapping.class); + mapping.setResource(resource); + resource.setUmapping(mapping); + + // specify mappings + for (int i = 0; i < 3; i++) { + UMappingItem item = entityFactory.newEntity(UMappingItem.class); + item.setExtAttrName("test" + i); + item.setIntAttrName("nonexistent" + i); + item.setIntMappingType(IntMappingType.UserPlainSchema); + item.setMandatoryCondition("false"); + item.setPurpose(MappingPurpose.SYNCHRONIZATION); + mapping.addItem(item); + item.setMapping(mapping); + } + UMappingItem accountId = entityFactory.newEntity(UMappingItem.class); + accountId.setExtAttrName("username"); + accountId.setIntAttrName("username"); + accountId.setIntMappingType(IntMappingType.UserId); + accountId.setPurpose(MappingPurpose.PROPAGATION); + mapping.setAccountIdItem(accountId); + accountId.setMapping(mapping); + + // map a derived attribute + UMappingItem derived = entityFactory.newEntity(UMappingItem.class); + derived.setAccountid(false); + derived.setExtAttrName("fullname"); + derived.setIntAttrName("cn"); + derived.setIntMappingType(IntMappingType.UserDerivedSchema); + derived.setPurpose(MappingPurpose.PROPAGATION); + mapping.addItem(derived); + derived.setMapping(mapping); + + // save the resource + ExternalResource actual = resourceDAO.save(resource); + assertNotNull(actual); + assertNotNull(actual.getUmapping()); + + resourceDAO.flush(); + resourceDAO.detach(actual); + connInstanceDAO.detach(connector); + + // assign the new resource to an user + User user = userDAO.find(1L); + assertNotNull("user not found", user); + + user.addResource(actual); + + resourceDAO.flush(); + + // retrieve resource + resource = resourceDAO.find(actual.getKey()); + assertNotNull(resource); + + // check connector + connector = connInstanceDAO.find(100L); + assertNotNull(connector); + + assertNotNull(connector.getResources()); + assertTrue(connector.getResources().contains(resource)); + + assertNotNull(resource.getConnector()); + assertTrue(resource.getConnector().equals(connector)); + + // check mappings + List<? extends UMappingItem> items = resource.getUmapping().getItems(); + assertNotNull(items); + assertEquals(5, items.size()); + + // check user + user = userDAO.find(1L); + assertNotNull(user); + assertNotNull(user.getResources()); + assertTrue(user.getResources().contains(actual)); + } + + @Test + public void delete() { + ExternalResource resource = resourceDAO.find("ws-target-resource-2"); + assertNotNull("find to delete did not work", resource); + + // ------------------------------------- + // Get originally associated connector + // ------------------------------------- + ConnInstance connector = resource.getConnector(); + assertNotNull(connector); + + Long connectorId = connector.getKey(); + // ------------------------------------- + + // ------------------------------------- + // Get originally associated users + // ------------------------------------- + List<User> users = userDAO.findByResource(resource); + assertNotNull(users); + + Set<Long> userIds = new HashSet<Long>(); + for (User user : users) { + userIds.add(user.getKey()); + } + // ------------------------------------- + + // Get tasks + List<PropagationTask> propagationTasks = taskDAO.findAll(resource, TaskType.PROPAGATION); + assertFalse(propagationTasks.isEmpty()); + + // delete resource + resourceDAO.delete(resource.getKey()); + + // close the transaction + resourceDAO.flush(); + + // resource must be removed + ExternalResource actual = resourceDAO.find("ws-target-resource-2"); + assertNull("delete did not work", actual); + + // resource must be not referenced any more from users + for (Long id : userIds) { + User actualUser = userDAO.find(id); + assertNotNull(actualUser); + for (ExternalResource res : actualUser.getResources()) { + assertFalse(res.getKey().equalsIgnoreCase(resource.getKey())); + } + } + + // resource must be not referenced any more from the connector + ConnInstance actualConnector = connInstanceDAO.find(connectorId); + assertNotNull(actualConnector); + for (ExternalResource res : actualConnector.getResources()) { + assertFalse(res.getKey().equalsIgnoreCase(resource.getKey())); + } + + // there must be no tasks + for (PropagationTask task : propagationTasks) { + assertNull(taskDAO.find(task.getKey())); + } + } + + @Test + public void emptyMapping() { + ExternalResource ldap = resourceDAO.find("resource-ldap"); + assertNotNull(ldap); + assertNotNull(ldap.getUmapping()); + assertNotNull(ldap.getRmapping()); + + List<? extends RMappingItem> items = ldap.getRmapping().getItems(); + assertNotNull(items); + assertFalse(items.isEmpty()); + List<Long> itemIds = new ArrayList<>(items.size()); + for (RMappingItem item : items) { + itemIds.add(item.getKey()); + } + + ldap.setRmapping(null); + + // need to avoid any class not defined in this Maven module + ldap.getPropagationActionsClassNames().clear(); + + resourceDAO.save(ldap); + resourceDAO.flush(); + + for (Long itemId : itemIds) { + assertNull(entityManager.find(JPARMappingItem.class, itemId)); + } + } + + @Test + public void issue243() { + ExternalResource csv = resourceDAO.find("resource-csv"); + assertNotNull(csv); + + int origMapItems = csv.getUmapping().getItems().size(); + + UMappingItem newMapItem = entityFactory.newEntity(UMappingItem.class); + newMapItem.setIntMappingType(IntMappingType.Username); + newMapItem.setExtAttrName("TEST"); + newMapItem.setPurpose(MappingPurpose.PROPAGATION); + csv.getUmapping().addItem(newMapItem); + + resourceDAO.save(csv); + resourceDAO.flush(); + + csv = resourceDAO.find("resource-csv"); + assertNotNull(csv); + assertEquals(origMapItems + 1, csv.getUmapping().getItems().size()); + } +}
http://git-wip-us.apache.org/repos/asf/syncope/blob/d30c8526/syncope620/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/relationship/RoleTest.java ---------------------------------------------------------------------- diff --git a/syncope620/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/relationship/RoleTest.java b/syncope620/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/relationship/RoleTest.java new file mode 100644 index 0000000..db6bdb8 --- /dev/null +++ b/syncope620/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/relationship/RoleTest.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.relationship; + +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.attrvalue.validation.InvalidEntityException; +import org.apache.syncope.core.persistence.api.dao.EntitlementDAO; +import org.apache.syncope.core.persistence.api.dao.PlainAttrDAO; +import org.apache.syncope.core.persistence.api.dao.PlainAttrValueDAO; +import org.apache.syncope.core.persistence.api.dao.PlainSchemaDAO; +import org.apache.syncope.core.persistence.api.dao.PolicyDAO; +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.PasswordPolicy; +import org.apache.syncope.core.persistence.api.entity.role.RPlainAttr; +import org.apache.syncope.core.persistence.api.entity.role.RPlainAttrValue; +import org.apache.syncope.core.persistence.api.entity.role.RPlainSchema; +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 RoleTest extends AbstractTest { + + @Autowired + private UserDAO userDAO; + + @Autowired + private RoleDAO roleDAO; + + @Autowired + private PlainSchemaDAO plainSchemaDAO; + + @Autowired + private PlainAttrDAO plainAttrDAO; + + @Autowired + private PlainAttrValueDAO plainAttrValueDAO; + + @Autowired + private EntitlementDAO entitlementDAO; + + @Autowired + private PolicyDAO policyDAO; + + @Test(expected = InvalidEntityException.class) + public void saveWithTwoOwners() { + Role root = roleDAO.find("root", null); + assertNotNull("did not find expected role", root); + + User user = userDAO.find(1L); + assertNotNull("did not find expected user", user); + + Role role = entityFactory.newEntity(Role.class); + role.setName("error"); + role.setUserOwner(user); + role.setRoleOwner(root); + + roleDAO.save(role); + } + + @Test + public void findByOwner() { + Role role = roleDAO.find(6L); + assertNotNull("did not find expected role", role); + + User user = userDAO.find(5L); + assertNotNull("did not find expected user", user); + + assertEquals(user, role.getUserOwner()); + + Role child1 = roleDAO.find(7L); + assertNotNull(child1); + assertEquals(role, child1.getParent()); + + Role child2 = roleDAO.find(10L); + assertNotNull(child2); + assertEquals(role, child2.getParent()); + + List<Role> ownedRoles = roleDAO.findOwnedByUser(user.getKey()); + assertFalse(ownedRoles.isEmpty()); + assertEquals(2, ownedRoles.size()); + assertTrue(ownedRoles.contains(role)); + assertTrue(ownedRoles.contains(child1)); + assertFalse(ownedRoles.contains(child2)); + } + + public void createWithPasswordPolicy() { + PasswordPolicy policy = (PasswordPolicy) policyDAO.find(4L); + Role role = entityFactory.newEntity(Role.class); + role.setName("roleWithPasswordPolicy"); + role.setPasswordPolicy(policy); + + Role actual = roleDAO.save(role); + assertNotNull(actual); + + actual = roleDAO.find(actual.getKey()); + assertNotNull(actual); + assertNotNull(actual.getPasswordPolicy()); + + roleDAO.delete(actual.getKey()); + assertNull(roleDAO.find(actual.getKey())); + + assertNotNull(policyDAO.find(4L)); + } + + @Test + public void delete() { + roleDAO.delete(2L); + + roleDAO.flush(); + + assertNull(roleDAO.find(2L)); + assertEquals(1, roleDAO.findByEntitlement(entitlementDAO.find("base")).size()); + assertEquals(userDAO.find(2L).getRoles().size(), 2); + assertNull(plainAttrDAO.find(700L, RPlainAttr.class)); + assertNull(plainAttrValueDAO.find(41L, RPlainAttrValue.class)); + assertNotNull(plainSchemaDAO.find("icon", RPlainSchema.class)); + } +} http://git-wip-us.apache.org/repos/asf/syncope/blob/d30c8526/syncope620/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/relationship/SecurityQuestionTest.java ---------------------------------------------------------------------- diff --git a/syncope620/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/relationship/SecurityQuestionTest.java b/syncope620/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/relationship/SecurityQuestionTest.java new file mode 100644 index 0000000..a3deb6e --- /dev/null +++ b/syncope620/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/relationship/SecurityQuestionTest.java @@ -0,0 +1,61 @@ +/* + * 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.relationship; + +import static org.junit.Assert.assertNull; + +import org.apache.syncope.core.persistence.api.dao.SecurityQuestionDAO; +import org.apache.syncope.core.persistence.api.dao.UserDAO; +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 SecurityQuestionTest extends AbstractTest { + + @Autowired + private SecurityQuestionDAO securityQuestionDAO; + + @Autowired + private UserDAO userDAO; + + @Test + public void test() { + User user = userDAO.find(4L); + assertNull(user.getSecurityQuestion()); + assertNull(user.getSecurityAnswer()); + + user.setSecurityQuestion(securityQuestionDAO.find(1L)); + user.setSecurityAnswer("Rossi"); + userDAO.save(user); + + userDAO.flush(); + + securityQuestionDAO.delete(1L); + + userDAO.flush(); + + user = userDAO.find(4L); + + assertNull(user.getSecurityQuestion()); + assertNull(user.getSecurityAnswer()); + } +} http://git-wip-us.apache.org/repos/asf/syncope/blob/d30c8526/syncope620/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/relationship/TaskTest.java ---------------------------------------------------------------------- diff --git a/syncope620/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/relationship/TaskTest.java b/syncope620/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/relationship/TaskTest.java new file mode 100644 index 0000000..e795a95 --- /dev/null +++ b/syncope620/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/relationship/TaskTest.java @@ -0,0 +1,291 @@ +/* + * 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.relationship; + +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.Date; +import java.util.HashSet; +import java.util.Set; +import org.apache.syncope.common.lib.to.UserTO; +import org.apache.syncope.common.lib.types.AttributableType; +import org.apache.syncope.common.lib.types.MatchingRule; +import org.apache.syncope.common.lib.types.PropagationMode; +import org.apache.syncope.common.lib.types.PropagationTaskExecStatus; +import org.apache.syncope.common.lib.types.ResourceOperation; +import org.apache.syncope.common.lib.types.TaskType; +import org.apache.syncope.common.lib.types.UnmatchingRule; +import org.apache.syncope.core.persistence.api.attrvalue.validation.InvalidEntityException; +import org.apache.syncope.core.persistence.api.dao.ExternalResourceDAO; +import org.apache.syncope.core.persistence.api.dao.TaskDAO; +import org.apache.syncope.core.persistence.api.dao.TaskExecDAO; +import org.apache.syncope.core.persistence.api.dao.UserDAO; +import org.apache.syncope.core.persistence.api.entity.ExternalResource; +import org.apache.syncope.core.persistence.api.entity.task.PropagationTask; +import org.apache.syncope.core.persistence.api.entity.task.PushTask; +import org.apache.syncope.core.persistence.api.entity.task.SyncTask; +import org.apache.syncope.core.persistence.api.entity.task.TaskExec; +import org.apache.syncope.core.persistence.api.entity.user.User; +import org.apache.syncope.core.persistence.jpa.AbstractTest; +import org.apache.syncope.core.provisioning.api.sync.SyncActions; +import org.identityconnectors.framework.common.objects.Attribute; +import org.identityconnectors.framework.common.objects.AttributeBuilder; +import org.junit.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.transaction.annotation.Transactional; + +@Transactional +public class TaskTest extends AbstractTest { + + @Autowired + private TaskDAO taskDAO; + + @Autowired + private TaskExecDAO taskExecDAO; + + @Autowired + private ExternalResourceDAO resourceDAO; + + @Autowired + private UserDAO userDAO; + + @Test + public void read() { + PropagationTask task = taskDAO.find(1L); + assertNotNull(task); + + assertNotNull(task.getExecs()); + assertFalse(task.getExecs().isEmpty()); + assertEquals(1, task.getExecs().size()); + } + + @Test + public void save() { + ExternalResource resource = resourceDAO.find("ws-target-resource-1"); + assertNotNull(resource); + + User user = userDAO.find(2L); + assertNotNull(user); + + PropagationTask task = entityFactory.newEntity(PropagationTask.class); + task.setResource(resource); + task.setSubjectType(AttributableType.USER); + task.setPropagationMode(PropagationMode.TWO_PHASES); + task.setPropagationOperation(ResourceOperation.CREATE); + task.setAccountId("[email protected]"); + + Set<Attribute> attributes = new HashSet<>(); + attributes.add(AttributeBuilder.build("testAttribute", "testValue1", "testValue2")); + attributes.add(AttributeBuilder.buildPassword("password".toCharArray())); + task.setAttributes(attributes); + + task = taskDAO.save(task); + assertNotNull(task); + + PropagationTask actual = taskDAO.find(task.getKey()); + assertEquals(task, actual); + + taskDAO.flush(); + + resource = resourceDAO.find("ws-target-resource-1"); + assertTrue(taskDAO.findAll(resource, TaskType.PROPAGATION).contains(task)); + } + + @Test + public void addPropagationTaskExecution() { + PropagationTask task = taskDAO.find(1L); + assertNotNull(task); + + int executionNumber = task.getExecs().size(); + + TaskExec execution = entityFactory.newEntity(TaskExec.class); + execution.setTask(task); + execution.setStatus(PropagationTaskExecStatus.CREATED.name()); + task.addExec(execution); + execution.setStartDate(new Date()); + + taskDAO.save(task); + taskDAO.flush(); + + task = taskDAO.find(1L); + assertNotNull(task); + + assertEquals(executionNumber + 1, task.getExecs().size()); + } + + @Test + public void addSyncTaskExecution() { + SyncTask task = taskDAO.find(4L); + assertNotNull(task); + + int executionNumber = task.getExecs().size(); + + TaskExec execution = entityFactory.newEntity(TaskExec.class); + execution.setStatus("Text-free status"); + execution.setTask(task); + task.addExec(execution); + execution.setMessage("A message"); + + taskDAO.save(task); + taskDAO.flush(); + + task = taskDAO.find(4L); + assertNotNull(task); + + assertEquals(executionNumber + 1, task.getExecs().size()); + } + + @Test + public void addPushTaskExecution() { + PushTask task = taskDAO.find(13L); + assertNotNull(task); + + int executionNumber = task.getExecs().size(); + + TaskExec execution = entityFactory.newEntity(TaskExec.class); + execution.setStatus("Text-free status"); + execution.setTask(task); + task.addExec(execution); + execution.setMessage("A message"); + + taskDAO.save(task); + taskDAO.flush(); + + task = taskDAO.find(13L); + assertNotNull(task); + + assertEquals(executionNumber + 1, task.getExecs().size()); + } + + @Test + public void deleteTask() { + taskDAO.delete(1L); + + taskDAO.flush(); + + assertNull(taskDAO.find(1L)); + assertNull(taskExecDAO.find(1L)); + } + + @Test + public void deleteTaskExecution() { + TaskExec execution = taskExecDAO.find(1L); + int executionNumber = execution.getTask().getExecs().size(); + + taskExecDAO.delete(1L); + + taskExecDAO.flush(); + + assertNull(taskExecDAO.find(1L)); + + PropagationTask task = taskDAO.find(1L); + assertEquals(task.getExecs().size(), executionNumber - 1); + } + + @Test + public void saveSyncTask() { + ExternalResource resource = resourceDAO.find("ws-target-resource-1"); + assertNotNull(resource); + + SyncTask task = entityFactory.newEntity(SyncTask.class); + task.setName("saveSyncTask"); + task.setDescription("SyncTask description"); + task.setUserTemplate(new UserTO()); + 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 SyncTask requires a target resource + exception = null; + try { + taskDAO.save(task); + } catch (InvalidEntityException e) { + exception = e; + } + assertNotNull(exception); + + task.setResource(resource); + task.getActionsClassNames().add(getClass().getName()); + + // this save() fails because jobActionsClassName does not implement + // the right interface + exception = null; + try { + taskDAO.save(task); + } catch (InvalidEntityException e) { + exception = e; + } + assertNotNull(exception); + + task.getActionsClassNames().clear(); + task.getActionsClassNames().add(SyncActions.class.getName()); + // this save() finally works + task = taskDAO.save(task); + assertNotNull(task); + + SyncTask actual = taskDAO.find(task.getKey()); + assertEquals(task, actual); + } + + @Test + public void issueSYNCOPE144() { + ExternalResource resource = resourceDAO.find("ws-target-resource-1"); + assertNotNull(resource); + + SyncTask task = entityFactory.newEntity(SyncTask.class); + + task.setResource(resource); + task.setName("issueSYNCOPE144"); + task.setDescription("issueSYNCOPE144 Description"); + task.getActionsClassNames().add(SyncActions.class.getName()); + task.setMatchingRule(MatchingRule.UPDATE); + task.setUnmatchingRule(UnmatchingRule.PROVISION); + + task = taskDAO.save(task); + assertNotNull(task); + + SyncTask actual = taskDAO.find(task.getKey()); + assertEquals(task, actual); + assertEquals("issueSYNCOPE144", actual.getName()); + assertEquals("issueSYNCOPE144 Description", actual.getDescription()); + + actual.setName("issueSYNCOPE144_2"); + actual.setDescription("issueSYNCOPE144 Description_2"); + + actual = taskDAO.save(actual); + assertNotNull(actual); + assertEquals("issueSYNCOPE144_2", actual.getName()); + assertEquals("issueSYNCOPE144 Description_2", actual.getDescription()); + } + +} http://git-wip-us.apache.org/repos/asf/syncope/blob/d30c8526/syncope620/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/relationship/UserTest.java ---------------------------------------------------------------------- diff --git a/syncope620/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/relationship/UserTest.java b/syncope620/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/relationship/UserTest.java new file mode 100644 index 0000000..e95f5c3 --- /dev/null +++ b/syncope620/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/relationship/UserTest.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.relationship; + +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.PlainAttrDAO; +import org.apache.syncope.core.persistence.api.dao.PlainAttrValueDAO; +import org.apache.syncope.core.persistence.api.dao.PlainSchemaDAO; +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.user.UPlainAttr; +import org.apache.syncope.core.persistence.api.entity.user.UPlainAttrValue; +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 UserTest extends AbstractTest { + + @Autowired + private UserDAO userDAO; + + @Autowired + private RoleDAO roleDAO; + + @Autowired + private PlainSchemaDAO plainSchemaDAO; + + @Autowired + private PlainAttrDAO plainAttrDAO; + + @Autowired + private PlainAttrValueDAO plainAttrValueDAO; + + @Test + public void test() { + userDAO.delete(4L); + + userDAO.flush(); + + assertNull(userDAO.find(4L)); + assertNull(plainAttrDAO.find(550L, UPlainAttr.class)); + assertNull(plainAttrValueDAO.find(22L, UPlainAttrValue.class)); + assertNotNull(plainSchemaDAO.find("loginDate", UPlainSchema.class)); + + List<Membership> memberships = roleDAO.findMemberships(roleDAO.find(7L)); + assertTrue(memberships.isEmpty()); + } +} http://git-wip-us.apache.org/repos/asf/syncope/blob/d30c8526/syncope620/core/persistence-jpa/src/test/resources/META-INF/persistence-enhance.xml ---------------------------------------------------------------------- diff --git a/syncope620/core/persistence-jpa/src/test/resources/META-INF/persistence-enhance.xml b/syncope620/core/persistence-jpa/src/test/resources/META-INF/persistence-enhance.xml new file mode 100644 index 0000000..8407b06 --- /dev/null +++ b/syncope620/core/persistence-jpa/src/test/resources/META-INF/persistence-enhance.xml @@ -0,0 +1,31 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- +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. +--> +<persistence xmlns="http://java.sun.com/xml/ns/persistence" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://java.sun.com/xml/ns/persistence + http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd" + version="2.0"> + + <persistence-unit name="syncopePersistenceUnit"> + <mapping-file>META-INF/spring-orm.xml</mapping-file> + <validation-mode>NONE</validation-mode> + </persistence-unit> + +</persistence>
