From e4551106b672069e603e55c5ae2f433607e96e39 Mon Sep 17 00:00:00 2001 From: Robert Godfrey Date: Tue, 5 Aug 2014 18:13:55 +0000 Subject: QPID-5940 : Make ConfiguredObjectTypeRegistry more easy to test, and add some tests git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1615969 13f79535-47bb-0310-9956-ffa450edef68 --- .../server/model/AbstractConfiguredObject.java | 12 +-- .../server/model/AbstractUnresolvedObject.java | 2 +- .../org/apache/qpid/server/model/BrokerModel.java | 11 ++ .../server/model/ConfiguredObjectTypeRegistry.java | 101 +++++++++--------- .../java/org/apache/qpid/server/model/Model.java | 3 + .../model/ConfigureObjectTypeRegistryTest.java | 95 +++++++++++++++++ .../server/model/testmodel/Test2RootCategory.java | 35 ++++++ .../model/testmodel/Test2RootCategoryImpl.java | 118 +++++++++++++++++++++ .../qpid/server/model/testmodel/TestModel.java | 24 +++++ .../server/management/amqp/ManagementNode.java | 3 +- .../plugin/servlet/rest/MetaDataServlet.java | 5 +- .../action/AbstractSpecialisedAttributeLister.java | 5 +- .../java/org/apache/qpid/systest/rest/Asserts.java | 16 +-- .../rest/AuthenticationProviderRestTest.java | 4 +- .../qpid/systest/rest/BrokerRestHttpsTest.java | 4 +- .../apache/qpid/systest/rest/BrokerRestTest.java | 5 +- .../qpid/systest/rest/ConnectionRestTest.java | 7 +- .../qpid/systest/rest/GroupProviderRestTest.java | 5 +- .../systest/rest/PreferencesProviderRestTest.java | 5 +- .../apache/qpid/systest/rest/QueueRestTest.java | 4 +- 20 files changed, 379 insertions(+), 85 deletions(-) create mode 100644 qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/ConfigureObjectTypeRegistryTest.java create mode 100644 qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/Test2RootCategory.java create mode 100644 qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/Test2RootCategoryImpl.java diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/AbstractConfiguredObject.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/AbstractConfiguredObject.java index 8b9effbd16..6c8945582c 100644 --- a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/AbstractConfiguredObject.java +++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/AbstractConfiguredObject.java @@ -197,9 +197,9 @@ public abstract class AbstractConfiguredObject> im _category = ConfiguredObjectTypeRegistry.getCategory(getClass()); - _attributeTypes = ConfiguredObjectTypeRegistry.getAttributeTypes(getClass()); - _automatedFields = ConfiguredObjectTypeRegistry.getAutomatedFields(getClass()); - _stateChangeMethods = ConfiguredObjectTypeRegistry.getStateChangeMethods(getClass()); + _attributeTypes = model.getTypeRegistry().getAttributeTypes(getClass()); + _automatedFields = model.getTypeRegistry().getAutomatedFields(getClass()); + _stateChangeMethods = model.getTypeRegistry().getStateChangeMethods(getClass()); Object idObj = attributes.get(ID); @@ -1044,7 +1044,7 @@ public abstract class AbstractConfiguredObject> im public final Collection getAttributeNames() { - return ConfiguredObjectTypeRegistry.getAttributeNames(getClass()); + return _model.getTypeRegistry().getAttributeNames(getClass()); } @Override @@ -1369,7 +1369,7 @@ public abstract class AbstractConfiguredObject> im @Override public Map getStatistics() { - Collection stats = ConfiguredObjectTypeRegistry.getStatistics(getClass()); + Collection stats = _model.getTypeRegistry().getStatistics(getClass()); Map map = new HashMap(); for(ConfiguredObjectStatistic stat : stats) { @@ -1439,7 +1439,7 @@ public abstract class AbstractConfiguredObject> im new Strings.MapResolver(inheritedContext), Strings.JAVA_SYS_PROPS_RESOLVER, Strings.ENV_VARS_RESOLVER, - ConfiguredObjectTypeRegistry.getDefaultContextResolver()); + object.getModel().getTypeRegistry().getDefaultContextResolver()); } private static OwnAttributeResolver getOwnAttributeResolver(final ConfiguredObject object) diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/AbstractUnresolvedObject.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/AbstractUnresolvedObject.java index e7e8bdd5e9..df6a6e4cea 100644 --- a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/AbstractUnresolvedObject.java +++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/AbstractUnresolvedObject.java @@ -50,7 +50,7 @@ public abstract class AbstractUnresolvedObject> im _parents = parents; Collection> attributes = - ConfiguredObjectTypeRegistry.getAttributes(clazz); + parents[0].getModel().getTypeRegistry().getAttributes(clazz); for(ConfiguredObjectAttribute attribute : attributes) { if(attribute.isPersisted()) diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/BrokerModel.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/BrokerModel.java index 39a40781dd..2cffea5d73 100644 --- a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/BrokerModel.java +++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/BrokerModel.java @@ -28,6 +28,9 @@ import java.util.HashSet; import java.util.Map; import java.util.Set; +import org.apache.qpid.server.plugin.ConfiguredObjectRegistration; +import org.apache.qpid.server.plugin.QpidServiceLoader; + public final class BrokerModel extends Model { @@ -52,6 +55,7 @@ public final class BrokerModel extends Model private final Set> _supportedTypes = new HashSet>(); + private final ConfiguredObjectTypeRegistry _typeRegistry; private Class _rootCategory; private final ConfiguredObjectFactory _objectFactory; @@ -101,8 +105,15 @@ public final class BrokerModel extends Model addRelationship(Session.class, Publisher.class); _objectFactory = new ConfiguredObjectFactoryImpl(this); + _typeRegistry = new ConfiguredObjectTypeRegistry((new QpidServiceLoader()).instancesOf(ConfiguredObjectRegistration.class), getSupportedCategories()); } + public final ConfiguredObjectTypeRegistry getTypeRegistry() + { + return _typeRegistry; + } + + public static Model getInstance() { return MODEL_INSTANCE; diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/ConfiguredObjectTypeRegistry.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/ConfiguredObjectTypeRegistry.java index 66ae7b2d2e..3201ff16f1 100644 --- a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/ConfiguredObjectTypeRegistry.java +++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/ConfiguredObjectTypeRegistry.java @@ -36,8 +36,8 @@ import java.util.SortedSet; import java.util.TreeSet; import org.apache.log4j.Logger; + import org.apache.qpid.server.plugin.ConfiguredObjectRegistration; -import org.apache.qpid.server.plugin.QpidServiceLoader; import org.apache.qpid.server.util.ServerScopedRuntimeException; import org.apache.qpid.util.Strings; @@ -56,66 +56,71 @@ public class ConfiguredObjectTypeRegistry }; - private static final Map, Collection>> _allAttributes = + private final Map, Collection>> _allAttributes = Collections.synchronizedMap(new HashMap, Collection>>()); - private static final Map, Collection>> _allStatistics = + private final Map, Collection>> _allStatistics = Collections.synchronizedMap(new HashMap, Collection>>()); - private static final Map, Map>> _allAttributeTypes = + private final Map, Map>> _allAttributeTypes = Collections.synchronizedMap(new HashMap, Map>>()); - private static final Map, Map> _allAutomatedFields = + private final Map, Map> _allAutomatedFields = Collections.synchronizedMap(new HashMap, Map>()); - private static final Map _defaultContext = + private final Map _defaultContext = Collections.synchronizedMap(new HashMap()); - private static final Map,Set>> _knownTypes = + private final Map,Set>> _knownTypes = Collections.synchronizedMap(new HashMap, Set>>()); - private static final Map, Collection>> _typeSpecificAttributes = + private final Map, Collection>> _typeSpecificAttributes = Collections.synchronizedMap(new HashMap, Collection>>()); - private static final Map, Map>> _stateChangeMethods = + private final Map, Map>> _stateChangeMethods = Collections.synchronizedMap(new HashMap, Map>>()); - static + public ConfiguredObjectTypeRegistry(Iterable configuredObjectRegistrations, Collection> categoriesRestriction) { - QpidServiceLoader loader = new QpidServiceLoader<>(); Set> categories = new HashSet<>(); Set> types = new HashSet<>(); - for (ConfiguredObjectRegistration registration : loader.instancesOf(ConfiguredObjectRegistration.class)) + for (ConfiguredObjectRegistration registration : configuredObjectRegistrations) { for (Class configuredObjectClass : registration.getConfiguredObjectClasses()) { - try + if(categoriesRestriction.isEmpty() || categoriesRestriction.contains(getCategory(configuredObjectClass))) { - process(configuredObjectClass); - ManagedObject annotation = configuredObjectClass.getAnnotation(ManagedObject.class); - if (annotation.category()) - { - categories.add(configuredObjectClass); - } - else + try { - Class category = getCategory(configuredObjectClass); - if(category != null) + process(configuredObjectClass); + ManagedObject annotation = configuredObjectClass.getAnnotation(ManagedObject.class); + if (annotation.category()) { - categories.add(category); + categories.add(configuredObjectClass); + } + else + { + Class category = getCategory(configuredObjectClass); + if (category != null) + { + categories.add(category); + } + } + if (!"".equals(annotation.type())) + { + types.add(configuredObjectClass); } } - if (!"".equals(annotation.type())) + catch (NoClassDefFoundError ncdfe) { - types.add(configuredObjectClass); + LOGGER.warn("A class definition could not be found while processing the model for '" + + configuredObjectClass.getName() + + "': " + + ncdfe.getMessage()); } } - catch(NoClassDefFoundError ncdfe) - { - LOGGER.warn("A class definition could not be found while processing the model for '" + configuredObjectClass.getName() + "': " + ncdfe.getMessage()); - } } } for (Class categoryClass : categories) @@ -188,7 +193,7 @@ public class ConfiguredObjectTypeRegistry return null; } - public static Class getTypeClass(final Class clazz) + private Class getTypeClass(final Class clazz) { String typeName = getType(clazz); Class typeClass = null; @@ -218,7 +223,7 @@ public class ConfiguredObjectTypeRegistry } - public static Collection> getTypeSpecialisations(Class clazz) + public Collection> getTypeSpecialisations(Class clazz) { Class categoryClass = getCategory(clazz); if(categoryClass == null) @@ -234,7 +239,7 @@ public class ConfiguredObjectTypeRegistry } - public static Collection> getTypeSpecificAttributes(Class clazz) + public Collection> getTypeSpecificAttributes(Class clazz) { Class typeClass = getTypeClass(clazz); if(typeClass == null) @@ -308,7 +313,7 @@ public class ConfiguredObjectTypeRegistry return ""; } - public static Strings.Resolver getDefaultContextResolver() + public Strings.Resolver getDefaultContextResolver() { return new Strings.MapResolver(_defaultContext); } @@ -345,7 +350,7 @@ public class ConfiguredObjectTypeRegistry - private static void process(final Class clazz) + private void process(final Class clazz) { synchronized (_allAttributes) { @@ -451,7 +456,7 @@ public class ConfiguredObjectTypeRegistry } } - private static void initialiseWithParentAttributes(final SortedSet> attributeSet, + private void initialiseWithParentAttributes(final SortedSet> attributeSet, final SortedSet> statisticSet, final Class parent) { @@ -473,7 +478,7 @@ public class ConfiguredObjectTypeRegistry } } - private static void processAttributesTypesAndFields(final Class clazz) + private void processAttributesTypesAndFields(final Class clazz) { Map> attrMap = new HashMap>(); Map fieldMap = new HashMap(); @@ -493,7 +498,7 @@ public class ConfiguredObjectTypeRegistry _allAutomatedFields.put(clazz, fieldMap); } - private static void processDefaultContext(final Class clazz) + private void processDefaultContext(final Class clazz) { for(Field field : clazz.getDeclaredFields()) { @@ -520,7 +525,7 @@ public class ConfiguredObjectTypeRegistry } } - private static void processStateChangeMethods(Class clazz) + private void processStateChangeMethods(Class clazz) { Map> map = new HashMap<>(); @@ -543,7 +548,7 @@ public class ConfiguredObjectTypeRegistry } } - private static void inheritTransitions(final Class parent, + private void inheritTransitions(final Class parent, final Map> map) { Map> parentMap = _stateChangeMethods.get(parent); @@ -567,7 +572,7 @@ public class ConfiguredObjectTypeRegistry } } - private static void addStateTransitions(final Class clazz, + private void addStateTransitions(final Class clazz, final Map> map) { for(Method m : clazz.getDeclaredMethods()) @@ -593,7 +598,7 @@ public class ConfiguredObjectTypeRegistry } } - private static void addStateTransition(final State fromState, + private void addStateTransition(final State fromState, final State toState, final Method method, final Map> map) @@ -614,7 +619,7 @@ public class ConfiguredObjectTypeRegistry } } - private static AutomatedField findField(final ConfiguredObjectAttribute attr, Class objClass) + private AutomatedField findField(final ConfiguredObjectAttribute attr, Class objClass) { Class clazz = objClass; while(clazz != null) @@ -665,7 +670,7 @@ public class ConfiguredObjectTypeRegistry throw new ServerScopedRuntimeException("Unable to find field definition for automated field " + attr.getName() + " in class " + objClass.getName()); } - public static Collection getAttributeNames(Class clazz) + public Collection getAttributeNames(Class clazz) { final Collection> attrs = getAttributes(clazz); @@ -706,7 +711,7 @@ public class ConfiguredObjectTypeRegistry } - protected static Collection> getAttributes(final Class clazz) + protected Collection> getAttributes(final Class clazz) { if(!_allAttributes.containsKey(clazz)) { @@ -717,7 +722,7 @@ public class ConfiguredObjectTypeRegistry } - protected static Collection getStatistics(final Class clazz) + protected Collection getStatistics(final Class clazz) { if(!_allAttributes.containsKey(clazz)) { @@ -728,7 +733,7 @@ public class ConfiguredObjectTypeRegistry } - public static Map> getAttributeTypes(final Class clazz) + public Map> getAttributeTypes(final Class clazz) { if(!_allAttributes.containsKey(clazz)) { @@ -737,7 +742,7 @@ public class ConfiguredObjectTypeRegistry return _allAttributeTypes.get(clazz); } - static Map getAutomatedFields(Class clazz) + Map getAutomatedFields(Class clazz) { if(!_allAttributes.containsKey(clazz)) { @@ -746,7 +751,7 @@ public class ConfiguredObjectTypeRegistry return _allAutomatedFields.get(clazz); } - static Map> getStateChangeMethods(final Class objectClass) + Map> getStateChangeMethods(final Class objectClass) { if(!_allAttributes.containsKey(objectClass)) { diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/Model.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/Model.java index 790ed74afb..9f671b47a8 100644 --- a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/Model.java +++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/Model.java @@ -145,6 +145,7 @@ public abstract class Model return allDescendants.contains(descendantClass); } + public abstract Collection> getSupportedCategories(); public abstract Collection> getChildTypes(Class parent); @@ -156,4 +157,6 @@ public abstract class Model public abstract ConfiguredObjectFactory getObjectFactory(); + public abstract ConfiguredObjectTypeRegistry getTypeRegistry(); + } 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 new file mode 100644 index 0000000000..8bd599f22f --- /dev/null +++ b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/ConfigureObjectTypeRegistryTest.java @@ -0,0 +1,95 @@ +/* + * + * 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; + +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.TestModel; +import org.apache.qpid.server.model.testmodel.TestRootCategory; +import org.apache.qpid.server.model.testmodel.TestRootCategoryImpl; + +public class ConfigureObjectTypeRegistryTest extends TestCase +{ + private ConfiguredObjectTypeRegistry _typeRegistry; + + @Override + public void setUp() throws Exception + { + super.setUp(); + Model model = TestModel.getInstance(); + _typeRegistry = model.getTypeRegistry(); + } + + public void testAllTypesRegistered() + { + Collection> types = + _typeRegistry.getTypeSpecialisations(TestRootCategory.class); + + assertEquals(2, types.size()); + assertTrue(types.contains(TestRootCategoryImpl.class)); + + assertTrue(types.contains(Test2RootCategoryImpl.class)); + } + + public void testTypeSpecificAttributes() + { + Collection> special = + _typeRegistry.getTypeSpecificAttributes(Test2RootCategoryImpl.class); + assertEquals(1, special.size()); + ConfiguredObjectAttribute attr = special.iterator().next(); + assertEquals("derivedAttribute",attr.getName()); + assertTrue(attr.isDerived()); + + special = _typeRegistry.getTypeSpecificAttributes(TestRootCategoryImpl.class); + assertEquals(0, special.size()); + + } + + public void testDefaultedValues() + { + checkDefaultedValue(_typeRegistry.getAttributes((Class) TestRootCategoryImpl.class), + TestRootCategory.DEFAULTED_VALUE_DEFAULT); + + checkDefaultedValue(_typeRegistry.getAttributes((Class) Test2RootCategoryImpl.class), + Test2RootCategory.DEFAULTED_VALUE_DEFAULT); + } + + private void checkDefaultedValue(final Collection> attrs, + final String defaultedValueDefault) + { + boolean found = false; + for(ConfiguredObjectAttribute attr : attrs) + { + if(attr.getName().equals("defaultedValue")) + { + assertEquals(defaultedValueDefault, ((ConfiguredAutomatedAttribute)attr).defaultValue()); + found = true; + break; + } + + } + assertTrue("Could not find attribute defaultedValue", 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 new file mode 100644 index 0000000000..e47c76cbbb --- /dev/null +++ b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/Test2RootCategory.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.DerivedAttribute; +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(); + + @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 new file mode 100644 index 0000000000..022e0a256f --- /dev/null +++ b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/Test2RootCategoryImpl.java @@ -0,0 +1,118 @@ +/* + * + * 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.configuration.updater.CurrentThreadTaskExecutor; +import org.apache.qpid.server.configuration.updater.TaskExecutor; +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 = "test2" ) +public class Test2RootCategoryImpl extends AbstractConfiguredObject + implements Test2RootCategory +{ + @ManagedAttributeField + private String _automatedPersistedValue; + + @ManagedAttributeField + private String _automatedNonPersistedValue; + + @ManagedAttributeField + private String _defaultedValue; + + @ManagedAttributeField + private String _stringValue; + + @ManagedAttributeField + private Map _mapValue; + + @ManagedObjectFactoryConstructor + public Test2RootCategoryImpl(final Map attributes) + { + super(parentsMap(), attributes, newTaskExecutor(), TestModel.getInstance()); + } + + private static CurrentThreadTaskExecutor newTaskExecutor() + { + CurrentThreadTaskExecutor currentThreadTaskExecutor = new CurrentThreadTaskExecutor(); + currentThreadTaskExecutor.start(); + return currentThreadTaskExecutor; + } + + public Test2RootCategoryImpl(final Map attributes, + final TaskExecutor taskExecutor) + { + super(parentsMap(), attributes, taskExecutor); + } + + @Override + protected boolean setState(final State desiredState) + { + return false; + } + + @Override + public String getAutomatedPersistedValue() + { + return _automatedPersistedValue; + } + + @Override + public String getAutomatedNonPersistedValue() + { + return _automatedNonPersistedValue; + } + + @Override + public String getDefaultedValue() + { + return _defaultedValue; + } + + @Override + public int getDerivedAttribute() + { + return 0; + } + + @Override + public String getStringValue() + { + return _stringValue; + } + + @Override + public Map getMapValue() + { + return _mapValue; + } + + @Override + public State getState() + { + return null; + } +} 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 a87ed710a4..fc98b51731 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 @@ -27,7 +27,9 @@ import java.util.Collections; import org.apache.qpid.server.model.ConfiguredObject; import org.apache.qpid.server.model.ConfiguredObjectFactory; import org.apache.qpid.server.model.ConfiguredObjectFactoryImpl; +import org.apache.qpid.server.model.ConfiguredObjectTypeRegistry; import org.apache.qpid.server.model.Model; +import org.apache.qpid.server.plugin.ConfiguredObjectRegistration; public class TestModel extends Model { @@ -38,6 +40,7 @@ public class TestModel extends Model }; private final ConfiguredObjectFactory _objectFactory; + private ConfiguredObjectTypeRegistry _registry; private TestModel() { @@ -47,6 +50,21 @@ public class TestModel extends Model public TestModel(final ConfiguredObjectFactory objectFactory) { _objectFactory = objectFactory == null ? new ConfiguredObjectFactoryImpl(this) : objectFactory; + ConfiguredObjectRegistration configuredObjectRegistration = new ConfiguredObjectRegistration() + { + @Override + public Collection> getConfiguredObjectClasses() + { + return Arrays.>asList(TestRootCategoryImpl.class, Test2RootCategoryImpl.class); + } + + @Override + public String getType() + { + return "test"; + } + }; + _registry = new ConfiguredObjectTypeRegistry(Arrays.asList(configuredObjectRegistration), getSupportedCategories()); } @@ -92,6 +110,12 @@ public class TestModel extends Model return _objectFactory; } + @Override + public ConfiguredObjectTypeRegistry getTypeRegistry() + { + return _registry; + } + public static Model getInstance() { return INSTANCE; diff --git a/qpid/java/broker-plugins/management-amqp/src/main/java/org/apache/qpid/server/management/amqp/ManagementNode.java b/qpid/java/broker-plugins/management-amqp/src/main/java/org/apache/qpid/server/management/amqp/ManagementNode.java index 2c40e536be..e73d177599 100644 --- a/qpid/java/broker-plugins/management-amqp/src/main/java/org/apache/qpid/server/management/amqp/ManagementNode.java +++ b/qpid/java/broker-plugins/management-amqp/src/main/java/org/apache/qpid/server/management/amqp/ManagementNode.java @@ -52,7 +52,6 @@ import org.apache.qpid.server.message.internal.InternalMessage; import org.apache.qpid.server.message.internal.InternalMessageHeader; import org.apache.qpid.server.model.ConfigurationChangeListener; import org.apache.qpid.server.model.ConfiguredObject; -import org.apache.qpid.server.model.ConfiguredObjectTypeRegistry; import org.apache.qpid.server.model.ManagedObject; import org.apache.qpid.server.model.State; import org.apache.qpid.server.plugin.MessageConverter; @@ -236,7 +235,7 @@ class ManagementNode implements MessageSource, MessageDestination } } managedEntityType = new ManagedEntityType(clazz.getName(), parentSet.toArray(new ManagedEntityType[parentSet.size()]), - (String[])(ConfiguredObjectTypeRegistry.getAttributeNames( + (String[])(_managedObject.getModel().getTypeRegistry().getAttributeNames( clazz).toArray(new String[0])), opsList.toArray(new String[opsList.size()])); _entityTypes.put(clazz.getName(),managedEntityType); diff --git a/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/MetaDataServlet.java b/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/MetaDataServlet.java index 0fefa93a81..55c2bf6901 100644 --- a/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/MetaDataServlet.java +++ b/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/MetaDataServlet.java @@ -82,7 +82,8 @@ public class MetaDataServlet extends AbstractServlet private Map processCategory(final Class clazz) { Map typeToDataMap = new TreeMap<>(); - for(Class type : ConfiguredObjectTypeRegistry.getTypeSpecialisations(clazz)) + ConfiguredObjectTypeRegistry typeRegistry = _instance.getTypeRegistry(); + for(Class type : typeRegistry.getTypeSpecialisations(clazz)) { typeToDataMap.put(ConfiguredObjectTypeRegistry.getType(type), processType(type)); } @@ -99,7 +100,7 @@ public class MetaDataServlet extends AbstractServlet private Map processAttributes(final Class type) { Collection> attributes = - ConfiguredObjectTypeRegistry.getAttributeTypes(type).values(); + _instance.getTypeRegistry().getAttributeTypes(type).values(); Map attributeDetails = new LinkedHashMap<>(); for(ConfiguredObjectAttribute attribute : attributes) diff --git a/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/action/AbstractSpecialisedAttributeLister.java b/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/action/AbstractSpecialisedAttributeLister.java index 5d1e7cba21..c697603c6c 100644 --- a/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/action/AbstractSpecialisedAttributeLister.java +++ b/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/action/AbstractSpecialisedAttributeLister.java @@ -42,15 +42,16 @@ abstract class AbstractSpecialisedAttributeLister i @Override final public Object perform(Map request, Broker broker) { + ConfiguredObjectTypeRegistry typeRegistry = broker.getModel().getTypeRegistry(); Collection> groupProviderTypes = - ConfiguredObjectTypeRegistry.getTypeSpecialisations(getCategoryClass()); + typeRegistry.getTypeSpecialisations(getCategoryClass()); Map attributes = new TreeMap(); for (Class groupProviderType : groupProviderTypes) { Collection> typeSpecificAttributes = - ConfiguredObjectTypeRegistry.getTypeSpecificAttributes(groupProviderType); + typeRegistry.getTypeSpecificAttributes(groupProviderType); Map data = new HashMap(); diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/Asserts.java b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/Asserts.java index 3ae32a17ae..7b337580d3 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/Asserts.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/Asserts.java @@ -35,8 +35,8 @@ import junit.framework.TestCase; import org.apache.qpid.client.AMQConnection; import org.apache.qpid.server.model.Binding; import org.apache.qpid.server.model.Broker; +import org.apache.qpid.server.model.BrokerModel; import org.apache.qpid.server.model.ConfiguredObject; -import org.apache.qpid.server.model.ConfiguredObjectTypeRegistry; import org.apache.qpid.server.model.Connection; import org.apache.qpid.server.model.Exchange; import org.apache.qpid.server.model.ExclusivityPolicy; @@ -68,7 +68,7 @@ public class Asserts { assertNotNull("Virtualhost " + virtualHostName + " data are not found", virtualHost); assertAttributesPresent(virtualHost, - ConfiguredObjectTypeRegistry.getAttributeNames(VirtualHost.class), + BrokerModel.getInstance().getTypeRegistry().getAttributeNames(VirtualHost.class), ConfiguredObject.CREATED_BY, ConfiguredObject.CREATED_TIME, ConfiguredObject.LAST_UPDATED_BY, @@ -117,7 +117,7 @@ public class Asserts { assertNotNull("Queue " + queueName + " is not found!", queueData); Asserts.assertAttributesPresent(queueData, - ConfiguredObjectTypeRegistry.getAttributeNames(Queue.class), + BrokerModel.getInstance().getTypeRegistry().getAttributeNames(Queue.class), Queue.CREATED_BY, Queue.CREATED_TIME, Queue.LAST_UPDATED_BY, @@ -224,7 +224,7 @@ public class Asserts { assertNotNull("Unexpected connection data", connectionData); assertAttributesPresent(connectionData, - ConfiguredObjectTypeRegistry.getAttributeNames(Connection.class), + BrokerModel.getInstance().getTypeRegistry().getAttributeNames(Connection.class), Connection.STATE, Connection.DURABLE, Connection.LIFETIME_POLICY, @@ -284,7 +284,7 @@ public class Asserts if ("AMQP".equals(port.get(ConfiguredObject.TYPE))) { assertAttributesPresent(port, - ConfiguredObjectTypeRegistry.getAttributeNames(Port.class), + BrokerModel.getInstance().getTypeRegistry().getAttributeNames(Port.class), ConfiguredObject.TYPE, ConfiguredObject.CREATED_BY, ConfiguredObject.CREATED_TIME, @@ -302,7 +302,7 @@ public class Asserts else { assertAttributesPresent(port, - ConfiguredObjectTypeRegistry.getAttributeNames(Port.class), + BrokerModel.getInstance().getTypeRegistry().getAttributeNames(Port.class), ConfiguredObject.TYPE, ConfiguredObject.CREATED_BY, ConfiguredObject.CREATED_TIME, @@ -340,7 +340,7 @@ public class Asserts public static void assertExchange(String exchangeName, String type, Map exchangeData) { assertNotNull("Exchange " + exchangeName + " is not found!", exchangeData); - assertAttributesPresent(exchangeData, ConfiguredObjectTypeRegistry.getAttributeNames(Exchange.class), + assertAttributesPresent(exchangeData, BrokerModel.getInstance().getTypeRegistry().getAttributeNames(Exchange.class), Exchange.ALTERNATE_EXCHANGE, ConfiguredObject.CREATED_BY, ConfiguredObject.CREATED_TIME, @@ -376,7 +376,7 @@ public class Asserts { assertNotNull("Binding map should not be null", binding); assertAttributesPresent(binding, - ConfiguredObjectTypeRegistry.getAttributeNames(Binding.class), + BrokerModel.getInstance().getTypeRegistry().getAttributeNames(Binding.class), Binding.STATE, ConfiguredObject.TYPE, ConfiguredObject.CREATED_BY, diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/AuthenticationProviderRestTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/AuthenticationProviderRestTest.java index 57d75ecbae..2467705903 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/AuthenticationProviderRestTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/AuthenticationProviderRestTest.java @@ -28,8 +28,8 @@ import java.util.UUID; import org.apache.qpid.server.BrokerOptions; import org.apache.qpid.server.model.AuthenticationProvider; +import org.apache.qpid.server.model.BrokerModel; import org.apache.qpid.server.model.ConfiguredObject; -import org.apache.qpid.server.model.ConfiguredObjectTypeRegistry; import org.apache.qpid.server.model.ExternalFileBasedAuthenticationManager; import org.apache.qpid.server.model.LifetimePolicy; import org.apache.qpid.server.model.Port; @@ -307,7 +307,7 @@ public class AuthenticationProviderRestTest extends QpidRestTestCase private void assertProvider(boolean managesPrincipals, String type, Map provider) { - Asserts.assertAttributesPresent(provider, ConfiguredObjectTypeRegistry.getAttributeNames( + Asserts.assertAttributesPresent(provider, BrokerModel.getInstance().getTypeRegistry().getAttributeNames( AuthenticationProvider.class), AuthenticationProvider.DESCRIPTION, ConfiguredObject.CONTEXT, ConfiguredObject.DESIRED_STATE, ConfiguredObject.CREATED_BY, diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/BrokerRestHttpsTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/BrokerRestHttpsTest.java index f59d9f797f..319cc1c9da 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/BrokerRestHttpsTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/BrokerRestHttpsTest.java @@ -29,8 +29,8 @@ import java.util.HashMap; import java.util.Map; import org.apache.qpid.server.model.Broker; +import org.apache.qpid.server.model.BrokerModel; import org.apache.qpid.server.model.ConfiguredObject; -import org.apache.qpid.server.model.ConfiguredObjectTypeRegistry; import org.apache.qpid.server.model.Port; import org.apache.qpid.server.model.Protocol; import org.apache.qpid.server.model.Transport; @@ -63,7 +63,7 @@ public class BrokerRestHttpsTest extends QpidRestTestCase { Map brokerDetails = getRestTestHelper().getJsonAsSingletonList("broker"); - Asserts.assertAttributesPresent(brokerDetails, ConfiguredObjectTypeRegistry.getAttributeNames(Broker.class), + Asserts.assertAttributesPresent(brokerDetails, BrokerModel.getInstance().getTypeRegistry().getAttributeNames(Broker.class), Broker.PROCESS_PID, ConfiguredObject.TYPE, ConfiguredObject.CREATED_BY, diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/BrokerRestTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/BrokerRestTest.java index 6faca2e32d..bae27b802c 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/BrokerRestTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/BrokerRestTest.java @@ -34,8 +34,8 @@ import javax.jms.TextMessage; import org.apache.qpid.common.QpidProperties; import org.apache.qpid.server.model.Broker; +import org.apache.qpid.server.model.BrokerModel; import org.apache.qpid.server.model.ConfiguredObject; -import org.apache.qpid.server.model.ConfiguredObjectTypeRegistry; import org.apache.qpid.server.model.LifetimePolicy; import org.apache.qpid.server.model.Port; import org.apache.qpid.server.model.State; @@ -201,7 +201,8 @@ public class BrokerRestTest extends QpidRestTestCase protected void assertBrokerAttributes(Map brokerDetails) { - Asserts.assertAttributesPresent(brokerDetails, ConfiguredObjectTypeRegistry.getAttributeNames(Broker.class), + Asserts.assertAttributesPresent(brokerDetails, BrokerModel.getInstance().getTypeRegistry().getAttributeNames( + Broker.class), Broker.PROCESS_PID, ConfiguredObject.TYPE, ConfiguredObject.CREATED_BY, diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/ConnectionRestTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/ConnectionRestTest.java index ad4a370a04..8a7851e43d 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/ConnectionRestTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/ConnectionRestTest.java @@ -32,12 +32,10 @@ import javax.jms.MessageConsumer; import javax.jms.MessageProducer; import javax.servlet.http.HttpServletResponse; -import org.junit.Assert; - import org.apache.qpid.client.AMQConnection; import org.apache.qpid.client.AMQSession; +import org.apache.qpid.server.model.BrokerModel; import org.apache.qpid.server.model.ConfiguredObject; -import org.apache.qpid.server.model.ConfiguredObjectTypeRegistry; import org.apache.qpid.server.model.Connection; import org.apache.qpid.server.model.Session; @@ -232,7 +230,8 @@ public class ConnectionRestTest extends QpidRestTestCase private void assertSession(Map sessionData, AMQSession session) { assertNotNull("Session map cannot be null", sessionData); - Asserts.assertAttributesPresent(sessionData, ConfiguredObjectTypeRegistry.getAttributeNames(Session.class), + Asserts.assertAttributesPresent(sessionData, BrokerModel.getInstance().getTypeRegistry().getAttributeNames( + Session.class), ConfiguredObject.TYPE, ConfiguredObject.CREATED_BY, ConfiguredObject.CREATED_TIME, diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/GroupProviderRestTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/GroupProviderRestTest.java index 7bc2429942..4f1c1ad7a7 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/GroupProviderRestTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/GroupProviderRestTest.java @@ -29,8 +29,8 @@ import java.util.Properties; import java.util.UUID; import org.apache.qpid.server.BrokerOptions; +import org.apache.qpid.server.model.BrokerModel; import org.apache.qpid.server.model.ConfiguredObject; -import org.apache.qpid.server.model.ConfiguredObjectTypeRegistry; import org.apache.qpid.server.model.Group; import org.apache.qpid.server.model.GroupProvider; import org.apache.qpid.server.model.LifetimePolicy; @@ -322,7 +322,8 @@ public class GroupProviderRestTest extends QpidRestTestCase private void assertProvider(String name, String type, Map provider) { - Asserts.assertAttributesPresent(provider, ConfiguredObjectTypeRegistry.getAttributeNames(GroupProvider.class), + Asserts.assertAttributesPresent(provider, BrokerModel.getInstance().getTypeRegistry().getAttributeNames( + GroupProvider.class), ConfiguredObject.TYPE, ConfiguredObject.CREATED_BY, ConfiguredObject.CREATED_TIME, diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/PreferencesProviderRestTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/PreferencesProviderRestTest.java index 1d2b5d8bb5..6db204b9ca 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/PreferencesProviderRestTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/PreferencesProviderRestTest.java @@ -28,8 +28,8 @@ import java.util.List; import java.util.Map; import org.apache.qpid.server.model.AuthenticationProvider; +import org.apache.qpid.server.model.BrokerModel; import org.apache.qpid.server.model.ConfiguredObject; -import org.apache.qpid.server.model.ConfiguredObjectTypeRegistry; import org.apache.qpid.server.model.ExternalFileBasedAuthenticationManager; import org.apache.qpid.server.model.LifetimePolicy; import org.apache.qpid.server.model.PreferencesProvider; @@ -163,7 +163,8 @@ public class PreferencesProviderRestTest extends QpidRestTestCase public void assertProviderCommonAttributes(Map provider) { Asserts.assertAttributesPresent(provider, - ConfiguredObjectTypeRegistry.getAttributeNames(PreferencesProvider.class), + BrokerModel.getInstance().getTypeRegistry().getAttributeNames( + PreferencesProvider.class), ConfiguredObject.CREATED_BY, ConfiguredObject.CREATED_TIME, ConfiguredObject.LAST_UPDATED_BY, diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/QueueRestTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/QueueRestTest.java index db25b91236..baebc9a28e 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/QueueRestTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/QueueRestTest.java @@ -34,8 +34,8 @@ import javax.jms.MessageProducer; import javax.jms.Session; import org.apache.qpid.server.model.Binding; +import org.apache.qpid.server.model.BrokerModel; import org.apache.qpid.server.model.ConfiguredObject; -import org.apache.qpid.server.model.ConfiguredObjectTypeRegistry; import org.apache.qpid.server.model.Consumer; import org.apache.qpid.server.model.LifetimePolicy; import org.apache.qpid.server.model.Queue; @@ -206,7 +206,7 @@ public class QueueRestTest extends QpidRestTestCase { assertNotNull("Consumer map should not be null", consumer); Asserts.assertAttributesPresent(consumer, - ConfiguredObjectTypeRegistry.getAttributeNames(Consumer.class), Consumer.STATE, + BrokerModel.getInstance().getTypeRegistry().getAttributeNames(Consumer.class), Consumer.STATE, Consumer.SETTLEMENT_MODE, Consumer.EXCLUSIVE, Consumer.SELECTOR, Consumer.NO_LOCAL, ConfiguredObject.TYPE, -- cgit v1.2.1