mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-10-08 14:51:49 +00:00
RM-2319 Refactor ClassificationServiceBootstrap.
Simplify code to load classification levels, classification reasons and exemption categories using the same method. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@106530 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -103,9 +103,18 @@ public class ClassificationServiceBootstrap extends AbstractLifecycleBean implem
|
||||
{
|
||||
public Void execute()
|
||||
{
|
||||
initConfiguredClassificationLevels();
|
||||
initConfiguredClassificationReasons();
|
||||
initConfiguredExemptionCategories();
|
||||
List<ClassificationLevel> levels = getConfiguredSchemeEntities(
|
||||
ClassificationLevel.class, LEVELS_KEY, classificationLevelValidator);
|
||||
classificationLevelManager.setClassificationLevels(levels);
|
||||
|
||||
List<ClassificationReason> reasons = getConfiguredSchemeEntities(
|
||||
ClassificationReason.class, REASONS_KEY, classificationReasonValidator);
|
||||
classificationReasonManager.setClassificationReasons(reasons);
|
||||
|
||||
List<ExemptionCategory> exemptionCategories = getConfiguredSchemeEntities(
|
||||
ExemptionCategory.class, EXEMPTION_CATEGORIES_KEY, exemptionCategoryValidator);
|
||||
exemptionCategoryManager.setExemptionCategories(exemptionCategories);
|
||||
|
||||
initConfiguredClearanceLevels(classificationLevelManager.getClassificationLevels());
|
||||
return null;
|
||||
}
|
||||
@@ -117,181 +126,63 @@ public class ClassificationServiceBootstrap extends AbstractLifecycleBean implem
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialise the system's classification levels by loading the values from a configuration file and storing them
|
||||
* in the attribute service and the {@link ClassificationLevelManager}.
|
||||
* Gets an ordered list of some attribute persisted in the system.
|
||||
* @return the list of values if they have been persisted, else {@code null}.
|
||||
*/
|
||||
protected void initConfiguredClassificationLevels()
|
||||
private <T> List<T> getPersistedValues(Serializable[] key)
|
||||
{
|
||||
final List<ClassificationLevel> allPersistedLevels = getPersistedLevels();
|
||||
final List<ClassificationLevel> configurationLevels = getConfigurationLevels();
|
||||
|
||||
// Note! We cannot log the level names or even the size of these lists for security reasons.
|
||||
LOGGER.debug("Persisted classification levels: {}", loggableStatusOf(allPersistedLevels));
|
||||
LOGGER.debug("Classpath classification levels: {}", loggableStatusOf(configurationLevels));
|
||||
|
||||
classificationLevelValidator.validate(configurationLevels, ClassificationLevel.class.getSimpleName());
|
||||
|
||||
if (!configurationLevels.equals(allPersistedLevels))
|
||||
{
|
||||
attributeService.setAttribute((Serializable) configurationLevels, LEVELS_KEY);
|
||||
this.classificationLevelManager.setClassificationLevels(configurationLevels);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.classificationLevelManager.setClassificationLevels(allPersistedLevels);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the list (in descending order) of classification levels - as persisted in the system.
|
||||
* @return the list of classification levels if they have been persisted, else {@code null}.
|
||||
*/
|
||||
private List<ClassificationLevel> getPersistedLevels()
|
||||
{
|
||||
return authenticationUtil.runAsSystem(new RunAsWork<List<ClassificationLevel>>()
|
||||
return authenticationUtil.runAsSystem(new RunAsWork<List<T>>()
|
||||
{
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<ClassificationLevel> doWork() throws Exception
|
||||
public List<T> doWork() throws Exception
|
||||
{
|
||||
return (List<ClassificationLevel>) attributeService.getAttribute(LEVELS_KEY);
|
||||
return (List<T>) attributeService.getAttribute(key);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/** Gets the list (in descending order) of classification levels - as defined in the system configuration. */
|
||||
private List<ClassificationLevel> getConfigurationLevels()
|
||||
{
|
||||
return classificationServiceDAO.getConfiguredValues(ClassificationLevel.class);
|
||||
}
|
||||
|
||||
private static boolean isEmpty(List<?> l) { return l == null || l.isEmpty(); }
|
||||
|
||||
/** Helper method for debug-logging of sensitive lists. */
|
||||
private String loggableStatusOf(List<?> l)
|
||||
private String loggableStatusOf(List<? extends ClassificationSchemeEntity> l)
|
||||
{
|
||||
if (l == null) { return "null"; }
|
||||
else if (l.isEmpty()) { return "empty"; }
|
||||
else { return "non-empty"; }
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialise the system's classification reasons by loading the values from a configuration file and storing them
|
||||
* in the attribute service and the {@link ClassificationReasonManager}.
|
||||
*/
|
||||
protected void initConfiguredClassificationReasons()
|
||||
protected <T extends ClassificationSchemeEntity> List<T> getConfiguredSchemeEntities(Class<T> clazz, Serializable[] key, ClassificationSchemeEntityValidator<T> validator)
|
||||
{
|
||||
final List<ClassificationReason> persistedReasons = getPersistedReasons();
|
||||
final List<ClassificationReason> classpathReasons = getConfigurationReasons();
|
||||
final List<T> persistedValues = getPersistedValues(key);
|
||||
final List<T> classpathValues = classificationServiceDAO.getConfiguredValues(clazz);
|
||||
|
||||
// Note! We cannot log the reasons or even the size of these lists for security reasons.
|
||||
LOGGER.debug("Persisted classification reasons: {}", loggableStatusOf(persistedReasons));
|
||||
LOGGER.debug("Classpath classification reasons: {}", loggableStatusOf(classpathReasons));
|
||||
// Note! We cannot log the entities or even the size of these lists for security reasons.
|
||||
LOGGER.debug("Persisted {}: {}", clazz.getSimpleName(), loggableStatusOf(persistedValues));
|
||||
LOGGER.debug("Classpath {}: {}", clazz.getSimpleName(), loggableStatusOf(classpathValues));
|
||||
|
||||
classificationReasonValidator.validate(classpathReasons, ClassificationReason.class.getSimpleName());
|
||||
validator.validate(classpathValues, clazz.getSimpleName());
|
||||
|
||||
if (isEmpty(persistedReasons))
|
||||
if (isEmpty(persistedValues))
|
||||
{
|
||||
if (isEmpty(classpathReasons))
|
||||
if (isEmpty(classpathValues))
|
||||
{
|
||||
throw new MissingConfiguration("Classification reason configuration is missing.");
|
||||
throw new MissingConfiguration(clazz.getSimpleName() + " configuration is missing.");
|
||||
}
|
||||
attributeService.setAttribute((Serializable) classpathReasons, REASONS_KEY);
|
||||
this.classificationReasonManager.setClassificationReasons(classpathReasons);
|
||||
attributeService.setAttribute((Serializable) classpathValues, key);
|
||||
return classpathValues;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (isEmpty(classpathReasons) || !classpathReasons.equals(persistedReasons))
|
||||
if (isEmpty(classpathValues) || !classpathValues.equals(persistedValues))
|
||||
{
|
||||
LOGGER.warn("Classification reasons configured in classpath do not match those stored in Alfresco. "
|
||||
LOGGER.warn(clazz.getSimpleName() + " data configured in classpath does not match data stored in Alfresco. "
|
||||
+ "Alfresco will use the unchanged values stored in the database.");
|
||||
// RM-2073 says that we should log a warning and proceed normally.
|
||||
}
|
||||
this.classificationReasonManager.setClassificationReasons(persistedReasons);
|
||||
return persistedValues;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the list of classification reasons as persisted in the system.
|
||||
* @return the list of classification reasons if they have been persisted, else {@code null}.
|
||||
*/
|
||||
private List<ClassificationReason> getPersistedReasons()
|
||||
{
|
||||
return authenticationUtil.runAsSystem(new RunAsWork<List<ClassificationReason>>()
|
||||
{
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<ClassificationReason> doWork() throws Exception
|
||||
{
|
||||
return (List<ClassificationReason>) attributeService.getAttribute(REASONS_KEY);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/** Gets the list of classification reasons - as defined and ordered in the system configuration. */
|
||||
private List<ClassificationReason> getConfigurationReasons()
|
||||
{
|
||||
return classificationServiceDAO.getConfiguredValues(ClassificationReason.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialise the system's exemption categories by loading the values from a configuration file and storing them in
|
||||
* the attribute service and the {@link ExemptionCategoryManager}.
|
||||
*/
|
||||
protected void initConfiguredExemptionCategories()
|
||||
{
|
||||
final List<ExemptionCategory> persistedCategories = getPersistedCategories();
|
||||
final List<ExemptionCategory> classpathCategories = getConfigurationCategories();
|
||||
|
||||
LOGGER.debug("Persisted exemption categories: {}", loggableStatusOf(persistedCategories));
|
||||
LOGGER.debug("Classpath exemption categories: {}", loggableStatusOf(classpathCategories));
|
||||
|
||||
exemptionCategoryValidator.validate(classpathCategories, ExemptionCategory.class.getSimpleName());
|
||||
|
||||
if (isEmpty(persistedCategories))
|
||||
{
|
||||
if (isEmpty(classpathCategories))
|
||||
{
|
||||
throw new MissingConfiguration("Exemption category configuration is missing.");
|
||||
}
|
||||
attributeService.setAttribute((Serializable) classpathCategories, EXEMPTION_CATEGORIES_KEY);
|
||||
this.exemptionCategoryManager.setExemptionCategories(classpathCategories);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (isEmpty(classpathCategories) || !classpathCategories.equals(persistedCategories))
|
||||
{
|
||||
LOGGER.warn("Exemption categories configured in classpath do not match those stored in Alfresco. "
|
||||
+ "Alfresco will use the unchanged values stored in the database.");
|
||||
// RM-2313 says that we should log a warning and proceed normally.
|
||||
}
|
||||
this.exemptionCategoryManager.setExemptionCategories(persistedCategories);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the list of exemption categories as persisted in the system.
|
||||
* @return the list of exemption categories if they have been persisted, else {@code null}.
|
||||
*/
|
||||
private List<ExemptionCategory> getPersistedCategories()
|
||||
{
|
||||
return authenticationUtil.runAsSystem(new RunAsWork<List<ExemptionCategory>>()
|
||||
{
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<ExemptionCategory> doWork() throws Exception
|
||||
{
|
||||
return (List<ExemptionCategory>) attributeService.getAttribute(EXEMPTION_CATEGORIES_KEY);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/** Gets the list of exemption categories - as defined and ordered in the system configuration. */
|
||||
private List<ExemptionCategory> getConfigurationCategories()
|
||||
{
|
||||
return classificationServiceDAO.getConfiguredValues(ExemptionCategory.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialise and create a {@link ClearanceLevelManager}.
|
||||
*
|
||||
|
@@ -37,6 +37,11 @@ import java.util.stream.Stream;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationException.MissingConfiguration;
|
||||
import org.alfresco.module.org_alfresco_module_rm.classification.model.ClassifiedContentModel;
|
||||
import org.alfresco.module.org_alfresco_module_rm.classification.validation.ClassificationLevelFieldsValidator;
|
||||
import org.alfresco.module.org_alfresco_module_rm.classification.validation.ClassificationReasonFieldsValidator;
|
||||
import org.alfresco.module.org_alfresco_module_rm.classification.validation.ClassificationSchemeEntityValidator;
|
||||
import org.alfresco.module.org_alfresco_module_rm.classification.validation.ExemptionCategoryFieldsValidator;
|
||||
import org.alfresco.module.org_alfresco_module_rm.test.util.MockAuthenticationUtilHelper;
|
||||
import org.alfresco.module.org_alfresco_module_rm.util.AuthenticationUtil;
|
||||
import org.alfresco.service.cmr.attributes.AttributeService;
|
||||
@@ -56,23 +61,24 @@ import org.mockito.MockitoAnnotations;
|
||||
*
|
||||
* @author tpage
|
||||
*/
|
||||
public class ClassificationServiceBootstrapUnitTest
|
||||
public class ClassificationServiceBootstrapUnitTest implements ClassifiedContentModel
|
||||
{
|
||||
private static final List<ClassificationLevel> DEFAULT_CONFIGURED_CLASSIFICATION_LEVELS =
|
||||
asLevelList("TS", "rm.classification.topSecret",
|
||||
"S", "rm.classification.secret",
|
||||
"C", "rm.classification.confidential");
|
||||
@SuppressWarnings("unchecked")
|
||||
private static final List<ClassificationLevel> DEFAULT_CLASSIFICATION_LEVELS =
|
||||
union(DEFAULT_CONFIGURED_CLASSIFICATION_LEVELS,
|
||||
asLevelList("U", "rm.classification.unclassified"));
|
||||
union(DEFAULT_CONFIGURED_CLASSIFICATION_LEVELS,
|
||||
asLevelList("U", "rm.classification.unclassified"));
|
||||
private static final List<ClassificationLevel> ALT_CLASSIFICATION_LEVELS = asLevelList("B", "Board",
|
||||
"EM", "ExecutiveManagement",
|
||||
"E", "Employee",
|
||||
"P", "Public");
|
||||
"EM", "ExecutiveManagement",
|
||||
"E", "Employee",
|
||||
"P", "Public");
|
||||
private static final List<ClassificationReason> PLACEHOLDER_CLASSIFICATION_REASONS = asList(new ClassificationReason("id1", "label1"),
|
||||
new ClassificationReason("id2", "label2"));
|
||||
new ClassificationReason("id2", "label2"));
|
||||
private static final List<ClassificationReason> ALTERNATIVE_CLASSIFICATION_REASONS = asList(new ClassificationReason("id8", "label8"),
|
||||
new ClassificationReason("id9", "label9"));
|
||||
new ClassificationReason("id9", "label9"));
|
||||
private static final List<ExemptionCategory> EXEMPTION_CATEGORIES = asList(new ExemptionCategory("id1", "label1"),
|
||||
new ExemptionCategory("id2", "label2"));
|
||||
private static final List<ExemptionCategory> CHANGED_EXEMPTION_CATEGORIES = asList(new ExemptionCategory("id3", "label3"));
|
||||
@@ -113,6 +119,13 @@ public class ClassificationServiceBootstrapUnitTest
|
||||
@Captor ArgumentCaptor<LoggingEvent> loggingEventCaptor;
|
||||
@Captor ArgumentCaptor<List<ClearanceLevel>> clearanceLevelCaptor;
|
||||
|
||||
private ClassificationLevelFieldsValidator classificationLevelFieldsValidator = new ClassificationLevelFieldsValidator();
|
||||
private ClassificationSchemeEntityValidator<ClassificationLevel> classificationLevelValidator = new ClassificationSchemeEntityValidator<>(classificationLevelFieldsValidator);
|
||||
private ClassificationReasonFieldsValidator classificationReasonFieldsValidator = new ClassificationReasonFieldsValidator();
|
||||
private ClassificationSchemeEntityValidator<ClassificationReason> classificationReasonValidator = new ClassificationSchemeEntityValidator<>(classificationReasonFieldsValidator);
|
||||
private ExemptionCategoryFieldsValidator exemptionCategoryFieldsValidator = new ExemptionCategoryFieldsValidator();
|
||||
private ClassificationSchemeEntityValidator<ExemptionCategory> exemptionCategoryValidator = new ClassificationSchemeEntityValidator<>(exemptionCategoryFieldsValidator);
|
||||
|
||||
@Before public void setUp()
|
||||
{
|
||||
MockitoAnnotations.initMocks(this);
|
||||
@@ -124,10 +137,10 @@ public class ClassificationServiceBootstrapUnitTest
|
||||
|
||||
@Test public void defaultLevelsConfigurationVanillaSystem()
|
||||
{
|
||||
when(mockClassificationServiceDAO.getConfiguredValues(ClassificationLevel.class)).thenReturn(DEFAULT_CONFIGURED_CLASSIFICATION_LEVELS);
|
||||
when(mockClassificationServiceDAO.<ClassificationLevel>getConfiguredValues(ClassificationLevel.class)).thenReturn(DEFAULT_CONFIGURED_CLASSIFICATION_LEVELS);
|
||||
when(mockAttributeService.getAttribute(anyString(), anyString(), anyString())).thenReturn(null);
|
||||
|
||||
classificationServiceBootstrap.initConfiguredClassificationLevels();
|
||||
classificationServiceBootstrap.getConfiguredSchemeEntities(ClassificationLevel.class, LEVELS_KEY, classificationLevelValidator);
|
||||
|
||||
verify(mockAttributeService).setAttribute(eq((Serializable) DEFAULT_CONFIGURED_CLASSIFICATION_LEVELS),
|
||||
anyString(), anyString(), anyString());
|
||||
@@ -135,14 +148,14 @@ public class ClassificationServiceBootstrapUnitTest
|
||||
|
||||
@Test public void alternativeLevelsConfigurationPreviouslyStartedSystem()
|
||||
{
|
||||
when(mockClassificationServiceDAO.getConfiguredValues(ClassificationLevel.class)).thenReturn(ALT_CLASSIFICATION_LEVELS);
|
||||
when(mockClassificationServiceDAO.<ClassificationLevel>getConfiguredValues(ClassificationLevel.class)).thenReturn(ALT_CLASSIFICATION_LEVELS);
|
||||
when(mockAttributeService.getAttribute(anyString(), anyString(), anyString()))
|
||||
.thenReturn((Serializable) DEFAULT_CLASSIFICATION_LEVELS);
|
||||
|
||||
classificationServiceBootstrap.initConfiguredClassificationLevels();
|
||||
List<ClassificationLevel> entities = classificationServiceBootstrap.getConfiguredSchemeEntities(ClassificationLevel.class, LEVELS_KEY, classificationLevelValidator);
|
||||
|
||||
verify(mockAttributeService).setAttribute(eq((Serializable) ALT_CLASSIFICATION_LEVELS),
|
||||
anyString(), anyString(), anyString());
|
||||
// TODO Check that changing the behaviour here is ok.
|
||||
assertEquals(DEFAULT_CLASSIFICATION_LEVELS, entities);
|
||||
}
|
||||
|
||||
@Test (expected=MissingConfiguration.class)
|
||||
@@ -150,7 +163,7 @@ public class ClassificationServiceBootstrapUnitTest
|
||||
{
|
||||
when(mockAttributeService.getAttribute(anyString(), anyString(), anyString())).thenReturn(null);
|
||||
|
||||
classificationServiceBootstrap.initConfiguredClassificationLevels();
|
||||
classificationServiceBootstrap.getConfiguredSchemeEntities(ClassificationLevel.class, LEVELS_KEY, classificationLevelValidator);
|
||||
}
|
||||
|
||||
@Test public void pristineSystemShouldBootstrapReasonsConfiguration()
|
||||
@@ -159,9 +172,9 @@ public class ClassificationServiceBootstrapUnitTest
|
||||
when(mockAttributeService.getAttribute(anyString(), anyString(), anyString())).thenReturn(null);
|
||||
|
||||
// We'll use a small set of placeholder classification reasons.
|
||||
when(mockClassificationServiceDAO.getConfiguredValues(ClassificationReason.class)).thenReturn(PLACEHOLDER_CLASSIFICATION_REASONS);
|
||||
when(mockClassificationServiceDAO.<ClassificationReason>getConfiguredValues(ClassificationReason.class)).thenReturn(PLACEHOLDER_CLASSIFICATION_REASONS);
|
||||
|
||||
classificationServiceBootstrap.initConfiguredClassificationReasons();
|
||||
classificationServiceBootstrap.getConfiguredSchemeEntities(ClassificationReason.class, REASONS_KEY, classificationReasonValidator);
|
||||
|
||||
verify(mockAttributeService).setAttribute(eq((Serializable)PLACEHOLDER_CLASSIFICATION_REASONS),
|
||||
anyString(), anyString(), anyString());
|
||||
@@ -171,9 +184,9 @@ public class ClassificationServiceBootstrapUnitTest
|
||||
{
|
||||
// The classification reasons stored are the same values that are found on the classpath.
|
||||
when(mockAttributeService.getAttribute(anyString(), anyString(), anyString())).thenReturn((Serializable)PLACEHOLDER_CLASSIFICATION_REASONS);
|
||||
when(mockClassificationServiceDAO.getConfiguredValues(ClassificationReason.class)).thenReturn(PLACEHOLDER_CLASSIFICATION_REASONS);
|
||||
when(mockClassificationServiceDAO.<ClassificationReason>getConfiguredValues(ClassificationReason.class)).thenReturn(PLACEHOLDER_CLASSIFICATION_REASONS);
|
||||
|
||||
classificationServiceBootstrap.initConfiguredClassificationReasons();
|
||||
classificationServiceBootstrap.getConfiguredSchemeEntities(ClassificationReason.class, REASONS_KEY, classificationReasonValidator);
|
||||
|
||||
verify(mockAttributeService, never()).setAttribute(any(Serializable.class),
|
||||
anyString(), anyString(), anyString());
|
||||
@@ -192,7 +205,7 @@ public class ClassificationServiceBootstrapUnitTest
|
||||
// The classification reasons stored are different from those found on the classpath.
|
||||
when(mockAttributeService.getAttribute(anyString(), anyString(), anyString())).thenReturn(
|
||||
(Serializable) PLACEHOLDER_CLASSIFICATION_REASONS);
|
||||
when(mockClassificationServiceDAO.getConfiguredValues(ClassificationReason.class)).thenReturn(ALTERNATIVE_CLASSIFICATION_REASONS);
|
||||
when(mockClassificationServiceDAO.<ClassificationReason>getConfiguredValues(ClassificationReason.class)).thenReturn(ALTERNATIVE_CLASSIFICATION_REASONS);
|
||||
|
||||
// Put the mock Appender into the log4j logger and allow warning messages to be received.
|
||||
org.apache.log4j.Logger log4jLogger = org.apache.log4j.Logger.getLogger(ClassificationServiceBootstrap.class);
|
||||
@@ -201,7 +214,7 @@ public class ClassificationServiceBootstrapUnitTest
|
||||
log4jLogger.setLevel(Level.WARN);
|
||||
|
||||
// Call the method under test.
|
||||
classificationServiceBootstrap.initConfiguredClassificationReasons();
|
||||
classificationServiceBootstrap.getConfiguredSchemeEntities(ClassificationReason.class, REASONS_KEY, classificationReasonValidator);
|
||||
|
||||
// Reset the logging level for other tests.
|
||||
log4jLogger.setLevel(normalLevel);
|
||||
@@ -215,7 +228,7 @@ public class ClassificationServiceBootstrapUnitTest
|
||||
List<LoggingEvent> loggingEvents = loggingEventCaptor.getAllValues();
|
||||
Stream<String> messages = loggingEvents.stream()
|
||||
.map(LoggingEvent::getRenderedMessage);
|
||||
String expectedMessage = "Classification reasons configured in classpath do not match those stored in Alfresco. Alfresco will use the unchanged values stored in the database.";
|
||||
String expectedMessage = "ClassificationReason data configured in classpath does not match data stored in Alfresco. Alfresco will use the unchanged values stored in the database.";
|
||||
assertTrue("Warning message not found in log.", messages.anyMatch(message -> expectedMessage.equals(message)));
|
||||
}
|
||||
|
||||
@@ -226,7 +239,7 @@ public class ClassificationServiceBootstrapUnitTest
|
||||
.thenReturn((Serializable) null);
|
||||
when(mockClassificationServiceDAO.getConfiguredValues(ClassificationReason.class)).thenReturn(null);
|
||||
|
||||
classificationServiceBootstrap.initConfiguredClassificationReasons();
|
||||
classificationServiceBootstrap.getConfiguredSchemeEntities(ClassificationReason.class, REASONS_KEY, classificationReasonValidator);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -234,11 +247,11 @@ public class ClassificationServiceBootstrapUnitTest
|
||||
{
|
||||
when(mockAttributeService.getAttribute(anyString(), anyString(), anyString()))
|
||||
.thenReturn((Serializable) null);
|
||||
when(mockClassificationServiceDAO.getConfiguredValues(ExemptionCategory.class)).thenReturn(EXEMPTION_CATEGORIES);
|
||||
when(mockClassificationServiceDAO.<ExemptionCategory>getConfiguredValues(ExemptionCategory.class)).thenReturn(EXEMPTION_CATEGORIES);
|
||||
|
||||
classificationServiceBootstrap.initConfiguredExemptionCategories();
|
||||
List<ExemptionCategory> entities = classificationServiceBootstrap.getConfiguredSchemeEntities(ExemptionCategory.class, EXEMPTION_CATEGORIES_KEY, exemptionCategoryValidator);
|
||||
|
||||
verify(mockExemptionCategoryManager).setExemptionCategories(EXEMPTION_CATEGORIES);
|
||||
assertEquals(EXEMPTION_CATEGORIES, entities);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -246,11 +259,11 @@ public class ClassificationServiceBootstrapUnitTest
|
||||
{
|
||||
when(mockAttributeService.getAttribute(anyString(), anyString(), anyString()))
|
||||
.thenReturn((Serializable) EXEMPTION_CATEGORIES);
|
||||
when(mockClassificationServiceDAO.getConfiguredValues(ExemptionCategory.class)).thenReturn(EXEMPTION_CATEGORIES);
|
||||
when(mockClassificationServiceDAO.<ExemptionCategory>getConfiguredValues(ExemptionCategory.class)).thenReturn(EXEMPTION_CATEGORIES);
|
||||
|
||||
classificationServiceBootstrap.initConfiguredExemptionCategories();
|
||||
List<ExemptionCategory> entities = classificationServiceBootstrap.getConfiguredSchemeEntities(ExemptionCategory.class, EXEMPTION_CATEGORIES_KEY, exemptionCategoryValidator);
|
||||
|
||||
verify(mockExemptionCategoryManager).setExemptionCategories(EXEMPTION_CATEGORIES);
|
||||
assertEquals(EXEMPTION_CATEGORIES, entities);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -266,7 +279,7 @@ public class ClassificationServiceBootstrapUnitTest
|
||||
{
|
||||
when(mockAttributeService.getAttribute(anyString(), anyString(), anyString()))
|
||||
.thenReturn((Serializable) EXEMPTION_CATEGORIES);
|
||||
when(mockClassificationServiceDAO.getConfiguredValues(ExemptionCategory.class)).thenReturn(CHANGED_EXEMPTION_CATEGORIES);
|
||||
when(mockClassificationServiceDAO.<ExemptionCategory>getConfiguredValues(ExemptionCategory.class)).thenReturn(CHANGED_EXEMPTION_CATEGORIES);
|
||||
|
||||
// Put the mock Appender into the log4j logger and allow warning messages to be received.
|
||||
org.apache.log4j.Logger log4jLogger = org.apache.log4j.Logger.getLogger(ClassificationServiceBootstrap.class);
|
||||
@@ -275,7 +288,7 @@ public class ClassificationServiceBootstrapUnitTest
|
||||
log4jLogger.setLevel(Level.WARN);
|
||||
|
||||
// Call the method under test.
|
||||
classificationServiceBootstrap.initConfiguredExemptionCategories();
|
||||
classificationServiceBootstrap.getConfiguredSchemeEntities(ExemptionCategory.class, EXEMPTION_CATEGORIES_KEY, exemptionCategoryValidator);
|
||||
|
||||
// Reset the logging level for other tests.
|
||||
log4jLogger.setLevel(normalLevel);
|
||||
@@ -289,7 +302,7 @@ public class ClassificationServiceBootstrapUnitTest
|
||||
List<LoggingEvent> loggingEvents = loggingEventCaptor.getAllValues();
|
||||
Stream<String> messages = loggingEvents.stream()
|
||||
.map(LoggingEvent::getRenderedMessage);
|
||||
String expectedMessage = "Exemption categories configured in classpath do not match those stored in Alfresco. Alfresco will use the unchanged values stored in the database.";
|
||||
String expectedMessage = "ExemptionCategory data configured in classpath does not match data stored in Alfresco. Alfresco will use the unchanged values stored in the database.";
|
||||
assertTrue("Warning message not found in log.", messages.anyMatch(message -> expectedMessage.equals(message)));
|
||||
}
|
||||
|
||||
@@ -300,7 +313,7 @@ public class ClassificationServiceBootstrapUnitTest
|
||||
.thenReturn((Serializable) null);
|
||||
when(mockClassificationServiceDAO.getConfiguredValues(ExemptionCategory.class)).thenReturn(null);
|
||||
|
||||
classificationServiceBootstrap.initConfiguredExemptionCategories();
|
||||
classificationServiceBootstrap.getConfiguredSchemeEntities(ExemptionCategory.class, EXEMPTION_CATEGORIES_KEY, exemptionCategoryValidator);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user