diff --git a/source/java/org/alfresco/repo/model/ml/MultilingualTestSuite.java b/source/java/org/alfresco/repo/model/ModelTestSuite.java similarity index 56% rename from source/java/org/alfresco/repo/model/ml/MultilingualTestSuite.java rename to source/java/org/alfresco/repo/model/ModelTestSuite.java index 562831c875..acf282e382 100644 --- a/source/java/org/alfresco/repo/model/ml/MultilingualTestSuite.java +++ b/source/java/org/alfresco/repo/model/ModelTestSuite.java @@ -1,56 +1,67 @@ -/* - * Copyright (C) 2005-2010 Alfresco Software Limited. - * - * This file is part of Alfresco - * - * Alfresco is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Alfresco 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Alfresco. If not, see . - */ -package org.alfresco.repo.model.ml; - -import junit.framework.Test; -import junit.framework.TestSuite; - -import org.alfresco.repo.model.ml.tools.ContentFilterLanguagesMapTest; -import org.alfresco.repo.model.ml.tools.EditionServiceImplTest; -import org.alfresco.repo.model.ml.tools.EmptyTranslationAspectTest; -import org.alfresco.repo.model.ml.tools.MLContainerTypeTest; -import org.alfresco.repo.model.ml.tools.MultilingualContentServiceImplTest; -import org.alfresco.repo.model.ml.tools.MultilingualDocumentAspectTest; - -/** - * Multilingual test suite - * - * @author yanipig - */ -public class MultilingualTestSuite extends TestSuite -{ - /** - * Creates the test suite - * - * @return the test suite - */ - public static Test suite() - { - TestSuite suite = new TestSuite(); - - suite.addTestSuite(EmptyTranslationAspectTest.class); - suite.addTestSuite(ContentFilterLanguagesMapTest.class); - suite.addTestSuite(MultilingualContentServiceImplTest.class); - suite.addTestSuite(MultilingualDocumentAspectTest.class); - suite.addTestSuite(MLContainerTypeTest.class); - suite.addTestSuite(EditionServiceImplTest.class); - - return suite; - } -} +/* + * Copyright (C) 2005-2010 Alfresco Software Limited. + * + * This file is part of Alfresco + * + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Alfresco 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + */ +package org.alfresco.repo.model; + +import org.alfresco.repo.model.filefolder.FileFolderDuplicateChildTest; +import org.alfresco.repo.model.filefolder.FileFolderServiceImplTest; +import org.alfresco.repo.model.ml.tools.ContentFilterLanguagesMapTest; +import org.alfresco.repo.model.ml.tools.EditionServiceImplTest; +import org.alfresco.repo.model.ml.tools.EmptyTranslationAspectTest; +import org.alfresco.repo.model.ml.tools.MLContainerTypeTest; +import org.alfresco.repo.model.ml.tools.MultilingualContentServiceImplTest; +import org.alfresco.repo.model.ml.tools.MultilingualDocumentAspectTest; +import org.alfresco.util.ApplicationContextHelper; + +import junit.framework.Test; +import junit.framework.TestSuite; + +/** + * Model test suite + */ +public class ModelTestSuite extends TestSuite +{ + /** + * Creates the test suite + * + * @return the test suite + */ + public static Test suite() + { + TestSuite suite = new TestSuite(); + + // Ensure that the default context is available + ApplicationContextHelper.getApplicationContext(); + + // Add the multilingual tests + suite.addTestSuite( ContentFilterLanguagesMapTest.class ); + suite.addTestSuite( EmptyTranslationAspectTest.class ); + suite.addTestSuite( MLContainerTypeTest.class ); + suite.addTestSuite( MultilingualContentServiceImplTest.class ); + suite.addTestSuite( MultilingualDocumentAspectTest.class ); + suite.addTestSuite( EditionServiceImplTest.class ); + + // Add the file folder tests + // These need to come afterwards, as they insert extra + // interceptors which would otherwise confuse things + suite.addTestSuite( FileFolderServiceImplTest.class ); + suite.addTestSuite( FileFolderDuplicateChildTest.class ); + + return suite; + } +} diff --git a/source/java/org/alfresco/repo/model/filefolder/FileFolderTestSuite.java b/source/java/org/alfresco/repo/model/filefolder/FileFolderTestSuite.java deleted file mode 100644 index 60d1682074..0000000000 --- a/source/java/org/alfresco/repo/model/filefolder/FileFolderTestSuite.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (C) 2005-2010 Alfresco Software Limited. - * - * This file is part of Alfresco - * - * Alfresco is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Alfresco 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Alfresco. If not, see . - */ -package org.alfresco.repo.model.filefolder; - -import junit.framework.Test; -import junit.framework.TestSuite; - -/** - * Suite for FileFolderService tests. - * - * @author Derek Hulley - */ -public class FileFolderTestSuite extends TestSuite -{ - public static Test suite() - { - TestSuite suite = new TestSuite(); - - suite.addTestSuite(FileFolderServiceImplTest.class); - suite.addTestSuite(FileFolderDuplicateChildTest.class); - - return suite; - } -} diff --git a/source/java/org/alfresco/repo/model/ml/tools/MultilingualContentServiceImplTest.java b/source/java/org/alfresco/repo/model/ml/tools/MultilingualContentServiceImplTest.java index 4d1f22a342..228edc8ea4 100644 --- a/source/java/org/alfresco/repo/model/ml/tools/MultilingualContentServiceImplTest.java +++ b/source/java/org/alfresco/repo/model/ml/tools/MultilingualContentServiceImplTest.java @@ -26,6 +26,7 @@ import org.springframework.extensions.surf.util.I18NUtil; import org.alfresco.model.ContentModel; import org.alfresco.repo.security.authentication.AuthenticationComponent; import org.alfresco.repo.security.authentication.AuthenticationUtil; +import org.alfresco.service.cmr.model.FileExistsException; import org.alfresco.service.cmr.repository.ContentData; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.datatype.DefaultTypeConverter; @@ -197,27 +198,79 @@ public class MultilingualContentServiceImplTest extends AbstractMultilingualTest multilingualContentService.makeTranslation(chineseContentNodeRef, Locale.CHINESE); NodeRef koreanContentNodeRef = createContent("Document_ko.txt"); multilingualContentService.addTranslation(koreanContentNodeRef, chineseContentNodeRef, Locale.KOREAN); + + + // The pivot translation (base language) is Chinese + // (It won't matter which language we query to check this) + assertEquals( + "The wrong language was set as the pivot translation", + chineseContentNodeRef, + multilingualContentService.getPivotTranslation(chineseContentNodeRef) + ); + assertEquals( + "The wrong language was set as the pivot translation", + chineseContentNodeRef, + multilingualContentService.getPivotTranslation(koreanContentNodeRef) + ); + + // Create with a null name, and off a non-pivot just to be sure + // The locale will be added to the pivot's file name to create a unique one NodeRef nullNameNodeRef = multilingualContentService.addEmptyTranslation( koreanContentNodeRef, null, Locale.CANADA); String nullName = fileFolderService.getFileInfo(nullNameNodeRef).getName(); assertEquals("Empty translation name not generated correctly.", "Document_en_CA.txt", nullName); - // Create with the same name + + // This will be referencing the same pivot still + assertEquals( + "The wrong language was set as the pivot translation", + chineseContentNodeRef, + multilingualContentService.getPivotTranslation(nullNameNodeRef) + ); + + + // Create with the same name as the document we're the translation of + // The locale will be added to the supplied file name to create a unique one NodeRef sameNameNodeRef = multilingualContentService.addEmptyTranslation( chineseContentNodeRef, "Document.txt", Locale.CANADA_FRENCH); String sameName = fileFolderService.getFileInfo(sameNameNodeRef).getName(); assertEquals("Empty translation name not generated correctly.", "Document_fr_CA.txt", sameName); + + // Still correctly referencing the pivot + assertEquals( + "The wrong language was set as the pivot translation", + chineseContentNodeRef, + multilingualContentService.getPivotTranslation(sameNameNodeRef) + ); + + // Create with a different name + // As there's no clash, the locale won't be added NodeRef differentNameNodeRef = multilingualContentService.addEmptyTranslation( chineseContentNodeRef, "Document2.txt", Locale.JAPANESE); String differentName = fileFolderService.getFileInfo(differentNameNodeRef).getName(); assertEquals("Empty translation name not generated correctly.", "Document2.txt", differentName); + + // If we tried to add a 2nd language with the different name, + // it would fail as the name isn't used + // (The automatic appending of the locale to avoid duplicates only + // works on the Pivot version's name, it isn't allowed for + // the names of non-pivot versions) + try { + multilingualContentService.addEmptyTranslation( + chineseContentNodeRef, + "Document2.txt", + Locale.FRENCH); + fail("A duplicate translation filename was created"); + } catch(FileExistsException e) { + // Good, this was spotted + } } public void testGetTranslationContainerPermissions() throws Exception