@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 props.setProperty(ModuleDetails.PROP_EDITIONS, "CommuniT"); installingModuleDetails = new ModuleDetailsImpl(props); 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[CommuniT]")); } 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 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 }
@Test public void testCheckCompatibleVersion() { TFile theWar = getFile(".war", "module/test.war"); // Version 4.1.0 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 } catch (ModuleManagementToolException exception) { assertTrue( exception.getMessage().contains("must be installed on a war version greater than 10.1")); } installingModuleDetails.setRepoVersionMin(new VersionNumber("1.1")); this.checkCompatibleVersion(theWar, installingModuleDetails); // does not throw exception installingModuleDetails.setRepoVersionMax(new VersionNumber("3.0")); try { this.checkCompatibleVersion(theWar, installingModuleDetails); 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 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 } catch (ModuleManagementToolException exception) { assertTrue( exception .getMessage() .contains("cannot be installed on a war version greater than 4.0.999")); } }
@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 props.setProperty(ModuleDetails.PROP_EDITIONS, "CommuniT"); installingModuleDetails = new ModuleDetailsImpl(props); try { this.checkCompatibleEditionUsingManifest(theWar, installingModuleDetails); 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); try { this.checkCompatibleEditionUsingManifest(theWar, installingModuleDetails); 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"); 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]")); } 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]")); } }
@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"); installingModuleDetails.setRepoVersionMin(new VersionNumber("10.1")); try { this.checkCompatibleVersionUsingManifest(theWar, installingModuleDetails); fail(); // should never get here } catch (ModuleManagementToolException exception) { assertTrue( exception.getMessage().contains("must be installed on a war version greater than 10.1")); } installingModuleDetails.setRepoVersionMin(new VersionNumber("1.1")); this.checkCompatibleVersionUsingManifest( theWar, installingModuleDetails); // does not throw exception installingModuleDetails.setRepoVersionMax(new VersionNumber("3.0")); try { this.checkCompatibleVersionUsingManifest(theWar, installingModuleDetails); 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 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 } 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); }
/** * Main * * @param args command line interface arguments */ public static void main(String[] args) { if (args.length <= 1) { outputUsage(); System.exit(ERROR_EXIT_CODE); } ModuleManagementTool manager = new ModuleManagementTool(); String operation = args[0]; if (operation.equals(OP_INSTALL) == true && args.length >= 3) { String aepFileLocation = args[1]; String warFileLocation = args[2]; boolean forceInstall = false; boolean previewInstall = false; boolean backup = true; boolean directory = false; if (args.length > 3) { for (int i = 3; i < args.length; i++) { String option = args[i]; if (OPTION_VERBOSE.equals(option) == true) { manager.setVerbose(true); } else if (OPTION_FORCE.equals(option) == true) { forceInstall = true; } else if (OPTION_PREVIEW.equals(option) == true) { previewInstall = true; manager.setVerbose(true); } else if (OPTION_NOBACKUP.equals(option) == true) { backup = false; } else if (OPTION_DIRECTORY.equals(option) == true) { directory = true; } } } try { if (directory == false) { // Install the module manager.installModule( aepFileLocation, warFileLocation, previewInstall, forceInstall, backup); } else { // Install the modules from the directory manager.installModules( aepFileLocation, warFileLocation, previewInstall, forceInstall, backup); } System.exit(SUCCESS_EXIT_CODE); } catch (ModuleManagementToolException e) { // These are user-friendly manager.outputMessage(e.getMessage()); outputUsage(); System.exit(ERROR_EXIT_CODE); } } else if (OP_LIST.equals(operation) == true && args.length == 2) { // List the installed modules String warFileLocation = args[1]; manager.listModules(warFileLocation); System.exit(SUCCESS_EXIT_CODE); } else { outputUsage(); System.exit(SUCCESS_EXIT_CODE); } }