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 3e4363ac2e..42c3782823 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 @@ -71,6 +71,8 @@ public class ClassificationServiceBootstrap extends AbstractLifecycleBean implem /** Set the object from which configuration options will be read. */ public void setClassificationServiceDAO(ClassificationServiceDAO classificationServiceDAO) { this.classificationServiceDAO = classificationServiceDAO; } public void setAttributeService(AttributeService attributeService) { this.attributeService = attributeService; } + /** Used in unit tests. */ + protected void setClearanceLevelManager(ClearanceLevelManager clearanceLevelManager) { this.clearanceLevelManager = clearanceLevelManager; } public ClassificationLevelManager getClassificationLevelManager() { return classificationLevelManager; } public ClassificationReasonManager getClassificationReasonManager() { return classificationReasonManager; } diff --git a/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/classification/ClassificationServiceBootstrapUnitTest.java b/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/classification/ClassificationServiceBootstrapUnitTest.java index 0ae13faf8d..b327017f36 100644 --- a/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/classification/ClassificationServiceBootstrapUnitTest.java +++ b/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/classification/ClassificationServiceBootstrapUnitTest.java @@ -24,6 +24,7 @@ import static org.junit.Assert.assertTrue; import static org.mockito.Matchers.any; import static org.mockito.Matchers.anyString; import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -98,14 +99,18 @@ public class ClassificationServiceBootstrapUnitTest @Mock ClassificationServiceDAO mockClassificationServiceDAO; @Mock AttributeService mockAttributeService; @Mock AuthenticationUtil mockAuthenticationUtil; + @Mock ClearanceLevelManager mockClearanceLevelManager; /** Using a mock appender in the class logger so that we can verify some of the logging requirements. */ @Mock Appender mockAppender; @Captor ArgumentCaptor loggingEventCaptor; + @Captor ArgumentCaptor> clearanceLevelCaptor; @Before public void setUp() { MockitoAnnotations.initMocks(this); MockAuthenticationUtilHelper.setup(mockAuthenticationUtil); + // This seems to be necessary because the ClearanceLevelManager isn't a constructor argument. + classificationServiceBootstrap.setClearanceLevelManager(mockClearanceLevelManager); } @Test public void defaultLevelsConfigurationVanillaSystem() @@ -223,11 +228,12 @@ public class ClassificationServiceBootstrapUnitTest ClassificationLevel topSecret = new ClassificationLevel("1", "TopSecret"); ClassificationLevel secret = new ClassificationLevel("2", "Secret"); ImmutableList classificationLevels = ImmutableList.of(topSecret, secret, ClassificationLevelManager.UNCLASSIFIED); + doNothing().when(mockClearanceLevelManager).setClearanceLevels(clearanceLevelCaptor.capture()); // Call the method under test. classificationServiceBootstrap.initConfiguredClearanceLevels(classificationLevels); - List clearanceLevels = classificationServiceBootstrap.getClearanceLevelManager().getClearanceLevels(); + List clearanceLevels = clearanceLevelCaptor.getValue(); assertEquals("There should be one clearance level for each classification level.", classificationLevels.size(), clearanceLevels.size()); assertEquals("TopSecret", clearanceLevels.get(0).getDisplayLabel()); assertEquals("Secret", clearanceLevels.get(1).getDisplayLabel());