mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Initial creation of ClassificationService, as part of RM-1945 and RM-1946.
This check-in adds the basic ClassificationService API, its initial implementation, ClassificationServiceImpl, along with some basic support types such as ClassificationServiceException (for service-specific exceptions) and Configuration. It also adds unit tests ClassificationServiceImplUnitTest and ConfigurationUnitTest. The ClassificationService begins our support for ‘Classified Records’, whereby Alfresco content can be given a ClassificationLevel and thereafter will only be accessible to users with the appropriate security clearance. The vanilla service includes a default set, rm-classification-levels.json (Top Secret etc) which links through to the i18n’d display data via rm-classification.properties in the usual way. The service is defined in its own spring context file, rm-classified-records-context.xml, as it is distinct from the file plan and should be applicable to content outside that file plan. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@99932 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -0,0 +1,146 @@
|
||||
/*
|
||||
* 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.classification;
|
||||
|
||||
import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationServiceException.MissingConfiguration;
|
||||
import org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest;
|
||||
import org.alfresco.service.cmr.attributes.AttributeService;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mock;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
|
||||
/**
|
||||
* Unit tests for {@link ClassificationServiceImpl}.
|
||||
*
|
||||
* @author Neil Mc Erlean
|
||||
* @since 3.0
|
||||
*/
|
||||
public class ClassificationServiceImplUnitTest extends BaseUnitTest
|
||||
{
|
||||
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");
|
||||
/**
|
||||
* A convenience method for turning lists of level id Strings into lists
|
||||
* of {@code ClassificationLevel} objects.
|
||||
*
|
||||
* @param idsAndLabels A varargs/array of Strings like so: [ id0, label0, id1, label1... ]
|
||||
* @throws IllegalArgumentException if {@code idsAndLabels} has a non-even length.
|
||||
*/
|
||||
public static List<ClassificationLevel> asLevelList(String ... idsAndLabels)
|
||||
{
|
||||
if (idsAndLabels.length % 2 != 0)
|
||||
{
|
||||
throw new IllegalArgumentException(String.format("Cannot create %s objects with %d args.",
|
||||
ClassificationLevel.class.getSimpleName(), idsAndLabels.length));
|
||||
}
|
||||
|
||||
final int resultLength = idsAndLabels.length / 2;
|
||||
final String[] ids = new String[resultLength];
|
||||
final String[] labels = new String[resultLength];
|
||||
|
||||
for (int i = 0; i < idsAndLabels.length; i++)
|
||||
{
|
||||
if (i % 2 == 0) { ids[i / 2] = idsAndLabels[i]; }
|
||||
else { labels[(i - 1) / 2] = idsAndLabels[i]; }
|
||||
}
|
||||
|
||||
final List<ClassificationLevel> levels = new ArrayList<>(resultLength);
|
||||
|
||||
for (int i = 0; i < resultLength; i++)
|
||||
{
|
||||
levels.add(new ClassificationLevel(ids[i], labels[i]));
|
||||
}
|
||||
|
||||
return levels;
|
||||
}
|
||||
|
||||
@Mock(name="attributeService") protected AttributeService mockedAttributeService;
|
||||
|
||||
private ClassificationServiceImpl classificationService;
|
||||
|
||||
@Test public void defaultConfigurationVanillaSystem()
|
||||
{
|
||||
classificationService = new TestClassificationService(null, DEFAULT_CLASSIFICATION_LEVELS);
|
||||
classificationService.setAttributeService(mockedAttributeService);
|
||||
|
||||
classificationService.initConfiguredClassificationLevels();
|
||||
|
||||
assertEquals(DEFAULT_CLASSIFICATION_LEVELS, classificationService.getApplicableLevels());
|
||||
}
|
||||
|
||||
@Test public void alternativeConfigurationVanillaSystem()
|
||||
{
|
||||
classificationService = new TestClassificationService(null, ALT_CLASSIFICATION_LEVELS);
|
||||
classificationService.setAttributeService(mockedAttributeService);
|
||||
|
||||
classificationService.initConfiguredClassificationLevels();
|
||||
|
||||
assertEquals(ALT_CLASSIFICATION_LEVELS, classificationService.getApplicableLevels());
|
||||
}
|
||||
|
||||
@Test public void alternativeConfigurationPreviouslyStartedSystem()
|
||||
{
|
||||
classificationService = new TestClassificationService(DEFAULT_CLASSIFICATION_LEVELS, ALT_CLASSIFICATION_LEVELS);
|
||||
classificationService.setAttributeService(mockedAttributeService);
|
||||
|
||||
classificationService.initConfiguredClassificationLevels();
|
||||
|
||||
assertEquals(ALT_CLASSIFICATION_LEVELS, classificationService.getApplicableLevels());
|
||||
}
|
||||
|
||||
@Test (expected=MissingConfiguration.class)
|
||||
public void missingConfigurationVanillaSystemShouldFail() throws Exception
|
||||
{
|
||||
classificationService = new TestClassificationService(null, null);
|
||||
classificationService.setAttributeService(mockedAttributeService);
|
||||
|
||||
classificationService.initConfiguredClassificationLevels();
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper class for test purposes that allows us to replace the persisted
|
||||
* and configured lists of {@link ClassificationLevel}s.
|
||||
*/
|
||||
private static class TestClassificationService extends ClassificationServiceImpl
|
||||
{
|
||||
private final List<ClassificationLevel> persisted;
|
||||
private final List<ClassificationLevel> configured;
|
||||
public TestClassificationService(List<ClassificationLevel> persisted, List<ClassificationLevel> configured)
|
||||
{
|
||||
this.persisted = persisted;
|
||||
this.configured = configured;
|
||||
}
|
||||
|
||||
@Override List<ClassificationLevel> getPersistedLevels() { return persisted; }
|
||||
@Override List<ClassificationLevel> getConfiguredLevels() { return configured; }
|
||||
}
|
||||
}
|
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* 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.classification;
|
||||
|
||||
import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationServiceException.MalformedConfiguration;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.alfresco.module.org_alfresco_module_rm.classification.ClassificationServiceImplUnitTest.asLevelList;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
|
||||
/**
|
||||
* Unit tests for {@link Configuration}.
|
||||
*
|
||||
* @author Neil Mc Erlean
|
||||
* @since 3.0
|
||||
*/
|
||||
public class ConfigurationUnitTest
|
||||
{
|
||||
private static final List<ClassificationLevel> DEFAULT_CLASSIFICATION_LEVELS = asLevelList("TopSecret", "TS",
|
||||
"Secret", "S",
|
||||
"Confidential", "C",
|
||||
"NoClearance", "NC");
|
||||
|
||||
@Test public void readingDefaultConfigurationShouldWork()
|
||||
{
|
||||
Configuration c = new Configuration(ClassificationServiceImpl.DEFAULT_CONFIG_LOCATION);
|
||||
List<ClassificationLevel> config = c.getConfiguredLevels();
|
||||
assertEquals(DEFAULT_CLASSIFICATION_LEVELS, config);
|
||||
}
|
||||
|
||||
@Test public void readingMissingConfigurationShouldProduceEmptyConfig() throws Exception
|
||||
{
|
||||
Configuration c = new Configuration("/no/such/resource");
|
||||
assertTrue(c.getConfiguredLevels().isEmpty());
|
||||
}
|
||||
|
||||
@Test (expected = MalformedConfiguration.class)
|
||||
public void readingMalformedConfigurationShouldFail() throws Exception
|
||||
{
|
||||
Configuration c = new Configuration("/alfresco/classification/rm-classification-levels-malformed.json");
|
||||
c.getConfiguredLevels();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user