diff options
| author | Robert Godfrey <rgodfrey@apache.org> | 2015-02-02 20:50:15 +0000 |
|---|---|---|
| committer | Robert Godfrey <rgodfrey@apache.org> | 2015-02-02 20:50:15 +0000 |
| commit | 2ff075fb2760b003e29b2a5235519a30a6da9395 (patch) | |
| tree | e39b07e5d0411cba86fecced8f81861c850b6563 /qpid/java/broker-plugins | |
| parent | 144d624d33077723fda55e4640157dde7c56a314 (diff) | |
| download | qpid-python-2ff075fb2760b003e29b2a5235519a30a6da9395.tar.gz | |
QPID-6341 : Add test and allow a default alt text for oversized values
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1656566 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/java/broker-plugins')
2 files changed, 86 insertions, 1 deletions
diff --git a/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/ConfiguredObjectToMapConverter.java b/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/ConfiguredObjectToMapConverter.java index 24fb272186..28bbac2a61 100644 --- a/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/ConfiguredObjectToMapConverter.java +++ b/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/ConfiguredObjectToMapConverter.java @@ -164,7 +164,12 @@ public class ConfiguredObjectToMapConverter String valueString = String.valueOf(value); if(valueString.length() > oversizeThreshold) { - object.put(name, String.valueOf(value).substring(0,oversizeThreshold-4) + "..."); + + String replacementValue = "".equals(attribute.getOversizedAltText()) + ? String.valueOf(value).substring(0, oversizeThreshold - 4) + "..." + : attribute.getOversizedAltText(); + + object.put(name, replacementValue); } else { diff --git a/qpid/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/ConfiguredObjectToMapConverterTest.java b/qpid/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/ConfiguredObjectToMapConverterTest.java index 8687330d49..b5847ad293 100644 --- a/qpid/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/ConfiguredObjectToMapConverterTest.java +++ b/qpid/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/ConfiguredObjectToMapConverterTest.java @@ -28,6 +28,7 @@ import static org.mockito.Mockito.when; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; @@ -216,6 +217,85 @@ public class ConfiguredObjectToMapConverterTest extends TestCase } + public void testOversizedAttributes() + { + + Model model = createTestModel(); + ConfiguredObjectTypeRegistry typeRegistry = model.getTypeRegistry(); + final Map<String, ConfiguredObjectAttribute<?, ?>> attributeTypes = + typeRegistry.getAttributeTypes(TestChild.class); + final ConfiguredObjectAttribute longAttr = mock(ConfiguredObjectAttribute.class); + when(longAttr.isOversized()).thenReturn(true); + when(longAttr.getOversizedAltText()).thenReturn(""); + when(attributeTypes.get(eq("longAttr"))).thenReturn(longAttr); + + TestChild mockChild = mock(TestChild.class); + when(mockChild.getModel()).thenReturn(model); + when(_configuredObject.getModel()).thenReturn(model); + configureMockToReturnOneAttribute(mockChild, "longAttr", "this is not long"); + when(_configuredObject.getChildren(TestChild.class)).thenReturn(Arrays.asList(mockChild)); + + + Map<String, Object> resultMap = _converter.convertObjectToMap(_configuredObject, + ConfiguredObject.class, + 1, + false, + false, + false, + false, + 20); + Object children = resultMap.get("testchilds"); + assertNotNull(children); + assertTrue(children instanceof Collection); + assertTrue(((Collection)children).size()==1); + Object attrs = ((Collection)children).iterator().next(); + assertTrue(attrs instanceof Map); + assertEquals("this is not long", ((Map) attrs).get("longAttr")); + + + + resultMap = _converter.convertObjectToMap(_configuredObject, + ConfiguredObject.class, + 1, + false, + false, + false, + false, + 8); + + children = resultMap.get("testchilds"); + assertNotNull(children); + assertTrue(children instanceof Collection); + assertTrue(((Collection)children).size()==1); + attrs = ((Collection)children).iterator().next(); + assertTrue(attrs instanceof Map); + assertEquals("this...", ((Map) attrs).get("longAttr")); + + + + + when(longAttr.getOversizedAltText()).thenReturn("test alt text"); + + resultMap = _converter.convertObjectToMap(_configuredObject, + ConfiguredObject.class, + 1, + false, + false, + false, + false, + 8); + + children = resultMap.get("testchilds"); + assertNotNull(children); + assertTrue(children instanceof Collection); + assertTrue(((Collection)children).size()==1); + attrs = ((Collection)children).iterator().next(); + assertTrue(attrs instanceof Map); + assertEquals("test alt text", ((Map) attrs).get("longAttr")); + + + } + private Model createTestModel() { Model model = mock(Model.class); |
