From b083f69c32ff4118b842d9fe46f932dbf33c872a Mon Sep 17 00:00:00 2001 From: Robert Godfrey Date: Sat, 16 Aug 2014 23:56:56 +0000 Subject: QPID-6009 : [Java Broker] Add tests of valid value meta data git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1618433 13f79535-47bb-0310-9956-ffa450edef68 --- .../server/model/ConfiguredAutomatedAttribute.java | 2 + .../model/ConfigureObjectTypeRegistryTest.java | 37 +++++++++++++ .../server/model/testmodel/Test2RootCategory.java | 5 ++ .../model/testmodel/Test2RootCategoryImpl.java | 16 ++++++ .../server/model/testmodel/TestChildCategory.java | 35 +++++++++++++ .../model/testmodel/TestChildCategoryImpl.java | 60 ++++++++++++++++++++++ .../qpid/server/model/testmodel/TestModel.java | 11 ++-- .../server/model/testmodel/TestRootCategory.java | 6 +++ .../model/testmodel/TestRootCategoryImpl.java | 10 ++++ 9 files changed, 179 insertions(+), 3 deletions(-) create mode 100644 qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestChildCategory.java create mode 100644 qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestChildCategoryImpl.java (limited to 'qpid/java') 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 6d73509c40..4ef1d315dd 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 @@ -27,6 +27,7 @@ import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; import java.util.Arrays; import java.util.Collection; +import java.util.Collections; import org.apache.log4j.Logger; @@ -138,6 +139,7 @@ public class ConfiguredAutomatedAttribute extend catch (InvocationTargetException | IllegalAccessException e) { LOGGER.warn("Could not execute the validValues generation method " + _validValuesMethod.getName(), e); + return Collections.emptySet(); } } return Arrays.asList(_annotation.validValues()); diff --git a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/ConfigureObjectTypeRegistryTest.java b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/ConfigureObjectTypeRegistryTest.java index 8bd599f22f..3301c046a8 100644 --- a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/ConfigureObjectTypeRegistryTest.java +++ b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/ConfigureObjectTypeRegistryTest.java @@ -20,12 +20,14 @@ */ package org.apache.qpid.server.model; +import java.util.Arrays; import java.util.Collection; import junit.framework.TestCase; import org.apache.qpid.server.model.testmodel.Test2RootCategory; import org.apache.qpid.server.model.testmodel.Test2RootCategoryImpl; +import org.apache.qpid.server.model.testmodel.TestChildCategory; import org.apache.qpid.server.model.testmodel.TestModel; import org.apache.qpid.server.model.testmodel.TestRootCategory; import org.apache.qpid.server.model.testmodel.TestRootCategoryImpl; @@ -76,6 +78,21 @@ public class ConfigureObjectTypeRegistryTest extends TestCase Test2RootCategory.DEFAULTED_VALUE_DEFAULT); } + public void testValidValues() + { + checkValidValues("validValue",_typeRegistry.getAttributes((Class) TestRootCategoryImpl.class), + Arrays.asList( TestRootCategory.VALID_VALUE1, TestRootCategory.VALID_VALUE2 ) ); + + checkValidValues("validValue", _typeRegistry.getAttributes((Class) Test2RootCategoryImpl.class), + Test2RootCategoryImpl.functionGeneratedValidValues()); + + + checkValidValues("validValueNotInterpolated", _typeRegistry.getAttributes((Class) TestChildCategory.class), + Arrays.asList(TestChildCategory.NON_INTERPOLATED_VALID_VALUE)); + + + } + private void checkDefaultedValue(final Collection> attrs, final String defaultedValueDefault) { @@ -92,4 +109,24 @@ public class ConfigureObjectTypeRegistryTest extends TestCase } assertTrue("Could not find attribute defaultedValue", found); } + + private void checkValidValues(final String attrName, final Collection> attrs, + final Collection validValues) + { + boolean found = false; + for(ConfiguredObjectAttribute attr : attrs) + { + if(attr.getName().equals(attrName)) + { + Collection foundValues = ((ConfiguredAutomatedAttribute) attr).validValues(); + assertEquals("Valid values not as expected, counts differ", validValues.size(), foundValues.size()); + assertTrue("Valid values do not include all expected values", foundValues.containsAll(validValues)); + assertTrue("Valid values contain unexpected addtional values", validValues.containsAll(foundValues)); + found = true; + break; + } + + } + assertTrue("Could not find attribute " + attrName, found); + } } diff --git a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/Test2RootCategory.java b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/Test2RootCategory.java index e47c76cbbb..23f03db507 100644 --- a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/Test2RootCategory.java +++ b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/Test2RootCategory.java @@ -26,10 +26,15 @@ import org.apache.qpid.server.model.ManagedAttribute; public interface Test2RootCategory> extends TestRootCategory { String DEFAULTED_VALUE_DEFAULT = "differentDefault"; + @Override @ManagedAttribute( defaultValue = DEFAULTED_VALUE_DEFAULT) String getDefaultedValue(); + @Override + @ManagedAttribute( validValues = {"org.apache.qpid.server.model.testmodel.Test2RootCategoryImpl#functionGeneratedValidValues()"}) + String getValidValue(); + @DerivedAttribute public int getDerivedAttribute(); } diff --git a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/Test2RootCategoryImpl.java b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/Test2RootCategoryImpl.java index 022e0a256f..e98a9fa3dc 100644 --- a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/Test2RootCategoryImpl.java +++ b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/Test2RootCategoryImpl.java @@ -20,6 +20,8 @@ */ package org.apache.qpid.server.model.testmodel; +import java.util.Collection; +import java.util.Collections; import java.util.Map; import org.apache.qpid.server.configuration.updater.CurrentThreadTaskExecutor; @@ -49,6 +51,9 @@ public class Test2RootCategoryImpl extends AbstractConfiguredObject _mapValue; + @ManagedAttributeField + private String _validValue; + @ManagedObjectFactoryConstructor public Test2RootCategoryImpl(final Map attributes) { @@ -92,6 +97,12 @@ public class Test2RootCategoryImpl extends AbstractConfiguredObject functionGeneratedValidValues() + { + return Collections.singleton("generated"); + } } diff --git a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestChildCategory.java b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestChildCategory.java new file mode 100644 index 0000000000..0c8dcc8744 --- /dev/null +++ b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestChildCategory.java @@ -0,0 +1,35 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.qpid.server.model.testmodel; + +import org.apache.qpid.server.model.ConfiguredObject; +import org.apache.qpid.server.model.ManagedAttribute; +import org.apache.qpid.server.model.ManagedObject; + +@ManagedObject +public interface TestChildCategory> extends ConfiguredObject +{ + + String NON_INTERPOLATED_VALID_VALUE = "${file.separator}"; + + @ManagedAttribute(validValues = { NON_INTERPOLATED_VALID_VALUE }) + String getValidValueNotInterpolated(); +} diff --git a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestChildCategoryImpl.java b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestChildCategoryImpl.java new file mode 100644 index 0000000000..b5a4182f79 --- /dev/null +++ b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestChildCategoryImpl.java @@ -0,0 +1,60 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.qpid.server.model.testmodel; + +import java.util.Map; + +import org.apache.qpid.server.model.AbstractConfiguredObject; +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.State; + +@ManagedObject( category = false , type = "test" ) +public class TestChildCategoryImpl + extends AbstractConfiguredObject implements TestChildCategory +{ + + + @ManagedAttributeField + private String _validValueNotInterpolated; + + + @ManagedObjectFactoryConstructor + public TestChildCategoryImpl(final Map attributes, TestRootCategory parent) + { + super(parentsMap(parent), attributes); + } + + @Override + public State getState() + { + return null; + } + + + + @Override + public String getValidValueNotInterpolated() + { + return _validValueNotInterpolated; + } +} diff --git a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestModel.java b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestModel.java index fc98b51731..ab9d753b7d 100644 --- a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestModel.java +++ b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestModel.java @@ -36,7 +36,8 @@ public class TestModel extends Model private static final Model INSTANCE = new TestModel(); private Class[] _supportedClasses = new Class[] { - TestRootCategory.class + TestRootCategory.class, + TestChildCategory.class }; private final ConfiguredObjectFactory _objectFactory; @@ -77,7 +78,9 @@ public class TestModel extends Model @Override public Collection> getChildTypes(final Class parent) { - return Collections.emptySet(); + return TestRootCategory.class.isAssignableFrom(parent) + ? Collections.>singleton(TestChildCategory.class) + : Collections.>emptySet(); } @Override @@ -89,7 +92,9 @@ public class TestModel extends Model @Override public Collection> getParentTypes(final Class child) { - return Collections.emptySet(); + return TestChildCategory.class.isAssignableFrom(child) + ? Collections.>singleton(TestRootCategory.class) + : Collections.>emptySet(); } @Override diff --git a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestRootCategory.java b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestRootCategory.java index 954fe4dcb1..7f804006b2 100644 --- a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestRootCategory.java +++ b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestRootCategory.java @@ -42,9 +42,15 @@ public interface TestRootCategory> extends Configu String getAutomatedNonPersistedValue(); String DEFAULTED_VALUE_DEFAULT = "myDefaultVar"; + String VALID_VALUE1 = "FOO"; + String VALID_VALUE2 = "BAR"; + @ManagedAttribute( defaultValue = DEFAULTED_VALUE_DEFAULT) String getDefaultedValue(); + @ManagedAttribute(validValues = {VALID_VALUE1, VALID_VALUE2} ) + String getValidValue(); + @ManagedAttribute String getStringValue(); diff --git a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestRootCategoryImpl.java b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestRootCategoryImpl.java index d549086686..0c6a0cb0ca 100644 --- a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestRootCategoryImpl.java +++ b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestRootCategoryImpl.java @@ -49,6 +49,10 @@ public class TestRootCategoryImpl extends AbstractConfiguredObject _mapValue; + @ManagedAttributeField + private String _validValue; + + @ManagedObjectFactoryConstructor public TestRootCategoryImpl(final Map attributes) { @@ -109,4 +113,10 @@ public class TestRootCategoryImpl extends AbstractConfiguredObject