diff --git a/source/java/org/alfresco/repo/node/BaseNodeServiceTest.java b/source/java/org/alfresco/repo/node/BaseNodeServiceTest.java index 737e69327d..5e078f793f 100644 --- a/source/java/org/alfresco/repo/node/BaseNodeServiceTest.java +++ b/source/java/org/alfresco/repo/node/BaseNodeServiceTest.java @@ -72,6 +72,7 @@ import org.alfresco.util.GUID; import org.hibernate.dialect.DB2Dialect; import org.hibernate.dialect.Dialect; import org.springframework.context.ApplicationContext; +import org.springframework.extensions.surf.util.I18NUtil; /** * Provides a base set of tests of the various {@link org.alfresco.service.cmr.repository.NodeService} @@ -1714,6 +1715,19 @@ public abstract class BaseNodeServiceTest extends BaseSpringTest // Do nothing with them by default } + /** + * Checks that the 'check' values all match the 'expected' values + */ + private void checkProperties(Map checkProperties, Map expectedProperties) + { + for (QName qname : expectedProperties.keySet()) + { + Serializable value = expectedProperties.get(qname); + Serializable checkValue = checkProperties.get(qname); + assertEquals("Property mismatch - " + qname, value, checkValue); + } + } + /** * Check that properties go in and come out in the correct format. * @see #getCheckPropertyValues(Map) @@ -1759,18 +1773,10 @@ public abstract class BaseNodeServiceTest extends BaseSpringTest TYPE_QNAME_TEST_MANY_PROPERTIES, properties).getChildRef(); - // persist - flushAndClear(); - // get the properties back Map checkProperties = nodeService.getProperties(nodeRef); - // check - for (QName qname : expectedProperties.keySet()) - { - Serializable value = expectedProperties.get(qname); - Serializable checkValue = checkProperties.get(qname); - assertEquals("Property mismatch - " + qname, value, checkValue); - } + // Check + checkProperties(checkProperties, expectedProperties); // check multi-valued properties are created where necessary nodeService.setProperty(nodeRef, PROP_QNAME_MULTI_VALUE, "GHI"); @@ -1779,6 +1785,87 @@ public abstract class BaseNodeServiceTest extends BaseSpringTest assertTrue("Collection doesn't contain value", ((Collection)checkProperty).contains("GHI")); } + public void testPropertyLocaleBehaviour() throws Exception + { + Map properties = new HashMap(17); + properties.put(PROP_QNAME_BOOLEAN_VALUE, true); + properties.put(PROP_QNAME_INTEGER_VALUE, 123); + properties.put(PROP_QNAME_LONG_VALUE, 123L); + properties.put(PROP_QNAME_FLOAT_VALUE, 123.0F); + properties.put(PROP_QNAME_DOUBLE_VALUE, 123.0); + properties.put(PROP_QNAME_STRING_VALUE, "123.0"); + properties.put(PROP_QNAME_ML_TEXT_VALUE, new MLText("This is ML text in the default language")); + properties.put(PROP_QNAME_DATE_VALUE, new Date()); + // Get the check values + Map expectedProperties = new HashMap(properties); + getExpectedPropertyValues(expectedProperties); + + Locale.setDefault(Locale.JAPANESE); + + // create a new node + NodeRef nodeRef = nodeService.createNode( + rootNodeRef, + ASSOC_TYPE_QNAME_TEST_CHILDREN, + QName.createQName("pathA"), + TYPE_QNAME_TEST_MANY_PROPERTIES, + properties).getChildRef(); + + // Check the properties again + Map checkProperties = nodeService.getProperties(nodeRef); + checkProperties(checkProperties, expectedProperties); + + // Change the locale and set the properties again + I18NUtil.setLocale(Locale.US); + nodeService.setProperties(nodeRef, properties); + + // Check the properties again + checkProperties = nodeService.getProperties(nodeRef); + checkProperties(checkProperties, expectedProperties); + + // Change the locale and set the properties again + I18NUtil.setLocale(Locale.UK); + nodeService.setProperties(nodeRef, properties); + + // Check the properties again + checkProperties = nodeService.getProperties(nodeRef); + checkProperties(checkProperties, expectedProperties); + + // Change the locale and set the properties again + I18NUtil.setLocale(Locale.US); + nodeService.addProperties(nodeRef, properties); + + // Check the properties again + checkProperties = nodeService.getProperties(nodeRef); + checkProperties(checkProperties, expectedProperties); + + // Change the locale and set the properties again + I18NUtil.setLocale(Locale.UK); + nodeService.addProperties(nodeRef, properties); + + // Check the properties again + checkProperties = nodeService.getProperties(nodeRef); + checkProperties(checkProperties, expectedProperties); + + // Change the locale and set the properties again + I18NUtil.setLocale(Locale.US); + nodeService.setProperty(nodeRef, PROP_QNAME_DATE_VALUE, properties.get(PROP_QNAME_DATE_VALUE)); + + // Check the properties again + checkProperties = nodeService.getProperties(nodeRef); + checkProperties(checkProperties, expectedProperties); + + // Change the locale and set the properties again + I18NUtil.setLocale(Locale.UK); + nodeService.setProperty(nodeRef, PROP_QNAME_DATE_VALUE, properties.get(PROP_QNAME_DATE_VALUE)); + + // Check the properties again + checkProperties = nodeService.getProperties(nodeRef); + checkProperties(checkProperties, expectedProperties); + + setComplete(); + endTransaction(); + } + /** * Checks that empty collections can be persisted */