Apply Pre-Commit code formatting

This commit is contained in:
alfresco-build
2025-03-17 14:00:58 +00:00
parent 5255760f6e
commit bc8424482b
7038 changed files with 1006771 additions and 982869 deletions

View File

@@ -1,43 +1,42 @@
/*
* #%L
* Alfresco Repository
* %%
* Copyright (C) 2005 - 2022 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
*
* 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 <http://www.gnu.org/licenses/>.
* #L%
*/
package org.alfresco;
import org.junit.experimental.categories.Categories;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
/**
* All MMT Tool project UNIT test classes (no application context) should be added to this test suite.
*/
@RunWith(Categories.class)
@Suite.SuiteClasses({
org.alfresco.repo.module.tool.ModuleManagementToolTest.class,
org.alfresco.repo.module.tool.WarHelperImplTest.class,
org.alfresco.repo.module.tool.ModuleServiceImplTest.class
})
public class AllMmtUnitTestSuite
{
}
/*
* #%L
* Alfresco Repository
* %%
* Copyright (C) 2005 - 2022 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
*
* 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 <http://www.gnu.org/licenses/>.
* #L%
*/
package org.alfresco;
import org.junit.experimental.categories.Categories;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
/**
* All MMT Tool project UNIT test classes (no application context) should be added to this test suite.
*/
@RunWith(Categories.class)
@Suite.SuiteClasses({
org.alfresco.repo.module.tool.ModuleManagementToolTest.class,
org.alfresco.repo.module.tool.WarHelperImplTest.class,
org.alfresco.repo.module.tool.ModuleServiceImplTest.class
})
public class AllMmtUnitTestSuite
{}

View File

