mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-10-01 14:41:46 +00:00
Bump reflections from 0.9.12 to 0.10.2 (#776)
This commit is contained in:
@@ -66,9 +66,6 @@ import org.junit.runners.Suite;
|
||||
org.alfresco.repo.management.subsystems.CryptodocSwitchableApplicationContextFactoryTest.class,
|
||||
org.alfresco.repo.module.ModuleDetailsImplTest.class,
|
||||
org.alfresco.repo.module.ModuleVersionNumberTest.class,
|
||||
org.alfresco.repo.module.tool.ModuleManagementToolTest.class,
|
||||
org.alfresco.repo.module.tool.WarHelperImplTest.class,
|
||||
org.alfresco.repo.module.tool.ModuleServiceImplTest.class,
|
||||
org.alfresco.repo.node.integrity.IntegrityEventTest.class,
|
||||
org.alfresco.repo.policy.MTPolicyComponentTest.class,
|
||||
org.alfresco.repo.policy.PolicyComponentTest.class,
|
||||
|
@@ -2,7 +2,7 @@
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2020 Alfresco Software Limited
|
||||
* 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
|
||||
@@ -68,6 +68,10 @@ import org.junit.runners.Suite;
|
||||
org.alfresco.filesys.repo.ContentDiskDriverTest.class,
|
||||
org.alfresco.filesys.repo.LockKeeperImplTest.class,
|
||||
org.alfresco.repo.activities.ActivityServiceImplTest.class,
|
||||
org.alfresco.repo.activities.feed.cleanup.FeedCleanerTestCaseInsensitivity.class,
|
||||
org.alfresco.repo.activities.SiteActivityTestCaseSensitivity.class,
|
||||
org.alfresco.repo.activities.feed.cleanup.FeedCleanerTestCaseSensitivity.class,
|
||||
org.alfresco.repo.activities.SiteActivityTestCaseInsensitivity.class,
|
||||
org.alfresco.repo.admin.registry.RegistryServiceImplTest.class
|
||||
})
|
||||
public class AppContext01TestSuite
|
||||
|
@@ -1,28 +1,28 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 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%
|
||||
*/
|
||||
/*
|
||||
* #%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.repo.activities;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
@@ -102,19 +102,11 @@ public abstract class AbstractSiteActivityTest
|
||||
// AppToolId for site membership activities
|
||||
private static String appToolId = "siteService"; // refer to SiteService
|
||||
|
||||
private static boolean membersAddedUpdated = false;
|
||||
private static boolean membersRemoved = false;
|
||||
private static boolean controlsCreated = false;
|
||||
|
||||
public AbstractSiteActivityTest()
|
||||
{
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception
|
||||
{
|
||||
applicationContext = ApplicationContextHelper.getApplicationContext();
|
||||
String testid = ""+System.currentTimeMillis();
|
||||
String testid = "" + System.currentTimeMillis();
|
||||
|
||||
// Let's shut down the scheduler so that we aren't competing with the scheduled versions of the post lookup and
|
||||
// feed generator jobs
|
||||
@@ -189,10 +181,6 @@ public abstract class AbstractSiteActivityTest
|
||||
deleteSite(site1);
|
||||
deleteSite(site2);
|
||||
deleteSite(site3);
|
||||
|
||||
membersAddedUpdated = false;
|
||||
membersRemoved = false;
|
||||
controlsCreated = false;
|
||||
}
|
||||
|
||||
protected void createSite(String siteId, boolean isPublic) throws Exception
|
||||
@@ -332,51 +320,39 @@ public abstract class AbstractSiteActivityTest
|
||||
}
|
||||
assertEquals(expectedCount, activityService.getUserFeedEntries(userId, siteId, excludeThisUser, excludeOtherUsers, null, null).size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUserFeedControls() throws Exception
|
||||
|
||||
public void configureFeedControls() throws Exception
|
||||
{
|
||||
if (! controlsCreated)
|
||||
{
|
||||
// user 1 opts out of all activities for site 1
|
||||
login(user1, USER_PW);
|
||||
addFeedControl(site1, null);
|
||||
|
||||
// user 2 opts out of site membership activities (across all sites)
|
||||
login(user2, USER_PW);
|
||||
addFeedControl(null, appToolId);
|
||||
|
||||
// user 3 opts out of site membership activities for site 1 only
|
||||
login(user3, USER_PW);
|
||||
addFeedControl(site1, appToolId);
|
||||
|
||||
// TODO add more here, once we have more appToolIds
|
||||
|
||||
controlsCreated = true;
|
||||
}
|
||||
// user 1 opts out of all activities for site 1
|
||||
login(user1, USER_PW);
|
||||
addFeedControl(site1, null);
|
||||
|
||||
// user 2 opts out of site membership activities (across all sites)
|
||||
login(user2, USER_PW);
|
||||
addFeedControl(null, appToolId);
|
||||
|
||||
// user 3 opts out of site membership activities for site 1 only
|
||||
login(user3, USER_PW);
|
||||
addFeedControl(site1, appToolId);
|
||||
|
||||
// TODO add more here, once we have more appToolIds
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddAndUpdateMemberships() throws Exception
|
||||
|
||||
public void addAndUpdateMemberships() throws Exception
|
||||
{
|
||||
if (! membersAddedUpdated)
|
||||
{
|
||||
login(ADMIN_USER, ADMIN_PW);
|
||||
|
||||
addAndUpdateMemberships(site1, true); // public site, include all users
|
||||
addAndUpdateMemberships(site2, true); // private site, include all users
|
||||
addAndUpdateMemberships(site3, false); // private site, do not include user 4
|
||||
|
||||
generateFeed();
|
||||
|
||||
membersAddedUpdated = true;
|
||||
}
|
||||
login(ADMIN_USER, ADMIN_PW);
|
||||
|
||||
addAndUpdateMemberships(site1, true); // public site, include all users
|
||||
addAndUpdateMemberships(site2, true); // private site, include all users
|
||||
addAndUpdateMemberships(site3, false); // private site, do not include user 4
|
||||
|
||||
generateFeed();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetSiteFeedsAfterAddAndUpdateMemberships() throws Exception
|
||||
{
|
||||
testAddAndUpdateMemberships();
|
||||
addAndUpdateMemberships();
|
||||
|
||||
login(ADMIN_USER, ADMIN_PW);
|
||||
|
||||
@@ -400,14 +376,9 @@ public abstract class AbstractSiteActivityTest
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveMemberships() throws Exception
|
||||
|
||||
public void removeMemberships() throws Exception
|
||||
{
|
||||
if (! membersRemoved)
|
||||
{
|
||||
testAddAndUpdateMemberships();
|
||||
|
||||
login(ADMIN_USER, ADMIN_PW);
|
||||
|
||||
removeMemberships(site1, true);
|
||||
@@ -415,9 +386,6 @@ public abstract class AbstractSiteActivityTest
|
||||
removeMemberships(site3, false);
|
||||
|
||||
generateFeed();
|
||||
|
||||
membersRemoved = true;
|
||||
}
|
||||
}
|
||||
|
||||
protected void addAndUpdateMemberships(String siteId, boolean includeUser4) throws Exception
|
||||
@@ -456,8 +424,8 @@ public abstract class AbstractSiteActivityTest
|
||||
@Test
|
||||
public void testGetSiteFeedsAfterRemoveMemberships() throws Exception
|
||||
{
|
||||
testAddAndUpdateMemberships();
|
||||
testRemoveMemberships();
|
||||
addAndUpdateMemberships();
|
||||
removeMemberships();
|
||||
|
||||
login(ADMIN_USER, ADMIN_PW);
|
||||
|
||||
@@ -493,11 +461,11 @@ public abstract class AbstractSiteActivityTest
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetUserFeedsAfter() throws Exception
|
||||
public void testGetUserFeedsAfterApplyingFeedControls() throws Exception
|
||||
{
|
||||
testUserFeedControls();
|
||||
testAddAndUpdateMemberships();
|
||||
testRemoveMemberships();
|
||||
configureFeedControls();
|
||||
addAndUpdateMemberships();
|
||||
removeMemberships();
|
||||
|
||||
// as admin
|
||||
|
||||
@@ -506,22 +474,23 @@ public abstract class AbstractSiteActivityTest
|
||||
// site 1, with 4 users, each with 1 join, 1 role change = 4x2 = 8
|
||||
// site 2, with 4 users, each with 1 join, 1 role change = 4x2 = 8
|
||||
// site 3, with 3 users, each with 1 join, 1 role change = 3x2 = 6
|
||||
// Every user is removed from sites so in its feed it sees the removal for each site
|
||||
|
||||
// user 1 belongs to 3 sites = (2x8)+(1x6) = 22
|
||||
// user 2 belongs to 3 sites = (2x8)+(1x6) = 22
|
||||
// user 3 belongs to 3 sites = (2x8)+(1x6) = 22
|
||||
// user 4 belongs to 2 sites = (2x8) = 16
|
||||
|
||||
getUserFeed(user1, true, 14); // 14 = (22 - 8) due to feed control - exclude site 1
|
||||
// user 1 belongs to 3 sites and is removed from 3 sites = (2x8)+(1x6)+3 = 25
|
||||
// user 2 belongs to 3 sites and is removed from 3 sites = (2x8)+(1x6)+3 = 25
|
||||
// user 3 belongs to 3 sites and is removed from 3 sites = (2x8)+(1x6)+3 = 25
|
||||
// user 4 belongs to 2 sites and is removed from 3 sites = (2x8)+2 = 18
|
||||
|
||||
getUserFeed(user1, true, 16); // 16 = (25 - 9) due to feed control - exclude site 1 (4 joins, 4 changes, 1 removal)
|
||||
getUserFeed(user2, true, 0); // 0 = due to feed control - exclude site membership activities (across all sites)
|
||||
getUserFeed(user3, true, 14); // 14 = (22 - 8) due to feed control - exclude site membership activities for site 1
|
||||
getUserFeed(user4, true, 16); // 16 = no feed control
|
||||
getUserFeed(user3, true, 16); // 16 = (25 - 9) due to feed control - exclude site membership activities for site 1
|
||||
getUserFeed(user4, true, 18); // 18 = no feed control
|
||||
|
||||
// as user1
|
||||
|
||||
login(user1, USER_PW);
|
||||
|
||||
getUserFeed(user1, false, 14);
|
||||
getUserFeed(user1, false, 16);
|
||||
|
||||
// as user2
|
||||
|
||||
@@ -529,7 +498,7 @@ public abstract class AbstractSiteActivityTest
|
||||
|
||||
try
|
||||
{
|
||||
getUserFeed(user1, true, 14);
|
||||
getUserFeed(user1, true, 16);
|
||||
|
||||
fail("User feed should only be accessible to user or an admin");
|
||||
}
|
||||
@@ -543,12 +512,12 @@ public abstract class AbstractSiteActivityTest
|
||||
login(user1, USER_PW);
|
||||
|
||||
getUserFeed(null, site1, false, false, false, 0);
|
||||
getUserFeed(null, site2, false, false, false, 8);
|
||||
getUserFeed(null, site3, false, false, false, 6);
|
||||
getUserFeed(null, site2, false, false, false, 9);
|
||||
getUserFeed(null, site3, false, false, false, 7);
|
||||
|
||||
getUserFeed(null, null, false, false, false, 14); // no filter
|
||||
getUserFeed(null, null, false, false, false, 16); // no filter
|
||||
getUserFeed(null, null, false, true, false, 12); // exclude any from user1
|
||||
getUserFeed(null, null, false, false, true, 2); // exclude all except user1
|
||||
getUserFeed(null, null, false, false, true, 4); // exclude all except user1
|
||||
getUserFeed(null, null, false, true, true, 0); // exclude all (NOOP)
|
||||
|
||||
// TODO - add more (eg. other non-admin user activities)
|
||||
|
@@ -1,507 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 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.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;
|
||||
|
||||
/**
|
||||
* @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");
|
||||
this.manager.listModules(warLocation);
|
||||
}
|
||||
|
||||
public void testListAndInstall() throws Exception {
|
||||
|
||||
String warLocation = getFileLocation(".war", "module/test.war");
|
||||
String ampLocation = getFileLocation(".amp", "module/test_v1.amp");
|
||||
String ampV2Location = getFileLocation(".amp", "module/test_v2.amp");
|
||||
|
||||
TFile war = new TFile(warLocation);
|
||||
|
||||
List<ModuleDetails> details = this.manager.warHelper.listModules(war);
|
||||
assertNotNull(details);
|
||||
assertEquals(details.size(), 0);
|
||||
|
||||
this.manager.installModule(ampLocation, warLocation);
|
||||
|
||||
details = this.manager.warHelper.listModules(war);
|
||||
assertNotNull(details);
|
||||
assertEquals(details.size(), 1);
|
||||
ModuleDetails aModule = details.get(0);
|
||||
assertEquals("test", aModule.getId());
|
||||
assertEquals("1.0", aModule.getModuleVersionNumber().toString());
|
||||
|
||||
this.manager.installModule(ampV2Location, warLocation);
|
||||
|
||||
details = this.manager.warHelper.listModules(war);
|
||||
assertNotNull(details);
|
||||
assertEquals(details.size(), 1);
|
||||
aModule = details.get(0);
|
||||
assertEquals("test", aModule.getId());
|
||||
assertEquals("2.0", aModule.getModuleVersionNumber().toString());
|
||||
|
||||
String testAmpDepV2Location = getFileLocation(".amp", "module/dependent_on_test_v2.amp");
|
||||
String testAmp7 = getFileLocation(".amp", "module/test_v7.amp");
|
||||
|
||||
this.manager.installModule(testAmpDepV2Location, warLocation, false, true, false);
|
||||
this.manager.installModule(testAmp7, warLocation, false, true, false);
|
||||
|
||||
details = this.manager.warHelper.listModules(war);
|
||||
assertNotNull(details);
|
||||
assertEquals(details.size(), 3);
|
||||
|
||||
//Sort them by installation date
|
||||
Collections.sort(details, new Comparator<ModuleDetails>() {
|
||||
@Override
|
||||
public int compare(ModuleDetails a, ModuleDetails b) {
|
||||
return a.getInstallDate().compareTo(b.getInstallDate());
|
||||
}
|
||||
});
|
||||
|
||||
ModuleDetails installedModule = details.get(0);
|
||||
assertEquals("test", installedModule.getId());
|
||||
assertEquals("2.0", installedModule.getModuleVersionNumber().toString());
|
||||
|
||||
installedModule = details.get(1);
|
||||
assertEquals("org.alfresco.module.test.dependent", installedModule.getId());
|
||||
assertEquals("2.0", installedModule.getModuleVersionNumber().toString());
|
||||
|
||||
installedModule = details.get(2);
|
||||
assertEquals("forcedtest", installedModule.getId());
|
||||
assertEquals("1.0", installedModule.getModuleVersionNumber().toString());
|
||||
|
||||
}
|
||||
|
||||
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,97 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 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.repo.module.tool;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
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 org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.stubbing.Answer;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Tests some of ModuleServiceImpl that is not covered by other tests
|
||||
* @author Gethin James
|
||||
*/
|
||||
public class ModuleServiceImplTest
|
||||
{
|
||||
ModuleServiceImpl moduleService;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception
|
||||
{
|
||||
moduleService = new ModuleServiceImpl();
|
||||
Resource simpleMod = new PathMatchingResourcePatternResolver().getResource("classpath:alfresco/module/simplemodule.properties");
|
||||
assertNotNull(simpleMod);
|
||||
RegistryService reg = mock(RegistryService.class);
|
||||
ApplicationContext applicationContext = mock(ApplicationContext.class);
|
||||
|
||||
when(reg.getProperty((RegistryKey) any())).thenAnswer(new Answer<Serializable>()
|
||||
{
|
||||
public Serializable answer(InvocationOnMock invocation) throws Throwable
|
||||
{
|
||||
RegistryKey key = (RegistryKey) invocation.getArguments()[0];
|
||||
return new ModuleVersionNumber("1.1");
|
||||
}
|
||||
});
|
||||
doReturn(Arrays.asList("fee", "alfresco-simple-module", "fo")).when(reg).getChildElements((RegistryKey) any());
|
||||
doReturn(new Resource[] {simpleMod}).when(applicationContext).getResources(anyString());
|
||||
moduleService.setRegistryService(reg);
|
||||
moduleService.setApplicationContext(applicationContext);
|
||||
}
|
||||
|
||||
@Test(expected = UnsupportedOperationException.class)
|
||||
public void testSetApplyToTenants() throws Exception
|
||||
{
|
||||
moduleService.setApplyToTenants(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetMissingModules() throws Exception
|
||||
{
|
||||
List<ModuleDetails> miss = moduleService.getMissingModules();
|
||||
assertNotNull(miss);
|
||||
//There are 3 modules. 2 of which are missing. "alfresco-simple-module" should be found.
|
||||
assertEquals(2, miss.size());
|
||||
}
|
||||
}
|
@@ -1,417 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 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.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 java.io.*;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
import java.util.jar.Manifest;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* 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 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 equal to or 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 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 equal to or 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);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@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]"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
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);
|
||||
|
||||
assertNotNull(manifest);
|
||||
assertEquals("Alfresco Share Enterprise", manifest.getMainAttributes().getValue(MANIFEST_IMPLEMENTATION_TITLE));
|
||||
assertEquals("3.4.11", manifest.getMainAttributes().getValue(MANIFEST_SPECIFICATION_VERSION));
|
||||
|
||||
theWar = getFile(".war", "module/alfresco-4.2.a.war");
|
||||
manifest = this.findManifest(theWar);
|
||||
|
||||
assertNotNull(manifest);
|
||||
assertEquals("Alfresco Repository Community", manifest.getMainAttributes().getValue(MANIFEST_IMPLEMENTATION_TITLE));
|
||||
assertEquals("4.2.a", manifest.getMainAttributes().getValue(MANIFEST_SPECIFICATION_VERSION));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListModules() throws Exception
|
||||
{
|
||||
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");
|
||||
details = this.listModules(theWar);
|
||||
assertNotNull(details);
|
||||
assertEquals(details.size(), 1);
|
||||
ModuleDetails aModule = details.get(0);
|
||||
assertEquals("alfresco-mm-share", aModule.getId());
|
||||
assertEquals("0.1.5.6", aModule.getModuleVersionNumber().toString());
|
||||
assertEquals(ModuleInstallState.INSTALLED, aModule.getInstallState());
|
||||
|
||||
}
|
||||
|
||||
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 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
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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));
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
@@ -2,7 +2,7 @@
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2020 Alfresco Software Limited
|
||||
* 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
|
||||
@@ -29,10 +29,16 @@ import static java.util.Collections.emptySet;
|
||||
import static java.util.stream.Collectors.toSet;
|
||||
|
||||
import static junit.framework.TestCase.assertEquals;
|
||||
import static org.reflections.scanners.Scanners.MethodsAnnotated;
|
||||
import static org.reflections.scanners.Scanners.SubTypes;
|
||||
import static org.reflections.scanners.Scanners.TypesAnnotated;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@@ -49,6 +55,7 @@ import org.junit.experimental.categories.Category;
|
||||
import org.junit.runners.Suite.SuiteClasses;
|
||||
import org.reflections.Reflections;
|
||||
import org.reflections.scanners.MethodAnnotationsScanner;
|
||||
import org.reflections.scanners.Scanners;
|
||||
import org.reflections.scanners.SubTypesScanner;
|
||||
import org.reflections.scanners.TypeAnnotationsScanner;
|
||||
|
||||
@@ -69,7 +76,7 @@ public class OmittedTestClassFinderUnitTest
|
||||
public void checkTestClassesReferencedInTestSuites()
|
||||
{
|
||||
// We assume that all of our tests are in org.alfresco.
|
||||
Reflections reflections = new Reflections("org.alfresco", new MethodAnnotationsScanner(), new TypeAnnotationsScanner(), new SubTypesScanner());
|
||||
Reflections reflections = new Reflections("org.alfresco", MethodsAnnotated, TypesAnnotated, SubTypes);
|
||||
|
||||
// Find the test classes which are not in test suites.
|
||||
Set<String> testClasses = getTestClassesOnPath(reflections);
|
||||
@@ -162,13 +169,14 @@ public class OmittedTestClassFinderUnitTest
|
||||
* @param annotation The class of the annotation to look for.
|
||||
* @return The set of canonical names of classes containing methods annotated with the annotation.
|
||||
*/
|
||||
private Set<String> findClassesWithMethodAnnotation(Reflections reflections, Class annotation)
|
||||
private Set<String> findClassesWithMethodAnnotation(Reflections reflections, Class<? extends Annotation> annotation)
|
||||
{
|
||||
return reflections.getStore()
|
||||
.get(MethodAnnotationsScanner.class, annotation.getName())
|
||||
return reflections.getMethodsAnnotatedWith(annotation)
|
||||
.stream()
|
||||
// Get the class name from the method name.
|
||||
.map(methodName -> methodName.split("\\.[^\\.]+\\(")[0])
|
||||
.map(Method::getDeclaringClass)
|
||||
.flatMap(c -> Stream.concat(Stream.of(c), reflections.getSubTypesOf(c).stream()))
|
||||
.map(Class::getCanonicalName)
|
||||
.filter(Objects::nonNull)
|
||||
.collect(toSet());
|
||||
}
|
||||
|
||||
|
@@ -1,27 +0,0 @@
|
||||
# Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
# contributor license agreements. See the NOTICE file distributed with
|
||||
# this work for additional information regarding copyright ownership.
|
||||
# The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
# (the "License"); you may not use this file except in compliance with
|
||||
# the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
# ==== Beginning of Alfresco required/optional properties ====== #
|
||||
# NB: These properties are filtered at build time by Maven, single
|
||||
# sourcing from POM properties
|
||||
module.id=alfresco-simple-module
|
||||
#module.aliases=myModule-123, my-module
|
||||
module.title=Alfresco JAR Module Project
|
||||
module.description=UNSUPPORTED experiment
|
||||
module.version=1.0.0-SNAPSHOT
|
||||
|
||||
# The following optional properties can be used to prevent the module from being added
|
||||
# to inappropriate versions of the WAR file.
|
||||
module.repo.version.min=2.0
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user