diff options
| author | Keith Wall <kwall@apache.org> | 2014-12-29 17:08:20 +0000 |
|---|---|---|
| committer | Keith Wall <kwall@apache.org> | 2014-12-29 17:08:20 +0000 |
| commit | 6c07f50f9e9a3f1c620a4ea7dee4f117507261d6 (patch) | |
| tree | 138022a7576e5c06b827e58e4a7ed0ece818c5e1 /qpid/java | |
| parent | 1c420bf20a6902efb0256c881c8b777ccd211b4a (diff) | |
| download | qpid-python-6c07f50f9e9a3f1c620a4ea7dee4f117507261d6.tar.gz | |
QPID-6292: [Java Broker Tests] Refactor AbstractConfiguredObjects unit tests to use several smaller test models
We now have two test models:
* 'singleton' with a single object - used for tests around the behaviour of attributes, context variables etc
* 'hierarchy' with a hierarchy of objects - used to test parent/child interactions, supported child types, and
managed interfaces.
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1648393 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/java')
35 files changed, 1337 insertions, 1356 deletions
diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/plugin/QpidServiceLoader.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/plugin/QpidServiceLoader.java index 9f94e7d09d..f70afb12ba 100644 --- a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/plugin/QpidServiceLoader.java +++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/plugin/QpidServiceLoader.java @@ -84,7 +84,8 @@ public class QpidServiceLoader private boolean isDisabledConfiguredType(final ConfiguredObjectTypeFactory<?> typeFactory) { - return Boolean.getBoolean("qpid.type.disabled:" + typeFactory.getCategoryClass().getSimpleName().toLowerCase() + String simpleName = typeFactory.getCategoryClass().getSimpleName().toLowerCase(); + return Boolean.getBoolean("qpid.type.disabled:" + simpleName + "." + typeFactory.getType()); } } diff --git a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/AbstractConfiguredObjectTest.java b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/AbstractConfiguredObjectTest.java deleted file mode 100644 index d0477a3e34..0000000000 --- a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/AbstractConfiguredObjectTest.java +++ /dev/null @@ -1,620 +0,0 @@ -/* - * - * 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.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; -import java.util.UUID; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicInteger; - -import org.apache.qpid.server.configuration.IllegalConfigurationException; -import org.apache.qpid.server.model.testmodel.TestChildCategory; -import org.apache.qpid.server.model.testmodel.TestChildCategoryImpl; -import org.apache.qpid.server.model.testmodel.TestConfiguredObject; -import org.apache.qpid.server.model.testmodel.TestEnum; -import org.apache.qpid.server.model.testmodel.TestModel; -import org.apache.qpid.server.model.testmodel.TestRootCategory; -import org.apache.qpid.server.model.testmodel.TestRootCategoryImpl; -import org.apache.qpid.server.store.ConfiguredObjectRecord; -import org.apache.qpid.test.utils.QpidTestCase; - -public class AbstractConfiguredObjectTest extends QpidTestCase -{ - private final Model _model = TestModel.getInstance(); - - public void testAttributePersistence() - { - final String objectName = "testNonPersistAttributes"; - TestRootCategory object = - _model.getObjectFactory().create(TestRootCategory.class, - Collections.<String, Object>singletonMap(ConfiguredObject.NAME, - objectName) - ); - - assertEquals(objectName, object.getName()); - assertNull(object.getAutomatedNonPersistedValue()); - assertNull(object.getAutomatedPersistedValue()); - - ConfiguredObjectRecord record = object.asObjectRecord(); - - assertEquals(objectName, record.getAttributes().get(ConfiguredObject.NAME)); - - assertFalse(record.getAttributes().containsKey(TestRootCategory.AUTOMATED_PERSISTED_VALUE)); - assertFalse(record.getAttributes().containsKey(TestRootCategory.AUTOMATED_NONPERSISTED_VALUE)); - - - Map<String, Object> updatedAttributes = new HashMap<>(); - - final String newValue = "newValue"; - - updatedAttributes.put(TestRootCategory.AUTOMATED_PERSISTED_VALUE, newValue); - updatedAttributes.put(TestRootCategory.AUTOMATED_NONPERSISTED_VALUE, newValue); - object.setAttributes(updatedAttributes); - - assertEquals(newValue, object.getAutomatedPersistedValue()); - assertEquals(newValue, object.getAutomatedNonPersistedValue()); - - record = object.asObjectRecord(); - assertEquals(objectName, record.getAttributes().get(ConfiguredObject.NAME)); - assertEquals(newValue, record.getAttributes().get(TestRootCategory.AUTOMATED_PERSISTED_VALUE)); - - assertFalse(record.getAttributes().containsKey(TestRootCategory.AUTOMATED_NONPERSISTED_VALUE)); - - } - - public void testDefaultedAttributeValue() - { - final String objectName = "myName"; - - Map<String, Object> attributes = Collections.<String, Object>singletonMap(ConfiguredObject.NAME, objectName); - - TestRootCategory object1 = _model.getObjectFactory().create(TestRootCategory.class, - attributes); - - assertEquals(objectName, object1.getName()); - assertEquals(TestRootCategory.DEFAULTED_VALUE_DEFAULT, object1.getDefaultedValue()); - } - - public void testOverriddenDefaultedAttributeValue() - { - final String objectName = "myName"; - - Map<String, Object> attributes = new HashMap<>(); - attributes.put(ConfiguredObject.NAME, objectName); - attributes.put(TestRootCategory.DEFAULTED_VALUE, "override"); - - TestRootCategory object = _model.getObjectFactory().create(TestRootCategory.class, - attributes); - - assertEquals(objectName, object.getName()); - assertEquals("override", object.getDefaultedValue()); - - } - - public void testOverriddenDefaultedAttributeValueRevertedToDefault() - { - final String objectName = "myName"; - - Map<String, Object> attributes = new HashMap<>(); - attributes.put(ConfiguredObject.NAME, objectName); - attributes.put(TestRootCategory.DEFAULTED_VALUE, "override"); - - TestRootCategory object = _model.getObjectFactory().create(TestRootCategory.class, - attributes); - - assertEquals(objectName, object.getName()); - assertEquals("override", object.getDefaultedValue()); - - object.setAttributes(Collections.singletonMap(TestRootCategory.DEFAULTED_VALUE, null)); - assertEquals(TestRootCategory.DEFAULTED_VALUE_DEFAULT, object.getDefaultedValue()); - } - - public void testEnumAttributeValueFromString() - { - final String objectName = "myName"; - - Map<String, Object> attributes = new HashMap<>(); - attributes.put(ConfiguredObject.NAME, objectName); - attributes.put(TestRootCategory.ENUM_VALUE, TestEnum.TEST_ENUM1.name()); - - TestRootCategory object1 = _model.getObjectFactory().create(TestRootCategory.class, - attributes); - - assertEquals(objectName, object1.getName()); - assertEquals(TestEnum.TEST_ENUM1, object1.getEnumValue()); - } - - public void testEnumAttributeValueFromEnum() - { - final String objectName = "myName"; - - Map<String, Object> attributes = new HashMap<>(); - attributes.put(ConfiguredObject.NAME, objectName); - attributes.put(TestRootCategory.ENUM_VALUE, TestEnum.TEST_ENUM1); - - TestRootCategory object1 = _model.getObjectFactory().create(TestRootCategory.class, - attributes); - - assertEquals(objectName, object1.getName()); - assertEquals(TestEnum.TEST_ENUM1, object1.getEnumValue()); - } - - public void testStringAttributeValueFromContextVariableProvidedBySystemProperty() - { - String sysPropertyName = "testStringAttributeValueFromContextVariableProvidedBySystemProperty"; - String contextToken = "${" + sysPropertyName + "}"; - - System.setProperty(sysPropertyName, "myValue"); - - final String objectName = "myName"; - - Map<String, Object> attributes = new HashMap<>(); - attributes.put(ConfiguredObject.NAME, objectName); - attributes.put(TestRootCategory.STRING_VALUE, contextToken); - - TestRootCategory object1 = _model.getObjectFactory().create(TestRootCategory.class, - attributes); - - assertEquals(objectName, object1.getName()); - assertEquals("myValue", object1.getStringValue()); - - // System property set empty string - - System.setProperty(sysPropertyName, ""); - TestRootCategory object2 = _model.getObjectFactory().create(TestRootCategory.class, - attributes); - - assertEquals("", object2.getStringValue()); - - // System property not set - System.clearProperty(sysPropertyName); - - TestRootCategory object3 = _model.getObjectFactory().create(TestRootCategory.class, - attributes); - - // yields the unexpanded token - not sure if this is really useful behaviour? - assertEquals(contextToken, object3.getStringValue()); - } - - public void testMapAttributeValueFromContextVariableProvidedBySystemProperty() - { - String sysPropertyName = "testMapAttributeValueFromContextVariableProvidedBySystemProperty"; - String contextToken = "${" + sysPropertyName + "}"; - - Map<String,String> expectedMap = new HashMap<>(); - expectedMap.put("field1", "value1"); - expectedMap.put("field2", "value2"); - - System.setProperty(sysPropertyName, "{ \"field1\" : \"value1\", \"field2\" : \"value2\"}"); - - final String objectName = "myName"; - - Map<String, Object> attributes = new HashMap<>(); - attributes.put(ConfiguredObject.NAME, objectName); - attributes.put(TestRootCategory.MAP_VALUE, contextToken); - - TestRootCategory object1 = _model.getObjectFactory().create(TestRootCategory.class, - attributes); - - assertEquals(objectName, object1.getName()); - assertEquals(expectedMap, object1.getMapValue()); - - // System property not set - System.clearProperty(sysPropertyName); - } - - - public void testDefaultContextIsInContextKeys() - { - final String objectName = "myName"; - - Map<String, Object> attributes = new HashMap<>(); - attributes.put(ConfiguredObject.NAME, objectName); - - - TestRootCategory object = _model.getObjectFactory().create(TestRootCategory.class, - attributes); - - - assertTrue("context default not in contextKeys", - object.getContextKeys(true).contains(TestRootCategory.TEST_CONTEXT_DEFAULT)); - assertEquals(object.getContextValue(String.class, TestRootCategory.TEST_CONTEXT_DEFAULT), "default"); - - setTestSystemProperty(TestRootCategory.TEST_CONTEXT_DEFAULT, "notdefault"); - assertTrue("context default not in contextKeys", - object.getContextKeys(true).contains(TestRootCategory.TEST_CONTEXT_DEFAULT)); - assertEquals(object.getContextValue(String.class, TestRootCategory.TEST_CONTEXT_DEFAULT), "notdefault"); - } - - public void testStringAttributeValueFromContextVariableProvidedObjectsContext() - { - String contextToken = "${myReplacement}"; - - final String objectName = "myName"; - - Map<String, Object> attributes = new HashMap<>(); - attributes.put(ConfiguredObject.NAME, objectName); - attributes.put(ConfiguredObject.CONTEXT, Collections.singletonMap("myReplacement", "myValue")); - attributes.put(TestRootCategory.STRING_VALUE, contextToken); - - TestRootCategory object1 = _model.getObjectFactory().create(TestRootCategory.class, - attributes); - // Check the object's context itself - assertTrue(object1.getContext().containsKey("myReplacement")); - assertEquals("myValue", object1.getContext().get("myReplacement")); - - assertEquals(objectName, object1.getName()); - assertEquals("myValue", object1.getStringValue()); - } - - public void testCreationOfObjectWithInvalidInterpolatedValues() - { - final String parentName = "parent"; - TestRootCategory parent = - _model.getObjectFactory().create(TestRootCategory.class, - Collections.<String, Object>singletonMap(ConfiguredObject.NAME, - parentName) - ); - - parent.setAttributes(Collections.singletonMap(ConfiguredObject.CONTEXT, - Collections.singletonMap("contextVal", "foo"))); - - final Map<String, Object> attributes = new HashMap<>(); - attributes.put("intValue", "${contextVal}"); - attributes.put("name", "child"); - attributes.put("integerSet", "[ ]"); - attributes.put(ConfiguredObject.TYPE, TestChildCategoryImpl.TEST_CHILD_TYPE); - - try - { - _model.getObjectFactory().create(TestChildCategory.class, attributes, parent); - fail("creation of child object should have failed due to invalid value"); - } - catch (IllegalArgumentException e) - { - // PASS - String message = e.getMessage(); - assertTrue("Message does not contain the attribute name", message.contains("intValue")); - assertTrue("Message does not contain the non-interpolated value", message.contains("contextVal")); - assertTrue("Message does not contain the interpolated value", message.contains("foo")); - - } - - assertTrue("Child should not have been registered with parent", - parent.getChildren(TestChildCategory.class).isEmpty()); - } - - public void testCreationOfObjectWithInvalidDefaultValues() - { - final String parentName = "parent"; - TestRootCategory parent = - _model.getObjectFactory().create(TestRootCategory.class, - Collections.<String, Object>singletonMap(ConfiguredObject.NAME, - parentName) - ); - - final Map<String, Object> attributes = new HashMap<>(); - attributes.put("intValue", "1"); - attributes.put("name", "child"); - attributes.put(ConfiguredObject.TYPE, TestChildCategoryImpl.TEST_CHILD_TYPE); - - try - { - _model.getObjectFactory().create(TestChildCategory.class, attributes, parent); - fail("creation of child object should have failed due to invalid value"); - } - catch (IllegalArgumentException e) - { - // PASS - String message = e.getMessage(); - assertTrue("Message does not contain the attribute name", message.contains("integerSet")); - assertTrue("Message does not contain the error value", message.contains("foo")); - - } - - assertTrue("Child should not have been registered with parent", - parent.getChildren(TestChildCategory.class).isEmpty()); - } - - public void testOpeningResultsInErroredStateWhenResolutionFails() throws Exception - { - TestConfiguredObject object = new TestConfiguredObject(getName()); - object.setThrowExceptionOnPostResolve(true); - object.open(); - assertFalse("Unexpected opened", object.isOpened()); - assertEquals("Unexpected state", State.ERRORED, object.getState()); - - object.setThrowExceptionOnPostResolve(false); - object.setAttributes(Collections.<String, Object>singletonMap(Port.DESIRED_STATE, State.ACTIVE)); - assertTrue("Unexpected opened", object.isOpened()); - assertEquals("Unexpected state", State.ACTIVE, object.getState()); - } - - public void testOpeningInERROREDStateAfterFailedOpenOnDesiredStateChangeToActive() throws Exception - { - TestConfiguredObject object = new TestConfiguredObject(getName()); - object.setThrowExceptionOnOpen(true); - object.open(); - assertFalse("Unexpected opened", object.isOpened()); - assertEquals("Unexpected state", State.ERRORED, object.getState()); - - object.setThrowExceptionOnOpen(false); - object.setAttributes(Collections.<String, Object>singletonMap(Port.DESIRED_STATE, State.ACTIVE)); - assertTrue("Unexpected opened", object.isOpened()); - assertEquals("Unexpected state", State.ACTIVE, object.getState()); - } - - public void testOpeningInERROREDStateAfterFailedOpenOnStart() throws Exception - { - TestConfiguredObject object = new TestConfiguredObject(getName()); - object.setThrowExceptionOnOpen(true); - object.open(); - assertFalse("Unexpected opened", object.isOpened()); - assertEquals("Unexpected state", State.ERRORED, object.getState()); - - object.setThrowExceptionOnOpen(false); - object.start(); - assertTrue("Unexpected opened", object.isOpened()); - assertEquals("Unexpected state", State.ACTIVE, object.getState()); - } - - public void testDeletionERROREDStateAfterFailedOpenOnDelete() throws Exception - { - TestConfiguredObject object = new TestConfiguredObject(getName()); - object.setThrowExceptionOnOpen(true); - object.open(); - assertFalse("Unexpected opened", object.isOpened()); - assertEquals("Unexpected state", State.ERRORED, object.getState()); - - object.delete(); - assertFalse("Unexpected opened", object.isOpened()); - assertEquals("Unexpected state", State.DELETED, object.getState()); - } - - public void testDeletionInERROREDStateAfterFailedOpenOnDesiredStateChangeToDelete() throws Exception - { - TestConfiguredObject object = new TestConfiguredObject(getName()); - object.setThrowExceptionOnOpen(true); - object.open(); - assertFalse("Unexpected opened", object.isOpened()); - assertEquals("Unexpected state", State.ERRORED, object.getState()); - - object.setAttributes(Collections.<String, Object>singletonMap(Port.DESIRED_STATE, State.DELETED)); - assertFalse("Unexpected opened", object.isOpened()); - assertEquals("Unexpected state", State.DELETED, object.getState()); - } - - - public void testCreationWithExceptionThrownFromValidationOnCreate() throws Exception - { - TestConfiguredObject object = new TestConfiguredObject(getName()); - object.setThrowExceptionOnValidationOnCreate(true); - try - { - object.create(); - fail("IllegalConfigurationException is expected to be thrown"); - } - catch(IllegalConfigurationException e) - { - //pass - } - assertFalse("Unexpected opened", object.isOpened()); - } - - public void testCreationWithoutExceptionThrownFromValidationOnCreate() throws Exception - { - TestConfiguredObject object = new TestConfiguredObject(getName()); - object.setThrowExceptionOnValidationOnCreate(false); - object.create(); - assertTrue("Unexpected opened", object.isOpened()); - assertEquals("Unexpected state", State.ACTIVE, object.getState()); - } - - public void testCreationWithExceptionThrownFromOnOpen() throws Exception - { - TestConfiguredObject object = new TestConfiguredObject(getName()); - object.setThrowExceptionOnOpen(true); - try - { - object.create(); - fail("Exception should have been re-thrown"); - } - catch (RuntimeException re) - { - // pass - } - - assertFalse("Unexpected opened", object.isOpened()); - assertEquals("Unexpected state", State.DELETED, object.getState()); - } - - public void testCreationWithExceptionThrownFromOnCreate() throws Exception - { - TestConfiguredObject object = new TestConfiguredObject(getName()); - object.setThrowExceptionOnCreate(true); - try - { - object.create(); - fail("Exception should have been re-thrown"); - } - catch (RuntimeException re) - { - // pass - } - - assertFalse("Unexpected opened", object.isOpened()); - assertEquals("Unexpected state", State.DELETED, object.getState()); - } - - public void testUnresolvedChildInERROREDStateIsNotValidatedOrOpenedOrAttainedDesiredStateOnParentOpen() throws Exception - { - TestConfiguredObject parent = new TestConfiguredObject("parent"); - TestConfiguredObject child1 = new TestConfiguredObject("child1", parent, parent.getTaskExecutor()); - child1.registerWithParents(); - TestConfiguredObject child2 = new TestConfiguredObject("child2", parent, parent.getTaskExecutor()); - child2.registerWithParents(); - - child1.setThrowExceptionOnPostResolve(true); - - parent.open(); - - assertTrue("Parent should be resolved", parent.isResolved()); - assertTrue("Parent should be validated", parent.isValidated()); - assertTrue("Parent should be opened", parent.isOpened()); - assertEquals("Unexpected parent state", State.ACTIVE, parent.getState()); - - assertTrue("Child2 should be resolved", child2.isResolved()); - assertTrue("Child2 should be validated", child2.isValidated()); - assertTrue("Child2 should be opened", child2.isOpened()); - assertEquals("Unexpected child2 state", State.ACTIVE, child2.getState()); - - assertFalse("Child2 should not be resolved", child1.isResolved()); - assertFalse("Child1 should not be validated", child1.isValidated()); - assertFalse("Child1 should not be opened", child1.isOpened()); - assertEquals("Unexpected child1 state", State.ERRORED, child1.getState()); - } - - public void testUnvalidatedChildInERROREDStateIsNotOpenedOrAttainedDesiredStateOnParentOpen() throws Exception - { - TestConfiguredObject parent = new TestConfiguredObject("parent"); - TestConfiguredObject child1 = new TestConfiguredObject("child1", parent, parent.getTaskExecutor()); - child1.registerWithParents(); - TestConfiguredObject child2 = new TestConfiguredObject("child2", parent, parent.getTaskExecutor()); - child2.registerWithParents(); - - child1.setThrowExceptionOnValidate(true); - - parent.open(); - - assertTrue("Parent should be resolved", parent.isResolved()); - assertTrue("Parent should be validated", parent.isValidated()); - assertTrue("Parent should be opened", parent.isOpened()); - assertEquals("Unexpected parent state", State.ACTIVE, parent.getState()); - - assertTrue("Child2 should be resolved", child2.isResolved()); - assertTrue("Child2 should be validated", child2.isValidated()); - assertTrue("Child2 should be opened", child2.isOpened()); - assertEquals("Unexpected child2 state", State.ACTIVE, child2.getState()); - - assertTrue("Child1 should be resolved", child1.isResolved()); - assertFalse("Child1 should not be validated", child1.isValidated()); - assertFalse("Child1 should not be opened", child1.isOpened()); - assertEquals("Unexpected child1 state", State.ERRORED, child1.getState()); - } - - public void testCreateEnforcesAttributeValidValues() throws Exception - { - final String objectName = getName(); - Map<String, Object> illegalCreateAttributes = new HashMap<>(); - illegalCreateAttributes.put(ConfiguredObject.NAME, objectName); - illegalCreateAttributes.put(TestRootCategory.VALID_VALUE, "illegal"); - - try - { - _model.getObjectFactory().create(TestRootCategory.class, illegalCreateAttributes); - fail("Exception not thrown"); - } - catch (IllegalConfigurationException ice) - { - // PASS - } - - Map<String, Object> legalCreateAttributes = new HashMap<>(); - legalCreateAttributes.put(ConfiguredObject.NAME, objectName); - legalCreateAttributes.put(TestRootCategory.VALID_VALUE, TestRootCategory.VALID_VALUE1); - - TestRootCategory object = _model.getObjectFactory().create(TestRootCategory.class, legalCreateAttributes); - assertEquals(TestRootCategory.VALID_VALUE1, object.getValidValue()); - } - - public void testChangeEnforcesAttributeValidValues() throws Exception - { - final String objectName = getName(); - Map<String, Object> legalCreateAttributes = new HashMap<>(); - legalCreateAttributes.put(ConfiguredObject.NAME, objectName); - legalCreateAttributes.put(TestRootCategory.VALID_VALUE, TestRootCategory.VALID_VALUE1); - - TestRootCategory object = _model.getObjectFactory().create(TestRootCategory.class, legalCreateAttributes); - assertEquals(TestRootCategory.VALID_VALUE1, object.getValidValue()); - - object.setAttributes(Collections.singletonMap(TestRootCategory.VALID_VALUE,TestRootCategory.VALID_VALUE2)); - assertEquals(TestRootCategory.VALID_VALUE2, object.getValidValue()); - - try - { - object.setAttributes(Collections.singletonMap(TestRootCategory.VALID_VALUE, "illegal")); - fail("Exception not thrown"); - } - catch (IllegalConfigurationException iae) - { - // PASS - } - - assertEquals(TestRootCategory.VALID_VALUE2, object.getValidValue()); - - object.setAttributes(Collections.singletonMap(TestRootCategory.VALID_VALUE,null)); - assertNull(object.getValidValue()); - - } - - public void testCreateEnforcesAttributeValidValuesWithSets() throws Exception - { - final String objectName = getName(); - final Map<String, Object> name = Collections.singletonMap(ConfiguredObject.NAME, (Object)objectName); - - Map<String, Object> illegalCreateAttributes = new HashMap<>(name); - illegalCreateAttributes.put(TestRootCategory.ENUMSET_VALUES, Collections.singleton(TestEnum.TEST_ENUM3)); - - try - { - _model.getObjectFactory().create(TestRootCategory.class, illegalCreateAttributes); - fail("Exception not thrown"); - } - catch (IllegalConfigurationException ice) - { - // PASS - } - - { - Map<String, Object> legalCreateAttributesEnums = new HashMap<>(name); - legalCreateAttributesEnums.put(TestRootCategory.ENUMSET_VALUES, - Arrays.asList(TestEnum.TEST_ENUM2, TestEnum.TEST_ENUM3)); - - TestRootCategory obj = _model.getObjectFactory().create(TestRootCategory.class, legalCreateAttributesEnums); - assertTrue(obj.getEnumSetValues().containsAll(Arrays.asList(TestEnum.TEST_ENUM2, TestEnum.TEST_ENUM3))); - } - - { - Map<String, Object> legalCreateAttributesStrings = new HashMap<>(name); - legalCreateAttributesStrings.put(TestRootCategory.ENUMSET_VALUES, - Arrays.asList(TestEnum.TEST_ENUM2.name(), TestEnum.TEST_ENUM3.name())); - - TestRootCategory obj = _model.getObjectFactory().create(TestRootCategory.class, legalCreateAttributesStrings); - assertTrue(obj.getEnumSetValues().containsAll(Arrays.asList(TestEnum.TEST_ENUM2, TestEnum.TEST_ENUM3))); - } - } -} diff --git a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/AttributeValueConverterTest.java b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/AttributeValueConverterTest.java index 8ddcb179cc..a257a7a208 100644 --- a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/AttributeValueConverterTest.java +++ b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/AttributeValueConverterTest.java @@ -37,8 +37,8 @@ import java.util.Set; import junit.framework.TestCase; -import org.apache.qpid.server.model.testmodel.TestModel; -import org.apache.qpid.server.model.testmodel.TestRootCategory; +import org.apache.qpid.server.model.testmodels.hierarchy.TestModel; +import org.apache.qpid.server.model.testmodels.hierarchy.TestCar; public class AttributeValueConverterTest extends TestCase { @@ -61,7 +61,7 @@ public class AttributeValueConverterTest extends TestCase _context.put("mapWithInterpolatedContents", "{\"${mykey}\" : \"b\"}"); _context.put("mykey", "mykey1"); - ConfiguredObject object = _objectFactory.create(TestRootCategory.class, _attributes); + ConfiguredObject object = _objectFactory.create(TestCar.class, _attributes); AttributeValueConverter<Map> mapConverter = getConverter(Map.class, Map.class); @@ -96,7 +96,7 @@ public class AttributeValueConverterTest extends TestCase { _context.put("simpleCollection", "[\"a\", \"b\"]"); - ConfiguredObject object = _objectFactory.create(TestRootCategory.class, _attributes); + ConfiguredObject object = _objectFactory.create(TestCar.class, _attributes); AttributeValueConverter<Collection> collectionConverter = getConverter(Collection.class, Collection.class); @@ -131,7 +131,7 @@ public class AttributeValueConverterTest extends TestCase { _context.put("simpleList", "[\"a\", \"b\"]"); - ConfiguredObject object = _objectFactory.create(TestRootCategory.class, _attributes); + ConfiguredObject object = _objectFactory.create(TestCar.class, _attributes); AttributeValueConverter<List> listConverter = getConverter(List.class, List.class); @@ -164,7 +164,7 @@ public class AttributeValueConverterTest extends TestCase { _context.put("simpleSet", "[\"a\", \"b\"]"); - ConfiguredObject object = _objectFactory.create(TestRootCategory.class, _attributes); + ConfiguredObject object = _objectFactory.create(TestCar.class, _attributes); AttributeValueConverter<Set> setConverter = getConverter(Set.class, Set.class);; diff --git a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/ConfiguredObjectTypeRegistryTest.java b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/ConfiguredObjectTypeRegistryTest.java deleted file mode 100644 index 174966c4c0..0000000000 --- a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/ConfiguredObjectTypeRegistryTest.java +++ /dev/null @@ -1,218 +0,0 @@ -/* - * - * 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 static org.hamcrest.CoreMatchers.hasItem; -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; -import java.util.Set; - -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.TestManagedClass0; -import org.apache.qpid.server.model.testmodel.TestManagedClass1; -import org.apache.qpid.server.model.testmodel.TestManagedClass2; -import org.apache.qpid.server.model.testmodel.TestManagedClass3; -import org.apache.qpid.server.model.testmodel.TestManagedClass4; -import org.apache.qpid.server.model.testmodel.TestManagedClass5; -import org.apache.qpid.server.model.testmodel.TestManagedInterface1; -import org.apache.qpid.server.model.testmodel.TestManagedInterface3; -import org.apache.qpid.server.model.testmodel.TestModel; -import org.apache.qpid.server.model.testmodel.TestRootCategory; -import org.apache.qpid.server.model.testmodel.TestRootCategoryImpl; -import org.apache.qpid.server.plugin.ConfiguredObjectRegistration; - -public class ConfiguredObjectTypeRegistryTest extends TestCase -{ - private ConfiguredObjectTypeRegistry _typeRegistry; - - @Override - public void setUp() throws Exception - { - super.setUp(); - Model model = TestModel.getInstance(); - _typeRegistry = model.getTypeRegistry(); - } - - public void testAllTypesRegistered() - { - Collection<Class<? extends ConfiguredObject>> types = - _typeRegistry.getTypeSpecialisations(TestRootCategory.class); - - assertEquals(2, types.size()); - assertTrue(types.contains(TestRootCategoryImpl.class)); - - assertTrue(types.contains(Test2RootCategoryImpl.class)); - } - - public void testTypeSpecificAttributes() - { - Collection<ConfiguredObjectAttribute<?, ?>> 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); - } - - 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)); - - - } - - public void testGetManagedInterfacesForTypeNotImplementingManagedInterfaceAndNotHavingManagedAnnotation() - { - ConfiguredObjectTypeRegistry typeRegistry = createConfiguredObjectTypeRegistry(TestRootCategoryImpl.class); - assertEquals("Unexpected interfaces from object not implementing Managed interfaces", - Collections.emptySet(), typeRegistry.getManagedInterfaces(TestRootCategory.class)); - } - - public void testGetManagedInterfacesForTypeImplementingManagedInterfaceButNotHavingManagedAnnotation() - { - ConfiguredObjectTypeRegistry typeRegistry = createConfiguredObjectTypeRegistry(TestRootCategoryImpl.class, TestManagedClass5.class); - assertEquals("Unexpected interfaces from object not implementing Managed interfaces", - Collections.emptySet(), typeRegistry.getManagedInterfaces(TestManagedClass5.class)); - } - - public void testGetManagedInterfacesForTypesImplementingManagedInterfacesWithManagedAnnotation() - { - ConfiguredObjectTypeRegistry typeRegistry = createConfiguredObjectTypeRegistry(TestRootCategoryImpl.class, TestManagedClass0.class, TestManagedClass1.class, TestManagedClass4.class); - Set<Class<?>> expected = Collections.<Class<?>>singleton(TestManagedInterface1.class); - assertEquals("Unexpected interfaces on child class", expected, typeRegistry.getManagedInterfaces(TestManagedClass1.class)); - assertEquals("Unexpected interfaces on super class", expected, typeRegistry.getManagedInterfaces(TestManagedClass0.class)); - assertEquals("Unexpected interfaces on class implementing interface with annotation twice", - expected, typeRegistry.getManagedInterfaces(TestManagedClass4.class)); - } - - public void testGetManagedInterfacesForTypeHavingDirectManagedAnnotation() - { - ConfiguredObjectTypeRegistry typeRegistry = createConfiguredObjectTypeRegistry(TestRootCategoryImpl.class, TestManagedClass2.class, TestManagedClass3.class); - - assertEquals("Unexpected interfaces on class implementing 1 interface with annotation", - new HashSet<>(Arrays.asList(TestManagedInterface1.class)), typeRegistry.getManagedInterfaces(TestManagedClass2.class)); - assertEquals("Unexpected interfaces on class implementing 2 interfaces with annotation", - new HashSet<>(Arrays.asList(TestManagedInterface3.class, TestManagedInterface1.class)), - typeRegistry.getManagedInterfaces(TestManagedClass3.class)); - - } - - public void testGetValidChildTypes() - { - Collection<String> validTypes = _typeRegistry.getValidChildTypes(TestRootCategory.class, - TestChildCategory.class); - assertThat(validTypes, hasItem("testchild")); - assertThat(validTypes.size(), is(1)); - } - - - private ConfiguredObjectTypeRegistry createConfiguredObjectTypeRegistry(Class<? extends ConfiguredObject>... supportedTypes) - { - ConfiguredObjectRegistration configuredObjectRegistration = createConfiguredObjectRegistration(supportedTypes); - - return new ConfiguredObjectTypeRegistry(Arrays.asList(configuredObjectRegistration), Arrays.asList(TestRootCategory.class, TestChildCategory.class)); - } - - private ConfiguredObjectRegistration createConfiguredObjectRegistration(final Class<? extends ConfiguredObject>... supportedTypes) - { - return new ConfiguredObjectRegistration() - { - @Override - public Collection<Class<? extends ConfiguredObject>> getConfiguredObjectClasses() - { - return Arrays.asList(supportedTypes); - } - - @Override - public String getType() - { - return "test"; - } - }; - } - - private void checkDefaultedValue(final Collection<ConfiguredObjectAttribute<?, ?>> 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); - } - - private void checkValidValues(final String attrName, final Collection<ConfiguredObjectAttribute<?, ?>> attrs, - final Collection<String> validValues) - { - boolean found = false; - for(ConfiguredObjectAttribute<?, ?> attr : attrs) - { - if(attr.getName().equals(attrName)) - { - Collection<String> 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 deleted file mode 100644 index 23f03db507..0000000000 --- a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/Test2RootCategory.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * - * 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<X extends Test2RootCategory<X>> extends TestRootCategory<X> -{ - 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/TestChildCategory.java b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestChildCategory.java deleted file mode 100644 index de4b1ae1c2..0000000000 --- a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestChildCategory.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * - * 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.Set; - -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; - -@ManagedObject -public interface TestChildCategory<X extends TestChildCategory<X>> extends ConfiguredObject<X> -{ - String NON_INTERPOLATED_VALID_VALUE = "${file.separator}"; - - @ManagedAttribute(validValues = { NON_INTERPOLATED_VALID_VALUE }, defaultValue = "") - String getValidValueNotInterpolated(); - - @ManagedAttribute( defaultValue = "3" ) - int getIntValue(); - - @ManagedAttribute( defaultValue = "[ \"1\", \"2\", \"foo\" ]" ) - Set<Integer> getIntegerSet(); -} diff --git a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestManagedClass1.java b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestManagedClass1.java deleted file mode 100644 index c7aa648223..0000000000 --- a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestManagedClass1.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * - * 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.ManagedObject; - -/** - * This is a test managed type extending TestManagedClass0. - * Because TestManagedClass0 implements managed interface TestManagedInterface1 with ManagedAnnotation set, - * the instances of this class will be managed entities of type TestManagedInterface1. - */ -@ManagedObject( category = false , type = "ChildClass" ) -public class TestManagedClass1 extends TestManagedClass0 -{ - public TestManagedClass1(final Map<String, Object> attributes, TestRootCategory<?> parent) - { - super(attributes, parent); - } -} diff --git a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestManagedClass2.java b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestManagedClass2.java deleted file mode 100644 index 62cc0c0c01..0000000000 --- a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestManagedClass2.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * - * 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.ManagedObject; - -/** - * This is a test managed type implementing managed interface TestManagedInterface2 and having ManagedAnnotation set. - * The instances of this class will be managed entities of type TestManagedInterface1 - */ -@ManagedObject( category = false , type = "ChildClass2" ) -public class TestManagedClass2 extends TestManagedClass0 implements TestManagedInterface2 -{ - public TestManagedClass2(final Map<String, Object> attributes, TestRootCategory<?> parent) - { - super(attributes, parent); - } -} diff --git a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestManagedClass4.java b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestManagedClass4.java deleted file mode 100644 index ff8f4b058c..0000000000 --- a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestManagedClass4.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * - * 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.ManagedObject; - -/** - * This is a test managed type extending managed type TestManagedClass0 and implementing TestManagedInterface2 - * The instances of this class will be managed entities of types TestManagedInterface1 only - * as it has no direct ManagedAnnotation set and no ManagedAnnotation declared in TestManagedInterface2. - */ -@ManagedObject( category = false , type = "ChildClass4" ) -public class TestManagedClass4 extends TestManagedClass0 implements TestManagedInterface2 -{ - public TestManagedClass4(final Map<String, Object> attributes, TestRootCategory<?> parent) - { - super(attributes, parent); - } -} diff --git a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestManagedClass5.java b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestManagedClass5.java deleted file mode 100644 index 5894363204..0000000000 --- a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestManagedClass5.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * - * 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.ManagedObject; - -/** - * This is a test type which has no ManagedAnnotation set and thus it should not expose any ManagedInterface - */ -@ManagedObject( category = false , type = "ChildClass3" ) -public class TestManagedClass5 extends TestChildCategoryImpl implements TestManagedInterface2 -{ - public TestManagedClass5(final Map<String, Object> attributes, TestRootCategory<?> parent) - { - super(attributes, parent); - } -} 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 deleted file mode 100644 index bb5441b3a4..0000000000 --- a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestRootCategoryImpl.java +++ /dev/null @@ -1,143 +0,0 @@ -/* - * - * 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.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.Map; -import java.util.Set; - -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.VirtualHost; - -@ManagedObject( category = false, - type = TestRootCategoryImpl.TEST_ROOT_TYPE, - validChildTypes = "org.apache.qpid.server.model.testmodel.TestRootCategoryImpl#getSupportedChildTypes()") -public class TestRootCategoryImpl extends AbstractConfiguredObject<TestRootCategoryImpl> - implements TestRootCategory<TestRootCategoryImpl> -{ - public static final String TEST_ROOT_TYPE = "testroot"; - - @ManagedAttributeField - private String _automatedPersistedValue; - - @ManagedAttributeField - private String _automatedNonPersistedValue; - - @ManagedAttributeField - private String _defaultedValue; - - @ManagedAttributeField - private String _stringValue; - - @ManagedAttributeField - private Map<String,String> _mapValue; - - @ManagedAttributeField - private String _validValue; - - @ManagedAttributeField - private TestEnum _enumValue; - - @ManagedAttributeField - private Set<TestEnum> _enumSetValues; - - - @ManagedObjectFactoryConstructor - public TestRootCategoryImpl(final Map<String, Object> attributes) - { - super(parentsMap(), attributes, newTaskExecutor(), TestModel.getInstance()); - } - - private static CurrentThreadTaskExecutor newTaskExecutor() - { - CurrentThreadTaskExecutor currentThreadTaskExecutor = new CurrentThreadTaskExecutor(); - currentThreadTaskExecutor.start(); - return currentThreadTaskExecutor; - } - - public TestRootCategoryImpl(final Map<String, Object> attributes, - final TaskExecutor taskExecutor) - { - super(parentsMap(), attributes, taskExecutor); - } - - - @Override - public String getAutomatedPersistedValue() - { - return _automatedPersistedValue; - } - - @Override - public String getAutomatedNonPersistedValue() - { - return _automatedNonPersistedValue; - } - - @Override - public String getDefaultedValue() - { - return _defaultedValue; - } - - @Override - public String getStringValue() - { - return _stringValue; - } - - @Override - public Map<String, String> getMapValue() - { - return _mapValue; - } - - @Override - public TestEnum getEnumValue() - { - return _enumValue; - } - - @Override - public Set<TestEnum> getEnumSetValues() - { - return _enumSetValues; - } - - @Override - public String getValidValue() - { - return _validValue; - } - - @SuppressWarnings("unused") - public static Map<String, Collection<String>> getSupportedChildTypes() - { - return Collections.singletonMap(TestChildCategory.class.getSimpleName(), (Collection<String>)Collections.singleton(TestChildCategoryImpl.TEST_CHILD_TYPE)); - } -} diff --git a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/hierarchy/AbstractConfiguredObjectTest.java b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/hierarchy/AbstractConfiguredObjectTest.java new file mode 100644 index 0000000000..474f7c4d01 --- /dev/null +++ b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/hierarchy/AbstractConfiguredObjectTest.java @@ -0,0 +1,97 @@ +/* + * 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.testmodels.hierarchy; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +import org.apache.qpid.server.configuration.IllegalConfigurationException; +import org.apache.qpid.server.model.ConfiguredObject; +import org.apache.qpid.server.model.Model; +import org.apache.qpid.test.utils.QpidTestCase; + +/** + * Tests behaviour of AbstractConfiguredObjects when hierarchies of objects are used together. + * Responsibilities to include adding/removing of children and correct firing of listeners. + */ +public class AbstractConfiguredObjectTest extends QpidTestCase +{ + private final Model _model = TestModel.getInstance(); + + public void testCreateCategoryDefault() + { + final String objectName = "testCreateCategoryDefault"; + Map<String, Object> attributes = Collections.<String, Object>singletonMap(ConfiguredObject.NAME, objectName); + + TestCar object = _model.getObjectFactory().create(TestCar.class, attributes); + + assertEquals(objectName, object.getName()); + assertEquals(TestStandardCarImpl.TEST_STANDARD_CAR_TYPE, object.getType()); + assertTrue(object instanceof TestStandardCar); + } + + public void testCreateUnrecognisedType() + { + final String objectName = "testCreateCategoryDefault"; + Map<String, Object> attributes = new HashMap<>(); + attributes.put(ConfiguredObject.NAME, objectName); + attributes.put(ConfiguredObject.TYPE, "notatype"); + + try + { + _model.getObjectFactory().create(TestCar.class, attributes); + fail("Exception not thrown"); + } + catch (IllegalConfigurationException ice) + { + // PASS + } + } + + public void testCreateCarWithEngine() + { + final String carName = "myCar"; + Map<String, Object> carAttributes = new HashMap<>(); + carAttributes.put(ConfiguredObject.NAME, carName); + carAttributes.put(ConfiguredObject.TYPE, TestKitCarImpl.TEST_KITCAR_TYPE); + + TestCar car = _model.getObjectFactory().create(TestCar.class, carAttributes); + + assertEquals(carName, car.getName()); + + assertEquals(0, car.getChildren(TestEngine.class).size()); + + String engineName = "myEngine"; + + Map<String, Object> engineAttributes = new HashMap<>(); + engineAttributes.put(ConfiguredObject.NAME, engineName); + engineAttributes.put(ConfiguredObject.TYPE, TestElecEngineImpl.TEST_ELEC_ENGINE_TYPE); + + TestEngine engine = (TestEngine) car.createChild(TestEngine.class, engineAttributes); + + assertEquals(1, car.getChildren(TestEngine.class).size()); + + assertEquals(engineName, engine.getName()); + assertEquals(TestElecEngineImpl.TEST_ELEC_ENGINE_TYPE, engine.getType()); + + } + +} diff --git a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/hierarchy/ConfiguredObjectTypeRegistryTest.java b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/hierarchy/ConfiguredObjectTypeRegistryTest.java new file mode 100644 index 0000000000..ea17238377 --- /dev/null +++ b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/hierarchy/ConfiguredObjectTypeRegistryTest.java @@ -0,0 +1,74 @@ +/* + * + * 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.testmodels.hierarchy; + +import static org.hamcrest.CoreMatchers.hasItem; +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +import java.util.Collection; +import java.util.Set; + +import junit.framework.TestCase; + +import org.apache.qpid.server.model.ConfiguredObject; +import org.apache.qpid.server.model.ConfiguredObjectTypeRegistry; +import org.apache.qpid.server.model.ManagedInterface; + +public class ConfiguredObjectTypeRegistryTest extends TestCase +{ + private ConfiguredObjectTypeRegistry _typeRegistry = TestModel.getInstance().getTypeRegistry(); + + public void testTypeSpecialisations() + { + Collection<Class<? extends ConfiguredObject>> types = _typeRegistry.getTypeSpecialisations(TestEngine.class); + + assertEquals("Unexpected number of specialisations for " + TestEngine.class + " Found : " + types, 3, types.size()); + assertTrue(types.contains(TestPetrolEngineImpl.class)); + assertTrue(types.contains(TestHybridEngineImpl.class)); + assertTrue(types.contains(TestElecEngineImpl.class)); + } + + public void testGetValidChildTypes() + { + // The standard car restricts its engine type + Collection<String> standardCarValidEnginesTypes = _typeRegistry.getValidChildTypes(TestStandardCarImpl.class, TestEngine.class); + assertThat(standardCarValidEnginesTypes, hasItem(TestPetrolEngineImpl.TEST_PETROL_ENGINE_TYPE)); + assertThat(standardCarValidEnginesTypes, hasItem(TestHybridEngineImpl.TEST_HYBRID_ENGINE_TYPE)); + assertThat(standardCarValidEnginesTypes.size(), is(2)); + + Collection<String> kitCarValidEngineTypes = _typeRegistry.getValidChildTypes(TestKitCarImpl.class, TestEngine.class); + // Would it be more useful to producers of management UIs if this were populated with all possible types? + assertNull(kitCarValidEngineTypes); + } + + public void testManagedInterfaces() + { + // The electric engine is recharable + Set<Class<? extends ManagedInterface>> elecEngIntfcs = _typeRegistry.getManagedInterfaces(TestElecEngine.class); + assertThat(elecEngIntfcs, hasItem(TestRechargeable.class)); + assertThat(elecEngIntfcs.size(), is(1)); + + // The pertrol engine implements no additional interfaces + Set<Class<? extends ManagedInterface>> stdCarIntfcs = _typeRegistry.getManagedInterfaces(TestPetrolEngine.class); + assertThat(stdCarIntfcs.size(), is(0)); + } +} diff --git a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestManagedInterface2.java b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/hierarchy/TestCar.java index 7ecb2d63ac..e2c436e31b 100644 --- a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestManagedInterface2.java +++ b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/hierarchy/TestCar.java @@ -18,14 +18,12 @@ * under the License. * */ -package org.apache.qpid.server.model.testmodel; +package org.apache.qpid.server.model.testmodels.hierarchy; -import org.apache.qpid.server.model.ManagedInterface; +import org.apache.qpid.server.model.ConfiguredObject; +import org.apache.qpid.server.model.ManagedObject; -/** - * This is a test managed interface which has no ManagedAnnotation. - * All types implementing this interface would need to have ManagedAnnotation declared in order to became managed entity. - */ -public interface TestManagedInterface2 extends ManagedInterface +@ManagedObject( defaultType = TestStandardCarImpl.TEST_STANDARD_CAR_TYPE) +public interface TestCar<X extends TestCar<X>> extends ConfiguredObject<X> { } diff --git a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/hierarchy/TestElecCar.java b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/hierarchy/TestElecCar.java new file mode 100644 index 0000000000..dc8f65d3a0 --- /dev/null +++ b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/hierarchy/TestElecCar.java @@ -0,0 +1,27 @@ +/* + * 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.testmodels.hierarchy; + +import org.apache.qpid.server.model.ManagedObject; + +@ManagedObject(category = false) +public interface TestElecCar<X extends TestElecCar<X>> extends TestCar<X> +{ +} diff --git a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/hierarchy/TestElecEngine.java b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/hierarchy/TestElecEngine.java new file mode 100644 index 0000000000..7dc3d8d59d --- /dev/null +++ b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/hierarchy/TestElecEngine.java @@ -0,0 +1,27 @@ +/* + * 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.testmodels.hierarchy; + +import org.apache.qpid.server.model.ManagedObject; + +@ManagedObject (category = false) +public interface TestElecEngine<X extends TestElecEngine<X>> extends TestEngine<X>, TestRechargeable +{ +} 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/testmodels/hierarchy/TestElecEngineImpl.java index 778d8e9cea..c875aea369 100644 --- 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/testmodels/hierarchy/TestElecEngineImpl.java @@ -18,55 +18,34 @@ * under the License. * */ -package org.apache.qpid.server.model.testmodel; +package org.apache.qpid.server.model.testmodels.hierarchy; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; import java.util.Map; -import java.util.Set; 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 = TestChildCategoryImpl.TEST_CHILD_TYPE ) -public class TestChildCategoryImpl - extends AbstractConfiguredObject<TestChildCategoryImpl> implements TestChildCategory<TestChildCategoryImpl> +@ManagedObject( category = false, type = TestElecEngineImpl.TEST_ELEC_ENGINE_TYPE) +public class TestElecEngineImpl + extends AbstractConfiguredObject<TestElecEngineImpl> implements TestElecEngine<TestElecEngineImpl> { - public static final String TEST_CHILD_TYPE = "testchild"; - - - @ManagedAttributeField - private String _validValueNotInterpolated; - - @ManagedAttributeField - private int _intValue; - - @ManagedAttributeField - private Set<Integer> _integerSet; - + public static final String TEST_ELEC_ENGINE_TYPE = "ELEC"; @ManagedObjectFactoryConstructor - public TestChildCategoryImpl(final Map<String, Object> attributes, TestRootCategory<?> parent) + public TestElecEngineImpl(final Map<String, Object> attributes, TestCar<?> parent) { super(parentsMap(parent), attributes); } - @Override - public String getValidValueNotInterpolated() + @SuppressWarnings("unused") + public static Map<String, Collection<String>> getSupportedChildTypes() { - return _validValueNotInterpolated; + Collection<String> types = Arrays.asList(TestElecEngineImpl.TEST_ELEC_ENGINE_TYPE); + return Collections.singletonMap(TestEngine.class.getSimpleName(), types); } - @Override - public int getIntValue() - { - return _intValue; - } - - @Override - public Set<Integer> getIntegerSet() - { - return _integerSet; - } } diff --git a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestManagedInterface1.java b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/hierarchy/TestEngine.java index aac5adad18..a6754b2a64 100644 --- a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestManagedInterface1.java +++ b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/hierarchy/TestEngine.java @@ -18,16 +18,12 @@ * under the License. * */ -package org.apache.qpid.server.model.testmodel; +package org.apache.qpid.server.model.testmodels.hierarchy; -import org.apache.qpid.server.model.ManagedAnnotation; -import org.apache.qpid.server.model.ManagedInterface; +import org.apache.qpid.server.model.ConfiguredObject; +import org.apache.qpid.server.model.ManagedObject; -/** - * This is a test managed interface which has ManagedAnnotation. - * All types implementing this interface will inherit the annotation and will be managed entities of type TestManagedInterface1 - */ -@ManagedAnnotation -public interface TestManagedInterface1 extends ManagedInterface +@ManagedObject(category = true) +public interface TestEngine<X extends TestEngine<X>> extends ConfiguredObject<X> { } diff --git a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/hierarchy/TestHybridEngine.java b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/hierarchy/TestHybridEngine.java new file mode 100644 index 0000000000..322a44ee23 --- /dev/null +++ b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/hierarchy/TestHybridEngine.java @@ -0,0 +1,26 @@ +/* + * 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.testmodels.hierarchy; + +import org.apache.qpid.server.model.ManagedObject; + +@ManagedObject (category = false) +public interface TestHybridEngine<X extends TestHybridEngine<X>> extends TestEngine<X>, TestRechargeable +{ +} diff --git a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestManagedClass3.java b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/hierarchy/TestHybridEngineImpl.java index c78f7404a6..dd6cd03a69 100644 --- a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestManagedClass3.java +++ b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/hierarchy/TestHybridEngineImpl.java @@ -1,5 +1,4 @@ /* - * * 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 @@ -16,23 +15,24 @@ * 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; + +package org.apache.qpid.server.model.testmodels.hierarchy; import java.util.Map; +import org.apache.qpid.server.model.AbstractConfiguredObject; import org.apache.qpid.server.model.ManagedObject; +import org.apache.qpid.server.model.ManagedObjectFactoryConstructor; -/** - * This is a test managed type implementing managed interface TestManagedInterface1 and TestManagedInterface3. - * The instances of this class will be managed entities of types TestManagedInterface1 and TestManagedInterface3. - */ -@ManagedObject( category = false , type = "ChildClass3" ) -public class TestManagedClass3 extends TestChildCategoryImpl implements TestManagedInterface1,TestManagedInterface3 +@ManagedObject( category = false, type = TestHybridEngineImpl.TEST_HYBRID_ENGINE_TYPE) +public class TestHybridEngineImpl extends AbstractConfiguredObject<TestHybridEngineImpl> implements TestHybridEngine<TestHybridEngineImpl> { - public TestManagedClass3(final Map<String, Object> attributes, TestRootCategory<?> parent) + public static final String TEST_HYBRID_ENGINE_TYPE = "HYBRID"; + + @ManagedObjectFactoryConstructor + public TestHybridEngineImpl(final Map<String, Object> attributes, TestCar<?> parent) { - super(attributes, parent); + super(parentsMap(parent), attributes); } } diff --git a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/hierarchy/TestKitCar.java b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/hierarchy/TestKitCar.java new file mode 100644 index 0000000000..742f957d9b --- /dev/null +++ b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/hierarchy/TestKitCar.java @@ -0,0 +1,26 @@ +/* + * 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.testmodels.hierarchy; + +import org.apache.qpid.server.model.ManagedObject; + +@ManagedObject(category = false) +public interface TestKitCar<X extends TestKitCar<X>> extends TestCar<X> +{ +} diff --git a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/hierarchy/TestKitCarImpl.java b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/hierarchy/TestKitCarImpl.java new file mode 100644 index 0000000000..5785071e15 --- /dev/null +++ b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/hierarchy/TestKitCarImpl.java @@ -0,0 +1,56 @@ +/* + * 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.testmodels.hierarchy; + +import java.util.Map; + +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.ManagedObject; +import org.apache.qpid.server.model.ManagedObjectFactoryConstructor; + +@ManagedObject( category = false, + type = TestKitCarImpl.TEST_KITCAR_TYPE) +public class TestKitCarImpl extends AbstractConfiguredObject<TestKitCarImpl> + implements TestKitCar<TestKitCarImpl> +{ + public static final String TEST_KITCAR_TYPE = "testkitcar"; + + @ManagedObjectFactoryConstructor + public TestKitCarImpl(final Map<String, Object> attributes) + { + super(parentsMap(), attributes, newTaskExecutor(), TestModel.getInstance()); + } + + @Override + public <C extends ConfiguredObject> C createChild(final Class<C> childClass, + final Map<String, Object> attributes, + final ConfiguredObject... otherParents) + { + return (C) getObjectFactory().create(childClass, attributes, this); + } + + private static CurrentThreadTaskExecutor newTaskExecutor() + { + CurrentThreadTaskExecutor currentThreadTaskExecutor = new CurrentThreadTaskExecutor(); + currentThreadTaskExecutor.start(); + return currentThreadTaskExecutor; + } +} diff --git a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/hierarchy/TestModel.java b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/hierarchy/TestModel.java new file mode 100644 index 0000000000..31ee8c2e7e --- /dev/null +++ b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/hierarchy/TestModel.java @@ -0,0 +1,117 @@ +/* + * + * 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.testmodels.hierarchy; + +import java.util.Arrays; +import java.util.Collection; +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 +{ + private static final Model INSTANCE = new TestModel(); + private Class<? extends ConfiguredObject>[] _supportedCategories = + new Class[] { + TestCar.class, + TestEngine.class + }; + + private final ConfiguredObjectFactory _objectFactory; + private ConfiguredObjectTypeRegistry _registry; + + private TestModel() + { + this(null); + } + + public TestModel(final ConfiguredObjectFactory objectFactory) + { + _objectFactory = objectFactory == null ? new ConfiguredObjectFactoryImpl(this) : objectFactory; + + ConfiguredObjectRegistration configuredObjectRegistration = new ConfiguredObjectRegistrationImpl(); + + _registry = new ConfiguredObjectTypeRegistry(Collections.singletonList(configuredObjectRegistration), Collections.EMPTY_LIST); + } + + + @Override + public Collection<Class<? extends ConfiguredObject>> getSupportedCategories() + { + return Arrays.asList(_supportedCategories); + } + + @Override + public Collection<Class<? extends ConfiguredObject>> getChildTypes(final Class<? extends ConfiguredObject> parent) + { + return TestCar.class.isAssignableFrom(parent) + ? Collections.<Class<? extends ConfiguredObject>>singleton(TestEngine.class) + : Collections.<Class<? extends ConfiguredObject>>emptySet(); + } + + @Override + public Class<? extends ConfiguredObject> getRootCategory() + { + return TestCar.class; + } + + @Override + public Collection<Class<? extends ConfiguredObject>> getParentTypes(final Class<? extends ConfiguredObject> child) + { + return TestEngine.class.isAssignableFrom(child) + ? Collections.<Class<? extends ConfiguredObject>>singleton(TestCar.class) + : Collections.<Class<? extends ConfiguredObject>>emptySet(); + } + + @Override + public int getMajorVersion() + { + return 99; + } + + @Override + public int getMinorVersion() + { + return 99; + } + + @Override + public ConfiguredObjectFactory getObjectFactory() + { + return _objectFactory; + } + + @Override + public ConfiguredObjectTypeRegistry getTypeRegistry() + { + return _registry; + } + + public static Model getInstance() + { + return INSTANCE; + } +} diff --git a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/hierarchy/TestPetrolEngine.java b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/hierarchy/TestPetrolEngine.java new file mode 100644 index 0000000000..7ca6953b29 --- /dev/null +++ b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/hierarchy/TestPetrolEngine.java @@ -0,0 +1,27 @@ +/* + * 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.testmodels.hierarchy; + +import org.apache.qpid.server.model.ManagedObject; + +@ManagedObject (category = false) +public interface TestPetrolEngine<X extends TestPetrolEngine<X>> extends TestEngine<X> +{ +} diff --git a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestManagedClass0.java b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/hierarchy/TestPetrolEngineImpl.java index 1e53f2ecd5..8047db3a34 100644 --- a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestManagedClass0.java +++ b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/hierarchy/TestPetrolEngineImpl.java @@ -18,23 +18,23 @@ * under the License. * */ -package org.apache.qpid.server.model.testmodel; +package org.apache.qpid.server.model.testmodels.hierarchy; import java.util.Map; -import org.apache.qpid.server.model.ManagedInterface; +import org.apache.qpid.server.model.AbstractConfiguredObject; import org.apache.qpid.server.model.ManagedObject; +import org.apache.qpid.server.model.ManagedObjectFactoryConstructor; -/** - * This is a test managed type implementing TestManagedInterface1 which extends ManagedInterface. - * Because TestManagedInterface1 already has ManagedAnnotation set, the instances of this class will be managed entities - * of type TestManagedInterface1. - */ -@ManagedObject( category = false , type = "SuperClass" ) -public class TestManagedClass0 extends TestChildCategoryImpl implements TestManagedInterface1 +@ManagedObject( category = false, type = TestPetrolEngineImpl.TEST_PETROL_ENGINE_TYPE) +public class TestPetrolEngineImpl + extends AbstractConfiguredObject<TestPetrolEngineImpl> implements TestPetrolEngine<TestPetrolEngineImpl> { - public TestManagedClass0(final Map<String, Object> attributes, TestRootCategory<?> parent) + public static final String TEST_PETROL_ENGINE_TYPE = "PETROL"; + + @ManagedObjectFactoryConstructor + public TestPetrolEngineImpl(final Map<String, Object> attributes, TestCar<?> parent) { - super(attributes, parent); + super(parentsMap(parent), attributes); } } diff --git a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestManagedInterface3.java b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/hierarchy/TestRechargeable.java index d1d0a1b820..26eed78b28 100644 --- a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestManagedInterface3.java +++ b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/hierarchy/TestRechargeable.java @@ -18,12 +18,13 @@ * under the License. * */ -package org.apache.qpid.server.model.testmodel; +package org.apache.qpid.server.model.testmodels.hierarchy; import org.apache.qpid.server.model.ManagedAnnotation; import org.apache.qpid.server.model.ManagedInterface; + @ManagedAnnotation -public interface TestManagedInterface3 extends ManagedInterface +public interface TestRechargeable extends ManagedInterface { } diff --git a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/hierarchy/TestStandardCar.java b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/hierarchy/TestStandardCar.java new file mode 100644 index 0000000000..302eb41442 --- /dev/null +++ b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/hierarchy/TestStandardCar.java @@ -0,0 +1,27 @@ +/* + * 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.testmodels.hierarchy; + +import org.apache.qpid.server.model.ManagedObject; + +@ManagedObject(category = false) +public interface TestStandardCar<X extends TestStandardCar<X>> extends TestCar<X> +{ +} diff --git a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/hierarchy/TestStandardCarImpl.java b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/hierarchy/TestStandardCarImpl.java new file mode 100644 index 0000000000..83dfd73b8b --- /dev/null +++ b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/hierarchy/TestStandardCarImpl.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.testmodels.hierarchy; + +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.Map; + +import org.apache.qpid.server.configuration.updater.CurrentThreadTaskExecutor; +import org.apache.qpid.server.model.AbstractConfiguredObject; +import org.apache.qpid.server.model.ManagedObject; +import org.apache.qpid.server.model.ManagedObjectFactoryConstructor; + +@ManagedObject( category = false, + type = TestStandardCarImpl.TEST_STANDARD_CAR_TYPE, + validChildTypes = "org.apache.qpid.server.model.testmodels.hierarchy.TestStandardCarImpl#getSupportedChildTypes()") +public class TestStandardCarImpl extends AbstractConfiguredObject<TestStandardCarImpl> + implements TestStandardCar<TestStandardCarImpl> +{ + public static final String TEST_STANDARD_CAR_TYPE = "testpertrolcar"; + + @ManagedObjectFactoryConstructor + public TestStandardCarImpl(final Map<String, Object> attributes) + { + super(parentsMap(), attributes, newTaskExecutor(), TestModel.getInstance()); + } + + private static CurrentThreadTaskExecutor newTaskExecutor() + { + CurrentThreadTaskExecutor currentThreadTaskExecutor = new CurrentThreadTaskExecutor(); + currentThreadTaskExecutor.start(); + return currentThreadTaskExecutor; + } + + @SuppressWarnings("unused") + public static Map<String, Collection<String>> getSupportedChildTypes() + { + Collection<String> types = Arrays.asList(TestPetrolEngineImpl.TEST_PETROL_ENGINE_TYPE, TestHybridEngineImpl.TEST_HYBRID_ENGINE_TYPE); + return Collections.singletonMap(TestEngine.class.getSimpleName(), types); + } +} diff --git a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/lifecycle/AbstractConfiguredObjectTest.java b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/lifecycle/AbstractConfiguredObjectTest.java new file mode 100644 index 0000000000..ea23692320 --- /dev/null +++ b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/lifecycle/AbstractConfiguredObjectTest.java @@ -0,0 +1,217 @@ +/* + * 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.testmodels.lifecycle; + +import java.util.Collections; + +import org.apache.qpid.server.configuration.IllegalConfigurationException; +import org.apache.qpid.server.model.Port; +import org.apache.qpid.server.model.State; +import org.apache.qpid.test.utils.QpidTestCase; + +public class AbstractConfiguredObjectTest extends QpidTestCase +{ + + public void testOpeningResultsInErroredStateWhenResolutionFails() throws Exception + { + TestConfiguredObject object = new TestConfiguredObject(getName()); + object.setThrowExceptionOnPostResolve(true); + object.open(); + assertFalse("Unexpected opened", object.isOpened()); + assertEquals("Unexpected state", State.ERRORED, object.getState()); + + object.setThrowExceptionOnPostResolve(false); + object.setAttributes(Collections.<String, Object>singletonMap(Port.DESIRED_STATE, State.ACTIVE)); + assertTrue("Unexpected opened", object.isOpened()); + assertEquals("Unexpected state", State.ACTIVE, object.getState()); + } + + public void testOpeningInERROREDStateAfterFailedOpenOnDesiredStateChangeToActive() throws Exception + { + TestConfiguredObject object = new TestConfiguredObject(getName()); + object.setThrowExceptionOnOpen(true); + object.open(); + assertFalse("Unexpected opened", object.isOpened()); + assertEquals("Unexpected state", State.ERRORED, object.getState()); + + object.setThrowExceptionOnOpen(false); + object.setAttributes(Collections.<String, Object>singletonMap(Port.DESIRED_STATE, State.ACTIVE)); + assertTrue("Unexpected opened", object.isOpened()); + assertEquals("Unexpected state", State.ACTIVE, object.getState()); + } + + public void testOpeningInERROREDStateAfterFailedOpenOnStart() throws Exception + { + TestConfiguredObject object = new TestConfiguredObject(getName()); + object.setThrowExceptionOnOpen(true); + object.open(); + assertFalse("Unexpected opened", object.isOpened()); + assertEquals("Unexpected state", State.ERRORED, object.getState()); + + object.setThrowExceptionOnOpen(false); + object.start(); + assertTrue("Unexpected opened", object.isOpened()); + assertEquals("Unexpected state", State.ACTIVE, object.getState()); + } + + public void testDeletionERROREDStateAfterFailedOpenOnDelete() throws Exception + { + TestConfiguredObject object = new TestConfiguredObject(getName()); + object.setThrowExceptionOnOpen(true); + object.open(); + assertFalse("Unexpected opened", object.isOpened()); + assertEquals("Unexpected state", State.ERRORED, object.getState()); + + object.delete(); + assertFalse("Unexpected opened", object.isOpened()); + assertEquals("Unexpected state", State.DELETED, object.getState()); + } + + public void testDeletionInERROREDStateAfterFailedOpenOnDesiredStateChangeToDelete() throws Exception + { + TestConfiguredObject object = new TestConfiguredObject(getName()); + object.setThrowExceptionOnOpen(true); + object.open(); + assertFalse("Unexpected opened", object.isOpened()); + assertEquals("Unexpected state", State.ERRORED, object.getState()); + + object.setAttributes(Collections.<String, Object>singletonMap(Port.DESIRED_STATE, State.DELETED)); + assertFalse("Unexpected opened", object.isOpened()); + assertEquals("Unexpected state", State.DELETED, object.getState()); + } + + + public void testCreationWithExceptionThrownFromValidationOnCreate() throws Exception + { + TestConfiguredObject object = new TestConfiguredObject(getName()); + object.setThrowExceptionOnValidationOnCreate(true); + try + { + object.create(); + fail("IllegalConfigurationException is expected to be thrown"); + } + catch(IllegalConfigurationException e) + { + //pass + } + assertFalse("Unexpected opened", object.isOpened()); + } + + public void testCreationWithoutExceptionThrownFromValidationOnCreate() throws Exception + { + TestConfiguredObject object = new TestConfiguredObject(getName()); + object.setThrowExceptionOnValidationOnCreate(false); + object.create(); + assertTrue("Unexpected opened", object.isOpened()); + assertEquals("Unexpected state", State.ACTIVE, object.getState()); + } + + public void testCreationWithExceptionThrownFromOnOpen() throws Exception + { + TestConfiguredObject object = new TestConfiguredObject(getName()); + object.setThrowExceptionOnOpen(true); + try + { + object.create(); + fail("Exception should have been re-thrown"); + } + catch (RuntimeException re) + { + // pass + } + + assertFalse("Unexpected opened", object.isOpened()); + assertEquals("Unexpected state", State.DELETED, object.getState()); + } + + public void testCreationWithExceptionThrownFromOnCreate() throws Exception + { + TestConfiguredObject object = new TestConfiguredObject(getName()); + object.setThrowExceptionOnCreate(true); + try + { + object.create(); + fail("Exception should have been re-thrown"); + } + catch (RuntimeException re) + { + // pass + } + + assertFalse("Unexpected opened", object.isOpened()); + assertEquals("Unexpected state", State.DELETED, object.getState()); + } + + public void testUnresolvedChildInERROREDStateIsNotValidatedOrOpenedOrAttainedDesiredStateOnParentOpen() throws Exception + { + TestConfiguredObject parent = new TestConfiguredObject("parent"); + TestConfiguredObject child1 = new TestConfiguredObject("child1", parent, parent.getTaskExecutor()); + child1.registerWithParents(); + TestConfiguredObject child2 = new TestConfiguredObject("child2", parent, parent.getTaskExecutor()); + child2.registerWithParents(); + + child1.setThrowExceptionOnPostResolve(true); + + parent.open(); + + assertTrue("Parent should be resolved", parent.isResolved()); + assertTrue("Parent should be validated", parent.isValidated()); + assertTrue("Parent should be opened", parent.isOpened()); + assertEquals("Unexpected parent state", State.ACTIVE, parent.getState()); + + assertTrue("Child2 should be resolved", child2.isResolved()); + assertTrue("Child2 should be validated", child2.isValidated()); + assertTrue("Child2 should be opened", child2.isOpened()); + assertEquals("Unexpected child2 state", State.ACTIVE, child2.getState()); + + assertFalse("Child2 should not be resolved", child1.isResolved()); + assertFalse("Child1 should not be validated", child1.isValidated()); + assertFalse("Child1 should not be opened", child1.isOpened()); + assertEquals("Unexpected child1 state", State.ERRORED, child1.getState()); + } + + public void testUnvalidatedChildInERROREDStateIsNotOpenedOrAttainedDesiredStateOnParentOpen() throws Exception + { + TestConfiguredObject parent = new TestConfiguredObject("parent"); + TestConfiguredObject child1 = new TestConfiguredObject("child1", parent, parent.getTaskExecutor()); + child1.registerWithParents(); + TestConfiguredObject child2 = new TestConfiguredObject("child2", parent, parent.getTaskExecutor()); + child2.registerWithParents(); + + child1.setThrowExceptionOnValidate(true); + + parent.open(); + + assertTrue("Parent should be resolved", parent.isResolved()); + assertTrue("Parent should be validated", parent.isValidated()); + assertTrue("Parent should be opened", parent.isOpened()); + assertEquals("Unexpected parent state", State.ACTIVE, parent.getState()); + + assertTrue("Child2 should be resolved", child2.isResolved()); + assertTrue("Child2 should be validated", child2.isValidated()); + assertTrue("Child2 should be opened", child2.isOpened()); + assertEquals("Unexpected child2 state", State.ACTIVE, child2.getState()); + + assertTrue("Child1 should be resolved", child1.isResolved()); + assertFalse("Child1 should not be validated", child1.isValidated()); + assertFalse("Child1 should not be opened", child1.isOpened()); + assertEquals("Unexpected child1 state", State.ERRORED, child1.getState()); + } + +} diff --git a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestConfiguredObject.java b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/lifecycle/TestConfiguredObject.java index 8f61e37ad4..0b35ba9330 100644 --- a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestConfiguredObject.java +++ b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/lifecycle/TestConfiguredObject.java @@ -16,7 +16,8 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.qpid.server.model.testmodel; + +package org.apache.qpid.server.model.testmodels.lifecycle; import static org.mockito.Mockito.mock; diff --git a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/singleton/AbstractConfiguredObjectTest.java b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/singleton/AbstractConfiguredObjectTest.java new file mode 100644 index 0000000000..325e2843fa --- /dev/null +++ b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/singleton/AbstractConfiguredObjectTest.java @@ -0,0 +1,445 @@ +/* + * 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.testmodels.singleton; + +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +import org.apache.qpid.server.configuration.IllegalConfigurationException; +import org.apache.qpid.server.model.ConfiguredObject; +import org.apache.qpid.server.model.Model; +import org.apache.qpid.server.store.ConfiguredObjectRecord; +import org.apache.qpid.test.utils.QpidTestCase; + +/** + * Tests behaviour of AbstractConfiguredObject related to attributes including + * persistence, defaulting, and attribute values derived from context variables. + */ +public class AbstractConfiguredObjectTest extends QpidTestCase +{ + private final Model _model = TestModel.getInstance(); + + public void testAttributePersistence() + { + final String objectName = "testNonPersistAttributes"; + TestSingleton object = + _model.getObjectFactory().create(TestSingleton.class, + Collections.<String, Object>singletonMap(ConfiguredObject.NAME, + objectName) + ); + + assertEquals(objectName, object.getName()); + assertNull(object.getAutomatedNonPersistedValue()); + assertNull(object.getAutomatedPersistedValue()); + assertEquals(TestSingletonImpl.DERIVED_VALUE, object.getDerivedValue()); + + ConfiguredObjectRecord record = object.asObjectRecord(); + + assertEquals(objectName, record.getAttributes().get(ConfiguredObject.NAME)); + + assertFalse(record.getAttributes().containsKey(TestSingleton.AUTOMATED_PERSISTED_VALUE)); + assertFalse(record.getAttributes().containsKey(TestSingleton.AUTOMATED_NONPERSISTED_VALUE)); + assertFalse(record.getAttributes().containsKey(TestSingleton.DERIVED_VALUE)); + + Map<String, Object> updatedAttributes = new HashMap<>(); + + final String newValue = "newValue"; + + updatedAttributes.put(TestSingleton.AUTOMATED_PERSISTED_VALUE, newValue); + updatedAttributes.put(TestSingleton.AUTOMATED_NONPERSISTED_VALUE, newValue); + updatedAttributes.put(TestSingleton.DERIVED_VALUE, System.currentTimeMillis()); // Will be ignored + object.setAttributes(updatedAttributes); + + assertEquals(newValue, object.getAutomatedPersistedValue()); + assertEquals(newValue, object.getAutomatedNonPersistedValue()); + + record = object.asObjectRecord(); + assertEquals(objectName, record.getAttributes().get(ConfiguredObject.NAME)); + assertEquals(newValue, record.getAttributes().get(TestSingleton.AUTOMATED_PERSISTED_VALUE)); + + assertFalse(record.getAttributes().containsKey(TestSingleton.AUTOMATED_NONPERSISTED_VALUE)); + assertFalse(record.getAttributes().containsKey(TestSingleton.DERIVED_VALUE)); + + } + + public void testDefaultedAttributeValue() + { + final String objectName = "myName"; + + Map<String, Object> attributes = Collections.<String, Object>singletonMap(TestSingleton.NAME, objectName); + + TestSingleton object1 = _model.getObjectFactory().create(TestSingleton.class, + attributes); + + assertEquals(objectName, object1.getName()); + assertEquals(TestSingleton.DEFAULTED_VALUE_DEFAULT, object1.getDefaultedValue()); + } + + public void testOverriddenDefaultedAttributeValue() + { + final String objectName = "myName"; + + Map<String, Object> attributes = new HashMap<>(); + attributes.put(TestSingleton.NAME, objectName); + attributes.put(TestSingleton.DEFAULTED_VALUE, "override"); + + TestSingleton object = _model.getObjectFactory().create(TestSingleton.class, + attributes); + + assertEquals(objectName, object.getName()); + assertEquals("override", object.getDefaultedValue()); + + } + + public void testOverriddenDefaultedAttributeValueRevertedToDefault() + { + final String objectName = "myName"; + + Map<String, Object> attributes = new HashMap<>(); + attributes.put(TestSingleton.NAME, objectName); + attributes.put(TestSingleton.DEFAULTED_VALUE, "override"); + + TestSingleton object = _model.getObjectFactory().create(TestSingleton.class, + attributes); + + assertEquals(objectName, object.getName()); + assertEquals("override", object.getDefaultedValue()); + + object.setAttributes(Collections.singletonMap(TestSingleton.DEFAULTED_VALUE, null)); + + assertEquals(TestSingleton.DEFAULTED_VALUE_DEFAULT, object.getDefaultedValue()); + } + + public void testEnumAttributeValueFromString() + { + final String objectName = "myName"; + + Map<String, Object> attributes = new HashMap<>(); + attributes.put(TestSingleton.NAME, objectName); + attributes.put(TestSingleton.ENUM_VALUE, TestEnum.TEST_ENUM1.name()); + + TestSingleton object1 = _model.getObjectFactory().create(TestSingleton.class, + attributes); + + assertEquals(objectName, object1.getName()); + assertEquals(TestEnum.TEST_ENUM1, object1.getEnumValue()); + } + + public void testEnumAttributeValueFromEnum() + { + final String objectName = "myName"; + + Map<String, Object> attributes = new HashMap<>(); + attributes.put(TestSingleton.NAME, objectName); + attributes.put(TestSingleton.ENUM_VALUE, TestEnum.TEST_ENUM1); + + TestSingleton object1 = _model.getObjectFactory().create(TestSingleton.class, + attributes); + + assertEquals(objectName, object1.getName()); + assertEquals(TestEnum.TEST_ENUM1, object1.getEnumValue()); + } + + public void testIntegerAttributeValueFromString() + { + final String objectName = "myName"; + + Map<String, Object> attributes = new HashMap<>(); + attributes.put(TestSingleton.NAME, objectName); + attributes.put(TestSingleton.INT_VALUE, "-4"); + + TestSingleton object1 = _model.getObjectFactory().create(TestSingleton.class, + attributes); + + assertEquals(objectName, object1.getName()); + assertEquals(-4, object1.getIntValue()); + } + + public void testIntegerAttributeValueFromInteger() + { + final String objectName = "myName"; + + Map<String, Object> attributes = new HashMap<>(); + attributes.put(TestSingleton.NAME, objectName); + attributes.put(TestSingleton.INT_VALUE, 5); + + TestSingleton object1 = _model.getObjectFactory().create(TestSingleton.class, + attributes); + + assertEquals(objectName, object1.getName()); + assertEquals(5, object1.getIntValue()); + } + + public void testIntegerAttributeValueFromDouble() + { + final String objectName = "myName"; + + Map<String, Object> attributes = new HashMap<>(); + attributes.put(TestSingleton.NAME, objectName); + attributes.put(TestSingleton.INT_VALUE, 6.1); + + TestSingleton object1 = _model.getObjectFactory().create(TestSingleton.class, + attributes); + + assertEquals(objectName, object1.getName()); + assertEquals(6, object1.getIntValue()); + } + + public void testStringAttributeValueFromContextVariableProvidedBySystemProperty() + { + String sysPropertyName = "testStringAttributeValueFromContextVariableProvidedBySystemProperty"; + String contextToken = "${" + sysPropertyName + "}"; + + System.setProperty(sysPropertyName, "myValue"); + + final String objectName = "myName"; + + Map<String, Object> attributes = new HashMap<>(); + attributes.put(TestSingleton.NAME, objectName); + attributes.put(TestSingleton.STRING_VALUE, contextToken); + + TestSingleton object1 = _model.getObjectFactory().create(TestSingleton.class, + attributes); + + assertEquals(objectName, object1.getName()); + assertEquals("myValue", object1.getStringValue()); + + // System property set empty string + + System.setProperty(sysPropertyName, ""); + TestSingleton object2 = _model.getObjectFactory().create(TestSingleton.class, + attributes); + + assertEquals("", object2.getStringValue()); + + // System property not set + System.clearProperty(sysPropertyName); + + TestSingleton object3 = _model.getObjectFactory().create(TestSingleton.class, + attributes); + + // yields the unexpanded token - not sure if this is really useful behaviour? + assertEquals(contextToken, object3.getStringValue()); + } + + public void testMapAttributeValueFromContextVariableProvidedBySystemProperty() + { + String sysPropertyName = "testMapAttributeValueFromContextVariableProvidedBySystemProperty"; + String contextToken = "${" + sysPropertyName + "}"; + + Map<String,String> expectedMap = new HashMap<>(); + expectedMap.put("field1", "value1"); + expectedMap.put("field2", "value2"); + + System.setProperty(sysPropertyName, "{ \"field1\" : \"value1\", \"field2\" : \"value2\"}"); + + final String objectName = "myName"; + + Map<String, Object> attributes = new HashMap<>(); + attributes.put(TestSingleton.NAME, objectName); + attributes.put(TestSingleton.MAP_VALUE, contextToken); + + TestSingleton object1 = _model.getObjectFactory().create(TestSingleton.class, + attributes); + + assertEquals(objectName, object1.getName()); + assertEquals(expectedMap, object1.getMapValue()); + + // System property not set + System.clearProperty(sysPropertyName); + } + + public void testStringAttributeValueFromContextVariableProvidedObjectsContext() + { + String contextToken = "${myReplacement}"; + + final String objectName = "myName"; + + Map<String, Object> attributes = new HashMap<>(); + attributes.put(ConfiguredObject.NAME, objectName); + attributes.put(ConfiguredObject.CONTEXT, Collections.singletonMap("myReplacement", "myValue")); + attributes.put(TestSingleton.STRING_VALUE, contextToken); + + TestSingleton object1 = _model.getObjectFactory().create(TestSingleton.class, + attributes); + // Check the object's context itself + assertTrue(object1.getContext().containsKey("myReplacement")); + assertEquals("myValue", object1.getContext().get("myReplacement")); + + assertEquals(objectName, object1.getName()); + assertEquals("myValue", object1.getStringValue()); + } + + public void testInvalidIntegerAttributeValueFromContextVariable() + { + final Map<String, Object> attributes = new HashMap<>(); + + attributes.put(TestSingleton.NAME, "myName"); + attributes.put(TestSingleton.TYPE, TestSingletonImpl.TEST_SINGLETON_TYPE); + attributes.put(TestSingleton.CONTEXT, Collections.singletonMap("contextVal", "notAnInteger")); + attributes.put(TestSingleton.INT_VALUE, "${contextVal}"); + + try + { + _model.getObjectFactory().create(TestSingleton.class, attributes); + fail("creation of child object should have failed due to invalid value"); + } + catch (IllegalArgumentException e) + { + // PASS + String message = e.getMessage(); + assertTrue("Message does not contain the attribute name", message.contains("intValue")); + assertTrue("Message does not contain the non-interpolated value", message.contains("contextVal")); + assertTrue("Message does not contain the interpolated value", message.contains("contextVal")); + + } + } + + public void testCreateEnforcesAttributeValidValues() throws Exception + { + final String objectName = getName(); + Map<String, Object> illegalCreateAttributes = new HashMap<>(); + illegalCreateAttributes.put(ConfiguredObject.NAME, objectName); + illegalCreateAttributes.put(TestSingleton.VALID_VALUE, "illegal"); + + try + { + _model.getObjectFactory().create(TestSingleton.class, illegalCreateAttributes); + fail("Exception not thrown"); + } + catch (IllegalConfigurationException ice) + { + // PASS + } + + Map<String, Object> legalCreateAttributes = new HashMap<>(); + legalCreateAttributes.put(ConfiguredObject.NAME, objectName); + legalCreateAttributes.put(TestSingleton.VALID_VALUE, TestSingleton.VALID_VALUE1); + + TestSingleton object = _model.getObjectFactory().create(TestSingleton.class, legalCreateAttributes); + assertEquals(TestSingleton.VALID_VALUE1, object.getValidValue()); + } + + public void testChangeEnforcesAttributeValidValues() throws Exception + { + final String objectName = getName(); + Map<String, Object> legalCreateAttributes = new HashMap<>(); + legalCreateAttributes.put(ConfiguredObject.NAME, objectName); + legalCreateAttributes.put(TestSingleton.VALID_VALUE, TestSingleton.VALID_VALUE1); + + TestSingleton object = _model.getObjectFactory().create(TestSingleton.class, legalCreateAttributes); + assertEquals(TestSingleton.VALID_VALUE1, object.getValidValue()); + + object.setAttributes(Collections.singletonMap(TestSingleton.VALID_VALUE, TestSingleton.VALID_VALUE2)); + assertEquals(TestSingleton.VALID_VALUE2, object.getValidValue()); + + try + { + object.setAttributes(Collections.singletonMap(TestSingleton.VALID_VALUE, "illegal")); + fail("Exception not thrown"); + } + catch (IllegalConfigurationException iae) + { + // PASS + } + + assertEquals(TestSingleton.VALID_VALUE2, object.getValidValue()); + + object.setAttributes(Collections.singletonMap(TestSingleton.VALID_VALUE,null)); + assertNull(object.getValidValue()); + + } + + public void testCreateEnforcesAttributeValidValuesWithSets() throws Exception + { + final String objectName = getName(); + final Map<String, Object> name = Collections.singletonMap(ConfiguredObject.NAME, (Object)objectName); + + Map<String, Object> illegalCreateAttributes = new HashMap<>(name); + illegalCreateAttributes.put(TestSingleton.ENUMSET_VALUES, Collections.singleton(TestEnum.TEST_ENUM3)); + + try + { + _model.getObjectFactory().create(TestSingleton.class, illegalCreateAttributes); + fail("Exception not thrown"); + } + catch (IllegalConfigurationException ice) + { + // PASS + } + + { + Map<String, Object> legalCreateAttributesEnums = new HashMap<>(name); + legalCreateAttributesEnums.put(TestSingleton.ENUMSET_VALUES, + Arrays.asList(TestEnum.TEST_ENUM2, TestEnum.TEST_ENUM3)); + + TestSingleton obj = _model.getObjectFactory().create(TestSingleton.class, legalCreateAttributesEnums); + assertTrue(obj.getEnumSetValues().containsAll(Arrays.asList(TestEnum.TEST_ENUM2, TestEnum.TEST_ENUM3))); + } + + { + Map<String, Object> legalCreateAttributesStrings = new HashMap<>(name); + legalCreateAttributesStrings.put(TestSingleton.ENUMSET_VALUES, + Arrays.asList(TestEnum.TEST_ENUM2.name(), TestEnum.TEST_ENUM3.name())); + + TestSingleton + obj = _model.getObjectFactory().create(TestSingleton.class, legalCreateAttributesStrings); + assertTrue(obj.getEnumSetValues().containsAll(Arrays.asList(TestEnum.TEST_ENUM2, TestEnum.TEST_ENUM3))); + } + } + + public void testDefaultContextIsInContextKeys() + { + final String objectName = "myName"; + + Map<String, Object> attributes = new HashMap<>(); + attributes.put(ConfiguredObject.NAME, objectName); + + TestSingleton object = _model.getObjectFactory().create(TestSingleton.class, + attributes); + + + assertTrue("context default not in contextKeys", + object.getContextKeys(true).contains(TestSingleton.TEST_CONTEXT_DEFAULT)); + assertEquals(object.getContextValue(String.class, TestSingleton.TEST_CONTEXT_DEFAULT), "default"); + + setTestSystemProperty(TestSingleton.TEST_CONTEXT_DEFAULT, "notdefault"); + assertTrue("context default not in contextKeys", + object.getContextKeys(true).contains(TestSingleton.TEST_CONTEXT_DEFAULT)); + assertEquals(object.getContextValue(String.class, TestSingleton.TEST_CONTEXT_DEFAULT), "notdefault"); + } + + public void testDerivedAttributeValue() + { + final String objectName = "myName"; + + Map<String, Object> attributes = new HashMap<>(); + attributes.put(ConfiguredObject.NAME, objectName); + + TestSingleton object = _model.getObjectFactory().create(TestSingleton.class, attributes); + assertEquals(TestSingletonImpl.DERIVED_VALUE, object.getDerivedValue()); + + // Check that update is ignored + object.setAttribute(TestSingleton.DERIVED_VALUE, object.getDerivedValue(), System.currentTimeMillis()); + + assertEquals(TestSingletonImpl.DERIVED_VALUE, object.getDerivedValue()); + } +} diff --git a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestEnum.java b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/singleton/TestEnum.java index 75c6c197ce..d8ec160651 100644 --- a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestEnum.java +++ b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/singleton/TestEnum.java @@ -17,13 +17,9 @@ * under the License. */ -package org.apache.qpid.server.model.testmodel; +package org.apache.qpid.server.model.testmodels.singleton; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - public enum TestEnum { TEST_ENUM1, 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/testmodels/singleton/TestModel.java index 090c72762d..330127cfa2 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/testmodels/singleton/TestModel.java @@ -1,5 +1,4 @@ /* - * * 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 @@ -16,9 +15,8 @@ * 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; +package org.apache.qpid.server.model.testmodels.singleton; import java.util.Arrays; import java.util.Collection; @@ -36,8 +34,7 @@ public class TestModel extends Model private static final Model INSTANCE = new TestModel(); private Class<? extends ConfiguredObject>[] _supportedClasses = new Class[] { - TestRootCategory.class, - TestChildCategory.class + TestSingleton.class }; private final ConfiguredObjectFactory _objectFactory; @@ -56,13 +53,13 @@ public class TestModel extends Model @Override public Collection<Class<? extends ConfiguredObject>> getConfiguredObjectClasses() { - return Arrays.<Class<? extends ConfiguredObject>>asList(TestRootCategoryImpl.class, Test2RootCategoryImpl.class); + return Arrays.asList(_supportedClasses); } @Override public String getType() { - return "org.apache.qpid.server.model.testmodel"; + return "org.apache.qpid.server.model.testmodels.attribute"; } }; _registry = new ConfiguredObjectTypeRegistry(Arrays.asList(configuredObjectRegistration), getSupportedCategories()); @@ -78,23 +75,19 @@ public class TestModel extends Model @Override public Collection<Class<? extends ConfiguredObject>> getChildTypes(final Class<? extends ConfiguredObject> parent) { - return TestRootCategory.class.isAssignableFrom(parent) - ? Collections.<Class<? extends ConfiguredObject>>singleton(TestChildCategory.class) - : Collections.<Class<? extends ConfiguredObject>>emptySet(); + return Collections.emptySet(); } @Override public Class<? extends ConfiguredObject> getRootCategory() { - return TestRootCategory.class; + return TestSingleton.class; } @Override public Collection<Class<? extends ConfiguredObject>> getParentTypes(final Class<? extends ConfiguredObject> child) { - return TestChildCategory.class.isAssignableFrom(child) - ? Collections.<Class<? extends ConfiguredObject>>singleton(TestRootCategory.class) - : Collections.<Class<? extends ConfiguredObject>>emptySet(); + return Collections.<Class<? extends ConfiguredObject>>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/testmodels/singleton/TestSingleton.java index d8d26b86e6..e36097655b 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/testmodels/singleton/TestSingleton.java @@ -1,5 +1,4 @@ /* - * * 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 @@ -16,31 +15,30 @@ * 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; +package org.apache.qpid.server.model.testmodels.singleton; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; import java.util.Map; import java.util.Set; import org.apache.qpid.server.model.ConfiguredObject; +import org.apache.qpid.server.model.DerivedAttribute; import org.apache.qpid.server.model.ManagedAttribute; import org.apache.qpid.server.model.ManagedContextDefault; import org.apache.qpid.server.model.ManagedObject; -@ManagedObject( defaultType = TestRootCategoryImpl.TEST_ROOT_TYPE ) -public interface TestRootCategory<X extends TestRootCategory<X>> extends ConfiguredObject<X> +@ManagedObject( defaultType = TestSingletonImpl.TEST_SINGLETON_TYPE) +public interface TestSingleton<X extends TestSingleton<X>> extends ConfiguredObject<X> { String AUTOMATED_PERSISTED_VALUE = "automatedPersistedValue"; String AUTOMATED_NONPERSISTED_VALUE = "automatedNonPersistedValue"; + String DERIVED_VALUE = "derivedValue"; String DEFAULTED_VALUE = "defaultedValue"; String STRING_VALUE = "stringValue"; String MAP_VALUE = "mapValue"; - String VALID_VALUE = "validValue"; String ENUM_VALUE = "enumValue"; + String INT_VALUE = "intValue"; + String VALID_VALUE = "validValue"; String ENUMSET_VALUES = "enumSetValues"; String TEST_CONTEXT_DEFAULT = "TEST_CONTEXT_DEFAULT"; @@ -48,7 +46,6 @@ public interface TestRootCategory<X extends TestRootCategory<X>> extends Configu @ManagedContextDefault(name = TEST_CONTEXT_DEFAULT) String testGlobalDefault = "default"; - @ManagedAttribute String getAutomatedPersistedValue(); @@ -71,10 +68,16 @@ public interface TestRootCategory<X extends TestRootCategory<X>> extends Configu @ManagedAttribute TestEnum getEnumValue(); + @ManagedAttribute + int getIntValue(); + @ManagedAttribute(validValues = {VALID_VALUE1, VALID_VALUE2} ) String getValidValue(); @ManagedAttribute( validValues = {"[\"TEST_ENUM1\"]", "[\"TEST_ENUM2\", \"TEST_ENUM3\"]"}) Set<TestEnum> getEnumSetValues(); + @DerivedAttribute + long getDerivedValue(); + } 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/testmodels/singleton/TestSingletonImpl.java index 3a415b9a4c..47c30030b2 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/testmodels/singleton/TestSingletonImpl.java @@ -1,5 +1,4 @@ /* - * * 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 @@ -16,12 +15,9 @@ * 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; +package org.apache.qpid.server.model.testmodels.singleton; -import java.util.Collection; -import java.util.Collections; import java.util.Map; import java.util.Set; @@ -32,11 +28,13 @@ import org.apache.qpid.server.model.ManagedAttributeField; import org.apache.qpid.server.model.ManagedObject; import org.apache.qpid.server.model.ManagedObjectFactoryConstructor; -@ManagedObject( category = false , type = Test2RootCategoryImpl.TEST_ROOT_TYPE ) -public class Test2RootCategoryImpl extends AbstractConfiguredObject<Test2RootCategoryImpl> - implements Test2RootCategory<Test2RootCategoryImpl> +@ManagedObject( category = false, type = TestSingletonImpl.TEST_SINGLETON_TYPE) +public class TestSingletonImpl extends AbstractConfiguredObject<TestSingletonImpl> + implements TestSingleton<TestSingletonImpl> { - public static final String TEST_ROOT_TYPE = "testroot2"; + public static final String TEST_SINGLETON_TYPE = "testsingleton"; + + public static final int DERIVED_VALUE = -100; @ManagedAttributeField private String _automatedPersistedValue; @@ -51,19 +49,23 @@ public class Test2RootCategoryImpl extends AbstractConfiguredObject<Test2RootCat private String _stringValue; @ManagedAttributeField + private int _intValue; + + @ManagedAttributeField private Map<String,String> _mapValue; @ManagedAttributeField private String _validValue; @ManagedAttributeField - private TestEnum _enumValue; + private org.apache.qpid.server.model.testmodels.singleton.TestEnum _enumValue; @ManagedAttributeField - private Set<TestEnum> _enumSetValues; + private Set<org.apache.qpid.server.model.testmodels.singleton.TestEnum> _enumSetValues; + @ManagedObjectFactoryConstructor - public Test2RootCategoryImpl(final Map<String, Object> attributes) + public TestSingletonImpl(final Map<String, Object> attributes) { super(parentsMap(), attributes, newTaskExecutor(), TestModel.getInstance()); } @@ -75,12 +77,13 @@ public class Test2RootCategoryImpl extends AbstractConfiguredObject<Test2RootCat return currentThreadTaskExecutor; } - public Test2RootCategoryImpl(final Map<String, Object> attributes, - final TaskExecutor taskExecutor) + public TestSingletonImpl(final Map<String, Object> attributes, + final TaskExecutor taskExecutor) { super(parentsMap(), attributes, taskExecutor); } + @Override public String getAutomatedPersistedValue() { @@ -100,18 +103,6 @@ public class Test2RootCategoryImpl extends AbstractConfiguredObject<Test2RootCat } @Override - public String getValidValue() - { - return _validValue; - } - - @Override - public int getDerivedAttribute() - { - return 0; - } - - @Override public String getStringValue() { return _stringValue; @@ -135,8 +126,21 @@ public class Test2RootCategoryImpl extends AbstractConfiguredObject<Test2RootCat return _enumSetValues; } - public static Collection<String> functionGeneratedValidValues() + @Override + public String getValidValue() + { + return _validValue; + } + + @Override + public int getIntValue() + { + return _intValue; + } + + @Override + public long getDerivedValue() { - return Collections.singleton("generated"); + return DERIVED_VALUE; } } |