@@ -25,20 +25,21 @@
*/
package org.alfresco.repo.module.tool;
import de.schlichtherle.truezip.file.TFile;
import de.schlichtherle.truezip.file.TFileInputStream;
import de.schlichtherle.truezip.file.TVFS;
import junit.framework.TestCase;
import org.alfresco.service.cmr.module.ModuleDetails;
import org.alfresco.util.TempFileProvider;
import org.springframework.util.FileCopyUtils;
import java.io.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import de.schlichtherle.truezip.file.TFile;
import de.schlichtherle.truezip.file.TFileInputStream;
import de.schlichtherle.truezip.file.TVFS;
import junit.framework.TestCase;
import org.springframework.util.FileCopyUtils;
import org.alfresco.service.cmr.module.ModuleDetails;
import org.alfresco.util.TempFileProvider;
/**
* @see org.alfresco.repo.module.tool.ModuleManagementTool
*
@@ -49,24 +50,24 @@ public class ModuleManagementToolTest extends TestCase
{
private ModuleManagementTool manager = new ModuleManagementTool();
static final int BUFFER = 2048;
public void testBasicInstall()
throws Exception
throws Exception
{
manager.setVerbose(true);
String warLocation = getFileLocation(".war", "module/test.war");
String ampLocation = getFileLocation(".amp", "module/test_v1.amp");
String ampV2Location = getFileLocation(".amp", "module/test_v2.amp");
installerSharedTests(warLocation, ampLocation, ampV2Location);
installerSharedTests(warLocation, ampLocation, ampV2Location);
}
private void installerSharedTests(String warLocation, String ampLocation, String ampV2Location)
{
// Initial install of module
this.manager.installModule(ampLocation, warLocation);
// Check that the war has been modified correctly
List<String> files = new ArrayList<String>(10);
files.add("/WEB-INF/classes/alfresco/module/test/module.properties");
@@ -80,14 +81,14 @@ public class ModuleManagementToolTest extends TestCase
files.add("/jsp/test.jsp");
files.add("/css/test.css");
files.add("/extra.txt");
checkForFileExistance(warLocation, files);
checkForFileExistance(warLocation, files);
// Check the intstalled files
InstalledFiles installed0 = new InstalledFiles(warLocation, "test");
installed0.load();
assertNotNull(installed0);
assertEquals(9, installed0.getAdds().size());
//assertEquals(1, installed0.getMkdirs().size());
// assertEquals(1, installed0.getMkdirs().size());
// Try and install same version
try
@@ -96,14 +97,14 @@ public class ModuleManagementToolTest extends TestCase
// Already installed is now a Warning rather than an Error and is now non fatal
// fail("The module is already installed so an exception should have been raised since we are not forcing an overwite");
}
catch(ModuleManagementToolException exception)
catch (ModuleManagementToolException exception)
{
// Pass
}
// Install a later version
this.manager.installModule(ampV2Location, warLocation);
// Check that the war has been modified correctly
List<String> files2 = new ArrayList<String>(12);
files.add("/WEB-INF/classes/alfresco/module/test/module.properties");
@@ -114,18 +115,18 @@ public class ModuleManagementToolTest extends TestCase
files2.add("/WEB-INF/licenses/license.txt");
files2.add("/scripts/test2.js");
files2.add("/scripts/test3.js");
files2.add("/images/test.jpg");
files2.add("/images/test.jpg");
files2.add("/css/test.css");
files2.add("/WEB-INF/classes/alfresco/module/test/version2");
files2.add("/WEB-INF/classes/alfresco/module/test/version2/version2-context.xml");
checkForFileExistance(warLocation, files2);
checkForFileExistance(warLocation, files2);
List<String> files3 = new ArrayList<String>(2);
files3.add("/scripts/test.js");
files3.add("/jsp/test.jsp");
files3.add("/extra.txt");
checkForFileNonExistance(warLocation, files3);
// Check the intstalled files
InstalledFiles installed1 = new InstalledFiles(warLocation, "test");
installed1.load();
@@ -133,26 +134,26 @@ public class ModuleManagementToolTest extends TestCase
assertEquals(8, installed1.getAdds().size());
assertEquals(1, installed1.getMkdirs().size());
assertEquals(0, installed1.getUpdates().size());
/**
* Try and install an earlier version over a later version
* Try and install an earlier version over a later version
*/
try
{
this.manager.installModule(ampLocation, warLocation);
//fail("A later version of this module is already installed so an exception should have been raised since we are not forcing an overwite");
//this is now a warning rather than an error
// fail("A later version of this module is already installed so an exception should have been raised since we are not forcing an overwite");
// this is now a warning rather than an error
// Check that the war has not been modified
checkForFileExistance(warLocation, files2);
checkForFileExistance(warLocation, files2);
checkForFileNonExistance(warLocation, files3);
}
catch(ModuleManagementToolException exception)
catch (ModuleManagementToolException exception)
{
// Pass
}
}
public void testBasicFolderInstall() throws Exception
{
manager.setVerbose(true);
@@ -161,38 +162,38 @@ public class ModuleManagementToolTest extends TestCase
String ampDirectory = extractToDir(".amp", "module/test_v1.amp");
String ampV2Directory = getFileLocation(".amp", "module/test_v2.amp");
assertNotNull(warDirectory);
assertNotNull(ampDirectory);
assertNotNull(ampV2Directory);
assertNotNull(ampDirectory);
assertNotNull(ampV2Directory);
installerSharedTests(warDirectory, ampDirectory, ampV2Directory);
//Now try it on share
// Now try it on share
warDirectory = extractToDir(".war", "module/share-3.4.11.war");
assertNotNull(warDirectory);
assertNotNull(ampDirectory);
assertNotNull(ampDirectory);
this.manager.installModule(ampDirectory, warDirectory);
warDirectory = extractToDir(".war", "module/share-4.2.a.war");
assertNotNull(warDirectory);
String ampV2Location = getFileLocation(".amp", "module/test_v6.amp");
this.manager.installModule(ampV2Location, warDirectory);
}
public void testDependencySuccess() throws Exception
{
manager.setVerbose(true);
String warLocation = getFileLocation(".war", "module/test.war");
String testAmpV1Location = getFileLocation(".amp", "module/test_v1.amp");
String testAmpV2Location = getFileLocation(".amp", "module/test_v2.amp");
String testAmpDepV1Location = getFileLocation(".amp", "module/dependent_on_test_v1.amp");
String testAmpDepV2Location = getFileLocation(".amp", "module/dependent_on_test_v2.amp");
// Install V1
this.manager.installModule(testAmpV1Location, warLocation, false, false, false);
// Install the module dependent on test_v1
this.manager.installModule(testAmpDepV1Location, warLocation, false, false, false);
try
{
// Attempt to upgrade the dependent module
@@ -203,87 +204,86 @@ public class ModuleManagementToolTest extends TestCase
{
System.out.println("Expected: " + e.getMessage());
}
// Install the test_v2
this.manager.installModule(testAmpV2Location, warLocation, false, false, false);
// The dependent module should now go in
this.manager.installModule(testAmpDepV2Location, warLocation, false, false, false);
}
public void testPreviewInstall()
throws Exception
throws Exception
{
manager.setVerbose(true);
String warLocation = getFileLocation(".war", "module/test.war");
String ampLocation = getFileLocation(".amp", "module/test_v1.amp");
// Initial install of module
this.manager.installModule(ampLocation, warLocation, true, false, true);
// TODO need to prove that the war file has not been updated in any way
}
public void testUninstall()
throws Exception
throws Exception
{
manager.setVerbose(true);
String warLocation = getFileLocation(".war", "module/test.war");
String ampLocation = getFileLocation(".amp", "module/test_v1.amp");
// Initial install of module
this.manager.installModule(ampLocation, warLocation, false, false, false);
this.manager.listModules(warLocation);
this.manager.uninstallModule("test", warLocation, false, false);
List<String> files = new ArrayList<String>(10);
files.add("/WEB-INF/classes/alfresco/module/test/module.properties");
files.add("/WEB-INF/classes/alfresco/module/test/modifications.install");
files.add("/WEB-INF/lib/test.jar");
files.add("/WEB-INF/classes/alfresco/module/test/module-context.xml");
checkForFileNonExistance(warLocation, files);
checkForFileNonExistance(warLocation, files);
}
public void testForcedInstall()
throws Exception
throws Exception
{
manager.setVerbose(true);
String warLocation = getFileLocation(".war", "module/alfresco-4.2.c.war");
String ampLocation = getFileLocation(".amp", "module/test_v4.amp");
try
{
// Initial install of module
this.manager.installModule(ampLocation, warLocation, false, false, false); //not forced
this.manager.installModule(ampLocation, warLocation, false, false, false); // not forced
fail("Failed to detect existing files in the amp");
}
catch (ModuleManagementToolException e)
{
assertTrue(e.getMessage().contains("The amp will overwrite an existing file"));
assertTrue(e.getMessage().contains("The amp will overwrite an existing file"));
}
String ampv2Location = getFileLocation(".amp", "module/test_v2.amp");
warLocation = getFileLocation(".war", "module/alfresco-4.2.c.war"); //Get a new war file
this.manager.installModule(ampLocation, warLocation, false, true, false); //install v1
this.manager.installModule(ampv2Location, warLocation, false, true, false); //install v2
//install another amp that replaces the same files
warLocation = getFileLocation(".war", "module/alfresco-4.2.c.war"); // Get a new war file
this.manager.installModule(ampLocation, warLocation, false, true, false); // install v1
this.manager.installModule(ampv2Location, warLocation, false, true, false); // install v2
// install another amp that replaces the same files
ampLocation = getFileLocation(".amp", "module/test_v4.amp");
warLocation = getFileLocation(".war", "module/alfresco-4.2.c.war"); //Get a new war file
String amp5Location = getFileLocation(".amp", "module/test_v7.amp"); //new amp that overides existing files
warLocation = getFileLocation(".war", "module/alfresco-4.2.c.war"); // Get a new war file
String amp5Location = getFileLocation(".amp", "module/test_v7.amp"); // new amp that overides existing files
this.manager.installModule(ampLocation, warLocation, false, true, false);
this.manager.installModule(amp5Location, warLocation, false, true, false);
}
public void testInstallFromDir()
throws Exception
throws Exception
{
manager.setVerbose(true);
String warLocation = getFileLocation(".war", "module/test.war");
String ampLocation = getFileLocation(".amp", "module/test_v1.amp");
String ampV2Location = getFileLocation(".amp", "module/test_v2.amp");
@@ -291,7 +291,7 @@ public class ModuleManagementToolTest extends TestCase
int index = ampV2Location.lastIndexOf(File.separator);
System.out.println(index);
String directoryLocation = ampV2Location.substring(0, index);
try
{
this.manager.installModules(directoryLocation, warLocation);
@@ -302,41 +302,41 @@ public class ModuleManagementToolTest extends TestCase
System.out.println("Expected failure: " + exception.getMessage());
}
}
public void testExistingFilesInWar() throws Exception
{
manager.setVerbose(true);
String warLocation = getFileLocation(".war", "module/test.war"); //Version 4.0.1
String warLocation = getFileLocation(".war", "module/test.war"); // Version 4.0.1
String ampLocation = getFileLocation(".amp", "module/test_v4.amp");
try
{
this.manager.installModule(ampLocation, warLocation, false, false, true);
this.manager.installModule(ampLocation, warLocation, false, false, true);
}
catch(ModuleManagementToolException exception)
catch (ModuleManagementToolException exception)
{
assertTrue(exception.getMessage().contains("will overwrite an existing file in the war"));
}
this.manager.installModule(ampLocation, warLocation, false, true, true); //Now force it
this.manager.installModule(ampLocation, warLocation, false, true, true); // Now force it
checkContentsOfFile(warLocation + "/jsp/relogin.jsp", "VERSIONONE");
checkContentsOfFile(warLocation + "/css/main.css", "p{margin-bottom:1em;}");
this.manager.installModule(ampLocation, warLocation, false, true, false); //install it again
this.manager.installModule(ampLocation, warLocation, false, true, false); // install it again
}
public void testWhiteSpaceInCustomMapping()
throws Exception
throws Exception
{
manager.setVerbose(true);
String warLocation = getFileLocation(".war", "module/test.war");
String ampLocation = getFileLocation(".amp", "module/test_v3.amp");
// Initial install of module
this.manager.installModule(ampLocation, warLocation, false, false, true);
List<String> files = new ArrayList<String>(10);
files.add("/WEB-INF/classes/alfresco/module/test/module.properties");
files.add("/WEB-INF/classes/alfresco/module/test/modifications.install");
@@ -345,16 +345,17 @@ public class ModuleManagementToolTest extends TestCase
files.add("/images/test.jpg");
files.add("/css/test.css");
files.add("/extra.txt");
checkForFileExistance(warLocation, files);
checkForFileExistance(warLocation, files);
}
public void testList() throws Exception
{
String warLocation = getFileLocation(".war", "module/test.war");
this.manager.listModules(warLocation);
}
public void testListAndInstall() throws Exception {
public void testListAndInstall() throws Exception
{
String warLocation = getFileLocation(".war", "module/test.war");
String ampLocation = getFileLocation(".amp", "module/test_v1.amp");
@@ -394,10 +395,11 @@ public class ModuleManagementToolTest extends TestCase
assertNotNull(details);
assertEquals(details.size(), 3);
//Sort them by installation date
// Sort them by installation date
Collections.sort(details, new Comparator<ModuleDetails>() {
@Override
public int compare(ModuleDetails a, ModuleDetails b) {
public int compare(ModuleDetails a, ModuleDetails b)
{
return a.getInstallDate().compareTo(b.getInstallDate());
}
});
@@ -417,77 +419,81 @@ public class ModuleManagementToolTest extends TestCase
}
private String getFileLocation(String extension, String location)
throws IOException
throws IOException
{
File file = TempFileProvider.createTempFile("moduleManagementToolTest-", extension);
File file = TempFileProvider.createTempFile("moduleManagementToolTest-", extension);
InputStream is = this.getClass().getClassLoader().getResourceAsStream(location);
assertNotNull(is);
OutputStream os = new FileOutputStream(file);
FileCopyUtils.copy(is, os);
OutputStream os = new FileOutputStream(file);
FileCopyUtils.copy(is, os);
return file.getPath();
}
private String extractToDir(String extension, String location)
{
File tmpDir = TempFileProvider.getTempDir();
File tmpDir = TempFileProvider.getTempDir();
try {
TFile zipFile = new TFile(this.getClass().getClassLoader().getResource(location).getPath());
TFile outDir = new TFile(tmpDir.getAbsolutePath()+"/moduleManagementToolTestDir"+System.currentTimeMillis());
outDir.mkdir();
zipFile.cp_rp(outDir);
TVFS.umount(zipFile);
return outDir.getPath();
} catch (Exception e) {
e.printStackTrace();
}
return null;
try
{
TFile zipFile = new TFile(this.getClass().getClassLoader().getResource(location).getPath());
TFile outDir = new TFile(tmpDir.getAbsolutePath() + "/moduleManagementToolTestDir" + System.currentTimeMillis());
outDir.mkdir();
zipFile.cp_rp(outDir);
TVFS.umount(zipFile);
return outDir.getPath();
}
catch (Exception e)
{
e.printStackTrace();
}
return null;
}
public void testNoWar() throws Exception
public void testNoWar() throws Exception
{
String noWar = "noWar";
String ampLocation = getFileLocation(".amp", "module/test_v1.amp");
try
{
this.manager.installModule(ampLocation, noWar,false,false, false);
this.manager.installModule(ampLocation, noWar, false, false, false);
}
catch (ModuleManagementToolException exception)
{
assertTrue(exception.getMessage().endsWith("does not exist."));
}
}
try
{
this.manager.installModule(ampLocation, noWar,false,false, true); //backup war
this.manager.installModule(ampLocation, noWar, false, false, true); // backup war
}
catch (ModuleManagementToolException exception)
{
assertTrue(exception.getMessage().endsWith("does not exist."));
}
}
}
private void checkForFileExistance(String warLocation, List<String> files)
{
for (String file : files)
{
File file0 = new TFile(warLocation + file);
assertTrue("The file/dir " + file + " does not exist in the WAR.", file0.exists());
}
}
}
private void checkForFileNonExistance(String warLocation, List<String> files)
{
for (String file : files)
{
File file0 = new TFile(warLocation + file);
assertFalse("The file/dir " + file + " does exist in the WAR.", file0.exists());
}
}
}
private void checkContentsOfFile(String location, String expectedContents)
throws IOException
throws IOException
{
File file = new TFile(location);
assertTrue(file.exists());
assertTrue(file.exists());
BufferedReader reader = null;
try
{
@@ -500,7 +506,12 @@ public class ModuleManagementToolTest extends TestCase
{
if (reader != null)
{
try { reader.close(); } catch (Throwable e ) {}
try
{
reader.close();
}
catch (Throwable e)
{}
}
}
}

View File

@@ -32,11 +32,10 @@ import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import org.alfresco.repo.admin.registry.RegistryKey;
import org.alfresco.repo.admin.registry.RegistryService;
import org.alfresco.repo.module.ModuleServiceImpl;
import org.alfresco.repo.module.ModuleVersionNumber;
import org.alfresco.service.cmr.module.ModuleDetails;
import java.io.Serializable;
import java.util.Arrays;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
import org.mockito.invocation.InvocationOnMock;
@@ -45,12 +44,15 @@ import org.springframework.context.ApplicationContext;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import java.io.Serializable;
import java.util.Arrays;
import java.util.List;
import org.alfresco.repo.admin.registry.RegistryKey;
import org.alfresco.repo.admin.registry.RegistryService;
import org.alfresco.repo.module.ModuleServiceImpl;
import org.alfresco.repo.module.ModuleVersionNumber;
import org.alfresco.service.cmr.module.ModuleDetails;
/**
* Tests some of ModuleServiceImpl that is not covered by other tests
*
* @author Gethin James
*/
public class ModuleServiceImplTest
@@ -66,8 +68,7 @@ public class ModuleServiceImplTest
RegistryService reg = mock(RegistryService.class);
ApplicationContext applicationContext = mock(ApplicationContext.class);
when(reg.getProperty((RegistryKey) any())).thenAnswer(new Answer<Serializable>()
{
when(reg.getProperty((RegistryKey) any())).thenAnswer(new Answer<Serializable>() {
public Serializable answer(InvocationOnMock invocation) throws Throwable
{
RegistryKey key = (RegistryKey) invocation.getArguments()[0];
@@ -75,7 +76,7 @@ public class ModuleServiceImplTest
}
});
doReturn(Arrays.asList("fee", "alfresco-simple-module", "fo")).when(reg).getChildElements((RegistryKey) any());
doReturn(new Resource[] {simpleMod}).when(applicationContext).getResources(anyString());
doReturn(new Resource[]{simpleMod}).when(applicationContext).getResources(anyString());
moduleService.setRegistryService(reg);
moduleService.setApplicationContext(applicationContext);
}
@@ -83,7 +84,7 @@ public class ModuleServiceImplTest
@Test(expected = UnsupportedOperationException.class)
public void testSetApplyToTenants() throws Exception
{
moduleService.setApplyToTenants(false);
moduleService.setApplyToTenants(false);
}
@Test
@@ -91,7 +92,7 @@ public class ModuleServiceImplTest
{
List<ModuleDetails> miss = moduleService.getMissingModules();
assertNotNull(miss);
//There are 3 modules. 2 of which are missing. "alfresco-simple-module" should be found.
// There are 3 modules. 2 of which are missing. "alfresco-simple-module" should be found.
assertEquals(2, miss.size());
}
}
}

