mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-10-08 14:51:49 +00:00
Move RM 2.2 dependency to 4.2.2-SNAPSHOT
* fix issues so that RM 2.2 is still backwards compatible with 4.2.1 (and 4.2.0) * added 'bean extender' .. a post processor bean that allows us to extend, rather than overrite, core bean definitions. Gives us a technique we can use that won't be disrupted when changes are made to core bean definitions. * unit test for above * tested with 4.2.2-SNAPSHOT and 4.2.1 git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@68290 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
2
pom.xml
2
pom.xml
@@ -66,7 +66,7 @@
|
|||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<alfresco.base.version>4.2.1</alfresco.base.version>
|
<alfresco.base.version>4.2.2-SNAPSHOT</alfresco.base.version>
|
||||||
|
|
||||||
<!-- Database properties - default values to be overridden in settings.xml -->
|
<!-- Database properties - default values to be overridden in settings.xml -->
|
||||||
<db.driver>org.postgresql.Driver</db.driver>
|
<db.driver>org.postgresql.Driver</db.driver>
|
||||||
|
@@ -3,8 +3,11 @@
|
|||||||
|
|
||||||
<beans>
|
<beans>
|
||||||
|
|
||||||
|
<!-- Ensure backwards compatibility with 4.2 and 4.2.1 -->
|
||||||
|
<bean class="org.alfresco.module.org_alfresco_module_rm.model.compatibility.DictionaryBootstrapPostProcessor"/>
|
||||||
|
|
||||||
<!-- Bootstrap Records Management Models -->
|
<!-- Bootstrap Records Management Models -->
|
||||||
<bean id="org_alfresco_module_rm_dictionaryBootstrap" parent="dictionaryModelBootstrap" depends-on="siteService_dictionaryBootstrap">
|
<bean id="org_alfresco_module_rm_dictionaryBootstrap" parent="dictionaryModelBootstrap">
|
||||||
<property name="models">
|
<property name="models">
|
||||||
<list>
|
<list>
|
||||||
<value>alfresco/module/org_alfresco_module_rm/model/recordsModel.xml</value>
|
<value>alfresco/module/org_alfresco_module_rm/model/recordsModel.xml</value>
|
||||||
|
@@ -3,14 +3,20 @@
|
|||||||
|
|
||||||
<beans>
|
<beans>
|
||||||
|
|
||||||
<bean id="jsonConversionComponent"
|
<!-- extending bean definition -->
|
||||||
class="org.alfresco.module.org_alfresco_module_rm.jscript.app.JSONConversionComponent"
|
<bean id="rm.jsonConversionComponent" class="org.alfresco.module.org_alfresco_module_rm.jscript.app.JSONConversionComponent"
|
||||||
parent="baseJsonConversionComponent">
|
parent="baseJsonConversionComponent">
|
||||||
<property name="recordService" ref="RecordService"/>
|
<property name="recordService" ref="RecordService"/>
|
||||||
<property name="filePlanService" ref="FilePlanService"/>
|
<property name="filePlanService" ref="FilePlanService"/>
|
||||||
<property name="capabilityService" ref="CapabilityService"/>
|
<property name="capabilityService" ref="CapabilityService"/>
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
|
<!-- extends core bean with RM extensions -->
|
||||||
|
<bean class="org.alfresco.module.org_alfresco_module_rm.util.BeanExtender">
|
||||||
|
<property name="beanName" value="jsonConversionComponent" />
|
||||||
|
<property name="extendingBeanName" value="rm.jsonConversionComponent" />
|
||||||
|
</bean>
|
||||||
|
|
||||||
<bean id="jsonConversionComponent.baseEvaluator"
|
<bean id="jsonConversionComponent.baseEvaluator"
|
||||||
abstract="true">
|
abstract="true">
|
||||||
<property name="jsonConversionComponent" ref="jsonConversionComponent"/>
|
<property name="jsonConversionComponent" ref="jsonConversionComponent"/>
|
||||||
|
@@ -0,0 +1,40 @@
|
|||||||
|
package org.alfresco.module.org_alfresco_module_rm.model.compatibility;
|
||||||
|
|
||||||
|
import org.springframework.beans.BeansException;
|
||||||
|
import org.springframework.beans.factory.config.BeanDefinition;
|
||||||
|
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
|
||||||
|
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dictionary bootstap post processor.
|
||||||
|
* <p>
|
||||||
|
* Ensures compatibility with 4.2 and 4.2.1 as well as 4.2.2.
|
||||||
|
*
|
||||||
|
* @author Roy Wetherall
|
||||||
|
* @since 2.2
|
||||||
|
*/
|
||||||
|
public class DictionaryBootstrapPostProcessor implements BeanFactoryPostProcessor
|
||||||
|
{
|
||||||
|
/** bean id's */
|
||||||
|
private static final String BEAN_SITESERVICE_BOOTSTRAP = "siteService_dictionaryBootstrap";
|
||||||
|
private static final String BEAN_RM_DICTIONARY_BOOTSTRAP = "org_alfresco_module_rm_dictionaryBootstrap";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.springframework.beans.factory.config.BeanFactoryPostProcessor#postProcessBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException
|
||||||
|
{
|
||||||
|
// if the site service bootstrap bean and the RM dictionary bean are present in the bean factory
|
||||||
|
if (beanFactory.containsBean(BEAN_SITESERVICE_BOOTSTRAP) &&
|
||||||
|
beanFactory.containsBean(BEAN_RM_DICTIONARY_BOOTSTRAP))
|
||||||
|
{
|
||||||
|
// get the RM dictionary bootstrap bean definition
|
||||||
|
BeanDefinition beanDef = beanFactory.getBeanDefinition(BEAN_RM_DICTIONARY_BOOTSTRAP);
|
||||||
|
|
||||||
|
// set the dependency
|
||||||
|
beanDef.setDependsOn(new String[]{BEAN_SITESERVICE_BOOTSTRAP});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -825,7 +825,7 @@ public class RecordServiceImpl extends BaseBehaviourBean
|
|||||||
ParameterCheck.mandatory("name", name);
|
ParameterCheck.mandatory("name", name);
|
||||||
|
|
||||||
NodeRef destination = nodeRef;
|
NodeRef destination = nodeRef;
|
||||||
if (filePlanService.isFilePlan(nodeRef))
|
if (isFilePlan(nodeRef))
|
||||||
{
|
{
|
||||||
// get the unfiled record container for the file plan
|
// get the unfiled record container for the file plan
|
||||||
destination = filePlanService.getUnfiledContainer(nodeRef);
|
destination = filePlanService.getUnfiledContainer(nodeRef);
|
||||||
@@ -1144,7 +1144,7 @@ public class RecordServiceImpl extends BaseBehaviourBean
|
|||||||
}
|
}
|
||||||
|
|
||||||
// DEBUG ...
|
// DEBUG ...
|
||||||
NodeRef filePlan = filePlanService.getFilePlan(record);
|
NodeRef filePlan = getFilePlan(record);
|
||||||
Set<Role> roles = filePlanRoleService.getRolesByUser(filePlan, AuthenticationUtil.getRunAsUser());
|
Set<Role> roles = filePlanRoleService.getRolesByUser(filePlan, AuthenticationUtil.getRunAsUser());
|
||||||
|
|
||||||
if (logger.isDebugEnabled())
|
if (logger.isDebugEnabled())
|
||||||
|
@@ -0,0 +1,103 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2005-2014 Alfresco Software Limited.
|
||||||
|
*
|
||||||
|
* This file is part of Alfresco
|
||||||
|
*
|
||||||
|
* Alfresco is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Alfresco is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package org.alfresco.module.org_alfresco_module_rm.util;
|
||||||
|
|
||||||
|
import org.alfresco.util.ParameterCheck;
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
import org.springframework.beans.BeansException;
|
||||||
|
import org.springframework.beans.MutablePropertyValues;
|
||||||
|
import org.springframework.beans.PropertyValue;
|
||||||
|
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||||
|
import org.springframework.beans.factory.config.BeanDefinition;
|
||||||
|
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
|
||||||
|
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extends the definition of a bean with another.
|
||||||
|
* <p>
|
||||||
|
* Implements bean factory post processor.
|
||||||
|
*
|
||||||
|
* @author Roy Wetherall
|
||||||
|
* @since 2.2
|
||||||
|
*/
|
||||||
|
public class BeanExtender implements BeanFactoryPostProcessor
|
||||||
|
{
|
||||||
|
/** name of bean to extend */
|
||||||
|
private String beanName;
|
||||||
|
|
||||||
|
/** extending bean name */
|
||||||
|
private String extendingBeanName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param beanName bean name
|
||||||
|
*/
|
||||||
|
public void setBeanName(String beanName)
|
||||||
|
{
|
||||||
|
this.beanName = beanName;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param extendingBeanName extending bean name
|
||||||
|
*/
|
||||||
|
public void setExtendingBeanName(String extendingBeanName)
|
||||||
|
{
|
||||||
|
this.extendingBeanName = extendingBeanName;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.springframework.beans.factory.config.BeanFactoryPostProcessor#postProcessBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException
|
||||||
|
{
|
||||||
|
ParameterCheck.mandatory("beanName", beanName);
|
||||||
|
ParameterCheck.mandatory("extendingBeanName", extendingBeanName);
|
||||||
|
|
||||||
|
// check for bean name
|
||||||
|
if (!beanFactory.containsBean(beanName))
|
||||||
|
{
|
||||||
|
throw new NoSuchBeanDefinitionException("Can't find bean '" + beanName + "' to be extended.");
|
||||||
|
}
|
||||||
|
|
||||||
|
// check for extending bean
|
||||||
|
if (!beanFactory.containsBean(extendingBeanName))
|
||||||
|
{
|
||||||
|
throw new NoSuchBeanDefinitionException("Can't find bean '" + extendingBeanName + "' that is going to extend origional bean definition.");
|
||||||
|
}
|
||||||
|
|
||||||
|
// get the bean definitions
|
||||||
|
BeanDefinition beanDefinition = beanFactory.getBeanDefinition(beanName);
|
||||||
|
BeanDefinition extendingBeanDefinition = beanFactory.getBeanDefinition(extendingBeanName);
|
||||||
|
|
||||||
|
// update class
|
||||||
|
if (StringUtils.isNotBlank(extendingBeanDefinition.getBeanClassName()) &&
|
||||||
|
!beanDefinition.getBeanClassName().equals(extendingBeanDefinition.getBeanClassName()))
|
||||||
|
{
|
||||||
|
beanDefinition.setBeanClassName(extendingBeanDefinition.getBeanClassName());
|
||||||
|
}
|
||||||
|
|
||||||
|
// update properties
|
||||||
|
MutablePropertyValues properties = beanDefinition.getPropertyValues();
|
||||||
|
MutablePropertyValues extendingProperties = extendingBeanDefinition.getPropertyValues();
|
||||||
|
for (PropertyValue propertyValue : extendingProperties.getPropertyValueList())
|
||||||
|
{
|
||||||
|
properties.add(propertyValue.getName(), propertyValue.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2005-2011 Alfresco Software Limited.
|
* Copyright (C) 2005-2014 Alfresco Software Limited.
|
||||||
*
|
*
|
||||||
* This file is part of Alfresco
|
* This file is part of Alfresco
|
||||||
*
|
*
|
||||||
|
@@ -100,7 +100,7 @@ public class FileReportActionUnitTest extends BaseUnitTest
|
|||||||
// == when ==
|
// == when ==
|
||||||
|
|
||||||
// execute action
|
// execute action
|
||||||
fileReportAction.execute(mockedAction, actionedUponNodeRef);
|
fileReportAction.executeImpl(mockedAction, actionedUponNodeRef);
|
||||||
|
|
||||||
// == then ==
|
// == then ==
|
||||||
verifyZeroInteractions(mockedReportService, mockedNodeService);
|
verifyZeroInteractions(mockedReportService, mockedNodeService);
|
||||||
@@ -124,7 +124,7 @@ public class FileReportActionUnitTest extends BaseUnitTest
|
|||||||
// == when ==
|
// == when ==
|
||||||
|
|
||||||
// execute action
|
// execute action
|
||||||
fileReportAction.execute(mockedAction, actionedUponNodeRef);
|
fileReportAction.executeImpl(mockedAction, actionedUponNodeRef);
|
||||||
|
|
||||||
// == then ==
|
// == then ==
|
||||||
verifyZeroInteractions(mockedReportService, mockedNodeService);
|
verifyZeroInteractions(mockedReportService, mockedNodeService);
|
||||||
@@ -159,7 +159,7 @@ public class FileReportActionUnitTest extends BaseUnitTest
|
|||||||
// == when ==
|
// == when ==
|
||||||
|
|
||||||
// execute action
|
// execute action
|
||||||
fileReportAction.execute(mockedAction, actionedUponNodeRef);
|
fileReportAction.executeImpl(mockedAction, actionedUponNodeRef);
|
||||||
|
|
||||||
// == then ==
|
// == then ==
|
||||||
|
|
||||||
@@ -198,7 +198,7 @@ public class FileReportActionUnitTest extends BaseUnitTest
|
|||||||
// == when ==
|
// == when ==
|
||||||
|
|
||||||
// execute action
|
// execute action
|
||||||
fileReportAction.execute(mockedAction, actionedUponNodeRef);
|
fileReportAction.executeImpl(mockedAction, actionedUponNodeRef);
|
||||||
|
|
||||||
// == then ==
|
// == then ==
|
||||||
|
|
||||||
|
@@ -0,0 +1,96 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2005-2014 Alfresco Software Limited.
|
||||||
|
*
|
||||||
|
* This file is part of Alfresco
|
||||||
|
*
|
||||||
|
* Alfresco is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Alfresco is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package org.alfresco.module.org_alfresco_module_rm.model.compatibility;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.doReturn;
|
||||||
|
import static org.mockito.Mockito.verifyZeroInteractions;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
|
import static org.mockito.Mockito.times;
|
||||||
|
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||||
|
|
||||||
|
import org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.mockito.InjectMocks;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import org.springframework.beans.factory.config.BeanDefinition;
|
||||||
|
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dictionary bootstrap post processor unit test.
|
||||||
|
*
|
||||||
|
* @author Roy Wetherall
|
||||||
|
* @since 2.2
|
||||||
|
*/
|
||||||
|
public class DictionaryBootstrapPostProcessorUnitTest extends BaseUnitTest
|
||||||
|
{
|
||||||
|
/** bean id's */
|
||||||
|
private static final String BEAN_SITESERVICE_BOOTSTRAP = "siteService_dictionaryBootstrap";
|
||||||
|
private static final String BEAN_RM_DICTIONARY_BOOTSTRAP = "org_alfresco_module_rm_dictionaryBootstrap";
|
||||||
|
|
||||||
|
@Mock private ConfigurableListableBeanFactory mockedBeanFactory;
|
||||||
|
@Mock private BeanDefinition mockedBeanDefinition;
|
||||||
|
|
||||||
|
@InjectMocks private DictionaryBootstrapPostProcessor postProcessor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* given the bean factory does not contain the site service bootstrap bean then ensure that it is
|
||||||
|
* not added as a dependency
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void noSiteServiceBootstrapBeanAvailable()
|
||||||
|
{
|
||||||
|
// === given ====
|
||||||
|
doReturn(false).when(mockedBeanFactory).containsBean(BEAN_SITESERVICE_BOOTSTRAP);
|
||||||
|
|
||||||
|
// === when ===
|
||||||
|
postProcessor.postProcessBeanFactory(mockedBeanFactory);
|
||||||
|
|
||||||
|
// === then ===
|
||||||
|
verify(mockedBeanFactory, times(1)).containsBean(BEAN_SITESERVICE_BOOTSTRAP);
|
||||||
|
verifyNoMoreInteractions(mockedBeanFactory);
|
||||||
|
verifyZeroInteractions(mockedBeanDefinition);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* given that the site service bootstrap bean is contained within the bean factory, ensure that
|
||||||
|
* it is added as a dependency
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void siteServiceBootstrapBeanAvailable()
|
||||||
|
{
|
||||||
|
// === given ====
|
||||||
|
doReturn(true).when(mockedBeanFactory).containsBean(BEAN_SITESERVICE_BOOTSTRAP);
|
||||||
|
doReturn(true).when(mockedBeanFactory).containsBean(BEAN_RM_DICTIONARY_BOOTSTRAP);
|
||||||
|
doReturn(mockedBeanDefinition).when(mockedBeanFactory).getBeanDefinition(BEAN_RM_DICTIONARY_BOOTSTRAP);
|
||||||
|
|
||||||
|
// === when ===
|
||||||
|
postProcessor.postProcessBeanFactory(mockedBeanFactory);
|
||||||
|
|
||||||
|
// === then ===
|
||||||
|
verify(mockedBeanFactory, times(1)).containsBean(BEAN_SITESERVICE_BOOTSTRAP);
|
||||||
|
verify(mockedBeanFactory, times(1)).containsBean(BEAN_RM_DICTIONARY_BOOTSTRAP);
|
||||||
|
|
||||||
|
verify(mockedBeanFactory, times(1)).getBeanDefinition(BEAN_RM_DICTIONARY_BOOTSTRAP);
|
||||||
|
verify(mockedBeanDefinition, times(1)).setDependsOn(new String[]{BEAN_SITESERVICE_BOOTSTRAP});
|
||||||
|
|
||||||
|
verifyNoMoreInteractions(mockedBeanFactory, mockedBeanDefinition);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@@ -25,12 +25,14 @@ import org.alfresco.module.org_alfresco_module_rm.hold.HoldServiceImplUnitTest;
|
|||||||
import org.alfresco.module.org_alfresco_module_rm.job.DispositionLifecycleJobExecuterUnitTest;
|
import org.alfresco.module.org_alfresco_module_rm.job.DispositionLifecycleJobExecuterUnitTest;
|
||||||
import org.alfresco.module.org_alfresco_module_rm.jscript.app.evaluator.FrozenEvaluatorUnitTest;
|
import org.alfresco.module.org_alfresco_module_rm.jscript.app.evaluator.FrozenEvaluatorUnitTest;
|
||||||
import org.alfresco.module.org_alfresco_module_rm.jscript.app.evaluator.TransferEvaluatorUnitTest;
|
import org.alfresco.module.org_alfresco_module_rm.jscript.app.evaluator.TransferEvaluatorUnitTest;
|
||||||
|
import org.alfresco.module.org_alfresco_module_rm.model.compatibility.DictionaryBootstrapPostProcessorUnitTest;
|
||||||
import org.alfresco.module.org_alfresco_module_rm.record.RecordMetadataBootstrapUnitTest;
|
import org.alfresco.module.org_alfresco_module_rm.record.RecordMetadataBootstrapUnitTest;
|
||||||
import org.alfresco.module.org_alfresco_module_rm.record.RecordServiceImplUnitTest;
|
import org.alfresco.module.org_alfresco_module_rm.record.RecordServiceImplUnitTest;
|
||||||
import org.alfresco.module.org_alfresco_module_rm.script.hold.HoldPostUnitTest;
|
import org.alfresco.module.org_alfresco_module_rm.script.hold.HoldPostUnitTest;
|
||||||
import org.alfresco.module.org_alfresco_module_rm.script.hold.HoldPutUnitTest;
|
import org.alfresco.module.org_alfresco_module_rm.script.hold.HoldPutUnitTest;
|
||||||
import org.alfresco.module.org_alfresco_module_rm.script.hold.HoldsGetUnitTest;
|
import org.alfresco.module.org_alfresco_module_rm.script.hold.HoldsGetUnitTest;
|
||||||
import org.alfresco.module.org_alfresco_module_rm.security.FilePlanPermissionServiceImplUnitTest;
|
import org.alfresco.module.org_alfresco_module_rm.security.FilePlanPermissionServiceImplUnitTest;
|
||||||
|
import org.alfresco.module.org_alfresco_module_rm.util.BeanExtenderUnitTest;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.junit.runners.Suite;
|
import org.junit.runners.Suite;
|
||||||
import org.junit.runners.Suite.SuiteClasses;
|
import org.junit.runners.Suite.SuiteClasses;
|
||||||
@@ -47,6 +49,8 @@ import org.junit.runners.Suite.SuiteClasses;
|
|||||||
RecordMetadataBootstrapUnitTest.class,
|
RecordMetadataBootstrapUnitTest.class,
|
||||||
RecordsManagementTypeFormFilterUnitTest.class,
|
RecordsManagementTypeFormFilterUnitTest.class,
|
||||||
DispositionLifecycleJobExecuterUnitTest.class,
|
DispositionLifecycleJobExecuterUnitTest.class,
|
||||||
|
DictionaryBootstrapPostProcessorUnitTest.class,
|
||||||
|
BeanExtenderUnitTest.class,
|
||||||
|
|
||||||
// services
|
// services
|
||||||
RecordServiceImplUnitTest.class,
|
RecordServiceImplUnitTest.class,
|
||||||
|
@@ -0,0 +1,245 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2005-2011 Alfresco Software Limited.
|
||||||
|
*
|
||||||
|
* This file is part of Alfresco
|
||||||
|
*
|
||||||
|
* Alfresco is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Alfresco is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package org.alfresco.module.org_alfresco_module_rm.util;
|
||||||
|
|
||||||
|
import static org.mockito.Matchers.anyString;
|
||||||
|
import static org.mockito.Mockito.doReturn;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.never;
|
||||||
|
import static org.mockito.Mockito.times;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest;
|
||||||
|
import org.alfresco.util.GUID;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.mockito.InjectMocks;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import org.springframework.beans.MutablePropertyValues;
|
||||||
|
import org.springframework.beans.PropertyValue;
|
||||||
|
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||||
|
import org.springframework.beans.factory.config.BeanDefinition;
|
||||||
|
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bean extender unit test.
|
||||||
|
*
|
||||||
|
* @author Roy Wetherall
|
||||||
|
* @since 2.2
|
||||||
|
*/
|
||||||
|
public class BeanExtenderUnitTest extends BaseUnitTest
|
||||||
|
{
|
||||||
|
private static final String BEAN_NAME = GUID.generate();
|
||||||
|
private static final String EXTENDING_BEAN_NAME = GUID.generate();
|
||||||
|
|
||||||
|
@Mock private ConfigurableListableBeanFactory mockedBeanFactory;
|
||||||
|
@Mock private BeanDefinition mockedBeanDefinition;
|
||||||
|
@Mock private BeanDefinition mockedExtendingBeanDefinition;
|
||||||
|
@Mock private MutablePropertyValues mockedPropertyValuesBean;
|
||||||
|
@Mock private MutablePropertyValues mockedPropertyValuesExtendingBean;
|
||||||
|
|
||||||
|
@InjectMocks private BeanExtender beanExtender;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void before()
|
||||||
|
{
|
||||||
|
super.before();
|
||||||
|
|
||||||
|
// setup common interactions
|
||||||
|
doReturn(mockedPropertyValuesBean).when(mockedBeanDefinition).getPropertyValues();
|
||||||
|
doReturn(mockedPropertyValuesExtendingBean).when(mockedExtendingBeanDefinition).getPropertyValues();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* given that the bean name is not set, ensure that an Illegal Argument
|
||||||
|
* exception is thrown.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void beanNameNotSet()
|
||||||
|
{
|
||||||
|
// === given ===
|
||||||
|
|
||||||
|
// set the extending bean name
|
||||||
|
beanExtender.setExtendingBeanName(EXTENDING_BEAN_NAME);
|
||||||
|
|
||||||
|
// expecting exception
|
||||||
|
exception.expect(IllegalArgumentException.class);
|
||||||
|
|
||||||
|
// === when ===
|
||||||
|
beanExtender.postProcessBeanFactory(mockedBeanFactory);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* given that the extending bean name is not set, ensure that an illegal
|
||||||
|
* argument exception is thrown.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void extendingBeanNameNotSet()
|
||||||
|
{
|
||||||
|
// === given ===
|
||||||
|
|
||||||
|
// set the extending bean name
|
||||||
|
beanExtender.setBeanName(BEAN_NAME);
|
||||||
|
|
||||||
|
// expecting exception
|
||||||
|
exception.expect(IllegalArgumentException.class);
|
||||||
|
|
||||||
|
// === when ===
|
||||||
|
beanExtender.postProcessBeanFactory(mockedBeanFactory);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* given that the bean does not exist ensure that an exception is thrown
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void beanDoesNotExist()
|
||||||
|
{
|
||||||
|
// === given ===
|
||||||
|
|
||||||
|
// set the bean names
|
||||||
|
beanExtender.setBeanName(BEAN_NAME);
|
||||||
|
beanExtender.setExtendingBeanName(EXTENDING_BEAN_NAME);
|
||||||
|
doReturn(false).when(mockedBeanFactory).containsBean(BEAN_NAME);
|
||||||
|
doReturn(true).when(mockedBeanFactory).containsBean(EXTENDING_BEAN_NAME);
|
||||||
|
|
||||||
|
// expecting exception
|
||||||
|
exception.expect(NoSuchBeanDefinitionException.class);
|
||||||
|
|
||||||
|
// === when ===
|
||||||
|
beanExtender.postProcessBeanFactory(mockedBeanFactory);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* given that the extending bean does not exist ensure that an exception is thrown
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void extendingBeanDoesNotExist()
|
||||||
|
{
|
||||||
|
// === given ===
|
||||||
|
|
||||||
|
// set the bean names
|
||||||
|
beanExtender.setBeanName(BEAN_NAME);
|
||||||
|
beanExtender.setExtendingBeanName(EXTENDING_BEAN_NAME);
|
||||||
|
doReturn(true).when(mockedBeanFactory).containsBean(BEAN_NAME);
|
||||||
|
doReturn(false).when(mockedBeanFactory).containsBean(EXTENDING_BEAN_NAME);
|
||||||
|
|
||||||
|
// expecting exception
|
||||||
|
exception.expect(NoSuchBeanDefinitionException.class);
|
||||||
|
|
||||||
|
// === when ===
|
||||||
|
beanExtender.postProcessBeanFactory(mockedBeanFactory);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* given that a different class name has been set on the extending bean ensure it is
|
||||||
|
* set correctly on the origional bean
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void beanClassNameSet()
|
||||||
|
{
|
||||||
|
// === given ===
|
||||||
|
|
||||||
|
// set the bean names
|
||||||
|
beanExtender.setBeanName(BEAN_NAME);
|
||||||
|
beanExtender.setExtendingBeanName(EXTENDING_BEAN_NAME);
|
||||||
|
|
||||||
|
// both beans are available in the bean factory
|
||||||
|
doReturn(true).when(mockedBeanFactory).containsBean(BEAN_NAME);
|
||||||
|
doReturn(true).when(mockedBeanFactory).containsBean(EXTENDING_BEAN_NAME);
|
||||||
|
|
||||||
|
// return the mocked bean definitions
|
||||||
|
doReturn(mockedBeanDefinition).when(mockedBeanFactory).getBeanDefinition(BEAN_NAME);
|
||||||
|
doReturn(mockedExtendingBeanDefinition).when(mockedBeanFactory).getBeanDefinition(EXTENDING_BEAN_NAME);
|
||||||
|
|
||||||
|
// bean class names
|
||||||
|
doReturn("a").when(mockedBeanDefinition).getBeanClassName();
|
||||||
|
doReturn("b").when(mockedExtendingBeanDefinition).getBeanClassName();
|
||||||
|
|
||||||
|
// no properties have been defined
|
||||||
|
doReturn(Collections.EMPTY_LIST).when(mockedPropertyValuesExtendingBean).getPropertyValueList();
|
||||||
|
|
||||||
|
// === when ===
|
||||||
|
beanExtender.postProcessBeanFactory(mockedBeanFactory);
|
||||||
|
|
||||||
|
// === then ===
|
||||||
|
|
||||||
|
// expect the class name to be set on the bean
|
||||||
|
verify(mockedBeanDefinition, times(1)).setBeanClassName("b");
|
||||||
|
verify(mockedPropertyValuesBean, never()).add(anyString(), anyString());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* given that new property values have been set on the extending bean ensure that they
|
||||||
|
* are correctly set on the original bean.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void beanPropertyValuesSet()
|
||||||
|
{
|
||||||
|
// === given ===
|
||||||
|
|
||||||
|
// set the bean names
|
||||||
|
beanExtender.setBeanName(BEAN_NAME);
|
||||||
|
beanExtender.setExtendingBeanName(EXTENDING_BEAN_NAME);
|
||||||
|
|
||||||
|
// both beans are available in the bean factory
|
||||||
|
doReturn(true).when(mockedBeanFactory).containsBean(BEAN_NAME);
|
||||||
|
doReturn(true).when(mockedBeanFactory).containsBean(EXTENDING_BEAN_NAME);
|
||||||
|
|
||||||
|
// return the mocked bean definitions
|
||||||
|
doReturn(mockedBeanDefinition).when(mockedBeanFactory).getBeanDefinition(BEAN_NAME);
|
||||||
|
doReturn(mockedExtendingBeanDefinition).when(mockedBeanFactory).getBeanDefinition(EXTENDING_BEAN_NAME);
|
||||||
|
|
||||||
|
// bean class names
|
||||||
|
doReturn("a").when(mockedBeanDefinition).getBeanClassName();
|
||||||
|
doReturn(null).when(mockedExtendingBeanDefinition).getBeanClassName();
|
||||||
|
|
||||||
|
PropertyValue mockedPropertyValueOne = generateMockedPropertyValue("one", "1");
|
||||||
|
PropertyValue mockedPropertyValueTwo = generateMockedPropertyValue("two", "2");
|
||||||
|
List<PropertyValue> list = new ArrayList<PropertyValue>(2);
|
||||||
|
list.add(mockedPropertyValueOne);
|
||||||
|
list.add(mockedPropertyValueTwo);
|
||||||
|
doReturn(list).when(mockedPropertyValuesExtendingBean).getPropertyValueList();
|
||||||
|
|
||||||
|
// === when ===
|
||||||
|
beanExtender.postProcessBeanFactory(mockedBeanFactory);
|
||||||
|
|
||||||
|
// === then ===
|
||||||
|
|
||||||
|
// expect the class name to be set on the bean
|
||||||
|
verify(mockedBeanDefinition, never()).setBeanClassName(anyString());
|
||||||
|
verify(mockedPropertyValuesBean, times(1)).add("one", "1");
|
||||||
|
verify(mockedPropertyValuesBean, times(1)).add("two", "2");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper method to generate a mocked property value
|
||||||
|
*/
|
||||||
|
private PropertyValue generateMockedPropertyValue(String name, String value)
|
||||||
|
{
|
||||||
|
PropertyValue result = mock(PropertyValue.class);
|
||||||
|
doReturn(name).when(result).getName();
|
||||||
|
doReturn(value).when(result).getValue();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user