From f367dd8e742e5e8f96d8e79bd1df82441af4cc4c Mon Sep 17 00:00:00 2001 From: Jan Vonka Date: Mon, 26 Apr 2010 15:42:35 +0000 Subject: [PATCH] Unit test fix for PostgreSQL (which does not support '\u0000' embedded in a string) git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@19992 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../repo/search/SearcherComponentTest.java | 15 +++++++++++++ .../search/impl/lucene/ADMLuceneTest.java | 15 ++++++++++++- .../authentication/AuthenticationTest.java | 22 +++++++++++++++---- 3 files changed, 47 insertions(+), 5 deletions(-) diff --git a/source/java/org/alfresco/repo/search/SearcherComponentTest.java b/source/java/org/alfresco/repo/search/SearcherComponentTest.java index 8547472dba..933b9d1e86 100644 --- a/source/java/org/alfresco/repo/search/SearcherComponentTest.java +++ b/source/java/org/alfresco/repo/search/SearcherComponentTest.java @@ -44,6 +44,8 @@ import org.alfresco.service.namespace.QName; import org.alfresco.service.transaction.TransactionService; import org.alfresco.util.ApplicationContextHelper; import org.alfresco.util.ISO9075; +import org.hibernate.dialect.Dialect; +import org.hibernate.dialect.PostgreSQLDialect; import org.springframework.context.ApplicationContext; /** @@ -63,6 +65,8 @@ public class SearcherComponentTest extends TestCase private static String COMPLEX_LOCAL_NAME = "\u0020\u0060\u00ac\u00a6\u0021\"\u00a3\u0024\u0025\u005e\u0026\u002a\u0028\u0029\u002d\u005f\u003d\u002b\t\n\\\u0000\u005b\u005d\u007b\u007d\u003b\u0027\u0023\u003a\u0040\u007e\u002c\u002e\u002f\u003c\u003e\u003f\\u007c\u005f\u0078\u0054\u0036\u0035\u0041\u005f"; + private static String COMPLEX_LOCAL_NAME_NO_U0000 = "\u0020\u0060\u00ac\u00a6\u0021\"\u00a3\u0024\u0025\u005e\u0026\u002a\u0028\u0029\u002d\u005f\u003d\u002b\t\n\\\u005b\u005d\u007b\u007d\u003b\u0027\u0023\u003a\u0040\u007e\u002c\u002e\u002f\u003c\u003e\u003f\\u007c\u005f\u0078\u0054\u0036\u0035\u0041\u005f"; + private ServiceRegistry serviceRegistry; @@ -79,9 +83,20 @@ public class SearcherComponentTest extends TestCase private NodeRef rootNodeRef; private UserTransaction txn; + + // TODO: pending replacement + private Dialect dialect; public void setUp() throws Exception { + dialect = (Dialect) ctx.getBean("dialect"); + if (dialect instanceof PostgreSQLDialect) + { + // Note: PostgreSQL does not support \u0000 char embedded in a string + // http://archives.postgresql.org/pgsql-jdbc/2007-02/msg00115.php + COMPLEX_LOCAL_NAME = COMPLEX_LOCAL_NAME_NO_U0000; + } + serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY); transactionService = serviceRegistry.getTransactionService(); dictionaryService = BaseNodeServiceTest.loadModel(ctx); diff --git a/source/java/org/alfresco/repo/search/impl/lucene/ADMLuceneTest.java b/source/java/org/alfresco/repo/search/impl/lucene/ADMLuceneTest.java index 95efbdddb9..d77464109e 100644 --- a/source/java/org/alfresco/repo/search/impl/lucene/ADMLuceneTest.java +++ b/source/java/org/alfresco/repo/search/impl/lucene/ADMLuceneTest.java @@ -97,6 +97,8 @@ import org.alfresco.util.CachingDateFormat; import org.alfresco.util.ISO9075; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.hibernate.dialect.Dialect; +import org.hibernate.dialect.PostgreSQLDialect; import org.springframework.context.ApplicationContext; import org.springframework.extensions.surf.util.I18NUtil; @@ -210,6 +212,9 @@ public class ADMLuceneTest extends TestCase implements DictionaryListener private NodeRef n15; private M2Model model; + + // TODO: pending replacement + private Dialect dialect; /** * @@ -240,6 +245,8 @@ public class ADMLuceneTest extends TestCase implements DictionaryListener public void setUp() throws Exception { + dialect = (Dialect) ctx.getBean("dialect"); + nodeService = (NodeService) ctx.getBean("dbNodeService"); dictionaryService = (DictionaryService) ctx.getBean("dictionaryService"); dictionaryDAO = (DictionaryDAO) ctx.getBean("dictionaryDAO"); @@ -5927,7 +5934,13 @@ public class ADMLuceneTest extends TestCase implements DictionaryListener public void testAddEscapedChild() throws Exception { String COMPLEX_LOCAL_NAME = "\u0020\u0060\u00ac\u00a6\u0021\"\u00a3\u0024\u0025\u005e\u0026\u002a\u0028\u0029\u002d\u005f\u003d\u002b\t\n\\\u0000\u005b\u005d\u007b\u007d\u003b\u0027\u0023\u003a\u0040\u007e\u002c\u002e\u002f\u003c\u003e\u003f\\u007c\u005f\u0078\u0054\u0036\u0035\u0041\u005f"; - + if (dialect instanceof PostgreSQLDialect) + { + // Note: PostgreSQL does not support \u0000 char embedded in a string + // http://archives.postgresql.org/pgsql-jdbc/2007-02/msg00115.php + COMPLEX_LOCAL_NAME = "\u0020\u0060\u00ac\u00a6\u0021\"\u00a3\u0024\u0025\u005e\u0026\u002a\u0028\u0029\u002d\u005f\u003d\u002b\t\n\\\u005b\u005d\u007b\u007d\u003b\u0027\u0023\u003a\u0040\u007e\u002c\u002e\u002f\u003c\u003e\u003f\\u007c\u005f\u0078\u0054\u0036\u0035\u0041\u005f"; + } + luceneFTS.pause(); buildBaseIndex(); runBaseTests(); diff --git a/source/java/org/alfresco/repo/security/authentication/AuthenticationTest.java b/source/java/org/alfresco/repo/security/authentication/AuthenticationTest.java index d925d420d3..baab37819f 100644 --- a/source/java/org/alfresco/repo/security/authentication/AuthenticationTest.java +++ b/source/java/org/alfresco/repo/security/authentication/AuthenticationTest.java @@ -62,6 +62,8 @@ import org.alfresco.service.namespace.NamespaceService; import org.alfresco.service.namespace.QName; import org.alfresco.service.transaction.TransactionService; import org.alfresco.util.ApplicationContextHelper; +import org.hibernate.dialect.Dialect; +import org.hibernate.dialect.PostgreSQLDialect; import org.springframework.context.ApplicationContext; @SuppressWarnings("unchecked") @@ -112,6 +114,9 @@ public class AuthenticationTest extends TestCase private PersonService personService; private UserNameMatcher userNameMatcher; + + // TODO: pending replacement + private Dialect dialect; public AuthenticationTest() { @@ -125,7 +130,8 @@ public class AuthenticationTest extends TestCase public void setUp() throws Exception { - + dialect = (Dialect) ctx.getBean("dialect"); + nodeService = (NodeService) ctx.getBean("nodeService"); tenantService = (TenantService) ctx.getBean("tenantService"); searchService = (SearchService) ctx.getBean("searchService"); @@ -369,9 +375,17 @@ public class AuthenticationTest extends TestCase if (! tenantService.isEnabled()) { - authenticationService.createAuthentication("Andy `\u00ac\u00a6!\u00a3$%^&*()-_=+\t\n\u0000[]{};'#:@~,./<>?|", "".toCharArray()); - authenticationService.authenticate("Andy `\u00ac\u00a6!\u00a3$%^&*()-_=+\t\n\u0000[]{};'#:@~,./<>?|", "".toCharArray()); - assertEquals("Andy `\u00ac\u00a6!\u00a3$%^&*()-_=+\t\n\u0000[]{};'#:@~,./<>?|", authenticationService.getCurrentUserName()); + String un = "Andy `\u00ac\u00a6!\u00a3$%^&*()-_=+\t\n\u0000[]{};'#:@~,./<>?|"; + if (dialect instanceof PostgreSQLDialect) + { + // Note: PostgreSQL does not support \u0000 char embedded in a string + // http://archives.postgresql.org/pgsql-jdbc/2007-02/msg00115.php + un = "Andy `\u00ac\u00a6!\u00a3$%^&*()-_=+\t\n[]{};'#:@~,./<>?|"; + } + + authenticationService.createAuthentication(un, "".toCharArray()); + authenticationService.authenticate(un, "".toCharArray()); + assertEquals(un, authenticationService.getCurrentUserName()); } else {