RM-2027 Unit testing for classification reason loading.

+review RM @nmcerlean

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@100355 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Tom Page
2015-03-27 16:43:59 +00:00
parent 266baccb9d
commit a734159cee
2 changed files with 70 additions and 47 deletions

View File

@@ -18,18 +18,7 @@
*/
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.MockAuthenticationUtilHelper;
import org.alfresco.module.org_alfresco_module_rm.util.AuthenticationUtil;
import org.alfresco.service.cmr.attributes.AttributeService;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import static java.util.Arrays.asList;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
@@ -37,10 +26,19 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyZeroInteractions;
import static org.mockito.Mockito.when;
import static org.junit.Assert.fail;
import static java.util.Arrays.asList;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationServiceException.MissingConfiguration;
import org.alfresco.module.org_alfresco_module_rm.test.util.MockAuthenticationUtilHelper;
import org.alfresco.module.org_alfresco_module_rm.util.AuthenticationUtil;
import org.alfresco.service.cmr.attributes.AttributeService;
import org.junit.Before;
import org.junit.Test;
import org.slf4j.Logger;
/**
* Unit tests for {@link ClassificationServiceImpl}.
@@ -58,8 +56,10 @@ public class ClassificationServiceImplUnitTest
"Executive Management", "EM",
"Employee", "E",
"Public", "P");
private static final List<ClassificationReason> PLACEHOLDER_CLASSIFICATION_REASONS = asList(new ClassificationReason("r1", "l1"),
new ClassificationReason("r2", "l2"));
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"),
new ClassificationReason("id9", "label9"));
/**
* A convenience method for turning lists of level id Strings into lists
* of {@code ClassificationLevel} objects.
@@ -90,13 +90,15 @@ public class ClassificationServiceImplUnitTest
private AttributeService mockedAttributeService = mock(AttributeService.class);
private AuthenticationUtil mockedAuthenticationUtil;
private Configuration mockConfig = mock(Configuration.class);
/** Using a mock logger in the class so that we can verify some of the logging requirements. */
private Logger mockLogger = mock(Logger.class);
@Before public void setUp()
{
reset(mockConfig, mockedAttributeService);
reset(mockConfig, mockedAttributeService, mockLogger);
mockedAuthenticationUtil = MockAuthenticationUtilHelper.create();
classificationService = new ClassificationServiceImpl(mockConfig);
classificationService = new ClassificationServiceImpl(mockConfig, mockLogger);
classificationService.setAttributeService(mockedAttributeService);
classificationService.setAuthenticationUtil(mockedAuthenticationUtil);
}
@@ -146,27 +148,44 @@ public class ClassificationServiceImplUnitTest
anyString(), anyString(), anyString());
}
@Ignore ("This test is currently failing. Needs to be fixed.") // FIXME
@Test public void previouslyStartedSystemShouldProceedNormallyIfConfiguredReasonsHaveNotChanged()
@Test public void checkAttributesNotTouchedIfConfiguredReasonsHaveNotChanged()
{
// There are existing classification reasons stored in the AttributeService.
// 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);
// We'll use a small set of placeholder classification reasons.
when(mockConfig.getConfiguredReasons()).thenReturn(PLACEHOLDER_CLASSIFICATION_REASONS);
classificationService.initConfiguredClassificationReasons();
// This line added to try and work out what the interaction *is*.
verifyZeroInteractions(mockedAttributeService);
verify(mockedAttributeService, never()).setAttribute(any(Serializable.class),
anyString(), anyString(), anyString());
}
@Ignore ("To be implemented") // TODO
/**
* Check that if the reasons supplied on the classpath differ from those already persisted then a warning is logged
* and no change is made to the persisted reasons.
*/
@Test public void previouslyStartedSystemShouldWarnIfConfiguredReasonsHaveChanged()
{
fail("TODO");
// 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);
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());
}
@Test(expected=MissingConfiguration.class)
public void noReasonsFoundCausesException()
{
when(mockedAttributeService.getAttribute(anyString(), anyString(), anyString())).thenReturn(
(Serializable) null);
when(mockConfig.getConfiguredReasons()).thenReturn(null);
classificationService.initConfiguredClassificationReasons();
}
}