Merged HEAD-BUG-FIX (4.3/Cloud) to HEAD (4.3/Cloud)

57072: Merged V4.2-BUG-FIX (4.2.1) to HEAD-BUG-FIX (Cloud/4.3)
      56559: Merged V4.1-BUG-FIX (4.1.7) to V4.2-BUG-FIX (4.2.1)
         56110: MNT-9104 : If username contains uppercase letters the action of joining a site will not be displayed in "My activities"
          Rename test SiteActivityTest to AbstractSiteActivityTest and FeedCleanerTest to AbstractFeedCleanerTest.
          Add case sensitivity tests SiteActivityTestCaseInsensitivity, SiteActivityTestCaseSensitivity, FeedCleanerTestCaseInsensitivity, FeedCleanerTestCaseSensitivity.
          Was implemented code, the activities dependent of 'user.name.caseSensitive' property.


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@61703 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Alan Davis
2014-02-11 19:14:16 +00:00
parent b11acd5737
commit 92a49b48e6
11 changed files with 228 additions and 60 deletions

View File

@@ -34,6 +34,7 @@
<property name="policyComponent" ref="policyComponent"/> <property name="policyComponent" ref="policyComponent"/>
<property name="transactionService" ref="transactionService"/> <property name="transactionService" ref="transactionService"/>
<property name="userNamesAreCaseSensitive" value="${user.name.caseSensitive}"/>
<property name="maxIdRange"> <property name="maxIdRange">
<value>${activities.feed.max.idRange}</value> <!-- max ID range between max(id) and min(id). Limits absolute number of entries. --> <value>${activities.feed.max.idRange}</value> <!-- max ID range between max(id) and min(id). Limits absolute number of entries. -->
</property> </property>
@@ -100,6 +101,8 @@
<property name="subscriptionService" ref="SubscriptionService"/> <property name="subscriptionService" ref="SubscriptionService"/>
<property name="tenantService" ref="tenantService"/> <property name="tenantService" ref="tenantService"/>
<property name="userNamesAreCaseSensitive" value="${user.name.caseSensitive}"/>
<property name="templateSearchPaths"> <property name="templateSearchPaths">
<list> <list>
<value>alfresco/extension/templates/activities</value> <value>alfresco/extension/templates/activities</value>

View File

