mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
RM-2448 (Extend classified document properties view)
RM-2449 (Extend classified record properties view) +review RM-137 git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@109139 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -115,6 +115,7 @@
|
|||||||
org.alfresco.module.org_alfresco_module_rm.classification.ClassificationSchemeService.getExemptionCategories=ACL_ALLOW
|
org.alfresco.module.org_alfresco_module_rm.classification.ClassificationSchemeService.getExemptionCategories=ACL_ALLOW
|
||||||
org.alfresco.module.org_alfresco_module_rm.classification.ClassificationSchemeService.getReclassification=ACL_ALLOW
|
org.alfresco.module.org_alfresco_module_rm.classification.ClassificationSchemeService.getReclassification=ACL_ALLOW
|
||||||
org.alfresco.module.org_alfresco_module_rm.classification.ClassificationSchemeService.getReclassificationValues=ACL_ALLOW
|
org.alfresco.module.org_alfresco_module_rm.classification.ClassificationSchemeService.getReclassificationValues=ACL_ALLOW
|
||||||
|
org.alfresco.module.org_alfresco_module_rm.classification.ClassificationSchemeService.getExemptionCategoryById=ACL_ALLOW
|
||||||
org.alfresco.module.org_alfresco_module_rm.classification.ClassificationSchemeService.*=ACL_DENY
|
org.alfresco.module.org_alfresco_module_rm.classification.ClassificationSchemeService.*=ACL_DENY
|
||||||
</value>
|
</value>
|
||||||
</property>
|
</property>
|
||||||
|
@@ -941,4 +941,12 @@
|
|||||||
<property name="classificationSchemeService" ref="ClassificationSchemeService" />
|
<property name="classificationSchemeService" ref="ClassificationSchemeService" />
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
|
<bean id="exemptionsCategoriesPropertyDecorator"
|
||||||
|
parent="baseDecorator"
|
||||||
|
class="org.alfresco.repo.jscript.app.ExemptionsCategoriesPropertyDecorator"
|
||||||
|
depends-on="classifiedContentDictionaryBootstrap">
|
||||||
|
<property name="propertyName" value="clf:declassificationExemptions" />
|
||||||
|
<property name="classificationSchemeService" ref="ClassificationSchemeService" />
|
||||||
|
</bean>
|
||||||
|
|
||||||
</beans>
|
</beans>
|
@@ -21,6 +21,7 @@ package org.alfresco.module.org_alfresco_module_rm.classification;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationException.ExemptionCategoryIdNotFound;
|
||||||
import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationException.LevelIdNotFound;
|
import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationException.LevelIdNotFound;
|
||||||
import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationException.ReasonIdNotFound;
|
import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationException.ReasonIdNotFound;
|
||||||
|
|
||||||
@@ -80,6 +81,15 @@ public interface ClassificationSchemeService
|
|||||||
*/
|
*/
|
||||||
List<ExemptionCategory> getExemptionCategories();
|
List<ExemptionCategory> getExemptionCategories();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the exemption category for the given exemption category id
|
||||||
|
*
|
||||||
|
* @param exemptionCategoryId {@link String} The exemption category id for which the exemption category should be retrieved.
|
||||||
|
* @return The exemption category for the given exemption category id
|
||||||
|
* @throws ExemptionCategoryIdNotFound If the given exemption id is not found
|
||||||
|
*/
|
||||||
|
ExemptionCategory getExemptionCategoryById(String exemptionCategoryId) throws ExemptionCategoryIdNotFound;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Identifies the reclassification type for the provided pair of {@link ClassificationLevel levels}.
|
* Identifies the reclassification type for the provided pair of {@link ClassificationLevel levels}.
|
||||||
*
|
*
|
||||||
|
@@ -19,7 +19,6 @@
|
|||||||
package org.alfresco.module.org_alfresco_module_rm.classification;
|
package org.alfresco.module.org_alfresco_module_rm.classification;
|
||||||
|
|
||||||
import static java.util.Collections.unmodifiableSet;
|
import static java.util.Collections.unmodifiableSet;
|
||||||
|
|
||||||
import static org.alfresco.module.org_alfresco_module_rm.util.RMParameterCheck.checkNotBlank;
|
import static org.alfresco.module.org_alfresco_module_rm.util.RMParameterCheck.checkNotBlank;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@@ -27,6 +26,7 @@ import java.util.HashSet;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationException.ExemptionCategoryIdNotFound;
|
||||||
import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationException.LevelIdNotFound;
|
import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationException.LevelIdNotFound;
|
||||||
import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationException.ReasonIdNotFound;
|
import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationException.ReasonIdNotFound;
|
||||||
import org.alfresco.module.org_alfresco_module_rm.classification.model.ClassifiedContentModel;
|
import org.alfresco.module.org_alfresco_module_rm.classification.model.ClassifiedContentModel;
|
||||||
@@ -162,4 +162,14 @@ public class ClassificationSchemeServiceImpl extends ServiceBaseImpl implements
|
|||||||
}
|
}
|
||||||
return unmodifiableSet(result);
|
return unmodifiableSet(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.alfresco.module.org_alfresco_module_rm.classification.ClassificationSchemeService#getExemptionCategoryById(java.lang.String)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public ExemptionCategory getExemptionCategoryById(String exemptionCategoryId) throws ExemptionCategoryIdNotFound
|
||||||
|
{
|
||||||
|
checkNotBlank("exemptionCategoryId", exemptionCategoryId);
|
||||||
|
return exemptionCategoryManager.findCategoryById(exemptionCategoryId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,118 @@
|
|||||||
|
/*
|
||||||
|
* 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.repo.jscript.app;
|
||||||
|
|
||||||
|
import static org.alfresco.util.ParameterCheck.mandatory;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.alfresco.error.AlfrescoRuntimeException;
|
||||||
|
import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationSchemeService;
|
||||||
|
import org.alfresco.module.org_alfresco_module_rm.classification.ExemptionCategory;
|
||||||
|
import org.alfresco.service.cmr.repository.NodeRef;
|
||||||
|
import org.alfresco.service.namespace.QName;
|
||||||
|
import org.json.simple.JSONArray;
|
||||||
|
import org.json.simple.JSONAware;
|
||||||
|
import org.json.simple.JSONObject;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Exemption categories property decorator
|
||||||
|
*
|
||||||
|
* @author Tuna Aksoy
|
||||||
|
* @since 3.0.a
|
||||||
|
*/
|
||||||
|
public class ExemptionsCategoriesPropertyDecorator extends BasePropertyDecorator
|
||||||
|
{
|
||||||
|
/** Constants */
|
||||||
|
protected static final String ID = "id";
|
||||||
|
protected static final String LABEL = "label";
|
||||||
|
protected static final String VALUE = "value";
|
||||||
|
protected static final String DISPLAY_LABEL = "displayLabel";
|
||||||
|
protected static final String FULL_CATEGORY = "fullCategory";
|
||||||
|
|
||||||
|
/** Classification scheme service */
|
||||||
|
private ClassificationSchemeService classificationSchemeService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the classificationSchemeService
|
||||||
|
*/
|
||||||
|
protected ClassificationSchemeService getClassificationSchemeService()
|
||||||
|
{
|
||||||
|
return this.classificationSchemeService;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param classificationSchemeService the classificationSchemeService to set
|
||||||
|
*/
|
||||||
|
public void setClassificationSchemeService(ClassificationSchemeService classificationSchemeService)
|
||||||
|
{
|
||||||
|
this.classificationSchemeService = classificationSchemeService;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.alfresco.repo.jscript.app.PropertyDecorator#decorate(org.alfresco.service.namespace.QName, org.alfresco.service.cmr.repository.NodeRef, java.io.Serializable)
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public JSONAware decorate(QName propertyName, NodeRef nodeRef, Serializable value)
|
||||||
|
{
|
||||||
|
mandatory("value", value);
|
||||||
|
|
||||||
|
JSONArray jsonArray = new JSONArray();
|
||||||
|
JSONArray exemptionCategoryIds = new JSONArray();
|
||||||
|
|
||||||
|
if (value instanceof String)
|
||||||
|
{
|
||||||
|
exemptionCategoryIds = new Gson().fromJson((String) value, JSONArray.class);
|
||||||
|
}
|
||||||
|
else if (value instanceof List)
|
||||||
|
{
|
||||||
|
List<String> values = (List<String>) value;
|
||||||
|
for (String exemptionCategoryId : values)
|
||||||
|
{
|
||||||
|
exemptionCategoryIds.add(exemptionCategoryId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new AlfrescoRuntimeException("Unexpected value instance: '" + value + "'.");
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < exemptionCategoryIds.size(); i++)
|
||||||
|
{
|
||||||
|
String exemptionCategoryId = (String) exemptionCategoryIds.get(i);
|
||||||
|
ExemptionCategory exemptionCategory = getClassificationSchemeService().getExemptionCategoryById(exemptionCategoryId);
|
||||||
|
String exemptionCategoryDisplayLabel = exemptionCategory.getDisplayLabel();
|
||||||
|
String exemptionCategoryFullCategory = exemptionCategoryId + ": " + exemptionCategoryDisplayLabel;
|
||||||
|
|
||||||
|
JSONObject jsonObject = new JSONObject();
|
||||||
|
jsonObject.put(ID, exemptionCategoryId);
|
||||||
|
jsonObject.put(LABEL, exemptionCategoryFullCategory);
|
||||||
|
jsonObject.put(VALUE, exemptionCategoryId);
|
||||||
|
jsonObject.put(DISPLAY_LABEL, exemptionCategoryDisplayLabel);
|
||||||
|
jsonObject.put(FULL_CATEGORY, exemptionCategoryFullCategory);
|
||||||
|
|
||||||
|
jsonArray.add(jsonObject);
|
||||||
|
}
|
||||||
|
|
||||||
|
return jsonArray;
|
||||||
|
}
|
||||||
|
}
|
@@ -27,6 +27,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationException.ExemptionCategoryIdNotFound;
|
||||||
import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationException.LevelIdNotFound;
|
import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationException.LevelIdNotFound;
|
||||||
import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationException.ReasonIdNotFound;
|
import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationException.ReasonIdNotFound;
|
||||||
import org.alfresco.module.org_alfresco_module_rm.test.util.ExceptionUtils;
|
import org.alfresco.module.org_alfresco_module_rm.test.util.ExceptionUtils;
|
||||||
@@ -84,6 +85,7 @@ public class ClassificationSchemeServiceImplUnitTest
|
|||||||
@Mock private DictionaryService mockDictionaryService;
|
@Mock private DictionaryService mockDictionaryService;
|
||||||
@Mock private ClassificationLevelManager mockLevelManager;
|
@Mock private ClassificationLevelManager mockLevelManager;
|
||||||
@Mock private ClassificationReasonManager mockReasonManager;
|
@Mock private ClassificationReasonManager mockReasonManager;
|
||||||
|
@Mock private ExemptionCategoryManager mockExemptionCategoryManager;
|
||||||
@Captor private ArgumentCaptor<Map<QName, Serializable>> propertiesCaptor;
|
@Captor private ArgumentCaptor<Map<QName, Serializable>> propertiesCaptor;
|
||||||
|
|
||||||
@Before public void setUp()
|
@Before public void setUp()
|
||||||
@@ -156,4 +158,21 @@ public class ClassificationSchemeServiceImplUnitTest
|
|||||||
doThrow(new ReasonIdNotFound("Id not found!")).when(mockReasonManager).findReasonById(classificationReasonId);
|
doThrow(new ReasonIdNotFound("Id not found!")).when(mockReasonManager).findReasonById(classificationReasonId);
|
||||||
classificationSchemeServiceImpl.getClassificationReasonById(classificationReasonId);
|
classificationSchemeServiceImpl.getClassificationReasonById(classificationReasonId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getExemptionCategoryById()
|
||||||
|
{
|
||||||
|
String exemptionCategoryId = "exemptionCategoryId";
|
||||||
|
ExemptionCategory exemptionCategory = new ExemptionCategory(exemptionCategoryId, "displayLabelKey");
|
||||||
|
when(mockExemptionCategoryManager.findCategoryById(exemptionCategoryId)).thenReturn(exemptionCategory);
|
||||||
|
classificationSchemeServiceImpl.getExemptionCategoryById(exemptionCategoryId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = ExemptionCategoryIdNotFound.class)
|
||||||
|
public void getExemptionCategoryById_nonExisting()
|
||||||
|
{
|
||||||
|
String exemptionCategoryId = "aRandomId";
|
||||||
|
doThrow(new ExemptionCategoryIdNotFound("Id not found!")).when(mockExemptionCategoryManager).findCategoryById(exemptionCategoryId);
|
||||||
|
classificationSchemeServiceImpl.getExemptionCategoryById(exemptionCategoryId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,169 @@
|
|||||||
|
/*
|
||||||
|
* 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.repo.jscript.app;
|
||||||
|
|
||||||
|
import static org.alfresco.repo.jscript.app.ExemptionsCategoriesPropertyDecorator.DISPLAY_LABEL;
|
||||||
|
import static org.alfresco.repo.jscript.app.ExemptionsCategoriesPropertyDecorator.FULL_CATEGORY;
|
||||||
|
import static org.alfresco.repo.jscript.app.ExemptionsCategoriesPropertyDecorator.ID;
|
||||||
|
import static org.alfresco.repo.jscript.app.ExemptionsCategoriesPropertyDecorator.LABEL;
|
||||||
|
import static org.alfresco.repo.jscript.app.ExemptionsCategoriesPropertyDecorator.VALUE;
|
||||||
|
import static org.alfresco.util.GUID.generate;
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
import static org.mockito.Mockito.doReturn;
|
||||||
|
|
||||||
|
import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationSchemeService;
|
||||||
|
import org.alfresco.module.org_alfresco_module_rm.classification.ExemptionCategory;
|
||||||
|
import org.json.simple.JSONArray;
|
||||||
|
import org.json.simple.JSONObject;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mockito.InjectMocks;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.runners.MockitoJUnitRunner;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.JsonSyntaxException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Exemption categories property decorator unit test
|
||||||
|
*
|
||||||
|
* @author Tuna Aksoy
|
||||||
|
* @since 3.0.a
|
||||||
|
*/
|
||||||
|
@RunWith(MockitoJUnitRunner.class)
|
||||||
|
public class ExemptionCategoriesPropertyDecoratorUnitTest
|
||||||
|
{
|
||||||
|
/** Exemption categories property decorator */
|
||||||
|
private @InjectMocks ExemptionsCategoriesPropertyDecorator decorator = new ExemptionsCategoriesPropertyDecorator();
|
||||||
|
|
||||||
|
/** Mocked classification scheme service */
|
||||||
|
private @Mock ClassificationSchemeService mockedClassificationSchemeService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Given that no exemption category id is supplied
|
||||||
|
* When decorated
|
||||||
|
* Then an {@link IllegalArgumentException} is thrown
|
||||||
|
*/
|
||||||
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
public void testDecoratorWithoutExemptionCategoryId()
|
||||||
|
{
|
||||||
|
decorator.decorate(null, null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Given that an exemption category id in an invalid format is supplied
|
||||||
|
* When decorated
|
||||||
|
* Then an {@link JsonSyntaxException} is thrown
|
||||||
|
*/
|
||||||
|
@Test(expected = JsonSyntaxException.class)
|
||||||
|
public void testDecoratorWithInvalidExemptionCategoryId()
|
||||||
|
{
|
||||||
|
String exemptionCategoryId = generate();
|
||||||
|
String exemptionCategoryDisplayLabel = generate();
|
||||||
|
|
||||||
|
ExemptionCategory exemptionCategory = new ExemptionCategory(exemptionCategoryId, exemptionCategoryDisplayLabel);
|
||||||
|
doReturn(exemptionCategory).when(mockedClassificationSchemeService).getExemptionCategoryById(exemptionCategoryId);
|
||||||
|
|
||||||
|
decorator.decorate(null, null, exemptionCategoryId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Given that an exemption category id is supplied
|
||||||
|
* When decorated
|
||||||
|
* Then the result is a {@link JSONArray} containing the exemption category id, label, value, display label and full category
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
@Test
|
||||||
|
public void testDecoratorWithExemptionCategoryId()
|
||||||
|
{
|
||||||
|
String exemptionCategoryId = generate();
|
||||||
|
String exemptionCategoryDisplayLabel = generate();
|
||||||
|
String exemptionCategoryFullCategory = exemptionCategoryId + ": " + exemptionCategoryDisplayLabel;
|
||||||
|
|
||||||
|
ExemptionCategory exemptionCategory = new ExemptionCategory(exemptionCategoryId, exemptionCategoryDisplayLabel);
|
||||||
|
doReturn(exemptionCategory).when(mockedClassificationSchemeService).getExemptionCategoryById(exemptionCategoryId);
|
||||||
|
|
||||||
|
JSONArray exemptionCategoryIds = new JSONArray();
|
||||||
|
exemptionCategoryIds.add(exemptionCategoryId);
|
||||||
|
|
||||||
|
JSONArray decoratedProperty = (JSONArray) decorator.decorate(null, null, new Gson().toJson(exemptionCategoryIds));
|
||||||
|
assertNotNull(decoratedProperty);
|
||||||
|
assertEquals(1, decoratedProperty.size());
|
||||||
|
|
||||||
|
JSONObject jsonObject = (JSONObject) decoratedProperty.get(0);
|
||||||
|
assertNotNull(jsonObject);
|
||||||
|
|
||||||
|
assertEquals(exemptionCategoryId, jsonObject.get(ID));
|
||||||
|
assertEquals(exemptionCategoryFullCategory, jsonObject.get(LABEL));
|
||||||
|
assertEquals(exemptionCategoryId, jsonObject.get(VALUE));
|
||||||
|
assertEquals(exemptionCategoryDisplayLabel, jsonObject.get(DISPLAY_LABEL));
|
||||||
|
assertEquals(exemptionCategoryFullCategory, jsonObject.get(FULL_CATEGORY));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Given that two exemption category ids are supplied
|
||||||
|
* When decorated
|
||||||
|
* Then the result is a {@link JSONArray} containing the exemption category ids,
|
||||||
|
* labels, values, display labels and full category of both exemption categories
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
@Test
|
||||||
|
public void testDecorateWithMultipleExemptionCategoryIds()
|
||||||
|
{
|
||||||
|
String exemptionCategoryId1 = generate();
|
||||||
|
String exemptionCategoryDisplayLabel1 = generate();
|
||||||
|
String exemptionCategoryIdFullCategory1 = exemptionCategoryId1 + ": " + exemptionCategoryDisplayLabel1;
|
||||||
|
|
||||||
|
String exemptionCategoryId2 = generate();
|
||||||
|
String exemptionCategoryDisplayLabel2 = generate();
|
||||||
|
String exemptionCategoryFullCategory2 = exemptionCategoryId2 + ": " + exemptionCategoryDisplayLabel2;
|
||||||
|
|
||||||
|
ExemptionCategory exemptionCategory1 = new ExemptionCategory(exemptionCategoryId1, exemptionCategoryDisplayLabel1);
|
||||||
|
ExemptionCategory exemptionCategory2 = new ExemptionCategory(exemptionCategoryId2, exemptionCategoryDisplayLabel2);
|
||||||
|
doReturn(exemptionCategory1).when(mockedClassificationSchemeService).getExemptionCategoryById(exemptionCategoryId1);
|
||||||
|
doReturn(exemptionCategory2).when(mockedClassificationSchemeService).getExemptionCategoryById(exemptionCategoryId2);
|
||||||
|
|
||||||
|
JSONArray exemptionCategoryIds = new JSONArray();
|
||||||
|
exemptionCategoryIds.add(exemptionCategoryId1);
|
||||||
|
exemptionCategoryIds.add(exemptionCategoryId2);
|
||||||
|
|
||||||
|
JSONArray decoratedProperty = (JSONArray) decorator.decorate(null, null, new Gson().toJson(exemptionCategoryIds));
|
||||||
|
assertNotNull(decoratedProperty);
|
||||||
|
assertEquals(2, decoratedProperty.size());
|
||||||
|
|
||||||
|
JSONObject jsonObject1 = (JSONObject) decoratedProperty.get(0);
|
||||||
|
assertNotNull(jsonObject1);
|
||||||
|
|
||||||
|
assertEquals(exemptionCategoryId1, jsonObject1.get(ID));
|
||||||
|
assertEquals(exemptionCategoryIdFullCategory1, jsonObject1.get(LABEL));
|
||||||
|
assertEquals(exemptionCategoryId1, jsonObject1.get(VALUE));
|
||||||
|
assertEquals(exemptionCategoryDisplayLabel1, jsonObject1.get(DISPLAY_LABEL));
|
||||||
|
assertEquals(exemptionCategoryIdFullCategory1, jsonObject1.get(FULL_CATEGORY));
|
||||||
|
|
||||||
|
JSONObject jsonObject2 = (JSONObject) decoratedProperty.get(1);
|
||||||
|
assertNotNull(jsonObject2);
|
||||||
|
|
||||||
|
assertEquals(exemptionCategoryId2, jsonObject2.get(ID));
|
||||||
|
assertEquals(exemptionCategoryFullCategory2, jsonObject2.get(LABEL));
|
||||||
|
assertEquals(exemptionCategoryId2, jsonObject2.get(VALUE));
|
||||||
|
assertEquals(exemptionCategoryDisplayLabel2, jsonObject2.get(DISPLAY_LABEL));
|
||||||
|
assertEquals(exemptionCategoryFullCategory2, jsonObject2.get(FULL_CATEGORY));
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user