mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Merged HEAD-QA to HEAD (4.2) (including moving test classes into separate folders)
51903 to 54309 git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@54310 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -1,144 +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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.alfresco.repo.module;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import javax.transaction.UserTransaction;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationComponent;
|
||||
import org.alfresco.service.ServiceRegistry;
|
||||
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||
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.search.CategoryService;
|
||||
import org.alfresco.service.transaction.TransactionService;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
/**
|
||||
* Tests various module components.
|
||||
*
|
||||
* @see org.alfresco.repo.module.ImporterModuleComponent
|
||||
* @see org.alfresco.repo.module.ModuleComponent
|
||||
*
|
||||
* @author Derek Hulley
|
||||
*/
|
||||
public class ComponentsTest extends TestCase
|
||||
{
|
||||
private static ApplicationContext ctx = new ClassPathXmlApplicationContext("module/module-component-test-beans.xml");
|
||||
|
||||
private ServiceRegistry serviceRegistry;
|
||||
private AuthenticationComponent authenticationComponent;
|
||||
private TransactionService transactionService;
|
||||
private NodeService nodeService;
|
||||
private UserTransaction txn;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception
|
||||
{
|
||||
serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);
|
||||
authenticationComponent = (AuthenticationComponent) ctx.getBean("AuthenticationComponent");
|
||||
transactionService = serviceRegistry.getTransactionService();
|
||||
nodeService = serviceRegistry.getNodeService();
|
||||
|
||||
// Run as system user
|
||||
authenticationComponent.setSystemUserAsCurrentUser();
|
||||
|
||||
// Start a transaction
|
||||
txn = transactionService.getUserTransaction();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception
|
||||
{
|
||||
// Clear authentication
|
||||
try
|
||||
{
|
||||
authenticationComponent.clearCurrentSecurityContext();
|
||||
}
|
||||
catch (Throwable e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
// Rollback the transaction
|
||||
try
|
||||
{
|
||||
// txn.rollback();
|
||||
txn.commit();
|
||||
}
|
||||
catch (Throwable e)
|
||||
{
|
||||
// Ignore
|
||||
}
|
||||
}
|
||||
|
||||
/** Ensure that the test starts and stops properly */
|
||||
public void testSetup() throws Exception
|
||||
{
|
||||
}
|
||||
|
||||
private NodeRef getLoadedCategoryRoot()
|
||||
{
|
||||
StoreRef storeRef = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore");
|
||||
|
||||
CategoryService categoryService = serviceRegistry.getCategoryService();
|
||||
// Check if the categories exist
|
||||
Collection<ChildAssociationRef> assocRefs = categoryService.getRootCategories(
|
||||
storeRef,
|
||||
ContentModel.ASPECT_GEN_CLASSIFIABLE);
|
||||
// Find it
|
||||
for (ChildAssociationRef assocRef : assocRefs)
|
||||
{
|
||||
NodeRef nodeRef = assocRef.getChildRef();
|
||||
if (nodeRef.getId().equals("test:xyz-root"))
|
||||
{
|
||||
// Found it
|
||||
return nodeRef;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void testImporterModuleComponent() throws Exception
|
||||
{
|
||||
// Delete any pre-existing data
|
||||
NodeRef nodeRef = getLoadedCategoryRoot();
|
||||
if (nodeRef != null)
|
||||
{
|
||||
CategoryService categoryService = serviceRegistry.getCategoryService();
|
||||
categoryService.deleteCategory(nodeRef);
|
||||
}
|
||||
// Double check to make sure it is gone
|
||||
nodeRef = getLoadedCategoryRoot();
|
||||
assertNull("Category not deleted", nodeRef);
|
||||
|
||||
ImporterModuleComponent component = (ImporterModuleComponent) ctx.getBean("module.test.importerComponent");
|
||||
// Execute it
|
||||
component.execute();
|
||||
|
||||
// Now make sure the data exists
|
||||
nodeRef = getLoadedCategoryRoot();
|
||||
assertNotNull("Loaded category root not found", nodeRef);
|
||||
}
|
||||
}
|
@@ -1,319 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2013 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.alfresco.repo.module;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.repo.admin.registry.RegistryService;
|
||||
import org.alfresco.repo.tenant.TenantAdminService;
|
||||
import org.alfresco.service.cmr.module.ModuleDetails;
|
||||
import org.alfresco.service.cmr.module.ModuleService;
|
||||
import org.alfresco.service.descriptor.DescriptorService;
|
||||
import org.alfresco.util.BaseAlfrescoTestCase;
|
||||
import org.alfresco.util.GUID;
|
||||
import org.alfresco.util.VersionNumber;
|
||||
|
||||
/**
|
||||
* @see org.alfresco.repo.module.ModuleComponentHelper
|
||||
* <p/>
|
||||
* This test creates a bunch of dummy components and then simulates
|
||||
* startups with different module current versions.
|
||||
* <p/>
|
||||
* There are 3 modules. There are 3 components.
|
||||
*
|
||||
* @author Derek Hulley
|
||||
*/
|
||||
public class ModuleComponentHelperTest extends BaseAlfrescoTestCase
|
||||
{
|
||||
private final String SOME_GUID = "" + GUID.generate();
|
||||
private final String[] MODULE_IDS =
|
||||
{
|
||||
"M0 @ " + SOME_GUID,
|
||||
"M1 @ " + SOME_GUID,
|
||||
"M2 @ " + SOME_GUID
|
||||
};
|
||||
private final String[] COMPONENT_NAMES =
|
||||
{
|
||||
"C0 @ " + SOME_GUID,
|
||||
"C1 @ " + SOME_GUID,
|
||||
"C2 @ " + SOME_GUID
|
||||
};
|
||||
private final VersionNumber[] VERSIONS =
|
||||
{
|
||||
new VersionNumber("0"),
|
||||
new VersionNumber("1"),
|
||||
new VersionNumber("2"),
|
||||
new VersionNumber("3")
|
||||
};
|
||||
private static final Map<VersionNumber, Integer> EXECUTION_COUNT_BY_VERSION;
|
||||
static
|
||||
{
|
||||
EXECUTION_COUNT_BY_VERSION = new HashMap<VersionNumber, Integer>(13);
|
||||
EXECUTION_COUNT_BY_VERSION.put(new VersionNumber("0.0"), 3);
|
||||
EXECUTION_COUNT_BY_VERSION.put(new VersionNumber("0.5"), 3);
|
||||
EXECUTION_COUNT_BY_VERSION.put(new VersionNumber("1.0"), 6);
|
||||
EXECUTION_COUNT_BY_VERSION.put(new VersionNumber("1.5"), 3);
|
||||
EXECUTION_COUNT_BY_VERSION.put(new VersionNumber("2.0"), 6);
|
||||
EXECUTION_COUNT_BY_VERSION.put(new VersionNumber("2.5"), 3);
|
||||
EXECUTION_COUNT_BY_VERSION.put(new VersionNumber("3.0"), 3);
|
||||
EXECUTION_COUNT_BY_VERSION.put(new VersionNumber("3.5"), 0);
|
||||
};
|
||||
|
||||
private RegistryService registryService;
|
||||
private TenantAdminService tenantAdminService;
|
||||
private DescriptorService descriptorService;
|
||||
private DummyModuleService moduleService;
|
||||
private ModuleComponentHelper helper;
|
||||
|
||||
private DummyModuleComponent[][] components;
|
||||
|
||||
public void setUp() throws Exception
|
||||
{
|
||||
super.setUp();
|
||||
|
||||
registryService = (RegistryService) ctx.getBean("RegistryService");
|
||||
tenantAdminService = (TenantAdminService) ctx.getBean("tenantAdminService");
|
||||
|
||||
descriptorService = serviceRegistry.getDescriptorService();
|
||||
|
||||
moduleService = new DummyModuleService();
|
||||
helper = new ModuleComponentHelper();
|
||||
helper.setModuleService(moduleService);
|
||||
helper.setRegistryService(registryService);
|
||||
helper.setServiceRegistry(serviceRegistry);
|
||||
helper.setDescriptorService(descriptorService);
|
||||
helper.setTenantAdminService(tenantAdminService);
|
||||
|
||||
// Register the components
|
||||
components = new DummyModuleComponent[3][3]; // i,j
|
||||
for (int i = 0; i < 3; i++) // i = module number
|
||||
{
|
||||
for (int j = 0; j < 3; j++) // j = component number
|
||||
{
|
||||
DummyModuleComponent component = new DummyModuleComponent(
|
||||
MODULE_IDS[i],
|
||||
COMPONENT_NAMES[j],
|
||||
VERSIONS[j],
|
||||
VERSIONS[j+1]);
|
||||
component.setServiceRegistry(serviceRegistry);
|
||||
component.setAuthenticationComponent(authenticationComponent);
|
||||
component.setModuleService(moduleService);
|
||||
component.setTenantAdminService(tenantAdminService);
|
||||
// Don't initialize the component as that will do the registration. We do it manually.
|
||||
helper.registerComponent(component);
|
||||
// Add to array
|
||||
components[i][j] = component;
|
||||
}
|
||||
}
|
||||
// M1-C1 depends on M0-C1
|
||||
components[1][1].setDependsOn(Collections.<ModuleComponent>singletonList(components[0][1]));
|
||||
}
|
||||
|
||||
public void testSetup() throws Exception
|
||||
{
|
||||
// See that it all starts OK
|
||||
}
|
||||
|
||||
private void startComponents(VersionNumber moduleVersion)
|
||||
{
|
||||
int expectedCount = (Integer) EXECUTION_COUNT_BY_VERSION.get(moduleVersion);
|
||||
// Set the current version number for all modules
|
||||
moduleService.setCurrentVersion(moduleVersion);
|
||||
// Start them
|
||||
helper.startModules();
|
||||
|
||||
// ALF-19207: MT module startup does not work
|
||||
// int tenantCount = 0;
|
||||
// if (tenantDeployerService.isEnabled())
|
||||
// {
|
||||
// tenantCount = tenantDeployerService.getTenants(true).size();
|
||||
// }
|
||||
// // Check
|
||||
// assertEquals(
|
||||
// "Incorrent number of executions (version " + moduleVersion + ")",
|
||||
// expectedCount + (expectedCount * tenantCount),
|
||||
// executed);
|
||||
// Check
|
||||
assertEquals("Incorrent number of executions (version " + moduleVersion + ")", expectedCount, executed);
|
||||
}
|
||||
|
||||
public void testStartComponentsV00()
|
||||
{
|
||||
VersionNumber moduleVersion = new VersionNumber("0.0");
|
||||
startComponents(moduleVersion);
|
||||
}
|
||||
|
||||
public void testStartComponentsV05()
|
||||
{
|
||||
VersionNumber moduleVersion = new VersionNumber("0.5");
|
||||
startComponents(moduleVersion);
|
||||
}
|
||||
|
||||
public void testStartComponentsV10()
|
||||
{
|
||||
VersionNumber moduleVersion = new VersionNumber("1.0");
|
||||
startComponents(moduleVersion);
|
||||
}
|
||||
|
||||
public void testStartComponentsV15()
|
||||
{
|
||||
VersionNumber moduleVersion = new VersionNumber("1.5");
|
||||
startComponents(moduleVersion);
|
||||
}
|
||||
|
||||
public void testStartComponentsV30()
|
||||
{
|
||||
VersionNumber moduleVersion = new VersionNumber("3.0");
|
||||
startComponents(moduleVersion);
|
||||
}
|
||||
|
||||
public void testStartComponentsV35()
|
||||
{
|
||||
VersionNumber moduleVersion = new VersionNumber("3.5");
|
||||
startComponents(moduleVersion);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper bean to simulate module presences under controlled conditions.
|
||||
*/
|
||||
private class DummyModuleService implements ModuleService
|
||||
{
|
||||
private VersionNumber currentVersion;
|
||||
/** Set the current version of all the modules */
|
||||
public void setCurrentVersion(VersionNumber currentVersion)
|
||||
{
|
||||
this.currentVersion = currentVersion;
|
||||
}
|
||||
|
||||
public void registerComponent(ModuleComponent component)
|
||||
{
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public List<ModuleDetails> getAllModules()
|
||||
{
|
||||
// Reset the execution count
|
||||
executed = 0;
|
||||
// Create some module details
|
||||
List<ModuleDetails> details = new ArrayList<ModuleDetails>(3);
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
ModuleDetails moduleDetails = new ModuleDetailsImpl(
|
||||
MODULE_IDS[i],
|
||||
currentVersion,
|
||||
"Module-" + i,
|
||||
"Description-" + i);
|
||||
details.add(moduleDetails);
|
||||
}
|
||||
// Done
|
||||
return details;
|
||||
}
|
||||
|
||||
public ModuleDetails getModule(String moduleId)
|
||||
{
|
||||
for (int i = 0; i < MODULE_IDS.length; i++)
|
||||
{
|
||||
if (!MODULE_IDS[i].equals(moduleId))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
new ModuleDetailsImpl(
|
||||
MODULE_IDS[i],
|
||||
currentVersion,
|
||||
"Module-" + i,
|
||||
"Description-" + i);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void startModules()
|
||||
{
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ModuleDetails> getMissingModules()
|
||||
{
|
||||
// Create some module details
|
||||
List<ModuleDetails> details = new ArrayList<ModuleDetails>(3);
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
ModuleDetails moduleDetails = new ModuleDetailsImpl(
|
||||
MODULE_IDS[i],
|
||||
currentVersion,
|
||||
"",
|
||||
"");
|
||||
details.add(moduleDetails);
|
||||
}
|
||||
// Done
|
||||
return details;
|
||||
}
|
||||
|
||||
public void shutdownModules()
|
||||
{
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
/** Keep track of the execution count */
|
||||
private volatile int executed = 0;
|
||||
|
||||
/**
|
||||
* A dummy
|
||||
* @author Derek Hulley
|
||||
*/
|
||||
private class DummyModuleComponent extends AbstractModuleComponent
|
||||
{
|
||||
private DummyModuleComponent(String moduleId, String name, VersionNumber from, VersionNumber to)
|
||||
{
|
||||
super.setServiceRegistry(serviceRegistry);
|
||||
super.setAuthenticationComponent(authenticationComponent);
|
||||
super.setModuleService(moduleService);
|
||||
super.setTenantAdminService(tenantAdminService);
|
||||
|
||||
super.setModuleId(moduleId);
|
||||
super.setName(name);
|
||||
super.setAppliesFromVersion(from.toString());
|
||||
super.setAppliesToVersion(to.toString());
|
||||
super.setSinceVersion("10.1.2");
|
||||
|
||||
super.setDescription("A dummy module component");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void executeInternal() throws Throwable
|
||||
{
|
||||
// Record execution
|
||||
executed++;
|
||||
}
|
||||
}
|
||||
|
||||
/** No-operation tester class */
|
||||
public static class NoopModuleComponent extends AbstractModuleComponent
|
||||
{
|
||||
@Override
|
||||
protected void executeInternal() throws Throwable
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,136 +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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.alfresco.repo.module;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.service.cmr.module.ModuleDependency;
|
||||
import org.alfresco.service.cmr.module.ModuleDetails;
|
||||
import org.alfresco.service.cmr.module.ModuleInstallState;
|
||||
import org.alfresco.util.VersionNumber;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
* @see org.alfresco.repo.module.ModuleDetailsImpl
|
||||
*
|
||||
* @author Derek Hulley
|
||||
*/
|
||||
public class ModuleDetailsImplTest extends TestCase
|
||||
{
|
||||
private Properties defaultProperties;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception
|
||||
{
|
||||
defaultProperties = new Properties();
|
||||
defaultProperties.setProperty(ModuleDetails.PROP_ID, "org.alfresco.module.Test");
|
||||
defaultProperties.setProperty(ModuleDetails.PROP_ALIASES, "test, Test");
|
||||
defaultProperties.setProperty(ModuleDetails.PROP_TITLE, "Test");
|
||||
defaultProperties.setProperty(ModuleDetails.PROP_DESCRIPTION, "Test description");
|
||||
defaultProperties.setProperty(ModuleDetails.PROP_VERSION, "1.0.0");
|
||||
defaultProperties.setProperty(ModuleDetails.PROP_EDITIONS, "Community, Enterprise");
|
||||
defaultProperties.setProperty(ModuleDetails.PROP_REPO_VERSION_MIN, new VersionNumber("1.2").toString());
|
||||
defaultProperties.setProperty(ModuleDetails.PROP_REPO_VERSION_MAX, new VersionNumber("1.4.3").toString());
|
||||
defaultProperties.setProperty(ModuleDetails.PROP_DEPENDS_PREFIX + "a", "1.2.3");
|
||||
defaultProperties.setProperty(ModuleDetails.PROP_DEPENDS_PREFIX + "b", "*");
|
||||
defaultProperties.setProperty(ModuleDetails.PROP_DEPENDS_PREFIX + "c", "- 1.2");
|
||||
defaultProperties.setProperty(ModuleDetails.PROP_DEPENDS_PREFIX + "d", "1.2 -");
|
||||
defaultProperties.setProperty(ModuleDetails.PROP_DEPENDS_PREFIX + "e", "* - 1.2");
|
||||
defaultProperties.setProperty(ModuleDetails.PROP_DEPENDS_PREFIX + "f", "1.2 - *");
|
||||
defaultProperties.setProperty(ModuleDetails.PROP_DEPENDS_PREFIX + "g", "0.5, 0.6");
|
||||
defaultProperties.setProperty(ModuleDetails.PROP_DEPENDS_PREFIX + "h", "0.5 - 0.6, 0.9 - *");
|
||||
defaultProperties.setProperty(ModuleDetails.PROP_INSTALL_STATE, ModuleInstallState.INSTALLED.toString());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public void testDefaults()
|
||||
{
|
||||
ModuleDetails details = new ModuleDetailsImpl(defaultProperties);
|
||||
}
|
||||
|
||||
public void testWriteAndReadProperties()
|
||||
{
|
||||
ModuleDetails details = new ModuleDetailsImpl(defaultProperties);
|
||||
// convert back to properties
|
||||
Properties processedProperties = details.getProperties();
|
||||
assertEquals("The number of properties changed", defaultProperties.size(), processedProperties.size());
|
||||
assertEquals("The properties are different", defaultProperties, processedProperties);
|
||||
}
|
||||
|
||||
public void testDependencyChecks()
|
||||
{
|
||||
ModuleDetails details = new ModuleDetailsImpl(defaultProperties);
|
||||
|
||||
Properties tempProperties = new Properties();
|
||||
tempProperties.setProperty(ModuleDetails.PROP_ID, "a");
|
||||
tempProperties.setProperty(ModuleDetails.PROP_TITLE, "A");
|
||||
tempProperties.setProperty(ModuleDetails.PROP_DESCRIPTION, "A description");
|
||||
tempProperties.setProperty(ModuleDetails.PROP_VERSION, "1.0.0");
|
||||
ModuleDetails tempDetails = new ModuleDetailsImpl(tempProperties);
|
||||
|
||||
List<ModuleDependency> dependencies = details.getDependencies();
|
||||
assertEquals("Incorrect number of dependencies", 8, dependencies.size());
|
||||
for (ModuleDependency dependency : dependencies)
|
||||
{
|
||||
if (dependency.getDependencyId().equals(tempDetails.getId()))
|
||||
{
|
||||
// It should not match
|
||||
assertFalse("No match expected", dependency.isValidDependency(tempDetails));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void testTrimming() throws Exception
|
||||
{
|
||||
defaultProperties.setProperty(ModuleDetails.PROP_INSTALL_STATE, " ");
|
||||
ModuleDetails details = new ModuleDetailsImpl(defaultProperties);
|
||||
assertEquals("Expected the install state to be UNKNOWN", ModuleInstallState.UNKNOWN, details.getInstallState());
|
||||
}
|
||||
|
||||
public void testInvalidIds() throws Exception
|
||||
{
|
||||
String[] invalidIds = new String[] {"", " ", "$", "module$Test", "module.Test$", "org alfresco module Test"};
|
||||
for (String invalidId : invalidIds)
|
||||
{
|
||||
try
|
||||
{
|
||||
defaultProperties.setProperty(ModuleDetails.PROP_ID, invalidId);
|
||||
new ModuleDetailsImpl(defaultProperties);
|
||||
fail("Invalid ID not detected: " + invalidId);
|
||||
}
|
||||
catch (AlfrescoRuntimeException e)
|
||||
{
|
||||
// Expected
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void testValidIds() throws Exception
|
||||
{
|
||||
String[] validIds = new String[] {"abc123", " abc123 ", "a-b-c", "a.b.c", "a_b_c", "A.1.2.3"};
|
||||
for (String validId : validIds)
|
||||
{
|
||||
defaultProperties.setProperty(ModuleDetails.PROP_ID, validId);
|
||||
new ModuleDetailsImpl(defaultProperties);
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,450 +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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.alfresco.repo.module.tool;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.alfresco.util.TempFileProvider;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
|
||||
import de.schlichtherle.truezip.file.TFile;
|
||||
import de.schlichtherle.truezip.file.TFileInputStream;
|
||||
import de.schlichtherle.truezip.file.TVFS;
|
||||
|
||||
/**
|
||||
* @see org.alfresco.repo.module.tool.ModuleManagementTool
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
* @author Derek Hulley
|
||||
*/
|
||||
public class ModuleManagementToolTest extends TestCase
|
||||
{
|
||||
private ModuleManagementTool manager = new ModuleManagementTool();
|
||||
static final int BUFFER = 2048;
|
||||
|
||||
public void testBasicInstall()
|
||||
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);
|
||||
}
|
||||
|
||||
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");
|
||||
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");
|
||||
files.add("/WEB-INF/classes/alfresco/module/test");
|
||||
files.add("/WEB-INF/licenses/license.txt");
|
||||
files.add("/scripts/test.js");
|
||||
files.add("/images/test.jpg");
|
||||
files.add("/jsp/test.jsp");
|
||||
files.add("/css/test.css");
|
||||
files.add("/extra.txt");
|
||||
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());
|
||||
|
||||
// Try and install same version
|
||||
try
|
||||
{
|
||||
this.manager.installModule(ampLocation, warLocation);
|
||||
// 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)
|
||||
{
|
||||
// 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");
|
||||
files.add("/WEB-INF/classes/alfresco/module/test/modifications.install");
|
||||
files2.add("/WEB-INF/lib/test.jar");
|
||||
files2.add("/WEB-INF/classes/alfresco/module/test/module-context.xml");
|
||||
files2.add("/WEB-INF/classes/alfresco/module/test");
|
||||
files2.add("/WEB-INF/licenses/license.txt");
|
||||
files2.add("/scripts/test2.js");
|
||||
files2.add("/scripts/test3.js");
|
||||
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);
|
||||
|
||||
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();
|
||||
assertNotNull(installed1);
|
||||
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
|
||||
{
|
||||
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
|
||||
|
||||
// Check that the war has not been modified
|
||||
checkForFileExistance(warLocation, files2);
|
||||
checkForFileNonExistance(warLocation, files3);
|
||||
}
|
||||
catch(ModuleManagementToolException exception)
|
||||
{
|
||||
// Pass
|
||||
}
|
||||
}
|
||||
|
||||
public void testBasicFolderInstall() throws Exception
|
||||
{
|
||||
manager.setVerbose(true);
|
||||
|
||||
String warDirectory = extractToDir(".war", "module/test.war");
|
||||
String ampDirectory = extractToDir(".amp", "module/test_v1.amp");
|
||||
String ampV2Directory = getFileLocation(".amp", "module/test_v2.amp");
|
||||
assertNotNull(warDirectory);
|
||||
assertNotNull(ampDirectory);
|
||||
assertNotNull(ampV2Directory);
|
||||
installerSharedTests(warDirectory, ampDirectory, ampV2Directory);
|
||||
|
||||
//Now try it on share
|
||||
warDirectory = extractToDir(".war", "module/share-3.4.11.war");
|
||||
assertNotNull(warDirectory);
|
||||
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
|
||||
this.manager.installModule(testAmpDepV2Location, warLocation, false, false, false);
|
||||
fail("Failed to detect inadequate dependency on the test amp");
|
||||
}
|
||||
catch (ModuleManagementToolException e)
|
||||
{
|
||||
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
|
||||
{
|
||||
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
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
public void testForcedInstall()
|
||||
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
|
||||
fail("Failed to detect existing files in the amp");
|
||||
}
|
||||
catch (ModuleManagementToolException e)
|
||||
{
|
||||
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
|
||||
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
|
||||
this.manager.installModule(ampLocation, warLocation, false, true, false);
|
||||
this.manager.installModule(amp5Location, warLocation, false, true, false);
|
||||
}
|
||||
|
||||
public void testInstallFromDir()
|
||||
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");
|
||||
|
||||
int index = ampV2Location.lastIndexOf(File.separator);
|
||||
System.out.println(index);
|
||||
String directoryLocation = ampV2Location.substring(0, index);
|
||||
|
||||
try
|
||||
{
|
||||
this.manager.installModules(directoryLocation, warLocation);
|
||||
}
|
||||
catch (ModuleManagementToolException exception)
|
||||
{
|
||||
exception.printStackTrace();
|
||||
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 ampLocation = getFileLocation(".amp", "module/test_v4.amp");
|
||||
|
||||
try
|
||||
{
|
||||
this.manager.installModule(ampLocation, warLocation, false, false, true);
|
||||
}
|
||||
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
|
||||
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
|
||||
|
||||
}
|
||||
|
||||
public void testWhiteSpaceInCustomMapping()
|
||||
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");
|
||||
files.add("/WEB-INF/lib/test.jar");
|
||||
files.add("/WEB-INF/classes/alfresco/module/test/module-context.xml");
|
||||
files.add("/images/test.jpg");
|
||||
files.add("/css/test.css");
|
||||
files.add("/extra.txt");
|
||||
checkForFileExistance(warLocation, files);
|
||||
}
|
||||
|
||||
public void testList()
|
||||
throws Exception
|
||||
{
|
||||
String warLocation = getFileLocation(".war", "module/test.war");
|
||||
String ampLocation = getFileLocation(".amp", "module/test_v1.amp");
|
||||
|
||||
this.manager.listModules(warLocation);
|
||||
|
||||
this.manager.installModule(ampLocation, warLocation);
|
||||
|
||||
this.manager.listModules(warLocation);
|
||||
}
|
||||
|
||||
private String getFileLocation(String extension, String location)
|
||||
throws IOException
|
||||
{
|
||||
File file = TempFileProvider.createTempFile("moduleManagementToolTest-", extension);
|
||||
InputStream is = this.getClass().getClassLoader().getResourceAsStream(location);
|
||||
assertNotNull(is);
|
||||
OutputStream os = new FileOutputStream(file);
|
||||
FileCopyUtils.copy(is, os);
|
||||
return file.getPath();
|
||||
}
|
||||
|
||||
private String extractToDir(String extension, String location)
|
||||
{
|
||||
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;
|
||||
}
|
||||
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);
|
||||
}
|
||||
catch (ModuleManagementToolException exception)
|
||||
{
|
||||
assertTrue(exception.getMessage().endsWith("does not exist."));
|
||||
}
|
||||
try
|
||||
{
|
||||
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
|
||||
{
|
||||
File file = new TFile(location);
|
||||
assertTrue(file.exists());
|
||||
BufferedReader reader = null;
|
||||
try
|
||||
{
|
||||
reader = new BufferedReader(new InputStreamReader(new TFileInputStream(file)));
|
||||
String line = reader.readLine();
|
||||
assertNotNull(line);
|
||||
assertEquals(expectedContents, line.trim());
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (reader != null)
|
||||
{
|
||||
try { reader.close(); } catch (Throwable e ) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,361 +0,0 @@
|
||||
package org.alfresco.repo.module.tool;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.alfresco.repo.module.ModuleDetailsImpl;
|
||||
import org.alfresco.service.cmr.module.ModuleDetails;
|
||||
import org.alfresco.util.TempFileProvider;
|
||||
import org.alfresco.util.VersionNumber;
|
||||
import org.junit.Test;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
|
||||
import de.schlichtherle.truezip.file.TArchiveDetector;
|
||||
import de.schlichtherle.truezip.file.TConfig;
|
||||
import de.schlichtherle.truezip.file.TFile;
|
||||
import de.schlichtherle.truezip.file.TFileInputStream;
|
||||
import de.schlichtherle.truezip.fs.archive.zip.ZipDriver;
|
||||
import de.schlichtherle.truezip.socket.sl.IOPoolLocator;
|
||||
|
||||
/**
|
||||
* Tests the war helper.
|
||||
*
|
||||
* @author Gethin James
|
||||
*/
|
||||
public class WarHelperImplTest extends WarHelperImpl
|
||||
{
|
||||
|
||||
public WarHelperImplTest()
|
||||
{
|
||||
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));
|
||||
|
||||
}
|
||||
@Test
|
||||
public void testCheckCompatibleVersion()
|
||||
{
|
||||
TFile theWar = getFile(".war", "module/test.war"); //Version 4.1.0
|
||||
|
||||
ModuleDetails installingModuleDetails = new ModuleDetailsImpl("test_it", new VersionNumber("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().endsWith("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().endsWith("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().endsWith("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 VersionNumber("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().endsWith("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().endsWith("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().endsWith("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 VersionNumber("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
|
||||
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 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]"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoVersionProperties()
|
||||
{
|
||||
TFile theWar = getFile(".war", "module/empty.war");
|
||||
|
||||
ModuleDetails installingModuleDetails = new ModuleDetailsImpl("test_it", new VersionNumber("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
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests to see if the war is a share war.
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void testIsShareWar()
|
||||
{
|
||||
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));
|
||||
|
||||
|
||||
}
|
||||
|
||||
private TFile getFile(String extension, String location)
|
||||
{
|
||||
File file = TempFileProvider.createTempFile("moduleManagementToolTest-", extension);
|
||||
InputStream is = this.getClass().getClassLoader().getResourceAsStream(location);
|
||||
assertNotNull(is);
|
||||
OutputStream os;
|
||||
try
|
||||
{
|
||||
os = new FileOutputStream(file);
|
||||
FileCopyUtils.copy(is, os);
|
||||
}
|
||||
catch (IOException error)
|
||||
{
|
||||
error.printStackTrace();
|
||||
}
|
||||
return new TFile(file);
|
||||
}
|
||||
}
|
@@ -1,9 +0,0 @@
|
||||
# The default AMP => WAR file mappings
|
||||
/config=/WEB-INF/classes
|
||||
/lib=/WEB-INF/lib
|
||||
/licenses=/WEB-INF/licenses
|
||||
/web/jsp=/jsp
|
||||
/web/css=/css
|
||||
/web/images=/images
|
||||
/web/scripts=/scripts
|
||||
/web/php=/php
|
Reference in New Issue
Block a user