Author: kwall
Date: Wed Apr 13 08:02:34 2016
New Revision: 1738906
URL: http://svn.apache.org/viewvc?rev=1738906&view=rev
Log:
QPID-7157: [Java Broker] Automatically populate valid values for attributes
that are of an enumerated type, unless otherwise restricted.
Modified:
qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/ConfiguredAutomatedAttribute.java
qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/ConfiguredSettableInjectedAttribute.java
qpid/java/trunk/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/hierarchy/ConfiguredObjectTypeRegistryTest.java
qpid/java/trunk/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/hierarchy/InjectedAttributeTest.java
qpid/java/trunk/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/hierarchy/TestCar.java
qpid/java/trunk/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/hierarchy/TestKitCarImpl.java
qpid/java/trunk/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/hierarchy/TestStandardCarImpl.java
Modified:
qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/ConfiguredAutomatedAttribute.java
URL:
http://svn.apache.org/viewvc/qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/ConfiguredAutomatedAttribute.java?rev=1738906&r1=1738905&r2=1738906&view=diff
==============================================================================
---
qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/ConfiguredAutomatedAttribute.java
(original)
+++
qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/ConfiguredAutomatedAttribute.java
Wed Apr 13 08:02:34 2016
@@ -25,9 +25,11 @@ import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
+import java.util.List;
import java.util.regex.Pattern;
import org.slf4j.Logger;
@@ -188,6 +190,16 @@ public class ConfiguredAutomatedAttribut
return Collections.emptySet();
}
}
+ else if (_annotation.validValues().length == 0 &&
getGetter().getReturnType().isEnum())
+ {
+ final Enum<?>[] constants = (Enum<?>[])
getGetter().getReturnType().getEnumConstants();
+ List<String> validValues = new ArrayList<>(constants.length);
+ for (Enum<?> constant : constants)
+ {
+ validValues.add(constant.name());
+ }
+ return validValues;
+ }
else
{
return Arrays.asList(_annotation.validValues());
Modified:
qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/ConfiguredSettableInjectedAttribute.java
URL:
http://svn.apache.org/viewvc/qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/ConfiguredSettableInjectedAttribute.java?rev=1738906&r1=1738905&r2=1738906&view=diff
==============================================================================
---
qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/ConfiguredSettableInjectedAttribute.java
(original)
+++
qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/ConfiguredSettableInjectedAttribute.java
Wed Apr 13 08:02:34 2016
@@ -25,9 +25,11 @@ import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
+import java.util.List;
import java.util.regex.Pattern;
import org.slf4j.Logger;
@@ -219,6 +221,16 @@ public class ConfiguredSettableInjectedA
return Collections.emptySet();
}
}
+ else if ((_validValues == null || _validValues.length == 0) &&
getType().isEnum())
+ {
+ final Enum<?>[] constants = (Enum<?>[])
getType().getEnumConstants();
+ List<String> validValues = new ArrayList<>(constants.length);
+ for (Enum<?> constant : constants)
+ {
+ validValues.add(constant.name());
+ }
+ return validValues;
+ }
else
{
return _validValues == null ? Collections.<String>emptySet() :
Arrays.asList(_validValues);
Modified:
qpid/java/trunk/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/hierarchy/ConfiguredObjectTypeRegistryTest.java
URL:
http://svn.apache.org/viewvc/qpid/java/trunk/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/hierarchy/ConfiguredObjectTypeRegistryTest.java?rev=1738906&r1=1738905&r2=1738906&view=diff
==============================================================================
---
qpid/java/trunk/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/hierarchy/ConfiguredObjectTypeRegistryTest.java
(original)
+++
qpid/java/trunk/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/hierarchy/ConfiguredObjectTypeRegistryTest.java
Wed Apr 13 08:02:34 2016
@@ -30,9 +30,13 @@ import java.util.HashMap;
import java.util.Map;
import java.util.Set;
+import com.google.common.collect.Lists;
+
import org.apache.qpid.server.model.ConfiguredObject;
+import org.apache.qpid.server.model.ConfiguredObjectAttribute;
import org.apache.qpid.server.model.ConfiguredObjectOperation;
import org.apache.qpid.server.model.ConfiguredObjectTypeRegistry;
+import org.apache.qpid.server.model.ConfiguredSettableAttribute;
import org.apache.qpid.server.model.ManagedInterface;
import org.apache.qpid.test.utils.QpidTestCase;
@@ -121,4 +125,24 @@ public class ConfiguredObjectTypeRegistr
// pass
}
}
+
+ public void testEnumValidValues_UnrestrictedSet() throws Exception
+ {
+ Map<String, ConfiguredObjectAttribute<?, ?>> attributeTypes =
_typeRegistry.getAttributeTypes(TestCar.class);
+ ConfiguredSettableAttribute<?, ?> attribute =
(ConfiguredSettableAttribute<?, ?>) attributeTypes.get("bodyColour");
+
+ assertEquals("The attribute's valid values should match the set of the
enum",
+ Lists.newArrayList("BLACK", "RED", "BLUE", "GREY"),
+ attribute.validValues());
+ }
+
+ public void testEnumValidValues_RestrictedSet() throws Exception
+ {
+ Map<String, ConfiguredObjectAttribute<?, ?>> attributeTypes =
_typeRegistry.getAttributeTypes(TestCar.class);
+ ConfiguredSettableAttribute<?, ?> attribute =
(ConfiguredSettableAttribute<?, ?>) attributeTypes.get("interiorColour");
+
+ assertEquals("The attribute's valid values should match the restricted
set defined on the attribute itself",
+ Lists.newArrayList("GREY", "BLACK"),
+ attribute.validValues());
+ }
}
Modified:
qpid/java/trunk/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/hierarchy/InjectedAttributeTest.java
URL:
http://svn.apache.org/viewvc/qpid/java/trunk/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/hierarchy/InjectedAttributeTest.java?rev=1738906&r1=1738905&r2=1738906&view=diff
==============================================================================
---
qpid/java/trunk/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/hierarchy/InjectedAttributeTest.java
(original)
+++
qpid/java/trunk/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/hierarchy/InjectedAttributeTest.java
Wed Apr 13 08:02:34 2016
@@ -29,8 +29,11 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import com.google.common.collect.Lists;
+
import org.apache.qpid.server.configuration.IllegalConfigurationException;
import org.apache.qpid.server.model.*;
+import org.apache.qpid.server.model.testmodels.hierarchy.TestCar.Colour;
import org.apache.qpid.server.plugin.ConfiguredObjectAttributeInjector;
import org.apache.qpid.test.utils.QpidTestCase;
@@ -194,8 +197,52 @@ public class InjectedAttributeTest exten
{
// pass
}
+ }
+ public void testInjectedSettableAttributeEnumValidValues_Unrestricted()
+ {
+ final ConfiguredSettableInjectedAttribute<?, ?> attribute =
+ new ConfiguredSettableInjectedAttribute<TestCar<?>,
Colour>("trimColour",
+
Colour.class,
+
Colour.class,
+
Colour.BLACK.name(),
+
false,
+
true,
+
false,
+
"",
+
false,
+
"",
+
"",
+
null,
+
"",
+
null);
+ assertEquals("The attribute's valid values should match the set of the
enum",
+ Lists.newArrayList("BLACK", "RED", "BLUE", "GREY"),
+ attribute.validValues());
+ }
+
+ public void testInjectedSettableAttributeEnumValidValues_RestrictedSet()
+ {
+ final ConfiguredSettableInjectedAttribute<?, ?> attribute =
+ new ConfiguredSettableInjectedAttribute<TestCar<?>,
Colour>("trimColour",
+
Colour.class,
+
Colour.class,
+
Colour.BLACK.name(),
+
false,
+
true,
+
false,
+ "",
+
false,
+ "",
+ "",
+
new String[] {Colour.GREY.name(), Colour.BLACK.name()},
+ "",
+
null);
+
+ assertEquals("The attribute's valid values should match the restricted
set defined on the attribute itself",
+ Lists.newArrayList("GREY", "BLACK"),
+ attribute.validValues());
}
public void testInjectedDerivedAttribute() throws Exception
Modified:
qpid/java/trunk/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/hierarchy/TestCar.java
URL:
http://svn.apache.org/viewvc/qpid/java/trunk/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/hierarchy/TestCar.java?rev=1738906&r1=1738905&r2=1738906&view=diff
==============================================================================
---
qpid/java/trunk/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/hierarchy/TestCar.java
(original)
+++
qpid/java/trunk/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/hierarchy/TestCar.java
Wed Apr 13 08:02:34 2016
@@ -21,6 +21,7 @@
package org.apache.qpid.server.model.testmodels.hierarchy;
import org.apache.qpid.server.model.ConfiguredObject;
+import org.apache.qpid.server.model.ManagedAttribute;
import org.apache.qpid.server.model.ManagedContextDefault;
import org.apache.qpid.server.model.ManagedObject;
import org.apache.qpid.server.model.ManagedOperation;
@@ -29,10 +30,19 @@ import org.apache.qpid.server.model.Para
@ManagedObject( defaultType = TestStandardCarImpl.TEST_STANDARD_CAR_TYPE)
public interface TestCar<X extends TestCar<X>> extends ConfiguredObject<X>
{
+ enum Colour { BLACK, RED, BLUE, GREY };
+
String TEST_CONTEXT_VAR = "TEST_CONTEXT_VAR";
@ManagedContextDefault(name = TEST_CONTEXT_VAR)
String testGlobalDefault = "a value ${ancestor:testcar:name}";
+ @ManagedAttribute
+ Colour getBodyColour();
+
+
+ @ManagedAttribute(validValues = {"GREY", "BLACK"})
+ Colour getInteriorColour();
+
enum Door { DRIVER, PASSENGER }
@ManagedOperation
Modified:
qpid/java/trunk/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/hierarchy/TestKitCarImpl.java
URL:
http://svn.apache.org/viewvc/qpid/java/trunk/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/hierarchy/TestKitCarImpl.java?rev=1738906&r1=1738905&r2=1738906&view=diff
==============================================================================
---
qpid/java/trunk/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/hierarchy/TestKitCarImpl.java
(original)
+++
qpid/java/trunk/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/hierarchy/TestKitCarImpl.java
Wed Apr 13 08:02:34 2016
@@ -40,6 +40,12 @@ public class TestKitCarImpl extends Abst
private final SecurityManager _securityManager;
@ManagedAttributeField
+ private Colour _bodyColour;
+
+ @ManagedAttributeField
+ private Colour _interiorColour;
+
+ @ManagedAttributeField
private Map<String,Object> _parameters;
@ManagedAttributeField
@@ -90,4 +96,17 @@ public class TestKitCarImpl extends Abst
{
return _alternateEngine;
}
+
+ @Override
+ public Colour getBodyColour()
+ {
+ return _bodyColour;
+ }
+
+ @Override
+ public Colour getInteriorColour()
+ {
+ return _interiorColour;
+ }
+
}
Modified:
qpid/java/trunk/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/hierarchy/TestStandardCarImpl.java
URL:
http://svn.apache.org/viewvc/qpid/java/trunk/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/hierarchy/TestStandardCarImpl.java?rev=1738906&r1=1738905&r2=1738906&view=diff
==============================================================================
---
qpid/java/trunk/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/hierarchy/TestStandardCarImpl.java
(original)
+++
qpid/java/trunk/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/hierarchy/TestStandardCarImpl.java
Wed Apr 13 08:02:34 2016
@@ -30,6 +30,7 @@ import com.google.common.util.concurrent
import org.apache.qpid.server.configuration.updater.CurrentThreadTaskExecutor;
import org.apache.qpid.server.model.AbstractConfiguredObject;
import org.apache.qpid.server.model.ConfiguredObject;
+import org.apache.qpid.server.model.ManagedAttributeField;
import org.apache.qpid.server.model.ManagedObject;
import org.apache.qpid.server.model.ManagedObjectFactoryConstructor;
import org.apache.qpid.server.model.testmodels.TestSecurityManager;
@@ -44,6 +45,12 @@ public class TestStandardCarImpl extends
public static final String TEST_STANDARD_CAR_TYPE = "testpertrolcar";
private final SecurityManager _securityManager;
+ @ManagedAttributeField
+ private Colour _bodyColour;
+
+ @ManagedAttributeField
+ private Colour _interiorColour;
+
@ManagedObjectFactoryConstructor
public TestStandardCarImpl(final Map<String, Object> attributes)
{
@@ -91,4 +98,16 @@ public class TestStandardCarImpl extends
{
return door;
}
+
+ @Override
+ public Colour getBodyColour()
+ {
+ return _bodyColour;
+ }
+
+ @Override
+ public Colour getInteriorColour()
+ {
+ return _interiorColour;
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]