Add cache for maven in Travis (#316)

(cherry picked from master commit 15e0f0b601)
Add Travis config (#302)

The tests were refactored to run Spring annotations instead of ApplicationContextHelper to mitigate the problems of Camel Context loading. The refactored tests are all part of AppContext06TestSuite.

Disabled PdfBoxContentTransformerTest as it requires installation of additional software on the build agent. The test is deprecated already.

(cherry picked from master commit 24db520ff5)
Add Travis status to Readme

(cherry picked from master commit 103570ff3a)
This commit is contained in:
Alan Davis
2019-01-24 12:06:09 +00:00
parent 855c7e06ba
commit 66053fafe5
22 changed files with 2296 additions and 2374 deletions

83
.travis.yml Normal file
View File

@@ -0,0 +1,83 @@
dist: trusty
sudo: required
language: java
jdk:
- openjdk11
# Backwards compatibility with Java 8
# - oraclejdk8
services:
- docker
cache:
directories:
- $HOME/.m2
matrix:
include:
- name: "AllUnitTestsSuite"
script: mvn test -B -Dtest=AllUnitTestsSuite
- name: "AppContext01TestSuite"
before_install:
- docker run -d -p 5433:5432 -e POSTGRES_PASSWORD=alfresco -e POSTGRES_USER=alfresco -e POSTGRES_DB=alfresco postgres:10.1 postgres -c 'max_connections=300'
- docker run -d -p 61616:61616 -p 5672:5672 alfresco/alfresco-activemq:5.15.6
script: travis_wait 20 mvn test -B -Dtest=AppContext01TestSuite -Ddb.driver=org.postgresql.Driver -Ddb.name=alfresco -Ddb.url=jdbc:postgresql://localhost:5433/alfresco -Ddb.username=alfresco -Ddb.password=alfresco
- name: "AppContext02TestSuite"
before_install:
- docker run -d -p 5433:5432 -e POSTGRES_PASSWORD=alfresco -e POSTGRES_USER=alfresco -e POSTGRES_DB=alfresco postgres:10.1 postgres -c 'max_connections=300'
- docker run -d -p 61616:61616 -p 5672:5672 alfresco/alfresco-activemq:5.15.6
script: travis_wait 20 mvn test -B -Dtest=AppContext02TestSuite -Ddb.driver=org.postgresql.Driver -Ddb.name=alfresco -Ddb.url=jdbc:postgresql://localhost:5433/alfresco -Ddb.username=alfresco -Ddb.password=alfresco
- name: "AppContext03TestSuite"
before_install:
- docker run -d -p 5433:5432 -e POSTGRES_PASSWORD=alfresco -e POSTGRES_USER=alfresco -e POSTGRES_DB=alfresco postgres:10.1 postgres -c 'max_connections=300'
- docker run -d -p 61616:61616 -p 5672:5672 alfresco/alfresco-activemq:5.15.6
script: travis_wait 20 mvn test -B -Dtest=AppContext03TestSuite -Ddb.driver=org.postgresql.Driver -Ddb.name=alfresco -Ddb.url=jdbc:postgresql://localhost:5433/alfresco -Ddb.username=alfresco -Ddb.password=alfresco
- name: "AppContext04TestSuite"
before_install:
- docker run -d -p 5433:5432 -e POSTGRES_PASSWORD=alfresco -e POSTGRES_USER=alfresco -e POSTGRES_DB=alfresco postgres:10.1 postgres -c 'max_connections=300'
- docker run -d -p 61616:61616 -p 5672:5672 alfresco/alfresco-activemq:5.15.6
script: travis_wait 20 mvn test -B -Dtest=AppContext04TestSuite -Ddb.driver=org.postgresql.Driver -Ddb.name=alfresco -Ddb.url=jdbc:postgresql://localhost:5433/alfresco -Ddb.username=alfresco -Ddb.password=alfresco
- name: "AppContext05TestSuite"
before_install:
- docker run -d -p 5433:5432 -e POSTGRES_PASSWORD=alfresco -e POSTGRES_USER=alfresco -e POSTGRES_DB=alfresco postgres:10.1 postgres -c 'max_connections=300'
- docker run -d -p 61616:61616 -p 5672:5672 alfresco/alfresco-activemq:5.15.6
script: travis_wait 20 mvn test -B -Dtest=AppContext05TestSuite -Ddb.driver=org.postgresql.Driver -Ddb.name=alfresco -Ddb.url=jdbc:postgresql://localhost:5433/alfresco -Ddb.username=alfresco -Ddb.password=alfresco
- name: "AppContext06TestSuite"
before_install:
- docker run -d -p 5433:5432 -e POSTGRES_PASSWORD=alfresco -e POSTGRES_USER=alfresco -e POSTGRES_DB=alfresco postgres:10.1 postgres -c 'max_connections=300'
- docker run -d -p 61616:61616 -p 5672:5672 alfresco/alfresco-activemq:5.15.6
- docker run -d -p 8090:8090 -e JAVA_OPTS=" -Xms256m -Xmx256m" alfresco/alfresco-pdf-renderer:1.3
- docker run -d -p 8091:8090 -e JAVA_OPTS=" -Xms256m -Xmx256m" alfresco/alfresco-imagemagick:1.3
- docker run -d -p 8092:8090 -e JAVA_OPTS=" -Xms256m -Xmx256m" alfresco/alfresco-libreoffice:1.3
- docker run -d -p 8093:8090 -e JAVA_OPTS=" -Xms256m -Xmx256m" alfresco/alfresco-tika:1.3
script: travis_wait 20 mvn test -B -Dtest=AppContext06TestSuite -Ddb.driver=org.postgresql.Driver -Ddb.name=alfresco -Ddb.url=jdbc:postgresql://localhost:5433/alfresco -Ddb.username=alfresco -Ddb.password=alfresco -Dalfresco-pdf-renderer.url=http://localhost:8090/ -Djodconverter.url=http://localhost:8092/ -Dimg.url=http://localhost:8091/ -Dtika.url=http://localhost:8093/
- name: "AppContextExtraTestSuite"
before_install:
- docker run -d -p 5433:5432 -e POSTGRES_PASSWORD=alfresco -e POSTGRES_USER=alfresco -e POSTGRES_DB=alfresco postgres:10.1 postgres -c 'max_connections=300'
- docker run -d -p 61616:61616 -p 5672:5672 alfresco/alfresco-activemq:5.15.6
script: travis_wait 20 mvn test -B -Dtest=AppContextExtraTestSuite -Ddb.driver=org.postgresql.Driver -Ddb.name=alfresco -Ddb.url=jdbc:postgresql://localhost:5433/alfresco -Ddb.username=alfresco -Ddb.password=alfresco
- name: "MiscContextTestSuite"
before_install:
- docker run -d -p 5433:5432 -e POSTGRES_PASSWORD=alfresco -e POSTGRES_USER=alfresco -e POSTGRES_DB=alfresco postgres:10.1 postgres -c 'max_connections=300'
- docker run -d -p 61616:61616 -p 5672:5672 alfresco/alfresco-activemq:5.15.6
- docker run -d -p 8090:8090 -e JAVA_OPTS=" -Xms256m -Xmx256m" alfresco/alfresco-pdf-renderer:1.3
- docker run -d -p 8091:8090 -e JAVA_OPTS=" -Xms256m -Xmx256m" alfresco/alfresco-imagemagick:1.3
- docker run -d -p 8092:8090 -e JAVA_OPTS=" -Xms256m -Xmx256m" alfresco/alfresco-libreoffice:1.3
- docker run -d -p 8093:8090 -e JAVA_OPTS=" -Xms256m -Xmx256m" alfresco/alfresco-tika:1.3
script: travis_wait 20 mvn test -B -Dtest=MiscContextTestSuite -Ddb.driver=org.postgresql.Driver -Ddb.name=alfresco -Ddb.url=jdbc:postgresql://localhost:5433/alfresco -Ddb.username=alfresco -Ddb.password=alfresco -Dalfresco-pdf-renderer.url=http://localhost:8090/ -Djodconverter.url=http://localhost:8092/ -Dimg.url=http://localhost:8091/ -Dtika.url=http://localhost:8093/
- name: "MySQL tests"
before_install:
- docker run -d -p 3307:3306 -e MYSQL_ROOT_PASSWORD=alfresco -e MYSQL_USER=alfresco -e MYSQL_DATABASE=alfresco -e MYSQL_PASSWORD=alfresco mysql:5.7.23 --transaction-isolation='READ-COMMITTED'
- docker run -d -p 61616:61616 -p 5672:5672 alfresco/alfresco-activemq:5.15.6
script: travis_wait 20 mvn test -B -Dtest=AllDBTestsTestSuite -Ddb.driver=com.mysql.jdbc.Driver -Ddb.name=alfresco -Ddb.url=jdbc:mysql://localhost:3307/alfresco -Ddb.username=alfresco -Ddb.password=alfresco
- name: "PostgreSQL tests"
before_install:
- docker run -d -p 5433:5432 -e POSTGRES_PASSWORD=alfresco -e POSTGRES_USER=alfresco -e POSTGRES_DB=alfresco postgres:10.1 postgres -c 'max_connections=300'
- docker run -d -p 61616:61616 -p 5672:5672 alfresco/alfresco-activemq:5.15.6
script: travis_wait 20 mvn test -B -Dtest=AllDBTestsTestSuite -Ddb.driver=org.postgresql.Driver -Ddb.name=alfresco -Ddb.url=jdbc:postgresql://localhost:5433/alfresco -Ddb.username=alfresco -Ddb.password=alfresco
- name: "MariaDB tests"
before_install:
- docker run -d -p 3307:3306 --name mariadb -e MYSQL_ROOT_PASSWORD=alfresco -e MYSQL_USER=alfresco -e MYSQL_DATABASE=alfresco -e MYSQL_PASSWORD=alfresco mariadb:10.2.18 --transaction-isolation=READ-COMMITTED --max-connections=300 --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
- docker run -d -p 61616:61616 -p 5672:5672 alfresco/alfresco-activemq:5.15.6
script: travis_wait 20 mvn test -B -Dtest=AllDBTestsTestSuite -Ddb.url=jdbc:mariadb://localhost/alfresco?useUnicode=yes\&characterEncoding=UTF-8 -Ddb.name=alfresco -Ddb.url=jdbc:mariadb://localhost:3307/alfresco -Ddb.username=alfresco -Ddb.password=alfresco -Ddb.driver=org.mariadb.jdbc.Driver
install: travis_retry mvn install -DskipTests=true -Dmaven.javadoc.skip=true -B -V

View File

@@ -1,4 +1,6 @@
### Alfresco Repository
[![Build Status](https://travis-ci.com/Alfresco/alfresco-repository.svg?branch=master)](https://travis-ci.com/Alfresco/alfresco-repository)
Repository is a library packaged as a jar file which is part of [Alfresco Content Services Repository](https://community.alfresco.com/docs/DOC-6385-project-overview-repository).
The library contains the following:
* DAOs and SQL scripts

View File

@@ -35,10 +35,23 @@ import org.junit.runners.Suite;
* Repository project tests using the main context alfresco/application-context.xml.
* To balance test jobs tests using this context have been split into multiple test suites.
* Tests marked as DBTests are automatically excluded and are run as part of {@link AllDBTestsTestSuite}.
*
* <p>
* All of the tests are using Spring annotations to load full application context, see BaseSpringTest
* Any new tests included in this test suite must follow the same pattern
* </p>
*/
@RunWith(Categories.class)
@Categories.ExcludeCategory({DBTests.class, NonBuildTests.class})
@Suite.SuiteClasses({
// Requires a running ActiveMQ
org.alfresco.repo.rawevents.EventBehaviourTest.class,
org.alfresco.repo.rawevents.TransactionAwareEventProducerTest.class,
// Requires running transformers
org.alfresco.repo.rendition2.RenditionService2IntegrationTest.class,
org.alfresco.repo.rendition2.LegacyLocalTransformClientIntegrationTest.class,
org.alfresco.repo.rendition2.LegacyLocalTransformServiceRegistryTest.class,
org.alfresco.repo.rendition2.RenditionTest.class,
org.alfresco.repo.solr.SOLRTrackingComponentTest.class,
org.alfresco.repo.tagging.TaggingServiceImplTest.class,
org.alfresco.repo.transaction.AlfrescoTransactionSupportTest.class,

View File

@@ -58,7 +58,8 @@ import org.springframework.context.ApplicationContext;
org.alfresco.repo.content.transform.EMLTransformerTest.class,
org.alfresco.repo.content.transform.MediaWikiContentTransformerTest.class,
org.alfresco.repo.content.transform.OpenOfficeContentTransformerTest.class,
org.alfresco.repo.content.transform.PdfBoxContentTransformerTest.class,
// Requires a transformer to be installed in the system
//org.alfresco.repo.content.transform.PdfBoxContentTransformerTest.class,
org.alfresco.repo.content.transform.PoiContentTransformerTest.class,
org.alfresco.repo.content.transform.PoiHssfContentTransformerTest.class,
org.alfresco.repo.content.transform.PoiOOXMLContentTransformerTest.class,
@@ -138,22 +139,7 @@ import org.springframework.context.ApplicationContext;
org.alfresco.repo.rendition.RenditionServicePermissionsTest.class,
// [ibatis/hierarchy-test/hierarchy-test-context.xml]
org.alfresco.ibatis.HierarchicalSqlSessionFactoryBeanTest.class,
// [classpath:/test-messaging-context.xml]
// TODO enable in REPO-3811
//org.alfresco.messaging.camel.CamelRoutesTest.class,
// Requires a running ActiveMQ
org.alfresco.repo.rawevents.EventBehaviourTest.class,
org.alfresco.repo.rawevents.TransactionAwareEventProducerTest.class,
// Requires running transformers
org.alfresco.repo.rendition2.RenditionService2IntegrationTest.class,
org.alfresco.repo.rendition2.LegacyLocalTransformClientIntegrationTest.class,
org.alfresco.repo.rendition2.LegacyLocalTransformServiceRegistryTest.class,
// Due to problems reloading the context (bits of it remain), NoLocalTransformRenditionTest has been commented out.
// It works on its own.
org.alfresco.repo.rendition2.RenditionTest.class,
// org.alfresco.repo.rendition2.NoLocalTransformRenditionTest.class,
org.alfresco.ibatis.HierarchicalSqlSessionFactoryBeanTest.class
})
public class MiscContextTestSuite
{

View File

@@ -164,7 +164,8 @@ public class RepositoryStartStopTest extends TestCase
* a context twice without error, using it
* when running.
*/
public void testOpenCloseOpenCloseFull() throws Exception
// test ignored from 24 Oct 2018
public void ignoredTestOpenCloseOpenCloseFull() throws Exception
{
assertNoCachedApplicationContext();

View File

@@ -30,8 +30,6 @@ import java.util.List;
import javax.transaction.UserTransaction;
import junit.framework.TestCase;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.action.ActionImpl;
import org.alfresco.repo.action.RuntimeActionService;
@@ -48,10 +46,11 @@ import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.namespace.QName;
import org.alfresco.service.namespace.RegexQNamePattern;
import org.alfresco.service.transaction.TransactionService;
import org.alfresco.test_category.OwnJVMTestsCategory;
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
import org.alfresco.util.ApplicationContextHelper;
import org.junit.experimental.categories.Category;
import org.alfresco.util.BaseSpringTest;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.quartz.CalendarIntervalTrigger;
import org.quartz.DateBuilder;
import org.quartz.Job;
@@ -69,16 +68,12 @@ import org.quartz.impl.triggers.SimpleTriggerImpl;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.ConfigurableApplicationContext;
/**
* Unit tests for the {@link ScheduledPersistedActionService}
*/
@Category(OwnJVMTestsCategory.class)
public class ScheduledPersistedActionServiceTest extends TestCase
public class ScheduledPersistedActionServiceTest extends BaseSpringTest
{
private static ConfigurableApplicationContext ctx = (ConfigurableApplicationContext) ApplicationContextHelper.getApplicationContext();
private ScheduledPersistedActionServiceBootstrap bootstrap;
private ScheduledPersistedActionService service;
private ScheduledPersistedActionServiceImpl serviceImpl;
@@ -93,17 +88,17 @@ public class ScheduledPersistedActionServiceTest extends TestCase
private Action testAction2;
private Action testAction3;
@Override
protected void setUp() throws Exception
@Before
public void setUp() throws Exception
{
actionService = (ActionService) ctx.getBean("actionService");
nodeService = (NodeService) ctx.getBean("nodeService");
transactionService = (TransactionService) ctx.getBean("transactionService");
runtimeActionService = (RuntimeActionService) ctx.getBean("actionService");
service = (ScheduledPersistedActionService) ctx.getBean("ScheduledPersistedActionService");
serviceImpl = (ScheduledPersistedActionServiceImpl) ctx.getBean("scheduledPersistedActionService");
scheduler = (Scheduler) ctx.getBean("schedulerFactory");
bootstrap = (ScheduledPersistedActionServiceBootstrap) ctx.getBean("scheduledPersistedActionServiceBootstrap");
actionService = (ActionService) applicationContext.getBean("actionService");
nodeService = (NodeService) applicationContext.getBean("nodeService");
transactionService = (TransactionService) applicationContext.getBean("transactionService");
runtimeActionService = (RuntimeActionService) applicationContext.getBean("actionService");
service = (ScheduledPersistedActionService) applicationContext.getBean("ScheduledPersistedActionService");
serviceImpl = (ScheduledPersistedActionServiceImpl) applicationContext.getBean("scheduledPersistedActionService");
scheduler = (Scheduler) applicationContext.getBean("schedulerFactory");
bootstrap = (ScheduledPersistedActionServiceBootstrap) applicationContext.getBean("scheduledPersistedActionServiceBootstrap");
// Set the current security context as admin
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
@@ -112,7 +107,7 @@ public class ScheduledPersistedActionServiceTest extends TestCase
txn.begin();
// Register the test executor, if needed
SleepActionExecuter.registerIfNeeded(ctx);
SleepActionExecuter.registerIfNeeded(applicationContext);
// Zap all test schedules
List<ScheduledPersistedAction> schedules = service.listSchedules();
@@ -140,8 +135,8 @@ public class ScheduledPersistedActionServiceTest extends TestCase
scheduler.standby();
}
@Override
protected void tearDown() throws Exception
@After
public void tearDown() throws Exception
{
UserTransaction txn = transactionService.getUserTransaction();
txn.begin();
@@ -161,6 +156,7 @@ public class ScheduledPersistedActionServiceTest extends TestCase
/**
* Test that the {@link ScheduledPersistedAction} implementation behaves properly
*/
@Test
public void testPersistedActionImpl() throws Exception
{
ScheduledPersistedActionImpl schedule = new ScheduledPersistedActionImpl(testAction);
@@ -250,6 +246,7 @@ public class ScheduledPersistedActionServiceTest extends TestCase
/**
* Tests that the to-trigger stuff works properly
*/
@Test
public void testActionToTrigger() throws Exception
{
// Can't get a trigger until persisted
@@ -385,6 +382,7 @@ public class ScheduledPersistedActionServiceTest extends TestCase
/**
* Tests that the triggers are suitably tweaked based on when the last run occured
*/
@Test
public void testAsTriggerLastRun() throws Exception
{
long future = System.currentTimeMillis() + 1234567;
@@ -571,6 +569,7 @@ public class ScheduledPersistedActionServiceTest extends TestCase
/**
* Tests that we can create, save, edit, delete etc the scheduled persisted actions
*/
@Test
public void testCreation()
{
ScheduledPersistedAction schedule = service.createSchedule(testAction);
@@ -592,6 +591,7 @@ public class ScheduledPersistedActionServiceTest extends TestCase
assertEquals(ScheduledPersistedAction.IntervalPeriod.Day, schedule.getScheduleIntervalPeriod());
}
@Test
public void testCreateSaveLoad() throws Exception
{
// create and save schedule
@@ -648,6 +648,7 @@ public class ScheduledPersistedActionServiceTest extends TestCase
* Ensures that we can create, save, edit, save load, edit, save, load etc, all without problems, and without
* creating duplicates
*/
@Test
public void testEditing() throws Exception
{
// create and save schedule
@@ -729,6 +730,7 @@ public class ScheduledPersistedActionServiceTest extends TestCase
/**
* Tests that the listings work, both of all scheduled, and from an action
*/
@Test
public void testLoadList() throws Exception
{
assertEquals(0, service.listSchedules().size());
@@ -750,6 +752,7 @@ public class ScheduledPersistedActionServiceTest extends TestCase
assertEquals(2, service.listSchedules().size());
}
@Test
public void testLoadFromAction() throws Exception
{
// Create schedule
@@ -770,6 +773,7 @@ public class ScheduledPersistedActionServiceTest extends TestCase
/**
* Tests that the startup registering works properly
*/
@Test
public void testStartup() throws Exception
{
// Startup with none there, nothing happens
@@ -792,7 +796,7 @@ public class ScheduledPersistedActionServiceTest extends TestCase
schedule.setScheduleStart(new Date(future));
service.saveSchedule(schedule);
((ScheduledPersistedActionServiceImpl) ctx.getBean("scheduledPersistedActionService"))
((ScheduledPersistedActionServiceImpl) applicationContext.getBean("scheduledPersistedActionService"))
.removeFromScheduler((ScheduledPersistedActionImpl) schedule);
assertEquals(0, scheduler
@@ -812,6 +816,7 @@ public class ScheduledPersistedActionServiceTest extends TestCase
/**
* Ensures that deletion works correctly
*/
@Test
public void testDeletion() throws Exception
{
// Delete does nothing if not persisted
@@ -890,6 +895,7 @@ public class ScheduledPersistedActionServiceTest extends TestCase
/**
* Tests that things get properly injected onto the job bean
*/
@Test
public void testJobBeanInjection() throws Exception
{
// This test needs the scheduler running properly
@@ -906,7 +912,7 @@ public class ScheduledPersistedActionServiceTest extends TestCase
.startAt(new Date(1))
.withSchedule(SimpleScheduleBuilder.simpleSchedule().withMisfireHandlingInstructionFireNow())
.build();
Scheduler scheduler = (Scheduler) ctx.getBean("schedulerFactory");
Scheduler scheduler = (Scheduler) applicationContext.getBean("schedulerFactory");
scheduler.scheduleJob(details, now);
// Allow it to run
@@ -924,9 +930,10 @@ public class ScheduledPersistedActionServiceTest extends TestCase
/**
* Tests that things actually get run correctly. Each sub-test runs in its own transaction
*/
@Test
public void testExecution() throws Exception
{
final SleepActionExecuter sleepActionExec = (SleepActionExecuter) ctx.getBean(SleepActionExecuter.NAME);
final SleepActionExecuter sleepActionExec = (SleepActionExecuter) applicationContext.getBean(SleepActionExecuter.NAME);
sleepActionExec.resetTimesExecuted();
sleepActionExec.setSleepMs(1);
@@ -1114,9 +1121,10 @@ public class ScheduledPersistedActionServiceTest extends TestCase
* Tests that when we have more than one schedule defined and active, then the correct things run at the correct
* times, and we never get confused
*/
@Test
public void testMultipleExecutions() throws Exception
{
final SleepActionExecuter sleepActionExec = (SleepActionExecuter) ctx.getBean(SleepActionExecuter.NAME);
final SleepActionExecuter sleepActionExec = (SleepActionExecuter) applicationContext.getBean(SleepActionExecuter.NAME);
sleepActionExec.resetTimesExecuted();
sleepActionExec.setSleepMs(1);

View File

@@ -25,11 +25,6 @@
*/
package org.alfresco.repo.blog;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
@@ -45,7 +40,6 @@ import org.alfresco.query.PagingRequest;
import org.alfresco.query.PagingResults;
import org.alfresco.repo.policy.BehaviourFilter;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.site.SiteModel;
import org.alfresco.repo.transaction.RetryingTransactionHelper;
import org.alfresco.service.cmr.blog.BlogPostInfo;
import org.alfresco.service.cmr.blog.BlogService;
@@ -62,19 +56,15 @@ import org.alfresco.service.cmr.site.SiteService;
import org.alfresco.service.cmr.site.SiteVisibility;
import org.alfresco.service.cmr.tagging.TaggingService;
import org.alfresco.service.namespace.QName;
import org.alfresco.util.ApplicationContextHelper;
import org.alfresco.util.BaseSpringTest;
import org.alfresco.util.GUID;
import org.alfresco.util.Pair;
import org.alfresco.util.PropertyMap;
import org.alfresco.util.testing.category.LuceneTests;
import org.alfresco.util.testing.category.RedundantTests;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.springframework.context.ApplicationContext;
/**
* Test cases for {@link BlogServiceImpl}.
@@ -83,11 +73,8 @@ import org.springframework.context.ApplicationContext;
* @since 4.0
*/
@Category(LuceneTests.class)
public class BlogServiceImplTest
public class BlogServiceImplTest extends BaseSpringTest
{
private static final ApplicationContext testContext = ApplicationContextHelper.getApplicationContext();
// injected services
private static MutableAuthenticationService AUTHENTICATION_SERVICE;
private static BehaviourFilter BEHAVIOUR_FILTER;
@@ -99,7 +86,7 @@ public class BlogServiceImplTest
private static SiteService SITE_SERVICE;
private static TaggingService TAGGING_SERVICE;
private static final String TEST_USER = BlogServiceImplTest.class.getSimpleName() + "_testuser";
private static final String TEST_USER = BlogServiceImplTest.class.getSimpleName() + GUID.generate();
private static final String ADMIN_USER = AuthenticationUtil.getAdminUserName();
@@ -115,17 +102,18 @@ public class BlogServiceImplTest
private static SiteInfo BLOG_SITE;
private static NodeRef BLOG_CONTAINER_NODE;
@BeforeClass public static void initTestsContext() throws Exception
@Before
public void before() throws Exception
{
AUTHENTICATION_SERVICE = (MutableAuthenticationService)testContext.getBean("authenticationService");
BEHAVIOUR_FILTER = (BehaviourFilter)testContext.getBean("policyBehaviourFilter");
BLOG_SERVICE = (BlogService)testContext.getBean("blogService");
DICTIONARY_SERVICE = (DictionaryService)testContext.getBean("dictionaryService");
NODE_SERVICE = (NodeService)testContext.getBean("nodeService");
PERSON_SERVICE = (PersonService)testContext.getBean("personService");
TRANSACTION_HELPER = (RetryingTransactionHelper)testContext.getBean("retryingTransactionHelper");
SITE_SERVICE = (SiteService)testContext.getBean("siteService");
TAGGING_SERVICE = (TaggingService)testContext.getBean("TaggingService");
AUTHENTICATION_SERVICE = (MutableAuthenticationService)applicationContext.getBean("authenticationService");
BEHAVIOUR_FILTER = (BehaviourFilter)applicationContext.getBean("policyBehaviourFilter");
BLOG_SERVICE = (BlogService)applicationContext.getBean("blogService");
DICTIONARY_SERVICE = (DictionaryService)applicationContext.getBean("dictionaryService");
NODE_SERVICE = (NodeService)applicationContext.getBean("nodeService");
PERSON_SERVICE = (PersonService)applicationContext.getBean("personService");
TRANSACTION_HELPER = (RetryingTransactionHelper)applicationContext.getBean("retryingTransactionHelper");
SITE_SERVICE = (SiteService)applicationContext.getBean("siteService");
TAGGING_SERVICE = (TaggingService)applicationContext.getBean("TaggingService");
AuthenticationUtil.setFullyAuthenticatedUser(ADMIN_USER);
createUser(TEST_USER);
@@ -133,6 +121,7 @@ public class BlogServiceImplTest
// We need to create the test site as the test user so that they can contribute content to it in tests below.
AuthenticationUtil.setFullyAuthenticatedUser(TEST_USER);
createTestSiteWithBlogContainer();
AuthenticationUtil.setFullyAuthenticatedUser(ADMIN_USER);
}
private static void createTestSiteWithBlogContainer() throws Exception
@@ -171,61 +160,6 @@ public class BlogServiceImplTest
});
}
/**
* By default, all tests are run as the admin user.
*/
@Before public void setAdminUser()
{
AuthenticationUtil.setFullyAuthenticatedUser(ADMIN_USER);
}
@After public void deleteTestNodes() throws Exception
{
performDeletionOfNodes(testNodesToTidy);
}
@AfterClass public static void deleteClassTestNodesAndUsers() throws Exception
{
performDeletionOfNodes(CLASS_TEST_NODES_TO_TIDY);
deleteUser(TEST_USER);
}
/**
* Deletes the specified NodeRefs, if they exist.
* @param nodesToDelete List<NodeRef>
*/
private static void performDeletionOfNodes(final List<NodeRef> nodesToDelete)
{
TRANSACTION_HELPER.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>()
{
@Override
public Void execute() throws Throwable
{
AuthenticationUtil.setFullyAuthenticatedUser(ADMIN_USER);
for (NodeRef node : nodesToDelete)
{
if (NODE_SERVICE.exists(node))
{
// st:site nodes can only be deleted via the SiteService
if (NODE_SERVICE.getType(node).equals(SiteModel.TYPE_SITE))
{
SiteInfo siteInfo = SITE_SERVICE.getSite(node);
SITE_SERVICE.deleteSite(siteInfo.getShortName());
}
else
{
NODE_SERVICE.deleteNode(node);
}
}
}
return null;
}
});
}
@Test public void createDraftBlogPostsAndGetPagedResults() throws Exception
{
final int arbitraryNumberGreaterThanPageSize = 42;
@@ -906,21 +840,4 @@ public class BlogServiceImplTest
}
});
}
private static void deleteUser(final String userName)
{
TRANSACTION_HELPER.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>()
{
@Override
public Void execute() throws Throwable
{
if (PERSON_SERVICE.personExists(userName))
{
PERSON_SERVICE.deletePerson(userName);
}
return null;
}
});
}
}

View File

@@ -25,10 +25,6 @@
*/
package org.alfresco.repo.oauth1;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.util.List;
import org.alfresco.model.ContentModel;
@@ -40,24 +36,18 @@ import org.alfresco.service.cmr.oauth1.OAuth1CredentialsStoreService;
import org.alfresco.service.cmr.remotecredentials.OAuth1CredentialsInfo;
import org.alfresco.service.cmr.security.MutableAuthenticationService;
import org.alfresco.service.cmr.security.PersonService;
import org.alfresco.test_category.BaseSpringTestsCategory;
import org.alfresco.test_category.OwnJVMTestsCategory;
import org.alfresco.util.ApplicationContextHelper;
import org.alfresco.util.BaseSpringTest;
import org.alfresco.util.GUID;
import org.alfresco.util.PropertyMap;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.After;
import org.junit.Before;
import org.junit.FixMethodOrder;
import org.junit.experimental.categories.Category;
import org.junit.runners.MethodSorters;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
@Category(BaseSpringTestsCategory.class)
public class OAuth1CredentialsStoreServiceTest
public class OAuth1CredentialsStoreServiceTest extends BaseSpringTest
{
private static ApplicationContext ctx = ApplicationContextHelper.getApplicationContext();
private static OAuth1CredentialsStoreService oauth1CredentialsStoreService;
private static ServiceRegistry serviceRegistry;
private static RetryingTransactionHelper transactionHelper;
@@ -75,31 +65,28 @@ public class OAuth1CredentialsStoreServiceTest
private static String UpdatedSecret = "321ihgfedcba";
//Users
private static String TEST_USER_ONE = OAuth1CredentialsStoreService.class.getSimpleName() + "testuser1";
private static String TEST_USER_TWO = OAuth1CredentialsStoreService.class.getSimpleName() + "testuser2";
private static String TEST_USER_ONE = OAuth1CredentialsStoreService.class.getSimpleName() + GUID.generate();
private static String TEST_USER_TWO = OAuth1CredentialsStoreService.class.getSimpleName() + GUID.generate();
private static final String ADMIN_USER = AuthenticationUtil.getAdminUserName();
@BeforeClass
public static void setUp() throws Exception
@Before
public void before() throws Exception
{
serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);
serviceRegistry = (ServiceRegistry) applicationContext.getBean(ServiceRegistry.SERVICE_REGISTRY);
transactionHelper = serviceRegistry.getTransactionService().getRetryingTransactionHelper();
authenticationService = serviceRegistry.getAuthenticationService();
personService = serviceRegistry.getPersonService();
oauth1CredentialsStoreService = (OAuth1CredentialsStoreService) ctx.getBean("oauth1CredentialsStoreService");
oauth1CredentialsStoreService = (OAuth1CredentialsStoreService) applicationContext.getBean("oauth1CredentialsStoreService");
AuthenticationUtil.setFullyAuthenticatedUser(ADMIN_USER);
createUser(TEST_USER_ONE);
createUser(TEST_USER_TWO);
}
@AfterClass
public static void tearDown() throws Exception
@After
public void tearDown() throws Exception
{
// Do the teardown as admin
AuthenticationUtil.setFullyAuthenticatedUser(ADMIN_USER);
deleteUser(TEST_USER_ONE);
deleteUser(TEST_USER_TWO);
AuthenticationUtil.clearCurrentSecurityContext();
}
@Test
@@ -226,22 +213,4 @@ public class OAuth1CredentialsStoreServiceTest
}
});
}
private static void deleteUser(final String userName)
{
transactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>()
{
@Override
public Void execute() throws Throwable
{
if (personService.personExists(userName))
{
personService.deletePerson(userName);
}
return null;
}
});
}
}

View File

@@ -44,18 +44,19 @@ import org.alfresco.service.cmr.security.PersonService;
import org.alfresco.test_category.BaseSpringTestsCategory;
import org.alfresco.test_category.OwnJVMTestsCategory;
import org.alfresco.util.ApplicationContextHelper;
import org.alfresco.util.BaseSpringTest;
import org.alfresco.util.GUID;
import org.alfresco.util.PropertyMap;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.springframework.context.ApplicationContext;
@Category(BaseSpringTestsCategory.class)
public class OAuth2CredentialsStoreServiceTest
public class OAuth2CredentialsStoreServiceTest extends BaseSpringTest
{
private static ApplicationContext ctx = ApplicationContextHelper.getApplicationContext();
private static OAuth2CredentialsStoreService oauth2CredentialsStoreService;
private static ServiceRegistry serviceRegistry;
private static RetryingTransactionHelper transactionHelper;
@@ -79,31 +80,28 @@ public class OAuth2CredentialsStoreServiceTest
private static Date UpdatedIssuedAt = new Date(dec292012);
//Users
private static String TEST_USER_ONE = OAuth2CredentialsStoreService.class.getSimpleName() + "testuser1";
private static String TEST_USER_TWO = OAuth2CredentialsStoreService.class.getSimpleName() + "testuser2";
private static String TEST_USER_ONE = OAuth2CredentialsStoreService.class.getSimpleName() + GUID.generate();
private static String TEST_USER_TWO = OAuth2CredentialsStoreService.class.getSimpleName() + GUID.generate();
private static final String ADMIN_USER = AuthenticationUtil.getAdminUserName();
@BeforeClass
public static void setUp() throws Exception
@Before
public void setUp() throws Exception
{
serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);
serviceRegistry = (ServiceRegistry) applicationContext.getBean(ServiceRegistry.SERVICE_REGISTRY);
transactionHelper = serviceRegistry.getTransactionService().getRetryingTransactionHelper();
authenticationService = serviceRegistry.getAuthenticationService();
personService = serviceRegistry.getPersonService();
oauth2CredentialsStoreService = (OAuth2CredentialsStoreService) ctx.getBean("oauth2CredentialsStoreService");
oauth2CredentialsStoreService = (OAuth2CredentialsStoreService) applicationContext.getBean("oauth2CredentialsStoreService");
AuthenticationUtil.setFullyAuthenticatedUser(ADMIN_USER);
createUser(TEST_USER_ONE);
createUser(TEST_USER_TWO);
}
@AfterClass
public static void tearDown() throws Exception
@After
public void tearDown() throws Exception
{
// Do the teardown as admin
AuthenticationUtil.setFullyAuthenticatedUser(ADMIN_USER);
deleteUser(TEST_USER_ONE);
deleteUser(TEST_USER_TWO);
AuthenticationUtil.clearCurrentSecurityContext();
}
@Test
@@ -239,22 +237,4 @@ public class OAuth2CredentialsStoreServiceTest
}
});
}
private static void deleteUser(final String userName)
{
transactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>()
{
@Override
public Void execute() throws Throwable
{
if (personService.personExists(userName))
{
personService.deletePerson(userName);
}
return null;
}
});
}
}

View File

@@ -25,11 +25,6 @@
*/
package org.alfresco.repo.rawevents;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.util.Locale;
import org.alfresco.model.ContentModel;
@@ -44,7 +39,6 @@ import org.alfresco.repo.rawevents.types.EventType;
import org.alfresco.repo.rawevents.types.OnContentUpdatePolicyEvent;
import org.alfresco.repo.security.authentication.AuthenticationComponent;
import org.alfresco.repo.transaction.RetryingTransactionHelper;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.ContentData;
import org.alfresco.service.cmr.repository.ContentService;
@@ -53,64 +47,49 @@ 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.namespace.QName;
import org.alfresco.test_category.OwnJVMTestsCategory;
import org.alfresco.util.ApplicationContextHelper;
import org.alfresco.util.BaseSpringTest;
import org.alfresco.util.GUID;
import org.alfresco.util.PropertyMap;
import org.apache.camel.CamelContext;
import org.apache.camel.component.mock.MockEndpoint;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.rules.TestName;
import org.springframework.context.ApplicationContext;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.beans.factory.annotation.Autowired;
/**
* Provides a base set of tests for {@link EventBehaviour}
*
* @author Cristian Turlica
*/
@Category(OwnJVMTestsCategory.class)
public class EventBehaviourTest
public class EventBehaviourTest extends BaseSpringTest
{
private static final String TEST_NAMESPACE = "http://www.alfresco.org/test/EventBehaviourTest";
@Autowired
private RetryingTransactionHelper retryingTransactionHelper;
@Autowired
private ContentService contentService;
@Autowired
private PolicyComponent policyComponent;
@Autowired
private NodeService nodeService;
@Autowired
private AuthenticationComponent authenticationComponent;
private NodeRef rootNodeRef;
private NodeRef contentNodeRef;
@Autowired
private CamelContext camelContext;
@Autowired
private AbstractEventProducer eventProducer;
private ObjectMapper messagingObjectMapper;
private boolean policyFired = false;
private boolean newContent = true;
@Rule
public TestName name = new TestName();
@Before
public void setUp() throws Exception
{
ApplicationContext ctx = ApplicationContextHelper.getApplicationContext();
retryingTransactionHelper = (RetryingTransactionHelper) ctx.getBean("retryingTransactionHelper");
nodeService = (NodeService) ctx.getBean("NodeService");
contentService = (ContentService) ctx.getBean(ServiceRegistry.CONTENT_SERVICE.getLocalName());
policyComponent = (PolicyComponent) ctx.getBean("policyComponent");
authenticationComponent = (AuthenticationComponent) ctx.getBean("authenticationComponent");
camelContext = (CamelContext) ctx.getBean("alfrescoCamelContext");
eventProducer = (AbstractEventProducer) ctx.getBean("transactionAwareEventProducer");
messagingObjectMapper = (ObjectMapper) ctx.getBean("alfrescoEventObjectMapper");
// authenticate
authenticationComponent.setSystemUserAsCurrentUser();
}
@@ -142,7 +121,7 @@ public class EventBehaviourTest
private void setupTestData()
{
// create a store and get the root node
StoreRef storeRef = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, name.getMethodName());
StoreRef storeRef = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, this.getClass().getName());
if (!nodeService.exists(storeRef))
{
storeRef = nodeService.createStore(storeRef.getProtocol(), storeRef.getIdentifier());
@@ -397,7 +376,7 @@ public class EventBehaviourTest
private String getMockEndpointUri()
{
return "mock:" + this.getClass().getSimpleName() + "_" + name.getMethodName();
return "mock:" + this.getClass().getSimpleName() + "_" + GUID.generate();
}
@SuppressWarnings("unused")

View File

@@ -25,23 +25,15 @@
*/
package org.alfresco.repo.rawevents;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import org.alfresco.repo.rawevents.types.EventType;
import org.alfresco.repo.rawevents.types.OnContentUpdatePolicyEvent;
import org.alfresco.repo.transaction.RetryingTransactionHelper;
import org.alfresco.test_category.OwnJVMTestsCategory;
import org.alfresco.util.ApplicationContextHelper;
import org.alfresco.util.BaseSpringTest;
import org.alfresco.util.GUID;
import org.apache.camel.CamelContext;
import org.apache.camel.component.mock.MockEndpoint;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.rules.TestName;
import org.springframework.context.ApplicationContext;
import org.springframework.beans.factory.annotation.Autowired;
import com.fasterxml.jackson.databind.ObjectMapper;
@@ -50,27 +42,17 @@ import com.fasterxml.jackson.databind.ObjectMapper;
*
* @author Cristian Turlica
*/
@Category(OwnJVMTestsCategory.class)
public class TransactionAwareEventProducerTest
public class TransactionAwareEventProducerTest extends BaseSpringTest
{
@Autowired
private RetryingTransactionHelper retryingTransactionHelper;
@Autowired
private CamelContext camelContext;
@Autowired
private TransactionAwareEventProducer eventProducer;
@Autowired
private ObjectMapper messagingObjectMapper;
@Rule
public TestName name = new TestName();
@Before
public void setUp() throws Exception
{
ApplicationContext ctx = ApplicationContextHelper.getApplicationContext();
retryingTransactionHelper = (RetryingTransactionHelper) ctx.getBean("retryingTransactionHelper");
camelContext = (CamelContext) ctx.getBean("alfrescoCamelContext");
eventProducer = (TransactionAwareEventProducer) ctx.getBean("transactionAwareEventProducer");
messagingObjectMapper = (ObjectMapper) ctx.getBean("alfrescoEventObjectMapper");
}
@Test
public void send() throws Exception
{
@@ -127,6 +109,6 @@ public class TransactionAwareEventProducerTest
private String getMockEndpointUri()
{
return "mock:" + this.getClass().getSimpleName() + "_" + name.getMethodName();
return "mock:" + this.getClass().getSimpleName() + "_" + GUID.generate();
}
}

View File

@@ -115,10 +115,6 @@ public abstract class AbstractRenditionIntegrationTest extends BaseSpringTest
@BeforeClass
public static void before()
{
// Ensure other applications contexts are closed...
// Multiple consumers not supported for same direct vm in different Camel contexts.
ApplicationContextHelper.closeApplicationContext();
// Use the docker images for transforms
System.setProperty("alfresco-pdf-renderer.url", "http://localhost:8090/");
System.setProperty("img.url", "http://localhost:8091");

View File

@@ -25,7 +25,6 @@
*/
package org.alfresco.repo.rendition2;
import junit.framework.TestCase;
import org.alfresco.repo.content.transform.swf.SWFTransformationOptions;
import org.alfresco.repo.rendition.RenditionServiceImpl;
import org.alfresco.repo.security.authentication.AuthenticationComponent;
@@ -34,14 +33,16 @@ import org.alfresco.repo.thumbnail.ThumbnailRenditionConvertor;
import org.alfresco.service.cmr.rendition.RenditionDefinition;
import org.alfresco.service.cmr.rendition.RenditionService;
import org.alfresco.service.cmr.repository.TransformationOptions;
import org.alfresco.util.ApplicationContextHelper;
import org.springframework.context.ApplicationContext;
import org.alfresco.util.BaseSpringTest;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.StringJoiner;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
/**
* Tests that the replacement {@link RenditionDefinition2} generates the same {@link TransformationOptions} as the
@@ -52,28 +53,26 @@ import java.util.StringJoiner;
* @author adavis
*/
@Deprecated
public class RenditionDefinitionTest extends TestCase
public class RenditionDefinitionTest extends BaseSpringTest
{
private RenditionServiceImpl renditionService;
private RenditionDefinitionRegistry2 renditionDefinitionRegistry2;
private TransformationOptionsConverter transformationOptionsConverter;
private static ApplicationContext ctx = ApplicationContextHelper.getApplicationContext();
private AuthenticationComponent authenticationComponent;
@Override
protected void setUp() throws Exception
@Before
public void setUp() throws Exception
{
authenticationComponent = (AuthenticationComponent) ctx.getBean("AuthenticationComponent");
renditionService = (RenditionServiceImpl) ctx.getBean("renditionService");
renditionDefinitionRegistry2 = (RenditionDefinitionRegistry2) ctx.getBean("renditionDefinitionRegistry2");
transformationOptionsConverter = (TransformationOptionsConverter) ctx.getBean("transformOptionsConverter");
authenticationComponent = (AuthenticationComponent) applicationContext.getBean("AuthenticationComponent");
renditionService = (RenditionServiceImpl) applicationContext.getBean("renditionService");
renditionDefinitionRegistry2 = (RenditionDefinitionRegistry2) applicationContext.getBean("renditionDefinitionRegistry2");
transformationOptionsConverter = (TransformationOptionsConverter) applicationContext.getBean("transformOptionsConverter");
authenticationComponent.setSystemUserAsCurrentUser();
}
@Override
protected void tearDown() throws Exception
@After
public void tearDown() throws Exception
{
try
{
@@ -98,6 +97,7 @@ public class RenditionDefinitionTest extends TestCase
return null;
}
@Test
public void testGetRenderingEngineDefinition() throws Exception
{
ThumbnailRenditionConvertor converter = new ThumbnailRenditionConvertor();

View File

@@ -33,8 +33,6 @@ import java.util.Map;
import javax.transaction.Status;
import javax.transaction.UserTransaction;
import junit.framework.TestCase;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.domain.dialect.Dialect;
import org.alfresco.repo.domain.dialect.PostgreSQLDialect;
@@ -51,22 +49,19 @@ import org.alfresco.service.cmr.search.QueryParameterDefinition;
import org.alfresco.service.namespace.DynamicNamespacePrefixResolver;
import org.alfresco.service.namespace.QName;
import org.alfresco.service.transaction.TransactionService;
import org.alfresco.test_category.OwnJVMTestsCategory;
import org.alfresco.util.ApplicationContextHelper;
import org.alfresco.util.BaseSpringTest;
import org.alfresco.util.ISO9075;
import org.junit.experimental.categories.Category;
import org.springframework.context.ApplicationContext;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
/**
* @see org.alfresco.repo.search.SearcherComponent
*
* @author Derek Hulley
*/
@Category({OwnJVMTestsCategory.class})
public class SearcherComponentTest extends TestCase
public class SearcherComponentTest extends BaseSpringTest
{
private static ApplicationContext ctx = ApplicationContextHelper.getApplicationContext();
//private static String COMPLEX_LOCAL_NAME = " `¬¦!\"£$%^&*()-_=+\t\n\\\u0000[]{};'#:@~,./<>?\\|\u0123\u4567\u8900\uabcd\uefff_xT65A_";
// \u0123 and \u8900 removed
@@ -96,9 +91,10 @@ public class SearcherComponentTest extends TestCase
// TODO: pending replacement
private Dialect dialect;
@Before
public void setUp() throws Exception
{
dialect = (Dialect) ctx.getBean("dialect");
dialect = (Dialect) applicationContext.getBean("dialect");
if (dialect instanceof PostgreSQLDialect)
{
// Note: PostgreSQL does not support \u0000 char embedded in a string
@@ -106,16 +102,16 @@ public class SearcherComponentTest extends TestCase
COMPLEX_LOCAL_NAME = COMPLEX_LOCAL_NAME_NO_U0000;
}
serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);
serviceRegistry = (ServiceRegistry) applicationContext.getBean(ServiceRegistry.SERVICE_REGISTRY);
transactionService = serviceRegistry.getTransactionService();
dictionaryService = BaseNodeServiceTest.loadModel(ctx);
dictionaryService = BaseNodeServiceTest.loadModel(applicationContext);
nodeService = serviceRegistry.getNodeService();
this.authenticationComponent = (AuthenticationComponent) ctx.getBean("authenticationComponent");
this.authenticationComponent = (AuthenticationComponent) applicationContext.getBean("authenticationComponent");
this.authenticationComponent.setSystemUserAsCurrentUser();
// get the indexer and searcher factory
IndexerAndSearcher indexerAndSearcher = (IndexerAndSearcher) ctx.getBean("indexerAndSearcherFactory");
IndexerAndSearcher indexerAndSearcher = (IndexerAndSearcher) applicationContext.getBean("indexerAndSearcherFactory");
searcher = new SearcherComponent();
searcher.setIndexerAndSearcherFactory(indexerAndSearcher);
// create a test workspace
@@ -127,6 +123,7 @@ public class SearcherComponentTest extends TestCase
txn.begin();
}
@After
public void tearDown() throws Exception
{
if (txn.getStatus() == Status.STATUS_ACTIVE)
@@ -137,6 +134,7 @@ public class SearcherComponentTest extends TestCase
super.tearDown();
}
@Test
public void testNodeXPath() throws Exception
{
Map<QName, ChildAssociationRef> assocRefs = BaseNodeServiceTest.buildNodeGraph(nodeService, rootNodeRef);
@@ -299,6 +297,7 @@ public class SearcherComponentTest extends TestCase
assertEquals(2, list.size());
}
@Test
public void testSelectAPI() throws Exception
{
Map<QName, ChildAssociationRef> assocRefs = BaseNodeServiceTest.buildNodeGraph(nodeService, rootNodeRef);

View File

@@ -35,8 +35,6 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import junit.framework.TestCase;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.dictionary.DictionaryDAO;
import org.alfresco.repo.dictionary.M2Model;
@@ -62,26 +60,24 @@ import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.alfresco.service.transaction.TransactionService;
import org.alfresco.test_category.OwnJVMTestsCategory;
import org.alfresco.util.ApplicationContextHelper;
import org.alfresco.util.BaseSpringTest;
import org.alfresco.util.PropertyMap;
import org.alfresco.util.testing.category.LuceneTests;
import org.alfresco.util.testing.category.PerformanceTests;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.Before;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.springframework.context.ConfigurableApplicationContext;
/**
* Tests tracking component
*
* @since 4.0
*/
@Category({OwnJVMTestsCategory.class, LuceneTests.class})
public class SOLRTrackingComponentTest extends TestCase
public class SOLRTrackingComponentTest extends BaseSpringTest
{
private static final Log logger = LogFactory.getLog(SOLRTrackingComponentTest.class);
private ConfigurableApplicationContext ctx = (ConfigurableApplicationContext) ApplicationContextHelper.getApplicationContext();
private static enum NodeStatus
{
UPDATED, DELETED;
@@ -103,24 +99,24 @@ public class SOLRTrackingComponentTest extends TestCase
private StoreRef storeRef;
private NodeRef rootNodeRef;
@Override
public void setUp() throws Exception
@Before
public void before() throws Exception
{
ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);
ServiceRegistry serviceRegistry = (ServiceRegistry) applicationContext.getBean(ServiceRegistry.SERVICE_REGISTRY);
transactionService = serviceRegistry.getTransactionService();
txnHelper = transactionService.getRetryingTransactionHelper();
solrTrackingComponent = (SOLRTrackingComponent) ctx.getBean("solrTrackingComponent");
nodeDAO = (NodeDAO)ctx.getBean("nodeDAO");
qnameDAO = (QNameDAO) ctx.getBean("qnameDAO");
dictionaryDAO = (DictionaryDAO)ctx.getBean("dictionaryDAO");
nodeService = (NodeService)ctx.getBean("NodeService");
fileFolderService = (FileFolderService)ctx.getBean("FileFolderService");
solrTrackingComponent = (SOLRTrackingComponent) applicationContext.getBean("solrTrackingComponent");
nodeDAO = (NodeDAO)applicationContext.getBean("nodeDAO");
qnameDAO = (QNameDAO) applicationContext.getBean("qnameDAO");
dictionaryDAO = (DictionaryDAO)applicationContext.getBean("dictionaryDAO");
nodeService = (NodeService)applicationContext.getBean("NodeService");
fileFolderService = (FileFolderService)applicationContext.getBean("FileFolderService");
dictionaryService = serviceRegistry.getDictionaryService();
namespaceService = serviceRegistry.getNamespaceService();
authenticationComponent = (AuthenticationComponent)ctx.getBean("authenticationComponent");
authenticationComponent = (AuthenticationComponent)applicationContext.getBean("authenticationComponent");
dbNodeService = (DbNodeServiceImpl)ctx.getBean("dbNodeService");
dbNodeService = (DbNodeServiceImpl)applicationContext.getBean("dbNodeService");
dbNodeService.setEnableTimestampPropagation(false);
authenticationComponent.setSystemUserAsCurrentUser();
@@ -129,6 +125,7 @@ public class SOLRTrackingComponentTest extends TestCase
rootNodeRef = nodeService.getRootNode(storeRef);
}
@Test
public void testAclChangeSetLimits()
{
List<AclChangeSet> aclChangeSets = getAclChangeSets(null, null, null, null, 50);
@@ -148,6 +145,7 @@ public class SOLRTrackingComponentTest extends TestCase
// This test is no longer valid as we may or may include shared acls not linked to defining ones
// If they are not linked to a node they will be counted wring ...
// @Test
// public void testGetAcls_Simple()
// {
// List<AclChangeSet> cs = getAclChangeSets(null, null, null, null, 50);
@@ -170,6 +168,7 @@ public class SOLRTrackingComponentTest extends TestCase
// assertEquals("ACL count should have matched", totalAcls, totalAclsCheck);
// }
@Test
public void testGetNodeMetaData()
{
long startTime = System.currentTimeMillis();
@@ -283,6 +282,7 @@ public class SOLRTrackingComponentTest extends TestCase
return transactionService.getRetryingTransactionHelper().doInTransaction(callback, true);
}
@Test
public void testGetTransactionLimits()
{
long startTime = System.currentTimeMillis();
@@ -341,6 +341,7 @@ public class SOLRTrackingComponentTest extends TestCase
assertEquals(0, txns.size());
}
@Test
public void testGetNodeMetaDataExludesResidualProperties()
{
long startTime = System.currentTimeMillis();
@@ -365,6 +366,7 @@ public class SOLRTrackingComponentTest extends TestCase
}
@Test
public void testGetNodeMetaData100Nodes()
{
long startTime = System.currentTimeMillis();
@@ -394,6 +396,8 @@ public class SOLRTrackingComponentTest extends TestCase
// assertEquals("Unxpected number of nodes", 3, bt.getSuccessCount());
}
@Category(PerformanceTests.class)
@Test
public void testNodeMetaDataManyNodes() throws Exception
{
long fromCommitTime = System.currentTimeMillis();
@@ -451,6 +455,8 @@ public class SOLRTrackingComponentTest extends TestCase
getNodeMetaData(nodeMetaDataParams, null, st);
}
@Category(PerformanceTests.class)
@Test
public void testNodeMetaDataCache() throws Exception
{
long fromCommitTime = System.currentTimeMillis();
@@ -481,6 +487,7 @@ public class SOLRTrackingComponentTest extends TestCase
getNodeMetaData(nodeMetaDataParams, filter, st);
}
@Test
public void testNodeMetaDataNullPropertyValue() throws Exception
{
long fromCommitTime = System.currentTimeMillis();
@@ -503,6 +510,7 @@ public class SOLRTrackingComponentTest extends TestCase
getNodeMetaData(nodeMetaDataParams, null, st);
}
@Test
public void testFilters()
{
long startTime = System.currentTimeMillis();
@@ -525,6 +533,7 @@ public class SOLRTrackingComponentTest extends TestCase
getNodeMetaData(nodeMetaDataParams, null, st);
}
@Test
public void testModelDiffs()
{
Collection<QName> allModels = dictionaryService.getAllModels();

View File

@@ -63,8 +63,7 @@ import org.alfresco.service.cmr.tagging.TagScope;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.alfresco.service.transaction.TransactionService;
import org.alfresco.test_category.OwnJVMTestsCategory;
import org.alfresco.util.ApplicationContextHelper;
import org.alfresco.util.BaseSpringTest;
import org.alfresco.util.GUID;
import org.alfresco.util.Pair;
import org.alfresco.util.PropertyMap;
@@ -77,18 +76,13 @@ import org.junit.Before;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;
import org.junit.runners.MethodSorters;
import org.mockito.runners.MockitoJUnitRunner;
import org.springframework.context.ConfigurableApplicationContext;
import java.io.ByteArrayInputStream;
import java.io.Serializable;
import java.io.UnsupportedEncodingException;
import java.util.*;
import static org.junit.Assert.*;
/**
* Tagging service implementation unit test
*
@@ -96,13 +90,8 @@ import static org.junit.Assert.*;
* @author Nick Burch
*/
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
@Category({OwnJVMTestsCategory.class, LuceneTests.class})
@RunWith(MockitoJUnitRunner.class)
public class TaggingServiceImplTest
public class TaggingServiceImplTest extends BaseSpringTest
{
private static ConfigurableApplicationContext ctx =
(ConfigurableApplicationContext)ApplicationContextHelper.getApplicationContext();
private static final Log logger = LogFactory.getLog(TaggingServiceImplTest.class);
/** Services */
@@ -164,31 +153,31 @@ public class TaggingServiceImplTest
}
// Get services
this.taggingService = (TaggingServiceImpl)ctx.getBean("taggingService");
this.nodeService = (NodeService) ctx.getBean("NodeService");
this.fileFolderService = (FileFolderService) ctx.getBean("FileFolderService");
this.copyService = (CopyService) ctx.getBean("CopyService");
this.checkOutCheckInService = (CheckOutCheckInService) ctx.getBean("CheckoutCheckinService");
this.actionService = (ActionService)ctx.getBean("ActionService");
this.transactionService = (TransactionService)ctx.getBean("transactionComponent");
this.siteService = ctx.getBean("SiteService", SiteService.class);
this.taggingService = (TaggingServiceImpl)applicationContext.getBean("taggingService");
this.nodeService = (NodeService) applicationContext.getBean("NodeService");
this.fileFolderService = (FileFolderService) applicationContext.getBean("FileFolderService");
this.copyService = (CopyService) applicationContext.getBean("CopyService");
this.checkOutCheckInService = (CheckOutCheckInService) applicationContext.getBean("CheckoutCheckinService");
this.actionService = (ActionService)applicationContext.getBean("ActionService");
this.transactionService = (TransactionService)applicationContext.getBean("transactionComponent");
this.siteService = applicationContext.getBean("SiteService", SiteService.class);
//MNT-10807 : Auditing does not take into account audit.filter.alfresco-access.transaction.user
UserAuditFilter userAuditFilter = new UserAuditFilter();
userAuditFilter.setUserFilterPattern("System;.*");
userAuditFilter.afterPropertiesSet();
AuditComponent auditComponent = (AuditComponent) ctx.getBean("auditComponent");
AuditComponent auditComponent = (AuditComponent) applicationContext.getBean("auditComponent");
auditComponent.setUserAuditFilter(userAuditFilter);
AuditServiceImpl auditServiceImpl = (AuditServiceImpl) ctx.getBean("auditService");
AuditServiceImpl auditServiceImpl = (AuditServiceImpl) applicationContext.getBean("auditService");
auditServiceImpl.setAuditComponent(auditComponent);
this.auditService = (AuditService)ctx.getBean("auditService");
this.scriptService = (ScriptService)ctx.getBean("scriptService");
this.actionTrackingService = (ActionTrackingService)ctx.getBean("actionTrackingService");
this.authenticationComponent = (AuthenticationComponent)ctx.getBean("authenticationComponent");
this.auditService = (AuditService)applicationContext.getBean("auditService");
this.scriptService = (ScriptService)applicationContext.getBean("scriptService");
this.actionTrackingService = (ActionTrackingService)applicationContext.getBean("actionTrackingService");
this.authenticationComponent = (AuthenticationComponent)applicationContext.getBean("authenticationComponent");
this.personService = (PersonService)ctx.getBean("PersonService");
this.permissionService = (PermissionService)ctx.getBean("PermissionService");
this.authenticationService = (MutableAuthenticationService)ctx.getBean("authenticationService");
this.nodeRefPropInterceptor = (NodeRefPropertyMethodInterceptor)ctx.getBean("nodeRefPropertyInterceptor");
this.personService = (PersonService)applicationContext.getBean("PersonService");
this.permissionService = (PermissionService)applicationContext.getBean("PermissionService");
this.authenticationService = (MutableAuthenticationService)applicationContext.getBean("authenticationService");
this.nodeRefPropInterceptor = (NodeRefPropertyMethodInterceptor)applicationContext.getBean("nodeRefPropertyInterceptor");
if (init == false)
{
@@ -225,7 +214,7 @@ public class TaggingServiceImplTest
// We want to know when tagging actions have finished running
asyncOccurs = new AsyncOccurs();
((PolicyComponent)ctx.getBean("policyComponent")).bindClassBehaviour(
((PolicyComponent)applicationContext.getBean("policyComponent")).bindClassBehaviour(
AsynchronousActionExecutionQueuePolicies.OnAsyncActionExecute.QNAME,
ActionModel.TYPE_ACTION,
new JavaBehaviour(asyncOccurs, "onAsyncActionExecute", NotificationFrequency.EVERY_EVENT)
@@ -233,7 +222,7 @@ public class TaggingServiceImplTest
// We do want action tracking whenever the tag scope updater runs
UpdateTagScopesActionExecuter updateTagsAction =
(UpdateTagScopesActionExecuter)ctx.getBean("update-tagscope");
(UpdateTagScopesActionExecuter)applicationContext.getBean("update-tagscope");
updateTagsAction.setTrackStatus(true);
// Create the folders and documents to be tagged
@@ -733,7 +722,7 @@ public class TaggingServiceImplTest
// return null;
// }
// });
}
}
@Test
@SuppressWarnings("unchecked")
@@ -1760,7 +1749,7 @@ public class TaggingServiceImplTest
@Test
public void test93OnStartupJob() throws Exception
{
final UpdateTagScopesActionExecuter updateTagsAction = (UpdateTagScopesActionExecuter) ctx
final UpdateTagScopesActionExecuter updateTagsAction = (UpdateTagScopesActionExecuter) applicationContext
.getBean("update-tagscope");
class TestData
{
@@ -1935,7 +1924,7 @@ public class TaggingServiceImplTest
logger.debug(Thread.currentThread() + " - About to start tagging for " + tag);
// Do the updates
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getSystemUserName());
RetryingTransactionCallback<Void> txnCallback = new RetryingTransactionCallback<Void>()
{
@Override
@@ -2490,7 +2479,7 @@ public class TaggingServiceImplTest
// STEP5 start job taggingStartupJobDetail
// Fire off the quartz bean, this time it can really work
final UpdateTagScopesActionExecuter updateTagsAction = (UpdateTagScopesActionExecuter) ctx.getBean("update-tagscope");
final UpdateTagScopesActionExecuter updateTagsAction = (UpdateTagScopesActionExecuter) applicationContext.getBean("update-tagscope");
UpdateTagScopesQuartzJob job = new UpdateTagScopesQuartzJob();
job.execute(actionService, updateTagsAction);

View File

@@ -31,8 +31,6 @@ import java.io.StringWriter;
import java.util.HashMap;
import java.util.Map;
import junit.framework.TestCase;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.dictionary.DictionaryComponent;
import org.alfresco.repo.dictionary.DictionaryDAO;
@@ -41,7 +39,6 @@ import org.alfresco.repo.node.BaseNodeServiceTest;
import org.alfresco.repo.security.authentication.AuthenticationComponent;
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.model.FileFolderService;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.repository.StoreRef;
@@ -50,20 +47,18 @@ import org.alfresco.service.cmr.repository.TemplateService;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.alfresco.service.transaction.TransactionService;
import org.alfresco.test_category.OwnJVMTestsCategory;
import org.alfresco.util.ApplicationContextHelper;
import org.junit.experimental.categories.Category;
import org.springframework.context.ApplicationContext;
import org.alfresco.util.BaseSpringTest;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.extensions.surf.util.I18NUtil;
/**
* @author Kevin Roast
*/
@Category(OwnJVMTestsCategory.class)
public class TemplateServiceImplTest extends TestCase
public class TemplateServiceImplTest extends BaseSpringTest
{
private static final String TEMPLATE_1 = "org/alfresco/repo/template/test_template1.ftl";
private static final ApplicationContext ctx = ApplicationContextHelper.getApplicationContext();
private NodeRef root_node;
private TemplateService templateService;
@@ -72,22 +67,18 @@ public class TemplateServiceImplTest extends TestCase
private ServiceRegistry serviceRegistry;
private AuthenticationComponent authenticationComponent;
/*
* @see junit.framework.TestCase#setUp()
*/
protected void setUp() throws Exception
@Before
public void setUp() throws Exception
{
super.setUp();
transactionService = (TransactionService)applicationContext.getBean("transactionComponent");
nodeService = (NodeService)applicationContext.getBean("nodeService");
templateService = (TemplateService)applicationContext.getBean("templateService");
serviceRegistry = (ServiceRegistry)applicationContext.getBean("ServiceRegistry");
transactionService = (TransactionService)ctx.getBean("transactionComponent");
nodeService = (NodeService)ctx.getBean("nodeService");
templateService = (TemplateService)ctx.getBean("templateService");
serviceRegistry = (ServiceRegistry)ctx.getBean("ServiceRegistry");
this.authenticationComponent = (AuthenticationComponent)ctx.getBean("authenticationComponent");
this.authenticationComponent = (AuthenticationComponent)applicationContext.getBean("authenticationComponent");
this.authenticationComponent.setSystemUserAsCurrentUser();
DictionaryDAO dictionaryDao = (DictionaryDAO)ctx.getBean("dictionaryDAO");
DictionaryDAO dictionaryDao = (DictionaryDAO)applicationContext.getBean("dictionaryDAO");
// load the system model
ClassLoader cl = BaseNodeServiceTest.class.getClassLoader();
@@ -104,7 +95,7 @@ public class TemplateServiceImplTest extends TestCase
DictionaryComponent dictionary = new DictionaryComponent();
dictionary.setDictionaryDAO(dictionaryDao);
BaseNodeServiceTest.loadModel(ctx);
BaseNodeServiceTest.loadModel(applicationContext);
transactionService.getRetryingTransactionHelper().doInTransaction(
new RetryingTransactionCallback<Object>()
@@ -142,13 +133,14 @@ public class TemplateServiceImplTest extends TestCase
});
}
@Override
protected void tearDown() throws Exception
@After
public void tearDown() throws Exception
{
authenticationComponent.clearCurrentSecurityContext();
super.tearDown();
}
@Test
public void testTemplates()
{
transactionService.getRetryingTransactionHelper().doInTransaction(
@@ -185,11 +177,13 @@ public class TemplateServiceImplTest extends TestCase
return model;
}
@Test
public void testGetTemplateProcessor()
{
assertNotNull(templateService.getTemplateProcessor(null));
}
@Test
public void testProcessTemplate()
{
Map model = createTemplateModel(root_node);

View File

@@ -25,8 +25,6 @@
*/
package org.alfresco.repo.tenant;
import static org.junit.Assert.*;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
@@ -49,12 +47,11 @@ import org.alfresco.service.cmr.security.PersonService;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.alfresco.service.transaction.TransactionService;
import org.alfresco.util.ApplicationContextHelper;
import org.alfresco.util.BaseSpringTest;
import org.alfresco.util.GUID;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
/**
* A test for MultiTServiceImpl class.
@@ -62,9 +59,8 @@ import org.springframework.context.ApplicationContext;
* @author alex.mukha
* @since 4.2.3
*/
public class MultiTServiceImplTest
public class MultiTServiceImplTest extends BaseSpringTest
{
private static ApplicationContext ctx = ApplicationContextHelper.getApplicationContext();
private MultiTServiceImpl multiTServiceImpl;
private TenantAdminService tenantAdminService;
private PersonService personService;
@@ -112,15 +108,15 @@ public class MultiTServiceImplTest
@Before
public void setUp() throws Exception
{
multiTServiceImpl = ctx.getBean("tenantService", MultiTServiceImpl.class);
tenantAdminService = ctx.getBean("tenantAdminService", TenantAdminService.class);
personService = ctx.getBean("PersonService", PersonService.class);
tenantService = ctx.getBean("tenantService", TenantService.class);
authenticationService = ctx.getBean("AuthenticationService", MutableAuthenticationService.class);
transactionService = ctx.getBean("TransactionService", TransactionService.class);
nodeService = ctx.getBean("NodeService", NodeService.class);
searchService = ctx.getBean("SearchService", SearchService.class);
namespaceService = ctx.getBean("NamespaceService", NamespaceService.class);
multiTServiceImpl = applicationContext.getBean("tenantService", MultiTServiceImpl.class);
tenantAdminService = applicationContext.getBean("tenantAdminService", TenantAdminService.class);
personService = applicationContext.getBean("PersonService", PersonService.class);
tenantService = applicationContext.getBean("tenantService", TenantService.class);
authenticationService = applicationContext.getBean("AuthenticationService", MutableAuthenticationService.class);
transactionService = applicationContext.getBean("TransactionService", TransactionService.class);
nodeService = applicationContext.getBean("NodeService", NodeService.class);
searchService = applicationContext.getBean("SearchService", SearchService.class);
namespaceService = applicationContext.getBean("NamespaceService", NamespaceService.class);
DOMAIN = GUID.generate();
USER1 = GUID.generate();
@@ -920,7 +916,7 @@ public class MultiTServiceImplTest
// TODO: WARNING: HACK for ALF-19155: MT deleteTenant does not work
// PersonService prevents 'guest' authorities from being deleted
{
BehaviourFilter behaviourFilter = (BehaviourFilter) ctx.getBean("policyBehaviourFilter");
BehaviourFilter behaviourFilter = (BehaviourFilter) applicationContext.getBean("policyBehaviourFilter");
behaviourFilter.disableBehaviour(ContentModel.TYPE_PERSON);
behaviourFilter.disableBehaviour(ContentModel.ASPECT_UNDELETABLE);
}

View File

@@ -31,40 +31,35 @@ import java.util.Map;
import javax.transaction.UserTransaction;
import junit.framework.TestCase;
import org.alfresco.repo.transaction.AlfrescoTransactionSupport.TxnReadState;
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.transaction.TransactionService;
import org.alfresco.test_category.OwnJVMTestsCategory;
import org.alfresco.util.ApplicationContextHelper;
import org.junit.experimental.categories.Category;
import org.springframework.context.ApplicationContext;
import org.alfresco.util.BaseSpringTest;
import org.junit.Before;
import org.junit.Test;
/**
* Tests integration between our <tt>UserTransaction</tt> implementation and
* our <tt>TransactionManager</tt>.
*
* @see org.alfresco.repo.transaction.AlfrescoTransactionManager
* @see org.alfresco.util.transaction.SpringAwareUserTransaction
*
* @author Derek Hulley
*/
@Category(OwnJVMTestsCategory.class)
public class AlfrescoTransactionSupportTest extends TestCase
public class AlfrescoTransactionSupportTest extends BaseSpringTest
{
private static ApplicationContext ctx = ApplicationContextHelper.getApplicationContext();
private ServiceRegistry serviceRegistry;
TransactionService transactionService;
@Before
public void setUp() throws Exception
{
serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);
serviceRegistry = (ServiceRegistry) applicationContext.getBean(ServiceRegistry.SERVICE_REGISTRY);
transactionService = serviceRegistry.getTransactionService();
}
@Test
public void testTransactionId() throws Exception
{
// get a user transaction
@@ -127,6 +122,7 @@ public class AlfrescoTransactionSupportTest extends TestCase
assertNull("Thread shouldn't have a txn ID after rollback", AlfrescoTransactionSupport.getTransactionId());
}
@Test
public void testListener() throws Exception
{
final List<String> strings = new ArrayList<String>(1);
@@ -175,6 +171,7 @@ public class AlfrescoTransactionSupportTest extends TestCase
assertTrue("afterCommit not called on listener", strings.contains("afterCommit"));
}
@Test
public void testListenerNew() throws Exception
{
final List<String> strings = new ArrayList<String>(1);
@@ -223,6 +220,7 @@ public class AlfrescoTransactionSupportTest extends TestCase
* the transaction in the pre-commit callback. This is caused by the listener set being
* modified during calls to the listeners.
*/
@Test
public void testPreCommitListenerBinding() throws Exception
{
final String beforeCommit = "beforeCommit";
@@ -291,6 +289,7 @@ public class AlfrescoTransactionSupportTest extends TestCase
assertTrue("Expected callbacks not all processed: " + testList, testList.size() == 0);
}
@Test
public void testReadWriteStateRetrieval() throws Exception
{
final TxnReadState[] postCommitReadState = new TxnReadState[1];
@@ -348,6 +347,7 @@ public class AlfrescoTransactionSupportTest extends TestCase
assertEquals("Expected 'no transaction'", TxnReadState.TXN_NONE, postCommitReadState[0]);
}
@Test
public void testResourceHelper() throws Exception
{
// start a transaction

View File

@@ -37,7 +37,6 @@ import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import javax.transaction.Status;
import javax.transaction.UserTransaction;
import junit.framework.TestCase;
import org.alfresco.error.ExceptionStackUtil;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.domain.dialect.Dialect;
@@ -55,15 +54,16 @@ import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.alfresco.service.transaction.TransactionService;
import org.alfresco.test_category.OwnJVMTestsCategory;
import org.alfresco.util.ApplicationContextHelper;
import org.alfresco.util.BaseSpringTest;
import org.alfresco.util.GUID;
import org.alfresco.util.Pair;
import org.alfresco.util.transaction.TransactionListenerAdapter;
import org.apache.commons.lang.mutable.MutableInt;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.experimental.categories.Category;
import org.springframework.context.ApplicationContext;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.dao.ConcurrencyFailureException;
/**
@@ -75,15 +75,12 @@ import org.springframework.dao.ConcurrencyFailureException;
* @author Derek Hulley
* @since 2.1
*/
@Category(OwnJVMTestsCategory.class)
public class RetryingTransactionHelperTest extends TestCase
public class RetryingTransactionHelperTest extends BaseSpringTest
{
private static Log logger = LogFactory.getLog("org.alfresco.repo.transaction.RetryingTransactionHelperTest");
private static final QName PROP_CHECK_VALUE = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "check_value");
private static ApplicationContext ctx = ApplicationContextHelper.getApplicationContext();
private ServiceRegistry serviceRegistry;
private AuthenticationComponent authenticationComponent;
private TransactionService transactionService;
@@ -95,13 +92,13 @@ public class RetryingTransactionHelperTest extends TestCase
private NodeRef rootNodeRef;
private NodeRef workingNodeRef;
@Override
@Before
public void setUp() throws Exception
{
dialect = (Dialect) ctx.getBean("dialect");
dialect = (Dialect) applicationContext.getBean("dialect");
serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);
authenticationComponent = (AuthenticationComponent) ctx.getBean("authenticationComponent");
serviceRegistry = (ServiceRegistry) applicationContext.getBean(ServiceRegistry.SERVICE_REGISTRY);
authenticationComponent = (AuthenticationComponent) applicationContext.getBean("authenticationComponent");
transactionService = serviceRegistry.getTransactionService();
nodeService = serviceRegistry.getNodeService();
txnHelper = transactionService.getRetryingTransactionHelper();
@@ -111,22 +108,23 @@ public class RetryingTransactionHelperTest extends TestCase
StoreRef storeRef = nodeService.createStore(
StoreRef.PROTOCOL_WORKSPACE,
"test-" + getName() + "-" + System.currentTimeMillis());
"test-" + System.currentTimeMillis());
rootNodeRef = nodeService.getRootNode(storeRef);
// Create a node to work on
workingNodeRef = nodeService.createNode(
rootNodeRef,
ContentModel.ASSOC_CHILDREN,
QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, getName()),
QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, GUID.generate()),
ContentModel.TYPE_CMOBJECT).getChildRef();
}
@Override
@After
public void tearDown() throws Exception
{
try { authenticationComponent.clearCurrentSecurityContext(); } catch (Throwable e) {}
}
@Test
public void testSetUp() throws Exception
{
assertNotNull(rootNodeRef);
@@ -177,6 +175,7 @@ public class RetryingTransactionHelperTest extends TestCase
/**
* Check that it works without complications.
*/
@Test
public void testSuccessNoRetry()
{
long beforeValue = getCheckValue();
@@ -198,6 +197,7 @@ public class RetryingTransactionHelperTest extends TestCase
* This also checks that any mischievous attempts to manipulate the transaction
* (other than setRollback) are detected.
*/
@Test
public void testUserTransactionStatus()
{
UserTransaction txnBefore = RetryingTransactionHelper.getActiveUserTransaction();
@@ -251,6 +251,7 @@ public class RetryingTransactionHelperTest extends TestCase
/**
* Check that the retries happening for simple concurrency exceptions
*/
@Test
public void testSuccessWithRetry()
{
RetryingTransactionCallback<Long> callback = new RetryingTransactionCallback<Long>()
@@ -278,6 +279,7 @@ public class RetryingTransactionHelperTest extends TestCase
/**
* Checks that a non-retrying exception is passed out and that the transaction is rolled back.
*/
@Test
public void testNonRetryingFailure()
{
RetryingTransactionCallback<Long> callback = new RetryingTransactionCallback<Long>()
@@ -312,6 +314,7 @@ public class RetryingTransactionHelperTest extends TestCase
* absorbed and that another isn't generated, but that the transaction was rolled back
* properly.
*/
@Test
public void testNonRetryingSilentRollback()
{
RetryingTransactionCallback<Long> callback = new RetryingTransactionCallback<Long>()
@@ -338,6 +341,7 @@ public class RetryingTransactionHelperTest extends TestCase
/**
* Checks nesting of two transactions with <code>requiresNew == false</code>
*/
@Test
public void testNestedWithPropagation()
{
RetryingTransactionCallback<Long> callback = new RetryingTransactionCallback<Long>()
@@ -366,6 +370,7 @@ public class RetryingTransactionHelperTest extends TestCase
/**
* Checks nesting of two transactions with <code>requiresNew == true</code>
*/
@Test
public void testNestedWithoutPropagation()
{
RetryingTransactionCallback<Long> callback = new RetryingTransactionCallback<Long>()
@@ -397,6 +402,7 @@ public class RetryingTransactionHelperTest extends TestCase
* <p/>
* Note: skip test for non-MySQL
*/
@Test
public void testNestedWithoutPropagationConcurrentUntilFailureMySQL() throws InterruptedException
{
final RetryingTransactionHelper txnHelperForTest = transactionService.getRetryingTransactionHelper();
@@ -441,6 +447,7 @@ public class RetryingTransactionHelperTest extends TestCase
}
}
@Test
public void testConcurrencyRetryingNoFailure() throws InterruptedException
{
Thread t1 = new Thread(new ConcurrentTransaction(5000));
@@ -497,6 +504,7 @@ public class RetryingTransactionHelperTest extends TestCase
}
}
@Test
public void testZeroAndNegativeRetries()
{
final MutableInt callCount = new MutableInt(0);
@@ -536,6 +544,7 @@ public class RetryingTransactionHelperTest extends TestCase
}
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testTimeLimit()
{
final RetryingTransactionHelper txnHelper = new RetryingTransactionHelper();
@@ -557,6 +566,7 @@ public class RetryingTransactionHelperTest extends TestCase
}
}
@Test
public void testALF_17631()
{
final MutableInt callCount = new MutableInt(0);
@@ -598,6 +608,7 @@ public class RetryingTransactionHelperTest extends TestCase
}
@Test
public void testForceWritable() throws Exception
{
authenticationComponent.setCurrentUser(AuthenticationUtil.getAdminUserName());
@@ -670,6 +681,7 @@ public class RetryingTransactionHelperTest extends TestCase
}
}
@Test
public void testStartNewTransaction() throws Exception
{
// MNT-10096

View File

@@ -29,24 +29,19 @@ import java.util.Random;
import javax.transaction.UserTransaction;
import junit.framework.TestCase;
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
import org.alfresco.service.transaction.TransactionService;
import org.alfresco.test_category.OwnJVMTestsCategory;
import org.alfresco.util.ApplicationContextHelper;
import org.junit.experimental.categories.Category;
import org.springframework.context.ApplicationContext;
import org.alfresco.util.BaseSpringTest;
import org.junit.Before;
import org.junit.Test;
/**
* @see org.alfresco.repo.transaction.TransactionAwareSingleton
*
* @author Derek Hulley
*/
@Category(OwnJVMTestsCategory.class)
public class TransactionAwareSingletonTest extends TestCase
public class TransactionAwareSingletonTest extends BaseSpringTest
{
private static ApplicationContext ctx = ApplicationContextHelper.getApplicationContext();
private static Random rand = new Random();
/** the instance to test */
@@ -56,11 +51,13 @@ public class TransactionAwareSingletonTest extends TestCase
private TransactionService transactionService;
@Before
public void setUp() throws Exception
{
transactionService = (TransactionService) ctx.getBean("transactionComponent");
transactionService = (TransactionService) applicationContext.getBean("transactionComponent");
}
@Test
public void testCommit() throws Throwable
{
UserTransaction txn = transactionService.getUserTransaction();
@@ -84,6 +81,7 @@ public class TransactionAwareSingletonTest extends TestCase
check(INTEGER_ONE, false);
}
@Test
public void testRollback() throws Throwable
{
UserTransaction txn = transactionService.getUserTransaction();
@@ -108,6 +106,7 @@ public class TransactionAwareSingletonTest extends TestCase
}
private static final int THREAD_COUNT = 20;
@Test
public void testThreadsCommit() throws Throwable
{
TestThread[] threads = new TestThread[THREAD_COUNT];
@@ -133,6 +132,7 @@ public class TransactionAwareSingletonTest extends TestCase
}
}
}
@Test
public void testThreadsRollback() throws Throwable
{
TestThread[] threads = new TestThread[THREAD_COUNT];

View File

@@ -47,7 +47,10 @@ import org.alfresco.service.namespace.QName;
import org.alfresco.service.transaction.ReadOnlyServerException;
import org.alfresco.test_category.OwnJVMTestsCategory;
import org.alfresco.util.ApplicationContextHelper;
import org.alfresco.util.BaseSpringTest;
import org.alfresco.util.PropertyMap;
import org.junit.Before;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.springframework.context.ApplicationContext;
import org.springframework.dao.InvalidDataAccessApiUsageException;
@@ -60,11 +63,8 @@ import org.springframework.transaction.PlatformTransactionManager;
*
* @author Derek Hulley
*/
@Category(OwnJVMTestsCategory.class)
public class TransactionServiceImplTest extends TestCase
public class TransactionServiceImplTest extends BaseSpringTest
{
private static ApplicationContext ctx = ApplicationContextHelper.getApplicationContext();
private PlatformTransactionManager transactionManager;
private TransactionServiceImpl transactionService;
private NodeService nodeService;
@@ -76,20 +76,22 @@ public class TransactionServiceImplTest extends TestCase
private Dialect dialect;
@Before
public void setUp() throws Exception
{
transactionManager = (PlatformTransactionManager) ctx.getBean("transactionManager");
transactionManager = (PlatformTransactionManager) applicationContext.getBean("transactionManager");
transactionService = new TransactionServiceImpl();
transactionService.setTransactionManager(transactionManager);
transactionService.setAllowWrite(true, vetoName);
nodeService = (NodeService) ctx.getBean("dbNodeService");
authenticationService = (MutableAuthenticationService) ctx.getBean("AuthenticationService");
personService = (PersonService) ctx.getBean("PersonService");
nodeService = (NodeService) applicationContext.getBean("dbNodeService");
authenticationService = (MutableAuthenticationService) applicationContext.getBean("AuthenticationService");
personService = (PersonService) applicationContext.getBean("PersonService");
dialect = (Dialect) ctx.getBean("dialect");
dialect = (Dialect) applicationContext.getBean("dialect");
}
@Test
public void testPropagatingTxn() throws Exception
{
// start a transaction
@@ -124,6 +126,7 @@ public class TransactionServiceImplTest extends TestCase
}
}
@Test
public void testNonPropagatingTxn() throws Exception
{
// start a transaction
@@ -146,6 +149,7 @@ public class TransactionServiceImplTest extends TestCase
txnOuter.commit();
}
@Test
public void testReadOnlyTxn() throws Exception
{
// start a read-only transaction
@@ -218,6 +222,7 @@ public class TransactionServiceImplTest extends TestCase
* Test the write veto
* @throws Exception
*/
@Test
public void testReadOnlyVetoTxn() throws Exception
{
@@ -254,6 +259,7 @@ public class TransactionServiceImplTest extends TestCase
}
}
@Test
public void testGetRetryingTransactionHelper()
{
RetryingTransactionCallback<Object> callback = new RetryingTransactionCallback<Object>()
@@ -268,7 +274,7 @@ public class TransactionServiceImplTest extends TestCase
assertFalse("Retriers must be new instances",
transactionService.getRetryingTransactionHelper() == transactionService.getRetryingTransactionHelper());
// The same must apply when using the ServiceRegistry (ALF-18718)
ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);
ServiceRegistry serviceRegistry = (ServiceRegistry) applicationContext.getBean(ServiceRegistry.SERVICE_REGISTRY);
assertFalse("Retriers must be new instance when retrieved from ServiceRegistry",
serviceRegistry.getRetryingTransactionHelper() == serviceRegistry.getRetryingTransactionHelper());
@@ -300,7 +306,7 @@ public class TransactionServiceImplTest extends TestCase
private void createUser(String userName)
{
// login as system user to create test user
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getSystemUserName());
// if user with given user name doesn't already exist then create user
if (!this.authenticationService.authenticationExists(userName))
{
@@ -322,6 +328,7 @@ public class TransactionServiceImplTest extends TestCase
AuthenticationUtil.clearCurrentSecurityContext();
}
@Test
public void testSystemUserHasWritePermissionsInReadOnlyMode()
{
createUser(USER_ALFRESCO);