mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Initial implementation of RM-2238, RM-2288, RM-2289 & RM-2290. Classification Abbreviations and tests.
In fact, this is pretty much done. Still to do: Unclassified Abbreviation. New class ClassificationLevelValidation which contains the various validation checks for level abbreviations. Unit tests for same. This new class is used by ClassificationServiceBootstrap. Added a new exception type just so that we have somewhere to store any illegal characters in a level abbreviation. Had to change the classification level IDs to “TS”, “S” & “C” as “Confidential” has a length > 10. I’d been thinking of doing this is a separate commit but the additional validation requires that we do it now. Minor fallout in test code due to ID changes. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@105641 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -0,0 +1,107 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2015 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.classification;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
import static org.alfresco.module.org_alfresco_module_rm.classification.ClassificationLevelValidation.ILLEGAL_ABBREVIATION_CHARS;
|
||||
import static org.alfresco.module.org_alfresco_module_rm.test.util.ExceptionUtils.expectedException;
|
||||
import static org.hamcrest.CoreMatchers.allOf;
|
||||
import static org.hamcrest.core.IsCollectionContaining.hasItem;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationException.IllegalAbbreviationChars;
|
||||
import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationException.IllegalConfiguration;
|
||||
import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationException.MissingConfiguration;
|
||||
import org.hamcrest.Matcher;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Unit tests for the {@link ClassificationLevelValidation}.
|
||||
*
|
||||
* @author Neil Mc Erlean
|
||||
*/
|
||||
public class ClassificationLevelValidationUnitTest
|
||||
{
|
||||
private final ClassificationLevelValidation validation = new ClassificationLevelValidation();
|
||||
|
||||
@Test(expected=MissingConfiguration.class)
|
||||
public void classificationLevelsAreRequired()
|
||||
{
|
||||
validation.validateLevels(Collections.emptyList());
|
||||
}
|
||||
|
||||
@Test public void nonEmptyAbbreviationsAreMandatory()
|
||||
{
|
||||
// A missing or empty level ID is illegal.
|
||||
for (String illegalID : asList(null, "", " ", "\t"))
|
||||
{
|
||||
expectedException(IllegalArgumentException.class, () ->
|
||||
{
|
||||
validation.validateLevel(new ClassificationLevel(illegalID, "value.does.not.matter"));
|
||||
return null;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected=IllegalConfiguration.class)
|
||||
public void longAbbreviationsAreIllegal()
|
||||
{
|
||||
validation.validateLevel(new ClassificationLevel("12345678901", "value.does.not.matter"));
|
||||
}
|
||||
|
||||
/**
|
||||
* This test ensures that validation will catch any and all illegal characters in a
|
||||
* {@link ClassificationLevel#getId() level ID} and report them all.
|
||||
*/
|
||||
@Test public void someCharactersAreBannedInAbbreviations()
|
||||
{
|
||||
for (Character illegalChar : ILLEGAL_ABBREVIATION_CHARS)
|
||||
{
|
||||
IllegalAbbreviationChars e = expectedException(IllegalAbbreviationChars.class, () ->
|
||||
{
|
||||
validation.validateLevel(new ClassificationLevel("Hello" + illegalChar, "value.does.not.matter"));
|
||||
return null;
|
||||
});
|
||||
assertTrue("Exception did not contain helpful example of illegal character",
|
||||
e.getIllegalChars().contains(illegalChar));
|
||||
}
|
||||
|
||||
// We also expect an abbreviation with multiple illegal chars in it to have them all reported in the exception.
|
||||
final List<Character> someIllegalChars = ILLEGAL_ABBREVIATION_CHARS.subList(0, 3);
|
||||
|
||||
IllegalAbbreviationChars e = expectedException(IllegalAbbreviationChars.class, () ->
|
||||
{
|
||||
validation.validateLevel(new ClassificationLevel(someIllegalChars.toString(),
|
||||
"value.does.not.matter"));
|
||||
return null;
|
||||
});
|
||||
|
||||
// Construct a sequence of Matchers - one for each illegal char we expect to see.
|
||||
// Apologies for the Java generics madness here. This is really a List of Matchers of List<Character>
|
||||
List<Matcher<? super Iterable<? super Character>>> containsCharMatchers = someIllegalChars.stream()
|
||||
.map(c -> hasItem(c))
|
||||
.collect(Collectors.toList());
|
||||
assertThat(e.getIllegalChars(), allOf(containsCharMatchers));
|
||||
}
|
||||
}
|
@@ -57,14 +57,14 @@ import org.mockito.MockitoAnnotations;
|
||||
*/
|
||||
public class ClassificationServiceBootstrapUnitTest
|
||||
{
|
||||
private static final List<ClassificationLevel> DEFAULT_CLASSIFICATION_LEVELS = asLevelList("Top Secret", "rm.classification.topSecret",
|
||||
"Secret", "rm.classification.secret",
|
||||
"Confidential", "rm.classification.confidential",
|
||||
"No Clearance", "rm.classification.noClearance");
|
||||
private static final List<ClassificationLevel> ALT_CLASSIFICATION_LEVELS = asLevelList("Board", "B",
|
||||
"Executive Management", "EM",
|
||||
"Employee", "E",
|
||||
"Public", "P");
|
||||
private static final List<ClassificationLevel> DEFAULT_CLASSIFICATION_LEVELS = asLevelList("TS", "rm.classification.topSecret",
|
||||
"S", "rm.classification.secret",
|
||||
"C", "rm.classification.confidential",
|
||||
"NC", "rm.classification.noClearance");
|
||||
private static final List<ClassificationLevel> ALT_CLASSIFICATION_LEVELS = asLevelList("B", "Board",
|
||||
"EM", "ExecutiveManagement",
|
||||
"E", "Employee",
|
||||
"P", "Public");
|
||||
private static final List<ClassificationReason> PLACEHOLDER_CLASSIFICATION_REASONS = asList(new ClassificationReason("id1", "label1"),
|
||||
new ClassificationReason("id2", "label2"));
|
||||
private static final List<ClassificationReason> ALTERNATIVE_CLASSIFICATION_REASONS = asList(new ClassificationReason("id8", "label8"),
|
||||
|
Reference in New Issue
Block a user