@@ -233,6 +233,11 @@ public class ActivityPostServiceImpl implements ActivityPostService
{ {
Date postDate = new Date(); Date postDate = new Date();
ActivityPostEntity activityPost = new ActivityPostEntity(); ActivityPostEntity activityPost = new ActivityPostEntity();
//MNT-9104 If username contains uppercase letters the action of joining a site will not be displayed in "My activities"
if (! userNamesAreCaseSensitive)
{
userId = userId.toLowerCase();
}
activityPost.setUserId(userId); activityPost.setUserId(userId);
activityPost.setSiteNetwork(tenantService.getName(siteId)); activityPost.setSiteNetwork(tenantService.getName(siteId));

View File

@@ -624,6 +624,11 @@ public class ActivityServiceImpl implements ActivityService, InitializingBean
{ {
logger.debug("Inserting feed control for siteId: " + feedControl.getSiteId() + ",\n appToolId : " + feedControl.getAppToolId() + ",\n for user : " + userId); logger.debug("Inserting feed control for siteId: " + feedControl.getSiteId() + ",\n appToolId : " + feedControl.getAppToolId() + ",\n for user : " + userId);
} }
//MNT-9104 If username contains uppercase letters the action of joining a site will not be displayed in "My activities"
if (! userNamesAreCaseSensitive)
{
userId = userId.toLowerCase();
}
feedControlDAO.insertFeedControl(new FeedControlEntity(userId, feedControl)); feedControlDAO.insertFeedControl(new FeedControlEntity(userId, feedControl));
} }
} }
@@ -673,6 +678,11 @@ public class ActivityServiceImpl implements ActivityService, InitializingBean
{ {
ParameterCheck.mandatoryString("userId", userId); ParameterCheck.mandatoryString("userId", userId);
if (!userNamesAreCaseSensitive)
{
userId = userId.toLowerCase();
}
try try
{ {
List<FeedControlEntity> feedControlDaos = feedControlDAO.selectFeedControls(userId); List<FeedControlEntity> feedControlDaos = feedControlDAO.selectFeedControls(userId);
@@ -721,6 +731,12 @@ public class ActivityServiceImpl implements ActivityService, InitializingBean
{ {
logger.debug("Deleting feed control for siteId: " + feedControl.getSiteId() + ",\n appToolId : " + feedControl.getAppToolId() + ",\n for user : " + userId); logger.debug("Deleting feed control for siteId: " + feedControl.getSiteId() + ",\n appToolId : " + feedControl.getAppToolId() + ",\n for user : " + userId);
} }
// MNT-9104 If username contains uppercase letters the action of joining a site will not be displayed in "My activities"
if (!userNamesAreCaseSensitive)
{
userId = userId.toLowerCase();
}
feedControlDAO.deleteFeedControl(new FeedControlEntity(userId, feedControl)); feedControlDAO.deleteFeedControl(new FeedControlEntity(userId, feedControl));
} }
catch (SQLException e) catch (SQLException e)
@@ -746,6 +762,12 @@ public class ActivityServiceImpl implements ActivityService, InitializingBean
{ {
logger.debug("Selecting feed control for siteId: " + feedControl.getSiteId() + ",\n appToolId : " + feedControl.getAppToolId() + ",\n for user : " + userId); logger.debug("Selecting feed control for siteId: " + feedControl.getSiteId() + ",\n appToolId : " + feedControl.getAppToolId() + ",\n for user : " + userId);
} }
// MNT-9104 If username contains uppercase letters the action of joining a site will not be displayed in "My activities"
if (!userNamesAreCaseSensitive)
{
userId = userId.toLowerCase();
}
long id = feedControlDAO.selectFeedControl(new FeedControlEntity(userId, feedControl)); long id = feedControlDAO.selectFeedControl(new FeedControlEntity(userId, feedControl));
boolean exists = (id != -1); boolean exists = (id != -1);
if (logger.isDebugEnabled()) if (logger.isDebugEnabled())

View File

@@ -81,6 +81,13 @@ public abstract class FeedTaskProcessor
private static final String URL_SERVICE_TEMPLATES = "/api/activities/templates"; private static final String URL_SERVICE_TEMPLATES = "/api/activities/templates";
private static final String URL_SERVICE_TEMPLATE = "/api/activities/template"; private static final String URL_SERVICE_TEMPLATE = "/api/activities/template";
private boolean userNamesAreCaseSensitive = false;
public void setUserNamesAreCaseSensitive(boolean userNamesAreCaseSensitive)
{
this.userNamesAreCaseSensitive = userNamesAreCaseSensitive;
}
public void process(int jobTaskNode, long minSeq, long maxSeq, RepoCtx ctx) throws Exception public void process(int jobTaskNode, long minSeq, long maxSeq, RepoCtx ctx) throws Exception
{ {
long startTime = System.currentTimeMillis(); long startTime = System.currentTimeMillis();
@@ -245,6 +252,12 @@ public abstract class FeedTaskProcessor
ActivityFeedEntity feed = new ActivityFeedEntity(); ActivityFeedEntity feed = new ActivityFeedEntity();
// Generate activity feed summary // Generate activity feed summary
//MNT-9104 If username contains uppercase letters the action of joining a site will not be displayed in "My activities"
if (! userNamesAreCaseSensitive)
{
recipient = recipient.toLowerCase();
postingUserId = postingUserId.toLowerCase();
}
feed.setFeedUserId(recipient); feed.setFeedUserId(recipient);
feed.setPostUserId(postingUserId); feed.setPostUserId(postingUserId);
feed.setActivityType(activityType); feed.setActivityType(activityType);
@@ -618,6 +631,12 @@ public abstract class FeedTaskProcessor
protected List<FeedControlEntity> getFeedControls(String connectedUser) throws SQLException protected List<FeedControlEntity> getFeedControls(String connectedUser) throws SQLException
{ {
//MNT-9104 If username contains uppercase letters the action of joining a site will not be displayed in "My activities"
if (! userNamesAreCaseSensitive)
{
connectedUser = connectedUser.toLowerCase();
}
return selectUserFeedControls(connectedUser); return selectUserFeedControls(connectedUser);
} }

View File

@@ -68,6 +68,7 @@ public class FeedCleaner implements NodeServicePolicies.BeforeDeleteNodePolicy
private int maxIdRange = 1000000; private int maxIdRange = 1000000;
private int maxAgeMins = 0; private int maxAgeMins = 0;
private int maxFeedSize = 100; private int maxFeedSize = 100;
private boolean userNamesAreCaseSensitive = false;
private ActivityFeedDAO feedDAO; private ActivityFeedDAO feedDAO;
@@ -80,6 +81,10 @@ public class FeedCleaner implements NodeServicePolicies.BeforeDeleteNodePolicy
private FeedCleanerDeleteSiteTransactionListener deleteSiteTransactionListener; private FeedCleanerDeleteSiteTransactionListener deleteSiteTransactionListener;
private FeedCleanerDeletePersonTransactionListener deletePersonTransactionListener; private FeedCleanerDeletePersonTransactionListener deletePersonTransactionListener;
public void setUserNamesAreCaseSensitive(boolean userNamesAreCaseSensitive)
{
this.userNamesAreCaseSensitive = userNamesAreCaseSensitive;
}
public void setFeedDAO(ActivityFeedDAO feedDAO) public void setFeedDAO(ActivityFeedDAO feedDAO)
{ {
@@ -430,7 +435,11 @@ public class FeedCleaner implements NodeServicePolicies.BeforeDeleteNodePolicy
public void beforeDeleteNodePerson(NodeRef personNodeRef) public void beforeDeleteNodePerson(NodeRef personNodeRef)
{ {
String userId = (String)nodeService.getProperty(personNodeRef, ContentModel.PROP_USERNAME); String userId = (String)nodeService.getProperty(personNodeRef, ContentModel.PROP_USERNAME);
//MNT-9104 If username contains uppercase letters the action of joining a site will not be displayed in "My activities"
if (! userNamesAreCaseSensitive)
{
userId = userId.toLowerCase();
}
Set<String> deletedUserIds = (Set<String>)AlfrescoTransactionSupport.getResource(KEY_DELETED_USER_IDS); Set<String> deletedUserIds = (Set<String>)AlfrescoTransactionSupport.getResource(KEY_DELETED_USER_IDS);
if (deletedUserIds == null) if (deletedUserIds == null)
{ {
@@ -503,8 +512,19 @@ public class FeedCleaner implements NodeServicePolicies.BeforeDeleteNodePolicy
Set<String> deletedUserIds = TransactionalResourceHelper.getSet(KEY_DELETED_USER_IDS); Set<String> deletedUserIds = TransactionalResourceHelper.getSet(KEY_DELETED_USER_IDS);
if (deletedUserIds != null) if (deletedUserIds != null)
{ {
for (final String userId : deletedUserIds) for (String user : deletedUserIds)
{ {
//MNT-9104 If username contains uppercase letters the action of joining a site will not be displayed in "My activities"
final String userId;
if (! userNamesAreCaseSensitive)
{
userId = user.toLowerCase();
}
else
{
userId = user;
}
transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>() transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>()
{ {
public Void execute() throws Throwable public Void execute() throws Throwable

View File

@@ -18,11 +18,11 @@
*/ */
package org.alfresco.repo.activities; package org.alfresco.repo.activities;
import static org.junit.Assert.*;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import junit.framework.TestCase;
import org.alfresco.model.ContentModel; import org.alfresco.model.ContentModel;
import org.alfresco.repo.activities.feed.FeedGenerator; import org.alfresco.repo.activities.feed.FeedGenerator;
import org.alfresco.repo.activities.feed.local.LocalFeedTaskProcessor; import org.alfresco.repo.activities.feed.local.LocalFeedTaskProcessor;
@@ -37,30 +37,27 @@ import org.alfresco.service.cmr.security.MutableAuthenticationService;
import org.alfresco.service.cmr.security.PersonService; import org.alfresco.service.cmr.security.PersonService;
import org.alfresco.service.cmr.site.SiteService; import org.alfresco.service.cmr.site.SiteService;
import org.alfresco.service.cmr.site.SiteVisibility; import org.alfresco.service.cmr.site.SiteVisibility;
import org.alfresco.util.ApplicationContextHelper;
import org.alfresco.util.PropertyMap; import org.alfresco.util.PropertyMap;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.Test;
import org.quartz.Scheduler; import org.quartz.Scheduler;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
/** /**
* Simple Activity Service unit test using site (membership) activities * Simple Activity Service unit test using site (membership) activities
* *
* @author janv * @author janv
*/ */
public class SiteActivityTest extends TestCase public abstract class AbstractSiteActivityTest
{ {
private static Log logger = LogFactory.getLog(SiteActivityTest.class); private static Log logger = LogFactory.getLog(AbstractSiteActivityTest.class);
private static final String[] CONFIG_LOCATIONS = private ApplicationContext applicationContext;
{
"classpath:alfresco/application-context.xml"
//, "classpath:alfresco/subsystems/ActivitiesFeed/default/activities-feed-context.xml"
};
private static ApplicationContext applicationContext = new ClassPathXmlApplicationContext(
SiteActivityTest.CONFIG_LOCATIONS);
private SiteService siteService; private SiteService siteService;
private ActivityService activityService; private ActivityService activityService;
@@ -99,14 +96,14 @@ public class SiteActivityTest extends TestCase
private static boolean membersRemoved = false; private static boolean membersRemoved = false;
private static boolean controlsCreated = false; private static boolean controlsCreated = false;
public SiteActivityTest() public AbstractSiteActivityTest()
{ {
} }
@Override @Before
protected void setUp() throws Exception public void setUp() throws Exception
{ {
super.setUp(); applicationContext = ApplicationContextHelper.getApplicationContext();
String testid = ""+System.currentTimeMillis(); String testid = ""+System.currentTimeMillis();
// Let's shut down the scheduler so that we aren't competing with the scheduled versions of the post lookup and // Let's shut down the scheduler so that we aren't competing with the scheduled versions of the post lookup and
@@ -143,10 +140,10 @@ public class SiteActivityTest extends TestCase
site2 = "test_site2_" + testid; site2 = "test_site2_" + testid;
site3 = "test_site3_" + testid; site3 = "test_site3_" + testid;
user1 = "test_user1_" + testid; user1 = "Test_User1_" + testid;
user2 = "test_user2_" + testid; user2 = "Test_User2_" + testid;
user3 = "test_user3_" + testid; user3 = "Test_User3_" + testid;
user4 = "test_user4_" + testid; user4 = "Test_User4_" + testid;
// create users // create users
@@ -168,8 +165,8 @@ public class SiteActivityTest extends TestCase
createSite(site3, false); createSite(site3, false);
} }
@Override @After
protected void tearDown() throws Exception public void tearDown() throws Exception
{ {
login(ADMIN_USER, ADMIN_PW); login(ADMIN_USER, ADMIN_PW);
@@ -185,8 +182,6 @@ public class SiteActivityTest extends TestCase
membersAddedUpdated = false; membersAddedUpdated = false;
membersRemoved = false; membersRemoved = false;
controlsCreated = false; controlsCreated = false;
super.tearDown();
} }
protected void createSite(String siteId, boolean isPublic) throws Exception protected void createSite(String siteId, boolean isPublic) throws Exception
@@ -205,6 +200,22 @@ public class SiteActivityTest extends TestCase
siteService.deleteSite(siteId); siteService.deleteSite(siteId);
} }
@Test
//MNT-9104 If username contains uppercase letters the action of joining a site will not be displayed in "My activities"
public void testUserActivitiesOnSite() throws Exception
{
login(ADMIN_USER, ADMIN_PW);
addMembership(site1, user4, SiteModel.SITE_CONSUMER);
generateFeed();
login(user4, USER_PW);
getUserFeed(user4, site1, false, false, true, 1);
}
@Test
public void testGetSiteFeedsBefore() throws Exception public void testGetSiteFeedsBefore() throws Exception
{ {
login(ADMIN_USER, ADMIN_PW); login(ADMIN_USER, ADMIN_PW);
@@ -245,6 +256,7 @@ public class SiteActivityTest extends TestCase
assertEquals(expectedCount, activityService.getSiteFeedEntries(siteId).size()); assertEquals(expectedCount, activityService.getSiteFeedEntries(siteId).size());
} }
@Test
public void testGetUserFeedsBefore() throws Exception public void testGetUserFeedsBefore() throws Exception
{ {
// as admin // as admin
@@ -305,6 +317,7 @@ public class SiteActivityTest extends TestCase
assertEquals(expectedCount, activityService.getUserFeedEntries(userId, siteId, excludeThisUser, excludeOtherUsers, null, null).size()); assertEquals(expectedCount, activityService.getUserFeedEntries(userId, siteId, excludeThisUser, excludeOtherUsers, null, null).size());
} }
@Test
public void testUserFeedControls() throws Exception public void testUserFeedControls() throws Exception
{ {
if (! controlsCreated) if (! controlsCreated)
@@ -327,6 +340,7 @@ public class SiteActivityTest extends TestCase
} }
} }
@Test
public void testAddAndUpdateMemberships() throws Exception public void testAddAndUpdateMemberships() throws Exception
{ {
if (! membersAddedUpdated) if (! membersAddedUpdated)
@@ -343,6 +357,7 @@ public class SiteActivityTest extends TestCase
} }
} }
@Test
public void testGetSiteFeedsAfterAddAndUpdateMemberships() throws Exception public void testGetSiteFeedsAfterAddAndUpdateMemberships() throws Exception
{ {
testAddAndUpdateMemberships(); testAddAndUpdateMemberships();
@@ -369,6 +384,8 @@ public class SiteActivityTest extends TestCase
// ignore // ignore
} }
} }
@Test
public void testRemoveMemberships() throws Exception public void testRemoveMemberships() throws Exception
{ {
if (! membersRemoved) if (! membersRemoved)
@@ -420,6 +437,7 @@ public class SiteActivityTest extends TestCase
activityService.setFeedControl(new FeedControl(siteId, appToolId)); activityService.setFeedControl(new FeedControl(siteId, appToolId));
} }
@Test
public void testGetSiteFeedsAfterRemoveMemberships() throws Exception public void testGetSiteFeedsAfterRemoveMemberships() throws Exception
{ {
testAddAndUpdateMemberships(); testAddAndUpdateMemberships();
@@ -458,6 +476,7 @@ public class SiteActivityTest extends TestCase
} }
} }
@Test
public void testGetUserFeedsAfter() throws Exception public void testGetUserFeedsAfter() throws Exception
{ {
testUserFeedControls(); testUserFeedControls();
@@ -566,4 +585,11 @@ public class SiteActivityTest extends TestCase
postLookup.execute(); postLookup.execute();
feedGenerator.execute(); feedGenerator.execute();
} }
@AfterClass
// remove system "user.name.caseSensitive" property
public static void afterClass()
{
System.clearProperty("user.name.caseSensitive");
}
} }

View File

@@ -0,0 +1,9 @@
package org.alfresco.repo.activities;
public class SiteActivityTestCaseInsensitivity extends AbstractSiteActivityTest
{
static
{
System.setProperty("user.name.caseSensitive", "false");
}
}

View File

@@ -0,0 +1,9 @@
package org.alfresco.repo.activities;
public class SiteActivityTestCaseSensitivity extends AbstractSiteActivityTest
{
static
{
System.setProperty("user.name.caseSensitive", "true");
}
}

View File

@@ -18,6 +18,8 @@
*/ */
package org.alfresco.repo.activities.feed.cleanup; package org.alfresco.repo.activities.feed.cleanup;
import static org.junit.Assert.*;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.io.StringWriter; import java.io.StringWriter;
import java.util.Date; import java.util.Date;
@@ -37,6 +39,10 @@ import org.alfresco.service.cmr.site.SiteService;
import org.alfresco.service.cmr.site.SiteVisibility; import org.alfresco.service.cmr.site.SiteVisibility;
import org.alfresco.util.ApplicationContextHelper; import org.alfresco.util.ApplicationContextHelper;
import org.alfresco.util.PropertyMap; import org.alfresco.util.PropertyMap;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.Test;
import org.quartz.Scheduler; import org.quartz.Scheduler;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
@@ -46,16 +52,16 @@ import org.springframework.context.ApplicationContext;
* @author janv * @author janv
* @since 3.0 * @since 3.0
*/ */
public class FeedCleanerTest extends TestCase public abstract class AbstractFeedCleanerTest
{ {
private static ApplicationContext ctx = ApplicationContextHelper.getApplicationContext(); private ApplicationContext ctx;
private ActivityFeedDAO feedDAO; private ActivityFeedDAO feedDAO;
private FeedCleaner cleaner; protected FeedCleaner cleaner;
private SiteService siteService; private SiteService siteService;
private PersonService personService; private PersonService personService;
protected RetryingTransactionHelper transactionHelper; protected RetryingTransactionHelper transactionHelper;
private static final String TEST_SITE = "testSite"; private static final String TEST_SITE = "testSite";
private static final String TEST_SITE_1 = TEST_SITE+"1"; private static final String TEST_SITE_1 = TEST_SITE+"1";
@@ -70,12 +76,13 @@ public class FeedCleanerTest extends TestCase
private static final String TEST_USER_B = "testUserB"; private static final String TEST_USER_B = "testUserB";
private static final String TEST_USER_C = "testUserC"; private static final String TEST_USER_C = "testUserC";
private static final String TEST_USER_D = "testUserD"; private static final String TEST_USER_D = "testUserD";
private static final String TEST_USER_E = "testUserE"; protected static final String TEST_USER_E = "testUserE";
private static final String TEST_USER_F = "testUserF"; private static final String TEST_USER_F = "testUserF";
@Override @Before
public void setUp() throws Exception public void setUp() throws Exception
{ {
ctx = ApplicationContextHelper.getApplicationContext();
JobLockService jobLockService = (JobLockService) ctx.getBean("JobLockService"); JobLockService jobLockService = (JobLockService) ctx.getBean("JobLockService");
PolicyComponent policyComponent = (PolicyComponent) ctx.getBean("policyComponent"); PolicyComponent policyComponent = (PolicyComponent) ctx.getBean("policyComponent");
NodeService nodeService = (NodeService) ctx.getBean("NodeService"); NodeService nodeService = (NodeService) ctx.getBean("NodeService");
@@ -84,7 +91,7 @@ public class FeedCleanerTest extends TestCase
personService = (PersonService) ctx.getBean("PersonService"); personService = (PersonService) ctx.getBean("PersonService");
feedDAO = (ActivityFeedDAO) ctx.getBean("feedDAO"); feedDAO = (ActivityFeedDAO) ctx.getBean("feedDAO");
transactionHelper = (RetryingTransactionHelper)ctx.getBean("retryingTransactionHelper"); transactionHelper = (RetryingTransactionHelper)ctx.getBean("retryingTransactionHelper");
// Let's shut down the scheduler so that we aren't competing with the scheduled versions of jobs (ie. feed cleaner) // Let's shut down the scheduler so that we aren't competing with the scheduled versions of jobs (ie. feed cleaner)
Scheduler scheduler = (Scheduler) ctx.getBean("schedulerFactory"); Scheduler scheduler = (Scheduler) ctx.getBean("schedulerFactory");
scheduler.shutdown(); scheduler.shutdown();
@@ -107,6 +114,7 @@ public class FeedCleanerTest extends TestCase
cleaner.setNodeService(nodeService); cleaner.setNodeService(nodeService);
} }
@After
public void tearDown() throws Exception public void tearDown() throws Exception
{ {
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName()); AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
@@ -130,6 +138,7 @@ public class FeedCleanerTest extends TestCase
// NOOP // NOOP
} }
@Test
public void testMaxIdRange() throws Exception public void testMaxIdRange() throws Exception
{ {
// insert site feed entries for TEST_SITE_4 // insert site feed entries for TEST_SITE_4
@@ -154,6 +163,8 @@ public class FeedCleanerTest extends TestCase
// Check // Check
assertEquals(5, feedDAO.selectSiteFeedEntries(TEST_SITE_4, -1).size()); assertEquals(5, feedDAO.selectSiteFeedEntries(TEST_SITE_4, -1).size());
} }
@Test
public void testMaxAge() throws Exception public void testMaxAge() throws Exception
{ {
cleaner.setMaxFeedSize(0); cleaner.setMaxFeedSize(0);
@@ -199,7 +210,7 @@ public class FeedCleanerTest extends TestCase
feedEntry.setPostDate(new Date()); // now feedEntry.setPostDate(new Date()); // now
feedEntry.setSiteNetwork(TEST_SITE_3); feedEntry.setSiteNetwork(TEST_SITE_3);
feedEntry.setActivityType("testActivityType"); feedEntry.setActivityType("testActivityType");
feedEntry.setPostUserId(TEST_USER_A); feedEntry.setPostUserId(TEST_USER_A);
feedEntry.setFeedUserId(TEST_USER_B); feedEntry.setFeedUserId(TEST_USER_B);
feedEntry.setFeedDate(new Date()); feedEntry.setFeedDate(new Date());
@@ -217,10 +228,11 @@ public class FeedCleanerTest extends TestCase
assertEquals(1, feedDAO.selectUserFeedEntries(TEST_USER_B, null, false, false, -1L, -1).size()); assertEquals(1, feedDAO.selectUserFeedEntries(TEST_USER_B, null, false, false, -1L, -1).size());
} }
@Test
public void testMaxSize() throws Exception public void testMaxSize() throws Exception
{ {
cleaner.setMaxAgeMins(0); cleaner.setMaxAgeMins(0);
// insert site feed entries for TEST_SITE_4 // insert site feed entries for TEST_SITE_4
for (int i = 0; i < 10; i++) for (int i = 0; i < 10; i++)
@@ -310,6 +322,7 @@ public class FeedCleanerTest extends TestCase
assertEquals(10, feedDAO.selectUserFeedEntries(TEST_USER_F, null, false, false, -1L, -1).size()); assertEquals(10, feedDAO.selectUserFeedEntries(TEST_USER_F, null, false, false, -1L, -1).size());
} }
@Test
public void testSiteDelete() throws Exception public void testSiteDelete() throws Exception
{ {
cleaner.setMaxAgeMins(100); cleaner.setMaxAgeMins(100);
@@ -348,7 +361,7 @@ public class FeedCleanerTest extends TestCase
feedEntry.setPostDate(new Date(System.currentTimeMillis()-(i*60*1000L))); feedEntry.setPostDate(new Date(System.currentTimeMillis()-(i*60*1000L)));
feedEntry.setSiteNetwork(TEST_SITE_5); feedEntry.setSiteNetwork(TEST_SITE_5);
feedEntry.setActivityType("testActivityType"); feedEntry.setActivityType("testActivityType");
feedEntry.setPostUserId(TEST_USER_C); feedEntry.setPostUserId(TEST_USER_C);
feedEntry.setFeedUserId(TEST_USER_D); feedEntry.setFeedUserId(TEST_USER_D);
feedEntry.setFeedDate(new Date()); feedEntry.setFeedDate(new Date());
@@ -378,14 +391,28 @@ public class FeedCleanerTest extends TestCase
}, false, true); }, false, true);
} }
@Test
public void testPersonDelete() throws Exception public void testPersonDelete() throws Exception
{
boolean caseSensitive = Boolean.getBoolean(System.getProperty("user.name.caseSensitive"));
if (caseSensitive)
{
testPersonDelete(TEST_USER_E);
}
else
{
testPersonDelete(TEST_USER_E.toLowerCase());
}
}
protected void testPersonDelete(final String userId) throws Exception
{ {
cleaner.setMaxAgeMins(100); cleaner.setMaxAgeMins(100);
createPerson(TEST_USER_E); // ignore result createPerson(userId); // ignore result
assertEquals(0, feedDAO.selectSiteFeedEntries(TEST_SITE_6, -1).size()); assertEquals(0, feedDAO.selectSiteFeedEntries(TEST_SITE_6, -1).size());
assertEquals(0, feedDAO.selectUserFeedEntries(TEST_USER_E, null, false, false, -1L, -1).size()); assertEquals(0, feedDAO.selectUserFeedEntries(userId, null, false, false, -1L, -1).size());
final int site6FeedCnt = 10; final int site6FeedCnt = 10;
@@ -397,16 +424,16 @@ public class FeedCleanerTest extends TestCase
feedEntry.setPostDate(new Date(System.currentTimeMillis()-(i*60*1000L))); feedEntry.setPostDate(new Date(System.currentTimeMillis()-(i*60*1000L)));
feedEntry.setSiteNetwork(TEST_SITE_6); feedEntry.setSiteNetwork(TEST_SITE_6);
feedEntry.setActivityType("testActivityType"); feedEntry.setActivityType("testActivityType");
feedEntry.setPostUserId(TEST_USER_E); feedEntry.setPostUserId(userId);
feedEntry.setFeedUserId(""); feedEntry.setFeedUserId("");
feedEntry.setFeedDate(new Date()); feedEntry.setFeedDate(new Date());
//bypassing FeedTaskProcessor.process() call feedDAO.insertFeedEntry()
feedDAO.insertFeedEntry(feedEntry); // for TEST_SITE_6 site feed feedDAO.insertFeedEntry(feedEntry); // for TEST_SITE_6 site feed
feedEntry.setFeedUserId(TEST_USER_E); // for TEST_USER_E user feed feedEntry.setFeedUserId(userId); // for TEST_USER_E user feed
feedEntry.setFeedDate(new Date()); feedEntry.setFeedDate(new Date());
//bypassing FeedTaskProcessor.process() call feedDAO.insertFeedEntry()
feedDAO.insertFeedEntry(feedEntry); feedDAO.insertFeedEntry(feedEntry);
} }
final int site7FeedCnt = 5; final int site7FeedCnt = 5;
@@ -418,26 +445,26 @@ public class FeedCleanerTest extends TestCase
feedEntry.setPostDate(new Date(System.currentTimeMillis()-(i*60*1000L))); feedEntry.setPostDate(new Date(System.currentTimeMillis()-(i*60*1000L)));
feedEntry.setSiteNetwork(TEST_SITE_7); feedEntry.setSiteNetwork(TEST_SITE_7);
feedEntry.setActivityType("testActivityType"); feedEntry.setActivityType("testActivityType");
feedEntry.setPostUserId(TEST_USER_E); feedEntry.setPostUserId(userId);
feedEntry.setFeedUserId(""); feedEntry.setFeedUserId("");
feedEntry.setFeedDate(new Date()); feedEntry.setFeedDate(new Date());
//bypassing FeedTaskProcessor.process() call feedDAO.insertFeedEntry()
feedDAO.insertFeedEntry(feedEntry); // for TEST_SITE_7 site feed feedDAO.insertFeedEntry(feedEntry); // for TEST_SITE_7 site feed
feedEntry.setFeedUserId(TEST_USER_E); // for TEST_USER_E user feed feedEntry.setFeedUserId(userId); // for TEST_USER_E user feed
feedEntry.setFeedDate(new Date()); feedEntry.setFeedDate(new Date());
//bypassing FeedTaskProcessor.process() call feedDAO.insertFeedEntry()
feedDAO.insertFeedEntry(feedEntry); feedDAO.insertFeedEntry(feedEntry);
} }
assertEquals(site6FeedCnt, feedDAO.selectSiteFeedEntries(TEST_SITE_6, -1).size()); assertEquals(site6FeedCnt, feedDAO.selectSiteFeedEntries(TEST_SITE_6, -1).size());
assertEquals(site7FeedCnt, feedDAO.selectSiteFeedEntries(TEST_SITE_7, -1).size()); assertEquals(site7FeedCnt, feedDAO.selectSiteFeedEntries(TEST_SITE_7, -1).size());
assertEquals(site6FeedCnt+site7FeedCnt, feedDAO.selectUserFeedEntries(TEST_USER_E, null, false, false, -1L, -1).size()); assertEquals(site6FeedCnt+site7FeedCnt, feedDAO.selectUserFeedEntries(userId, null, false, false, -1L, -1).size());
// delete the person // delete the person
personService.deletePerson(TEST_USER_E); personService.deletePerson(userId);
// note: site feed cleanup is done in separate txn after commit // note: site feed cleanup is done in separate txn after commit
transactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>() transactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>()
{ {
@@ -446,11 +473,11 @@ public class FeedCleanerTest extends TestCase
assertEquals(site6FeedCnt, feedDAO.selectSiteFeedEntries(TEST_SITE_6, -1).size()); assertEquals(site6FeedCnt, feedDAO.selectSiteFeedEntries(TEST_SITE_6, -1).size());
assertEquals(site7FeedCnt, feedDAO.selectSiteFeedEntries(TEST_SITE_7, -1).size()); assertEquals(site7FeedCnt, feedDAO.selectSiteFeedEntries(TEST_SITE_7, -1).size());
assertEquals(0, feedDAO.selectUserFeedEntries(TEST_USER_E, null, false, false, -1L, -1).size()); assertEquals(0, feedDAO.selectUserFeedEntries(userId, null, false, false, -1L, -1).size());
assertTrue(createPerson(TEST_USER_E)); assertTrue(createPerson(userId));
assertEquals(0, feedDAO.selectUserFeedEntries(TEST_USER_E, null, false, false, -1L, -1).size()); assertEquals(0, feedDAO.selectUserFeedEntries(userId, null, false, false, -1L, -1).size());
return null; return null;
} }
}, false, true); }, false, true);
@@ -476,6 +503,7 @@ public class FeedCleanerTest extends TestCase
return false; // already exists return false; // already exists
} }
@Test
public void testConcurrentAccessAndRemoval() throws Exception public void testConcurrentAccessAndRemoval() throws Exception
{ {
cleaner.setMaxAgeMins(1); cleaner.setMaxAgeMins(1);
@@ -604,4 +632,11 @@ public class FeedCleanerTest extends TestCase
} }
} }
} }
@AfterClass
// remove system "user.name.caseSensitive" property
public static void afterClass()
{
System.clearProperty("user.name.caseSensitive");
}
} }

View File

@@ -0,0 +1,10 @@
package org.alfresco.repo.activities.feed.cleanup;
public class FeedCleanerTestCaseInsensitivity extends AbstractFeedCleanerTest
{
static
{
System.setProperty("user.name.caseSensitive", "false");
}
}

View File

@@ -0,0 +1,10 @@
package org.alfresco.repo.activities.feed.cleanup;
public class FeedCleanerTestCaseSensitivity extends AbstractFeedCleanerTest
{
static
{
System.setProperty("user.name.caseSensitive", "true");
}
}