View File

@@ -25,29 +25,30 @@
*/
package org.alfresco.repo.module.tool;
import de.schlichtherle.truezip.file.TArchiveDetector;
import de.schlichtherle.truezip.file.TConfig;
import de.schlichtherle.truezip.file.TFile;
import de.schlichtherle.truezip.fs.archive.zip.ZipDriver;
import de.schlichtherle.truezip.socket.sl.IOPoolLocator;
import org.alfresco.repo.module.ModuleDetailsImpl;
import org.alfresco.repo.module.ModuleVersionNumber;
import org.alfresco.service.cmr.module.ModuleDetails;
import org.alfresco.service.cmr.module.ModuleInstallState;
import org.alfresco.util.TempFileProvider;
import org.alfresco.util.VersionNumber;
import org.junit.Test;
import org.springframework.util.FileCopyUtils;
import static org.junit.Assert.*;
import java.io.*;
import java.util.List;
import java.util.Properties;
import java.util.jar.Manifest;
import static org.junit.Assert.*;
import de.schlichtherle.truezip.file.TArchiveDetector;
import de.schlichtherle.truezip.file.TConfig;
import de.schlichtherle.truezip.file.TFile;
import de.schlichtherle.truezip.fs.archive.zip.ZipDriver;
import de.schlichtherle.truezip.socket.sl.IOPoolLocator;
import org.junit.Test;
import org.springframework.util.FileCopyUtils;
import org.alfresco.repo.module.ModuleDetailsImpl;
import org.alfresco.repo.module.ModuleVersionNumber;
import org.alfresco.service.cmr.module.ModuleDetails;
import org.alfresco.service.cmr.module.ModuleInstallState;
import org.alfresco.util.TempFileProvider;
import org.alfresco.util.VersionNumber;
/**
* Tests the war helper.
* Tests the war helper.
*
* @author Gethin James
*/
@@ -56,51 +57,51 @@ public class WarHelperImplTest extends WarHelperImpl
public WarHelperImplTest()
{
super(new LogOutput()
{
super(new LogOutput() {
@Override
public void info(Object message)
{
System.out.println(message);
}
});
TConfig config = TConfig.get();
config.setArchiveDetector(new TArchiveDetector("war|amp", new ZipDriver(IOPoolLocator.SINGLETON)));
}
@Test
public void testRegEx()
{
String x = "1";
assertTrue(x.matches(REGEX_NUMBER_OR_DOT));
x = "king";
assertFalse(x.matches(REGEX_NUMBER_OR_DOT));
x = "2.5.a";
assertFalse(x.matches(REGEX_NUMBER_OR_DOT));
x = "1.2.5";
assertTrue(x.matches(REGEX_NUMBER_OR_DOT));
x = "123";
assertTrue(x.matches(REGEX_NUMBER_OR_DOT));
x = "3.4.11";
assertTrue(x.matches(REGEX_NUMBER_OR_DOT));
x = "4.1.1";
assertTrue(x.matches(REGEX_NUMBER_OR_DOT));
x = "4.2.b";
assertFalse(x.matches(REGEX_NUMBER_OR_DOT));
String x = "1";
assertTrue(x.matches(REGEX_NUMBER_OR_DOT));
x = "king";
assertFalse(x.matches(REGEX_NUMBER_OR_DOT));
x = "2.5.a";
assertFalse(x.matches(REGEX_NUMBER_OR_DOT));
x = "1.2.5";
assertTrue(x.matches(REGEX_NUMBER_OR_DOT));
x = "123";
assertTrue(x.matches(REGEX_NUMBER_OR_DOT));
x = "3.4.11";
assertTrue(x.matches(REGEX_NUMBER_OR_DOT));
x = "4.1.1";
assertTrue(x.matches(REGEX_NUMBER_OR_DOT));
x = "4.2.b";
assertFalse(x.matches(REGEX_NUMBER_OR_DOT));
}
@Test
public void testCheckCompatibleVersion()
{
TFile theWar = getFile(".war", "module/test.war"); //Version 4.1.0
TFile theWar = getFile(".war", "module/test.war"); // Version 4.1.0
ModuleDetails installingModuleDetails = new ModuleDetailsImpl("test_it", new ModuleVersionNumber("9999"), "Test Mod", "Testing module");
ModuleDetails installingModuleDetails = new ModuleDetailsImpl("test_it", new ModuleVersionNumber("9999"), "Test Mod", "Testing module");
installingModuleDetails.setRepoVersionMin(new VersionNumber("10.1"));
try
{
this.checkCompatibleVersion(theWar, installingModuleDetails);
fail(); //should never get here
fail(); // should never get here
}
catch (ModuleManagementToolException exception)
{
@@ -108,54 +109,54 @@ public class WarHelperImplTest extends WarHelperImpl
}
installingModuleDetails.setRepoVersionMin(new VersionNumber("1.1"));
this.checkCompatibleVersion(theWar, installingModuleDetails); //does not throw exception
this.checkCompatibleVersion(theWar, installingModuleDetails); // does not throw exception
installingModuleDetails.setRepoVersionMax(new VersionNumber("3.0"));
try
{
this.checkCompatibleVersion(theWar, installingModuleDetails);
fail(); //should never get here
fail(); // should never get here
}
catch (ModuleManagementToolException exception)
{
assertTrue(exception.getMessage().contains("cannot be installed on a war version greater than 3.0"));
}
}
installingModuleDetails.setRepoVersionMax(new VersionNumber("99"));
this.checkCompatibleVersion(theWar, installingModuleDetails); //does not throw exception
installingModuleDetails.setRepoVersionMin(new VersionNumber("4.1.0")); //current war version
installingModuleDetails.setRepoVersionMax(new VersionNumber("4.1.0")); //current war version
this.checkCompatibleVersion(theWar, installingModuleDetails); //does not throw exception
installingModuleDetails.setRepoVersionMin(new VersionNumber("3.4.0")); //current war version
installingModuleDetails.setRepoVersionMax(new VersionNumber("4.1.0")); //current war version
this.checkCompatibleVersion(theWar, installingModuleDetails); //does not throw exception
this.checkCompatibleVersion(theWar, installingModuleDetails); // does not throw exception
installingModuleDetails.setRepoVersionMin(new VersionNumber("4.1.0")); // current war version
installingModuleDetails.setRepoVersionMax(new VersionNumber("4.1.0")); // current war version
this.checkCompatibleVersion(theWar, installingModuleDetails); // does not throw exception
installingModuleDetails.setRepoVersionMin(new VersionNumber("3.4.0")); // current war version
installingModuleDetails.setRepoVersionMax(new VersionNumber("4.1.0")); // current war version
this.checkCompatibleVersion(theWar, installingModuleDetails); // does not throw exception
try
{
installingModuleDetails.setRepoVersionMin(new VersionNumber("3.4.0")); //current war version
installingModuleDetails.setRepoVersionMax(new VersionNumber("4.0.999")); //current war version
this.checkCompatibleVersion(theWar, installingModuleDetails); //does not throw exception
fail("Should not pass as current version is 4.1.0 and the max value is 4.0.999"); //should never get here
installingModuleDetails.setRepoVersionMin(new VersionNumber("3.4.0")); // current war version
installingModuleDetails.setRepoVersionMax(new VersionNumber("4.0.999")); // current war version
this.checkCompatibleVersion(theWar, installingModuleDetails); // does not throw exception
fail("Should not pass as current version is 4.1.0 and the max value is 4.0.999"); // should never get here
}
catch (ModuleManagementToolException exception)
{
assertTrue(exception.getMessage().contains("cannot be installed on a war version greater than 4.0.999"));
}
}
@Test
public void testCheckCompatibleVersionUsingManifest() throws IOException
{
//Now check the compatible versions using the manifest
TFile theWar = getFile(".war", "module/share-3.4.11.war");
ModuleDetails installingModuleDetails = new ModuleDetailsImpl("test_it", new ModuleVersionNumber("9999"), "Test Mod", "Testing module");
// Now check the compatible versions using the manifest
TFile theWar = getFile(".war", "module/share-3.4.11.war");
ModuleDetails installingModuleDetails = new ModuleDetailsImpl("test_it", new ModuleVersionNumber("9999"), "Test Mod", "Testing module");
installingModuleDetails.setRepoVersionMin(new VersionNumber("10.1"));
try
{
this.checkCompatibleVersionUsingManifest(theWar, installingModuleDetails);
fail(); //should never get here
fail(); // should never get here
}
catch (ModuleManagementToolException exception)
{
@@ -163,163 +164,167 @@ public class WarHelperImplTest extends WarHelperImpl
}
installingModuleDetails.setRepoVersionMin(new VersionNumber("1.1"));
this.checkCompatibleVersionUsingManifest(theWar, installingModuleDetails); //does not throw exception
this.checkCompatibleVersionUsingManifest(theWar, installingModuleDetails); // does not throw exception
installingModuleDetails.setRepoVersionMax(new VersionNumber("3.0"));
try
{
this.checkCompatibleVersionUsingManifest(theWar, installingModuleDetails);
fail(); //should never get here
fail(); // should never get here
}
catch (ModuleManagementToolException exception)
{
assertTrue(exception.getMessage().contains("cannot be installed on a war version greater than 3.0"));
}
}
installingModuleDetails.setRepoVersionMax(new VersionNumber("99"));
this.checkCompatibleVersionUsingManifest(theWar, installingModuleDetails); //does not throw exception
installingModuleDetails.setRepoVersionMin(new VersionNumber("3.4.11")); //current war version
installingModuleDetails.setRepoVersionMax(new VersionNumber("3.4.11")); //current war version
this.checkCompatibleVersionUsingManifest(theWar, installingModuleDetails); //does not throw exception
installingModuleDetails.setRepoVersionMin(new VersionNumber("3.4.7")); //current war version
installingModuleDetails.setRepoVersionMax(new VersionNumber("3.4.11")); //current war version
this.checkCompatibleVersionUsingManifest(theWar, installingModuleDetails); //does not throw exception
this.checkCompatibleVersionUsingManifest(theWar, installingModuleDetails); // does not throw exception
installingModuleDetails.setRepoVersionMin(new VersionNumber("3.4.11")); // current war version
installingModuleDetails.setRepoVersionMax(new VersionNumber("3.4.11")); // current war version
this.checkCompatibleVersionUsingManifest(theWar, installingModuleDetails); // does not throw exception
installingModuleDetails.setRepoVersionMin(new VersionNumber("3.4.7")); // current war version
installingModuleDetails.setRepoVersionMax(new VersionNumber("3.4.11")); // current war version
this.checkCompatibleVersionUsingManifest(theWar, installingModuleDetails); // does not throw exception
try
{
installingModuleDetails.setRepoVersionMin(new VersionNumber("3.4.0")); //current war version
installingModuleDetails.setRepoVersionMax(new VersionNumber("3.4.10")); //current war version
this.checkCompatibleVersionUsingManifest(theWar, installingModuleDetails); //does not throw exception
fail("Should not pass as current version is 3.4.11 and the max value is 3.4.10"); //should never get here
installingModuleDetails.setRepoVersionMin(new VersionNumber("3.4.0")); // current war version
installingModuleDetails.setRepoVersionMax(new VersionNumber("3.4.10")); // current war version
this.checkCompatibleVersionUsingManifest(theWar, installingModuleDetails); // does not throw exception
fail("Should not pass as current version is 3.4.11 and the max value is 3.4.10"); // should never get here
}
catch (ModuleManagementToolException exception)
{
assertTrue(exception.getMessage().contains("cannot be installed on a war version greater than 3.4.10"));
}
theWar = getFile(".war", "module/share-4.2.a.war");
installingModuleDetails = new ModuleDetailsImpl("test_it", new ModuleVersionNumber("9999"), "Test Mod", "Testing module");
installingModuleDetails.setRepoVersionMin(new VersionNumber("101.1"));
//this should fail BUT we are using a non-numeric version number so instead it passes without validation
this.checkCompatibleVersionUsingManifest(theWar, installingModuleDetails);
theWar = getFile(".war", "module/alfresco-4.2.a.war");
//this should fail BUT we are using a non-numeric version number so instead it passes without validation
this.checkCompatibleVersionUsingManifest(theWar, installingModuleDetails);
}
theWar = getFile(".war", "module/share-4.2.a.war");
installingModuleDetails = new ModuleDetailsImpl("test_it", new ModuleVersionNumber("9999"), "Test Mod", "Testing module");
installingModuleDetails.setRepoVersionMin(new VersionNumber("101.1"));
// this should fail BUT we are using a non-numeric version number so instead it passes without validation
this.checkCompatibleVersionUsingManifest(theWar, installingModuleDetails);
theWar = getFile(".war", "module/alfresco-4.2.a.war");
// this should fail BUT we are using a non-numeric version number so instead it passes without validation
this.checkCompatibleVersionUsingManifest(theWar, installingModuleDetails);
}
@Test
public void testCheckCompatibleEdition()
{
Properties props = dummyModuleProperties();
ModuleDetails installingModuleDetails = new ModuleDetailsImpl(props);
TFile theWar = getFile(".war", "module/test.war"); //Community Edition
//Test for no edition specified
this.checkCompatibleEdition(theWar, installingModuleDetails); //does not throw exception
//Test for invalid edition
TFile theWar = getFile(".war", "module/test.war"); // Community Edition
// Test for no edition specified
this.checkCompatibleEdition(theWar, installingModuleDetails); // does not throw exception
// Test for invalid edition
props.setProperty(ModuleDetails.PROP_EDITIONS, "CommuniT");
installingModuleDetails = new ModuleDetailsImpl(props);
try
{
this.checkCompatibleEdition(theWar, installingModuleDetails);
fail(); //should never get here
fail(); // should never get here
}
catch (ModuleManagementToolException exception)
{
assertTrue(exception.getMessage().endsWith("can only be installed in one of the following editions[CommuniT]"));
}
props.setProperty(ModuleDetails.PROP_EDITIONS, ("CoMMunity")); //should ignore case
props.setProperty(ModuleDetails.PROP_EDITIONS, ("CoMMunity")); // should ignore case
installingModuleDetails = new ModuleDetailsImpl(props);
this.checkCompatibleEdition(theWar, installingModuleDetails); //does not throw exception
props.setProperty(ModuleDetails.PROP_EDITIONS, ("enterprise,community,bob")); //should ignore case
this.checkCompatibleEdition(theWar, installingModuleDetails); // does not throw exception
props.setProperty(ModuleDetails.PROP_EDITIONS, ("enterprise,community,bob")); // should ignore case
installingModuleDetails = new ModuleDetailsImpl(props);
this.checkCompatibleEdition(theWar, installingModuleDetails); //does not throw exception
props.setProperty(ModuleDetails.PROP_EDITIONS, ("enterprise,Community")); //should ignore case
installingModuleDetails = new ModuleDetailsImpl(props);
this.checkCompatibleVersion(theWar, installingModuleDetails); //does not throw exception
this.checkCompatibleEdition(theWar, installingModuleDetails); // does not throw exception
props.setProperty(ModuleDetails.PROP_EDITIONS, ("enterprise,Community")); // should ignore case
installingModuleDetails = new ModuleDetailsImpl(props);
this.checkCompatibleVersion(theWar, installingModuleDetails); // does not throw exception
}
@Test
public void testCheckCompatibleEditionUsingManifest() throws IOException
{
Properties props = dummyModuleProperties();
ModuleDetails installingModuleDetails = new ModuleDetailsImpl(props);
TFile theWar = getFile(".war", "module/share-3.4.11.war"); //enterprise edition
//Test for no edition specified
this.checkCompatibleEditionUsingManifest(theWar, installingModuleDetails); //does not throw exception
//Test for invalid edition
TFile theWar = getFile(".war", "module/share-3.4.11.war"); // enterprise edition
// Test for no edition specified
this.checkCompatibleEditionUsingManifest(theWar, installingModuleDetails); // does not throw exception
// Test for invalid edition
props.setProperty(ModuleDetails.PROP_EDITIONS, "CommuniT");
installingModuleDetails = new ModuleDetailsImpl(props);
try
{
this.checkCompatibleEditionUsingManifest(theWar, installingModuleDetails);
fail(); //should never get here
fail(); // should never get here
}
catch (ModuleManagementToolException exception)
{
assertTrue(exception.getMessage().endsWith("can only be installed in one of the following editions[CommuniT]"));
}
props.setProperty(ModuleDetails.PROP_EDITIONS, ("Enterprise")); //should ignore case
installingModuleDetails = new ModuleDetailsImpl(props);
this.checkCompatibleEditionUsingManifest(theWar, installingModuleDetails); //does not throw exception
props.setProperty(ModuleDetails.PROP_EDITIONS, ("Community")); //should ignore case
installingModuleDetails = new ModuleDetailsImpl(props);
props.setProperty(ModuleDetails.PROP_EDITIONS, ("Enterprise")); // should ignore case
installingModuleDetails = new ModuleDetailsImpl(props);
this.checkCompatibleEditionUsingManifest(theWar, installingModuleDetails); // does not throw exception
props.setProperty(ModuleDetails.PROP_EDITIONS, ("Community")); // should ignore case
installingModuleDetails = new ModuleDetailsImpl(props);
try
{
this.checkCompatibleEditionUsingManifest(theWar, installingModuleDetails);
fail(); //should never get here
fail(); // should never get here
}
catch (ModuleManagementToolException exception)
{
assertTrue(exception.getMessage().endsWith("can only be installed in one of the following editions[Community]"));
}
theWar = getFile(".war", "module/share-4.2.a.war");
theWar = getFile(".war", "module/share-4.2.a.war");
this.checkCompatibleEditionUsingManifest(theWar, installingModuleDetails);
String propertiesLocation = getFile(".amp", "module/test_v5.amp") + "/module.properties";
installingModuleDetails = ModuleDetailsHelper.createModuleDetailsFromPropertyLocation(propertiesLocation);
try {
this.checkCompatibleEdition(theWar, installingModuleDetails);
fail(); //should never get here
} catch (ModuleManagementToolException exception) {
assertTrue(exception.getMessage().endsWith("can only be installed in one of the following editions[Enterprise]"));
}
String propertiesLocation = getFile(".amp", "module/test_v5.amp") + "/module.properties";
installingModuleDetails = ModuleDetailsHelper.createModuleDetailsFromPropertyLocation(propertiesLocation);
try
{
this.checkCompatibleEdition(theWar, installingModuleDetails);
fail(); // should never get here
}
catch (ModuleManagementToolException exception)
{
assertTrue(exception.getMessage().endsWith("can only be installed in one of the following editions[Enterprise]"));
}
theWar = getFile(".war", "module/share-3.4.11.war");
this.checkCompatibleEdition(theWar, installingModuleDetails);//should succeed
try {
theWar = getFile(".war", "module/share-4.2.a.war");
this.checkCompatibleEdition(theWar, installingModuleDetails);
fail(); //should never get here
} catch (ModuleManagementToolException exception) {
assertTrue(exception.getMessage().endsWith("can only be installed in one of the following editions[Enterprise]"));
}
this.checkCompatibleEdition(theWar, installingModuleDetails);// should succeed
try
{
theWar = getFile(".war", "module/share-4.2.a.war");
this.checkCompatibleEdition(theWar, installingModuleDetails);
fail(); // should never get here
}
catch (ModuleManagementToolException exception)
{
assertTrue(exception.getMessage().endsWith("can only be installed in one of the following editions[Enterprise]"));
}
}
@Test
public void testfindManifest() throws Exception {
//Now check the compatible versions using the manifest
public void testfindManifest() throws Exception
{
// Now check the compatible versions using the manifest
TFile theWar = getFile(".war", "module/share-3.4.11.war");
Manifest manifest = this.findManifest(theWar);
@@ -338,13 +343,13 @@ public class WarHelperImplTest extends WarHelperImpl
@Test
public void testListModules() throws Exception
{
TFile theWar = getFile(".war", "module/test.war");
TFile theWar = getFile(".war", "module/test.war");
List<ModuleDetails> details = this.listModules(theWar);
assertNotNull(details);
assertEquals(details.size(), 0);
theWar = getFile(".war", "module/share-4.2.a.war");
theWar = getFile(".war", "module/share-4.2.a.war");
details = this.listModules(theWar);
assertNotNull(details);
assertEquals(details.size(), 1);
@@ -355,51 +360,51 @@ public class WarHelperImplTest extends WarHelperImpl
}
private Properties dummyModuleProperties() {
Properties props = new Properties();
private Properties dummyModuleProperties()
{
Properties props = new Properties();
props.setProperty(ModuleDetails.PROP_ID, "TestComp");
props.setProperty(ModuleDetails.PROP_VERSION, "9999");
props.setProperty(ModuleDetails.PROP_TITLE, "Test for Compatiblity");
props.setProperty(ModuleDetails.PROP_DESCRIPTION, "Test for Compatible Editions");
return props;
}
return props;
}
@Test
public void testNoVersionProperties()
{
TFile theWar = getFile(".war", "module/empty.war");
TFile theWar = getFile(".war", "module/empty.war");
ModuleDetails installingModuleDetails = new ModuleDetailsImpl("test_it", new ModuleVersionNumber("9999"), "Test Mod", "Testing module");
ModuleDetails installingModuleDetails = new ModuleDetailsImpl("test_it", new ModuleVersionNumber("9999"), "Test Mod", "Testing module");
installingModuleDetails.setRepoVersionMin(new VersionNumber("10.1"));
this.checkCompatibleVersion(theWar, installingModuleDetails); //does not throw exception
this.checkCompatibleEdition(theWar, installingModuleDetails); //does not throw exception
this.checkCompatibleVersion(theWar, installingModuleDetails); // does not throw exception
this.checkCompatibleEdition(theWar, installingModuleDetails); // does not throw exception
}
/**
* Tests to see if the war is a share war.
*/
@Test
public void testIsShareWar()
{
TFile theWar = getFile(".war", "module/test.war"); //Version 4.1.0
assertFalse(this.isShareWar(theWar));
TFile theWar = getFile(".war", "module/test.war"); // Version 4.1.0
assertFalse(this.isShareWar(theWar));
theWar = getFile(".war", "module/empty.war");
assertFalse(this.isShareWar(theWar));
theWar = getFile(".war", "module/alfresco-4.2.a.war");
assertFalse(this.isShareWar(theWar));
theWar = getFile(".war", "module/share-4.2.a.war");
assertTrue(this.isShareWar(theWar));
theWar = getFile(".war", "module/empty.war");
assertFalse(this.isShareWar(theWar));
theWar = getFile(".war", "module/alfresco-4.2.a.war");
assertFalse(this.isShareWar(theWar));
theWar = getFile(".war", "module/share-4.2.a.war");
assertTrue(this.isShareWar(theWar));
}
private TFile getFile(String extension, String location)
private TFile getFile(String extension, String location)
{
File file = TempFileProvider.createTempFile("moduleManagementToolTest-", extension);
File file = TempFileProvider.createTempFile("moduleManagementToolTest-", extension);
InputStream is = this.getClass().getClassLoader().getResourceAsStream(location);
assertNotNull(is);
OutputStream os;
@@ -411,7 +416,7 @@ public class WarHelperImplTest extends WarHelperImpl
catch (IOException error)
{
error.printStackTrace();
}
}
return new TFile(file);
}
}
}