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 2017/06/19 14:20:40 UTC
[1/4] syncope git commit: Reduce number of integration test cases
executed by default build, moving time-consuming to full-it profile
Repository: syncope
Updated Branches:
refs/heads/2_0_X b1aa1cb99 -> b6dfd13e2
refs/heads/master 71e676b38 -> 59d6d4a37
http://git-wip-us.apache.org/repos/asf/syncope/blob/b6dfd13e/fit/core-reference/src/test/java/org/apache/syncope/fit/core/PullTaskITCase.java
----------------------------------------------------------------------
diff --git a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/PullTaskITCase.java b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/PullTaskITCase.java
index 0869613..67d8f78 100644
--- a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/PullTaskITCase.java
+++ b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/PullTaskITCase.java
@@ -32,9 +32,6 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.util.Date;
import java.util.HashSet;
-import java.util.List;
-import java.util.Locale;
-import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.UUID;
@@ -44,13 +41,10 @@ import org.apache.commons.collections4.IterableUtils;
import org.apache.commons.collections4.Predicate;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.SerializationUtils;
-import org.apache.commons.lang3.tuple.Pair;
import org.apache.syncope.client.lib.SyncopeClient;
import org.apache.syncope.common.lib.SyncopeClientException;
import org.apache.syncope.common.lib.SyncopeConstants;
import org.apache.syncope.common.lib.patch.DeassociationPatch;
-import org.apache.syncope.common.lib.patch.PasswordPatch;
-import org.apache.syncope.common.lib.patch.UserPatch;
import org.apache.syncope.common.lib.to.AbstractTaskTO;
import org.apache.syncope.common.lib.to.AnyObjectTO;
import org.apache.syncope.common.lib.to.AttrTO;
@@ -61,15 +55,11 @@ import org.apache.syncope.common.lib.to.PagedResult;
import org.apache.syncope.common.lib.to.ResourceTO;
import org.apache.syncope.common.lib.to.GroupTO;
import org.apache.syncope.common.lib.to.ProvisionTO;
-import org.apache.syncope.common.lib.policy.PullPolicyTO;
import org.apache.syncope.common.lib.to.MappingItemTO;
-import org.apache.syncope.common.lib.to.ProvisioningResult;
import org.apache.syncope.common.lib.to.PullTaskTO;
import org.apache.syncope.common.lib.to.ExecTO;
-import org.apache.syncope.common.lib.to.RealmTO;
import org.apache.syncope.common.lib.to.UserTO;
import org.apache.syncope.common.lib.types.AnyTypeKind;
-import org.apache.syncope.common.lib.types.CipherAlgorithm;
import org.apache.syncope.common.lib.types.ClientExceptionType;
import org.apache.syncope.common.lib.types.ConnConfProperty;
import org.apache.syncope.common.lib.types.ConnectorCapability;
@@ -81,15 +71,10 @@ import org.apache.syncope.common.rest.api.beans.AnyQuery;
import org.apache.syncope.common.rest.api.beans.TaskQuery;
import org.apache.syncope.common.rest.api.service.ConnectorService;
import org.apache.syncope.common.rest.api.service.TaskService;
-import org.apache.syncope.core.spring.security.Encryptor;
-import org.apache.syncope.core.provisioning.java.pushpull.DBPasswordPullActions;
-import org.apache.syncope.core.provisioning.java.pushpull.LDAPPasswordPullActions;
import org.apache.syncope.fit.ActivitiDetector;
import org.apache.syncope.fit.core.reference.PrefixMappingItemTransformer;
import org.apache.syncope.fit.core.reference.TestReconciliationFilterBuilder;
import org.apache.syncope.fit.core.reference.TestPullActions;
-import org.apache.syncope.fit.core.reference.TestPullRule;
-import org.identityconnectors.framework.common.objects.Name;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -337,41 +322,6 @@ public class PullTaskITCase extends AbstractTaskITCase {
}
}
- /**
- * Clean Syncope and LDAP resource status.
- */
- private void ldapCleanup() {
- PagedResult<GroupTO> matchingGroups = groupService.search(new AnyQuery.Builder().realm(
- SyncopeConstants.ROOT_REALM).
- fiql(SyncopeClient.getGroupSearchConditionBuilder().is("name").equalTo("testLDAPGroup").query()).
- build());
- if (matchingGroups.getSize() > 0) {
- for (GroupTO group : matchingGroups.getResult()) {
- DeassociationPatch deassociationPatch = new DeassociationPatch();
- deassociationPatch.setKey(group.getKey());
- deassociationPatch.setAction(ResourceDeassociationAction.UNLINK);
- deassociationPatch.getResources().add(RESOURCE_NAME_LDAP);
- groupService.deassociate(deassociationPatch);
- groupService.delete(group.getKey());
- }
- }
- PagedResult<UserTO> matchingUsers = userService.search(
- new AnyQuery.Builder().realm(SyncopeConstants.ROOT_REALM).
- fiql(SyncopeClient.getUserSearchConditionBuilder().is("username").equalTo("pullFromLDAP").
- query()).
- build());
- if (matchingUsers.getSize() > 0) {
- for (UserTO user : matchingUsers.getResult()) {
- DeassociationPatch deassociationPatch = new DeassociationPatch();
- deassociationPatch.setKey(user.getKey());
- deassociationPatch.setAction(ResourceDeassociationAction.UNLINK);
- deassociationPatch.getResources().add(RESOURCE_NAME_LDAP);
- userService.deassociate(deassociationPatch);
- userService.delete(user.getKey());
- }
- }
- }
-
@Test
public void reconcileFromLDAP() {
// First of all, clear any potential conflict with existing user / group
@@ -667,512 +617,4 @@ public class PullTaskITCase extends AbstractTaskITCase {
jdbcTemplate.execute("DELETE FROM testpull WHERE ID=1041");
}
}
-
- @Test
- public void orgUnit() {
- // 0. initial realms
- List<RealmTO> realms = realmService.list("/odd");
- int pre = realms.size();
-
- // 1. create task for pulling org units
- PullTaskTO pullTask = new PullTaskTO();
- pullTask.setActive(true);
- pullTask.setName("For orgUnit");
- pullTask.setResource(RESOURCE_NAME_LDAP_ORGUNIT);
- pullTask.setDestinationRealm("/odd");
- pullTask.setPullMode(PullMode.FULL_RECONCILIATION);
- pullTask.setPerformCreate(true);
- pullTask.setPerformUpdate(true);
- pullTask.setPerformDelete(true);
-
- Response response = taskService.create(pullTask);
- if (response.getStatusInfo().getStatusCode() != Response.Status.CREATED.getStatusCode()) {
- throw (RuntimeException) clientFactory.getExceptionMapper().fromResponse(response);
- }
- pullTask = getObject(response.getLocation(), TaskService.class, PullTaskTO.class);
- assertNotNull(pullTask);
-
- ExecTO exec = execProvisioningTask(taskService, pullTask.getKey(), 50, false);
- assertEquals(PropagationTaskExecStatus.SUCCESS, PropagationTaskExecStatus.valueOf(exec.getStatus()));
-
- // 2. check
- realms = realmService.list("/odd");
- int post = realms.size();
- assertEquals(pre + 2, post);
- }
-
- @Test
- public void issueSYNCOPE68() {
- //-----------------------------
- // Create a new user ... it should be updated applying pull policy
- //-----------------------------
- UserTO userTO = new UserTO();
- userTO.setRealm(SyncopeConstants.ROOT_REALM);
- userTO.setPassword("password123");
- userTO.setUsername("testuser2");
-
- userTO.getPlainAttrs().add(attrTO("firstname", "testuser2"));
- userTO.getPlainAttrs().add(attrTO("surname", "testuser2"));
- userTO.getPlainAttrs().add(attrTO("ctype", "a type"));
- userTO.getPlainAttrs().add(attrTO("fullname", "a type"));
- userTO.getPlainAttrs().add(attrTO("userId", "testuser2@syncope.apache.org"));
- userTO.getPlainAttrs().add(attrTO("email", "testuser2@syncope.apache.org"));
-
- userTO.getResources().add(RESOURCE_NAME_NOPROPAGATION2);
- userTO.getResources().add(RESOURCE_NAME_NOPROPAGATION4);
-
- userTO.getMemberships().add(
- new MembershipTO.Builder().group("bf825fe1-7320-4a54-bd64-143b5c18ab97").build());
-
- userTO = createUser(userTO).getEntity();
- assertNotNull(userTO);
- assertEquals("testuser2", userTO.getUsername());
- assertEquals(1, userTO.getMemberships().size());
- assertEquals(3, userTO.getResources().size());
- //-----------------------------
-
- try {
- //-----------------------------
- // add user template
- //-----------------------------
- UserTO template = new UserTO();
-
- template.getMemberships().add(
- new MembershipTO.Builder().group("b8d38784-57e7-4595-859a-076222644b55").build());
-
- template.getResources().add(RESOURCE_NAME_NOPROPAGATION4);
- //-----------------------------
-
- // Update pull task
- PullTaskTO task = taskService.read("81d88f73-d474-4450-9031-605daa4e313f", true);
- assertNotNull(task);
-
- task.getTemplates().put(AnyTypeKind.USER.name(), template);
-
- taskService.update(task);
- PullTaskTO actual = taskService.read(task.getKey(), true);
- assertNotNull(actual);
- assertEquals(task.getKey(), actual.getKey());
- assertFalse(actual.getTemplates().get(AnyTypeKind.USER.name()).getResources().isEmpty());
- assertFalse(((UserTO) actual.getTemplates().get(AnyTypeKind.USER.name())).getMemberships().isEmpty());
-
- ExecTO execution = execProvisioningTask(taskService, actual.getKey(), 50, false);
- assertEquals(PropagationTaskExecStatus.SUCCESS, PropagationTaskExecStatus.valueOf(execution.getStatus()));
-
- userTO = userService.read("testuser2");
- assertNotNull(userTO);
- assertEquals("testuser2@syncope.apache.org", userTO.getPlainAttr("userId").getValues().get(0));
- assertEquals(2, userTO.getMemberships().size());
- assertEquals(4, userTO.getResources().size());
- } finally {
- UserTO dUserTO = deleteUser(userTO.getKey()).getEntity();
- assertNotNull(dUserTO);
- }
- }
-
- @Test
- public void issueSYNCOPE230() {
- JdbcTemplate jdbcTemplate = new JdbcTemplate(testDataSource);
-
- // 1. populate the external table
- jdbcTemplate.execute("INSERT INTO testpull VALUES"
- + "('a54b3794-b231-47be-b24a-11e1a42949f6', 'issuesyncope230', 'Surname', 'syncope230@syncope.apache.org', NULL)");
-
- // 2. execute PullTask for resource-db-pull (table TESTPULL on external H2)
- execProvisioningTask(taskService, "7c2242f4-14af-4ab5-af31-cdae23783655", 50, false);
-
- // 3. read e-mail address for user created by the PullTask first execution
- UserTO userTO = userService.read("issuesyncope230");
- assertNotNull(userTO);
- String email = userTO.getPlainAttr("email").getValues().iterator().next();
- assertNotNull(email);
-
- // 4. update TESTPULL on external H2 by changing e-mail address
- jdbcTemplate.execute("UPDATE TESTPULL SET email='updatedSYNCOPE230@syncope.apache.org'");
-
- // 5. re-execute the PullTask
- execProvisioningTask(taskService, "7c2242f4-14af-4ab5-af31-cdae23783655", 50, false);
-
- // 6. verify that the e-mail was updated
- userTO = userService.read("issuesyncope230");
- assertNotNull(userTO);
- email = userTO.getPlainAttr("email").getValues().iterator().next();
- assertNotNull(email);
- assertEquals("updatedSYNCOPE230@syncope.apache.org", email);
- }
-
- @Test
- public void issueSYNCOPE258() {
- // -----------------------------
- // Add a custom correlation rule
- // -----------------------------
- PullPolicyTO policyTO = policyService.read("9454b0d7-2610-400a-be82-fc23cf553dd6");
- policyTO.getSpecification().getCorrelationRules().put(AnyTypeKind.USER.name(), TestPullRule.class.getName());
- policyService.update(policyTO);
- // -----------------------------
-
- PullTaskTO task = new PullTaskTO();
- task.setDestinationRealm(SyncopeConstants.ROOT_REALM);
- task.setName("Test Pull Rule");
- task.setActive(true);
- task.setResource(RESOURCE_NAME_WS2);
- task.setPullMode(PullMode.FULL_RECONCILIATION);
- task.setPerformCreate(true);
- task.setPerformDelete(true);
- task.setPerformUpdate(true);
-
- Response response = taskService.create(task);
- task = getObject(response.getLocation(), TaskService.class, PullTaskTO.class);
-
- UserTO userTO = UserITCase.getUniqueSampleTO("s258_1@apache.org");
- userTO.getResources().clear();
- userTO.getResources().add(RESOURCE_NAME_WS2);
-
- createUser(userTO);
-
- userTO = UserITCase.getUniqueSampleTO("s258_2@apache.org");
- userTO.getResources().clear();
- userTO.getResources().add(RESOURCE_NAME_WS2);
-
- userTO = createUser(userTO).getEntity();
-
- // change email in order to unmatch the second user
- UserPatch userPatch = new UserPatch();
- userPatch.setKey(userTO.getKey());
- userPatch.getPlainAttrs().add(attrAddReplacePatch("email", "s258@apache.org"));
-
- userService.update(userPatch);
-
- execProvisioningTask(taskService, task.getKey(), 50, false);
-
- PullTaskTO executed = taskService.read(task.getKey(), true);
- assertEquals(1, executed.getExecutions().size());
-
- // asser for just one match
- assertTrue(executed.getExecutions().get(0).getMessage().substring(0, 55) + "...",
- executed.getExecutions().get(0).getMessage().contains("[updated/failures]: 1/0"));
- }
-
- @Test
- public void issueSYNCOPE272() {
- removeTestUsers();
-
- // create user with testdb resource
- UserTO userTO = UserITCase.getUniqueSampleTO("syncope272@syncope.apache.org");
- userTO.getResources().add(RESOURCE_NAME_TESTDB);
-
- ProvisioningResult<UserTO> result = createUser(userTO);
- userTO = result.getEntity();
- try {
- assertNotNull(userTO);
- assertEquals(1, result.getPropagationStatuses().size());
- assertEquals(PropagationTaskExecStatus.SUCCESS, result.getPropagationStatuses().get(0).getStatus());
-
- ExecTO taskExecTO = execProvisioningTask(
- taskService, "986867e2-993b-430e-8feb-aa9abb4c1dcd", 50, false);
-
- assertNotNull(taskExecTO.getStatus());
- assertEquals(PropagationTaskExecStatus.SUCCESS, PropagationTaskExecStatus.valueOf(taskExecTO.getStatus()));
-
- userTO = userService.read(userTO.getKey());
- assertNotNull(userTO);
- assertNotNull(userTO.getPlainAttr("firstname").getValues().get(0));
- } finally {
- removeTestUsers();
- }
- }
-
- @Test
- public void issueSYNCOPE307() {
- UserTO userTO = UserITCase.getUniqueSampleTO("s307@apache.org");
- userTO.setUsername("test0");
- userTO.getPlainAttr("firstname").getValues().clear();
- userTO.getPlainAttr("firstname").getValues().add("nome0");
- userTO.getAuxClasses().add("csv");
-
- AttrTO csvuserid = new AttrTO();
- csvuserid.setSchema("csvuserid");
- userTO.getDerAttrs().add(csvuserid);
-
- userTO.getResources().clear();
- userTO.getResources().add(RESOURCE_NAME_WS2);
-
- userTO = createUser(userTO).getEntity();
- assertNotNull(userTO);
-
- userTO = userService.read(userTO.getKey());
- assertTrue(userTO.getVirAttrs().isEmpty());
-
- // Update pull task
- PullTaskTO task = taskService.read("38abbf9e-a1a3-40a1-a15f-7d0ac02f47f1", true);
- assertNotNull(task);
-
- UserTO template = new UserTO();
- template.setPassword("'password123'");
- template.getResources().add(RESOURCE_NAME_DBVIRATTR);
- template.getVirAttrs().add(attrTO("virtualdata", "'virtualvalue'"));
-
- task.getTemplates().put(AnyTypeKind.USER.name(), template);
-
- taskService.update(task);
-
- // exec task: one user from CSV will match the user created above and template will be applied
- execProvisioningTask(taskService, task.getKey(), 50, false);
-
- // check that template was successfully applied...
- userTO = userService.read(userTO.getKey());
- assertEquals("virtualvalue", userTO.getVirAttr("virtualdata").getValues().get(0));
-
- // ...and that propagation to db succeeded
- JdbcTemplate jdbcTemplate = new JdbcTemplate(testDataSource);
- String value = queryForObject(
- jdbcTemplate, 50, "SELECT USERNAME FROM testpull WHERE ID=?", String.class, userTO.getKey());
- assertEquals("virtualvalue", value);
- }
-
- @Test
- public void issueSYNCOPE313DB() throws Exception {
- // 1. create user in DB
- UserTO user = UserITCase.getUniqueSampleTO("syncope313-db@syncope.apache.org");
- user.setPassword("security123");
- user.getResources().add(RESOURCE_NAME_TESTDB);
- user = createUser(user).getEntity();
- assertNotNull(user);
- assertFalse(user.getResources().isEmpty());
-
- // 2. Check that the DB resource has the correct password
- JdbcTemplate jdbcTemplate = new JdbcTemplate(testDataSource);
- String value = queryForObject(
- jdbcTemplate, 50, "SELECT PASSWORD FROM test WHERE ID=?", String.class, user.getUsername());
- assertEquals(Encryptor.getInstance().encode("security123", CipherAlgorithm.SHA1), value.toUpperCase());
-
- // 3. Update the password in the DB
- String newCleanPassword = "new-security";
- String newPassword = Encryptor.getInstance().encode(newCleanPassword, CipherAlgorithm.SHA1);
- jdbcTemplate.execute("UPDATE test set PASSWORD='" + newPassword + "' where ID='" + user.getUsername() + "'");
-
- // 4. Pull the user from the resource
- PullTaskTO pullTask = new PullTaskTO();
- pullTask.setDestinationRealm(SyncopeConstants.ROOT_REALM);
- pullTask.setName("DB Pull Task");
- pullTask.setActive(true);
- pullTask.setPerformCreate(true);
- pullTask.setPerformUpdate(true);
- pullTask.setPullMode(PullMode.FULL_RECONCILIATION);
- pullTask.setResource(RESOURCE_NAME_TESTDB);
- pullTask.getActionsClassNames().add(DBPasswordPullActions.class.getName());
- Response taskResponse = taskService.create(pullTask);
-
- PullTaskTO actual = getObject(taskResponse.getLocation(), TaskService.class, PullTaskTO.class);
- assertNotNull(actual);
-
- pullTask = taskService.read(actual.getKey(), true);
- assertNotNull(pullTask);
- assertEquals(actual.getKey(), pullTask.getKey());
- assertEquals(actual.getJobDelegateClassName(), pullTask.getJobDelegateClassName());
-
- ExecTO execution = execProvisioningTask(taskService, pullTask.getKey(), 50, false);
- assertEquals(PropagationTaskExecStatus.SUCCESS, PropagationTaskExecStatus.valueOf(execution.getStatus()));
-
- // 5. Test the pulled user
- Pair<Map<String, Set<String>>, UserTO> self = clientFactory.create(user.getUsername(), newCleanPassword).self();
- assertNotNull(self);
-
- // 6. Delete PullTask + user
- taskService.delete(pullTask.getKey());
- deleteUser(user.getKey());
- }
-
- @Test
- public void issueSYNCOPE313LDAP() throws Exception {
- // First of all, clear any potential conflict with existing user / group
- ldapCleanup();
-
- UserTO user = null;
- PullTaskTO pullTask = null;
- ConnInstanceTO resourceConnector = null;
- ConnConfProperty property = null;
- try {
- // 1. create user in LDAP
- String oldCleanPassword = "security123";
- user = UserITCase.getUniqueSampleTO("syncope313-ldap@syncope.apache.org");
- user.setPassword(oldCleanPassword);
- user.getResources().add(RESOURCE_NAME_LDAP);
- user = createUser(user).getEntity();
- assertNotNull(user);
- assertFalse(user.getResources().isEmpty());
-
- // 2. request to change password only on Syncope and not on LDAP
- String newCleanPassword = "new-security123";
- UserPatch userPatch = new UserPatch();
- userPatch.setKey(user.getKey());
- userPatch.setPassword(new PasswordPatch.Builder().value(newCleanPassword).build());
- user = updateUser(userPatch).getEntity();
-
- // 3. Check that the Syncope user now has the changed password
- Pair<Map<String, Set<String>>, UserTO> self =
- clientFactory.create(user.getUsername(), newCleanPassword).self();
- assertNotNull(self);
-
- // 4. Check that the LDAP resource has the old password
- ConnObjectTO connObject =
- resourceService.readConnObject(RESOURCE_NAME_LDAP, AnyTypeKind.USER.name(), user.getKey());
- assertNotNull(getLdapRemoteObject(
- connObject.getAttr(Name.NAME).getValues().get(0),
- oldCleanPassword,
- connObject.getAttr(Name.NAME).getValues().get(0)));
-
- // 5. Update the LDAP Connector to retrieve passwords
- ResourceTO ldapResource = resourceService.read(RESOURCE_NAME_LDAP);
- resourceConnector = connectorService.read(
- ldapResource.getConnector(), Locale.ENGLISH.getLanguage());
- property = resourceConnector.getConfMap().get("retrievePasswordsWithSearch");
- property.getValues().clear();
- property.getValues().add(Boolean.TRUE);
- connectorService.update(resourceConnector);
-
- // 6. Pull the user from the resource
- pullTask = new PullTaskTO();
- pullTask.setDestinationRealm(SyncopeConstants.ROOT_REALM);
- pullTask.setName("LDAP Pull Task");
- pullTask.setActive(true);
- pullTask.setPerformCreate(true);
- pullTask.setPerformUpdate(true);
- pullTask.setPullMode(PullMode.FULL_RECONCILIATION);
- pullTask.setResource(RESOURCE_NAME_LDAP);
- pullTask.getActionsClassNames().add(LDAPPasswordPullActions.class.getName());
- Response taskResponse = taskService.create(pullTask);
-
- pullTask = getObject(taskResponse.getLocation(), TaskService.class, PullTaskTO.class);
- assertNotNull(pullTask);
-
- ExecTO execution = execProvisioningTask(taskService, pullTask.getKey(), 50, false);
- assertEquals(PropagationTaskExecStatus.SUCCESS, PropagationTaskExecStatus.valueOf(execution.getStatus()));
-
- // 7. Test the pulled user
- self = clientFactory.create(user.getUsername(), oldCleanPassword).self();
- assertNotNull(self);
- } catch (Exception e) {
- fail(e.getMessage());
- } finally {
- // Delete PullTask + user + reset the connector
- if (pullTask != null) {
- taskService.delete(pullTask.getKey());
- }
-
- if (resourceConnector != null && property != null) {
- property.getValues().clear();
- property.getValues().add(Boolean.FALSE);
- connectorService.update(resourceConnector);
- }
-
- if (user != null) {
- deleteUser(user.getKey());
- }
- }
- }
-
- @Test
- public void issueSYNCOPE1062() {
- GroupTO propagationGroup = null;
- PullTaskTO pullTask = null;
- UserTO user = null;
- GroupTO group = null;
- try {
- // 1. create group with resource for propagation
- propagationGroup = GroupITCase.getBasicSampleTO("SYNCOPE1062");
- propagationGroup.getResources().add(RESOURCE_NAME_DBPULL);
- propagationGroup = createGroup(propagationGroup).getEntity();
-
- // 2. create pull task for another resource, with user template assigning the group above
- pullTask = new PullTaskTO();
- pullTask.setDestinationRealm(SyncopeConstants.ROOT_REALM);
- pullTask.setName("SYNCOPE1062");
- pullTask.setActive(true);
- pullTask.setPerformCreate(true);
- pullTask.setPerformUpdate(true);
- pullTask.setPullMode(PullMode.FULL_RECONCILIATION);
- pullTask.setResource(RESOURCE_NAME_LDAP);
-
- UserTO template = new UserTO();
- template.getAuxClasses().add("minimal group");
- template.getMemberships().add(new MembershipTO.Builder().group(propagationGroup.getKey()).build());
- template.getPlainAttrs().add(attrTO("firstname", "'fixed'"));
- pullTask.getTemplates().put(AnyTypeKind.USER.name(), template);
-
- Response taskResponse = taskService.create(pullTask);
- pullTask = getObject(taskResponse.getLocation(), TaskService.class, PullTaskTO.class);
- assertNotNull(pullTask);
- assertFalse(pullTask.getTemplates().isEmpty());
-
- // 3. exec the pull task
- ExecTO execution = execProvisioningTask(taskService, pullTask.getKey(), 50, false);
- assertEquals(PropagationTaskExecStatus.SUCCESS, PropagationTaskExecStatus.valueOf(execution.getStatus()));
-
- // the user is successfully pulled...
- user = userService.read("pullFromLDAP");
- assertNotNull(user);
- assertEquals("pullFromLDAP@syncope.apache.org", user.getPlainAttr("email").getValues().get(0));
-
- group = groupService.read("testLDAPGroup");
- assertNotNull(group);
-
- ConnObjectTO connObject =
- resourceService.readConnObject(RESOURCE_NAME_LDAP, AnyTypeKind.USER.name(), user.getKey());
- assertNotNull(connObject);
- assertEquals("pullFromLDAP@syncope.apache.org", connObject.getAttr("mail").getValues().get(0));
- AttrTO userDn = connObject.getAttr(Name.NAME);
- assertNotNull(userDn);
- assertEquals(1, userDn.getValues().size());
- assertNotNull(
- getLdapRemoteObject(RESOURCE_LDAP_ADMIN_DN, RESOURCE_LDAP_ADMIN_PWD, userDn.getValues().get(0)));
-
- // ...and propagated
- PagedResult<AbstractTaskTO> propagationTasks = taskService.list(new TaskQuery.Builder(TaskType.PROPAGATION).
- resource(RESOURCE_NAME_DBPULL).
- anyTypeKind(AnyTypeKind.USER).entityKey(user.getKey()).build());
- assertEquals(1, propagationTasks.getSize());
-
- // 4. update the user on the external resource
- updateLdapRemoteObject(RESOURCE_LDAP_ADMIN_DN, RESOURCE_LDAP_ADMIN_PWD,
- userDn.getValues().get(0), Pair.of("mail", "pullFromLDAP2@syncope.apache.org"));
-
- connObject = resourceService.readConnObject(RESOURCE_NAME_LDAP, AnyTypeKind.USER.name(), user.getKey());
- assertNotNull(connObject);
- assertEquals("pullFromLDAP2@syncope.apache.org", connObject.getAttr("mail").getValues().get(0));
-
- // 5. exec the pull task again
- execution = execProvisioningTask(taskService, pullTask.getKey(), 50, false);
- assertEquals(PropagationTaskExecStatus.SUCCESS, PropagationTaskExecStatus.valueOf(execution.getStatus()));
-
- // the internal is updated...
- user = userService.read("pullFromLDAP");
- assertNotNull(user);
- assertEquals("pullFromLDAP2@syncope.apache.org", user.getPlainAttr("email").getValues().get(0));
-
- // ...and propagated
- propagationTasks = taskService.list(new TaskQuery.Builder(TaskType.PROPAGATION).
- resource(RESOURCE_NAME_DBPULL).
- anyTypeKind(AnyTypeKind.USER).entityKey(user.getKey()).build());
- assertEquals(2, propagationTasks.getSize());
- } catch (Exception e) {
- LOG.error("Unexpected during issueSYNCOPE1062()", e);
- fail(e.getMessage());
- } finally {
- if (pullTask != null) {
- taskService.delete(pullTask.getKey());
- }
-
- if (propagationGroup != null) {
- groupService.delete(propagationGroup.getKey());
- }
-
- if (group != null) {
- groupService.delete(group.getKey());
- }
- if (user != null) {
- userService.delete(user.getKey());
- }
- }
- }
}
http://git-wip-us.apache.org/repos/asf/syncope/blob/b6dfd13e/fit/core-reference/src/test/java/org/apache/syncope/fit/core/PullTaskIssuesITCase.java
----------------------------------------------------------------------
diff --git a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/PullTaskIssuesITCase.java b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/PullTaskIssuesITCase.java
new file mode 100644
index 0000000..59110f6
--- /dev/null
+++ b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/PullTaskIssuesITCase.java
@@ -0,0 +1,550 @@
+/*
+ * 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.fit.core;
+
+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 static org.junit.Assert.fail;
+
+import java.util.Locale;
+import java.util.Map;
+import java.util.Set;
+import javax.sql.DataSource;
+import javax.ws.rs.core.Response;
+import org.apache.commons.lang3.tuple.Pair;
+import org.apache.syncope.common.lib.SyncopeConstants;
+import org.apache.syncope.common.lib.patch.PasswordPatch;
+import org.apache.syncope.common.lib.patch.UserPatch;
+import org.apache.syncope.common.lib.to.AbstractTaskTO;
+import org.apache.syncope.common.lib.to.AttrTO;
+import org.apache.syncope.common.lib.to.ConnInstanceTO;
+import org.apache.syncope.common.lib.to.ConnObjectTO;
+import org.apache.syncope.common.lib.to.MembershipTO;
+import org.apache.syncope.common.lib.to.PagedResult;
+import org.apache.syncope.common.lib.to.ResourceTO;
+import org.apache.syncope.common.lib.to.GroupTO;
+import org.apache.syncope.common.lib.policy.PullPolicyTO;
+import org.apache.syncope.common.lib.to.ProvisioningResult;
+import org.apache.syncope.common.lib.to.PullTaskTO;
+import org.apache.syncope.common.lib.to.ExecTO;
+import org.apache.syncope.common.lib.to.UserTO;
+import org.apache.syncope.common.lib.types.AnyTypeKind;
+import org.apache.syncope.common.lib.types.CipherAlgorithm;
+import org.apache.syncope.common.lib.types.ConnConfProperty;
+import org.apache.syncope.common.lib.types.PropagationTaskExecStatus;
+import org.apache.syncope.common.lib.types.PullMode;
+import org.apache.syncope.common.lib.types.TaskType;
+import org.apache.syncope.common.rest.api.beans.TaskQuery;
+import org.apache.syncope.common.rest.api.service.TaskService;
+import org.apache.syncope.core.spring.security.Encryptor;
+import org.apache.syncope.core.provisioning.java.pushpull.DBPasswordPullActions;
+import org.apache.syncope.core.provisioning.java.pushpull.LDAPPasswordPullActions;
+import org.apache.syncope.fit.core.reference.TestPullRule;
+import org.identityconnectors.framework.common.objects.Name;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration(locations = { "classpath:testJDBCEnv.xml" })
+public class PullTaskIssuesITCase extends AbstractTaskITCase {
+
+ @Autowired
+ private DataSource testDataSource;
+
+ @Test
+ public void issueSYNCOPE68() {
+ //-----------------------------
+ // Create a new user ... it should be updated applying pull policy
+ //-----------------------------
+ UserTO userTO = new UserTO();
+ userTO.setRealm(SyncopeConstants.ROOT_REALM);
+ userTO.setPassword("password123");
+ userTO.setUsername("testuser2");
+
+ userTO.getPlainAttrs().add(attrTO("firstname", "testuser2"));
+ userTO.getPlainAttrs().add(attrTO("surname", "testuser2"));
+ userTO.getPlainAttrs().add(attrTO("ctype", "a type"));
+ userTO.getPlainAttrs().add(attrTO("fullname", "a type"));
+ userTO.getPlainAttrs().add(attrTO("userId", "testuser2@syncope.apache.org"));
+ userTO.getPlainAttrs().add(attrTO("email", "testuser2@syncope.apache.org"));
+
+ userTO.getResources().add(RESOURCE_NAME_NOPROPAGATION2);
+ userTO.getResources().add(RESOURCE_NAME_NOPROPAGATION4);
+
+ userTO.getMemberships().add(
+ new MembershipTO.Builder().group("bf825fe1-7320-4a54-bd64-143b5c18ab97").build());
+
+ userTO = createUser(userTO).getEntity();
+ assertNotNull(userTO);
+ assertEquals("testuser2", userTO.getUsername());
+ assertEquals(1, userTO.getMemberships().size());
+ assertEquals(3, userTO.getResources().size());
+ //-----------------------------
+
+ try {
+ //-----------------------------
+ // add user template
+ //-----------------------------
+ UserTO template = new UserTO();
+
+ template.getMemberships().add(
+ new MembershipTO.Builder().group("b8d38784-57e7-4595-859a-076222644b55").build());
+
+ template.getResources().add(RESOURCE_NAME_NOPROPAGATION4);
+ //-----------------------------
+
+ // Update pull task
+ PullTaskTO task = taskService.read("81d88f73-d474-4450-9031-605daa4e313f", true);
+ assertNotNull(task);
+
+ task.getTemplates().put(AnyTypeKind.USER.name(), template);
+
+ taskService.update(task);
+ PullTaskTO actual = taskService.read(task.getKey(), true);
+ assertNotNull(actual);
+ assertEquals(task.getKey(), actual.getKey());
+ assertFalse(actual.getTemplates().get(AnyTypeKind.USER.name()).getResources().isEmpty());
+ assertFalse(((UserTO) actual.getTemplates().get(AnyTypeKind.USER.name())).getMemberships().isEmpty());
+
+ ExecTO execution = execProvisioningTask(taskService, actual.getKey(), 50, false);
+ assertEquals(PropagationTaskExecStatus.SUCCESS, PropagationTaskExecStatus.valueOf(execution.getStatus()));
+
+ userTO = userService.read("testuser2");
+ assertNotNull(userTO);
+ assertEquals("testuser2@syncope.apache.org", userTO.getPlainAttr("userId").getValues().get(0));
+ assertEquals(2, userTO.getMemberships().size());
+ assertEquals(4, userTO.getResources().size());
+ } finally {
+ UserTO dUserTO = deleteUser(userTO.getKey()).getEntity();
+ assertNotNull(dUserTO);
+ }
+ }
+
+ @Test
+ public void issueSYNCOPE230() {
+ JdbcTemplate jdbcTemplate = new JdbcTemplate(testDataSource);
+
+ // 1. populate the external table
+ jdbcTemplate.execute("INSERT INTO testpull VALUES"
+ + "('a54b3794-b231-47be-b24a-11e1a42949f6', 'issuesyncope230', 'Surname', 'syncope230@syncope.apache.org', NULL)");
+
+ // 2. execute PullTask for resource-db-pull (table TESTPULL on external H2)
+ execProvisioningTask(taskService, "7c2242f4-14af-4ab5-af31-cdae23783655", 50, false);
+
+ // 3. read e-mail address for user created by the PullTask first execution
+ UserTO userTO = userService.read("issuesyncope230");
+ assertNotNull(userTO);
+ String email = userTO.getPlainAttr("email").getValues().iterator().next();
+ assertNotNull(email);
+
+ // 4. update TESTPULL on external H2 by changing e-mail address
+ jdbcTemplate.execute("UPDATE TESTPULL SET email='updatedSYNCOPE230@syncope.apache.org'");
+
+ // 5. re-execute the PullTask
+ execProvisioningTask(taskService, "7c2242f4-14af-4ab5-af31-cdae23783655", 50, false);
+
+ // 6. verify that the e-mail was updated
+ userTO = userService.read("issuesyncope230");
+ assertNotNull(userTO);
+ email = userTO.getPlainAttr("email").getValues().iterator().next();
+ assertNotNull(email);
+ assertEquals("updatedSYNCOPE230@syncope.apache.org", email);
+ }
+
+ @Test
+ public void issueSYNCOPE258() {
+ // -----------------------------
+ // Add a custom correlation rule
+ // -----------------------------
+ PullPolicyTO policyTO = policyService.read("9454b0d7-2610-400a-be82-fc23cf553dd6");
+ policyTO.getSpecification().getCorrelationRules().put(AnyTypeKind.USER.name(), TestPullRule.class.getName());
+ policyService.update(policyTO);
+ // -----------------------------
+
+ PullTaskTO task = new PullTaskTO();
+ task.setDestinationRealm(SyncopeConstants.ROOT_REALM);
+ task.setName("Test Pull Rule");
+ task.setActive(true);
+ task.setResource(RESOURCE_NAME_WS2);
+ task.setPullMode(PullMode.FULL_RECONCILIATION);
+ task.setPerformCreate(true);
+ task.setPerformDelete(true);
+ task.setPerformUpdate(true);
+
+ Response response = taskService.create(task);
+ task = getObject(response.getLocation(), TaskService.class, PullTaskTO.class);
+
+ UserTO userTO = UserITCase.getUniqueSampleTO("s258_1@apache.org");
+ userTO.getResources().clear();
+ userTO.getResources().add(RESOURCE_NAME_WS2);
+
+ createUser(userTO);
+
+ userTO = UserITCase.getUniqueSampleTO("s258_2@apache.org");
+ userTO.getResources().clear();
+ userTO.getResources().add(RESOURCE_NAME_WS2);
+
+ userTO = createUser(userTO).getEntity();
+
+ // change email in order to unmatch the second user
+ UserPatch userPatch = new UserPatch();
+ userPatch.setKey(userTO.getKey());
+ userPatch.getPlainAttrs().add(attrAddReplacePatch("email", "s258@apache.org"));
+
+ userService.update(userPatch);
+
+ execProvisioningTask(taskService, task.getKey(), 50, false);
+
+ PullTaskTO executed = taskService.read(task.getKey(), true);
+ assertEquals(1, executed.getExecutions().size());
+
+ // asser for just one match
+ assertTrue(executed.getExecutions().get(0).getMessage().substring(0, 55) + "...",
+ executed.getExecutions().get(0).getMessage().contains("[updated/failures]: 1/0"));
+ }
+
+ @Test
+ public void issueSYNCOPE272() {
+ removeTestUsers();
+
+ // create user with testdb resource
+ UserTO userTO = UserITCase.getUniqueSampleTO("syncope272@syncope.apache.org");
+ userTO.getResources().add(RESOURCE_NAME_TESTDB);
+
+ ProvisioningResult<UserTO> result = createUser(userTO);
+ userTO = result.getEntity();
+ try {
+ assertNotNull(userTO);
+ assertEquals(1, result.getPropagationStatuses().size());
+ assertEquals(PropagationTaskExecStatus.SUCCESS, result.getPropagationStatuses().get(0).getStatus());
+
+ ExecTO taskExecTO = execProvisioningTask(
+ taskService, "986867e2-993b-430e-8feb-aa9abb4c1dcd", 50, false);
+
+ assertNotNull(taskExecTO.getStatus());
+ assertEquals(PropagationTaskExecStatus.SUCCESS, PropagationTaskExecStatus.valueOf(taskExecTO.getStatus()));
+
+ userTO = userService.read(userTO.getKey());
+ assertNotNull(userTO);
+ assertNotNull(userTO.getPlainAttr("firstname").getValues().get(0));
+ } finally {
+ removeTestUsers();
+ }
+ }
+
+ @Test
+ public void issueSYNCOPE307() {
+ UserTO userTO = UserITCase.getUniqueSampleTO("s307@apache.org");
+ userTO.setUsername("test0");
+ userTO.getPlainAttr("firstname").getValues().clear();
+ userTO.getPlainAttr("firstname").getValues().add("nome0");
+ userTO.getAuxClasses().add("csv");
+
+ AttrTO csvuserid = new AttrTO();
+ csvuserid.setSchema("csvuserid");
+ userTO.getDerAttrs().add(csvuserid);
+
+ userTO.getResources().clear();
+ userTO.getResources().add(RESOURCE_NAME_WS2);
+
+ userTO = createUser(userTO).getEntity();
+ assertNotNull(userTO);
+
+ userTO = userService.read(userTO.getKey());
+ assertTrue(userTO.getVirAttrs().isEmpty());
+
+ // Update pull task
+ PullTaskTO task = taskService.read("38abbf9e-a1a3-40a1-a15f-7d0ac02f47f1", true);
+ assertNotNull(task);
+
+ UserTO template = new UserTO();
+ template.setPassword("'password123'");
+ template.getResources().add(RESOURCE_NAME_DBVIRATTR);
+ template.getVirAttrs().add(attrTO("virtualdata", "'virtualvalue'"));
+
+ task.getTemplates().put(AnyTypeKind.USER.name(), template);
+
+ taskService.update(task);
+
+ // exec task: one user from CSV will match the user created above and template will be applied
+ execProvisioningTask(taskService, task.getKey(), 50, false);
+
+ // check that template was successfully applied...
+ userTO = userService.read(userTO.getKey());
+ assertEquals("virtualvalue", userTO.getVirAttr("virtualdata").getValues().get(0));
+
+ // ...and that propagation to db succeeded
+ JdbcTemplate jdbcTemplate = new JdbcTemplate(testDataSource);
+ String value = queryForObject(
+ jdbcTemplate, 50, "SELECT USERNAME FROM testpull WHERE ID=?", String.class, userTO.getKey());
+ assertEquals("virtualvalue", value);
+ }
+
+ @Test
+ public void issueSYNCOPE313DB() throws Exception {
+ // 1. create user in DB
+ UserTO user = UserITCase.getUniqueSampleTO("syncope313-db@syncope.apache.org");
+ user.setPassword("security123");
+ user.getResources().add(RESOURCE_NAME_TESTDB);
+ user = createUser(user).getEntity();
+ assertNotNull(user);
+ assertFalse(user.getResources().isEmpty());
+
+ // 2. Check that the DB resource has the correct password
+ JdbcTemplate jdbcTemplate = new JdbcTemplate(testDataSource);
+ String value = queryForObject(
+ jdbcTemplate, 50, "SELECT PASSWORD FROM test WHERE ID=?", String.class, user.getUsername());
+ assertEquals(Encryptor.getInstance().encode("security123", CipherAlgorithm.SHA1), value.toUpperCase());
+
+ // 3. Update the password in the DB
+ String newCleanPassword = "new-security";
+ String newPassword = Encryptor.getInstance().encode(newCleanPassword, CipherAlgorithm.SHA1);
+ jdbcTemplate.execute("UPDATE test set PASSWORD='" + newPassword + "' where ID='" + user.getUsername() + "'");
+
+ // 4. Pull the user from the resource
+ PullTaskTO pullTask = new PullTaskTO();
+ pullTask.setDestinationRealm(SyncopeConstants.ROOT_REALM);
+ pullTask.setName("DB Pull Task");
+ pullTask.setActive(true);
+ pullTask.setPerformCreate(true);
+ pullTask.setPerformUpdate(true);
+ pullTask.setPullMode(PullMode.FULL_RECONCILIATION);
+ pullTask.setResource(RESOURCE_NAME_TESTDB);
+ pullTask.getActionsClassNames().add(DBPasswordPullActions.class.getName());
+ Response taskResponse = taskService.create(pullTask);
+
+ PullTaskTO actual = getObject(taskResponse.getLocation(), TaskService.class, PullTaskTO.class);
+ assertNotNull(actual);
+
+ pullTask = taskService.read(actual.getKey(), true);
+ assertNotNull(pullTask);
+ assertEquals(actual.getKey(), pullTask.getKey());
+ assertEquals(actual.getJobDelegateClassName(), pullTask.getJobDelegateClassName());
+
+ ExecTO execution = execProvisioningTask(taskService, pullTask.getKey(), 50, false);
+ assertEquals(PropagationTaskExecStatus.SUCCESS, PropagationTaskExecStatus.valueOf(execution.getStatus()));
+
+ // 5. Test the pulled user
+ Pair<Map<String, Set<String>>, UserTO> self = clientFactory.create(user.getUsername(), newCleanPassword).self();
+ assertNotNull(self);
+
+ // 6. Delete PullTask + user
+ taskService.delete(pullTask.getKey());
+ deleteUser(user.getKey());
+ }
+
+ @Test
+ public void issueSYNCOPE313LDAP() throws Exception {
+ // First of all, clear any potential conflict with existing user / group
+ ldapCleanup();
+
+ UserTO user = null;
+ PullTaskTO pullTask = null;
+ ConnInstanceTO resourceConnector = null;
+ ConnConfProperty property = null;
+ try {
+ // 1. create user in LDAP
+ String oldCleanPassword = "security123";
+ user = UserITCase.getUniqueSampleTO("syncope313-ldap@syncope.apache.org");
+ user.setPassword(oldCleanPassword);
+ user.getResources().add(RESOURCE_NAME_LDAP);
+ user = createUser(user).getEntity();
+ assertNotNull(user);
+ assertFalse(user.getResources().isEmpty());
+
+ // 2. request to change password only on Syncope and not on LDAP
+ String newCleanPassword = "new-security123";
+ UserPatch userPatch = new UserPatch();
+ userPatch.setKey(user.getKey());
+ userPatch.setPassword(new PasswordPatch.Builder().value(newCleanPassword).build());
+ user = updateUser(userPatch).getEntity();
+
+ // 3. Check that the Syncope user now has the changed password
+ Pair<Map<String, Set<String>>, UserTO> self =
+ clientFactory.create(user.getUsername(), newCleanPassword).self();
+ assertNotNull(self);
+
+ // 4. Check that the LDAP resource has the old password
+ ConnObjectTO connObject =
+ resourceService.readConnObject(RESOURCE_NAME_LDAP, AnyTypeKind.USER.name(), user.getKey());
+ assertNotNull(getLdapRemoteObject(
+ connObject.getAttr(Name.NAME).getValues().get(0),
+ oldCleanPassword,
+ connObject.getAttr(Name.NAME).getValues().get(0)));
+
+ // 5. Update the LDAP Connector to retrieve passwords
+ ResourceTO ldapResource = resourceService.read(RESOURCE_NAME_LDAP);
+ resourceConnector = connectorService.read(
+ ldapResource.getConnector(), Locale.ENGLISH.getLanguage());
+ property = resourceConnector.getConfMap().get("retrievePasswordsWithSearch");
+ property.getValues().clear();
+ property.getValues().add(Boolean.TRUE);
+ connectorService.update(resourceConnector);
+
+ // 6. Pull the user from the resource
+ pullTask = new PullTaskTO();
+ pullTask.setDestinationRealm(SyncopeConstants.ROOT_REALM);
+ pullTask.setName("LDAP Pull Task");
+ pullTask.setActive(true);
+ pullTask.setPerformCreate(true);
+ pullTask.setPerformUpdate(true);
+ pullTask.setPullMode(PullMode.FULL_RECONCILIATION);
+ pullTask.setResource(RESOURCE_NAME_LDAP);
+ pullTask.getActionsClassNames().add(LDAPPasswordPullActions.class.getName());
+ Response taskResponse = taskService.create(pullTask);
+
+ pullTask = getObject(taskResponse.getLocation(), TaskService.class, PullTaskTO.class);
+ assertNotNull(pullTask);
+
+ ExecTO execution = execProvisioningTask(taskService, pullTask.getKey(), 50, false);
+ assertEquals(PropagationTaskExecStatus.SUCCESS, PropagationTaskExecStatus.valueOf(execution.getStatus()));
+
+ // 7. Test the pulled user
+ self = clientFactory.create(user.getUsername(), oldCleanPassword).self();
+ assertNotNull(self);
+ } catch (Exception e) {
+ fail(e.getMessage());
+ } finally {
+ // Delete PullTask + user + reset the connector
+ if (pullTask != null) {
+ taskService.delete(pullTask.getKey());
+ }
+
+ if (resourceConnector != null && property != null) {
+ property.getValues().clear();
+ property.getValues().add(Boolean.FALSE);
+ connectorService.update(resourceConnector);
+ }
+
+ if (user != null) {
+ deleteUser(user.getKey());
+ }
+ }
+ }
+
+ @Test
+ public void issueSYNCOPE1062() {
+ GroupTO propagationGroup = null;
+ PullTaskTO pullTask = null;
+ UserTO user = null;
+ GroupTO group = null;
+ try {
+ // 1. create group with resource for propagation
+ propagationGroup = GroupITCase.getBasicSampleTO("SYNCOPE1062");
+ propagationGroup.getResources().add(RESOURCE_NAME_DBPULL);
+ propagationGroup = createGroup(propagationGroup).getEntity();
+
+ // 2. create pull task for another resource, with user template assigning the group above
+ pullTask = new PullTaskTO();
+ pullTask.setDestinationRealm(SyncopeConstants.ROOT_REALM);
+ pullTask.setName("SYNCOPE1062");
+ pullTask.setActive(true);
+ pullTask.setPerformCreate(true);
+ pullTask.setPerformUpdate(true);
+ pullTask.setPullMode(PullMode.FULL_RECONCILIATION);
+ pullTask.setResource(RESOURCE_NAME_LDAP);
+
+ UserTO template = new UserTO();
+ template.getAuxClasses().add("minimal group");
+ template.getMemberships().add(new MembershipTO.Builder().group(propagationGroup.getKey()).build());
+ template.getPlainAttrs().add(attrTO("firstname", "'fixed'"));
+ pullTask.getTemplates().put(AnyTypeKind.USER.name(), template);
+
+ Response taskResponse = taskService.create(pullTask);
+ pullTask = getObject(taskResponse.getLocation(), TaskService.class, PullTaskTO.class);
+ assertNotNull(pullTask);
+ assertFalse(pullTask.getTemplates().isEmpty());
+
+ // 3. exec the pull task
+ ExecTO execution = execProvisioningTask(taskService, pullTask.getKey(), 50, false);
+ assertEquals(PropagationTaskExecStatus.SUCCESS, PropagationTaskExecStatus.valueOf(execution.getStatus()));
+
+ // the user is successfully pulled...
+ user = userService.read("pullFromLDAP");
+ assertNotNull(user);
+ assertEquals("pullFromLDAP@syncope.apache.org", user.getPlainAttr("email").getValues().get(0));
+
+ group = groupService.read("testLDAPGroup");
+ assertNotNull(group);
+
+ ConnObjectTO connObject =
+ resourceService.readConnObject(RESOURCE_NAME_LDAP, AnyTypeKind.USER.name(), user.getKey());
+ assertNotNull(connObject);
+ assertEquals("pullFromLDAP@syncope.apache.org", connObject.getAttr("mail").getValues().get(0));
+ AttrTO userDn = connObject.getAttr(Name.NAME);
+ assertNotNull(userDn);
+ assertEquals(1, userDn.getValues().size());
+ assertNotNull(
+ getLdapRemoteObject(RESOURCE_LDAP_ADMIN_DN, RESOURCE_LDAP_ADMIN_PWD, userDn.getValues().get(0)));
+
+ // ...and propagated
+ PagedResult<AbstractTaskTO> propagationTasks = taskService.list(new TaskQuery.Builder(TaskType.PROPAGATION).
+ resource(RESOURCE_NAME_DBPULL).
+ anyTypeKind(AnyTypeKind.USER).entityKey(user.getKey()).build());
+ assertEquals(1, propagationTasks.getSize());
+
+ // 4. update the user on the external resource
+ updateLdapRemoteObject(RESOURCE_LDAP_ADMIN_DN, RESOURCE_LDAP_ADMIN_PWD,
+ userDn.getValues().get(0), Pair.of("mail", "pullFromLDAP2@syncope.apache.org"));
+
+ connObject = resourceService.readConnObject(RESOURCE_NAME_LDAP, AnyTypeKind.USER.name(), user.getKey());
+ assertNotNull(connObject);
+ assertEquals("pullFromLDAP2@syncope.apache.org", connObject.getAttr("mail").getValues().get(0));
+
+ // 5. exec the pull task again
+ execution = execProvisioningTask(taskService, pullTask.getKey(), 50, false);
+ assertEquals(PropagationTaskExecStatus.SUCCESS, PropagationTaskExecStatus.valueOf(execution.getStatus()));
+
+ // the internal is updated...
+ user = userService.read("pullFromLDAP");
+ assertNotNull(user);
+ assertEquals("pullFromLDAP2@syncope.apache.org", user.getPlainAttr("email").getValues().get(0));
+
+ // ...and propagated
+ propagationTasks = taskService.list(new TaskQuery.Builder(TaskType.PROPAGATION).
+ resource(RESOURCE_NAME_DBPULL).
+ anyTypeKind(AnyTypeKind.USER).entityKey(user.getKey()).build());
+ assertEquals(2, propagationTasks.getSize());
+ } catch (Exception e) {
+ LOG.error("Unexpected during issueSYNCOPE1062()", e);
+ fail(e.getMessage());
+ } finally {
+ if (pullTask != null) {
+ taskService.delete(pullTask.getKey());
+ }
+
+ if (propagationGroup != null) {
+ groupService.delete(propagationGroup.getKey());
+ }
+
+ if (group != null) {
+ groupService.delete(group.getKey());
+ }
+ if (user != null) {
+ userService.delete(user.getKey());
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/syncope/blob/b6dfd13e/fit/core-reference/src/test/java/org/apache/syncope/fit/core/ReportITCase.java
----------------------------------------------------------------------
diff --git a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/ReportITCase.java b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/ReportITCase.java
index 1851e6d..abd746c 100644
--- a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/ReportITCase.java
+++ b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/ReportITCase.java
@@ -49,18 +49,11 @@ import org.apache.syncope.common.lib.types.ReportExecExportFormat;
import org.apache.syncope.common.lib.types.ReportExecStatus;
import org.apache.syncope.common.rest.api.beans.BulkExecDeleteQuery;
import org.apache.syncope.common.rest.api.beans.ExecuteQuery;
-import org.apache.syncope.common.rest.api.service.ReportService;
import org.apache.syncope.fit.AbstractITCase;
import org.junit.Test;
public class ReportITCase extends AbstractITCase {
- private ReportTO createReport(final ReportTO report) {
- Response response = reportService.create(report);
- assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatusInfo().getStatusCode());
- return getObject(response.getLocation(), ReportService.class, ReportTO.class);
- }
-
@Test
public void getReportletConfs() {
Set<String> reportletConfs = syncopeService.platform().getReportletConfs();
@@ -282,61 +275,4 @@ public class ReportITCase extends AbstractITCase {
loggerService.delete(LoggerType.AUDIT, auditLoggerName.toLoggerName());
}
}
-
- @Test
- public void issueSYNCOPE43() {
- ReportTO reportTO = new ReportTO();
- reportTO.setName("issueSYNCOPE43" + getUUIDString());
- reportTO.setActive(true);
- reportTO.setTemplate("sample");
- reportTO = createReport(reportTO);
- assertNotNull(reportTO);
-
- ExecTO execution = reportService.execute(new ExecuteQuery.Builder().key(reportTO.getKey()).build());
- assertNotNull(execution);
-
- int maxit = 50;
- do {
- try {
- Thread.sleep(1000);
- } catch (InterruptedException e) {
- }
-
- reportTO = reportService.read(reportTO.getKey());
-
- maxit--;
- } while (reportTO.getExecutions().isEmpty() && maxit > 0);
-
- assertEquals(1, reportTO.getExecutions().size());
- }
-
- @Test
- public void issueSYNCOPE102() throws IOException {
- // Create
- ReportTO reportTO = reportService.read("0062ea9c-924d-4ecf-9961-4492a8cc6d1b");
- reportTO.setKey(null);
- reportTO.setName("issueSYNCOPE102" + getUUIDString());
- reportTO = createReport(reportTO);
- assertNotNull(reportTO);
-
- // Execute (multiple requests)
- for (int i = 0; i < 10; i++) {
- ExecTO execution = reportService.execute(new ExecuteQuery.Builder().key(reportTO.getKey()).build());
- assertNotNull(execution);
- }
-
- // Wait for one execution
- int maxit = 50;
- do {
- try {
- Thread.sleep(1000);
- } catch (InterruptedException e) {
- }
-
- reportTO = reportService.read(reportTO.getKey());
-
- maxit--;
- } while (reportTO.getExecutions().isEmpty() && maxit > 0);
- assertFalse(reportTO.getExecutions().isEmpty());
- }
}
http://git-wip-us.apache.org/repos/asf/syncope/blob/b6dfd13e/fit/core-reference/src/test/java/org/apache/syncope/fit/core/ReportIssuesITCase.java
----------------------------------------------------------------------
diff --git a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/ReportIssuesITCase.java b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/ReportIssuesITCase.java
new file mode 100644
index 0000000..fb0d845
--- /dev/null
+++ b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/ReportIssuesITCase.java
@@ -0,0 +1,90 @@
+/*
+ * 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.fit.core;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+
+import java.io.IOException;
+import org.apache.syncope.common.lib.to.ExecTO;
+import org.apache.syncope.common.lib.to.ReportTO;
+import org.apache.syncope.common.rest.api.beans.ExecuteQuery;
+import org.apache.syncope.fit.AbstractITCase;
+import org.junit.Test;
+
+public class ReportIssuesITCase extends AbstractITCase {
+
+ @Test
+ public void issueSYNCOPE43() {
+ ReportTO reportTO = new ReportTO();
+ reportTO.setName("issueSYNCOPE43" + getUUIDString());
+ reportTO.setActive(true);
+ reportTO.setTemplate("sample");
+ reportTO = createReport(reportTO);
+ assertNotNull(reportTO);
+
+ ExecTO execution = reportService.execute(new ExecuteQuery.Builder().key(reportTO.getKey()).build());
+ assertNotNull(execution);
+
+ int maxit = 50;
+ do {
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException e) {
+ }
+
+ reportTO = reportService.read(reportTO.getKey());
+
+ maxit--;
+ } while (reportTO.getExecutions().isEmpty() && maxit > 0);
+
+ assertEquals(1, reportTO.getExecutions().size());
+ }
+
+ @Test
+ public void issueSYNCOPE102() throws IOException {
+ // Create
+ ReportTO reportTO = reportService.read("0062ea9c-924d-4ecf-9961-4492a8cc6d1b");
+ reportTO.setKey(null);
+ reportTO.setName("issueSYNCOPE102" + getUUIDString());
+ reportTO = createReport(reportTO);
+ assertNotNull(reportTO);
+
+ // Execute (multiple requests)
+ for (int i = 0; i < 10; i++) {
+ ExecTO execution = reportService.execute(new ExecuteQuery.Builder().key(reportTO.getKey()).build());
+ assertNotNull(execution);
+ }
+
+ // Wait for one execution
+ int maxit = 50;
+ do {
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException e) {
+ }
+
+ reportTO = reportService.read(reportTO.getKey());
+
+ maxit--;
+ } while (reportTO.getExecutions().isEmpty() && maxit > 0);
+ assertFalse(reportTO.getExecutions().isEmpty());
+ }
+}
[3/4] syncope git commit: Reduce number of integration test cases
executed by default build, moving time-consuming to full-it profile
Posted by il...@apache.org.
http://git-wip-us.apache.org/repos/asf/syncope/blob/59d6d4a3/fit/core-reference/src/test/java/org/apache/syncope/fit/core/PullTaskITCase.java
----------------------------------------------------------------------
diff --git a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/PullTaskITCase.java b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/PullTaskITCase.java
index 0869613..67d8f78 100644
--- a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/PullTaskITCase.java
+++ b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/PullTaskITCase.java
@@ -32,9 +32,6 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.util.Date;
import java.util.HashSet;
-import java.util.List;
-import java.util.Locale;
-import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.UUID;
@@ -44,13 +41,10 @@ import org.apache.commons.collections4.IterableUtils;
import org.apache.commons.collections4.Predicate;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.SerializationUtils;
-import org.apache.commons.lang3.tuple.Pair;
import org.apache.syncope.client.lib.SyncopeClient;
import org.apache.syncope.common.lib.SyncopeClientException;
import org.apache.syncope.common.lib.SyncopeConstants;
import org.apache.syncope.common.lib.patch.DeassociationPatch;
-import org.apache.syncope.common.lib.patch.PasswordPatch;
-import org.apache.syncope.common.lib.patch.UserPatch;
import org.apache.syncope.common.lib.to.AbstractTaskTO;
import org.apache.syncope.common.lib.to.AnyObjectTO;
import org.apache.syncope.common.lib.to.AttrTO;
@@ -61,15 +55,11 @@ import org.apache.syncope.common.lib.to.PagedResult;
import org.apache.syncope.common.lib.to.ResourceTO;
import org.apache.syncope.common.lib.to.GroupTO;
import org.apache.syncope.common.lib.to.ProvisionTO;
-import org.apache.syncope.common.lib.policy.PullPolicyTO;
import org.apache.syncope.common.lib.to.MappingItemTO;
-import org.apache.syncope.common.lib.to.ProvisioningResult;
import org.apache.syncope.common.lib.to.PullTaskTO;
import org.apache.syncope.common.lib.to.ExecTO;
-import org.apache.syncope.common.lib.to.RealmTO;
import org.apache.syncope.common.lib.to.UserTO;
import org.apache.syncope.common.lib.types.AnyTypeKind;
-import org.apache.syncope.common.lib.types.CipherAlgorithm;
import org.apache.syncope.common.lib.types.ClientExceptionType;
import org.apache.syncope.common.lib.types.ConnConfProperty;
import org.apache.syncope.common.lib.types.ConnectorCapability;
@@ -81,15 +71,10 @@ import org.apache.syncope.common.rest.api.beans.AnyQuery;
import org.apache.syncope.common.rest.api.beans.TaskQuery;
import org.apache.syncope.common.rest.api.service.ConnectorService;
import org.apache.syncope.common.rest.api.service.TaskService;
-import org.apache.syncope.core.spring.security.Encryptor;
-import org.apache.syncope.core.provisioning.java.pushpull.DBPasswordPullActions;
-import org.apache.syncope.core.provisioning.java.pushpull.LDAPPasswordPullActions;
import org.apache.syncope.fit.ActivitiDetector;
import org.apache.syncope.fit.core.reference.PrefixMappingItemTransformer;
import org.apache.syncope.fit.core.reference.TestReconciliationFilterBuilder;
import org.apache.syncope.fit.core.reference.TestPullActions;
-import org.apache.syncope.fit.core.reference.TestPullRule;
-import org.identityconnectors.framework.common.objects.Name;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -337,41 +322,6 @@ public class PullTaskITCase extends AbstractTaskITCase {
}
}
- /**
- * Clean Syncope and LDAP resource status.
- */
- private void ldapCleanup() {
- PagedResult<GroupTO> matchingGroups = groupService.search(new AnyQuery.Builder().realm(
- SyncopeConstants.ROOT_REALM).
- fiql(SyncopeClient.getGroupSearchConditionBuilder().is("name").equalTo("testLDAPGroup").query()).
- build());
- if (matchingGroups.getSize() > 0) {
- for (GroupTO group : matchingGroups.getResult()) {
- DeassociationPatch deassociationPatch = new DeassociationPatch();
- deassociationPatch.setKey(group.getKey());
- deassociationPatch.setAction(ResourceDeassociationAction.UNLINK);
- deassociationPatch.getResources().add(RESOURCE_NAME_LDAP);
- groupService.deassociate(deassociationPatch);
- groupService.delete(group.getKey());
- }
- }
- PagedResult<UserTO> matchingUsers = userService.search(
- new AnyQuery.Builder().realm(SyncopeConstants.ROOT_REALM).
- fiql(SyncopeClient.getUserSearchConditionBuilder().is("username").equalTo("pullFromLDAP").
- query()).
- build());
- if (matchingUsers.getSize() > 0) {
- for (UserTO user : matchingUsers.getResult()) {
- DeassociationPatch deassociationPatch = new DeassociationPatch();
- deassociationPatch.setKey(user.getKey());
- deassociationPatch.setAction(ResourceDeassociationAction.UNLINK);
- deassociationPatch.getResources().add(RESOURCE_NAME_LDAP);
- userService.deassociate(deassociationPatch);
- userService.delete(user.getKey());
- }
- }
- }
-
@Test
public void reconcileFromLDAP() {
// First of all, clear any potential conflict with existing user / group
@@ -667,512 +617,4 @@ public class PullTaskITCase extends AbstractTaskITCase {
jdbcTemplate.execute("DELETE FROM testpull WHERE ID=1041");
}
}
-
- @Test
- public void orgUnit() {
- // 0. initial realms
- List<RealmTO> realms = realmService.list("/odd");
- int pre = realms.size();
-
- // 1. create task for pulling org units
- PullTaskTO pullTask = new PullTaskTO();
- pullTask.setActive(true);
- pullTask.setName("For orgUnit");
- pullTask.setResource(RESOURCE_NAME_LDAP_ORGUNIT);
- pullTask.setDestinationRealm("/odd");
- pullTask.setPullMode(PullMode.FULL_RECONCILIATION);
- pullTask.setPerformCreate(true);
- pullTask.setPerformUpdate(true);
- pullTask.setPerformDelete(true);
-
- Response response = taskService.create(pullTask);
- if (response.getStatusInfo().getStatusCode() != Response.Status.CREATED.getStatusCode()) {
- throw (RuntimeException) clientFactory.getExceptionMapper().fromResponse(response);
- }
- pullTask = getObject(response.getLocation(), TaskService.class, PullTaskTO.class);
- assertNotNull(pullTask);
-
- ExecTO exec = execProvisioningTask(taskService, pullTask.getKey(), 50, false);
- assertEquals(PropagationTaskExecStatus.SUCCESS, PropagationTaskExecStatus.valueOf(exec.getStatus()));
-
- // 2. check
- realms = realmService.list("/odd");
- int post = realms.size();
- assertEquals(pre + 2, post);
- }
-
- @Test
- public void issueSYNCOPE68() {
- //-----------------------------
- // Create a new user ... it should be updated applying pull policy
- //-----------------------------
- UserTO userTO = new UserTO();
- userTO.setRealm(SyncopeConstants.ROOT_REALM);
- userTO.setPassword("password123");
- userTO.setUsername("testuser2");
-
- userTO.getPlainAttrs().add(attrTO("firstname", "testuser2"));
- userTO.getPlainAttrs().add(attrTO("surname", "testuser2"));
- userTO.getPlainAttrs().add(attrTO("ctype", "a type"));
- userTO.getPlainAttrs().add(attrTO("fullname", "a type"));
- userTO.getPlainAttrs().add(attrTO("userId", "testuser2@syncope.apache.org"));
- userTO.getPlainAttrs().add(attrTO("email", "testuser2@syncope.apache.org"));
-
- userTO.getResources().add(RESOURCE_NAME_NOPROPAGATION2);
- userTO.getResources().add(RESOURCE_NAME_NOPROPAGATION4);
-
- userTO.getMemberships().add(
- new MembershipTO.Builder().group("bf825fe1-7320-4a54-bd64-143b5c18ab97").build());
-
- userTO = createUser(userTO).getEntity();
- assertNotNull(userTO);
- assertEquals("testuser2", userTO.getUsername());
- assertEquals(1, userTO.getMemberships().size());
- assertEquals(3, userTO.getResources().size());
- //-----------------------------
-
- try {
- //-----------------------------
- // add user template
- //-----------------------------
- UserTO template = new UserTO();
-
- template.getMemberships().add(
- new MembershipTO.Builder().group("b8d38784-57e7-4595-859a-076222644b55").build());
-
- template.getResources().add(RESOURCE_NAME_NOPROPAGATION4);
- //-----------------------------
-
- // Update pull task
- PullTaskTO task = taskService.read("81d88f73-d474-4450-9031-605daa4e313f", true);
- assertNotNull(task);
-
- task.getTemplates().put(AnyTypeKind.USER.name(), template);
-
- taskService.update(task);
- PullTaskTO actual = taskService.read(task.getKey(), true);
- assertNotNull(actual);
- assertEquals(task.getKey(), actual.getKey());
- assertFalse(actual.getTemplates().get(AnyTypeKind.USER.name()).getResources().isEmpty());
- assertFalse(((UserTO) actual.getTemplates().get(AnyTypeKind.USER.name())).getMemberships().isEmpty());
-
- ExecTO execution = execProvisioningTask(taskService, actual.getKey(), 50, false);
- assertEquals(PropagationTaskExecStatus.SUCCESS, PropagationTaskExecStatus.valueOf(execution.getStatus()));
-
- userTO = userService.read("testuser2");
- assertNotNull(userTO);
- assertEquals("testuser2@syncope.apache.org", userTO.getPlainAttr("userId").getValues().get(0));
- assertEquals(2, userTO.getMemberships().size());
- assertEquals(4, userTO.getResources().size());
- } finally {
- UserTO dUserTO = deleteUser(userTO.getKey()).getEntity();
- assertNotNull(dUserTO);
- }
- }
-
- @Test
- public void issueSYNCOPE230() {
- JdbcTemplate jdbcTemplate = new JdbcTemplate(testDataSource);
-
- // 1. populate the external table
- jdbcTemplate.execute("INSERT INTO testpull VALUES"
- + "('a54b3794-b231-47be-b24a-11e1a42949f6', 'issuesyncope230', 'Surname', 'syncope230@syncope.apache.org', NULL)");
-
- // 2. execute PullTask for resource-db-pull (table TESTPULL on external H2)
- execProvisioningTask(taskService, "7c2242f4-14af-4ab5-af31-cdae23783655", 50, false);
-
- // 3. read e-mail address for user created by the PullTask first execution
- UserTO userTO = userService.read("issuesyncope230");
- assertNotNull(userTO);
- String email = userTO.getPlainAttr("email").getValues().iterator().next();
- assertNotNull(email);
-
- // 4. update TESTPULL on external H2 by changing e-mail address
- jdbcTemplate.execute("UPDATE TESTPULL SET email='updatedSYNCOPE230@syncope.apache.org'");
-
- // 5. re-execute the PullTask
- execProvisioningTask(taskService, "7c2242f4-14af-4ab5-af31-cdae23783655", 50, false);
-
- // 6. verify that the e-mail was updated
- userTO = userService.read("issuesyncope230");
- assertNotNull(userTO);
- email = userTO.getPlainAttr("email").getValues().iterator().next();
- assertNotNull(email);
- assertEquals("updatedSYNCOPE230@syncope.apache.org", email);
- }
-
- @Test
- public void issueSYNCOPE258() {
- // -----------------------------
- // Add a custom correlation rule
- // -----------------------------
- PullPolicyTO policyTO = policyService.read("9454b0d7-2610-400a-be82-fc23cf553dd6");
- policyTO.getSpecification().getCorrelationRules().put(AnyTypeKind.USER.name(), TestPullRule.class.getName());
- policyService.update(policyTO);
- // -----------------------------
-
- PullTaskTO task = new PullTaskTO();
- task.setDestinationRealm(SyncopeConstants.ROOT_REALM);
- task.setName("Test Pull Rule");
- task.setActive(true);
- task.setResource(RESOURCE_NAME_WS2);
- task.setPullMode(PullMode.FULL_RECONCILIATION);
- task.setPerformCreate(true);
- task.setPerformDelete(true);
- task.setPerformUpdate(true);
-
- Response response = taskService.create(task);
- task = getObject(response.getLocation(), TaskService.class, PullTaskTO.class);
-
- UserTO userTO = UserITCase.getUniqueSampleTO("s258_1@apache.org");
- userTO.getResources().clear();
- userTO.getResources().add(RESOURCE_NAME_WS2);
-
- createUser(userTO);
-
- userTO = UserITCase.getUniqueSampleTO("s258_2@apache.org");
- userTO.getResources().clear();
- userTO.getResources().add(RESOURCE_NAME_WS2);
-
- userTO = createUser(userTO).getEntity();
-
- // change email in order to unmatch the second user
- UserPatch userPatch = new UserPatch();
- userPatch.setKey(userTO.getKey());
- userPatch.getPlainAttrs().add(attrAddReplacePatch("email", "s258@apache.org"));
-
- userService.update(userPatch);
-
- execProvisioningTask(taskService, task.getKey(), 50, false);
-
- PullTaskTO executed = taskService.read(task.getKey(), true);
- assertEquals(1, executed.getExecutions().size());
-
- // asser for just one match
- assertTrue(executed.getExecutions().get(0).getMessage().substring(0, 55) + "...",
- executed.getExecutions().get(0).getMessage().contains("[updated/failures]: 1/0"));
- }
-
- @Test
- public void issueSYNCOPE272() {
- removeTestUsers();
-
- // create user with testdb resource
- UserTO userTO = UserITCase.getUniqueSampleTO("syncope272@syncope.apache.org");
- userTO.getResources().add(RESOURCE_NAME_TESTDB);
-
- ProvisioningResult<UserTO> result = createUser(userTO);
- userTO = result.getEntity();
- try {
- assertNotNull(userTO);
- assertEquals(1, result.getPropagationStatuses().size());
- assertEquals(PropagationTaskExecStatus.SUCCESS, result.getPropagationStatuses().get(0).getStatus());
-
- ExecTO taskExecTO = execProvisioningTask(
- taskService, "986867e2-993b-430e-8feb-aa9abb4c1dcd", 50, false);
-
- assertNotNull(taskExecTO.getStatus());
- assertEquals(PropagationTaskExecStatus.SUCCESS, PropagationTaskExecStatus.valueOf(taskExecTO.getStatus()));
-
- userTO = userService.read(userTO.getKey());
- assertNotNull(userTO);
- assertNotNull(userTO.getPlainAttr("firstname").getValues().get(0));
- } finally {
- removeTestUsers();
- }
- }
-
- @Test
- public void issueSYNCOPE307() {
- UserTO userTO = UserITCase.getUniqueSampleTO("s307@apache.org");
- userTO.setUsername("test0");
- userTO.getPlainAttr("firstname").getValues().clear();
- userTO.getPlainAttr("firstname").getValues().add("nome0");
- userTO.getAuxClasses().add("csv");
-
- AttrTO csvuserid = new AttrTO();
- csvuserid.setSchema("csvuserid");
- userTO.getDerAttrs().add(csvuserid);
-
- userTO.getResources().clear();
- userTO.getResources().add(RESOURCE_NAME_WS2);
-
- userTO = createUser(userTO).getEntity();
- assertNotNull(userTO);
-
- userTO = userService.read(userTO.getKey());
- assertTrue(userTO.getVirAttrs().isEmpty());
-
- // Update pull task
- PullTaskTO task = taskService.read("38abbf9e-a1a3-40a1-a15f-7d0ac02f47f1", true);
- assertNotNull(task);
-
- UserTO template = new UserTO();
- template.setPassword("'password123'");
- template.getResources().add(RESOURCE_NAME_DBVIRATTR);
- template.getVirAttrs().add(attrTO("virtualdata", "'virtualvalue'"));
-
- task.getTemplates().put(AnyTypeKind.USER.name(), template);
-
- taskService.update(task);
-
- // exec task: one user from CSV will match the user created above and template will be applied
- execProvisioningTask(taskService, task.getKey(), 50, false);
-
- // check that template was successfully applied...
- userTO = userService.read(userTO.getKey());
- assertEquals("virtualvalue", userTO.getVirAttr("virtualdata").getValues().get(0));
-
- // ...and that propagation to db succeeded
- JdbcTemplate jdbcTemplate = new JdbcTemplate(testDataSource);
- String value = queryForObject(
- jdbcTemplate, 50, "SELECT USERNAME FROM testpull WHERE ID=?", String.class, userTO.getKey());
- assertEquals("virtualvalue", value);
- }
-
- @Test
- public void issueSYNCOPE313DB() throws Exception {
- // 1. create user in DB
- UserTO user = UserITCase.getUniqueSampleTO("syncope313-db@syncope.apache.org");
- user.setPassword("security123");
- user.getResources().add(RESOURCE_NAME_TESTDB);
- user = createUser(user).getEntity();
- assertNotNull(user);
- assertFalse(user.getResources().isEmpty());
-
- // 2. Check that the DB resource has the correct password
- JdbcTemplate jdbcTemplate = new JdbcTemplate(testDataSource);
- String value = queryForObject(
- jdbcTemplate, 50, "SELECT PASSWORD FROM test WHERE ID=?", String.class, user.getUsername());
- assertEquals(Encryptor.getInstance().encode("security123", CipherAlgorithm.SHA1), value.toUpperCase());
-
- // 3. Update the password in the DB
- String newCleanPassword = "new-security";
- String newPassword = Encryptor.getInstance().encode(newCleanPassword, CipherAlgorithm.SHA1);
- jdbcTemplate.execute("UPDATE test set PASSWORD='" + newPassword + "' where ID='" + user.getUsername() + "'");
-
- // 4. Pull the user from the resource
- PullTaskTO pullTask = new PullTaskTO();
- pullTask.setDestinationRealm(SyncopeConstants.ROOT_REALM);
- pullTask.setName("DB Pull Task");
- pullTask.setActive(true);
- pullTask.setPerformCreate(true);
- pullTask.setPerformUpdate(true);
- pullTask.setPullMode(PullMode.FULL_RECONCILIATION);
- pullTask.setResource(RESOURCE_NAME_TESTDB);
- pullTask.getActionsClassNames().add(DBPasswordPullActions.class.getName());
- Response taskResponse = taskService.create(pullTask);
-
- PullTaskTO actual = getObject(taskResponse.getLocation(), TaskService.class, PullTaskTO.class);
- assertNotNull(actual);
-
- pullTask = taskService.read(actual.getKey(), true);
- assertNotNull(pullTask);
- assertEquals(actual.getKey(), pullTask.getKey());
- assertEquals(actual.getJobDelegateClassName(), pullTask.getJobDelegateClassName());
-
- ExecTO execution = execProvisioningTask(taskService, pullTask.getKey(), 50, false);
- assertEquals(PropagationTaskExecStatus.SUCCESS, PropagationTaskExecStatus.valueOf(execution.getStatus()));
-
- // 5. Test the pulled user
- Pair<Map<String, Set<String>>, UserTO> self = clientFactory.create(user.getUsername(), newCleanPassword).self();
- assertNotNull(self);
-
- // 6. Delete PullTask + user
- taskService.delete(pullTask.getKey());
- deleteUser(user.getKey());
- }
-
- @Test
- public void issueSYNCOPE313LDAP() throws Exception {
- // First of all, clear any potential conflict with existing user / group
- ldapCleanup();
-
- UserTO user = null;
- PullTaskTO pullTask = null;
- ConnInstanceTO resourceConnector = null;
- ConnConfProperty property = null;
- try {
- // 1. create user in LDAP
- String oldCleanPassword = "security123";
- user = UserITCase.getUniqueSampleTO("syncope313-ldap@syncope.apache.org");
- user.setPassword(oldCleanPassword);
- user.getResources().add(RESOURCE_NAME_LDAP);
- user = createUser(user).getEntity();
- assertNotNull(user);
- assertFalse(user.getResources().isEmpty());
-
- // 2. request to change password only on Syncope and not on LDAP
- String newCleanPassword = "new-security123";
- UserPatch userPatch = new UserPatch();
- userPatch.setKey(user.getKey());
- userPatch.setPassword(new PasswordPatch.Builder().value(newCleanPassword).build());
- user = updateUser(userPatch).getEntity();
-
- // 3. Check that the Syncope user now has the changed password
- Pair<Map<String, Set<String>>, UserTO> self =
- clientFactory.create(user.getUsername(), newCleanPassword).self();
- assertNotNull(self);
-
- // 4. Check that the LDAP resource has the old password
- ConnObjectTO connObject =
- resourceService.readConnObject(RESOURCE_NAME_LDAP, AnyTypeKind.USER.name(), user.getKey());
- assertNotNull(getLdapRemoteObject(
- connObject.getAttr(Name.NAME).getValues().get(0),
- oldCleanPassword,
- connObject.getAttr(Name.NAME).getValues().get(0)));
-
- // 5. Update the LDAP Connector to retrieve passwords
- ResourceTO ldapResource = resourceService.read(RESOURCE_NAME_LDAP);
- resourceConnector = connectorService.read(
- ldapResource.getConnector(), Locale.ENGLISH.getLanguage());
- property = resourceConnector.getConfMap().get("retrievePasswordsWithSearch");
- property.getValues().clear();
- property.getValues().add(Boolean.TRUE);
- connectorService.update(resourceConnector);
-
- // 6. Pull the user from the resource
- pullTask = new PullTaskTO();
- pullTask.setDestinationRealm(SyncopeConstants.ROOT_REALM);
- pullTask.setName("LDAP Pull Task");
- pullTask.setActive(true);
- pullTask.setPerformCreate(true);
- pullTask.setPerformUpdate(true);
- pullTask.setPullMode(PullMode.FULL_RECONCILIATION);
- pullTask.setResource(RESOURCE_NAME_LDAP);
- pullTask.getActionsClassNames().add(LDAPPasswordPullActions.class.getName());
- Response taskResponse = taskService.create(pullTask);
-
- pullTask = getObject(taskResponse.getLocation(), TaskService.class, PullTaskTO.class);
- assertNotNull(pullTask);
-
- ExecTO execution = execProvisioningTask(taskService, pullTask.getKey(), 50, false);
- assertEquals(PropagationTaskExecStatus.SUCCESS, PropagationTaskExecStatus.valueOf(execution.getStatus()));
-
- // 7. Test the pulled user
- self = clientFactory.create(user.getUsername(), oldCleanPassword).self();
- assertNotNull(self);
- } catch (Exception e) {
- fail(e.getMessage());
- } finally {
- // Delete PullTask + user + reset the connector
- if (pullTask != null) {
- taskService.delete(pullTask.getKey());
- }
-
- if (resourceConnector != null && property != null) {
- property.getValues().clear();
- property.getValues().add(Boolean.FALSE);
- connectorService.update(resourceConnector);
- }
-
- if (user != null) {
- deleteUser(user.getKey());
- }
- }
- }
-
- @Test
- public void issueSYNCOPE1062() {
- GroupTO propagationGroup = null;
- PullTaskTO pullTask = null;
- UserTO user = null;
- GroupTO group = null;
- try {
- // 1. create group with resource for propagation
- propagationGroup = GroupITCase.getBasicSampleTO("SYNCOPE1062");
- propagationGroup.getResources().add(RESOURCE_NAME_DBPULL);
- propagationGroup = createGroup(propagationGroup).getEntity();
-
- // 2. create pull task for another resource, with user template assigning the group above
- pullTask = new PullTaskTO();
- pullTask.setDestinationRealm(SyncopeConstants.ROOT_REALM);
- pullTask.setName("SYNCOPE1062");
- pullTask.setActive(true);
- pullTask.setPerformCreate(true);
- pullTask.setPerformUpdate(true);
- pullTask.setPullMode(PullMode.FULL_RECONCILIATION);
- pullTask.setResource(RESOURCE_NAME_LDAP);
-
- UserTO template = new UserTO();
- template.getAuxClasses().add("minimal group");
- template.getMemberships().add(new MembershipTO.Builder().group(propagationGroup.getKey()).build());
- template.getPlainAttrs().add(attrTO("firstname", "'fixed'"));
- pullTask.getTemplates().put(AnyTypeKind.USER.name(), template);
-
- Response taskResponse = taskService.create(pullTask);
- pullTask = getObject(taskResponse.getLocation(), TaskService.class, PullTaskTO.class);
- assertNotNull(pullTask);
- assertFalse(pullTask.getTemplates().isEmpty());
-
- // 3. exec the pull task
- ExecTO execution = execProvisioningTask(taskService, pullTask.getKey(), 50, false);
- assertEquals(PropagationTaskExecStatus.SUCCESS, PropagationTaskExecStatus.valueOf(execution.getStatus()));
-
- // the user is successfully pulled...
- user = userService.read("pullFromLDAP");
- assertNotNull(user);
- assertEquals("pullFromLDAP@syncope.apache.org", user.getPlainAttr("email").getValues().get(0));
-
- group = groupService.read("testLDAPGroup");
- assertNotNull(group);
-
- ConnObjectTO connObject =
- resourceService.readConnObject(RESOURCE_NAME_LDAP, AnyTypeKind.USER.name(), user.getKey());
- assertNotNull(connObject);
- assertEquals("pullFromLDAP@syncope.apache.org", connObject.getAttr("mail").getValues().get(0));
- AttrTO userDn = connObject.getAttr(Name.NAME);
- assertNotNull(userDn);
- assertEquals(1, userDn.getValues().size());
- assertNotNull(
- getLdapRemoteObject(RESOURCE_LDAP_ADMIN_DN, RESOURCE_LDAP_ADMIN_PWD, userDn.getValues().get(0)));
-
- // ...and propagated
- PagedResult<AbstractTaskTO> propagationTasks = taskService.list(new TaskQuery.Builder(TaskType.PROPAGATION).
- resource(RESOURCE_NAME_DBPULL).
- anyTypeKind(AnyTypeKind.USER).entityKey(user.getKey()).build());
- assertEquals(1, propagationTasks.getSize());
-
- // 4. update the user on the external resource
- updateLdapRemoteObject(RESOURCE_LDAP_ADMIN_DN, RESOURCE_LDAP_ADMIN_PWD,
- userDn.getValues().get(0), Pair.of("mail", "pullFromLDAP2@syncope.apache.org"));
-
- connObject = resourceService.readConnObject(RESOURCE_NAME_LDAP, AnyTypeKind.USER.name(), user.getKey());
- assertNotNull(connObject);
- assertEquals("pullFromLDAP2@syncope.apache.org", connObject.getAttr("mail").getValues().get(0));
-
- // 5. exec the pull task again
- execution = execProvisioningTask(taskService, pullTask.getKey(), 50, false);
- assertEquals(PropagationTaskExecStatus.SUCCESS, PropagationTaskExecStatus.valueOf(execution.getStatus()));
-
- // the internal is updated...
- user = userService.read("pullFromLDAP");
- assertNotNull(user);
- assertEquals("pullFromLDAP2@syncope.apache.org", user.getPlainAttr("email").getValues().get(0));
-
- // ...and propagated
- propagationTasks = taskService.list(new TaskQuery.Builder(TaskType.PROPAGATION).
- resource(RESOURCE_NAME_DBPULL).
- anyTypeKind(AnyTypeKind.USER).entityKey(user.getKey()).build());
- assertEquals(2, propagationTasks.getSize());
- } catch (Exception e) {
- LOG.error("Unexpected during issueSYNCOPE1062()", e);
- fail(e.getMessage());
- } finally {
- if (pullTask != null) {
- taskService.delete(pullTask.getKey());
- }
-
- if (propagationGroup != null) {
- groupService.delete(propagationGroup.getKey());
- }
-
- if (group != null) {
- groupService.delete(group.getKey());
- }
- if (user != null) {
- userService.delete(user.getKey());
- }
- }
- }
}
http://git-wip-us.apache.org/repos/asf/syncope/blob/59d6d4a3/fit/core-reference/src/test/java/org/apache/syncope/fit/core/PullTaskIssuesITCase.java
----------------------------------------------------------------------
diff --git a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/PullTaskIssuesITCase.java b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/PullTaskIssuesITCase.java
new file mode 100644
index 0000000..59110f6
--- /dev/null
+++ b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/PullTaskIssuesITCase.java
@@ -0,0 +1,550 @@
+/*
+ * 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.fit.core;
+
+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 static org.junit.Assert.fail;
+
+import java.util.Locale;
+import java.util.Map;
+import java.util.Set;
+import javax.sql.DataSource;
+import javax.ws.rs.core.Response;
+import org.apache.commons.lang3.tuple.Pair;
+import org.apache.syncope.common.lib.SyncopeConstants;
+import org.apache.syncope.common.lib.patch.PasswordPatch;
+import org.apache.syncope.common.lib.patch.UserPatch;
+import org.apache.syncope.common.lib.to.AbstractTaskTO;
+import org.apache.syncope.common.lib.to.AttrTO;
+import org.apache.syncope.common.lib.to.ConnInstanceTO;
+import org.apache.syncope.common.lib.to.ConnObjectTO;
+import org.apache.syncope.common.lib.to.MembershipTO;
+import org.apache.syncope.common.lib.to.PagedResult;
+import org.apache.syncope.common.lib.to.ResourceTO;
+import org.apache.syncope.common.lib.to.GroupTO;
+import org.apache.syncope.common.lib.policy.PullPolicyTO;
+import org.apache.syncope.common.lib.to.ProvisioningResult;
+import org.apache.syncope.common.lib.to.PullTaskTO;
+import org.apache.syncope.common.lib.to.ExecTO;
+import org.apache.syncope.common.lib.to.UserTO;
+import org.apache.syncope.common.lib.types.AnyTypeKind;
+import org.apache.syncope.common.lib.types.CipherAlgorithm;
+import org.apache.syncope.common.lib.types.ConnConfProperty;
+import org.apache.syncope.common.lib.types.PropagationTaskExecStatus;
+import org.apache.syncope.common.lib.types.PullMode;
+import org.apache.syncope.common.lib.types.TaskType;
+import org.apache.syncope.common.rest.api.beans.TaskQuery;
+import org.apache.syncope.common.rest.api.service.TaskService;
+import org.apache.syncope.core.spring.security.Encryptor;
+import org.apache.syncope.core.provisioning.java.pushpull.DBPasswordPullActions;
+import org.apache.syncope.core.provisioning.java.pushpull.LDAPPasswordPullActions;
+import org.apache.syncope.fit.core.reference.TestPullRule;
+import org.identityconnectors.framework.common.objects.Name;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration(locations = { "classpath:testJDBCEnv.xml" })
+public class PullTaskIssuesITCase extends AbstractTaskITCase {
+
+ @Autowired
+ private DataSource testDataSource;
+
+ @Test
+ public void issueSYNCOPE68() {
+ //-----------------------------
+ // Create a new user ... it should be updated applying pull policy
+ //-----------------------------
+ UserTO userTO = new UserTO();
+ userTO.setRealm(SyncopeConstants.ROOT_REALM);
+ userTO.setPassword("password123");
+ userTO.setUsername("testuser2");
+
+ userTO.getPlainAttrs().add(attrTO("firstname", "testuser2"));
+ userTO.getPlainAttrs().add(attrTO("surname", "testuser2"));
+ userTO.getPlainAttrs().add(attrTO("ctype", "a type"));
+ userTO.getPlainAttrs().add(attrTO("fullname", "a type"));
+ userTO.getPlainAttrs().add(attrTO("userId", "testuser2@syncope.apache.org"));
+ userTO.getPlainAttrs().add(attrTO("email", "testuser2@syncope.apache.org"));
+
+ userTO.getResources().add(RESOURCE_NAME_NOPROPAGATION2);
+ userTO.getResources().add(RESOURCE_NAME_NOPROPAGATION4);
+
+ userTO.getMemberships().add(
+ new MembershipTO.Builder().group("bf825fe1-7320-4a54-bd64-143b5c18ab97").build());
+
+ userTO = createUser(userTO).getEntity();
+ assertNotNull(userTO);
+ assertEquals("testuser2", userTO.getUsername());
+ assertEquals(1, userTO.getMemberships().size());
+ assertEquals(3, userTO.getResources().size());
+ //-----------------------------
+
+ try {
+ //-----------------------------
+ // add user template
+ //-----------------------------
+ UserTO template = new UserTO();
+
+ template.getMemberships().add(
+ new MembershipTO.Builder().group("b8d38784-57e7-4595-859a-076222644b55").build());
+
+ template.getResources().add(RESOURCE_NAME_NOPROPAGATION4);
+ //-----------------------------
+
+ // Update pull task
+ PullTaskTO task = taskService.read("81d88f73-d474-4450-9031-605daa4e313f", true);
+ assertNotNull(task);
+
+ task.getTemplates().put(AnyTypeKind.USER.name(), template);
+
+ taskService.update(task);
+ PullTaskTO actual = taskService.read(task.getKey(), true);
+ assertNotNull(actual);
+ assertEquals(task.getKey(), actual.getKey());
+ assertFalse(actual.getTemplates().get(AnyTypeKind.USER.name()).getResources().isEmpty());
+ assertFalse(((UserTO) actual.getTemplates().get(AnyTypeKind.USER.name())).getMemberships().isEmpty());
+
+ ExecTO execution = execProvisioningTask(taskService, actual.getKey(), 50, false);
+ assertEquals(PropagationTaskExecStatus.SUCCESS, PropagationTaskExecStatus.valueOf(execution.getStatus()));
+
+ userTO = userService.read("testuser2");
+ assertNotNull(userTO);
+ assertEquals("testuser2@syncope.apache.org", userTO.getPlainAttr("userId").getValues().get(0));
+ assertEquals(2, userTO.getMemberships().size());
+ assertEquals(4, userTO.getResources().size());
+ } finally {
+ UserTO dUserTO = deleteUser(userTO.getKey()).getEntity();
+ assertNotNull(dUserTO);
+ }
+ }
+
+ @Test
+ public void issueSYNCOPE230() {
+ JdbcTemplate jdbcTemplate = new JdbcTemplate(testDataSource);
+
+ // 1. populate the external table
+ jdbcTemplate.execute("INSERT INTO testpull VALUES"
+ + "('a54b3794-b231-47be-b24a-11e1a42949f6', 'issuesyncope230', 'Surname', 'syncope230@syncope.apache.org', NULL)");
+
+ // 2. execute PullTask for resource-db-pull (table TESTPULL on external H2)
+ execProvisioningTask(taskService, "7c2242f4-14af-4ab5-af31-cdae23783655", 50, false);
+
+ // 3. read e-mail address for user created by the PullTask first execution
+ UserTO userTO = userService.read("issuesyncope230");
+ assertNotNull(userTO);
+ String email = userTO.getPlainAttr("email").getValues().iterator().next();
+ assertNotNull(email);
+
+ // 4. update TESTPULL on external H2 by changing e-mail address
+ jdbcTemplate.execute("UPDATE TESTPULL SET email='updatedSYNCOPE230@syncope.apache.org'");
+
+ // 5. re-execute the PullTask
+ execProvisioningTask(taskService, "7c2242f4-14af-4ab5-af31-cdae23783655", 50, false);
+
+ // 6. verify that the e-mail was updated
+ userTO = userService.read("issuesyncope230");
+ assertNotNull(userTO);
+ email = userTO.getPlainAttr("email").getValues().iterator().next();
+ assertNotNull(email);
+ assertEquals("updatedSYNCOPE230@syncope.apache.org", email);
+ }
+
+ @Test
+ public void issueSYNCOPE258() {
+ // -----------------------------
+ // Add a custom correlation rule
+ // -----------------------------
+ PullPolicyTO policyTO = policyService.read("9454b0d7-2610-400a-be82-fc23cf553dd6");
+ policyTO.getSpecification().getCorrelationRules().put(AnyTypeKind.USER.name(), TestPullRule.class.getName());
+ policyService.update(policyTO);
+ // -----------------------------
+
+ PullTaskTO task = new PullTaskTO();
+ task.setDestinationRealm(SyncopeConstants.ROOT_REALM);
+ task.setName("Test Pull Rule");
+ task.setActive(true);
+ task.setResource(RESOURCE_NAME_WS2);
+ task.setPullMode(PullMode.FULL_RECONCILIATION);
+ task.setPerformCreate(true);
+ task.setPerformDelete(true);
+ task.setPerformUpdate(true);
+
+ Response response = taskService.create(task);
+ task = getObject(response.getLocation(), TaskService.class, PullTaskTO.class);
+
+ UserTO userTO = UserITCase.getUniqueSampleTO("s258_1@apache.org");
+ userTO.getResources().clear();
+ userTO.getResources().add(RESOURCE_NAME_WS2);
+
+ createUser(userTO);
+
+ userTO = UserITCase.getUniqueSampleTO("s258_2@apache.org");
+ userTO.getResources().clear();
+ userTO.getResources().add(RESOURCE_NAME_WS2);
+
+ userTO = createUser(userTO).getEntity();
+
+ // change email in order to unmatch the second user
+ UserPatch userPatch = new UserPatch();
+ userPatch.setKey(userTO.getKey());
+ userPatch.getPlainAttrs().add(attrAddReplacePatch("email", "s258@apache.org"));
+
+ userService.update(userPatch);
+
+ execProvisioningTask(taskService, task.getKey(), 50, false);
+
+ PullTaskTO executed = taskService.read(task.getKey(), true);
+ assertEquals(1, executed.getExecutions().size());
+
+ // asser for just one match
+ assertTrue(executed.getExecutions().get(0).getMessage().substring(0, 55) + "...",
+ executed.getExecutions().get(0).getMessage().contains("[updated/failures]: 1/0"));
+ }
+
+ @Test
+ public void issueSYNCOPE272() {
+ removeTestUsers();
+
+ // create user with testdb resource
+ UserTO userTO = UserITCase.getUniqueSampleTO("syncope272@syncope.apache.org");
+ userTO.getResources().add(RESOURCE_NAME_TESTDB);
+
+ ProvisioningResult<UserTO> result = createUser(userTO);
+ userTO = result.getEntity();
+ try {
+ assertNotNull(userTO);
+ assertEquals(1, result.getPropagationStatuses().size());
+ assertEquals(PropagationTaskExecStatus.SUCCESS, result.getPropagationStatuses().get(0).getStatus());
+
+ ExecTO taskExecTO = execProvisioningTask(
+ taskService, "986867e2-993b-430e-8feb-aa9abb4c1dcd", 50, false);
+
+ assertNotNull(taskExecTO.getStatus());
+ assertEquals(PropagationTaskExecStatus.SUCCESS, PropagationTaskExecStatus.valueOf(taskExecTO.getStatus()));
+
+ userTO = userService.read(userTO.getKey());
+ assertNotNull(userTO);
+ assertNotNull(userTO.getPlainAttr("firstname").getValues().get(0));
+ } finally {
+ removeTestUsers();
+ }
+ }
+
+ @Test
+ public void issueSYNCOPE307() {
+ UserTO userTO = UserITCase.getUniqueSampleTO("s307@apache.org");
+ userTO.setUsername("test0");
+ userTO.getPlainAttr("firstname").getValues().clear();
+ userTO.getPlainAttr("firstname").getValues().add("nome0");
+ userTO.getAuxClasses().add("csv");
+
+ AttrTO csvuserid = new AttrTO();
+ csvuserid.setSchema("csvuserid");
+ userTO.getDerAttrs().add(csvuserid);
+
+ userTO.getResources().clear();
+ userTO.getResources().add(RESOURCE_NAME_WS2);
+
+ userTO = createUser(userTO).getEntity();
+ assertNotNull(userTO);
+
+ userTO = userService.read(userTO.getKey());
+ assertTrue(userTO.getVirAttrs().isEmpty());
+
+ // Update pull task
+ PullTaskTO task = taskService.read("38abbf9e-a1a3-40a1-a15f-7d0ac02f47f1", true);
+ assertNotNull(task);
+
+ UserTO template = new UserTO();
+ template.setPassword("'password123'");
+ template.getResources().add(RESOURCE_NAME_DBVIRATTR);
+ template.getVirAttrs().add(attrTO("virtualdata", "'virtualvalue'"));
+
+ task.getTemplates().put(AnyTypeKind.USER.name(), template);
+
+ taskService.update(task);
+
+ // exec task: one user from CSV will match the user created above and template will be applied
+ execProvisioningTask(taskService, task.getKey(), 50, false);
+
+ // check that template was successfully applied...
+ userTO = userService.read(userTO.getKey());
+ assertEquals("virtualvalue", userTO.getVirAttr("virtualdata").getValues().get(0));
+
+ // ...and that propagation to db succeeded
+ JdbcTemplate jdbcTemplate = new JdbcTemplate(testDataSource);
+ String value = queryForObject(
+ jdbcTemplate, 50, "SELECT USERNAME FROM testpull WHERE ID=?", String.class, userTO.getKey());
+ assertEquals("virtualvalue", value);
+ }
+
+ @Test
+ public void issueSYNCOPE313DB() throws Exception {
+ // 1. create user in DB
+ UserTO user = UserITCase.getUniqueSampleTO("syncope313-db@syncope.apache.org");
+ user.setPassword("security123");
+ user.getResources().add(RESOURCE_NAME_TESTDB);
+ user = createUser(user).getEntity();
+ assertNotNull(user);
+ assertFalse(user.getResources().isEmpty());
+
+ // 2. Check that the DB resource has the correct password
+ JdbcTemplate jdbcTemplate = new JdbcTemplate(testDataSource);
+ String value = queryForObject(
+ jdbcTemplate, 50, "SELECT PASSWORD FROM test WHERE ID=?", String.class, user.getUsername());
+ assertEquals(Encryptor.getInstance().encode("security123", CipherAlgorithm.SHA1), value.toUpperCase());
+
+ // 3. Update the password in the DB
+ String newCleanPassword = "new-security";
+ String newPassword = Encryptor.getInstance().encode(newCleanPassword, CipherAlgorithm.SHA1);
+ jdbcTemplate.execute("UPDATE test set PASSWORD='" + newPassword + "' where ID='" + user.getUsername() + "'");
+
+ // 4. Pull the user from the resource
+ PullTaskTO pullTask = new PullTaskTO();
+ pullTask.setDestinationRealm(SyncopeConstants.ROOT_REALM);
+ pullTask.setName("DB Pull Task");
+ pullTask.setActive(true);
+ pullTask.setPerformCreate(true);
+ pullTask.setPerformUpdate(true);
+ pullTask.setPullMode(PullMode.FULL_RECONCILIATION);
+ pullTask.setResource(RESOURCE_NAME_TESTDB);
+ pullTask.getActionsClassNames().add(DBPasswordPullActions.class.getName());
+ Response taskResponse = taskService.create(pullTask);
+
+ PullTaskTO actual = getObject(taskResponse.getLocation(), TaskService.class, PullTaskTO.class);
+ assertNotNull(actual);
+
+ pullTask = taskService.read(actual.getKey(), true);
+ assertNotNull(pullTask);
+ assertEquals(actual.getKey(), pullTask.getKey());
+ assertEquals(actual.getJobDelegateClassName(), pullTask.getJobDelegateClassName());
+
+ ExecTO execution = execProvisioningTask(taskService, pullTask.getKey(), 50, false);
+ assertEquals(PropagationTaskExecStatus.SUCCESS, PropagationTaskExecStatus.valueOf(execution.getStatus()));
+
+ // 5. Test the pulled user
+ Pair<Map<String, Set<String>>, UserTO> self = clientFactory.create(user.getUsername(), newCleanPassword).self();
+ assertNotNull(self);
+
+ // 6. Delete PullTask + user
+ taskService.delete(pullTask.getKey());
+ deleteUser(user.getKey());
+ }
+
+ @Test
+ public void issueSYNCOPE313LDAP() throws Exception {
+ // First of all, clear any potential conflict with existing user / group
+ ldapCleanup();
+
+ UserTO user = null;
+ PullTaskTO pullTask = null;
+ ConnInstanceTO resourceConnector = null;
+ ConnConfProperty property = null;
+ try {
+ // 1. create user in LDAP
+ String oldCleanPassword = "security123";
+ user = UserITCase.getUniqueSampleTO("syncope313-ldap@syncope.apache.org");
+ user.setPassword(oldCleanPassword);
+ user.getResources().add(RESOURCE_NAME_LDAP);
+ user = createUser(user).getEntity();
+ assertNotNull(user);
+ assertFalse(user.getResources().isEmpty());
+
+ // 2. request to change password only on Syncope and not on LDAP
+ String newCleanPassword = "new-security123";
+ UserPatch userPatch = new UserPatch();
+ userPatch.setKey(user.getKey());
+ userPatch.setPassword(new PasswordPatch.Builder().value(newCleanPassword).build());
+ user = updateUser(userPatch).getEntity();
+
+ // 3. Check that the Syncope user now has the changed password
+ Pair<Map<String, Set<String>>, UserTO> self =
+ clientFactory.create(user.getUsername(), newCleanPassword).self();
+ assertNotNull(self);
+
+ // 4. Check that the LDAP resource has the old password
+ ConnObjectTO connObject =
+ resourceService.readConnObject(RESOURCE_NAME_LDAP, AnyTypeKind.USER.name(), user.getKey());
+ assertNotNull(getLdapRemoteObject(
+ connObject.getAttr(Name.NAME).getValues().get(0),
+ oldCleanPassword,
+ connObject.getAttr(Name.NAME).getValues().get(0)));
+
+ // 5. Update the LDAP Connector to retrieve passwords
+ ResourceTO ldapResource = resourceService.read(RESOURCE_NAME_LDAP);
+ resourceConnector = connectorService.read(
+ ldapResource.getConnector(), Locale.ENGLISH.getLanguage());
+ property = resourceConnector.getConfMap().get("retrievePasswordsWithSearch");
+ property.getValues().clear();
+ property.getValues().add(Boolean.TRUE);
+ connectorService.update(resourceConnector);
+
+ // 6. Pull the user from the resource
+ pullTask = new PullTaskTO();
+ pullTask.setDestinationRealm(SyncopeConstants.ROOT_REALM);
+ pullTask.setName("LDAP Pull Task");
+ pullTask.setActive(true);
+ pullTask.setPerformCreate(true);
+ pullTask.setPerformUpdate(true);
+ pullTask.setPullMode(PullMode.FULL_RECONCILIATION);
+ pullTask.setResource(RESOURCE_NAME_LDAP);
+ pullTask.getActionsClassNames().add(LDAPPasswordPullActions.class.getName());
+ Response taskResponse = taskService.create(pullTask);
+
+ pullTask = getObject(taskResponse.getLocation(), TaskService.class, PullTaskTO.class);
+ assertNotNull(pullTask);
+
+ ExecTO execution = execProvisioningTask(taskService, pullTask.getKey(), 50, false);
+ assertEquals(PropagationTaskExecStatus.SUCCESS, PropagationTaskExecStatus.valueOf(execution.getStatus()));
+
+ // 7. Test the pulled user
+ self = clientFactory.create(user.getUsername(), oldCleanPassword).self();
+ assertNotNull(self);
+ } catch (Exception e) {
+ fail(e.getMessage());
+ } finally {
+ // Delete PullTask + user + reset the connector
+ if (pullTask != null) {
+ taskService.delete(pullTask.getKey());
+ }
+
+ if (resourceConnector != null && property != null) {
+ property.getValues().clear();
+ property.getValues().add(Boolean.FALSE);
+ connectorService.update(resourceConnector);
+ }
+
+ if (user != null) {
+ deleteUser(user.getKey());
+ }
+ }
+ }
+
+ @Test
+ public void issueSYNCOPE1062() {
+ GroupTO propagationGroup = null;
+ PullTaskTO pullTask = null;
+ UserTO user = null;
+ GroupTO group = null;
+ try {
+ // 1. create group with resource for propagation
+ propagationGroup = GroupITCase.getBasicSampleTO("SYNCOPE1062");
+ propagationGroup.getResources().add(RESOURCE_NAME_DBPULL);
+ propagationGroup = createGroup(propagationGroup).getEntity();
+
+ // 2. create pull task for another resource, with user template assigning the group above
+ pullTask = new PullTaskTO();
+ pullTask.setDestinationRealm(SyncopeConstants.ROOT_REALM);
+ pullTask.setName("SYNCOPE1062");
+ pullTask.setActive(true);
+ pullTask.setPerformCreate(true);
+ pullTask.setPerformUpdate(true);
+ pullTask.setPullMode(PullMode.FULL_RECONCILIATION);
+ pullTask.setResource(RESOURCE_NAME_LDAP);
+
+ UserTO template = new UserTO();
+ template.getAuxClasses().add("minimal group");
+ template.getMemberships().add(new MembershipTO.Builder().group(propagationGroup.getKey()).build());
+ template.getPlainAttrs().add(attrTO("firstname", "'fixed'"));
+ pullTask.getTemplates().put(AnyTypeKind.USER.name(), template);
+
+ Response taskResponse = taskService.create(pullTask);
+ pullTask = getObject(taskResponse.getLocation(), TaskService.class, PullTaskTO.class);
+ assertNotNull(pullTask);
+ assertFalse(pullTask.getTemplates().isEmpty());
+
+ // 3. exec the pull task
+ ExecTO execution = execProvisioningTask(taskService, pullTask.getKey(), 50, false);
+ assertEquals(PropagationTaskExecStatus.SUCCESS, PropagationTaskExecStatus.valueOf(execution.getStatus()));
+
+ // the user is successfully pulled...
+ user = userService.read("pullFromLDAP");
+ assertNotNull(user);
+ assertEquals("pullFromLDAP@syncope.apache.org", user.getPlainAttr("email").getValues().get(0));
+
+ group = groupService.read("testLDAPGroup");
+ assertNotNull(group);
+
+ ConnObjectTO connObject =
+ resourceService.readConnObject(RESOURCE_NAME_LDAP, AnyTypeKind.USER.name(), user.getKey());
+ assertNotNull(connObject);
+ assertEquals("pullFromLDAP@syncope.apache.org", connObject.getAttr("mail").getValues().get(0));
+ AttrTO userDn = connObject.getAttr(Name.NAME);
+ assertNotNull(userDn);
+ assertEquals(1, userDn.getValues().size());
+ assertNotNull(
+ getLdapRemoteObject(RESOURCE_LDAP_ADMIN_DN, RESOURCE_LDAP_ADMIN_PWD, userDn.getValues().get(0)));
+
+ // ...and propagated
+ PagedResult<AbstractTaskTO> propagationTasks = taskService.list(new TaskQuery.Builder(TaskType.PROPAGATION).
+ resource(RESOURCE_NAME_DBPULL).
+ anyTypeKind(AnyTypeKind.USER).entityKey(user.getKey()).build());
+ assertEquals(1, propagationTasks.getSize());
+
+ // 4. update the user on the external resource
+ updateLdapRemoteObject(RESOURCE_LDAP_ADMIN_DN, RESOURCE_LDAP_ADMIN_PWD,
+ userDn.getValues().get(0), Pair.of("mail", "pullFromLDAP2@syncope.apache.org"));
+
+ connObject = resourceService.readConnObject(RESOURCE_NAME_LDAP, AnyTypeKind.USER.name(), user.getKey());
+ assertNotNull(connObject);
+ assertEquals("pullFromLDAP2@syncope.apache.org", connObject.getAttr("mail").getValues().get(0));
+
+ // 5. exec the pull task again
+ execution = execProvisioningTask(taskService, pullTask.getKey(), 50, false);
+ assertEquals(PropagationTaskExecStatus.SUCCESS, PropagationTaskExecStatus.valueOf(execution.getStatus()));
+
+ // the internal is updated...
+ user = userService.read("pullFromLDAP");
+ assertNotNull(user);
+ assertEquals("pullFromLDAP2@syncope.apache.org", user.getPlainAttr("email").getValues().get(0));
+
+ // ...and propagated
+ propagationTasks = taskService.list(new TaskQuery.Builder(TaskType.PROPAGATION).
+ resource(RESOURCE_NAME_DBPULL).
+ anyTypeKind(AnyTypeKind.USER).entityKey(user.getKey()).build());
+ assertEquals(2, propagationTasks.getSize());
+ } catch (Exception e) {
+ LOG.error("Unexpected during issueSYNCOPE1062()", e);
+ fail(e.getMessage());
+ } finally {
+ if (pullTask != null) {
+ taskService.delete(pullTask.getKey());
+ }
+
+ if (propagationGroup != null) {
+ groupService.delete(propagationGroup.getKey());
+ }
+
+ if (group != null) {
+ groupService.delete(group.getKey());
+ }
+ if (user != null) {
+ userService.delete(user.getKey());
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/syncope/blob/59d6d4a3/fit/core-reference/src/test/java/org/apache/syncope/fit/core/ReportITCase.java
----------------------------------------------------------------------
diff --git a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/ReportITCase.java b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/ReportITCase.java
index 1851e6d..abd746c 100644
--- a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/ReportITCase.java
+++ b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/ReportITCase.java
@@ -49,18 +49,11 @@ import org.apache.syncope.common.lib.types.ReportExecExportFormat;
import org.apache.syncope.common.lib.types.ReportExecStatus;
import org.apache.syncope.common.rest.api.beans.BulkExecDeleteQuery;
import org.apache.syncope.common.rest.api.beans.ExecuteQuery;
-import org.apache.syncope.common.rest.api.service.ReportService;
import org.apache.syncope.fit.AbstractITCase;
import org.junit.Test;
public class ReportITCase extends AbstractITCase {
- private ReportTO createReport(final ReportTO report) {
- Response response = reportService.create(report);
- assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatusInfo().getStatusCode());
- return getObject(response.getLocation(), ReportService.class, ReportTO.class);
- }
-
@Test
public void getReportletConfs() {
Set<String> reportletConfs = syncopeService.platform().getReportletConfs();
@@ -282,61 +275,4 @@ public class ReportITCase extends AbstractITCase {
loggerService.delete(LoggerType.AUDIT, auditLoggerName.toLoggerName());
}
}
-
- @Test
- public void issueSYNCOPE43() {
- ReportTO reportTO = new ReportTO();
- reportTO.setName("issueSYNCOPE43" + getUUIDString());
- reportTO.setActive(true);
- reportTO.setTemplate("sample");
- reportTO = createReport(reportTO);
- assertNotNull(reportTO);
-
- ExecTO execution = reportService.execute(new ExecuteQuery.Builder().key(reportTO.getKey()).build());
- assertNotNull(execution);
-
- int maxit = 50;
- do {
- try {
- Thread.sleep(1000);
- } catch (InterruptedException e) {
- }
-
- reportTO = reportService.read(reportTO.getKey());
-
- maxit--;
- } while (reportTO.getExecutions().isEmpty() && maxit > 0);
-
- assertEquals(1, reportTO.getExecutions().size());
- }
-
- @Test
- public void issueSYNCOPE102() throws IOException {
- // Create
- ReportTO reportTO = reportService.read("0062ea9c-924d-4ecf-9961-4492a8cc6d1b");
- reportTO.setKey(null);
- reportTO.setName("issueSYNCOPE102" + getUUIDString());
- reportTO = createReport(reportTO);
- assertNotNull(reportTO);
-
- // Execute (multiple requests)
- for (int i = 0; i < 10; i++) {
- ExecTO execution = reportService.execute(new ExecuteQuery.Builder().key(reportTO.getKey()).build());
- assertNotNull(execution);
- }
-
- // Wait for one execution
- int maxit = 50;
- do {
- try {
- Thread.sleep(1000);
- } catch (InterruptedException e) {
- }
-
- reportTO = reportService.read(reportTO.getKey());
-
- maxit--;
- } while (reportTO.getExecutions().isEmpty() && maxit > 0);
- assertFalse(reportTO.getExecutions().isEmpty());
- }
}
http://git-wip-us.apache.org/repos/asf/syncope/blob/59d6d4a3/fit/core-reference/src/test/java/org/apache/syncope/fit/core/ReportIssuesITCase.java
----------------------------------------------------------------------
diff --git a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/ReportIssuesITCase.java b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/ReportIssuesITCase.java
new file mode 100644
index 0000000..fb0d845
--- /dev/null
+++ b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/ReportIssuesITCase.java
@@ -0,0 +1,90 @@
+/*
+ * 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.fit.core;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+
+import java.io.IOException;
+import org.apache.syncope.common.lib.to.ExecTO;
+import org.apache.syncope.common.lib.to.ReportTO;
+import org.apache.syncope.common.rest.api.beans.ExecuteQuery;
+import org.apache.syncope.fit.AbstractITCase;
+import org.junit.Test;
+
+public class ReportIssuesITCase extends AbstractITCase {
+
+ @Test
+ public void issueSYNCOPE43() {
+ ReportTO reportTO = new ReportTO();
+ reportTO.setName("issueSYNCOPE43" + getUUIDString());
+ reportTO.setActive(true);
+ reportTO.setTemplate("sample");
+ reportTO = createReport(reportTO);
+ assertNotNull(reportTO);
+
+ ExecTO execution = reportService.execute(new ExecuteQuery.Builder().key(reportTO.getKey()).build());
+ assertNotNull(execution);
+
+ int maxit = 50;
+ do {
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException e) {
+ }
+
+ reportTO = reportService.read(reportTO.getKey());
+
+ maxit--;
+ } while (reportTO.getExecutions().isEmpty() && maxit > 0);
+
+ assertEquals(1, reportTO.getExecutions().size());
+ }
+
+ @Test
+ public void issueSYNCOPE102() throws IOException {
+ // Create
+ ReportTO reportTO = reportService.read("0062ea9c-924d-4ecf-9961-4492a8cc6d1b");
+ reportTO.setKey(null);
+ reportTO.setName("issueSYNCOPE102" + getUUIDString());
+ reportTO = createReport(reportTO);
+ assertNotNull(reportTO);
+
+ // Execute (multiple requests)
+ for (int i = 0; i < 10; i++) {
+ ExecTO execution = reportService.execute(new ExecuteQuery.Builder().key(reportTO.getKey()).build());
+ assertNotNull(execution);
+ }
+
+ // Wait for one execution
+ int maxit = 50;
+ do {
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException e) {
+ }
+
+ reportTO = reportService.read(reportTO.getKey());
+
+ maxit--;
+ } while (reportTO.getExecutions().isEmpty() && maxit > 0);
+ assertFalse(reportTO.getExecutions().isEmpty());
+ }
+}
[4/4] syncope git commit: Reduce number of integration test cases
executed by default build, moving time-consuming to full-it profile
Posted by il...@apache.org.
Reduce number of integration test cases executed by default build, moving time-consuming to full-it profile
Project: http://git-wip-us.apache.org/repos/asf/syncope/repo
Commit: http://git-wip-us.apache.org/repos/asf/syncope/commit/59d6d4a3
Tree: http://git-wip-us.apache.org/repos/asf/syncope/tree/59d6d4a3
Diff: http://git-wip-us.apache.org/repos/asf/syncope/diff/59d6d4a3
Branch: refs/heads/master
Commit: 59d6d4a37b93757397f8e16da4bc2e7aa4fe3066
Parents: 71e676b
Author: Francesco Chicchiriccò <il...@apache.org>
Authored: Mon Jun 19 16:19:14 2017 +0200
Committer: Francesco Chicchiriccò <il...@apache.org>
Committed: Mon Jun 19 16:20:30 2017 +0200
----------------------------------------------------------------------
fit/core-reference/pom.xml | 3 +
.../org/apache/syncope/fit/AbstractITCase.java | 61 +-
.../core/AbstractNotificationTaskITCase.java | 107 ++++
.../syncope/fit/core/AbstractTaskITCase.java | 41 ++
.../apache/syncope/fit/core/GroupITCase.java | 195 -------
.../syncope/fit/core/GroupIssuesITCase.java | 235 ++++++++
.../fit/core/NotificationTaskITCase.java | 309 +---------
.../fit/core/NotificationTaskIssuesITCase.java | 207 +++++++
.../apache/syncope/fit/core/PullTaskITCase.java | 558 -------------------
.../syncope/fit/core/PullTaskIssuesITCase.java | 550 ++++++++++++++++++
.../apache/syncope/fit/core/ReportITCase.java | 64 ---
.../syncope/fit/core/ReportIssuesITCase.java | 90 +++
12 files changed, 1294 insertions(+), 1126 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/syncope/blob/59d6d4a3/fit/core-reference/pom.xml
----------------------------------------------------------------------
diff --git a/fit/core-reference/pom.xml b/fit/core-reference/pom.xml
index 7d395d7..df2aa32 100644
--- a/fit/core-reference/pom.xml
+++ b/fit/core-reference/pom.xml
@@ -230,6 +230,9 @@ under the License.
<includes>
<include>**/org/apache/syncope/fit/core/*ITCase.java</include>
</includes>
+ <excludes>
+ <exclude>**/*IssuesITCase.java</exclude>
+ </excludes>
</configuration>
<executions>
<execution>
http://git-wip-us.apache.org/repos/asf/syncope/blob/59d6d4a3/fit/core-reference/src/test/java/org/apache/syncope/fit/AbstractITCase.java
----------------------------------------------------------------------
diff --git a/fit/core-reference/src/test/java/org/apache/syncope/fit/AbstractITCase.java b/fit/core-reference/src/test/java/org/apache/syncope/fit/AbstractITCase.java
index d39ca3c..ba819af 100644
--- a/fit/core-reference/src/test/java/org/apache/syncope/fit/AbstractITCase.java
+++ b/fit/core-reference/src/test/java/org/apache/syncope/fit/AbstractITCase.java
@@ -18,6 +18,7 @@
*/
package org.apache.syncope.fit;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
@@ -36,6 +37,7 @@ import javax.naming.directory.InitialDirContext;
import javax.naming.directory.ModificationItem;
import javax.ws.rs.core.GenericType;
import javax.ws.rs.core.Response;
+import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.Pair;
@@ -52,14 +54,18 @@ import org.apache.syncope.common.lib.to.AnyObjectTO;
import org.apache.syncope.common.lib.to.AttrTO;
import org.apache.syncope.common.lib.to.ResourceTO;
import org.apache.syncope.common.lib.to.GroupTO;
+import org.apache.syncope.common.lib.to.MembershipTO;
+import org.apache.syncope.common.lib.to.NotificationTO;
import org.apache.syncope.common.lib.to.ProvisioningResult;
+import org.apache.syncope.common.lib.to.ReportTO;
import org.apache.syncope.common.lib.to.RoleTO;
import org.apache.syncope.common.lib.to.UserTO;
+import org.apache.syncope.common.lib.types.AnyTypeKind;
import org.apache.syncope.common.lib.types.ConnConfProperty;
import org.apache.syncope.common.lib.types.PatchOperation;
import org.apache.syncope.common.lib.types.SchemaType;
+import org.apache.syncope.common.lib.types.TraceLevel;
import org.apache.syncope.common.rest.api.RESTHeaders;
-import org.apache.syncope.common.rest.api.service.AccessTokenService;
import org.apache.syncope.common.rest.api.service.AnyObjectService;
import org.apache.syncope.common.rest.api.service.AnyTypeClassService;
import org.apache.syncope.common.rest.api.service.AnyTypeService;
@@ -89,6 +95,7 @@ import org.apache.syncope.common.rest.api.service.UserSelfService;
import org.apache.syncope.common.rest.api.service.UserService;
import org.apache.syncope.common.rest.api.service.UserWorkflowService;
import org.apache.syncope.common.rest.api.service.WorkflowService;
+import org.apache.syncope.fit.core.UserITCase;
import org.identityconnectors.common.security.Encryptor;
import org.junit.BeforeClass;
import org.slf4j.Logger;
@@ -343,6 +350,58 @@ public abstract class AbstractITCase {
return getObject(response.getLocation(), RoleService.class, RoleTO.class);
}
+ protected ReportTO createReport(final ReportTO report) {
+ Response response = reportService.create(report);
+ assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatusInfo().getStatusCode());
+ return getObject(response.getLocation(), ReportService.class, ReportTO.class);
+ }
+
+ protected Pair<String, String> createNotificationTask(
+ final boolean active,
+ final boolean includeAbout,
+ final TraceLevel traceLevel,
+ final String sender,
+ final String subject,
+ final String... staticRecipients) {
+
+ // 1. Create notification
+ NotificationTO notification = new NotificationTO();
+ notification.setTraceLevel(traceLevel);
+ notification.getEvents().add("[LOGIC]:[UserLogic]:[]:[create]:[SUCCESS]");
+
+ if (includeAbout) {
+ notification.getAbouts().put(AnyTypeKind.USER.name(),
+ SyncopeClient.getUserSearchConditionBuilder().
+ inGroups("bf825fe1-7320-4a54-bd64-143b5c18ab97").query());
+ }
+
+ notification.setRecipientsFIQL(SyncopeClient.getUserSearchConditionBuilder().
+ inGroups("f779c0d4-633b-4be5-8f57-32eb478a3ca5").query());
+ notification.setSelfAsRecipient(true);
+ notification.setRecipientAttrName("email");
+ if (staticRecipients != null) {
+ CollectionUtils.addAll(notification.getStaticRecipients(), staticRecipients);
+ }
+
+ notification.setSender(sender);
+ notification.setSubject(subject);
+ notification.setTemplate("optin");
+ notification.setActive(active);
+
+ Response response = notificationService.create(notification);
+ notification = getObject(response.getLocation(), NotificationService.class, NotificationTO.class);
+ assertNotNull(notification);
+
+ // 2. create user
+ UserTO userTO = UserITCase.getUniqueSampleTO("notificationtest@syncope.apache.org");
+ userTO.getMemberships().add(
+ new MembershipTO.Builder().group("bf825fe1-7320-4a54-bd64-143b5c18ab97").build());
+
+ userTO = createUser(userTO).getEntity();
+ assertNotNull(userTO);
+ return Pair.of(notification.getKey(), userTO.getUsername());
+ }
+
protected ProvisioningResult<UserTO> createUser(final UserTO userTO) {
return createUser(userTO, true);
}
http://git-wip-us.apache.org/repos/asf/syncope/blob/59d6d4a3/fit/core-reference/src/test/java/org/apache/syncope/fit/core/AbstractNotificationTaskITCase.java
----------------------------------------------------------------------
diff --git a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/AbstractNotificationTaskITCase.java b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/AbstractNotificationTaskITCase.java
new file mode 100644
index 0000000..41c7844
--- /dev/null
+++ b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/AbstractNotificationTaskITCase.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.fit.core;
+
+import static org.junit.Assert.assertNotNull;
+
+import com.icegreen.greenmail.util.GreenMail;
+import com.icegreen.greenmail.util.ServerSetup;
+import java.io.InputStream;
+import java.util.Properties;
+import javax.mail.Flags;
+import javax.mail.Folder;
+import javax.mail.Message;
+import javax.mail.Session;
+import javax.mail.Store;
+import org.apache.commons.io.IOUtils;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+
+public abstract class AbstractNotificationTaskITCase extends AbstractTaskITCase {
+
+ private static final String POP3_HOST = "localhost";
+
+ private static final int POP3_PORT = 1110;
+
+ private static String SMTP_HOST;
+
+ private static int SMTP_PORT;
+
+ private static GreenMail greenMail;
+
+ @BeforeClass
+ public static void startGreenMail() {
+ Properties props = new Properties();
+ InputStream propStream = null;
+ try {
+ propStream = ExceptionMapperITCase.class.getResourceAsStream("/mail.properties");
+ props.load(propStream);
+ } catch (Exception e) {
+ LOG.error("Could not load /mail.properties", e);
+ } finally {
+ IOUtils.closeQuietly(propStream);
+ }
+
+ SMTP_HOST = props.getProperty("smtpHost");
+ assertNotNull(SMTP_HOST);
+ SMTP_PORT = Integer.parseInt(props.getProperty("smtpPort"));
+ assertNotNull(SMTP_PORT);
+
+ ServerSetup[] config = new ServerSetup[2];
+ config[0] = new ServerSetup(SMTP_PORT, SMTP_HOST, ServerSetup.PROTOCOL_SMTP);
+ config[1] = new ServerSetup(POP3_PORT, POP3_HOST, ServerSetup.PROTOCOL_POP3);
+ greenMail = new GreenMail(config);
+ greenMail.start();
+ }
+
+ @AfterClass
+ public static void stopGreenMail() {
+ if (greenMail != null) {
+ greenMail.stop();
+ }
+ }
+
+ protected boolean verifyMail(final String sender, final String subject, final String mailAddress) throws Exception {
+ LOG.info("Waiting for notification to be sent...");
+ greenMail.waitForIncomingEmail(1);
+
+ boolean found = false;
+ Session session = Session.getDefaultInstance(System.getProperties());
+ session.setDebug(true);
+ Store store = session.getStore("pop3");
+ store.connect(POP3_HOST, POP3_PORT, mailAddress, mailAddress);
+
+ Folder inbox = store.getFolder("INBOX");
+ assertNotNull(inbox);
+ inbox.open(Folder.READ_WRITE);
+
+ Message[] messages = inbox.getMessages();
+ for (Message message : messages) {
+ if (sender.equals(message.getFrom()[0].toString()) && subject.equals(message.getSubject())) {
+ found = true;
+ message.setFlag(Flags.Flag.DELETED, true);
+ }
+ }
+
+ inbox.close(true);
+ store.close();
+ return found;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/syncope/blob/59d6d4a3/fit/core-reference/src/test/java/org/apache/syncope/fit/core/AbstractTaskITCase.java
----------------------------------------------------------------------
diff --git a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/AbstractTaskITCase.java b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/AbstractTaskITCase.java
index 6d7c897..94dafbd 100644
--- a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/AbstractTaskITCase.java
+++ b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/AbstractTaskITCase.java
@@ -30,12 +30,18 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
+import org.apache.syncope.client.lib.SyncopeClient;
+import org.apache.syncope.common.lib.SyncopeConstants;
+import org.apache.syncope.common.lib.patch.DeassociationPatch;
import org.apache.syncope.common.lib.to.AbstractTaskTO;
import org.apache.syncope.common.lib.to.ExecTO;
+import org.apache.syncope.common.lib.to.GroupTO;
import org.apache.syncope.common.lib.to.NotificationTaskTO;
import org.apache.syncope.common.lib.to.PagedResult;
import org.apache.syncope.common.lib.to.UserTO;
+import org.apache.syncope.common.lib.types.ResourceDeassociationAction;
import org.apache.syncope.common.lib.types.TaskType;
+import org.apache.syncope.common.rest.api.beans.AnyQuery;
import org.apache.syncope.common.rest.api.beans.ExecuteQuery;
import org.apache.syncope.common.rest.api.beans.TaskQuery;
import org.apache.syncope.common.rest.api.service.TaskService;
@@ -88,6 +94,41 @@ public abstract class AbstractTaskITCase extends AbstractITCase {
}
}
+ /**
+ * Clean Syncope and LDAP resource status.
+ */
+ protected void ldapCleanup() {
+ PagedResult<GroupTO> matchingGroups = groupService.search(new AnyQuery.Builder().realm(
+ SyncopeConstants.ROOT_REALM).
+ fiql(SyncopeClient.getGroupSearchConditionBuilder().is("name").equalTo("testLDAPGroup").query()).
+ build());
+ if (matchingGroups.getSize() > 0) {
+ for (GroupTO group : matchingGroups.getResult()) {
+ DeassociationPatch deassociationPatch = new DeassociationPatch();
+ deassociationPatch.setKey(group.getKey());
+ deassociationPatch.setAction(ResourceDeassociationAction.UNLINK);
+ deassociationPatch.getResources().add(RESOURCE_NAME_LDAP);
+ groupService.deassociate(deassociationPatch);
+ groupService.delete(group.getKey());
+ }
+ }
+ PagedResult<UserTO> matchingUsers = userService.search(
+ new AnyQuery.Builder().realm(SyncopeConstants.ROOT_REALM).
+ fiql(SyncopeClient.getUserSearchConditionBuilder().is("username").equalTo("pullFromLDAP").
+ query()).
+ build());
+ if (matchingUsers.getSize() > 0) {
+ for (UserTO user : matchingUsers.getResult()) {
+ DeassociationPatch deassociationPatch = new DeassociationPatch();
+ deassociationPatch.setKey(user.getKey());
+ deassociationPatch.setAction(ResourceDeassociationAction.UNLINK);
+ deassociationPatch.getResources().add(RESOURCE_NAME_LDAP);
+ userService.deassociate(deassociationPatch);
+ userService.delete(user.getKey());
+ }
+ }
+ }
+
protected static ExecTO execTask(final TaskService taskService, final String taskKey, final String initialStatus,
final int maxWaitSeconds, final boolean dryRun) {
http://git-wip-us.apache.org/repos/asf/syncope/blob/59d6d4a3/fit/core-reference/src/test/java/org/apache/syncope/fit/core/GroupITCase.java
----------------------------------------------------------------------
diff --git a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/GroupITCase.java b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/GroupITCase.java
index 3dff239..e24fc66 100644
--- a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/GroupITCase.java
+++ b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/GroupITCase.java
@@ -30,17 +30,11 @@ import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.UUID;
-import javax.naming.NamingEnumeration;
-import javax.naming.NamingException;
-import javax.naming.directory.DirContext;
-import javax.naming.directory.SearchControls;
-import javax.naming.directory.SearchResult;
import javax.ws.rs.ForbiddenException;
import javax.ws.rs.core.GenericType;
import javax.ws.rs.core.Response;
import org.apache.commons.collections4.IterableUtils;
import org.apache.commons.collections4.Predicate;
-import org.apache.commons.lang3.SerializationUtils;
import org.apache.syncope.client.lib.AnonymousAuthenticationHandler;
import org.apache.syncope.client.lib.SyncopeClient;
import org.apache.syncope.common.lib.AnyOperations;
@@ -61,27 +55,21 @@ import org.apache.syncope.common.lib.to.AttrTO;
import org.apache.syncope.common.lib.to.BulkActionResult;
import org.apache.syncope.common.lib.to.ConnInstanceTO;
import org.apache.syncope.common.lib.to.ConnObjectTO;
-import org.apache.syncope.common.lib.to.DerSchemaTO;
import org.apache.syncope.common.lib.to.ExecTO;
-import org.apache.syncope.common.lib.to.MappingItemTO;
import org.apache.syncope.common.lib.to.PagedResult;
import org.apache.syncope.common.lib.to.PlainSchemaTO;
import org.apache.syncope.common.lib.to.ResourceTO;
import org.apache.syncope.common.lib.to.GroupTO;
-import org.apache.syncope.common.lib.to.MappingTO;
import org.apache.syncope.common.lib.to.MembershipTO;
import org.apache.syncope.common.lib.to.PropagationStatus;
-import org.apache.syncope.common.lib.to.ProvisionTO;
import org.apache.syncope.common.lib.to.ProvisioningResult;
import org.apache.syncope.common.lib.to.SchedTaskTO;
import org.apache.syncope.common.lib.to.TypeExtensionTO;
import org.apache.syncope.common.lib.to.UserTO;
import org.apache.syncope.common.lib.types.AnyTypeKind;
-import org.apache.syncope.common.lib.types.AttrSchemaType;
import org.apache.syncope.common.lib.types.BulkMembersActionType;
import org.apache.syncope.common.lib.types.ClientExceptionType;
import org.apache.syncope.common.lib.types.ConnectorCapability;
-import org.apache.syncope.common.lib.types.MappingPurpose;
import org.apache.syncope.common.lib.types.PatchOperation;
import org.apache.syncope.common.lib.types.PropagationTaskExecStatus;
import org.apache.syncope.common.lib.types.ResourceAssociationAction;
@@ -888,187 +876,4 @@ public class GroupITCase extends AbstractITCase {
userService.delete(userTO.getKey());
}
}
-
- @Test
- public void issue178() {
- GroupTO groupTO = new GroupTO();
- String groupName = "torename" + getUUIDString();
- groupTO.setName(groupName);
- groupTO.setRealm("/");
-
- GroupTO actual = createGroup(groupTO).getEntity();
-
- assertNotNull(actual);
- assertEquals(groupName, actual.getName());
-
- GroupPatch groupPatch = new GroupPatch();
- groupPatch.setKey(actual.getKey());
- String renamedGroup = "renamed" + getUUIDString();
- groupPatch.setName(new StringReplacePatchItem.Builder().value(renamedGroup).build());
-
- actual = updateGroup(groupPatch).getEntity();
- assertNotNull(actual);
- assertEquals(renamedGroup, actual.getName());
- }
-
- @Test
- public void issueSYNCOPE632() {
- DerSchemaTO orig = schemaService.read(SchemaType.DERIVED, "displayProperty");
- DerSchemaTO modified = SerializationUtils.clone(orig);
- modified.setExpression("icon + '_' + show");
-
- GroupTO groupTO = getSampleTO("lastGroup");
- try {
- schemaService.update(SchemaType.DERIVED, modified);
-
- // 0. create group
- groupTO.getPlainAttrs().add(attrTO("icon", "anIcon"));
- groupTO.getPlainAttrs().add(attrTO("show", "true"));
- groupTO.getDerAttrs().add(attrTO("displayProperty", null));
- groupTO.getResources().clear();
-
- groupTO = createGroup(groupTO).getEntity();
- assertNotNull(groupTO);
-
- // 1. create new LDAP resource having ConnObjectKey mapped to a derived attribute
- ResourceTO newLDAP = resourceService.read(RESOURCE_NAME_LDAP);
- newLDAP.setKey("new-ldap");
- newLDAP.setPropagationPriority(0);
-
- for (ProvisionTO provision : newLDAP.getProvisions()) {
- provision.getVirSchemas().clear();
- }
-
- MappingTO mapping = newLDAP.getProvision(AnyTypeKind.GROUP.name()).getMapping();
-
- MappingItemTO connObjectKey = mapping.getConnObjectKeyItem();
- connObjectKey.setIntAttrName("displayProperty");
- connObjectKey.setPurpose(MappingPurpose.PROPAGATION);
- mapping.setConnObjectKeyItem(connObjectKey);
- mapping.setConnObjectLink("'cn=' + displayProperty + ',ou=groups,o=isp'");
-
- MappingItemTO description = new MappingItemTO();
- description.setIntAttrName("key");
- description.setExtAttrName("description");
- description.setPurpose(MappingPurpose.PROPAGATION);
- mapping.add(description);
-
- newLDAP = createResource(newLDAP);
- assertNotNull(newLDAP);
-
- // 2. update group and give the resource created above
- GroupPatch patch = new GroupPatch();
- patch.setKey(groupTO.getKey());
- patch.getResources().add(new StringPatchItem.Builder().
- operation(PatchOperation.ADD_REPLACE).
- value("new-ldap").build());
-
- groupTO = updateGroup(patch).getEntity();
- assertNotNull(groupTO);
-
- // 3. update the group
- GroupPatch groupPatch = new GroupPatch();
- groupPatch.setKey(groupTO.getKey());
- groupPatch.getPlainAttrs().add(attrAddReplacePatch("icon", "anotherIcon"));
-
- groupTO = updateGroup(groupPatch).getEntity();
- assertNotNull(groupTO);
-
- // 4. check that a single group exists in LDAP for the group created and updated above
- int entries = 0;
- DirContext ctx = null;
- try {
- ctx = getLdapResourceDirContext(null, null);
-
- SearchControls ctls = new SearchControls();
- ctls.setReturningAttributes(new String[] { "*", "+" });
- ctls.setSearchScope(SearchControls.SUBTREE_SCOPE);
-
- NamingEnumeration<SearchResult> result =
- ctx.search("ou=groups,o=isp", "(description=" + groupTO.getKey() + ")", ctls);
- while (result.hasMore()) {
- result.next();
- entries++;
- }
- } catch (Exception e) {
- // ignore
- } finally {
- if (ctx != null) {
- try {
- ctx.close();
- } catch (NamingException e) {
- // ignore
- }
- }
- }
-
- assertEquals(1, entries);
- } finally {
- schemaService.update(SchemaType.DERIVED, orig);
- if (groupTO.getKey() != null) {
- groupService.delete(groupTO.getKey());
- }
- resourceService.delete("new-ldap");
- }
- }
-
- @Test
- public void issueSYNCOPE717() {
- String doubleSchemaName = "double" + getUUIDString();
-
- // 1. create double schema without conversion pattern
- PlainSchemaTO schema = new PlainSchemaTO();
- schema.setKey(doubleSchemaName);
- schema.setType(AttrSchemaType.Double);
-
- schema = createSchema(SchemaType.PLAIN, schema);
- assertNotNull(schema);
- assertNull(schema.getConversionPattern());
-
- AnyTypeClassTO minimalGroup = anyTypeClassService.read("minimal group");
- assertNotNull(minimalGroup);
- minimalGroup.getPlainSchemas().add(doubleSchemaName);
- anyTypeClassService.update(minimalGroup);
-
- // 2. create group, provide valid input value
- GroupTO groupTO = getBasicSampleTO("syncope717");
- groupTO.getPlainAttrs().add(attrTO(doubleSchemaName, "11.23"));
-
- groupTO = createGroup(groupTO).getEntity();
- assertNotNull(groupTO);
- assertEquals("11.23", groupTO.getPlainAttr(doubleSchemaName).getValues().get(0));
-
- // 3. update schema, set conversion pattern
- schema = schemaService.read(SchemaType.PLAIN, schema.getKey());
- schema.setConversionPattern("0.000");
- schemaService.update(SchemaType.PLAIN, schema);
-
- // 4. re-read group, verify that pattern was applied
- groupTO = groupService.read(groupTO.getKey());
- assertNotNull(groupTO);
- assertEquals("11.230", groupTO.getPlainAttr(doubleSchemaName).getValues().get(0));
-
- // 5. modify group with new double value
- GroupPatch patch = new GroupPatch();
- patch.setKey(groupTO.getKey());
- patch.getPlainAttrs().add(new AttrPatch.Builder().attrTO(attrTO(doubleSchemaName, "11.257")).build());
-
- groupTO = updateGroup(patch).getEntity();
- assertNotNull(groupTO);
- assertEquals("11.257", groupTO.getPlainAttr(doubleSchemaName).getValues().get(0));
-
- // 6. update schema, unset conversion pattern
- schema.setConversionPattern(null);
- schemaService.update(SchemaType.PLAIN, schema);
-
- // 7. modify group with new double value, verify that no pattern is applied
- patch = new GroupPatch();
- patch.setKey(groupTO.getKey());
- patch.getPlainAttrs().add(new AttrPatch.Builder().attrTO(attrTO(doubleSchemaName, "11.23")).build());
-
- groupTO = updateGroup(patch).getEntity();
- assertNotNull(groupTO);
- assertEquals("11.23", groupTO.getPlainAttr(doubleSchemaName).getValues().get(0));
- }
-
}
http://git-wip-us.apache.org/repos/asf/syncope/blob/59d6d4a3/fit/core-reference/src/test/java/org/apache/syncope/fit/core/GroupIssuesITCase.java
----------------------------------------------------------------------
diff --git a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/GroupIssuesITCase.java b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/GroupIssuesITCase.java
new file mode 100644
index 0000000..7f1a03d
--- /dev/null
+++ b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/GroupIssuesITCase.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.fit.core;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+import javax.naming.directory.DirContext;
+import javax.naming.directory.SearchControls;
+import javax.naming.directory.SearchResult;
+import org.apache.commons.lang3.SerializationUtils;
+import org.apache.syncope.common.lib.patch.AttrPatch;
+import org.apache.syncope.common.lib.patch.GroupPatch;
+import org.apache.syncope.common.lib.patch.StringPatchItem;
+import org.apache.syncope.common.lib.patch.StringReplacePatchItem;
+import org.apache.syncope.common.lib.to.AnyTypeClassTO;
+import org.apache.syncope.common.lib.to.DerSchemaTO;
+import org.apache.syncope.common.lib.to.MappingItemTO;
+import org.apache.syncope.common.lib.to.PlainSchemaTO;
+import org.apache.syncope.common.lib.to.ResourceTO;
+import org.apache.syncope.common.lib.to.GroupTO;
+import org.apache.syncope.common.lib.to.MappingTO;
+import org.apache.syncope.common.lib.to.ProvisionTO;
+import org.apache.syncope.common.lib.types.AnyTypeKind;
+import org.apache.syncope.common.lib.types.AttrSchemaType;
+import org.apache.syncope.common.lib.types.MappingPurpose;
+import org.apache.syncope.common.lib.types.PatchOperation;
+import org.apache.syncope.common.lib.types.SchemaType;
+import org.apache.syncope.fit.AbstractITCase;
+import org.junit.Test;
+
+public class GroupIssuesITCase extends AbstractITCase {
+
+ @Test
+ public void issue178() {
+ GroupTO groupTO = new GroupTO();
+ String groupName = "torename" + getUUIDString();
+ groupTO.setName(groupName);
+ groupTO.setRealm("/");
+
+ GroupTO actual = createGroup(groupTO).getEntity();
+
+ assertNotNull(actual);
+ assertEquals(groupName, actual.getName());
+
+ GroupPatch groupPatch = new GroupPatch();
+ groupPatch.setKey(actual.getKey());
+ String renamedGroup = "renamed" + getUUIDString();
+ groupPatch.setName(new StringReplacePatchItem.Builder().value(renamedGroup).build());
+
+ actual = updateGroup(groupPatch).getEntity();
+ assertNotNull(actual);
+ assertEquals(renamedGroup, actual.getName());
+ }
+
+ @Test
+ public void issueSYNCOPE632() {
+ DerSchemaTO orig = schemaService.read(SchemaType.DERIVED, "displayProperty");
+ DerSchemaTO modified = SerializationUtils.clone(orig);
+ modified.setExpression("icon + '_' + show");
+
+ GroupTO groupTO = GroupITCase.getSampleTO("lastGroup");
+ try {
+ schemaService.update(SchemaType.DERIVED, modified);
+
+ // 0. create group
+ groupTO.getPlainAttrs().add(attrTO("icon", "anIcon"));
+ groupTO.getPlainAttrs().add(attrTO("show", "true"));
+ groupTO.getDerAttrs().add(attrTO("displayProperty", null));
+ groupTO.getResources().clear();
+
+ groupTO = createGroup(groupTO).getEntity();
+ assertNotNull(groupTO);
+
+ // 1. create new LDAP resource having ConnObjectKey mapped to a derived attribute
+ ResourceTO newLDAP = resourceService.read(RESOURCE_NAME_LDAP);
+ newLDAP.setKey("new-ldap");
+ newLDAP.setPropagationPriority(0);
+
+ for (ProvisionTO provision : newLDAP.getProvisions()) {
+ provision.getVirSchemas().clear();
+ }
+
+ MappingTO mapping = newLDAP.getProvision(AnyTypeKind.GROUP.name()).getMapping();
+
+ MappingItemTO connObjectKey = mapping.getConnObjectKeyItem();
+ connObjectKey.setIntAttrName("displayProperty");
+ connObjectKey.setPurpose(MappingPurpose.PROPAGATION);
+ mapping.setConnObjectKeyItem(connObjectKey);
+ mapping.setConnObjectLink("'cn=' + displayProperty + ',ou=groups,o=isp'");
+
+ MappingItemTO description = new MappingItemTO();
+ description.setIntAttrName("key");
+ description.setExtAttrName("description");
+ description.setPurpose(MappingPurpose.PROPAGATION);
+ mapping.add(description);
+
+ newLDAP = createResource(newLDAP);
+ assertNotNull(newLDAP);
+
+ // 2. update group and give the resource created above
+ GroupPatch patch = new GroupPatch();
+ patch.setKey(groupTO.getKey());
+ patch.getResources().add(new StringPatchItem.Builder().
+ operation(PatchOperation.ADD_REPLACE).
+ value("new-ldap").build());
+
+ groupTO = updateGroup(patch).getEntity();
+ assertNotNull(groupTO);
+
+ // 3. update the group
+ GroupPatch groupPatch = new GroupPatch();
+ groupPatch.setKey(groupTO.getKey());
+ groupPatch.getPlainAttrs().add(attrAddReplacePatch("icon", "anotherIcon"));
+
+ groupTO = updateGroup(groupPatch).getEntity();
+ assertNotNull(groupTO);
+
+ // 4. check that a single group exists in LDAP for the group created and updated above
+ int entries = 0;
+ DirContext ctx = null;
+ try {
+ ctx = getLdapResourceDirContext(null, null);
+
+ SearchControls ctls = new SearchControls();
+ ctls.setReturningAttributes(new String[] { "*", "+" });
+ ctls.setSearchScope(SearchControls.SUBTREE_SCOPE);
+
+ NamingEnumeration<SearchResult> result =
+ ctx.search("ou=groups,o=isp", "(description=" + groupTO.getKey() + ")", ctls);
+ while (result.hasMore()) {
+ result.next();
+ entries++;
+ }
+ } catch (Exception e) {
+ // ignore
+ } finally {
+ if (ctx != null) {
+ try {
+ ctx.close();
+ } catch (NamingException e) {
+ // ignore
+ }
+ }
+ }
+
+ assertEquals(1, entries);
+ } finally {
+ schemaService.update(SchemaType.DERIVED, orig);
+ if (groupTO.getKey() != null) {
+ groupService.delete(groupTO.getKey());
+ }
+ resourceService.delete("new-ldap");
+ }
+ }
+
+ @Test
+ public void issueSYNCOPE717() {
+ String doubleSchemaName = "double" + getUUIDString();
+
+ // 1. create double schema without conversion pattern
+ PlainSchemaTO schema = new PlainSchemaTO();
+ schema.setKey(doubleSchemaName);
+ schema.setType(AttrSchemaType.Double);
+
+ schema = createSchema(SchemaType.PLAIN, schema);
+ assertNotNull(schema);
+ assertNull(schema.getConversionPattern());
+
+ AnyTypeClassTO minimalGroup = anyTypeClassService.read("minimal group");
+ assertNotNull(minimalGroup);
+ minimalGroup.getPlainSchemas().add(doubleSchemaName);
+ anyTypeClassService.update(minimalGroup);
+
+ // 2. create group, provide valid input value
+ GroupTO groupTO = GroupITCase.getBasicSampleTO("syncope717");
+ groupTO.getPlainAttrs().add(attrTO(doubleSchemaName, "11.23"));
+
+ groupTO = createGroup(groupTO).getEntity();
+ assertNotNull(groupTO);
+ assertEquals("11.23", groupTO.getPlainAttr(doubleSchemaName).getValues().get(0));
+
+ // 3. update schema, set conversion pattern
+ schema = schemaService.read(SchemaType.PLAIN, schema.getKey());
+ schema.setConversionPattern("0.000");
+ schemaService.update(SchemaType.PLAIN, schema);
+
+ // 4. re-read group, verify that pattern was applied
+ groupTO = groupService.read(groupTO.getKey());
+ assertNotNull(groupTO);
+ assertEquals("11.230", groupTO.getPlainAttr(doubleSchemaName).getValues().get(0));
+
+ // 5. modify group with new double value
+ GroupPatch patch = new GroupPatch();
+ patch.setKey(groupTO.getKey());
+ patch.getPlainAttrs().add(new AttrPatch.Builder().attrTO(attrTO(doubleSchemaName, "11.257")).build());
+
+ groupTO = updateGroup(patch).getEntity();
+ assertNotNull(groupTO);
+ assertEquals("11.257", groupTO.getPlainAttr(doubleSchemaName).getValues().get(0));
+
+ // 6. update schema, unset conversion pattern
+ schema.setConversionPattern(null);
+ schemaService.update(SchemaType.PLAIN, schema);
+
+ // 7. modify group with new double value, verify that no pattern is applied
+ patch = new GroupPatch();
+ patch.setKey(groupTO.getKey());
+ patch.getPlainAttrs().add(new AttrPatch.Builder().attrTO(attrTO(doubleSchemaName, "11.23")).build());
+
+ groupTO = updateGroup(patch).getEntity();
+ assertNotNull(groupTO);
+ assertEquals("11.23", groupTO.getPlainAttr(doubleSchemaName).getValues().get(0));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/syncope/blob/59d6d4a3/fit/core-reference/src/test/java/org/apache/syncope/fit/core/NotificationTaskITCase.java
----------------------------------------------------------------------
diff --git a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/NotificationTaskITCase.java b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/NotificationTaskITCase.java
index e7fc955..421dab7 100644
--- a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/NotificationTaskITCase.java
+++ b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/NotificationTaskITCase.java
@@ -23,113 +23,15 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
-import com.icegreen.greenmail.util.GreenMail;
-import com.icegreen.greenmail.util.ServerSetup;
-import java.io.InputStream;
-import java.util.Properties;
-import javax.mail.Flags;
-import javax.mail.Folder;
-import javax.mail.Message;
-import javax.mail.Session;
-import javax.mail.Store;
-import javax.ws.rs.core.Response;
-import org.apache.commons.collections4.CollectionUtils;
-import org.apache.commons.io.IOUtils;
-import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.Pair;
-import org.apache.syncope.client.lib.SyncopeClient;
import org.apache.syncope.common.lib.to.AttrTO;
-import org.apache.syncope.common.lib.to.GroupTO;
-import org.apache.syncope.common.lib.to.MembershipTO;
-import org.apache.syncope.common.lib.to.NotificationTO;
import org.apache.syncope.common.lib.to.NotificationTaskTO;
import org.apache.syncope.common.lib.to.ExecTO;
-import org.apache.syncope.common.lib.to.PagedResult;
-import org.apache.syncope.common.lib.to.UserTO;
-import org.apache.syncope.common.lib.types.AnyTypeKind;
-import org.apache.syncope.common.lib.types.TaskType;
import org.apache.syncope.common.lib.types.TraceLevel;
-import org.apache.syncope.common.rest.api.beans.ExecuteQuery;
-import org.apache.syncope.common.rest.api.beans.TaskQuery;
-import org.apache.syncope.common.rest.api.service.NotificationService;
import org.apache.syncope.core.provisioning.java.job.notification.NotificationJob;
-import org.apache.syncope.fit.core.reference.TestNotificationRecipientsProvider;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
import org.junit.Test;
-public class NotificationTaskITCase extends AbstractTaskITCase {
-
- private static final String MAIL_ADDRESS = "notificationtest@syncope.apache.org";
-
- private static final String POP3_HOST = "localhost";
-
- private static final int POP3_PORT = 1110;
-
- private static String SMTP_HOST;
-
- private static int SMTP_PORT;
-
- private static GreenMail greenMail;
-
- @BeforeClass
- public static void startGreenMail() {
- Properties props = new Properties();
- InputStream propStream = null;
- try {
- propStream = ExceptionMapperITCase.class.getResourceAsStream("/mail.properties");
- props.load(propStream);
- } catch (Exception e) {
- LOG.error("Could not load /mail.properties", e);
- } finally {
- IOUtils.closeQuietly(propStream);
- }
-
- SMTP_HOST = props.getProperty("smtpHost");
- assertNotNull(SMTP_HOST);
- SMTP_PORT = Integer.parseInt(props.getProperty("smtpPort"));
- assertNotNull(SMTP_PORT);
-
- ServerSetup[] config = new ServerSetup[2];
- config[0] = new ServerSetup(SMTP_PORT, SMTP_HOST, ServerSetup.PROTOCOL_SMTP);
- config[1] = new ServerSetup(POP3_PORT, POP3_HOST, ServerSetup.PROTOCOL_POP3);
- greenMail = new GreenMail(config);
- greenMail.start();
- }
-
- @AfterClass
- public static void stopGreenMail() {
- if (greenMail != null) {
- greenMail.stop();
- }
- }
-
- private boolean verifyMail(final String sender, final String subject, final String mailAddress) throws Exception {
- LOG.info("Waiting for notification to be sent...");
- greenMail.waitForIncomingEmail(1);
-
- boolean found = false;
- Session session = Session.getDefaultInstance(System.getProperties());
- session.setDebug(true);
- Store store = session.getStore("pop3");
- store.connect(POP3_HOST, POP3_PORT, mailAddress, mailAddress);
-
- Folder inbox = store.getFolder("INBOX");
- assertNotNull(inbox);
- inbox.open(Folder.READ_WRITE);
-
- Message[] messages = inbox.getMessages();
- for (Message message : messages) {
- if (sender.equals(message.getFrom()[0].toString()) && subject.equals(message.getSubject())) {
- found = true;
- message.setFlag(Flags.Flag.DELETED, true);
- }
- }
-
- inbox.close(true);
- store.close();
- return found;
- }
+public class NotificationTaskITCase extends AbstractNotificationTaskITCase {
@Test
public void notifyByMail() throws Exception {
@@ -208,213 +110,4 @@ public class NotificationTaskITCase extends AbstractTaskITCase {
configurationService.set(origMaxRetries);
}
}
-
- @Test
- public void issueSYNCOPE81() {
- String sender = "syncope81@syncope.apache.org";
- Pair<String, String> created = createNotificationTask(true, true, TraceLevel.ALL, sender, "Test notification");
- NotificationTaskTO taskTO = findNotificationTask(created.getLeft(), 50);
- assertNotNull(taskTO);
- assertNotNull(taskTO.getNotification());
- assertTrue(taskTO.getExecutions().isEmpty());
-
- // generate an execution in order to verify the deletion of a notification task with one or more executions
- execNotificationTask(taskService, taskTO.getKey(), 50);
-
- taskTO = taskService.read(taskTO.getKey(), true);
- assertTrue(taskTO.isExecuted());
- assertFalse(taskTO.getExecutions().isEmpty());
-
- taskService.delete(taskTO.getKey());
- }
-
- @Test
- public void issueSYNCOPE86() {
- // 1. create notification task
- String sender = "syncope86@syncope.apache.org";
- Pair<String, String> created = createNotificationTask(true, true, TraceLevel.ALL, sender, "Test notification");
-
- // 2. get NotificationTaskTO for user just created
- NotificationTaskTO taskTO = findNotificationTask(created.getLeft(), 50);
- assertNotNull(taskTO);
- assertNotNull(taskTO.getNotification());
- assertTrue(taskTO.getExecutions().isEmpty());
-
- try {
- // 3. execute the generated NotificationTask
- execNotificationTask(taskService, taskTO.getKey(), 50);
-
- // 4. verify
- taskTO = taskService.read(taskTO.getKey(), true);
- assertNotNull(taskTO);
- assertTrue(taskTO.isExecuted());
- assertEquals(1, taskTO.getExecutions().size());
- } finally {
- // Remove execution to make test re-runnable
- taskService.deleteExecution(taskTO.getExecutions().get(0).getKey());
- }
- }
-
- @Test
- public void issueSYNCOPE192() throws Exception {
- String sender = "syncopetest-" + getUUIDString() + "@syncope.apache.org";
- String subject = "Test notification " + getUUIDString();
- Pair<String, String> created = createNotificationTask(true, true, TraceLevel.NONE, sender, subject);
- NotificationTaskTO taskTO = findNotificationTask(created.getLeft(), 50);
- assertNotNull(taskTO);
- assertNotNull(taskTO.getNotification());
- assertTrue(taskTO.getExecutions().isEmpty());
-
- taskService.execute(new ExecuteQuery.Builder().key(taskTO.getKey()).build());
-
- try {
- Thread.sleep(5);
- } catch (InterruptedException e) {
- }
-
- assertTrue(verifyMail(sender, subject, created.getRight()));
-
- // verify that last exec status was updated
- taskTO = taskService.read(taskTO.getKey(), true);
- assertNotNull(taskTO);
- assertTrue(taskTO.isExecuted());
- assertTrue(taskTO.getExecutions().isEmpty());
- assertTrue(StringUtils.isNotBlank(taskTO.getLatestExecStatus()));
- }
-
- @Test
- public void issueSYNCOPE445() throws Exception {
- String sender = "syncopetest-" + getUUIDString() + "@syncope.apache.org";
- String subject = "Test notification " + getUUIDString();
- Pair<String, String> created = createNotificationTask(
- true, true, TraceLevel.ALL, sender, subject, "syncope445@syncope.apache.org");
- NotificationTaskTO taskTO = findNotificationTask(created.getLeft(), 50);
- assertNotNull(taskTO);
- assertNotNull(taskTO.getNotification());
- assertTrue(taskTO.getExecutions().isEmpty());
-
- execNotificationTask(taskService, taskTO.getKey(), 50);
-
- assertTrue(verifyMail(sender, subject, created.getRight()));
-
- // verify task
- taskTO = taskService.read(taskTO.getKey(), true);
- assertTrue(taskTO.isExecuted());
- assertNotNull(taskTO);
- assertTrue(taskTO.getRecipients().contains("syncope445@syncope.apache.org"));
- }
-
- @Test
- public void issueSYNCOPE446() throws Exception {
- // 1. Create notification
- NotificationTO notification = new NotificationTO();
- notification.setTraceLevel(TraceLevel.ALL);
- notification.getEvents().add("[LOGIC]:[GroupLogic]:[]:[create]:[SUCCESS]");
-
- String groupName = "group" + getUUIDString();
- notification.getAbouts().put(AnyTypeKind.GROUP.name(),
- SyncopeClient.getGroupSearchConditionBuilder().is("name").equalTo(groupName).query());
-
- notification.setRecipientsFIQL(SyncopeClient.getUserSearchConditionBuilder().
- inGroups("f779c0d4-633b-4be5-8f57-32eb478a3ca5").query());
- notification.setSelfAsRecipient(false);
- notification.setRecipientAttrName("email");
- notification.getStaticRecipients().add(MAIL_ADDRESS);
- notification.setRecipientsProviderClassName(TestNotificationRecipientsProvider.class.getName());
-
- String sender = "syncopetest-" + getUUIDString() + "@syncope.apache.org";
- notification.setSender(sender);
- String subject = "Test notification " + getUUIDString();
- notification.setSubject(subject);
- notification.setTemplate("optin");
- notification.setActive(true);
-
- Response response = notificationService.create(notification);
- notification = getObject(response.getLocation(), NotificationService.class, NotificationTO.class);
- assertNotNull(notification);
- assertEquals(TestNotificationRecipientsProvider.class.getName(), notification.getRecipientsProviderClassName());
-
- // 2. create group
- GroupTO groupTO = new GroupTO();
- groupTO.setName(groupName);
- groupTO.setRealm("/even/two");
- groupTO = createGroup(groupTO).getEntity();
- assertNotNull(groupTO);
-
- // 3. verify
- NotificationTaskTO taskTO = findNotificationTask(notification.getKey(), 50);
- assertNotNull(taskTO);
- assertNotNull(taskTO.getNotification());
- assertTrue(taskTO.getRecipients().containsAll(
- new TestNotificationRecipientsProvider().provideRecipients(null)));
-
- NotificationTaskTO foundViaList = taskService.<NotificationTaskTO>list(
- new TaskQuery.Builder(TaskType.NOTIFICATION).notification(notification.getKey()).build()).
- getResult().get(0);
- assertEquals(taskTO, foundViaList);
-
- execNotificationTask(taskService, taskTO.getKey(), 50);
-
- assertTrue(verifyMail(sender, subject, MAIL_ADDRESS));
- }
-
- @Test
- public void issueSYNCOPE492() throws Exception {
- String sender = "syncopetest-" + getUUIDString() + "@syncope.apache.org";
- String subject = "Test notification " + getUUIDString();
- Pair<String, String> created =
- createNotificationTask(false, true, TraceLevel.NONE, sender, subject, "syncope445@syncope.apache.org");
-
- // verify that no task was created for disabled notification
- PagedResult<NotificationTaskTO> tasks =
- taskService.list(new TaskQuery.Builder(TaskType.NOTIFICATION).notification(created.getLeft()).build());
- assertEquals(0, tasks.getSize());
- }
-
- private Pair<String, String> createNotificationTask(
- final boolean active,
- final boolean includeAbout,
- final TraceLevel traceLevel,
- final String sender,
- final String subject,
- final String... staticRecipients) {
-
- // 1. Create notification
- NotificationTO notification = new NotificationTO();
- notification.setTraceLevel(traceLevel);
- notification.getEvents().add("[LOGIC]:[UserLogic]:[]:[create]:[SUCCESS]");
-
- if (includeAbout) {
- notification.getAbouts().put(AnyTypeKind.USER.name(),
- SyncopeClient.getUserSearchConditionBuilder().
- inGroups("bf825fe1-7320-4a54-bd64-143b5c18ab97").query());
- }
-
- notification.setRecipientsFIQL(SyncopeClient.getUserSearchConditionBuilder().
- inGroups("f779c0d4-633b-4be5-8f57-32eb478a3ca5").query());
- notification.setSelfAsRecipient(true);
- notification.setRecipientAttrName("email");
- if (staticRecipients != null) {
- CollectionUtils.addAll(notification.getStaticRecipients(), staticRecipients);
- }
-
- notification.setSender(sender);
- notification.setSubject(subject);
- notification.setTemplate("optin");
- notification.setActive(active);
-
- Response response = notificationService.create(notification);
- notification = getObject(response.getLocation(), NotificationService.class, NotificationTO.class);
- assertNotNull(notification);
-
- // 2. create user
- UserTO userTO = UserITCase.getUniqueSampleTO(MAIL_ADDRESS);
- userTO.getMemberships().add(
- new MembershipTO.Builder().group("bf825fe1-7320-4a54-bd64-143b5c18ab97").build());
-
- userTO = createUser(userTO).getEntity();
- assertNotNull(userTO);
- return Pair.of(notification.getKey(), userTO.getUsername());
- }
-
}
http://git-wip-us.apache.org/repos/asf/syncope/blob/59d6d4a3/fit/core-reference/src/test/java/org/apache/syncope/fit/core/NotificationTaskIssuesITCase.java
----------------------------------------------------------------------
diff --git a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/NotificationTaskIssuesITCase.java b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/NotificationTaskIssuesITCase.java
new file mode 100644
index 0000000..a695eb7
--- /dev/null
+++ b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/NotificationTaskIssuesITCase.java
@@ -0,0 +1,207 @@
+/*
+ * 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.fit.core;
+
+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 javax.ws.rs.core.Response;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.lang3.tuple.Pair;
+import org.apache.syncope.client.lib.SyncopeClient;
+import org.apache.syncope.common.lib.to.GroupTO;
+import org.apache.syncope.common.lib.to.NotificationTO;
+import org.apache.syncope.common.lib.to.NotificationTaskTO;
+import org.apache.syncope.common.lib.to.PagedResult;
+import org.apache.syncope.common.lib.types.AnyTypeKind;
+import org.apache.syncope.common.lib.types.TaskType;
+import org.apache.syncope.common.lib.types.TraceLevel;
+import org.apache.syncope.common.rest.api.beans.ExecuteQuery;
+import org.apache.syncope.common.rest.api.beans.TaskQuery;
+import org.apache.syncope.common.rest.api.service.NotificationService;
+import org.apache.syncope.fit.core.reference.TestNotificationRecipientsProvider;
+import org.junit.Test;
+
+public class NotificationTaskIssuesITCase extends AbstractNotificationTaskITCase {
+
+ @Test
+ public void issueSYNCOPE81() {
+ String sender = "syncope81@syncope.apache.org";
+ Pair<String, String> created = createNotificationTask(true, true, TraceLevel.ALL, sender, "Test notification");
+ NotificationTaskTO taskTO = findNotificationTask(created.getLeft(), 50);
+ assertNotNull(taskTO);
+ assertNotNull(taskTO.getNotification());
+ assertTrue(taskTO.getExecutions().isEmpty());
+
+ // generate an execution in order to verify the deletion of a notification task with one or more executions
+ execNotificationTask(taskService, taskTO.getKey(), 50);
+
+ taskTO = taskService.read(taskTO.getKey(), true);
+ assertTrue(taskTO.isExecuted());
+ assertFalse(taskTO.getExecutions().isEmpty());
+
+ taskService.delete(taskTO.getKey());
+ }
+
+ @Test
+ public void issueSYNCOPE86() {
+ // 1. create notification task
+ String sender = "syncope86@syncope.apache.org";
+ Pair<String, String> created = createNotificationTask(true, true, TraceLevel.ALL, sender, "Test notification");
+
+ // 2. get NotificationTaskTO for user just created
+ NotificationTaskTO taskTO = findNotificationTask(created.getLeft(), 50);
+ assertNotNull(taskTO);
+ assertNotNull(taskTO.getNotification());
+ assertTrue(taskTO.getExecutions().isEmpty());
+
+ try {
+ // 3. execute the generated NotificationTask
+ execNotificationTask(taskService, taskTO.getKey(), 50);
+
+ // 4. verify
+ taskTO = taskService.read(taskTO.getKey(), true);
+ assertNotNull(taskTO);
+ assertTrue(taskTO.isExecuted());
+ assertEquals(1, taskTO.getExecutions().size());
+ } finally {
+ // Remove execution to make test re-runnable
+ taskService.deleteExecution(taskTO.getExecutions().get(0).getKey());
+ }
+ }
+
+ @Test
+ public void issueSYNCOPE192() throws Exception {
+ String sender = "syncopetest-" + getUUIDString() + "@syncope.apache.org";
+ String subject = "Test notification " + getUUIDString();
+ Pair<String, String> created = createNotificationTask(true, true, TraceLevel.NONE, sender, subject);
+ NotificationTaskTO taskTO = findNotificationTask(created.getLeft(), 50);
+ assertNotNull(taskTO);
+ assertNotNull(taskTO.getNotification());
+ assertTrue(taskTO.getExecutions().isEmpty());
+
+ taskService.execute(new ExecuteQuery.Builder().key(taskTO.getKey()).build());
+
+ try {
+ Thread.sleep(5);
+ } catch (InterruptedException e) {
+ }
+
+ assertTrue(verifyMail(sender, subject, created.getRight()));
+
+ // verify that last exec status was updated
+ taskTO = taskService.read(taskTO.getKey(), true);
+ assertNotNull(taskTO);
+ assertTrue(taskTO.isExecuted());
+ assertTrue(taskTO.getExecutions().isEmpty());
+ assertTrue(StringUtils.isNotBlank(taskTO.getLatestExecStatus()));
+ }
+
+ @Test
+ public void issueSYNCOPE445() throws Exception {
+ String sender = "syncopetest-" + getUUIDString() + "@syncope.apache.org";
+ String subject = "Test notification " + getUUIDString();
+ Pair<String, String> created = createNotificationTask(
+ true, true, TraceLevel.ALL, sender, subject, "syncope445@syncope.apache.org");
+ NotificationTaskTO taskTO = findNotificationTask(created.getLeft(), 50);
+ assertNotNull(taskTO);
+ assertNotNull(taskTO.getNotification());
+ assertTrue(taskTO.getExecutions().isEmpty());
+
+ execNotificationTask(taskService, taskTO.getKey(), 50);
+
+ assertTrue(verifyMail(sender, subject, created.getRight()));
+
+ // verify task
+ taskTO = taskService.read(taskTO.getKey(), true);
+ assertTrue(taskTO.isExecuted());
+ assertNotNull(taskTO);
+ assertTrue(taskTO.getRecipients().contains("syncope445@syncope.apache.org"));
+ }
+
+ @Test
+ public void issueSYNCOPE446() throws Exception {
+ // 1. Create notification
+ NotificationTO notification = new NotificationTO();
+ notification.setTraceLevel(TraceLevel.ALL);
+ notification.getEvents().add("[LOGIC]:[GroupLogic]:[]:[create]:[SUCCESS]");
+
+ String groupName = "group" + getUUIDString();
+ notification.getAbouts().put(AnyTypeKind.GROUP.name(),
+ SyncopeClient.getGroupSearchConditionBuilder().is("name").equalTo(groupName).query());
+
+ notification.setRecipientsFIQL(SyncopeClient.getUserSearchConditionBuilder().
+ inGroups("f779c0d4-633b-4be5-8f57-32eb478a3ca5").query());
+ notification.setSelfAsRecipient(false);
+ notification.setRecipientAttrName("email");
+ notification.getStaticRecipients().add("notificationtest@syncope.apache.org");
+ notification.setRecipientsProviderClassName(TestNotificationRecipientsProvider.class.getName());
+
+ String sender = "syncopetest-" + getUUIDString() + "@syncope.apache.org";
+ notification.setSender(sender);
+ String subject = "Test notification " + getUUIDString();
+ notification.setSubject(subject);
+ notification.setTemplate("optin");
+ notification.setActive(true);
+
+ Response response = notificationService.create(notification);
+ notification = getObject(response.getLocation(), NotificationService.class, NotificationTO.class);
+ assertNotNull(notification);
+ assertEquals(TestNotificationRecipientsProvider.class.getName(), notification.getRecipientsProviderClassName());
+
+ // 2. create group
+ GroupTO groupTO = new GroupTO();
+ groupTO.setName(groupName);
+ groupTO.setRealm("/even/two");
+ groupTO = createGroup(groupTO).getEntity();
+ assertNotNull(groupTO);
+
+ // 3. verify
+ NotificationTaskTO taskTO = findNotificationTask(notification.getKey(), 50);
+ assertNotNull(taskTO);
+ assertNotNull(taskTO.getNotification());
+ assertTrue(taskTO.getRecipients().containsAll(
+ new TestNotificationRecipientsProvider().provideRecipients(null)));
+
+ NotificationTaskTO foundViaList = taskService.<NotificationTaskTO>list(
+ new TaskQuery.Builder(TaskType.NOTIFICATION).notification(notification.getKey()).build()).
+ getResult().get(0);
+ assertEquals(taskTO, foundViaList);
+
+ execNotificationTask(taskService, taskTO.getKey(), 50);
+
+ assertTrue(verifyMail(sender, subject, "notificationtest@syncope.apache.org"));
+ }
+
+ @Test
+ public void issueSYNCOPE492() throws Exception {
+ String sender = "syncopetest-" + getUUIDString() + "@syncope.apache.org";
+ String subject = "Test notification " + getUUIDString();
+ Pair<String, String> created =
+ createNotificationTask(false, true, TraceLevel.NONE, sender, subject, "syncope445@syncope.apache.org");
+
+ // verify that no task was created for disabled notification
+ PagedResult<NotificationTaskTO> tasks =
+ taskService.list(new TaskQuery.Builder(TaskType.NOTIFICATION).notification(created.getLeft()).build());
+ assertEquals(0, tasks.getSize());
+ }
+
+}
[2/4] syncope git commit: Reduce number of integration test cases
executed by default build, moving time-consuming to full-it profile
Posted by il...@apache.org.
Reduce number of integration test cases executed by default build, moving time-consuming to full-it profile
Project: http://git-wip-us.apache.org/repos/asf/syncope/repo
Commit: http://git-wip-us.apache.org/repos/asf/syncope/commit/b6dfd13e
Tree: http://git-wip-us.apache.org/repos/asf/syncope/tree/b6dfd13e
Diff: http://git-wip-us.apache.org/repos/asf/syncope/diff/b6dfd13e
Branch: refs/heads/2_0_X
Commit: b6dfd13e2f9cf3dadcd4121a1e978a5b05bfd2a3
Parents: b1aa1cb
Author: Francesco Chicchiriccò <il...@apache.org>
Authored: Mon Jun 19 16:19:14 2017 +0200
Committer: Francesco Chicchiriccò <il...@apache.org>
Committed: Mon Jun 19 16:20:11 2017 +0200
----------------------------------------------------------------------
fit/core-reference/pom.xml | 3 +
.../org/apache/syncope/fit/AbstractITCase.java | 61 +-
.../core/AbstractNotificationTaskITCase.java | 107 ++++
.../syncope/fit/core/AbstractTaskITCase.java | 41 ++
.../apache/syncope/fit/core/GroupITCase.java | 195 -------
.../syncope/fit/core/GroupIssuesITCase.java | 235 ++++++++
.../fit/core/NotificationTaskITCase.java | 309 +---------
.../fit/core/NotificationTaskIssuesITCase.java | 207 +++++++
.../apache/syncope/fit/core/PullTaskITCase.java | 558 -------------------
.../syncope/fit/core/PullTaskIssuesITCase.java | 550 ++++++++++++++++++
.../apache/syncope/fit/core/ReportITCase.java | 64 ---
.../syncope/fit/core/ReportIssuesITCase.java | 90 +++
12 files changed, 1294 insertions(+), 1126 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/syncope/blob/b6dfd13e/fit/core-reference/pom.xml
----------------------------------------------------------------------
diff --git a/fit/core-reference/pom.xml b/fit/core-reference/pom.xml
index 8aa248b..3040b95 100644
--- a/fit/core-reference/pom.xml
+++ b/fit/core-reference/pom.xml
@@ -230,6 +230,9 @@ under the License.
<includes>
<include>**/org/apache/syncope/fit/core/*ITCase.java</include>
</includes>
+ <excludes>
+ <exclude>**/*IssuesITCase.java</exclude>
+ </excludes>
</configuration>
<executions>
<execution>
http://git-wip-us.apache.org/repos/asf/syncope/blob/b6dfd13e/fit/core-reference/src/test/java/org/apache/syncope/fit/AbstractITCase.java
----------------------------------------------------------------------
diff --git a/fit/core-reference/src/test/java/org/apache/syncope/fit/AbstractITCase.java b/fit/core-reference/src/test/java/org/apache/syncope/fit/AbstractITCase.java
index d39ca3c..ba819af 100644
--- a/fit/core-reference/src/test/java/org/apache/syncope/fit/AbstractITCase.java
+++ b/fit/core-reference/src/test/java/org/apache/syncope/fit/AbstractITCase.java
@@ -18,6 +18,7 @@
*/
package org.apache.syncope.fit;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
@@ -36,6 +37,7 @@ import javax.naming.directory.InitialDirContext;
import javax.naming.directory.ModificationItem;
import javax.ws.rs.core.GenericType;
import javax.ws.rs.core.Response;
+import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.Pair;
@@ -52,14 +54,18 @@ import org.apache.syncope.common.lib.to.AnyObjectTO;
import org.apache.syncope.common.lib.to.AttrTO;
import org.apache.syncope.common.lib.to.ResourceTO;
import org.apache.syncope.common.lib.to.GroupTO;
+import org.apache.syncope.common.lib.to.MembershipTO;
+import org.apache.syncope.common.lib.to.NotificationTO;
import org.apache.syncope.common.lib.to.ProvisioningResult;
+import org.apache.syncope.common.lib.to.ReportTO;
import org.apache.syncope.common.lib.to.RoleTO;
import org.apache.syncope.common.lib.to.UserTO;
+import org.apache.syncope.common.lib.types.AnyTypeKind;
import org.apache.syncope.common.lib.types.ConnConfProperty;
import org.apache.syncope.common.lib.types.PatchOperation;
import org.apache.syncope.common.lib.types.SchemaType;
+import org.apache.syncope.common.lib.types.TraceLevel;
import org.apache.syncope.common.rest.api.RESTHeaders;
-import org.apache.syncope.common.rest.api.service.AccessTokenService;
import org.apache.syncope.common.rest.api.service.AnyObjectService;
import org.apache.syncope.common.rest.api.service.AnyTypeClassService;
import org.apache.syncope.common.rest.api.service.AnyTypeService;
@@ -89,6 +95,7 @@ import org.apache.syncope.common.rest.api.service.UserSelfService;
import org.apache.syncope.common.rest.api.service.UserService;
import org.apache.syncope.common.rest.api.service.UserWorkflowService;
import org.apache.syncope.common.rest.api.service.WorkflowService;
+import org.apache.syncope.fit.core.UserITCase;
import org.identityconnectors.common.security.Encryptor;
import org.junit.BeforeClass;
import org.slf4j.Logger;
@@ -343,6 +350,58 @@ public abstract class AbstractITCase {
return getObject(response.getLocation(), RoleService.class, RoleTO.class);
}
+ protected ReportTO createReport(final ReportTO report) {
+ Response response = reportService.create(report);
+ assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatusInfo().getStatusCode());
+ return getObject(response.getLocation(), ReportService.class, ReportTO.class);
+ }
+
+ protected Pair<String, String> createNotificationTask(
+ final boolean active,
+ final boolean includeAbout,
+ final TraceLevel traceLevel,
+ final String sender,
+ final String subject,
+ final String... staticRecipients) {
+
+ // 1. Create notification
+ NotificationTO notification = new NotificationTO();
+ notification.setTraceLevel(traceLevel);
+ notification.getEvents().add("[LOGIC]:[UserLogic]:[]:[create]:[SUCCESS]");
+
+ if (includeAbout) {
+ notification.getAbouts().put(AnyTypeKind.USER.name(),
+ SyncopeClient.getUserSearchConditionBuilder().
+ inGroups("bf825fe1-7320-4a54-bd64-143b5c18ab97").query());
+ }
+
+ notification.setRecipientsFIQL(SyncopeClient.getUserSearchConditionBuilder().
+ inGroups("f779c0d4-633b-4be5-8f57-32eb478a3ca5").query());
+ notification.setSelfAsRecipient(true);
+ notification.setRecipientAttrName("email");
+ if (staticRecipients != null) {
+ CollectionUtils.addAll(notification.getStaticRecipients(), staticRecipients);
+ }
+
+ notification.setSender(sender);
+ notification.setSubject(subject);
+ notification.setTemplate("optin");
+ notification.setActive(active);
+
+ Response response = notificationService.create(notification);
+ notification = getObject(response.getLocation(), NotificationService.class, NotificationTO.class);
+ assertNotNull(notification);
+
+ // 2. create user
+ UserTO userTO = UserITCase.getUniqueSampleTO("notificationtest@syncope.apache.org");
+ userTO.getMemberships().add(
+ new MembershipTO.Builder().group("bf825fe1-7320-4a54-bd64-143b5c18ab97").build());
+
+ userTO = createUser(userTO).getEntity();
+ assertNotNull(userTO);
+ return Pair.of(notification.getKey(), userTO.getUsername());
+ }
+
protected ProvisioningResult<UserTO> createUser(final UserTO userTO) {
return createUser(userTO, true);
}
http://git-wip-us.apache.org/repos/asf/syncope/blob/b6dfd13e/fit/core-reference/src/test/java/org/apache/syncope/fit/core/AbstractNotificationTaskITCase.java
----------------------------------------------------------------------
diff --git a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/AbstractNotificationTaskITCase.java b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/AbstractNotificationTaskITCase.java
new file mode 100644
index 0000000..41c7844
--- /dev/null
+++ b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/AbstractNotificationTaskITCase.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.fit.core;
+
+import static org.junit.Assert.assertNotNull;
+
+import com.icegreen.greenmail.util.GreenMail;
+import com.icegreen.greenmail.util.ServerSetup;
+import java.io.InputStream;
+import java.util.Properties;
+import javax.mail.Flags;
+import javax.mail.Folder;
+import javax.mail.Message;
+import javax.mail.Session;
+import javax.mail.Store;
+import org.apache.commons.io.IOUtils;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+
+public abstract class AbstractNotificationTaskITCase extends AbstractTaskITCase {
+
+ private static final String POP3_HOST = "localhost";
+
+ private static final int POP3_PORT = 1110;
+
+ private static String SMTP_HOST;
+
+ private static int SMTP_PORT;
+
+ private static GreenMail greenMail;
+
+ @BeforeClass
+ public static void startGreenMail() {
+ Properties props = new Properties();
+ InputStream propStream = null;
+ try {
+ propStream = ExceptionMapperITCase.class.getResourceAsStream("/mail.properties");
+ props.load(propStream);
+ } catch (Exception e) {
+ LOG.error("Could not load /mail.properties", e);
+ } finally {
+ IOUtils.closeQuietly(propStream);
+ }
+
+ SMTP_HOST = props.getProperty("smtpHost");
+ assertNotNull(SMTP_HOST);
+ SMTP_PORT = Integer.parseInt(props.getProperty("smtpPort"));
+ assertNotNull(SMTP_PORT);
+
+ ServerSetup[] config = new ServerSetup[2];
+ config[0] = new ServerSetup(SMTP_PORT, SMTP_HOST, ServerSetup.PROTOCOL_SMTP);
+ config[1] = new ServerSetup(POP3_PORT, POP3_HOST, ServerSetup.PROTOCOL_POP3);
+ greenMail = new GreenMail(config);
+ greenMail.start();
+ }
+
+ @AfterClass
+ public static void stopGreenMail() {
+ if (greenMail != null) {
+ greenMail.stop();
+ }
+ }
+
+ protected boolean verifyMail(final String sender, final String subject, final String mailAddress) throws Exception {
+ LOG.info("Waiting for notification to be sent...");
+ greenMail.waitForIncomingEmail(1);
+
+ boolean found = false;
+ Session session = Session.getDefaultInstance(System.getProperties());
+ session.setDebug(true);
+ Store store = session.getStore("pop3");
+ store.connect(POP3_HOST, POP3_PORT, mailAddress, mailAddress);
+
+ Folder inbox = store.getFolder("INBOX");
+ assertNotNull(inbox);
+ inbox.open(Folder.READ_WRITE);
+
+ Message[] messages = inbox.getMessages();
+ for (Message message : messages) {
+ if (sender.equals(message.getFrom()[0].toString()) && subject.equals(message.getSubject())) {
+ found = true;
+ message.setFlag(Flags.Flag.DELETED, true);
+ }
+ }
+
+ inbox.close(true);
+ store.close();
+ return found;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/syncope/blob/b6dfd13e/fit/core-reference/src/test/java/org/apache/syncope/fit/core/AbstractTaskITCase.java
----------------------------------------------------------------------
diff --git a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/AbstractTaskITCase.java b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/AbstractTaskITCase.java
index 6d7c897..94dafbd 100644
--- a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/AbstractTaskITCase.java
+++ b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/AbstractTaskITCase.java
@@ -30,12 +30,18 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
+import org.apache.syncope.client.lib.SyncopeClient;
+import org.apache.syncope.common.lib.SyncopeConstants;
+import org.apache.syncope.common.lib.patch.DeassociationPatch;
import org.apache.syncope.common.lib.to.AbstractTaskTO;
import org.apache.syncope.common.lib.to.ExecTO;
+import org.apache.syncope.common.lib.to.GroupTO;
import org.apache.syncope.common.lib.to.NotificationTaskTO;
import org.apache.syncope.common.lib.to.PagedResult;
import org.apache.syncope.common.lib.to.UserTO;
+import org.apache.syncope.common.lib.types.ResourceDeassociationAction;
import org.apache.syncope.common.lib.types.TaskType;
+import org.apache.syncope.common.rest.api.beans.AnyQuery;
import org.apache.syncope.common.rest.api.beans.ExecuteQuery;
import org.apache.syncope.common.rest.api.beans.TaskQuery;
import org.apache.syncope.common.rest.api.service.TaskService;
@@ -88,6 +94,41 @@ public abstract class AbstractTaskITCase extends AbstractITCase {
}
}
+ /**
+ * Clean Syncope and LDAP resource status.
+ */
+ protected void ldapCleanup() {
+ PagedResult<GroupTO> matchingGroups = groupService.search(new AnyQuery.Builder().realm(
+ SyncopeConstants.ROOT_REALM).
+ fiql(SyncopeClient.getGroupSearchConditionBuilder().is("name").equalTo("testLDAPGroup").query()).
+ build());
+ if (matchingGroups.getSize() > 0) {
+ for (GroupTO group : matchingGroups.getResult()) {
+ DeassociationPatch deassociationPatch = new DeassociationPatch();
+ deassociationPatch.setKey(group.getKey());
+ deassociationPatch.setAction(ResourceDeassociationAction.UNLINK);
+ deassociationPatch.getResources().add(RESOURCE_NAME_LDAP);
+ groupService.deassociate(deassociationPatch);
+ groupService.delete(group.getKey());
+ }
+ }
+ PagedResult<UserTO> matchingUsers = userService.search(
+ new AnyQuery.Builder().realm(SyncopeConstants.ROOT_REALM).
+ fiql(SyncopeClient.getUserSearchConditionBuilder().is("username").equalTo("pullFromLDAP").
+ query()).
+ build());
+ if (matchingUsers.getSize() > 0) {
+ for (UserTO user : matchingUsers.getResult()) {
+ DeassociationPatch deassociationPatch = new DeassociationPatch();
+ deassociationPatch.setKey(user.getKey());
+ deassociationPatch.setAction(ResourceDeassociationAction.UNLINK);
+ deassociationPatch.getResources().add(RESOURCE_NAME_LDAP);
+ userService.deassociate(deassociationPatch);
+ userService.delete(user.getKey());
+ }
+ }
+ }
+
protected static ExecTO execTask(final TaskService taskService, final String taskKey, final String initialStatus,
final int maxWaitSeconds, final boolean dryRun) {
http://git-wip-us.apache.org/repos/asf/syncope/blob/b6dfd13e/fit/core-reference/src/test/java/org/apache/syncope/fit/core/GroupITCase.java
----------------------------------------------------------------------
diff --git a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/GroupITCase.java b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/GroupITCase.java
index 3dff239..e24fc66 100644
--- a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/GroupITCase.java
+++ b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/GroupITCase.java
@@ -30,17 +30,11 @@ import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.UUID;
-import javax.naming.NamingEnumeration;
-import javax.naming.NamingException;
-import javax.naming.directory.DirContext;
-import javax.naming.directory.SearchControls;
-import javax.naming.directory.SearchResult;
import javax.ws.rs.ForbiddenException;
import javax.ws.rs.core.GenericType;
import javax.ws.rs.core.Response;
import org.apache.commons.collections4.IterableUtils;
import org.apache.commons.collections4.Predicate;
-import org.apache.commons.lang3.SerializationUtils;
import org.apache.syncope.client.lib.AnonymousAuthenticationHandler;
import org.apache.syncope.client.lib.SyncopeClient;
import org.apache.syncope.common.lib.AnyOperations;
@@ -61,27 +55,21 @@ import org.apache.syncope.common.lib.to.AttrTO;
import org.apache.syncope.common.lib.to.BulkActionResult;
import org.apache.syncope.common.lib.to.ConnInstanceTO;
import org.apache.syncope.common.lib.to.ConnObjectTO;
-import org.apache.syncope.common.lib.to.DerSchemaTO;
import org.apache.syncope.common.lib.to.ExecTO;
-import org.apache.syncope.common.lib.to.MappingItemTO;
import org.apache.syncope.common.lib.to.PagedResult;
import org.apache.syncope.common.lib.to.PlainSchemaTO;
import org.apache.syncope.common.lib.to.ResourceTO;
import org.apache.syncope.common.lib.to.GroupTO;
-import org.apache.syncope.common.lib.to.MappingTO;
import org.apache.syncope.common.lib.to.MembershipTO;
import org.apache.syncope.common.lib.to.PropagationStatus;
-import org.apache.syncope.common.lib.to.ProvisionTO;
import org.apache.syncope.common.lib.to.ProvisioningResult;
import org.apache.syncope.common.lib.to.SchedTaskTO;
import org.apache.syncope.common.lib.to.TypeExtensionTO;
import org.apache.syncope.common.lib.to.UserTO;
import org.apache.syncope.common.lib.types.AnyTypeKind;
-import org.apache.syncope.common.lib.types.AttrSchemaType;
import org.apache.syncope.common.lib.types.BulkMembersActionType;
import org.apache.syncope.common.lib.types.ClientExceptionType;
import org.apache.syncope.common.lib.types.ConnectorCapability;
-import org.apache.syncope.common.lib.types.MappingPurpose;
import org.apache.syncope.common.lib.types.PatchOperation;
import org.apache.syncope.common.lib.types.PropagationTaskExecStatus;
import org.apache.syncope.common.lib.types.ResourceAssociationAction;
@@ -888,187 +876,4 @@ public class GroupITCase extends AbstractITCase {
userService.delete(userTO.getKey());
}
}
-
- @Test
- public void issue178() {
- GroupTO groupTO = new GroupTO();
- String groupName = "torename" + getUUIDString();
- groupTO.setName(groupName);
- groupTO.setRealm("/");
-
- GroupTO actual = createGroup(groupTO).getEntity();
-
- assertNotNull(actual);
- assertEquals(groupName, actual.getName());
-
- GroupPatch groupPatch = new GroupPatch();
- groupPatch.setKey(actual.getKey());
- String renamedGroup = "renamed" + getUUIDString();
- groupPatch.setName(new StringReplacePatchItem.Builder().value(renamedGroup).build());
-
- actual = updateGroup(groupPatch).getEntity();
- assertNotNull(actual);
- assertEquals(renamedGroup, actual.getName());
- }
-
- @Test
- public void issueSYNCOPE632() {
- DerSchemaTO orig = schemaService.read(SchemaType.DERIVED, "displayProperty");
- DerSchemaTO modified = SerializationUtils.clone(orig);
- modified.setExpression("icon + '_' + show");
-
- GroupTO groupTO = getSampleTO("lastGroup");
- try {
- schemaService.update(SchemaType.DERIVED, modified);
-
- // 0. create group
- groupTO.getPlainAttrs().add(attrTO("icon", "anIcon"));
- groupTO.getPlainAttrs().add(attrTO("show", "true"));
- groupTO.getDerAttrs().add(attrTO("displayProperty", null));
- groupTO.getResources().clear();
-
- groupTO = createGroup(groupTO).getEntity();
- assertNotNull(groupTO);
-
- // 1. create new LDAP resource having ConnObjectKey mapped to a derived attribute
- ResourceTO newLDAP = resourceService.read(RESOURCE_NAME_LDAP);
- newLDAP.setKey("new-ldap");
- newLDAP.setPropagationPriority(0);
-
- for (ProvisionTO provision : newLDAP.getProvisions()) {
- provision.getVirSchemas().clear();
- }
-
- MappingTO mapping = newLDAP.getProvision(AnyTypeKind.GROUP.name()).getMapping();
-
- MappingItemTO connObjectKey = mapping.getConnObjectKeyItem();
- connObjectKey.setIntAttrName("displayProperty");
- connObjectKey.setPurpose(MappingPurpose.PROPAGATION);
- mapping.setConnObjectKeyItem(connObjectKey);
- mapping.setConnObjectLink("'cn=' + displayProperty + ',ou=groups,o=isp'");
-
- MappingItemTO description = new MappingItemTO();
- description.setIntAttrName("key");
- description.setExtAttrName("description");
- description.setPurpose(MappingPurpose.PROPAGATION);
- mapping.add(description);
-
- newLDAP = createResource(newLDAP);
- assertNotNull(newLDAP);
-
- // 2. update group and give the resource created above
- GroupPatch patch = new GroupPatch();
- patch.setKey(groupTO.getKey());
- patch.getResources().add(new StringPatchItem.Builder().
- operation(PatchOperation.ADD_REPLACE).
- value("new-ldap").build());
-
- groupTO = updateGroup(patch).getEntity();
- assertNotNull(groupTO);
-
- // 3. update the group
- GroupPatch groupPatch = new GroupPatch();
- groupPatch.setKey(groupTO.getKey());
- groupPatch.getPlainAttrs().add(attrAddReplacePatch("icon", "anotherIcon"));
-
- groupTO = updateGroup(groupPatch).getEntity();
- assertNotNull(groupTO);
-
- // 4. check that a single group exists in LDAP for the group created and updated above
- int entries = 0;
- DirContext ctx = null;
- try {
- ctx = getLdapResourceDirContext(null, null);
-
- SearchControls ctls = new SearchControls();
- ctls.setReturningAttributes(new String[] { "*", "+" });
- ctls.setSearchScope(SearchControls.SUBTREE_SCOPE);
-
- NamingEnumeration<SearchResult> result =
- ctx.search("ou=groups,o=isp", "(description=" + groupTO.getKey() + ")", ctls);
- while (result.hasMore()) {
- result.next();
- entries++;
- }
- } catch (Exception e) {
- // ignore
- } finally {
- if (ctx != null) {
- try {
- ctx.close();
- } catch (NamingException e) {
- // ignore
- }
- }
- }
-
- assertEquals(1, entries);
- } finally {
- schemaService.update(SchemaType.DERIVED, orig);
- if (groupTO.getKey() != null) {
- groupService.delete(groupTO.getKey());
- }
- resourceService.delete("new-ldap");
- }
- }
-
- @Test
- public void issueSYNCOPE717() {
- String doubleSchemaName = "double" + getUUIDString();
-
- // 1. create double schema without conversion pattern
- PlainSchemaTO schema = new PlainSchemaTO();
- schema.setKey(doubleSchemaName);
- schema.setType(AttrSchemaType.Double);
-
- schema = createSchema(SchemaType.PLAIN, schema);
- assertNotNull(schema);
- assertNull(schema.getConversionPattern());
-
- AnyTypeClassTO minimalGroup = anyTypeClassService.read("minimal group");
- assertNotNull(minimalGroup);
- minimalGroup.getPlainSchemas().add(doubleSchemaName);
- anyTypeClassService.update(minimalGroup);
-
- // 2. create group, provide valid input value
- GroupTO groupTO = getBasicSampleTO("syncope717");
- groupTO.getPlainAttrs().add(attrTO(doubleSchemaName, "11.23"));
-
- groupTO = createGroup(groupTO).getEntity();
- assertNotNull(groupTO);
- assertEquals("11.23", groupTO.getPlainAttr(doubleSchemaName).getValues().get(0));
-
- // 3. update schema, set conversion pattern
- schema = schemaService.read(SchemaType.PLAIN, schema.getKey());
- schema.setConversionPattern("0.000");
- schemaService.update(SchemaType.PLAIN, schema);
-
- // 4. re-read group, verify that pattern was applied
- groupTO = groupService.read(groupTO.getKey());
- assertNotNull(groupTO);
- assertEquals("11.230", groupTO.getPlainAttr(doubleSchemaName).getValues().get(0));
-
- // 5. modify group with new double value
- GroupPatch patch = new GroupPatch();
- patch.setKey(groupTO.getKey());
- patch.getPlainAttrs().add(new AttrPatch.Builder().attrTO(attrTO(doubleSchemaName, "11.257")).build());
-
- groupTO = updateGroup(patch).getEntity();
- assertNotNull(groupTO);
- assertEquals("11.257", groupTO.getPlainAttr(doubleSchemaName).getValues().get(0));
-
- // 6. update schema, unset conversion pattern
- schema.setConversionPattern(null);
- schemaService.update(SchemaType.PLAIN, schema);
-
- // 7. modify group with new double value, verify that no pattern is applied
- patch = new GroupPatch();
- patch.setKey(groupTO.getKey());
- patch.getPlainAttrs().add(new AttrPatch.Builder().attrTO(attrTO(doubleSchemaName, "11.23")).build());
-
- groupTO = updateGroup(patch).getEntity();
- assertNotNull(groupTO);
- assertEquals("11.23", groupTO.getPlainAttr(doubleSchemaName).getValues().get(0));
- }
-
}
http://git-wip-us.apache.org/repos/asf/syncope/blob/b6dfd13e/fit/core-reference/src/test/java/org/apache/syncope/fit/core/GroupIssuesITCase.java
----------------------------------------------------------------------
diff --git a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/GroupIssuesITCase.java b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/GroupIssuesITCase.java
new file mode 100644
index 0000000..7f1a03d
--- /dev/null
+++ b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/GroupIssuesITCase.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.fit.core;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+import javax.naming.directory.DirContext;
+import javax.naming.directory.SearchControls;
+import javax.naming.directory.SearchResult;
+import org.apache.commons.lang3.SerializationUtils;
+import org.apache.syncope.common.lib.patch.AttrPatch;
+import org.apache.syncope.common.lib.patch.GroupPatch;
+import org.apache.syncope.common.lib.patch.StringPatchItem;
+import org.apache.syncope.common.lib.patch.StringReplacePatchItem;
+import org.apache.syncope.common.lib.to.AnyTypeClassTO;
+import org.apache.syncope.common.lib.to.DerSchemaTO;
+import org.apache.syncope.common.lib.to.MappingItemTO;
+import org.apache.syncope.common.lib.to.PlainSchemaTO;
+import org.apache.syncope.common.lib.to.ResourceTO;
+import org.apache.syncope.common.lib.to.GroupTO;
+import org.apache.syncope.common.lib.to.MappingTO;
+import org.apache.syncope.common.lib.to.ProvisionTO;
+import org.apache.syncope.common.lib.types.AnyTypeKind;
+import org.apache.syncope.common.lib.types.AttrSchemaType;
+import org.apache.syncope.common.lib.types.MappingPurpose;
+import org.apache.syncope.common.lib.types.PatchOperation;
+import org.apache.syncope.common.lib.types.SchemaType;
+import org.apache.syncope.fit.AbstractITCase;
+import org.junit.Test;
+
+public class GroupIssuesITCase extends AbstractITCase {
+
+ @Test
+ public void issue178() {
+ GroupTO groupTO = new GroupTO();
+ String groupName = "torename" + getUUIDString();
+ groupTO.setName(groupName);
+ groupTO.setRealm("/");
+
+ GroupTO actual = createGroup(groupTO).getEntity();
+
+ assertNotNull(actual);
+ assertEquals(groupName, actual.getName());
+
+ GroupPatch groupPatch = new GroupPatch();
+ groupPatch.setKey(actual.getKey());
+ String renamedGroup = "renamed" + getUUIDString();
+ groupPatch.setName(new StringReplacePatchItem.Builder().value(renamedGroup).build());
+
+ actual = updateGroup(groupPatch).getEntity();
+ assertNotNull(actual);
+ assertEquals(renamedGroup, actual.getName());
+ }
+
+ @Test
+ public void issueSYNCOPE632() {
+ DerSchemaTO orig = schemaService.read(SchemaType.DERIVED, "displayProperty");
+ DerSchemaTO modified = SerializationUtils.clone(orig);
+ modified.setExpression("icon + '_' + show");
+
+ GroupTO groupTO = GroupITCase.getSampleTO("lastGroup");
+ try {
+ schemaService.update(SchemaType.DERIVED, modified);
+
+ // 0. create group
+ groupTO.getPlainAttrs().add(attrTO("icon", "anIcon"));
+ groupTO.getPlainAttrs().add(attrTO("show", "true"));
+ groupTO.getDerAttrs().add(attrTO("displayProperty", null));
+ groupTO.getResources().clear();
+
+ groupTO = createGroup(groupTO).getEntity();
+ assertNotNull(groupTO);
+
+ // 1. create new LDAP resource having ConnObjectKey mapped to a derived attribute
+ ResourceTO newLDAP = resourceService.read(RESOURCE_NAME_LDAP);
+ newLDAP.setKey("new-ldap");
+ newLDAP.setPropagationPriority(0);
+
+ for (ProvisionTO provision : newLDAP.getProvisions()) {
+ provision.getVirSchemas().clear();
+ }
+
+ MappingTO mapping = newLDAP.getProvision(AnyTypeKind.GROUP.name()).getMapping();
+
+ MappingItemTO connObjectKey = mapping.getConnObjectKeyItem();
+ connObjectKey.setIntAttrName("displayProperty");
+ connObjectKey.setPurpose(MappingPurpose.PROPAGATION);
+ mapping.setConnObjectKeyItem(connObjectKey);
+ mapping.setConnObjectLink("'cn=' + displayProperty + ',ou=groups,o=isp'");
+
+ MappingItemTO description = new MappingItemTO();
+ description.setIntAttrName("key");
+ description.setExtAttrName("description");
+ description.setPurpose(MappingPurpose.PROPAGATION);
+ mapping.add(description);
+
+ newLDAP = createResource(newLDAP);
+ assertNotNull(newLDAP);
+
+ // 2. update group and give the resource created above
+ GroupPatch patch = new GroupPatch();
+ patch.setKey(groupTO.getKey());
+ patch.getResources().add(new StringPatchItem.Builder().
+ operation(PatchOperation.ADD_REPLACE).
+ value("new-ldap").build());
+
+ groupTO = updateGroup(patch).getEntity();
+ assertNotNull(groupTO);
+
+ // 3. update the group
+ GroupPatch groupPatch = new GroupPatch();
+ groupPatch.setKey(groupTO.getKey());
+ groupPatch.getPlainAttrs().add(attrAddReplacePatch("icon", "anotherIcon"));
+
+ groupTO = updateGroup(groupPatch).getEntity();
+ assertNotNull(groupTO);
+
+ // 4. check that a single group exists in LDAP for the group created and updated above
+ int entries = 0;
+ DirContext ctx = null;
+ try {
+ ctx = getLdapResourceDirContext(null, null);
+
+ SearchControls ctls = new SearchControls();
+ ctls.setReturningAttributes(new String[] { "*", "+" });
+ ctls.setSearchScope(SearchControls.SUBTREE_SCOPE);
+
+ NamingEnumeration<SearchResult> result =
+ ctx.search("ou=groups,o=isp", "(description=" + groupTO.getKey() + ")", ctls);
+ while (result.hasMore()) {
+ result.next();
+ entries++;
+ }
+ } catch (Exception e) {
+ // ignore
+ } finally {
+ if (ctx != null) {
+ try {
+ ctx.close();
+ } catch (NamingException e) {
+ // ignore
+ }
+ }
+ }
+
+ assertEquals(1, entries);
+ } finally {
+ schemaService.update(SchemaType.DERIVED, orig);
+ if (groupTO.getKey() != null) {
+ groupService.delete(groupTO.getKey());
+ }
+ resourceService.delete("new-ldap");
+ }
+ }
+
+ @Test
+ public void issueSYNCOPE717() {
+ String doubleSchemaName = "double" + getUUIDString();
+
+ // 1. create double schema without conversion pattern
+ PlainSchemaTO schema = new PlainSchemaTO();
+ schema.setKey(doubleSchemaName);
+ schema.setType(AttrSchemaType.Double);
+
+ schema = createSchema(SchemaType.PLAIN, schema);
+ assertNotNull(schema);
+ assertNull(schema.getConversionPattern());
+
+ AnyTypeClassTO minimalGroup = anyTypeClassService.read("minimal group");
+ assertNotNull(minimalGroup);
+ minimalGroup.getPlainSchemas().add(doubleSchemaName);
+ anyTypeClassService.update(minimalGroup);
+
+ // 2. create group, provide valid input value
+ GroupTO groupTO = GroupITCase.getBasicSampleTO("syncope717");
+ groupTO.getPlainAttrs().add(attrTO(doubleSchemaName, "11.23"));
+
+ groupTO = createGroup(groupTO).getEntity();
+ assertNotNull(groupTO);
+ assertEquals("11.23", groupTO.getPlainAttr(doubleSchemaName).getValues().get(0));
+
+ // 3. update schema, set conversion pattern
+ schema = schemaService.read(SchemaType.PLAIN, schema.getKey());
+ schema.setConversionPattern("0.000");
+ schemaService.update(SchemaType.PLAIN, schema);
+
+ // 4. re-read group, verify that pattern was applied
+ groupTO = groupService.read(groupTO.getKey());
+ assertNotNull(groupTO);
+ assertEquals("11.230", groupTO.getPlainAttr(doubleSchemaName).getValues().get(0));
+
+ // 5. modify group with new double value
+ GroupPatch patch = new GroupPatch();
+ patch.setKey(groupTO.getKey());
+ patch.getPlainAttrs().add(new AttrPatch.Builder().attrTO(attrTO(doubleSchemaName, "11.257")).build());
+
+ groupTO = updateGroup(patch).getEntity();
+ assertNotNull(groupTO);
+ assertEquals("11.257", groupTO.getPlainAttr(doubleSchemaName).getValues().get(0));
+
+ // 6. update schema, unset conversion pattern
+ schema.setConversionPattern(null);
+ schemaService.update(SchemaType.PLAIN, schema);
+
+ // 7. modify group with new double value, verify that no pattern is applied
+ patch = new GroupPatch();
+ patch.setKey(groupTO.getKey());
+ patch.getPlainAttrs().add(new AttrPatch.Builder().attrTO(attrTO(doubleSchemaName, "11.23")).build());
+
+ groupTO = updateGroup(patch).getEntity();
+ assertNotNull(groupTO);
+ assertEquals("11.23", groupTO.getPlainAttr(doubleSchemaName).getValues().get(0));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/syncope/blob/b6dfd13e/fit/core-reference/src/test/java/org/apache/syncope/fit/core/NotificationTaskITCase.java
----------------------------------------------------------------------
diff --git a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/NotificationTaskITCase.java b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/NotificationTaskITCase.java
index e7fc955..421dab7 100644
--- a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/NotificationTaskITCase.java
+++ b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/NotificationTaskITCase.java
@@ -23,113 +23,15 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
-import com.icegreen.greenmail.util.GreenMail;
-import com.icegreen.greenmail.util.ServerSetup;
-import java.io.InputStream;
-import java.util.Properties;
-import javax.mail.Flags;
-import javax.mail.Folder;
-import javax.mail.Message;
-import javax.mail.Session;
-import javax.mail.Store;
-import javax.ws.rs.core.Response;
-import org.apache.commons.collections4.CollectionUtils;
-import org.apache.commons.io.IOUtils;
-import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.Pair;
-import org.apache.syncope.client.lib.SyncopeClient;
import org.apache.syncope.common.lib.to.AttrTO;
-import org.apache.syncope.common.lib.to.GroupTO;
-import org.apache.syncope.common.lib.to.MembershipTO;
-import org.apache.syncope.common.lib.to.NotificationTO;
import org.apache.syncope.common.lib.to.NotificationTaskTO;
import org.apache.syncope.common.lib.to.ExecTO;
-import org.apache.syncope.common.lib.to.PagedResult;
-import org.apache.syncope.common.lib.to.UserTO;
-import org.apache.syncope.common.lib.types.AnyTypeKind;
-import org.apache.syncope.common.lib.types.TaskType;
import org.apache.syncope.common.lib.types.TraceLevel;
-import org.apache.syncope.common.rest.api.beans.ExecuteQuery;
-import org.apache.syncope.common.rest.api.beans.TaskQuery;
-import org.apache.syncope.common.rest.api.service.NotificationService;
import org.apache.syncope.core.provisioning.java.job.notification.NotificationJob;
-import org.apache.syncope.fit.core.reference.TestNotificationRecipientsProvider;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
import org.junit.Test;
-public class NotificationTaskITCase extends AbstractTaskITCase {
-
- private static final String MAIL_ADDRESS = "notificationtest@syncope.apache.org";
-
- private static final String POP3_HOST = "localhost";
-
- private static final int POP3_PORT = 1110;
-
- private static String SMTP_HOST;
-
- private static int SMTP_PORT;
-
- private static GreenMail greenMail;
-
- @BeforeClass
- public static void startGreenMail() {
- Properties props = new Properties();
- InputStream propStream = null;
- try {
- propStream = ExceptionMapperITCase.class.getResourceAsStream("/mail.properties");
- props.load(propStream);
- } catch (Exception e) {
- LOG.error("Could not load /mail.properties", e);
- } finally {
- IOUtils.closeQuietly(propStream);
- }
-
- SMTP_HOST = props.getProperty("smtpHost");
- assertNotNull(SMTP_HOST);
- SMTP_PORT = Integer.parseInt(props.getProperty("smtpPort"));
- assertNotNull(SMTP_PORT);
-
- ServerSetup[] config = new ServerSetup[2];
- config[0] = new ServerSetup(SMTP_PORT, SMTP_HOST, ServerSetup.PROTOCOL_SMTP);
- config[1] = new ServerSetup(POP3_PORT, POP3_HOST, ServerSetup.PROTOCOL_POP3);
- greenMail = new GreenMail(config);
- greenMail.start();
- }
-
- @AfterClass
- public static void stopGreenMail() {
- if (greenMail != null) {
- greenMail.stop();
- }
- }
-
- private boolean verifyMail(final String sender, final String subject, final String mailAddress) throws Exception {
- LOG.info("Waiting for notification to be sent...");
- greenMail.waitForIncomingEmail(1);
-
- boolean found = false;
- Session session = Session.getDefaultInstance(System.getProperties());
- session.setDebug(true);
- Store store = session.getStore("pop3");
- store.connect(POP3_HOST, POP3_PORT, mailAddress, mailAddress);
-
- Folder inbox = store.getFolder("INBOX");
- assertNotNull(inbox);
- inbox.open(Folder.READ_WRITE);
-
- Message[] messages = inbox.getMessages();
- for (Message message : messages) {
- if (sender.equals(message.getFrom()[0].toString()) && subject.equals(message.getSubject())) {
- found = true;
- message.setFlag(Flags.Flag.DELETED, true);
- }
- }
-
- inbox.close(true);
- store.close();
- return found;
- }
+public class NotificationTaskITCase extends AbstractNotificationTaskITCase {
@Test
public void notifyByMail() throws Exception {
@@ -208,213 +110,4 @@ public class NotificationTaskITCase extends AbstractTaskITCase {
configurationService.set(origMaxRetries);
}
}
-
- @Test
- public void issueSYNCOPE81() {
- String sender = "syncope81@syncope.apache.org";
- Pair<String, String> created = createNotificationTask(true, true, TraceLevel.ALL, sender, "Test notification");
- NotificationTaskTO taskTO = findNotificationTask(created.getLeft(), 50);
- assertNotNull(taskTO);
- assertNotNull(taskTO.getNotification());
- assertTrue(taskTO.getExecutions().isEmpty());
-
- // generate an execution in order to verify the deletion of a notification task with one or more executions
- execNotificationTask(taskService, taskTO.getKey(), 50);
-
- taskTO = taskService.read(taskTO.getKey(), true);
- assertTrue(taskTO.isExecuted());
- assertFalse(taskTO.getExecutions().isEmpty());
-
- taskService.delete(taskTO.getKey());
- }
-
- @Test
- public void issueSYNCOPE86() {
- // 1. create notification task
- String sender = "syncope86@syncope.apache.org";
- Pair<String, String> created = createNotificationTask(true, true, TraceLevel.ALL, sender, "Test notification");
-
- // 2. get NotificationTaskTO for user just created
- NotificationTaskTO taskTO = findNotificationTask(created.getLeft(), 50);
- assertNotNull(taskTO);
- assertNotNull(taskTO.getNotification());
- assertTrue(taskTO.getExecutions().isEmpty());
-
- try {
- // 3. execute the generated NotificationTask
- execNotificationTask(taskService, taskTO.getKey(), 50);
-
- // 4. verify
- taskTO = taskService.read(taskTO.getKey(), true);
- assertNotNull(taskTO);
- assertTrue(taskTO.isExecuted());
- assertEquals(1, taskTO.getExecutions().size());
- } finally {
- // Remove execution to make test re-runnable
- taskService.deleteExecution(taskTO.getExecutions().get(0).getKey());
- }
- }
-
- @Test
- public void issueSYNCOPE192() throws Exception {
- String sender = "syncopetest-" + getUUIDString() + "@syncope.apache.org";
- String subject = "Test notification " + getUUIDString();
- Pair<String, String> created = createNotificationTask(true, true, TraceLevel.NONE, sender, subject);
- NotificationTaskTO taskTO = findNotificationTask(created.getLeft(), 50);
- assertNotNull(taskTO);
- assertNotNull(taskTO.getNotification());
- assertTrue(taskTO.getExecutions().isEmpty());
-
- taskService.execute(new ExecuteQuery.Builder().key(taskTO.getKey()).build());
-
- try {
- Thread.sleep(5);
- } catch (InterruptedException e) {
- }
-
- assertTrue(verifyMail(sender, subject, created.getRight()));
-
- // verify that last exec status was updated
- taskTO = taskService.read(taskTO.getKey(), true);
- assertNotNull(taskTO);
- assertTrue(taskTO.isExecuted());
- assertTrue(taskTO.getExecutions().isEmpty());
- assertTrue(StringUtils.isNotBlank(taskTO.getLatestExecStatus()));
- }
-
- @Test
- public void issueSYNCOPE445() throws Exception {
- String sender = "syncopetest-" + getUUIDString() + "@syncope.apache.org";
- String subject = "Test notification " + getUUIDString();
- Pair<String, String> created = createNotificationTask(
- true, true, TraceLevel.ALL, sender, subject, "syncope445@syncope.apache.org");
- NotificationTaskTO taskTO = findNotificationTask(created.getLeft(), 50);
- assertNotNull(taskTO);
- assertNotNull(taskTO.getNotification());
- assertTrue(taskTO.getExecutions().isEmpty());
-
- execNotificationTask(taskService, taskTO.getKey(), 50);
-
- assertTrue(verifyMail(sender, subject, created.getRight()));
-
- // verify task
- taskTO = taskService.read(taskTO.getKey(), true);
- assertTrue(taskTO.isExecuted());
- assertNotNull(taskTO);
- assertTrue(taskTO.getRecipients().contains("syncope445@syncope.apache.org"));
- }
-
- @Test
- public void issueSYNCOPE446() throws Exception {
- // 1. Create notification
- NotificationTO notification = new NotificationTO();
- notification.setTraceLevel(TraceLevel.ALL);
- notification.getEvents().add("[LOGIC]:[GroupLogic]:[]:[create]:[SUCCESS]");
-
- String groupName = "group" + getUUIDString();
- notification.getAbouts().put(AnyTypeKind.GROUP.name(),
- SyncopeClient.getGroupSearchConditionBuilder().is("name").equalTo(groupName).query());
-
- notification.setRecipientsFIQL(SyncopeClient.getUserSearchConditionBuilder().
- inGroups("f779c0d4-633b-4be5-8f57-32eb478a3ca5").query());
- notification.setSelfAsRecipient(false);
- notification.setRecipientAttrName("email");
- notification.getStaticRecipients().add(MAIL_ADDRESS);
- notification.setRecipientsProviderClassName(TestNotificationRecipientsProvider.class.getName());
-
- String sender = "syncopetest-" + getUUIDString() + "@syncope.apache.org";
- notification.setSender(sender);
- String subject = "Test notification " + getUUIDString();
- notification.setSubject(subject);
- notification.setTemplate("optin");
- notification.setActive(true);
-
- Response response = notificationService.create(notification);
- notification = getObject(response.getLocation(), NotificationService.class, NotificationTO.class);
- assertNotNull(notification);
- assertEquals(TestNotificationRecipientsProvider.class.getName(), notification.getRecipientsProviderClassName());
-
- // 2. create group
- GroupTO groupTO = new GroupTO();
- groupTO.setName(groupName);
- groupTO.setRealm("/even/two");
- groupTO = createGroup(groupTO).getEntity();
- assertNotNull(groupTO);
-
- // 3. verify
- NotificationTaskTO taskTO = findNotificationTask(notification.getKey(), 50);
- assertNotNull(taskTO);
- assertNotNull(taskTO.getNotification());
- assertTrue(taskTO.getRecipients().containsAll(
- new TestNotificationRecipientsProvider().provideRecipients(null)));
-
- NotificationTaskTO foundViaList = taskService.<NotificationTaskTO>list(
- new TaskQuery.Builder(TaskType.NOTIFICATION).notification(notification.getKey()).build()).
- getResult().get(0);
- assertEquals(taskTO, foundViaList);
-
- execNotificationTask(taskService, taskTO.getKey(), 50);
-
- assertTrue(verifyMail(sender, subject, MAIL_ADDRESS));
- }
-
- @Test
- public void issueSYNCOPE492() throws Exception {
- String sender = "syncopetest-" + getUUIDString() + "@syncope.apache.org";
- String subject = "Test notification " + getUUIDString();
- Pair<String, String> created =
- createNotificationTask(false, true, TraceLevel.NONE, sender, subject, "syncope445@syncope.apache.org");
-
- // verify that no task was created for disabled notification
- PagedResult<NotificationTaskTO> tasks =
- taskService.list(new TaskQuery.Builder(TaskType.NOTIFICATION).notification(created.getLeft()).build());
- assertEquals(0, tasks.getSize());
- }
-
- private Pair<String, String> createNotificationTask(
- final boolean active,
- final boolean includeAbout,
- final TraceLevel traceLevel,
- final String sender,
- final String subject,
- final String... staticRecipients) {
-
- // 1. Create notification
- NotificationTO notification = new NotificationTO();
- notification.setTraceLevel(traceLevel);
- notification.getEvents().add("[LOGIC]:[UserLogic]:[]:[create]:[SUCCESS]");
-
- if (includeAbout) {
- notification.getAbouts().put(AnyTypeKind.USER.name(),
- SyncopeClient.getUserSearchConditionBuilder().
- inGroups("bf825fe1-7320-4a54-bd64-143b5c18ab97").query());
- }
-
- notification.setRecipientsFIQL(SyncopeClient.getUserSearchConditionBuilder().
- inGroups("f779c0d4-633b-4be5-8f57-32eb478a3ca5").query());
- notification.setSelfAsRecipient(true);
- notification.setRecipientAttrName("email");
- if (staticRecipients != null) {
- CollectionUtils.addAll(notification.getStaticRecipients(), staticRecipients);
- }
-
- notification.setSender(sender);
- notification.setSubject(subject);
- notification.setTemplate("optin");
- notification.setActive(active);
-
- Response response = notificationService.create(notification);
- notification = getObject(response.getLocation(), NotificationService.class, NotificationTO.class);
- assertNotNull(notification);
-
- // 2. create user
- UserTO userTO = UserITCase.getUniqueSampleTO(MAIL_ADDRESS);
- userTO.getMemberships().add(
- new MembershipTO.Builder().group("bf825fe1-7320-4a54-bd64-143b5c18ab97").build());
-
- userTO = createUser(userTO).getEntity();
- assertNotNull(userTO);
- return Pair.of(notification.getKey(), userTO.getUsername());
- }
-
}
http://git-wip-us.apache.org/repos/asf/syncope/blob/b6dfd13e/fit/core-reference/src/test/java/org/apache/syncope/fit/core/NotificationTaskIssuesITCase.java
----------------------------------------------------------------------
diff --git a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/NotificationTaskIssuesITCase.java b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/NotificationTaskIssuesITCase.java
new file mode 100644
index 0000000..a695eb7
--- /dev/null
+++ b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/NotificationTaskIssuesITCase.java
@@ -0,0 +1,207 @@
+/*
+ * 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.fit.core;
+
+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 javax.ws.rs.core.Response;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.lang3.tuple.Pair;
+import org.apache.syncope.client.lib.SyncopeClient;
+import org.apache.syncope.common.lib.to.GroupTO;
+import org.apache.syncope.common.lib.to.NotificationTO;
+import org.apache.syncope.common.lib.to.NotificationTaskTO;
+import org.apache.syncope.common.lib.to.PagedResult;
+import org.apache.syncope.common.lib.types.AnyTypeKind;
+import org.apache.syncope.common.lib.types.TaskType;
+import org.apache.syncope.common.lib.types.TraceLevel;
+import org.apache.syncope.common.rest.api.beans.ExecuteQuery;
+import org.apache.syncope.common.rest.api.beans.TaskQuery;
+import org.apache.syncope.common.rest.api.service.NotificationService;
+import org.apache.syncope.fit.core.reference.TestNotificationRecipientsProvider;
+import org.junit.Test;
+
+public class NotificationTaskIssuesITCase extends AbstractNotificationTaskITCase {
+
+ @Test
+ public void issueSYNCOPE81() {
+ String sender = "syncope81@syncope.apache.org";
+ Pair<String, String> created = createNotificationTask(true, true, TraceLevel.ALL, sender, "Test notification");
+ NotificationTaskTO taskTO = findNotificationTask(created.getLeft(), 50);
+ assertNotNull(taskTO);
+ assertNotNull(taskTO.getNotification());
+ assertTrue(taskTO.getExecutions().isEmpty());
+
+ // generate an execution in order to verify the deletion of a notification task with one or more executions
+ execNotificationTask(taskService, taskTO.getKey(), 50);
+
+ taskTO = taskService.read(taskTO.getKey(), true);
+ assertTrue(taskTO.isExecuted());
+ assertFalse(taskTO.getExecutions().isEmpty());
+
+ taskService.delete(taskTO.getKey());
+ }
+
+ @Test
+ public void issueSYNCOPE86() {
+ // 1. create notification task
+ String sender = "syncope86@syncope.apache.org";
+ Pair<String, String> created = createNotificationTask(true, true, TraceLevel.ALL, sender, "Test notification");
+
+ // 2. get NotificationTaskTO for user just created
+ NotificationTaskTO taskTO = findNotificationTask(created.getLeft(), 50);
+ assertNotNull(taskTO);
+ assertNotNull(taskTO.getNotification());
+ assertTrue(taskTO.getExecutions().isEmpty());
+
+ try {
+ // 3. execute the generated NotificationTask
+ execNotificationTask(taskService, taskTO.getKey(), 50);
+
+ // 4. verify
+ taskTO = taskService.read(taskTO.getKey(), true);
+ assertNotNull(taskTO);
+ assertTrue(taskTO.isExecuted());
+ assertEquals(1, taskTO.getExecutions().size());
+ } finally {
+ // Remove execution to make test re-runnable
+ taskService.deleteExecution(taskTO.getExecutions().get(0).getKey());
+ }
+ }
+
+ @Test
+ public void issueSYNCOPE192() throws Exception {
+ String sender = "syncopetest-" + getUUIDString() + "@syncope.apache.org";
+ String subject = "Test notification " + getUUIDString();
+ Pair<String, String> created = createNotificationTask(true, true, TraceLevel.NONE, sender, subject);
+ NotificationTaskTO taskTO = findNotificationTask(created.getLeft(), 50);
+ assertNotNull(taskTO);
+ assertNotNull(taskTO.getNotification());
+ assertTrue(taskTO.getExecutions().isEmpty());
+
+ taskService.execute(new ExecuteQuery.Builder().key(taskTO.getKey()).build());
+
+ try {
+ Thread.sleep(5);
+ } catch (InterruptedException e) {
+ }
+
+ assertTrue(verifyMail(sender, subject, created.getRight()));
+
+ // verify that last exec status was updated
+ taskTO = taskService.read(taskTO.getKey(), true);
+ assertNotNull(taskTO);
+ assertTrue(taskTO.isExecuted());
+ assertTrue(taskTO.getExecutions().isEmpty());
+ assertTrue(StringUtils.isNotBlank(taskTO.getLatestExecStatus()));
+ }
+
+ @Test
+ public void issueSYNCOPE445() throws Exception {
+ String sender = "syncopetest-" + getUUIDString() + "@syncope.apache.org";
+ String subject = "Test notification " + getUUIDString();
+ Pair<String, String> created = createNotificationTask(
+ true, true, TraceLevel.ALL, sender, subject, "syncope445@syncope.apache.org");
+ NotificationTaskTO taskTO = findNotificationTask(created.getLeft(), 50);
+ assertNotNull(taskTO);
+ assertNotNull(taskTO.getNotification());
+ assertTrue(taskTO.getExecutions().isEmpty());
+
+ execNotificationTask(taskService, taskTO.getKey(), 50);
+
+ assertTrue(verifyMail(sender, subject, created.getRight()));
+
+ // verify task
+ taskTO = taskService.read(taskTO.getKey(), true);
+ assertTrue(taskTO.isExecuted());
+ assertNotNull(taskTO);
+ assertTrue(taskTO.getRecipients().contains("syncope445@syncope.apache.org"));
+ }
+
+ @Test
+ public void issueSYNCOPE446() throws Exception {
+ // 1. Create notification
+ NotificationTO notification = new NotificationTO();
+ notification.setTraceLevel(TraceLevel.ALL);
+ notification.getEvents().add("[LOGIC]:[GroupLogic]:[]:[create]:[SUCCESS]");
+
+ String groupName = "group" + getUUIDString();
+ notification.getAbouts().put(AnyTypeKind.GROUP.name(),
+ SyncopeClient.getGroupSearchConditionBuilder().is("name").equalTo(groupName).query());
+
+ notification.setRecipientsFIQL(SyncopeClient.getUserSearchConditionBuilder().
+ inGroups("f779c0d4-633b-4be5-8f57-32eb478a3ca5").query());
+ notification.setSelfAsRecipient(false);
+ notification.setRecipientAttrName("email");
+ notification.getStaticRecipients().add("notificationtest@syncope.apache.org");
+ notification.setRecipientsProviderClassName(TestNotificationRecipientsProvider.class.getName());
+
+ String sender = "syncopetest-" + getUUIDString() + "@syncope.apache.org";
+ notification.setSender(sender);
+ String subject = "Test notification " + getUUIDString();
+ notification.setSubject(subject);
+ notification.setTemplate("optin");
+ notification.setActive(true);
+
+ Response response = notificationService.create(notification);
+ notification = getObject(response.getLocation(), NotificationService.class, NotificationTO.class);
+ assertNotNull(notification);
+ assertEquals(TestNotificationRecipientsProvider.class.getName(), notification.getRecipientsProviderClassName());
+
+ // 2. create group
+ GroupTO groupTO = new GroupTO();
+ groupTO.setName(groupName);
+ groupTO.setRealm("/even/two");
+ groupTO = createGroup(groupTO).getEntity();
+ assertNotNull(groupTO);
+
+ // 3. verify
+ NotificationTaskTO taskTO = findNotificationTask(notification.getKey(), 50);
+ assertNotNull(taskTO);
+ assertNotNull(taskTO.getNotification());
+ assertTrue(taskTO.getRecipients().containsAll(
+ new TestNotificationRecipientsProvider().provideRecipients(null)));
+
+ NotificationTaskTO foundViaList = taskService.<NotificationTaskTO>list(
+ new TaskQuery.Builder(TaskType.NOTIFICATION).notification(notification.getKey()).build()).
+ getResult().get(0);
+ assertEquals(taskTO, foundViaList);
+
+ execNotificationTask(taskService, taskTO.getKey(), 50);
+
+ assertTrue(verifyMail(sender, subject, "notificationtest@syncope.apache.org"));
+ }
+
+ @Test
+ public void issueSYNCOPE492() throws Exception {
+ String sender = "syncopetest-" + getUUIDString() + "@syncope.apache.org";
+ String subject = "Test notification " + getUUIDString();
+ Pair<String, String> created =
+ createNotificationTask(false, true, TraceLevel.NONE, sender, subject, "syncope445@syncope.apache.org");
+
+ // verify that no task was created for disabled notification
+ PagedResult<NotificationTaskTO> tasks =
+ taskService.list(new TaskQuery.Builder(TaskType.NOTIFICATION).notification(created.getLeft()).build());
+ assertEquals(0, tasks.getSize());
+ }
+
+}