mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Rename Configuration to ClassificationServiceDAO.
Also formatting changes as per code review comments. +review RM-5 git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@100687 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -29,12 +29,12 @@ import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationS
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link Configuration}.
|
||||
* Unit tests for {@link ClassificationServiceDAO}.
|
||||
*
|
||||
* @author Neil Mc Erlean
|
||||
* @since 3.0
|
||||
*/
|
||||
public class ConfigurationUnitTest
|
||||
public class ClassificationServiceDAOUnitTest
|
||||
{
|
||||
private static final List<ClassificationLevel> DEFAULT_CLASSIFICATION_LEVELS = asLevelList("TopSecret", "TS",
|
||||
"Secret", "S",
|
||||
@@ -43,29 +43,29 @@ public class ConfigurationUnitTest
|
||||
|
||||
@Test public void getConfiguredLevels_readingDefaultConfigurationShouldWork()
|
||||
{
|
||||
Configuration c = new Configuration(ClassificationServiceImpl.DEFAULT_LEVELS_FILE, ClassificationServiceImpl.DEFAULT_REASONS_FILE);
|
||||
ClassificationServiceDAO c = new ClassificationServiceDAO(ClassificationServiceImpl.DEFAULT_LEVELS_FILE, ClassificationServiceImpl.DEFAULT_REASONS_FILE);
|
||||
List<ClassificationLevel> config = c.getConfiguredLevels();
|
||||
assertEquals(DEFAULT_CLASSIFICATION_LEVELS, config);
|
||||
}
|
||||
|
||||
@Test public void getConfiguredLevels_readingMissingConfigurationShouldProduceEmptyConfig() throws Exception
|
||||
{
|
||||
Configuration c = new Configuration("/no/such/resource", "/no/such/resource");
|
||||
ClassificationServiceDAO c = new ClassificationServiceDAO("/no/such/resource", "/no/such/resource");
|
||||
assertTrue(c.getConfiguredLevels().isEmpty());
|
||||
}
|
||||
|
||||
@Test (expected = MalformedConfiguration.class)
|
||||
public void getConfiguredLevels_readingMalformedConfigurationShouldFail()
|
||||
{
|
||||
Configuration c = new Configuration(
|
||||
"/alfresco/classification/rm-classification-levels-malformed.json",
|
||||
"/alfresco/classification/rm-classification-levels-malformed.json");
|
||||
c.getConfiguredLevels();
|
||||
ClassificationServiceDAO c = new ClassificationServiceDAO(
|
||||
"/alfresco/classification/rm-classification-levels-malformed.json",
|
||||
"/alfresco/classification/rm-classification-levels-malformed.json");
|
||||
c.getConfiguredLevels();
|
||||
}
|
||||
|
||||
@Test public void getConfiguredReasons_readingDefaultConfigurationShouldWork()
|
||||
{
|
||||
Configuration c = new Configuration(ClassificationServiceImpl.DEFAULT_LEVELS_FILE,
|
||||
ClassificationServiceDAO c = new ClassificationServiceDAO(ClassificationServiceImpl.DEFAULT_LEVELS_FILE,
|
||||
ClassificationServiceImpl.DEFAULT_REASONS_FILE);
|
||||
List<ClassificationReason> config = c.getConfiguredReasons();
|
||||
assertFalse(config.isEmpty());
|
||||
@@ -73,16 +73,16 @@ public class ConfigurationUnitTest
|
||||
|
||||
@Test public void getConfiguredReasons_readingMissingConfigurationShouldProduceEmptyConfig() throws Exception
|
||||
{
|
||||
Configuration c = new Configuration("/no/such/resource", "/no/such/resource");
|
||||
ClassificationServiceDAO c = new ClassificationServiceDAO("/no/such/resource", "/no/such/resource");
|
||||
assertTrue(c.getConfiguredReasons().isEmpty());
|
||||
}
|
||||
|
||||
@Test (expected = MalformedConfiguration.class)
|
||||
public void getConfiguredReasons_readingMalformedConfigurationShouldFail()
|
||||
{
|
||||
Configuration c = new Configuration(
|
||||
"/alfresco/classification/rm-classification-levels-malformed.json",
|
||||
"/alfresco/classification/rm-classification-levels-malformed.json");
|
||||
c.getConfiguredReasons();
|
||||
ClassificationServiceDAO c = new ClassificationServiceDAO(
|
||||
"/alfresco/classification/rm-classification-levels-malformed.json",
|
||||
"/alfresco/classification/rm-classification-levels-malformed.json");
|
||||
c.getConfiguredReasons();
|
||||
}
|
||||
}
|
@@ -87,25 +87,25 @@ public class ClassificationServiceImplUnitTest
|
||||
|
||||
private ClassificationServiceImpl classificationService;
|
||||
|
||||
private AttributeService mockedAttributeService = mock(AttributeService.class);
|
||||
private AuthenticationUtil mockedAuthenticationUtil;
|
||||
private Configuration mockConfig = mock(Configuration.class);
|
||||
private AttributeService mockedAttributeService = mock(AttributeService.class);
|
||||
private AuthenticationUtil mockedAuthenticationUtil;
|
||||
private ClassificationServiceDAO mockClassificationServiceDAO = mock(ClassificationServiceDAO.class);
|
||||
/** Using a mock logger in the class so that we can verify some of the logging requirements. */
|
||||
private Logger mockLogger = mock(Logger.class);
|
||||
private Logger mockLogger = mock(Logger.class);
|
||||
|
||||
@Before public void setUp()
|
||||
{
|
||||
reset(mockConfig, mockedAttributeService, mockLogger);
|
||||
reset(mockClassificationServiceDAO, mockedAttributeService, mockLogger);
|
||||
mockedAuthenticationUtil = MockAuthenticationUtilHelper.create();
|
||||
|
||||
classificationService = new ClassificationServiceImpl(mockConfig, mockLogger);
|
||||
classificationService = new ClassificationServiceImpl(mockClassificationServiceDAO, mockLogger);
|
||||
classificationService.setAttributeService(mockedAttributeService);
|
||||
classificationService.setAuthenticationUtil(mockedAuthenticationUtil);
|
||||
}
|
||||
|
||||
@Test public void defaultLevelsConfigurationVanillaSystem()
|
||||
{
|
||||
when(mockConfig.getConfiguredLevels()).thenReturn(DEFAULT_CLASSIFICATION_LEVELS);
|
||||
when(mockClassificationServiceDAO.getConfiguredLevels()).thenReturn(DEFAULT_CLASSIFICATION_LEVELS);
|
||||
when(mockedAttributeService.getAttribute(anyString(), anyString(), anyString())).thenReturn(null);
|
||||
|
||||
classificationService.initConfiguredClassificationLevels();
|
||||
@@ -116,7 +116,7 @@ public class ClassificationServiceImplUnitTest
|
||||
|
||||
@Test public void alternativeLevelsConfigurationPreviouslyStartedSystem()
|
||||
{
|
||||
when(mockConfig.getConfiguredLevels()).thenReturn(ALT_CLASSIFICATION_LEVELS);
|
||||
when(mockClassificationServiceDAO.getConfiguredLevels()).thenReturn(ALT_CLASSIFICATION_LEVELS);
|
||||
when(mockedAttributeService.getAttribute(anyString(), anyString(), anyString()))
|
||||
.thenReturn((Serializable) DEFAULT_CLASSIFICATION_LEVELS);
|
||||
|
||||
@@ -140,7 +140,7 @@ public class ClassificationServiceImplUnitTest
|
||||
when(mockedAttributeService.getAttribute(anyString(), anyString(), anyString())).thenReturn(null);
|
||||
|
||||
// We'll use a small set of placeholder classification reasons.
|
||||
when(mockConfig.getConfiguredReasons()).thenReturn(PLACEHOLDER_CLASSIFICATION_REASONS);
|
||||
when(mockClassificationServiceDAO.getConfiguredReasons()).thenReturn(PLACEHOLDER_CLASSIFICATION_REASONS);
|
||||
|
||||
classificationService.initConfiguredClassificationReasons();
|
||||
|
||||
@@ -152,7 +152,7 @@ public class ClassificationServiceImplUnitTest
|
||||
{
|
||||
// The classification reasons stored are the same values that are found on the classpath.
|
||||
when(mockedAttributeService.getAttribute(anyString(), anyString(), anyString())).thenReturn((Serializable)PLACEHOLDER_CLASSIFICATION_REASONS);
|
||||
when(mockConfig.getConfiguredReasons()).thenReturn(PLACEHOLDER_CLASSIFICATION_REASONS);
|
||||
when(mockClassificationServiceDAO.getConfiguredReasons()).thenReturn(PLACEHOLDER_CLASSIFICATION_REASONS);
|
||||
|
||||
classificationService.initConfiguredClassificationReasons();
|
||||
|
||||
@@ -169,23 +169,23 @@ public class ClassificationServiceImplUnitTest
|
||||
// The classification reasons stored are different from those found on the classpath.
|
||||
when(mockedAttributeService.getAttribute(anyString(), anyString(), anyString())).thenReturn(
|
||||
(Serializable) PLACEHOLDER_CLASSIFICATION_REASONS);
|
||||
when(mockConfig.getConfiguredReasons()).thenReturn(ALTERNATIVE_CLASSIFICATION_REASONS);
|
||||
when(mockClassificationServiceDAO.getConfiguredReasons()).thenReturn(ALTERNATIVE_CLASSIFICATION_REASONS);
|
||||
|
||||
classificationService.initConfiguredClassificationReasons();
|
||||
|
||||
verify(mockLogger).warn("Classification reasons configured in classpath do not match those stored in Alfresco."
|
||||
+ "Alfresco will use the unchanged values stored in the database.");
|
||||
verify(mockedAttributeService, never()).setAttribute(any(Serializable.class), anyString(), anyString(),
|
||||
anyString());
|
||||
verify(mockedAttributeService, never()).setAttribute(any(Serializable.class),
|
||||
anyString(), anyString(), anyString());
|
||||
}
|
||||
|
||||
@Test(expected=MissingConfiguration.class)
|
||||
@Test(expected = MissingConfiguration.class)
|
||||
public void noReasonsFoundCausesException()
|
||||
{
|
||||
when(mockedAttributeService.getAttribute(anyString(), anyString(), anyString())).thenReturn(
|
||||
(Serializable) null);
|
||||
when(mockConfig.getConfiguredReasons()).thenReturn(null);
|
||||
|
||||
when(mockedAttributeService.getAttribute(anyString(), anyString(), anyString()))
|
||||
.thenReturn((Serializable) null);
|
||||
when(mockClassificationServiceDAO.getConfiguredReasons()).thenReturn(null);
|
||||
|
||||
classificationService.initConfiguredClassificationReasons();
|
||||
}
|
||||
}
|
||||
|
@@ -29,7 +29,7 @@ import org.junit.runners.Suite;
|
||||
@Suite.SuiteClasses(
|
||||
{
|
||||
ClassificationServiceImplUnitTest.class,
|
||||
ConfigurationUnitTest.class
|
||||
ClassificationServiceDAOUnitTest.class
|
||||
})
|
||||
public class ClassificationSuite
|
||||
{
|
||||
|
Reference in New Issue
Block a user