RM-1947 New constraint to avoid invalid classification levels.

Create a service locator class to allow the non-Spring constraint to access
the Spring service.

+review RM-21

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@101788 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Tom Page
2015-04-14 09:33:51 +00:00
parent d6f5fa4f69
commit 3f866a031a
10 changed files with 514 additions and 246 deletions

View File

@@ -0,0 +1,76 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.alfresco.module.org_alfresco_module_rm.classification;
import static org.mockito.Mockito.doReturn;
import java.util.Arrays;
import java.util.List;
import org.alfresco.service.cmr.dictionary.ConstraintException;
import org.junit.Before;
import org.junit.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
/**
* Unit tests for the {@link ClassificationLevelConstraint}.
*
* @author tpage
*/
public class ClassificationLevelConstraintUnitTest
{
private static final ClassificationLevel LEVEL_ONE = new ClassificationLevel("id1", "DisplayKey1");
private static final ClassificationLevel LEVEL_TWO = new ClassificationLevel("id2", "DisplayKey2");
private static final List<ClassificationLevel> DEFAULT_LEVELS = Arrays.asList(LEVEL_ONE, LEVEL_TWO);
@InjectMocks ClassificationLevelConstraint classificationLevelConstraint;
@Mock ClassificationService mockClassificationService;
@Before
public void setUp()
{
MockitoAnnotations.initMocks(this);
// Currently this list of levels suffices for all the tests.
doReturn(DEFAULT_LEVELS).when(mockClassificationService).getClassificationLevels();
}
/** Check that evaluateSingleValue throws no exceptions when an id is found. */
@Test
public void evaluateSingleValue_valid()
{
classificationLevelConstraint.evaluateSingleValue("id1");
}
/** Check that evaluateSingleValue throws an exception when an id is not found. */
@Test(expected = ConstraintException.class)
public void evaluateSingleValue_stringNotFound()
{
classificationLevelConstraint.evaluateSingleValue("non-existant id");
}
/** Check that evaluateSingleValue throws an exception when supplied with something that isn't a String. */
@Test(expected = ConstraintException.class)
public void evaluateSingleValue_notString()
{
classificationLevelConstraint.evaluateSingleValue(Integer.valueOf(123));
}
}

View File

@@ -28,8 +28,9 @@ import org.junit.runners.Suite;
@RunWith(Suite.class)
@Suite.SuiteClasses(
{
ClassificationServiceImplUnitTest.class,
ClassificationServiceDAOUnitTest.class
ClassificationLevelConstraintUnitTest.class,
ClassificationServiceDAOUnitTest.class,
ClassificationServiceImplUnitTest.class
})
public class ClassificationSuite
{