diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/ClassificationServiceBootstrap.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/ClassificationServiceBootstrap.java
index 9fe69e7b7c..2c7b3d207c 100644
--- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/ClassificationServiceBootstrap.java
+++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/ClassificationServiceBootstrap.java
@@ -22,6 +22,8 @@ import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
+import org.alfresco.module.org_alfresco_module_rm.classification.validation.ClassificationLevelValidation;
+
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;
diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/validation/ClassificationLevelFieldsValidator.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/validation/ClassificationLevelFieldsValidator.java
new file mode 100644
index 0000000000..6822167fe8
--- /dev/null
+++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/validation/ClassificationLevelFieldsValidator.java
@@ -0,0 +1,60 @@
+/*
+ * 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 .
+ */
+package org.alfresco.module.org_alfresco_module_rm.classification.validation;
+
+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.alfresco.module.org_alfresco_module_rm.classification.ClassificationLevel;
+
+/**
+ * Validator for the fields in {@link ClassificationLevel}.
+ *
+ * @author tpage
+ * @since 3.0
+ */
+public class ClassificationLevelFieldsValidator implements EntityFieldsValidator
+{
+ /** The maximum number of characters allowed in a {@link ClassificationLevel#getId() level ID}. */
+ private static final int ABBREVIATION_LENGTH_LIMIT = 10;
+ /** Validator for the length of the level abbreviation. */
+ private FieldValidator lengthFieldValidator = new LengthFieldValidator(1, ABBREVIATION_LENGTH_LIMIT);
+ /** Validator for the characters in the level abbreviation. */
+ private FieldValidator filenameFieldValidator = new FilenameFieldValidator();
+ /** Validator that checks that the reserved symbol "U" is not configured as a classification level. */
+ private FieldValidator classificationLevelIsNotUnclassifiedValidator = new ClassificationLevelIsNotUnclassifiedValidator();
+
+ /**
+ * Validates the provided {@link ClassificationLevel}.
+ *
+ * @param classificationLevel the level to validate.
+ * @throws MissingConfiguration if the level abbreviation is missing.
+ * @throws IllegalConfiguration if the level abbreviation violates the standard restrictions.
+ * @throws IllegalAbbreviationChars if the level abbreviation contains illegal characters.
+ */
+ @Override
+ public void validate(ClassificationLevel classificationLevel)
+ {
+ final String levelId = classificationLevel.getId();
+
+ lengthFieldValidator.validate(levelId, "level abbreviation");
+ filenameFieldValidator.validate(levelId, "level abbreviation");
+ classificationLevelIsNotUnclassifiedValidator.validate(levelId, "level abbreviation");
+ }
+}
diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/validation/ClassificationLevelIsNotUnclassifiedValidator.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/validation/ClassificationLevelIsNotUnclassifiedValidator.java
new file mode 100644
index 0000000000..52e9dd7b46
--- /dev/null
+++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/validation/ClassificationLevelIsNotUnclassifiedValidator.java
@@ -0,0 +1,42 @@
+/*
+ * 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 .
+ */
+package org.alfresco.module.org_alfresco_module_rm.classification.validation;
+
+import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationException;
+import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationException.IllegalConfiguration;
+import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationLevelManager;
+
+/**
+ * A validator that checks that the reserved symbol "U" is not configured as a classification level.
+ *
+ * @author tpage
+ * @since 3.0
+ */
+public class ClassificationLevelIsNotUnclassifiedValidator implements FieldValidator
+{
+ @Override
+ public void validate(String levelId, String fieldName) throws ClassificationException
+ {
+ if (levelId.equals(ClassificationLevelManager.UNCLASSIFIED_ID))
+ {
+ throw new IllegalConfiguration("The unclassified abbreviation '" +
+ ClassificationLevelManager.UNCLASSIFIED_ID + "' is reserved for system use.");
+ }
+ }
+}
diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/ClassificationLevelValidation.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/validation/ClassificationLevelValidation.java
similarity index 50%
rename from rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/ClassificationLevelValidation.java
rename to rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/validation/ClassificationLevelValidation.java
index ba66c8a9fc..a3b4786c80 100644
--- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/ClassificationLevelValidation.java
+++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/validation/ClassificationLevelValidation.java
@@ -16,14 +16,15 @@
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see .
*/
-package org.alfresco.module.org_alfresco_module_rm.classification;
+package org.alfresco.module.org_alfresco_module_rm.classification.validation;
-import static java.util.Arrays.asList;
import static org.alfresco.module.org_alfresco_module_rm.util.RMCollectionUtils.getDuplicateElements;
-import java.util.ArrayList;
import java.util.List;
+import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationException;
+import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationLevel;
+
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;
@@ -36,47 +37,8 @@ import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationE
*/
public class ClassificationLevelValidation
{
- /** The maximum number of characters allowed in a {@link ClassificationLevel#getId() level ID}. */
- private static final int ABBREVIATION_LENGTH_LIMIT = 10;
-
- /**
- * Illegal characters in a {@link ClassificationLevel#getId() level ID}.
- * Equals to Alfresco's disallowed filename characters.
- */
- // See in contentModel.xml
- static final List ILLEGAL_ABBREVIATION_CHARS = asList('"', '*', '\\', '>', '<', '?', '/', ':', '|');
-
- /**
- * Validates the provided {@link ClassificationLevel}.
- * @param level the level to validate.
- * @throws MissingConfiguration if the level abbreviation is missing.
- * @throws IllegalConfiguration if the level abbreviation violates the standard restrictions.
- * @throws IllegalAbbreviationChars if the level abbreviation contains illegal characters.
- */
- void validateLevel(ClassificationLevel level)
- {
- final String levelId = level.getId();
-
- if (levelId == null || levelId.equals(""))
- {
- throw new MissingConfiguration("Classification level ID is missing.");
- }
- else if (levelId.equals(ClassificationLevelManager.UNCLASSIFIED_ID))
- {
- throw new IllegalConfiguration("The Unclassified ID abbreviation '" +
- ClassificationLevelManager.UNCLASSIFIED_ID + "' is reserved for system use.");
- }
- else if (levelId.length() > ABBREVIATION_LENGTH_LIMIT)
- {
- throw new IllegalConfiguration("Illegal classification level abbreviation. Length " +
- levelId.length() + " > " + ABBREVIATION_LENGTH_LIMIT);
- }
- else if (!getIllegalAbbreviationChars(levelId).isEmpty())
- {
- throw new IllegalAbbreviationChars("Illegal character(s) in level abbreviation",
- getIllegalAbbreviationChars(levelId));
- }
- }
+ /** A validator for the fields within the classification level. */
+ private EntityFieldsValidator classificationLevelFieldsValidator = new ClassificationLevelFieldsValidator();
/**
* Validates the provided {@link ClassificationLevel}s as a whole and individually.
@@ -100,17 +62,7 @@ public class ClassificationLevelValidation
for (ClassificationLevel level : levels)
{
- validateLevel(level);
+ classificationLevelFieldsValidator.validate(level);
}
}
-
- private List getIllegalAbbreviationChars(String s)
- {
- final List result = new ArrayList<>();
- for (Character c : ILLEGAL_ABBREVIATION_CHARS)
- {
- if (s.contains(c.toString())) result.add(c);
- }
- return result;
- }
}
diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/validation/EntityFieldsValidator.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/validation/EntityFieldsValidator.java
new file mode 100644
index 0000000000..8e42e41433
--- /dev/null
+++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/validation/EntityFieldsValidator.java
@@ -0,0 +1,37 @@
+/*
+ * 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 .
+ */
+package org.alfresco.module.org_alfresco_module_rm.classification.validation;
+
+import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationSchemeEntity;
+
+/**
+ * A validator for all the fields of a classification POJO.
+ *
+ * @author tpage
+ * @since 3.0
+ */
+public interface EntityFieldsValidator
+{
+ /**
+ * Validate the fields of the given POJO.
+ *
+ * @param pojo The object to validate.
+ */
+ void validate(T pojo);
+}
diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/validation/FieldValidator.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/validation/FieldValidator.java
new file mode 100644
index 0000000000..28d1780886
--- /dev/null
+++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/validation/FieldValidator.java
@@ -0,0 +1,32 @@
+/*
+ * 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 .
+ */
+package org.alfresco.module.org_alfresco_module_rm.classification.validation;
+
+import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationException;
+
+/**
+ * Validate a field.
+ *
+ * @author tpage
+ * @since 3.0
+ */
+public interface FieldValidator
+{
+ void validate(T field, String fieldName) throws ClassificationException;
+}
diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/validation/FilenameFieldValidator.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/validation/FilenameFieldValidator.java
new file mode 100644
index 0000000000..2e3a7c4e4a
--- /dev/null
+++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/validation/FilenameFieldValidator.java
@@ -0,0 +1,64 @@
+/*
+ * 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 .
+ */
+package org.alfresco.module.org_alfresco_module_rm.classification.validation;
+
+import static java.util.Arrays.asList;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationException;
+import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationException.IllegalAbbreviationChars;
+import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationLevel;
+
+/**
+ * Check that a field is suitable to be used as part of a filename.
+ *
+ * @author tpage
+ * @since 3.0
+ */
+public class FilenameFieldValidator implements FieldValidator
+{
+ /**
+ * Illegal characters in a {@link ClassificationLevel#getId() level ID}.
+ * Equals to Alfresco's disallowed filename characters.
+ */
+ // See in contentModel.xml
+ static final List ILLEGAL_ABBREVIATION_CHARS = asList('"', '*', '\\', '>', '<', '?', '/', ':', '|');
+
+ private List getIllegalAbbreviationChars(String s)
+ {
+ final List result = new ArrayList<>();
+ for (Character c : ILLEGAL_ABBREVIATION_CHARS)
+ {
+ if (s.contains(c.toString())) result.add(c);
+ }
+ return result;
+ }
+
+ @Override
+ public void validate(String field, String fieldName) throws ClassificationException
+ {
+ List illegalAbbreviationChars = getIllegalAbbreviationChars(field);
+ if (!illegalAbbreviationChars.isEmpty())
+ {
+ throw new IllegalAbbreviationChars("Illegal character(s) in " + fieldName, illegalAbbreviationChars);
+ }
+ }
+}
diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/validation/LengthFieldValidator.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/validation/LengthFieldValidator.java
new file mode 100644
index 0000000000..3ec9e3a155
--- /dev/null
+++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/validation/LengthFieldValidator.java
@@ -0,0 +1,82 @@
+/*
+ * 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 .
+ */
+package org.alfresco.module.org_alfresco_module_rm.classification.validation;
+
+import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationException;
+import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationException.IllegalConfiguration;
+import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationException.MissingConfiguration;
+
+/**
+ * Validate the length of a field.
+ *
+ * @author tpage
+ * @since 3.0
+ */
+public class LengthFieldValidator implements FieldValidator
+{
+ /** The minimum allowed length for the field. */
+ private int minimumLength;
+ /** The maximum allowed length for the field, or {@code null} if there is no maximum length. */
+ private Integer maximumLength = null;
+
+ /**
+ * Create a validator that only checks the minimum length.
+ *
+ * @param minimumLength The length of the shortest allowable field.
+ */
+ public LengthFieldValidator(int minimumLength)
+ {
+ this.minimumLength = minimumLength;
+ }
+
+ /**
+ * Create a validator that checks the minimum and maximum length.
+ *
+ * @param minimumLength The length of the shortest allowable field.
+ * @param maximumLength The length of the longest allowable field.
+ */
+ public LengthFieldValidator(int minimumLength, int maximumLength)
+ {
+ if (minimumLength > maximumLength)
+ {
+ throw new IllegalArgumentException("The minimum length may not be larger than the maximum length.");
+ }
+
+ this.minimumLength = minimumLength;
+ this.maximumLength = maximumLength;
+ }
+
+ @Override
+ public void validate(String field, String fieldName) throws ClassificationException
+ {
+ if (field == null || (field.length() == 0 && minimumLength > 0))
+ {
+ throw new MissingConfiguration(fieldName + " is missing.");
+ }
+ else if (field.length() < minimumLength)
+ {
+ throw new IllegalConfiguration("Illegal " + fieldName + ": Length " + field.length() + " < " + minimumLength);
+ }
+ else if (maximumLength != null && field.length() > maximumLength)
+ {
+ throw new IllegalConfiguration("Illegal " + fieldName + ": Length " + field.length() + " > " + maximumLength);
+ }
+ }
+
+}
diff --git a/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/classification/ClassificationLevelValidationUnitTest.java b/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/classification/validation/ClassificationLevelFieldsValidatorUnitTest.java
similarity index 62%
rename from rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/classification/ClassificationLevelValidationUnitTest.java
rename to rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/classification/validation/ClassificationLevelFieldsValidatorUnitTest.java
index 41354148ce..b3dafd1e7b 100644
--- a/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/classification/ClassificationLevelValidationUnitTest.java
+++ b/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/classification/validation/ClassificationLevelFieldsValidatorUnitTest.java
@@ -16,39 +16,32 @@
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see .
*/
-package org.alfresco.module.org_alfresco_module_rm.classification;
+package org.alfresco.module.org_alfresco_module_rm.classification.validation;
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.classification.validation.FilenameFieldValidator.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.CoreMatchers.containsString;
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.junit.Test;
-
-import java.util.Collections;
import java.util.List;
-/**
- * Unit tests for the {@link ClassificationLevelValidation}.
- *
- * @author Neil Mc Erlean
- */
-public class ClassificationLevelValidationUnitTest
-{
- private final ClassificationLevelValidation validation = new ClassificationLevelValidation();
+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.ClassificationLevel;
+import org.junit.Test;
- @Test(expected=MissingConfiguration.class)
- public void classificationLevelsAreRequired()
- {
- validation.validateLevels(Collections.emptyList());
- }
+/**
+ * Unit tests for the {@link ClassificationLevelFieldsValidator}.
+ *
+ * @author Neil Mc Erlean
+ * @author tpage
+ */
+public class ClassificationLevelFieldsValidatorUnitTest
+{
+ private final ClassificationLevelFieldsValidator validator = new ClassificationLevelFieldsValidator();
/** Ensures that null, empty or whitespace-only IDs are rejected. */
@Test public void nonEmptyAbbreviationsAreMandatory()
@@ -58,7 +51,7 @@ public class ClassificationLevelValidationUnitTest
{
expectedException(IllegalArgumentException.class, () ->
{
- validation.validateLevel(new ClassificationLevel(illegalID, "value.does.not.matter"));
+ validator.validate(new ClassificationLevel(illegalID, "value.does.not.matter"));
return null;
});
}
@@ -67,29 +60,16 @@ public class ClassificationLevelValidationUnitTest
@Test(expected=IllegalConfiguration.class)
public void systemUnclassifiedAbbreviationIsReserved()
{
- validation.validateLevel(new ClassificationLevel("U", "value.does.not.matter"));
+ validator.validate(new ClassificationLevel("U", "value.does.not.matter"));
}
@Test(expected=IllegalConfiguration.class)
public void longAbbreviationsAreIllegal()
{
- validation.validateLevel(new ClassificationLevel("12345678901", "value.does.not.matter"));
+ validator.validate(new ClassificationLevel("12345678901", "value.does.not.matter"));
}
- @Test public void ensureUniquenessOfAbbreviationIds()
- {
- IllegalConfiguration e = expectedException(IllegalConfiguration.class, () ->
- {
- validation.validateLevels(asList(new ClassificationLevel("FOO", "value.does.not.matter"),
- new ClassificationLevel("BAR", "value.does.not.matter"),
- new ClassificationLevel("---", "value.does.not.matter"),
- new ClassificationLevel("BAR", "value.does.not.matter"),
- new ClassificationLevel("FOO", "value.does.not.matter")));
- return null;
- });
- assertThat("Exception message did not identify the duplicate IDs", e.getMessage(),
- allOf(containsString("FOO"), containsString("BAR")));
- }
+
/**
* This test ensures that validation will catch any and all illegal characters in a
@@ -101,7 +81,7 @@ public class ClassificationLevelValidationUnitTest
{
IllegalAbbreviationChars e = expectedException(IllegalAbbreviationChars.class, () ->
{
- validation.validateLevel(new ClassificationLevel("Hello" + illegalChar, "value.does.not.matter"));
+ validator.validate(new ClassificationLevel("Hello" + illegalChar, "value.does.not.matter"));
return null;
});
assertTrue("Exception did not contain helpful example of illegal character",
@@ -113,7 +93,7 @@ public class ClassificationLevelValidationUnitTest
IllegalAbbreviationChars e = expectedException(IllegalAbbreviationChars.class, () ->
{
- validation.validateLevel(new ClassificationLevel(someIllegalChars.toString(),
+ validator.validate(new ClassificationLevel(someIllegalChars.toString(),
"value.does.not.matter"));
return null;
});
diff --git a/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/classification/validation/ClassificationLevelValidationUnitTest.java b/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/classification/validation/ClassificationLevelValidationUnitTest.java
new file mode 100644
index 0000000000..ff1d03b403
--- /dev/null
+++ b/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/classification/validation/ClassificationLevelValidationUnitTest.java
@@ -0,0 +1,64 @@
+/*
+ * 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 .
+ */
+package org.alfresco.module.org_alfresco_module_rm.classification.validation;
+
+import static java.util.Arrays.asList;
+import static org.alfresco.module.org_alfresco_module_rm.test.util.ExceptionUtils.expectedException;
+import static org.hamcrest.CoreMatchers.allOf;
+import static org.hamcrest.CoreMatchers.containsString;
+import static org.junit.Assert.assertThat;
+
+import java.util.Collections;
+
+import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationException;
+import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationLevel;
+import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationException.IllegalConfiguration;
+import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationException.MissingConfiguration;
+import org.junit.Test;
+
+/**
+ * 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 ensureUniquenessOfAbbreviationIds()
+ {
+ IllegalConfiguration e = expectedException(IllegalConfiguration.class, () ->
+ {
+ validation.validateLevels(asList(new ClassificationLevel("FOO", "value.does.not.matter"),
+ new ClassificationLevel("BAR", "value.does.not.matter"),
+ new ClassificationLevel("---", "value.does.not.matter"),
+ new ClassificationLevel("BAR", "value.does.not.matter"),
+ new ClassificationLevel("FOO", "value.does.not.matter")));
+ return null;
+ });
+ assertThat("Exception message did not identify the duplicate IDs", e.getMessage(),
+ allOf(containsString("FOO"), containsString("BAR")));
+ }
+}
diff --git a/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/classification/validation/LengthFieldValidatorUnitTest.java b/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/classification/validation/LengthFieldValidatorUnitTest.java
new file mode 100644
index 0000000000..5f4c05db9f
--- /dev/null
+++ b/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/classification/validation/LengthFieldValidatorUnitTest.java
@@ -0,0 +1,77 @@
+/*
+ * 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 .
+ */
+package org.alfresco.module.org_alfresco_module_rm.classification.validation;
+
+import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationException.IllegalConfiguration;
+import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationException.MissingConfiguration;
+import org.junit.Test;
+
+/**
+ * Unit tests for the {@link LengthFieldValidator}.
+ *
+ * @author tpage
+ * @since 3.0
+ */
+public class LengthFieldValidatorUnitTest
+{
+ private static final String FIELD_NAME = "FIELD_NAME";
+ /** The class under test. */
+ LengthFieldValidator lengthFieldValidator;
+
+ @Test
+ public void testValidate_passMinOnly()
+ {
+ lengthFieldValidator = new LengthFieldValidator(1);
+ lengthFieldValidator.validate("acceptable", FIELD_NAME);
+ }
+
+ @Test(expected = MissingConfiguration.class)
+ public void testValidate_missingConfiguration()
+ {
+ lengthFieldValidator = new LengthFieldValidator(1);
+ lengthFieldValidator.validate("", FIELD_NAME);
+ }
+
+ @Test(expected = IllegalConfiguration.class)
+ public void testValidate_tooShort()
+ {
+ lengthFieldValidator = new LengthFieldValidator(6);
+ lengthFieldValidator.validate("short", FIELD_NAME);
+ }
+
+ @Test
+ public void testValidate_passMinAndMax()
+ {
+ lengthFieldValidator = new LengthFieldValidator(5,5);
+ lengthFieldValidator.validate("super", FIELD_NAME);
+ }
+
+ @Test(expected = IllegalConfiguration.class)
+ public void testValidate_tooLong()
+ {
+ lengthFieldValidator = new LengthFieldValidator(6, 7);
+ lengthFieldValidator.validate("too long", FIELD_NAME);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testValidate_invalidArguments()
+ {
+ lengthFieldValidator = new LengthFieldValidator(3, 1);
+ }
+}