summaryrefslogtreecommitdiff
path: root/qpid/java
diff options
context:
space:
mode:
authorRobert Godfrey <rgodfrey@apache.org>2015-02-02 20:50:15 +0000
committerRobert Godfrey <rgodfrey@apache.org>2015-02-02 20:50:15 +0000
commit2ff075fb2760b003e29b2a5235519a30a6da9395 (patch)
treee39b07e5d0411cba86fecced8f81861c850b6563 /qpid/java
parent144d624d33077723fda55e4640157dde7c56a314 (diff)
downloadqpid-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')
-rw-r--r--qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/ConfiguredAutomatedAttribute.java6
-rw-r--r--qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/ConfiguredDerivedAttribute.java7
-rw-r--r--qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/ConfiguredObjectAttribute.java2
-rw-r--r--qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/ManagedAttribute.java1
-rw-r--r--qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/ConfiguredObjectToMapConverter.java7
-rw-r--r--qpid/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/ConfiguredObjectToMapConverterTest.java80
6 files changed, 102 insertions, 1 deletions
diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/ConfiguredAutomatedAttribute.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/ConfiguredAutomatedAttribute.java
index f65688fea7..9fca898dc0 100644
--- a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/ConfiguredAutomatedAttribute.java
+++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/ConfiguredAutomatedAttribute.java
@@ -129,6 +129,12 @@ public class ConfiguredAutomatedAttribute<C extends ConfiguredObject, T> extend
return _annotation.oversize();
}
+ @Override
+ public String getOversizedAltText()
+ {
+ return _annotation.oversizedAltText();
+ }
+
public String getDescription()
{
return _annotation.description();
diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/ConfiguredDerivedAttribute.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/ConfiguredDerivedAttribute.java
index 9a53553c86..71488edb8c 100644
--- a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/ConfiguredDerivedAttribute.java
+++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/ConfiguredDerivedAttribute.java
@@ -60,6 +60,13 @@ public class ConfiguredDerivedAttribute<C extends ConfiguredObject, T> extends
return _annotation.oversize();
}
+ @Override
+ public String getOversizedAltText()
+ {
+ return "";
+ }
+
+
public String getDescription()
{
return _annotation.description();
diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/ConfiguredObjectAttribute.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/ConfiguredObjectAttribute.java
index f03a036191..73b7839a8e 100644
--- a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/ConfiguredObjectAttribute.java
+++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/ConfiguredObjectAttribute.java
@@ -45,6 +45,8 @@ public abstract class ConfiguredObjectAttribute<C extends ConfiguredObject, T> e
public abstract boolean isOversized();
+ public abstract String getOversizedAltText();
+
public abstract String getDescription();
public T convert(final Object value, C object)
diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/ManagedAttribute.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/ManagedAttribute.java
index 75c349d9c0..05b2c610ba 100644
--- a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/ManagedAttribute.java
+++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/ManagedAttribute.java
@@ -36,4 +36,5 @@ public @interface ManagedAttribute
String description() default "";
String[] validValues() default {};
boolean oversize() default false;
+ String oversizedAltText() default "";
}
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);