mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
Phase one of merge of EC multilingual work
These files are their changes plus adjustments for formatting and immediate clashes I anticipate that this will break the build, but there are too many changes coming to risk it. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@5740 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -0,0 +1,138 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2007 Alfresco Software Limited.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
* As a special exception to the terms and conditions of version 2.0 of
|
||||
* the GPL, you may redistribute this Program in connection with Free/Libre
|
||||
* and Open Source Software ("FLOSS") applications as described in Alfresco's
|
||||
* FLOSS exception. You should have recieved a copy of the text describing
|
||||
* the FLOSS exception, and it is also available here:
|
||||
* http://www.alfresco.com/legal/licensing"
|
||||
*/
|
||||
package org.alfresco.repo.model.ml.tools;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.node.archive.NodeArchiveService;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationComponent;
|
||||
import org.alfresco.repo.transaction.TransactionUtil;
|
||||
import org.alfresco.repo.transaction.TransactionUtil.TransactionWork;
|
||||
import org.alfresco.service.ServiceRegistry;
|
||||
import org.alfresco.service.cmr.ml.ContentFilterLanguagesService;
|
||||
import org.alfresco.service.cmr.ml.MultilingualContentService;
|
||||
import org.alfresco.service.cmr.model.FileFolderService;
|
||||
import org.alfresco.service.cmr.repository.ContentWriter;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.cmr.repository.StoreRef;
|
||||
import org.alfresco.service.cmr.version.VersionService;
|
||||
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.springframework.context.ApplicationContext;
|
||||
|
||||
/**
|
||||
* Base multilingual test cases
|
||||
*
|
||||
* @author yanipig
|
||||
*/
|
||||
public abstract class AbstractMultilingualTestCases extends TestCase
|
||||
{
|
||||
|
||||
protected static ApplicationContext ctx = ApplicationContextHelper.getApplicationContext();
|
||||
|
||||
protected ServiceRegistry serviceRegistry;
|
||||
protected AuthenticationComponent authenticationComponent;
|
||||
protected TransactionService transactionService;
|
||||
protected NodeService nodeService;
|
||||
protected FileFolderService fileFolderService;
|
||||
protected VersionService versionService;
|
||||
protected MultilingualContentService multilingualContentService;
|
||||
protected NodeRef folderNodeRef;
|
||||
protected ContentFilterLanguagesService contentFilterLanguagesService;
|
||||
protected NodeArchiveService nodeArchiveService;
|
||||
@Override
|
||||
protected void setUp() throws Exception
|
||||
{
|
||||
nodeArchiveService = (NodeArchiveService) ctx.getBean("nodeArchiveService");
|
||||
serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);
|
||||
authenticationComponent = (AuthenticationComponent) ctx.getBean("AuthenticationComponent");
|
||||
transactionService = serviceRegistry.getTransactionService();
|
||||
nodeService = serviceRegistry.getNodeService();
|
||||
fileFolderService = serviceRegistry.getFileFolderService();
|
||||
versionService = serviceRegistry.getVersionService();
|
||||
multilingualContentService = (MultilingualContentService) ctx.getBean("MultilingualContentService");
|
||||
contentFilterLanguagesService = (ContentFilterLanguagesService) ctx.getBean("ContentFilterLanguagesService");
|
||||
|
||||
// Run as admin
|
||||
authenticationComponent.setCurrentUser("admin");
|
||||
|
||||
// Create a folder to work in
|
||||
TransactionWork<NodeRef> createFolderWork = new TransactionWork<NodeRef>()
|
||||
{
|
||||
public NodeRef doWork() throws Exception
|
||||
{
|
||||
StoreRef storeRef = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore");
|
||||
NodeRef rootNodeRef = nodeService.getRootNode(storeRef);
|
||||
// Create the folder
|
||||
NodeRef folderNodeRef = nodeService.createNode(
|
||||
rootNodeRef,
|
||||
ContentModel.ASSOC_CHILDREN,
|
||||
QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "testFolder"),
|
||||
ContentModel.TYPE_FOLDER).getChildRef();
|
||||
// done
|
||||
return folderNodeRef;
|
||||
}
|
||||
};
|
||||
folderNodeRef = TransactionUtil.executeInUserTransaction(transactionService, createFolderWork);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception
|
||||
{
|
||||
// Clear authentication
|
||||
try
|
||||
{
|
||||
authenticationComponent.clearCurrentSecurityContext();
|
||||
}
|
||||
catch (Throwable e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
protected NodeRef createContent()
|
||||
{
|
||||
NodeRef contentNodeRef = fileFolderService.create(
|
||||
folderNodeRef,
|
||||
"" + System.currentTimeMillis(),
|
||||
ContentModel.TYPE_CONTENT).getNodeRef();
|
||||
// add some content
|
||||
ContentWriter contentWriter = fileFolderService.getWriter(contentNodeRef);
|
||||
contentWriter.putContent("ABC");
|
||||
// done
|
||||
return contentNodeRef;
|
||||
}
|
||||
|
||||
public void testSetup() throws Exception
|
||||
{
|
||||
// Ensure that content can be created
|
||||
createContent();
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,146 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2007 Alfresco Software Limited.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
* As a special exception to the terms and conditions of version 2.0 of
|
||||
* the GPL, you may redistribute this Program in connection with Free/Libre
|
||||
* and Open Source Software ("FLOSS") applications as described in Alfresco's
|
||||
* FLOSS exception. You should have recieved a copy of the text describing
|
||||
* the FLOSS exception, and it is also available here:
|
||||
* http://www.alfresco.com/legal/licensing"
|
||||
*/
|
||||
package org.alfresco.repo.model.ml.tools;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* Content filter language service test cases
|
||||
*
|
||||
* @see org.alfresco.service.cmr.ml.ContentFilterLanguagesService
|
||||
* @see org.alfresco.repo.model.ml.ContentFilterLanguagesMap
|
||||
*
|
||||
* @author yanipig
|
||||
*/
|
||||
public class ContentFilterLanguagesMapTest extends AbstractMultilingualTestCases
|
||||
{
|
||||
|
||||
public void testGetFilterLanguages() throws Exception
|
||||
{
|
||||
// get the list of content filter languages
|
||||
List<String> lggs = contentFilterLanguagesService.getFilterLanguages();
|
||||
|
||||
// Ensure that the list is not null
|
||||
assertNotNull("Language list is null", lggs);
|
||||
|
||||
// Ensure that the list is read-only
|
||||
try
|
||||
{
|
||||
lggs.add("NEW LOCALE");
|
||||
assertTrue("Add a value to the content filter language list is not permit, this list would be read only", false);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// test case ok
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
lggs.remove(0);
|
||||
assertTrue("Remove a value to the content filter language list is not permit, this list would be read only", false);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// test case ok
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testGetMissingLanguages() throws Exception
|
||||
{
|
||||
List<String> lggs = contentFilterLanguagesService.getFilterLanguages();
|
||||
|
||||
// get missing languages with null parameter
|
||||
List<String> missingLggsNull = contentFilterLanguagesService.getMissingLanguages(null);
|
||||
|
||||
// Ensure that the returned list is not null
|
||||
assertNotNull("Language list returned with the null parameter is null", missingLggsNull);
|
||||
// Ensure that the returned list is entire
|
||||
assertEquals("Language list returned with the null parameter corrupted", missingLggsNull.size(), lggs.size());
|
||||
|
||||
// get missing languages with empty collection parameter
|
||||
List<String> missingLggsEmpty = contentFilterLanguagesService.getMissingLanguages(Collections.EMPTY_LIST);
|
||||
|
||||
// Ensure that the returned list is not null
|
||||
assertNotNull("Language list returned with the empty parameter is null", missingLggsEmpty);
|
||||
// Ensure that the returned list is entire
|
||||
assertEquals("Language list returned with the empty parameter corrupted", missingLggsEmpty.size(), lggs.size());
|
||||
|
||||
// get missing languages with a two locale list
|
||||
List<String> param = new ArrayList<String>();
|
||||
param.add(0, lggs.get(0));
|
||||
param.add(1, lggs.get(1));
|
||||
List<String> missingLggsOk = contentFilterLanguagesService.getMissingLanguages(param);
|
||||
|
||||
// Ensure that the returned list is not null
|
||||
assertNotNull("Language list returned with the correct parameter is null", missingLggsOk);
|
||||
// Ensure that the returned list size is correct
|
||||
assertEquals("Language list size returned with the correct parameter is not correct", missingLggsOk.size(), (lggs.size() - 2));
|
||||
// Ensure that the returned list don't content the preceding locales
|
||||
assertFalse("Language found : " + param.get(0), missingLggsOk.contains(param.get(0)));
|
||||
assertFalse("Language found : " + param.get(1), missingLggsOk.contains(param.get(1)));
|
||||
// get missing languages with a not found locale
|
||||
param.add(2, "WRONG LOCALE CODE");
|
||||
List<String> missingLggsWrong = contentFilterLanguagesService.getMissingLanguages(param);
|
||||
|
||||
// Ensure that the returned list is not null
|
||||
assertNotNull("Language list returned with the wrong parameter is null", missingLggsWrong);
|
||||
// Ensure that the returned list size is correct
|
||||
assertEquals("Language list size returned with the correct parameter is not correct", missingLggsWrong.size(), (lggs.size() - 2));
|
||||
// Ensure that the returned list don't content the wrong locale
|
||||
assertFalse("Language found : " + param.get(0), missingLggsWrong.contains(param.get(0)));
|
||||
assertFalse("Language found : " + param.get(1), missingLggsWrong.contains(param.get(1)));
|
||||
assertFalse("Language found : " + param.get(2), missingLggsWrong.contains(param.get(2)));
|
||||
}
|
||||
|
||||
public void testISOCodeConvertions() throws Exception
|
||||
{
|
||||
// New ISO code list
|
||||
String[] newCode = {"he", "id", "yi"};
|
||||
String[] oldCode = {"iw", "in", "ji"};
|
||||
|
||||
Locale loc0 = new Locale(newCode[0]);
|
||||
Locale loc1 = new Locale(newCode[1]);
|
||||
Locale loc2 = new Locale(newCode[2]);
|
||||
|
||||
// Ensure that java.util.Locale has converted the new ISO code into new iso code
|
||||
assertEquals("java.util.Locale Convertion not correct for " + newCode[0], oldCode[0], loc0.getLanguage());
|
||||
assertEquals("java.util.Locale Convertion not correct for " + newCode[1], oldCode[1], loc1.getLanguage());
|
||||
assertEquals("java.util.Locale Convertion not correct for " + newCode[2], oldCode[2], loc2.getLanguage());
|
||||
|
||||
// Ensure that the convertion is correcte
|
||||
assertEquals("Convertion of new ISO codes not correct for " + newCode[0], oldCode[0], contentFilterLanguagesService.convertToOldISOCode(newCode[0]));
|
||||
assertEquals("Convertion of new ISO codes not correct for " + newCode[1], oldCode[1], contentFilterLanguagesService.convertToOldISOCode(newCode[1]));
|
||||
assertEquals("Convertion of new ISO codes not correct for " + newCode[2], oldCode[2], contentFilterLanguagesService.convertToOldISOCode(newCode[2]));
|
||||
|
||||
|
||||
assertEquals("Convertion of old ISO codes not correct for " + oldCode[0], newCode[0], contentFilterLanguagesService.convertToNewISOCode(oldCode[0]));
|
||||
assertEquals("Convertion of old ISO codes not correct for " + oldCode[1], newCode[1], contentFilterLanguagesService.convertToNewISOCode(oldCode[1]));
|
||||
assertEquals("Convertion of old ISO codes not correct for " + oldCode[2], newCode[2], contentFilterLanguagesService.convertToNewISOCode(oldCode[2]));
|
||||
}
|
||||
}
|
@@ -0,0 +1,220 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2007 Alfresco Software Limited.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
* As a special exception to the terms and conditions of version 2.0 of
|
||||
* the GPL, you may redistribute this Program in connection with Free/Libre
|
||||
* and Open Source Software ("FLOSS") applications as described in Alfresco's
|
||||
* FLOSS exception. You should have recieved a copy of the text describing
|
||||
* the FLOSS exception, and it is also available here:
|
||||
* http://www.alfresco.com/legal/licensing"
|
||||
*/
|
||||
package org.alfresco.repo.model.ml.tools;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.service.cmr.repository.ContentData;
|
||||
import org.alfresco.service.cmr.repository.ContentService;
|
||||
import org.alfresco.service.cmr.repository.ContentWriter;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
|
||||
/**
|
||||
* Empty translations aspect test cases
|
||||
*
|
||||
* @see org.alfresco.service.cmr.ml.EmptyTranslationAspect
|
||||
*
|
||||
* @author yanipig
|
||||
*/
|
||||
public class EmptyTranslationAspectTest extends AbstractMultilingualTestCases {
|
||||
|
||||
protected ContentService contentService;
|
||||
|
||||
protected void setUp() throws Exception
|
||||
{
|
||||
contentService = (ContentService) ctx.getBean("ContentService");
|
||||
super.setUp();
|
||||
}
|
||||
|
||||
public void testCopy() throws Exception
|
||||
{
|
||||
NodeRef pivot = createContent();
|
||||
NodeRef empty = null;
|
||||
|
||||
multilingualContentService.makeTranslation(pivot, Locale.FRENCH);
|
||||
|
||||
empty = multilingualContentService.addEmptyTranslation(pivot, "empty_" + System.currentTimeMillis(), Locale.CHINESE);
|
||||
|
||||
boolean exceptionCatched = false;
|
||||
NodeRef copy = null;
|
||||
|
||||
try
|
||||
{
|
||||
copy = fileFolderService.copy(
|
||||
empty,
|
||||
nodeService.getPrimaryParent(empty).getParentRef(),
|
||||
"copyOfEmpty" + System.currentTimeMillis()).getNodeRef();
|
||||
|
||||
// test failed
|
||||
}
|
||||
catch (Exception ignore)
|
||||
{
|
||||
exceptionCatched = true;
|
||||
}
|
||||
|
||||
// Ensure that the copy of an empty translation throws an exception
|
||||
assertTrue("The copy of a translation must throws an exception", exceptionCatched);
|
||||
// Ensure that the copy node is null
|
||||
assertNull("The copy must fail ", copy);
|
||||
}
|
||||
|
||||
public void testDeleteNode() throws Exception
|
||||
{
|
||||
NodeRef pivot = createContent();
|
||||
NodeRef empty = null;
|
||||
|
||||
multilingualContentService.makeTranslation(pivot, Locale.FRENCH);
|
||||
|
||||
empty = multilingualContentService.addEmptyTranslation(pivot, "empty_" + System.currentTimeMillis(), Locale.CHINESE);
|
||||
|
||||
nodeService.deleteNode(empty);
|
||||
|
||||
// Ensure that the empty translation is removed from the workspace
|
||||
assertFalse("The empty translation must be removed from the wokspace", nodeService.exists(empty));
|
||||
// Ensure that the empty translation is not archived
|
||||
assertFalse("The empty translation must be removed from the wokspace", nodeService.exists(nodeArchiveService.getArchivedNode(empty)));
|
||||
}
|
||||
|
||||
public void testGetContent() throws Exception
|
||||
{
|
||||
NodeRef pivot = createContent();
|
||||
NodeRef otherTranslation = createContent();
|
||||
|
||||
NodeRef empty = null;
|
||||
|
||||
NodeRef mlContainer = multilingualContentService.makeTranslation(pivot, Locale.FRENCH);
|
||||
multilingualContentService.addTranslation(otherTranslation, pivot, Locale.KOREAN);
|
||||
|
||||
empty = multilingualContentService.addEmptyTranslation(pivot, "empty_" + System.currentTimeMillis(), Locale.CHINESE);
|
||||
|
||||
// Modify the content of the pivot
|
||||
String contentString = fileFolderService.getReader(pivot).getContentString();
|
||||
contentString += "_TEST_";
|
||||
|
||||
fileFolderService.getWriter(pivot).putContent(contentString);
|
||||
|
||||
// Ensure that the URL property of the empty translation content is null
|
||||
assertNull("The URL property of an empty translation must be null", ((ContentData) nodeService.getProperty(empty, ContentModel.PROP_CONTENT)).getContentUrl());
|
||||
// Ensure that the content retourned by a get reader of the empty document is the same as the pivot
|
||||
assertEquals("The content retourned of the empty translation must be the same that the content of the pivot",
|
||||
fileFolderService.getReader(pivot).getContentString(),
|
||||
fileFolderService.getReader(empty).getContentString());
|
||||
// Ensure that the content retourned by a get reader of the empty document is different to the non-pivot translation
|
||||
assertNotSame("The content retourned of the empty translation must be different that the content of a non-pivot translation",
|
||||
fileFolderService.getReader(otherTranslation).getContentString(),
|
||||
fileFolderService.getReader(empty).getContentString());
|
||||
|
||||
|
||||
// modify the pivot
|
||||
Map<QName, Serializable> props = nodeService.getProperties(mlContainer);
|
||||
props.put(ContentModel.PROP_LOCALE, Locale.KOREAN);
|
||||
nodeService.setProperties(mlContainer, props);
|
||||
|
||||
// Ensure that the modicfication of the pivot is take in account
|
||||
assertEquals("The modification of the pivot is not take in account",
|
||||
fileFolderService.getReader(otherTranslation).getContentString(),
|
||||
fileFolderService.getReader(empty).getContentString());
|
||||
}
|
||||
|
||||
public void testUpdateContent() throws Exception
|
||||
{
|
||||
NodeRef pivot = createContent();
|
||||
NodeRef empty = null;
|
||||
|
||||
multilingualContentService.makeTranslation(pivot, Locale.FRENCH);
|
||||
|
||||
empty = multilingualContentService.addEmptyTranslation(pivot, "empty_" + System.currentTimeMillis(), Locale.CHINESE);
|
||||
|
||||
// update the empty translation content
|
||||
ContentWriter writer = contentService.getWriter(empty, ContentModel.PROP_CONTENT, true);
|
||||
writer.setMimetype("text/plain");
|
||||
writer.putContent("ANY_CONTENT");
|
||||
|
||||
// Ensure that the URL property of the empty translation content is not null
|
||||
assertNotNull("The url of an updated (ex)empty transation can't be null", ((ContentData) nodeService.getProperty(empty, ContentModel.PROP_CONTENT)).getContentUrl());
|
||||
// Ensure that the mlEmptyTranslation aspect is removed
|
||||
assertFalse("The " + ContentModel.ASPECT_MULTILINGUAL_EMPTY_TRANSLATION + " aspect of an updated (ex)empty translation must be removed", nodeService.hasAspect(empty, ContentModel.ASPECT_MULTILINGUAL_EMPTY_TRANSLATION));
|
||||
// Ensure that the mlDocument aspect is not removed
|
||||
assertTrue("The " + ContentModel.ASPECT_MULTILINGUAL_DOCUMENT + " aspect of an updated (ex)empty translation must be keeped", nodeService.hasAspect(empty, ContentModel.ASPECT_MULTILINGUAL_DOCUMENT));
|
||||
// Ensure that the content is written
|
||||
assertEquals("The content of the (ex)empty translation is not correct",
|
||||
fileFolderService.getReader(empty).getContentString(),
|
||||
"ANY_CONTENT");
|
||||
// Ensure that the content is different that the content of the pivot
|
||||
assertNotSame("The content of the (ex)empty translation is not updated and is the same as the content of the pivot",
|
||||
fileFolderService.getReader(empty).getContentString(),
|
||||
fileFolderService.getReader(pivot).getContentString());
|
||||
}
|
||||
|
||||
public void testRemoveAspect() throws Exception
|
||||
{
|
||||
NodeRef pivot = createContent();
|
||||
NodeRef empty = null;
|
||||
|
||||
multilingualContentService.makeTranslation(pivot, Locale.FRENCH);
|
||||
|
||||
// 1. remove mlEmptyTranslation aspect with empty content
|
||||
empty = multilingualContentService.addEmptyTranslation(pivot, "empty_" + System.currentTimeMillis(), Locale.CHINESE);
|
||||
nodeService.removeAspect(empty, ContentModel.ASPECT_MULTILINGUAL_EMPTY_TRANSLATION);
|
||||
|
||||
// Ensure that the empty translation is deleted
|
||||
assertFalse("After removed the " + ContentModel.ASPECT_MULTILINGUAL_EMPTY_TRANSLATION + " of an empty translation with no content the node must be deleted",
|
||||
nodeService.exists(empty));
|
||||
assertFalse("After removed the " + ContentModel.ASPECT_MULTILINGUAL_EMPTY_TRANSLATION + " of an empty translation with no content the node must be deleted and can't be archived",
|
||||
nodeService.exists(nodeArchiveService.getArchivedNode(empty)));
|
||||
|
||||
// 2. remove mlDocument aspect with empty content
|
||||
empty = multilingualContentService.addEmptyTranslation(pivot, "empty_" + System.currentTimeMillis(), Locale.CHINESE);
|
||||
nodeService.removeAspect(empty, ContentModel.ASPECT_MULTILINGUAL_DOCUMENT);
|
||||
|
||||
// Ensure that the empty translation is deleted
|
||||
assertFalse("After removed the " + ContentModel.ASPECT_MULTILINGUAL_DOCUMENT + " of an empty translation with no content the node must be deleted",
|
||||
nodeService.exists(empty));
|
||||
assertFalse("After removed the " + ContentModel.ASPECT_MULTILINGUAL_DOCUMENT + " of an empty translation with no content the node must be deleted and can't be archived",
|
||||
nodeService.exists(nodeArchiveService.getArchivedNode(empty)));
|
||||
|
||||
// 3. remove mlEmptyTranslation aspect with not empty content
|
||||
empty = multilingualContentService.addEmptyTranslation(pivot, "empty_" + System.currentTimeMillis(), Locale.CHINESE);
|
||||
ContentWriter writer = contentService.getWriter(empty, ContentModel.PROP_CONTENT, true);
|
||||
writer.setMimetype("text/plain");
|
||||
writer.putContent("ANY_CONTENT");
|
||||
nodeService.removeAspect(empty, ContentModel.ASPECT_MULTILINGUAL_EMPTY_TRANSLATION);
|
||||
|
||||
// Ensure that the empty translation is NOT deleted
|
||||
assertTrue("After removed the " + ContentModel.ASPECT_MULTILINGUAL_EMPTY_TRANSLATION + " of an empty translation with content the node must NOT be deleted",
|
||||
nodeService.exists(empty));
|
||||
// Ensure that the mlEmptyTranslation aspect is removed
|
||||
assertFalse("After removed the " + ContentModel.ASPECT_MULTILINGUAL_EMPTY_TRANSLATION + " of an empty translation with content this aspect must be removed",
|
||||
nodeService.hasAspect(empty, ContentModel.ASPECT_MULTILINGUAL_EMPTY_TRANSLATION));
|
||||
// Ensure that the mlEmptyDocument in NOT removed
|
||||
assertTrue("After removed the " + ContentModel.ASPECT_MULTILINGUAL_EMPTY_TRANSLATION + " of an empty translation with content the " + ContentModel.ASPECT_MULTILINGUAL_DOCUMENT + " aspect must be keeped",
|
||||
nodeService.hasAspect(empty, ContentModel.ASPECT_MULTILINGUAL_DOCUMENT));
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,148 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2007 Alfresco Software Limited.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
* As a special exception to the terms and conditions of version 2.0 of
|
||||
* the GPL, you may redistribute this Program in connection with Free/Libre
|
||||
* and Open Source Software ("FLOSS") applications as described in Alfresco's
|
||||
* FLOSS exception. You should have recieved a copy of the text describing
|
||||
* the FLOSS exception, and it is also available here:
|
||||
* http://www.alfresco.com/legal/licensing"
|
||||
*/
|
||||
package org.alfresco.repo.model.ml.tools;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
|
||||
/**
|
||||
* Multilingual container type test cases
|
||||
*
|
||||
* @see org.alfresco.service.cmr.ml.MLContainerType
|
||||
*
|
||||
* @author yanipig
|
||||
*/
|
||||
public class MLContainerTypeTest extends AbstractMultilingualTestCases {
|
||||
|
||||
|
||||
public void testDeleteNode() throws Exception
|
||||
{
|
||||
NodeRef pivot = createContent();
|
||||
NodeRef empty;
|
||||
|
||||
NodeRef mlContainer = multilingualContentService.makeTranslation(pivot, Locale.FRENCH);
|
||||
empty = multilingualContentService.addEmptyTranslation(pivot, "Empty_" + System.currentTimeMillis(), Locale.ENGLISH);
|
||||
|
||||
nodeService.deleteNode(mlContainer);
|
||||
|
||||
// Ensure that the mlContainer is deleted
|
||||
assertFalse("The mlContainer must be deleted", nodeService.exists(mlContainer));
|
||||
// Ensure that the empty translation is deleted
|
||||
assertFalse("The mlEmptyTranslation must be deleted", nodeService.exists(empty));
|
||||
// Ensure that the non-empty document is not deleted
|
||||
assertTrue("The mlDocument must not be deleted", nodeService.exists(pivot));
|
||||
// Ensure that the mlDocument property of the non-empty document is removed
|
||||
assertFalse("The " + ContentModel.ASPECT_MULTILINGUAL_DOCUMENT + " aspect of the mlDocument must be removed",
|
||||
nodeService.hasAspect(pivot, ContentModel.ASPECT_MULTILINGUAL_DOCUMENT));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public void testEditLocale() throws Exception
|
||||
{
|
||||
NodeRef trans1 = createContent();
|
||||
NodeRef trans2 = createContent();
|
||||
NodeRef trans3 = createContent();
|
||||
NodeRef empty = null;
|
||||
|
||||
NodeRef mlContainer = multilingualContentService.makeTranslation(trans1, Locale.FRENCH);
|
||||
multilingualContentService.addTranslation(trans2, trans1, Locale.GERMAN);
|
||||
multilingualContentService.addTranslation(trans3, trans1, Locale.ITALIAN);
|
||||
empty = multilingualContentService.addEmptyTranslation(trans1, "EMPTY_" + System.currentTimeMillis(), Locale.JAPANESE);
|
||||
|
||||
// 1. Locale as null
|
||||
|
||||
// Ensure that the setting of the locale of the mlContainer as null throws an excpetion
|
||||
assertTrue("The setting of the locale of a mlContainer must throws an exception",
|
||||
setLocaleProp(mlContainer, null));
|
||||
// Ensure that the locale of the mlContainer is not changed
|
||||
assertEquals("The locale of the mlContainer would not be changed",
|
||||
Locale.FRENCH,
|
||||
nodeService.getProperty(mlContainer, ContentModel.PROP_LOCALE));
|
||||
|
||||
// 2. Set an non-existing locale
|
||||
|
||||
// Ensure that the setting of the locale of the mlContainer as a non-existing translation language throws an excpetion
|
||||
assertTrue("The setting of the locale of a mlContainer as a non-existing translation language must throws an exception",
|
||||
setLocaleProp(mlContainer, Locale.US));
|
||||
// Ensure that the locale of the mlContainer is not changed
|
||||
assertEquals("The locale of the mlContainer would not be changed",
|
||||
Locale.FRENCH,
|
||||
nodeService.getProperty(mlContainer, ContentModel.PROP_LOCALE));
|
||||
|
||||
// 3. Set the locale of a empty translation
|
||||
|
||||
// Ensure that the setting of the locale of the mlContainer as an empty translation language throws an excpetion
|
||||
assertTrue("The setting of the locale of a mlContainer as an empty translation language must throws an exception",
|
||||
setLocaleProp(mlContainer, Locale.JAPANESE));
|
||||
// Ensure that the locale of the mlContainer is not changed
|
||||
assertEquals("The locale of the mlContainer would not be changed",
|
||||
Locale.FRENCH,
|
||||
nodeService.getProperty(mlContainer, ContentModel.PROP_LOCALE));
|
||||
|
||||
// 4. Set an existing and valid locale
|
||||
|
||||
// Ensure that the setting of the locale of the mlContainer as an existing and a non-empty translation DOESN'T throw an excpetion
|
||||
assertFalse("The setting of the locale of a mlContainer as an existing and a non-empty translation DOESN'T throw an excpetion",
|
||||
setLocaleProp(mlContainer, Locale.ITALIAN));
|
||||
// Ensure that the locale of the mlContainer is not changed
|
||||
assertEquals("The locale of the mlContainer would be changed",
|
||||
Locale.ITALIAN,
|
||||
nodeService.getProperty(mlContainer, ContentModel.PROP_LOCALE));
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private boolean setLocaleProp(NodeRef node, Locale locale) throws Exception
|
||||
{
|
||||
Map<QName, Serializable> props = nodeService.getProperties(node);
|
||||
props.put(ContentModel.PROP_LOCALE, locale);
|
||||
|
||||
boolean exceptionCatched = false;
|
||||
|
||||
try
|
||||
{
|
||||
nodeService.setProperties(node, props);
|
||||
|
||||
}
|
||||
catch (IllegalArgumentException ignore)
|
||||
{
|
||||
exceptionCatched = true;
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
throw new Exception(ex);
|
||||
}
|
||||
|
||||
|
||||
return exceptionCatched;
|
||||
}
|
||||
}
|
@@ -0,0 +1,232 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2007 Alfresco Software Limited.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
* As a special exception to the terms and conditions of version 2.0 of
|
||||
* the GPL, you may redistribute this Program in connection with Free/Libre
|
||||
* and Open Source Software ("FLOSS") applications as described in Alfresco's
|
||||
* FLOSS exception. You should have recieved a copy of the text describing
|
||||
* the FLOSS exception, and it is also available here:
|
||||
* http://www.alfresco.com/legal/licensing"
|
||||
*/
|
||||
package org.alfresco.repo.model.ml.tools;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
import org.alfresco.i18n.I18NUtil;
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.version.Version;
|
||||
import org.alfresco.service.cmr.version.VersionHistory;
|
||||
|
||||
/**
|
||||
* @see org.alfresco.repo.ml.MultilingualContentServiceImpl
|
||||
*
|
||||
* @author Derek Hulley
|
||||
* @author Philippe Dubois
|
||||
*/
|
||||
public class MultilingualContentServiceImplTest extends AbstractMultilingualTestCases
|
||||
{
|
||||
|
||||
public void testMakeTranslation() throws Exception
|
||||
{
|
||||
NodeRef contentNodeRef = createContent();
|
||||
// Turn the content into a translation with the appropriate structures
|
||||
NodeRef mlContainerNodeRef = multilingualContentService.makeTranslation(contentNodeRef, Locale.CHINESE);
|
||||
// Check it
|
||||
assertNotNull("Container not created", mlContainerNodeRef);
|
||||
// Check the container child count
|
||||
assertEquals("Incorrect number of child nodes", 1, nodeService.getChildAssocs(mlContainerNodeRef).size());
|
||||
}
|
||||
|
||||
public void testAddTranslationUsingContainer() throws Exception
|
||||
{
|
||||
// Make a container with a single translation
|
||||
NodeRef chineseContentNodeRef = createContent();
|
||||
NodeRef mlContainerNodeRef = multilingualContentService.makeTranslation(chineseContentNodeRef, Locale.CHINESE);
|
||||
// Create some more content
|
||||
NodeRef frenchContentNodeRef = createContent();
|
||||
// Make this a translation of the Chinese
|
||||
NodeRef newMLContainerNodeRef = multilingualContentService.addTranslation(
|
||||
frenchContentNodeRef,
|
||||
mlContainerNodeRef,
|
||||
Locale.FRENCH);
|
||||
// Make sure that the original container was used
|
||||
assertEquals("Existing container should have been used", mlContainerNodeRef, newMLContainerNodeRef);
|
||||
// Check the container child count
|
||||
assertEquals("Incorrect number of child nodes", 2, nodeService.getChildAssocs(mlContainerNodeRef).size());
|
||||
}
|
||||
|
||||
public void testAddTranslationUsingContent() throws Exception
|
||||
{
|
||||
// Make a container with a single translation
|
||||
NodeRef chineseContentNodeRef = createContent();
|
||||
NodeRef mlContainerNodeRef = multilingualContentService.makeTranslation(chineseContentNodeRef, Locale.CHINESE);
|
||||
// Create some more content
|
||||
NodeRef frenchContentNodeRef = createContent();
|
||||
// Make this a translation of the Chinese
|
||||
NodeRef newMLContainerNodeRef = multilingualContentService.addTranslation(
|
||||
frenchContentNodeRef,
|
||||
chineseContentNodeRef,
|
||||
Locale.FRENCH);
|
||||
// Make sure that the original container was used
|
||||
assertEquals("Existing container should have been used", mlContainerNodeRef, newMLContainerNodeRef);
|
||||
// Check the container child count
|
||||
assertEquals("Incorrect number of child nodes", 2, nodeService.getChildAssocs(mlContainerNodeRef).size());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public void testGetMissingTranslation() throws Exception
|
||||
{
|
||||
List<String> langList = contentFilterLanguagesService.getFilterLanguages();
|
||||
int langListSize = langList.size();
|
||||
|
||||
// make sure that it exists at least tree language filter
|
||||
assertFalse("The testGetMissingTranslation test case needs at least three language", langListSize < 3);
|
||||
|
||||
// get the first tree locale of the content filter language list
|
||||
Locale loc1 = I18NUtil.parseLocale(langList.get(0));
|
||||
Locale loc2 = I18NUtil.parseLocale(langList.get(1));
|
||||
Locale loc3 = I18NUtil.parseLocale(langList.get(2));
|
||||
|
||||
// create three content
|
||||
NodeRef nodeRef1 = createContent();
|
||||
NodeRef nodeRef2 = createContent();
|
||||
NodeRef nodeRef3 = createContent();
|
||||
|
||||
NodeRef mlContainerNodeRef = multilingualContentService.makeTranslation(nodeRef1, loc1);
|
||||
|
||||
List<Locale> missing = multilingualContentService.getMissingTranslations(mlContainerNodeRef, false);
|
||||
|
||||
// make sure that the missing language list size is correct
|
||||
assertFalse("Missing Translation Size false. " +
|
||||
"Real size : " + missing.size() + ". Normal Size " + (langListSize - 1), missing.size() != (langListSize - 1));
|
||||
|
||||
// make sure that the missing language list is correct
|
||||
assertFalse("Missing Translation List false. Locale " + loc1 + " found", missing.contains(loc1.toString()));
|
||||
|
||||
multilingualContentService.addTranslation(nodeRef2, mlContainerNodeRef, loc2);
|
||||
multilingualContentService.addTranslation(nodeRef3, mlContainerNodeRef, loc3);
|
||||
|
||||
|
||||
missing = multilingualContentService.getMissingTranslations(mlContainerNodeRef, false);
|
||||
|
||||
// make sure that the missing language list size is correct
|
||||
assertFalse("Missing Translation Size false. " +
|
||||
"Real size : " + missing.size() + ". Normal Size " + (langListSize - 3), missing.size() != (langListSize - 3));
|
||||
|
||||
// make sure that the missing language list is correct
|
||||
assertFalse("Missing Translation List false. Locale " + loc2 + " or " + loc3 + " found", missing.contains(loc2.toString()) || missing.contains(loc3.toString()));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public void testPivotTranslation() throws Exception
|
||||
{
|
||||
NodeRef chineseContentNodeRef = createContent();
|
||||
|
||||
NodeRef mlContainerNodeRef = multilingualContentService.makeTranslation(chineseContentNodeRef, Locale.CHINESE);
|
||||
|
||||
// make sure that the pivot language is set
|
||||
assertNotNull("Pivot language not set", nodeService.getProperty(mlContainerNodeRef, ContentModel.PROP_LOCALE));
|
||||
|
||||
// make sure that the pivot language is correctly set
|
||||
assertTrue("Pivot language not correctly set", nodeService.getProperty(mlContainerNodeRef, ContentModel.PROP_LOCALE).equals(Locale.CHINESE));
|
||||
|
||||
NodeRef frenchContentNodeRef = createContent();
|
||||
multilingualContentService.addTranslation(frenchContentNodeRef, chineseContentNodeRef, Locale.FRENCH);
|
||||
|
||||
// make sure that the pivot noderef is correct
|
||||
assertTrue("Pivot node ref not correct", multilingualContentService.getPivotTranslation(mlContainerNodeRef).equals(chineseContentNodeRef));
|
||||
|
||||
// modify the pivot language
|
||||
nodeService.setProperty(mlContainerNodeRef, ContentModel.PROP_LOCALE, Locale.FRENCH);
|
||||
|
||||
// make sure that the modified pivot noderef is correct
|
||||
assertTrue("Pivot node ref not correct", multilingualContentService.getPivotTranslation(mlContainerNodeRef).equals(frenchContentNodeRef));
|
||||
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public void testCreateEmptyTranslation() throws Exception
|
||||
{
|
||||
NodeRef chineseContentNodeRef = createContent();
|
||||
NodeRef mlContainerNodeRef = multilingualContentService.makeTranslation(chineseContentNodeRef, Locale.CHINESE);
|
||||
|
||||
NodeRef empty = multilingualContentService.addEmptyTranslation(chineseContentNodeRef, "" + System.currentTimeMillis(), Locale.CANADA);
|
||||
|
||||
// Ensure that the empty translation is not null
|
||||
assertNotNull("The creation of the empty document failed ", empty);
|
||||
// Ensure that the empty translation has the mlDocument aspect
|
||||
assertTrue("The empty document must have the mlDocument aspect", nodeService.hasAspect(empty, ContentModel.ASPECT_MULTILINGUAL_DOCUMENT));
|
||||
// Ensure that the empty translation has the mlEmptyTranslation aspect
|
||||
assertTrue("The empty document must have the mlEmptyTranslation aspect", nodeService.hasAspect(empty, ContentModel.ASPECT_MULTILINGUAL_EMPTY_TRANSLATION));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public void testCreateEdition() throws Exception
|
||||
{
|
||||
// Make some content
|
||||
NodeRef chineseContentNodeRef = createContent();
|
||||
NodeRef frenchContentNodeRef = createContent();
|
||||
NodeRef japaneseContentNodeRef = createContent();
|
||||
// Add to container
|
||||
NodeRef mlContainerNodeRef = multilingualContentService.makeTranslation(chineseContentNodeRef, Locale.CHINESE);
|
||||
multilingualContentService.addTranslation(frenchContentNodeRef, mlContainerNodeRef, Locale.FRENCH);
|
||||
multilingualContentService.addTranslation(japaneseContentNodeRef, mlContainerNodeRef, Locale.JAPANESE);
|
||||
// Check the container child count
|
||||
assertEquals("Incorrect number of child nodes", 3, nodeService.getChildAssocs(mlContainerNodeRef).size());
|
||||
|
||||
// Version each of the documents
|
||||
List<NodeRef> nodeRefs = new ArrayList<NodeRef>(3);
|
||||
nodeRefs.add(chineseContentNodeRef);
|
||||
nodeRefs.add(frenchContentNodeRef);
|
||||
nodeRefs.add(japaneseContentNodeRef);
|
||||
versionService.createVersion(nodeRefs, null);
|
||||
// Get the current versions of each of the documents
|
||||
Version chineseVersionPreEdition = versionService.getCurrentVersion(chineseContentNodeRef);
|
||||
Version frenchVersionPreEdition = versionService.getCurrentVersion(frenchContentNodeRef);
|
||||
Version japaneseVersionPreEdition = versionService.getCurrentVersion(japaneseContentNodeRef);
|
||||
|
||||
// Create the edition, keeping the Chinese translation as the basis
|
||||
multilingualContentService.createEdition(chineseContentNodeRef);
|
||||
// Check the container child count
|
||||
assertEquals("Incorrect number of child nodes", 1, nodeService.getChildAssocs(mlContainerNodeRef).size());
|
||||
|
||||
// Get the document versions now
|
||||
Version chineseVersionPostEdition = versionService.getCurrentVersion(chineseContentNodeRef);
|
||||
assertFalse("Expected document to be gone", nodeService.exists(frenchContentNodeRef));
|
||||
assertFalse("Expected document to be gone", nodeService.exists(japaneseContentNodeRef));
|
||||
|
||||
// Now be sure that we can get the required information using the version service
|
||||
VersionHistory mlContainerVersionHistory = versionService.getVersionHistory(mlContainerNodeRef);
|
||||
Collection<Version> mlContainerVersions = mlContainerVersionHistory.getAllVersions();
|
||||
// Loop through and get all the children of each version
|
||||
for (Version mlContainerVersion : mlContainerVersions)
|
||||
{
|
||||
NodeRef versionedMLContainerNodeRef = mlContainerVersion.getFrozenStateNodeRef();
|
||||
// Get all the children
|
||||
Map<Locale, NodeRef> translationsByLocale = multilingualContentService.getTranslations(
|
||||
versionedMLContainerNodeRef);
|
||||
// Count the children
|
||||
int count = translationsByLocale.size();
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,220 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2007 Alfresco Software Limited.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
* As a special exception to the terms and conditions of version 2.0 of
|
||||
* the GPL, you may redistribute this Program in connection with Free/Libre
|
||||
* and Open Source Software ("FLOSS") applications as described in Alfresco's
|
||||
* FLOSS exception. You should have recieved a copy of the text describing
|
||||
* the FLOSS exception, and it is also available here:
|
||||
* http://www.alfresco.com/legal/licensing"
|
||||
*/
|
||||
package org.alfresco.repo.model.ml.tools;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
|
||||
/**
|
||||
* Multilingual document aspect test cases
|
||||
*
|
||||
* @see org.alfresco.service.cmr.ml.MultilingualDocumentAspect
|
||||
*
|
||||
* @author yanipig
|
||||
*/
|
||||
public class MultilingualDocumentAspectTest extends AbstractMultilingualTestCases
|
||||
{
|
||||
public void testCopy() throws Exception
|
||||
{
|
||||
NodeRef original = createContent();
|
||||
NodeRef mlContainer = multilingualContentService.makeTranslation(original, Locale.FRENCH);
|
||||
|
||||
NodeRef copy =
|
||||
fileFolderService.copy(original, nodeService.getPrimaryParent(original).getParentRef(), "COPY" + System.currentTimeMillis()).getNodeRef();
|
||||
|
||||
// Ensure that the copy removes the mlDocument aspect
|
||||
assertFalse("The copy of a mlDocument can't have the multilingual aspect", nodeService.hasAspect(copy, ContentModel.ASPECT_MULTILINGUAL_DOCUMENT));
|
||||
|
||||
// Ensure that the copy removes the association between the mlConatiner and the new node
|
||||
assertEquals("The copy of a mlDocument can't be a children of the mlContainer", 1, multilingualContentService.getTranslations(mlContainer).size());
|
||||
|
||||
// Ensure that the copy removes the Locale property of the new node
|
||||
assertNull("The copy of a mlDocument can't keep the locale property", nodeService.getProperty(copy, ContentModel.PROP_LOCALE));
|
||||
}
|
||||
|
||||
public void testDeleteNode() throws Exception
|
||||
{
|
||||
NodeRef trad1 = createContent();
|
||||
NodeRef trad2 = createContent();
|
||||
NodeRef trad3 = createContent();
|
||||
|
||||
NodeRef parent = nodeService.getPrimaryParent(trad1).getParentRef();
|
||||
|
||||
NodeRef mlContainer = multilingualContentService.makeTranslation(trad1, Locale.FRENCH);
|
||||
multilingualContentService.addTranslation(trad2, trad1, Locale.GERMAN);
|
||||
multilingualContentService.addTranslation(trad3, trad1, Locale.ITALIAN);
|
||||
|
||||
nodeService.deleteNode(trad3);
|
||||
|
||||
// Ensure that the deleted node is romoved from its space
|
||||
assertEquals("The deleted node must be removed to the space", 2, nodeService.getChildAssocs(parent).size());
|
||||
// Ensure that the mlContainer doesn't keep an association to the deleted node
|
||||
assertEquals("The deleted node must be removed to the child associations of the mlContainer", 2, multilingualContentService.getTranslations(mlContainer).size());
|
||||
|
||||
// retore the deleted node
|
||||
NodeRef restoredNode = nodeArchiveService.restoreArchivedNode(nodeArchiveService.getArchivedNode(trad3)).getRestoredNodeRef();
|
||||
|
||||
// Ensure that the restored node is restored to it s original space
|
||||
assertEquals("The restaured node must be restaured to the the space", 3, nodeService.getChildAssocs(parent).size());
|
||||
// Ensure that the restored node is not linked to the mlContainer
|
||||
assertEquals("The restaured node would not be restaured to the mlContainer", 2, multilingualContentService.getTranslations(mlContainer).size());
|
||||
// Ensure that the restored node doesn't keep the mlDocument aspect
|
||||
assertFalse("The restaured node can't keep the multilingual aspect", nodeService.hasAspect(restoredNode, ContentModel.ASPECT_MULTILINGUAL_DOCUMENT));
|
||||
// Ensure that the restored node doesn't keep the locale property
|
||||
assertNull("The restaured node can't keep the locale property", nodeService.getProperty(restoredNode, ContentModel.PROP_LOCALE));
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void testDeletePivot() throws Exception
|
||||
{
|
||||
NodeRef pivot = createContent();
|
||||
NodeRef trans1 = createContent();
|
||||
NodeRef mlContainer = multilingualContentService.makeTranslation(pivot, Locale.FRENCH);
|
||||
multilingualContentService.addTranslation(trans1, pivot, Locale.KOREAN);
|
||||
|
||||
//nodeService.deleteNode(trans1);
|
||||
nodeService.deleteNode(pivot);
|
||||
|
||||
// Ensure that pivot is removed
|
||||
assertFalse("The pivot would be removed", nodeService.exists(pivot));
|
||||
// Ensure that the mlContainer is removed
|
||||
assertFalse("The mlContainer must be removed if the pivot is removed", nodeService.exists(mlContainer));
|
||||
// Ensure that trans1 is NOT removed
|
||||
assertTrue("The last translation would not be removed", nodeService.exists(trans1));
|
||||
// Ensure that trans1 has no mlDocument aspect
|
||||
assertFalse("The last translation can't keep the multilingual aspect", nodeService.hasAspect(trans1, ContentModel.ASPECT_MULTILINGUAL_DOCUMENT));
|
||||
// Ensure that trans1 has no locale propety
|
||||
assertNull("The last translation can't keep the locale property", nodeService.getProperty(trans1, ContentModel.PROP_LOCALE));
|
||||
}
|
||||
|
||||
public void testDeleteLastNode() throws Exception
|
||||
{
|
||||
NodeRef pivot = createContent();
|
||||
NodeRef mlContainer = multilingualContentService.makeTranslation(pivot, Locale.FRENCH);
|
||||
|
||||
nodeService.deleteNode(pivot);
|
||||
|
||||
// Ensure that the mlContainer is removed too
|
||||
assertFalse("The mlContainer must be removed if the last translation is removed", nodeService.exists(mlContainer));
|
||||
|
||||
}
|
||||
|
||||
public void testRemoveAspect() throws Exception
|
||||
{
|
||||
// entierly covered by the delete tests
|
||||
}
|
||||
|
||||
public void testUpdateLocale() throws Exception
|
||||
{
|
||||
NodeRef pivot = createContent();
|
||||
NodeRef trans1 = createContent();
|
||||
NodeRef mlContainer = multilingualContentService.makeTranslation(pivot, Locale.FRENCH);
|
||||
multilingualContentService.addTranslation(trans1, pivot, Locale.KOREAN);
|
||||
|
||||
// modify the locale for the translation
|
||||
Map<QName, Serializable> props = nodeService.getProperties(trans1);
|
||||
props.put(ContentModel.PROP_LOCALE, Locale.GERMAN);
|
||||
nodeService.setProperties(trans1, props);
|
||||
|
||||
// Ensure that the pivot reference is not changed for the mlContainer and the locale is changed for the translation
|
||||
assertEquals("The locale for the pivot would be changed ",Locale.GERMAN, nodeService.getProperty(trans1, ContentModel.PROP_LOCALE));
|
||||
assertEquals("The pivot reference would not be changed in the mlContainer", Locale.FRENCH, nodeService.getProperty(mlContainer, ContentModel.PROP_LOCALE));
|
||||
|
||||
// modify the locale for the pivot
|
||||
props = nodeService.getProperties(pivot);
|
||||
props.put(ContentModel.PROP_LOCALE, Locale.US);
|
||||
nodeService.setProperties(pivot, props);
|
||||
|
||||
// Ensure that the pivot reference is changed (in the pivot and in the mlContainer)
|
||||
assertEquals("The locale for the pivot would be changed ", Locale.US, nodeService.getProperty(pivot, ContentModel.PROP_LOCALE));
|
||||
assertEquals("The pivot reference would be changes in the mlContainer", Locale.US, nodeService.getProperty(mlContainer, ContentModel.PROP_LOCALE));
|
||||
}
|
||||
|
||||
public void testUpdateRedundantLocale() throws Exception
|
||||
{
|
||||
NodeRef pivot = createContent();
|
||||
NodeRef trans1 = createContent();
|
||||
NodeRef trans2 = createContent();
|
||||
|
||||
multilingualContentService.makeTranslation(pivot, Locale.FRENCH);
|
||||
multilingualContentService.addTranslation(trans1, pivot, Locale.KOREAN);
|
||||
multilingualContentService.addTranslation(trans2, pivot, Locale.JAPANESE);
|
||||
|
||||
// 1. Try with redundant locale
|
||||
|
||||
// modify the locale for the translation 2
|
||||
Map<QName, Serializable> props = nodeService.getProperties(trans2);
|
||||
props.put(ContentModel.PROP_LOCALE, Locale.KOREAN);
|
||||
|
||||
boolean exceptionCatched = false;
|
||||
|
||||
try
|
||||
{
|
||||
nodeService.setProperties(trans2, props);
|
||||
// test failed
|
||||
} catch (Exception ignore)
|
||||
{
|
||||
exceptionCatched = true;
|
||||
}
|
||||
|
||||
// Ensure that the the exception was catched.
|
||||
assertTrue("The modification of this locale must catch an exception because it is already in use in another translation", exceptionCatched);
|
||||
// Ensure that the locale of the trans2 is unchanged
|
||||
assertEquals("The locale must not be changed",
|
||||
Locale.JAPANESE,
|
||||
(Locale) nodeService.getProperty(trans2, ContentModel.PROP_LOCALE));
|
||||
|
||||
// 2. Try with a non-redundant locale
|
||||
|
||||
props = nodeService.getProperties(trans2);
|
||||
props.put(ContentModel.PROP_LOCALE, Locale.ITALIAN);
|
||||
|
||||
exceptionCatched = false;
|
||||
|
||||
try
|
||||
{
|
||||
nodeService.setProperties(trans2, props);
|
||||
|
||||
} catch (Exception ignore)
|
||||
{
|
||||
// test failed
|
||||
exceptionCatched = true;
|
||||
}
|
||||
|
||||
// Ensure that the exception was not catched
|
||||
assertFalse("The modification of the locale would not throws an exception", exceptionCatched);
|
||||
// Ensure that the locale is modified
|
||||
assertEquals("The locale must be changed",
|
||||
Locale.ITALIAN,
|
||||
(Locale) nodeService.getProperty(trans2, ContentModel.PROP_LOCALE));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user