From 6c07f50f9e9a3f1c620a4ea7dee4f117507261d6 Mon Sep 17 00:00:00 2001 From: Keith Wall Date: Mon, 29 Dec 2014 17:08:20 +0000 Subject: 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 --- .../qpid/server/plugin/QpidServiceLoader.java | 3 +- .../server/model/AbstractConfiguredObjectTest.java | 620 --------------------- .../server/model/AttributeValueConverterTest.java | 12 +- .../model/ConfiguredObjectTypeRegistryTest.java | 218 -------- .../server/model/testmodel/Test2RootCategory.java | 40 -- .../model/testmodel/Test2RootCategoryImpl.java | 142 ----- .../server/model/testmodel/TestChildCategory.java | 43 -- .../model/testmodel/TestChildCategoryImpl.java | 72 --- .../model/testmodel/TestConfiguredObject.java | 261 --------- .../qpid/server/model/testmodel/TestEnum.java | 32 -- .../server/model/testmodel/TestManagedClass0.java | 40 -- .../server/model/testmodel/TestManagedClass1.java | 39 -- .../server/model/testmodel/TestManagedClass2.java | 38 -- .../server/model/testmodel/TestManagedClass3.java | 38 -- .../server/model/testmodel/TestManagedClass4.java | 39 -- .../server/model/testmodel/TestManagedClass5.java | 37 -- .../model/testmodel/TestManagedInterface1.java | 33 -- .../model/testmodel/TestManagedInterface2.java | 31 -- .../model/testmodel/TestManagedInterface3.java | 29 - .../qpid/server/model/testmodel/TestModel.java | 128 ----- .../server/model/testmodel/TestRootCategory.java | 80 --- .../model/testmodel/TestRootCategoryImpl.java | 143 ----- .../hierarchy/AbstractConfiguredObjectTest.java | 97 ++++ .../ConfiguredObjectTypeRegistryTest.java | 74 +++ .../server/model/testmodels/hierarchy/TestCar.java | 29 + .../model/testmodels/hierarchy/TestElecCar.java | 27 + .../model/testmodels/hierarchy/TestElecEngine.java | 27 + .../testmodels/hierarchy/TestElecEngineImpl.java | 51 ++ .../model/testmodels/hierarchy/TestEngine.java | 29 + .../testmodels/hierarchy/TestHybridEngine.java | 26 + .../testmodels/hierarchy/TestHybridEngineImpl.java | 38 ++ .../model/testmodels/hierarchy/TestKitCar.java | 26 + .../model/testmodels/hierarchy/TestKitCarImpl.java | 56 ++ .../model/testmodels/hierarchy/TestModel.java | 117 ++++ .../testmodels/hierarchy/TestPetrolEngine.java | 27 + .../testmodels/hierarchy/TestPetrolEngineImpl.java | 40 ++ .../testmodels/hierarchy/TestRechargeable.java | 30 + .../testmodels/hierarchy/TestStandardCar.java | 27 + .../testmodels/hierarchy/TestStandardCarImpl.java | 60 ++ .../lifecycle/AbstractConfiguredObjectTest.java | 217 ++++++++ .../testmodels/lifecycle/TestConfiguredObject.java | 262 +++++++++ .../singleton/AbstractConfiguredObjectTest.java | 445 +++++++++++++++ .../model/testmodels/singleton/TestEnum.java | 28 + .../model/testmodels/singleton/TestModel.java | 121 ++++ .../model/testmodels/singleton/TestSingleton.java | 83 +++ .../testmodels/singleton/TestSingletonImpl.java | 146 +++++ 46 files changed, 2091 insertions(+), 2110 deletions(-) delete mode 100644 qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/AbstractConfiguredObjectTest.java delete mode 100644 qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/ConfiguredObjectTypeRegistryTest.java delete mode 100644 qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/Test2RootCategory.java delete mode 100644 qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/Test2RootCategoryImpl.java delete mode 100644 qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestChildCategory.java delete mode 100644 qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestChildCategoryImpl.java delete mode 100644 qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestConfiguredObject.java delete mode 100644 qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestEnum.java delete mode 100644 qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestManagedClass0.java delete mode 100644 qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestManagedClass1.java delete mode 100644 qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestManagedClass2.java delete mode 100644 qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestManagedClass3.java delete mode 100644 qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestManagedClass4.java delete mode 100644 qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestManagedClass5.java delete mode 100644 qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestManagedInterface1.java delete mode 100644 qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestManagedInterface2.java delete mode 100644 qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestManagedInterface3.java delete mode 100644 qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestModel.java delete mode 100644 qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestRootCategory.java delete mode 100644 qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestRootCategoryImpl.java create mode 100644 qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/hierarchy/AbstractConfiguredObjectTest.java create mode 100644 qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/hierarchy/ConfiguredObjectTypeRegistryTest.java create mode 100644 qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/hierarchy/TestCar.java create mode 100644 qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/hierarchy/TestElecCar.java create mode 100644 qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/hierarchy/TestElecEngine.java create mode 100644 qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/hierarchy/TestElecEngineImpl.java create mode 100644 qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/hierarchy/TestEngine.java create mode 100644 qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/hierarchy/TestHybridEngine.java create mode 100644 qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/hierarchy/TestHybridEngineImpl.java create mode 100644 qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/hierarchy/TestKitCar.java create mode 100644 qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/hierarchy/TestKitCarImpl.java create mode 100644 qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/hierarchy/TestModel.java create mode 100644 qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/hierarchy/TestPetrolEngine.java create mode 100644 qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/hierarchy/TestPetrolEngineImpl.java create mode 100644 qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/hierarchy/TestRechargeable.java create mode 100644 qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/hierarchy/TestStandardCar.java create mode 100644 qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/hierarchy/TestStandardCarImpl.java create mode 100644 qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/lifecycle/AbstractConfiguredObjectTest.java create mode 100644 qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/lifecycle/TestConfiguredObject.java create mode 100644 qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/singleton/AbstractConfiguredObjectTest.java create mode 100644 qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/singleton/TestEnum.java create mode 100644 qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/singleton/TestModel.java create mode 100644 qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/singleton/TestSingleton.java create mode 100644 qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/singleton/TestSingletonImpl.java 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.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 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 attributes = Collections.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 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 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 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 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 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 expectedMap = new HashMap<>(); - expectedMap.put("field1", "value1"); - expectedMap.put("field2", "value2"); - - System.setProperty(sysPropertyName, "{ \"field1\" : \"value1\", \"field2\" : \"value2\"}"); - - final String objectName = "myName"; - - Map 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 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 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.singletonMap(ConfiguredObject.NAME, - parentName) - ); - - parent.setAttributes(Collections.singletonMap(ConfiguredObject.CONTEXT, - Collections.singletonMap("contextVal", "foo"))); - - final Map 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.singletonMap(ConfiguredObject.NAME, - parentName) - ); - - final Map 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.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.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.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 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 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 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 name = Collections.singletonMap(ConfiguredObject.NAME, (Object)objectName); - - Map 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 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 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 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 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 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 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> types = - _typeRegistry.getTypeSpecialisations(TestRootCategory.class); - - assertEquals(2, types.size()); - assertTrue(types.contains(TestRootCategoryImpl.class)); - - assertTrue(types.contains(Test2RootCategoryImpl.class)); - } - - public void testTypeSpecificAttributes() - { - Collection> special = - _typeRegistry.getTypeSpecificAttributes(Test2RootCategoryImpl.class); - assertEquals(1, special.size()); - ConfiguredObjectAttribute attr = special.iterator().next(); - assertEquals("derivedAttribute",attr.getName()); - assertTrue(attr.isDerived()); - - special = _typeRegistry.getTypeSpecificAttributes(TestRootCategoryImpl.class); - assertEquals(0, special.size()); - - } - - public void testDefaultedValues() - { - checkDefaultedValue(_typeRegistry.getAttributes((Class) TestRootCategoryImpl.class), - TestRootCategory.DEFAULTED_VALUE_DEFAULT); - - checkDefaultedValue(_typeRegistry.getAttributes((Class) Test2RootCategoryImpl.class), - Test2RootCategory.DEFAULTED_VALUE_DEFAULT); - } - - 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> expected = Collections.>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 validTypes = _typeRegistry.getValidChildTypes(TestRootCategory.class, - TestChildCategory.class); - assertThat(validTypes, hasItem("testchild")); - assertThat(validTypes.size(), is(1)); - } - - - private ConfiguredObjectTypeRegistry createConfiguredObjectTypeRegistry(Class... supportedTypes) - { - ConfiguredObjectRegistration configuredObjectRegistration = createConfiguredObjectRegistration(supportedTypes); - - return new ConfiguredObjectTypeRegistry(Arrays.asList(configuredObjectRegistration), Arrays.asList(TestRootCategory.class, TestChildCategory.class)); - } - - private ConfiguredObjectRegistration createConfiguredObjectRegistration(final Class... supportedTypes) - { - return new ConfiguredObjectRegistration() - { - @Override - public Collection> getConfiguredObjectClasses() - { - return Arrays.asList(supportedTypes); - } - - @Override - public String getType() - { - return "test"; - } - }; - } - - private void checkDefaultedValue(final Collection> attrs, - final String defaultedValueDefault) - { - boolean found = false; - for(ConfiguredObjectAttribute attr : attrs) - { - if(attr.getName().equals("defaultedValue")) - { - assertEquals(defaultedValueDefault, ((ConfiguredAutomatedAttribute)attr).defaultValue()); - found = true; - break; - } - - } - assertTrue("Could not find attribute defaultedValue", found); - } - - private void checkValidValues(final String attrName, final Collection> attrs, - final Collection validValues) - { - boolean found = false; - for(ConfiguredObjectAttribute attr : attrs) - { - if(attr.getName().equals(attrName)) - { - Collection foundValues = ((ConfiguredAutomatedAttribute) attr).validValues(); - assertEquals("Valid values not as expected, counts differ", validValues.size(), foundValues.size()); - assertTrue("Valid values do not include all expected values", foundValues.containsAll(validValues)); - assertTrue("Valid values contain unexpected addtional values", validValues.containsAll(foundValues)); - found = true; - break; - } - - } - assertTrue("Could not find attribute " + attrName, found); - } -} diff --git a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/Test2RootCategory.java b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/Test2RootCategory.java 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> extends TestRootCategory -{ - String DEFAULTED_VALUE_DEFAULT = "differentDefault"; - - @Override - @ManagedAttribute( defaultValue = DEFAULTED_VALUE_DEFAULT) - String getDefaultedValue(); - - @Override - @ManagedAttribute( validValues = {"org.apache.qpid.server.model.testmodel.Test2RootCategoryImpl#functionGeneratedValidValues()"}) - String getValidValue(); - - @DerivedAttribute - public int getDerivedAttribute(); -} diff --git a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/Test2RootCategoryImpl.java b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/Test2RootCategoryImpl.java deleted file mode 100644 index 3a415b9a4c..0000000000 --- a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/Test2RootCategoryImpl.java +++ /dev/null @@ -1,142 +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.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; - -@ManagedObject( category = false , type = Test2RootCategoryImpl.TEST_ROOT_TYPE ) -public class Test2RootCategoryImpl extends AbstractConfiguredObject - implements Test2RootCategory -{ - public static final String TEST_ROOT_TYPE = "testroot2"; - - @ManagedAttributeField - private String _automatedPersistedValue; - - @ManagedAttributeField - private String _automatedNonPersistedValue; - - @ManagedAttributeField - private String _defaultedValue; - - @ManagedAttributeField - private String _stringValue; - - @ManagedAttributeField - private Map _mapValue; - - @ManagedAttributeField - private String _validValue; - - @ManagedAttributeField - private TestEnum _enumValue; - - @ManagedAttributeField - private Set _enumSetValues; - - @ManagedObjectFactoryConstructor - public Test2RootCategoryImpl(final Map attributes) - { - super(parentsMap(), attributes, newTaskExecutor(), TestModel.getInstance()); - } - - private static CurrentThreadTaskExecutor newTaskExecutor() - { - CurrentThreadTaskExecutor currentThreadTaskExecutor = new CurrentThreadTaskExecutor(); - currentThreadTaskExecutor.start(); - return currentThreadTaskExecutor; - } - - public Test2RootCategoryImpl(final Map attributes, - final TaskExecutor taskExecutor) - { - super(parentsMap(), attributes, taskExecutor); - } - - @Override - public String getAutomatedPersistedValue() - { - return _automatedPersistedValue; - } - - @Override - public String getAutomatedNonPersistedValue() - { - return _automatedNonPersistedValue; - } - - @Override - public String getDefaultedValue() - { - return _defaultedValue; - } - - @Override - public String getValidValue() - { - return _validValue; - } - - @Override - public int getDerivedAttribute() - { - return 0; - } - - @Override - public String getStringValue() - { - return _stringValue; - } - - @Override - public Map getMapValue() - { - return _mapValue; - } - - @Override - public TestEnum getEnumValue() - { - return _enumValue; - } - - @Override - public Set getEnumSetValues() - { - return _enumSetValues; - } - - public static Collection functionGeneratedValidValues() - { - return Collections.singleton("generated"); - } -} diff --git a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestChildCategory.java b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestChildCategory.java 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> extends ConfiguredObject -{ - 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 getIntegerSet(); -} diff --git a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestChildCategoryImpl.java b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestChildCategoryImpl.java deleted file mode 100644 index 778d8e9cea..0000000000 --- a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestChildCategoryImpl.java +++ /dev/null @@ -1,72 +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 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 implements TestChildCategory -{ - public static final String TEST_CHILD_TYPE = "testchild"; - - - @ManagedAttributeField - private String _validValueNotInterpolated; - - @ManagedAttributeField - private int _intValue; - - @ManagedAttributeField - private Set _integerSet; - - - @ManagedObjectFactoryConstructor - public TestChildCategoryImpl(final Map attributes, TestRootCategory parent) - { - super(parentsMap(parent), attributes); - } - - @Override - public String getValidValueNotInterpolated() - { - return _validValueNotInterpolated; - } - - @Override - public int getIntValue() - { - return _intValue; - } - - @Override - public Set getIntegerSet() - { - return _integerSet; - } -} 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/testmodel/TestConfiguredObject.java deleted file mode 100644 index 8f61e37ad4..0000000000 --- a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestConfiguredObject.java +++ /dev/null @@ -1,261 +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 static org.mockito.Mockito.mock; - -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.Map; - -import org.apache.qpid.server.configuration.IllegalConfigurationException; -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.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.ManagedObject; -import org.apache.qpid.server.model.Model; -import org.apache.qpid.server.model.State; -import org.apache.qpid.server.model.StateTransition; -import org.apache.qpid.server.plugin.ConfiguredObjectRegistration; - -@ManagedObject -public class TestConfiguredObject extends AbstractConfiguredObject -{ - private boolean _opened; - private boolean _validated; - private boolean _resolved; - private boolean _throwExceptionOnOpen; - private boolean _throwExceptionOnValidationOnCreate; - private boolean _throwExceptionOnPostResolve; - private boolean _throwExceptionOnCreate; - private boolean _throwExceptionOnValidate; - - public final static Map, ConfiguredObject> createParents(ConfiguredObject parent) - { - return Collections., ConfiguredObject>singletonMap(parent.getCategoryClass(), parent); - } - - public TestConfiguredObject(String name) - { - this(name, mock(ConfiguredObject.class), CurrentThreadTaskExecutor.newStartedInstance()); - } - - public TestConfiguredObject(String name, ConfiguredObject parent, TaskExecutor taskExecutor) - { - this(createParents(parent), Collections.singletonMap(ConfiguredObject.NAME, name), taskExecutor, TestConfiguredObjectModel.INSTANCE); - } - - public TestConfiguredObject(ConfiguredObject parent, Map attributes) - { - this(createParents(parent), attributes, parent.getTaskExecutor(), TestConfiguredObjectModel.INSTANCE); - } - - public TestConfiguredObject(Map parents, Map attributes, TaskExecutor taskExecutor, Model model) - { - super(parents, attributes, taskExecutor, model); - _opened = false; - } - - @Override - protected void postResolve() - { - if (_throwExceptionOnPostResolve) - { - throw new IllegalConfigurationException("Cannot resolve"); - } - _resolved = true; - } - - @Override - protected void onCreate() - { - if (_throwExceptionOnCreate) - { - throw new IllegalConfigurationException("Cannot create"); - } - } - - @Override - protected void onOpen() - { - if (_throwExceptionOnOpen) - { - throw new IllegalConfigurationException("Cannot open"); - } - _opened = true; - } - - @Override - protected void validateOnCreate() - { - if (_throwExceptionOnValidationOnCreate) - { - throw new IllegalConfigurationException("Cannot validate on create"); - } - } - - @Override - public void onValidate() - { - if (_throwExceptionOnValidate) - { - throw new IllegalConfigurationException("Cannot validate"); - } - _validated = true; - } - - @StateTransition( currentState = {State.ERRORED, State.UNINITIALIZED}, desiredState = State.ACTIVE ) - protected void activate() - { - setState(State.ACTIVE); - } - - @StateTransition( currentState = {State.ERRORED, State.UNINITIALIZED}, desiredState = State.DELETED ) - protected void doDelete() - { - setState(State.DELETED); - } - - public boolean isOpened() - { - return _opened; - } - - public void setThrowExceptionOnOpen(boolean throwException) - { - _throwExceptionOnOpen = throwException; - } - - public void setThrowExceptionOnValidationOnCreate(boolean throwException) - { - _throwExceptionOnValidationOnCreate = throwException; - } - - public void setThrowExceptionOnPostResolve(boolean throwException) - { - _throwExceptionOnPostResolve = throwException; - } - - public void setThrowExceptionOnCreate(boolean throwExceptionOnCreate) - { - _throwExceptionOnCreate = throwExceptionOnCreate; - } - - public void setThrowExceptionOnValidate(boolean throwException) - { - _throwExceptionOnValidate= throwException; - } - - public boolean isValidated() - { - return _validated; - } - - public boolean isResolved() - { - return _resolved; - } - - public static class TestConfiguredObjectModel extends Model - { - - private Collection> CATEGORIES = Collections.>singleton(TestConfiguredObject.class); - private ConfiguredObjectFactoryImpl _configuredObjectFactory; - - private static TestConfiguredObjectModel INSTANCE = new TestConfiguredObjectModel(); - private ConfiguredObjectTypeRegistry _configuredObjectTypeRegistry; - - private TestConfiguredObjectModel() - { - _configuredObjectFactory = new ConfiguredObjectFactoryImpl(this); - ConfiguredObjectRegistration configuredObjectRegistration = new ConfiguredObjectRegistration() - { - @Override - public Collection> getConfiguredObjectClasses() - { - return CATEGORIES; - } - - @Override - public String getType() - { - return TestConfiguredObjectModel.class.getSimpleName(); - } - }; - _configuredObjectTypeRegistry = new ConfiguredObjectTypeRegistry(Arrays.asList(configuredObjectRegistration), CATEGORIES); - } - - @Override - public Collection> getSupportedCategories() - { - return CATEGORIES; - } - - @Override - public Collection> getChildTypes(Class parent) - { - return TestConfiguredObject.class.isAssignableFrom(parent) - ? CATEGORIES - : Collections.>emptySet(); - } - - @Override - public Class getRootCategory() - { - return TestConfiguredObject.class; - } - - @Override - public Collection> getParentTypes(final Class child) - { - return TestConfiguredObject.class.isAssignableFrom(child) - ? CATEGORIES - : Collections.>emptySet(); - } - - @Override - public int getMajorVersion() - { - return 99; - } - - @Override - public int getMinorVersion() - { - return 99; - } - - @Override - public ConfiguredObjectFactory getObjectFactory() - { - return _configuredObjectFactory; - } - - @Override - public ConfiguredObjectTypeRegistry getTypeRegistry() - { - return _configuredObjectTypeRegistry; - } - } -} 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/testmodel/TestEnum.java deleted file mode 100644 index 75c6c197ce..0000000000 --- a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestEnum.java +++ /dev/null @@ -1,32 +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.ArrayList; -import java.util.Collection; -import java.util.List; - -public enum TestEnum -{ - TEST_ENUM1, - TEST_ENUM2, - TEST_ENUM3; -} 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/testmodel/TestManagedClass0.java deleted file mode 100644 index 1e53f2ecd5..0000000000 --- a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestManagedClass0.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 java.util.Map; - -import org.apache.qpid.server.model.ManagedInterface; -import org.apache.qpid.server.model.ManagedObject; - -/** - * 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 -{ - public TestManagedClass0(final Map attributes, TestRootCategory parent) - { - super(attributes, parent); - } -} 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 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 attributes, TestRootCategory parent) - { - super(attributes, parent); - } -} 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/testmodel/TestManagedClass3.java deleted file mode 100644 index c78f7404a6..0000000000 --- a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestManagedClass3.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 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 -{ - public TestManagedClass3(final Map 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 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 attributes, TestRootCategory parent) - { - super(attributes, parent); - } -} 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/testmodel/TestManagedInterface1.java deleted file mode 100644 index aac5adad18..0000000000 --- a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestManagedInterface1.java +++ /dev/null @@ -1,33 +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.ManagedAnnotation; -import org.apache.qpid.server.model.ManagedInterface; - -/** - * 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 -{ -} 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/testmodel/TestManagedInterface2.java deleted file mode 100644 index 7ecb2d63ac..0000000000 --- a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestManagedInterface2.java +++ /dev/null @@ -1,31 +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.ManagedInterface; - -/** - * 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 -{ -} 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/testmodel/TestManagedInterface3.java deleted file mode 100644 index d1d0a1b820..0000000000 --- a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestManagedInterface3.java +++ /dev/null @@ -1,29 +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.ManagedAnnotation; -import org.apache.qpid.server.model.ManagedInterface; - -@ManagedAnnotation -public interface TestManagedInterface3 extends ManagedInterface -{ -} diff --git a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestModel.java b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestModel.java deleted file mode 100644 index 090c72762d..0000000000 --- a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestModel.java +++ /dev/null @@ -1,128 +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 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[] _supportedClasses = - new Class[] { - TestRootCategory.class, - TestChildCategory.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 ConfiguredObjectRegistration() - { - @Override - public Collection> getConfiguredObjectClasses() - { - return Arrays.>asList(TestRootCategoryImpl.class, Test2RootCategoryImpl.class); - } - - @Override - public String getType() - { - return "org.apache.qpid.server.model.testmodel"; - } - }; - _registry = new ConfiguredObjectTypeRegistry(Arrays.asList(configuredObjectRegistration), getSupportedCategories()); - } - - - @Override - public Collection> getSupportedCategories() - { - return Arrays.asList(_supportedClasses); - } - - @Override - public Collection> getChildTypes(final Class parent) - { - return TestRootCategory.class.isAssignableFrom(parent) - ? Collections.>singleton(TestChildCategory.class) - : Collections.>emptySet(); - } - - @Override - public Class getRootCategory() - { - return TestRootCategory.class; - } - - @Override - public Collection> getParentTypes(final Class child) - { - return TestChildCategory.class.isAssignableFrom(child) - ? Collections.>singleton(TestRootCategory.class) - : Collections.>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/testmodel/TestRootCategory.java b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestRootCategory.java deleted file mode 100644 index d8d26b86e6..0000000000 --- a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestRootCategory.java +++ /dev/null @@ -1,80 +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.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.ManagedAttribute; -import org.apache.qpid.server.model.ManagedContextDefault; -import org.apache.qpid.server.model.ManagedObject; - -@ManagedObject( defaultType = TestRootCategoryImpl.TEST_ROOT_TYPE ) -public interface TestRootCategory> extends ConfiguredObject -{ - String AUTOMATED_PERSISTED_VALUE = "automatedPersistedValue"; - String AUTOMATED_NONPERSISTED_VALUE = "automatedNonPersistedValue"; - String DEFAULTED_VALUE = "defaultedValue"; - String STRING_VALUE = "stringValue"; - String MAP_VALUE = "mapValue"; - String VALID_VALUE = "validValue"; - String ENUM_VALUE = "enumValue"; - String ENUMSET_VALUES = "enumSetValues"; - - String TEST_CONTEXT_DEFAULT = "TEST_CONTEXT_DEFAULT"; - - @ManagedContextDefault(name = TEST_CONTEXT_DEFAULT) - String testGlobalDefault = "default"; - - - @ManagedAttribute - String getAutomatedPersistedValue(); - - @ManagedAttribute( persist = false ) - String getAutomatedNonPersistedValue(); - - String DEFAULTED_VALUE_DEFAULT = "myDefaultVar"; - String VALID_VALUE1 = "FOO"; - String VALID_VALUE2 = "BAR"; - - @ManagedAttribute( defaultValue = DEFAULTED_VALUE_DEFAULT) - String getDefaultedValue(); - - @ManagedAttribute - String getStringValue(); - - @ManagedAttribute - Map getMapValue(); - - @ManagedAttribute - TestEnum getEnumValue(); - - @ManagedAttribute(validValues = {VALID_VALUE1, VALID_VALUE2} ) - String getValidValue(); - - @ManagedAttribute( validValues = {"[\"TEST_ENUM1\"]", "[\"TEST_ENUM2\", \"TEST_ENUM3\"]"}) - Set getEnumSetValues(); - -} 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 - implements TestRootCategory -{ - 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 _mapValue; - - @ManagedAttributeField - private String _validValue; - - @ManagedAttributeField - private TestEnum _enumValue; - - @ManagedAttributeField - private Set _enumSetValues; - - - @ManagedObjectFactoryConstructor - public TestRootCategoryImpl(final Map attributes) - { - super(parentsMap(), attributes, newTaskExecutor(), TestModel.getInstance()); - } - - private static CurrentThreadTaskExecutor newTaskExecutor() - { - CurrentThreadTaskExecutor currentThreadTaskExecutor = new CurrentThreadTaskExecutor(); - currentThreadTaskExecutor.start(); - return currentThreadTaskExecutor; - } - - public TestRootCategoryImpl(final Map 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 getMapValue() - { - return _mapValue; - } - - @Override - public TestEnum getEnumValue() - { - return _enumValue; - } - - @Override - public Set getEnumSetValues() - { - return _enumSetValues; - } - - @Override - public String getValidValue() - { - return _validValue; - } - - @SuppressWarnings("unused") - public static Map> getSupportedChildTypes() - { - return Collections.singletonMap(TestChildCategory.class.getSimpleName(), (Collection)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 attributes = Collections.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 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 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 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> 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 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 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> elecEngIntfcs = _typeRegistry.getManagedInterfaces(TestElecEngine.class); + assertThat(elecEngIntfcs, hasItem(TestRechargeable.class)); + assertThat(elecEngIntfcs.size(), is(1)); + + // The pertrol engine implements no additional interfaces + Set> 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/testmodels/hierarchy/TestCar.java b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/hierarchy/TestCar.java new file mode 100644 index 0000000000..e2c436e31b --- /dev/null +++ b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/hierarchy/TestCar.java @@ -0,0 +1,29 @@ +/* + * + * 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.ConfiguredObject; +import org.apache.qpid.server.model.ManagedObject; + +@ManagedObject( defaultType = TestStandardCarImpl.TEST_STANDARD_CAR_TYPE) +public interface TestCar> extends ConfiguredObject +{ +} 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> extends TestCar +{ +} 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> extends TestEngine, TestRechargeable +{ +} diff --git a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/hierarchy/TestElecEngineImpl.java b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/hierarchy/TestElecEngineImpl.java new file mode 100644 index 0000000000..c875aea369 --- /dev/null +++ b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/hierarchy/TestElecEngineImpl.java @@ -0,0 +1,51 @@ +/* + * + * 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.model.AbstractConfiguredObject; +import org.apache.qpid.server.model.ManagedObject; +import org.apache.qpid.server.model.ManagedObjectFactoryConstructor; + +@ManagedObject( category = false, type = TestElecEngineImpl.TEST_ELEC_ENGINE_TYPE) +public class TestElecEngineImpl + extends AbstractConfiguredObject implements TestElecEngine +{ + public static final String TEST_ELEC_ENGINE_TYPE = "ELEC"; + + @ManagedObjectFactoryConstructor + public TestElecEngineImpl(final Map attributes, TestCar parent) + { + super(parentsMap(parent), attributes); + } + + @SuppressWarnings("unused") + public static Map> getSupportedChildTypes() + { + Collection types = Arrays.asList(TestElecEngineImpl.TEST_ELEC_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/hierarchy/TestEngine.java b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/hierarchy/TestEngine.java new file mode 100644 index 0000000000..a6754b2a64 --- /dev/null +++ b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/hierarchy/TestEngine.java @@ -0,0 +1,29 @@ +/* + * + * 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.ConfiguredObject; +import org.apache.qpid.server.model.ManagedObject; + +@ManagedObject(category = true) +public interface TestEngine> extends ConfiguredObject +{ +} 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> extends TestEngine, TestRechargeable +{ +} diff --git a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/hierarchy/TestHybridEngineImpl.java b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/hierarchy/TestHybridEngineImpl.java new file mode 100644 index 0000000000..dd6cd03a69 --- /dev/null +++ b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/hierarchy/TestHybridEngineImpl.java @@ -0,0 +1,38 @@ +/* + * 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.model.AbstractConfiguredObject; +import org.apache.qpid.server.model.ManagedObject; +import org.apache.qpid.server.model.ManagedObjectFactoryConstructor; + +@ManagedObject( category = false, type = TestHybridEngineImpl.TEST_HYBRID_ENGINE_TYPE) +public class TestHybridEngineImpl extends AbstractConfiguredObject implements TestHybridEngine +{ + public static final String TEST_HYBRID_ENGINE_TYPE = "HYBRID"; + + @ManagedObjectFactoryConstructor + public TestHybridEngineImpl(final Map attributes, TestCar 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> extends TestCar +{ +} 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 + implements TestKitCar +{ + public static final String TEST_KITCAR_TYPE = "testkitcar"; + + @ManagedObjectFactoryConstructor + public TestKitCarImpl(final Map attributes) + { + super(parentsMap(), attributes, newTaskExecutor(), TestModel.getInstance()); + } + + @Override + public C createChild(final Class childClass, + final Map 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[] _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> getSupportedCategories() + { + return Arrays.asList(_supportedCategories); + } + + @Override + public Collection> getChildTypes(final Class parent) + { + return TestCar.class.isAssignableFrom(parent) + ? Collections.>singleton(TestEngine.class) + : Collections.>emptySet(); + } + + @Override + public Class getRootCategory() + { + return TestCar.class; + } + + @Override + public Collection> getParentTypes(final Class child) + { + return TestEngine.class.isAssignableFrom(child) + ? Collections.>singleton(TestCar.class) + : Collections.>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> extends TestEngine +{ +} diff --git a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/hierarchy/TestPetrolEngineImpl.java b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/hierarchy/TestPetrolEngineImpl.java new file mode 100644 index 0000000000..8047db3a34 --- /dev/null +++ b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/hierarchy/TestPetrolEngineImpl.java @@ -0,0 +1,40 @@ +/* + * + * 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.model.AbstractConfiguredObject; +import org.apache.qpid.server.model.ManagedObject; +import org.apache.qpid.server.model.ManagedObjectFactoryConstructor; + +@ManagedObject( category = false, type = TestPetrolEngineImpl.TEST_PETROL_ENGINE_TYPE) +public class TestPetrolEngineImpl + extends AbstractConfiguredObject implements TestPetrolEngine +{ + public static final String TEST_PETROL_ENGINE_TYPE = "PETROL"; + + @ManagedObjectFactoryConstructor + public TestPetrolEngineImpl(final Map attributes, TestCar parent) + { + super(parentsMap(parent), attributes); + } +} diff --git a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/hierarchy/TestRechargeable.java b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/hierarchy/TestRechargeable.java new file mode 100644 index 0000000000..26eed78b28 --- /dev/null +++ b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/hierarchy/TestRechargeable.java @@ -0,0 +1,30 @@ +/* + * + * 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.ManagedAnnotation; +import org.apache.qpid.server.model.ManagedInterface; + + +@ManagedAnnotation +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> extends TestCar +{ +} 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 + implements TestStandardCar +{ + public static final String TEST_STANDARD_CAR_TYPE = "testpertrolcar"; + + @ManagedObjectFactoryConstructor + public TestStandardCarImpl(final Map attributes) + { + super(parentsMap(), attributes, newTaskExecutor(), TestModel.getInstance()); + } + + private static CurrentThreadTaskExecutor newTaskExecutor() + { + CurrentThreadTaskExecutor currentThreadTaskExecutor = new CurrentThreadTaskExecutor(); + currentThreadTaskExecutor.start(); + return currentThreadTaskExecutor; + } + + @SuppressWarnings("unused") + public static Map> getSupportedChildTypes() + { + Collection 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.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.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.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/testmodels/lifecycle/TestConfiguredObject.java b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/lifecycle/TestConfiguredObject.java new file mode 100644 index 0000000000..0b35ba9330 --- /dev/null +++ b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/lifecycle/TestConfiguredObject.java @@ -0,0 +1,262 @@ +/* + * 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 static org.mockito.Mockito.mock; + +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.Map; + +import org.apache.qpid.server.configuration.IllegalConfigurationException; +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.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.ManagedObject; +import org.apache.qpid.server.model.Model; +import org.apache.qpid.server.model.State; +import org.apache.qpid.server.model.StateTransition; +import org.apache.qpid.server.plugin.ConfiguredObjectRegistration; + +@ManagedObject +public class TestConfiguredObject extends AbstractConfiguredObject +{ + private boolean _opened; + private boolean _validated; + private boolean _resolved; + private boolean _throwExceptionOnOpen; + private boolean _throwExceptionOnValidationOnCreate; + private boolean _throwExceptionOnPostResolve; + private boolean _throwExceptionOnCreate; + private boolean _throwExceptionOnValidate; + + public final static Map, ConfiguredObject> createParents(ConfiguredObject parent) + { + return Collections., ConfiguredObject>singletonMap(parent.getCategoryClass(), parent); + } + + public TestConfiguredObject(String name) + { + this(name, mock(ConfiguredObject.class), CurrentThreadTaskExecutor.newStartedInstance()); + } + + public TestConfiguredObject(String name, ConfiguredObject parent, TaskExecutor taskExecutor) + { + this(createParents(parent), Collections.singletonMap(ConfiguredObject.NAME, name), taskExecutor, TestConfiguredObjectModel.INSTANCE); + } + + public TestConfiguredObject(ConfiguredObject parent, Map attributes) + { + this(createParents(parent), attributes, parent.getTaskExecutor(), TestConfiguredObjectModel.INSTANCE); + } + + public TestConfiguredObject(Map parents, Map attributes, TaskExecutor taskExecutor, Model model) + { + super(parents, attributes, taskExecutor, model); + _opened = false; + } + + @Override + protected void postResolve() + { + if (_throwExceptionOnPostResolve) + { + throw new IllegalConfigurationException("Cannot resolve"); + } + _resolved = true; + } + + @Override + protected void onCreate() + { + if (_throwExceptionOnCreate) + { + throw new IllegalConfigurationException("Cannot create"); + } + } + + @Override + protected void onOpen() + { + if (_throwExceptionOnOpen) + { + throw new IllegalConfigurationException("Cannot open"); + } + _opened = true; + } + + @Override + protected void validateOnCreate() + { + if (_throwExceptionOnValidationOnCreate) + { + throw new IllegalConfigurationException("Cannot validate on create"); + } + } + + @Override + public void onValidate() + { + if (_throwExceptionOnValidate) + { + throw new IllegalConfigurationException("Cannot validate"); + } + _validated = true; + } + + @StateTransition( currentState = {State.ERRORED, State.UNINITIALIZED}, desiredState = State.ACTIVE ) + protected void activate() + { + setState(State.ACTIVE); + } + + @StateTransition( currentState = {State.ERRORED, State.UNINITIALIZED}, desiredState = State.DELETED ) + protected void doDelete() + { + setState(State.DELETED); + } + + public boolean isOpened() + { + return _opened; + } + + public void setThrowExceptionOnOpen(boolean throwException) + { + _throwExceptionOnOpen = throwException; + } + + public void setThrowExceptionOnValidationOnCreate(boolean throwException) + { + _throwExceptionOnValidationOnCreate = throwException; + } + + public void setThrowExceptionOnPostResolve(boolean throwException) + { + _throwExceptionOnPostResolve = throwException; + } + + public void setThrowExceptionOnCreate(boolean throwExceptionOnCreate) + { + _throwExceptionOnCreate = throwExceptionOnCreate; + } + + public void setThrowExceptionOnValidate(boolean throwException) + { + _throwExceptionOnValidate= throwException; + } + + public boolean isValidated() + { + return _validated; + } + + public boolean isResolved() + { + return _resolved; + } + + public static class TestConfiguredObjectModel extends Model + { + + private Collection> CATEGORIES = Collections.>singleton(TestConfiguredObject.class); + private ConfiguredObjectFactoryImpl _configuredObjectFactory; + + private static TestConfiguredObjectModel INSTANCE = new TestConfiguredObjectModel(); + private ConfiguredObjectTypeRegistry _configuredObjectTypeRegistry; + + private TestConfiguredObjectModel() + { + _configuredObjectFactory = new ConfiguredObjectFactoryImpl(this); + ConfiguredObjectRegistration configuredObjectRegistration = new ConfiguredObjectRegistration() + { + @Override + public Collection> getConfiguredObjectClasses() + { + return CATEGORIES; + } + + @Override + public String getType() + { + return TestConfiguredObjectModel.class.getSimpleName(); + } + }; + _configuredObjectTypeRegistry = new ConfiguredObjectTypeRegistry(Arrays.asList(configuredObjectRegistration), CATEGORIES); + } + + @Override + public Collection> getSupportedCategories() + { + return CATEGORIES; + } + + @Override + public Collection> getChildTypes(Class parent) + { + return TestConfiguredObject.class.isAssignableFrom(parent) + ? CATEGORIES + : Collections.>emptySet(); + } + + @Override + public Class getRootCategory() + { + return TestConfiguredObject.class; + } + + @Override + public Collection> getParentTypes(final Class child) + { + return TestConfiguredObject.class.isAssignableFrom(child) + ? CATEGORIES + : Collections.>emptySet(); + } + + @Override + public int getMajorVersion() + { + return 99; + } + + @Override + public int getMinorVersion() + { + return 99; + } + + @Override + public ConfiguredObjectFactory getObjectFactory() + { + return _configuredObjectFactory; + } + + @Override + public ConfiguredObjectTypeRegistry getTypeRegistry() + { + return _configuredObjectTypeRegistry; + } + } +} 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.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 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 attributes = Collections.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 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 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 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 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 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 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 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 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 expectedMap = new HashMap<>(); + expectedMap.put("field1", "value1"); + expectedMap.put("field2", "value2"); + + System.setProperty(sysPropertyName, "{ \"field1\" : \"value1\", \"field2\" : \"value2\"}"); + + final String objectName = "myName"; + + Map 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 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 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 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 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 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 name = Collections.singletonMap(ConfiguredObject.NAME, (Object)objectName); + + Map 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 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 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 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 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/testmodels/singleton/TestEnum.java b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/singleton/TestEnum.java new file mode 100644 index 0000000000..d8ec160651 --- /dev/null +++ b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/singleton/TestEnum.java @@ -0,0 +1,28 @@ +/* + * 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; + + +public enum TestEnum +{ + TEST_ENUM1, + TEST_ENUM2, + TEST_ENUM3; +} diff --git a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/singleton/TestModel.java b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/singleton/TestModel.java new file mode 100644 index 0000000000..330127cfa2 --- /dev/null +++ b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/singleton/TestModel.java @@ -0,0 +1,121 @@ +/* + * 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.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[] _supportedClasses = + new Class[] { + TestSingleton.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 ConfiguredObjectRegistration() + { + @Override + public Collection> getConfiguredObjectClasses() + { + return Arrays.asList(_supportedClasses); + } + + @Override + public String getType() + { + return "org.apache.qpid.server.model.testmodels.attribute"; + } + }; + _registry = new ConfiguredObjectTypeRegistry(Arrays.asList(configuredObjectRegistration), getSupportedCategories()); + } + + + @Override + public Collection> getSupportedCategories() + { + return Arrays.asList(_supportedClasses); + } + + @Override + public Collection> getChildTypes(final Class parent) + { + return Collections.emptySet(); + } + + @Override + public Class getRootCategory() + { + return TestSingleton.class; + } + + @Override + public Collection> getParentTypes(final Class child) + { + return Collections.>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/singleton/TestSingleton.java b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/singleton/TestSingleton.java new file mode 100644 index 0000000000..e36097655b --- /dev/null +++ b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/singleton/TestSingleton.java @@ -0,0 +1,83 @@ +/* + * 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.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 = TestSingletonImpl.TEST_SINGLETON_TYPE) +public interface TestSingleton> extends ConfiguredObject +{ + 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 ENUM_VALUE = "enumValue"; + String INT_VALUE = "intValue"; + String VALID_VALUE = "validValue"; + String ENUMSET_VALUES = "enumSetValues"; + + String TEST_CONTEXT_DEFAULT = "TEST_CONTEXT_DEFAULT"; + + @ManagedContextDefault(name = TEST_CONTEXT_DEFAULT) + String testGlobalDefault = "default"; + + @ManagedAttribute + String getAutomatedPersistedValue(); + + @ManagedAttribute( persist = false ) + String getAutomatedNonPersistedValue(); + + String DEFAULTED_VALUE_DEFAULT = "myDefaultVar"; + String VALID_VALUE1 = "FOO"; + String VALID_VALUE2 = "BAR"; + + @ManagedAttribute( defaultValue = DEFAULTED_VALUE_DEFAULT) + String getDefaultedValue(); + + @ManagedAttribute + String getStringValue(); + + @ManagedAttribute + Map getMapValue(); + + @ManagedAttribute + TestEnum getEnumValue(); + + @ManagedAttribute + int getIntValue(); + + @ManagedAttribute(validValues = {VALID_VALUE1, VALID_VALUE2} ) + String getValidValue(); + + @ManagedAttribute( validValues = {"[\"TEST_ENUM1\"]", "[\"TEST_ENUM2\", \"TEST_ENUM3\"]"}) + Set getEnumSetValues(); + + @DerivedAttribute + long getDerivedValue(); + +} diff --git a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/singleton/TestSingletonImpl.java b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/singleton/TestSingletonImpl.java new file mode 100644 index 0000000000..47c30030b2 --- /dev/null +++ b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/singleton/TestSingletonImpl.java @@ -0,0 +1,146 @@ +/* + * 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.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; + +@ManagedObject( category = false, type = TestSingletonImpl.TEST_SINGLETON_TYPE) +public class TestSingletonImpl extends AbstractConfiguredObject + implements TestSingleton +{ + public static final String TEST_SINGLETON_TYPE = "testsingleton"; + + public static final int DERIVED_VALUE = -100; + + @ManagedAttributeField + private String _automatedPersistedValue; + + @ManagedAttributeField + private String _automatedNonPersistedValue; + + @ManagedAttributeField + private String _defaultedValue; + + @ManagedAttributeField + private String _stringValue; + + @ManagedAttributeField + private int _intValue; + + @ManagedAttributeField + private Map _mapValue; + + @ManagedAttributeField + private String _validValue; + + @ManagedAttributeField + private org.apache.qpid.server.model.testmodels.singleton.TestEnum _enumValue; + + @ManagedAttributeField + private Set _enumSetValues; + + + @ManagedObjectFactoryConstructor + public TestSingletonImpl(final Map attributes) + { + super(parentsMap(), attributes, newTaskExecutor(), TestModel.getInstance()); + } + + private static CurrentThreadTaskExecutor newTaskExecutor() + { + CurrentThreadTaskExecutor currentThreadTaskExecutor = new CurrentThreadTaskExecutor(); + currentThreadTaskExecutor.start(); + return currentThreadTaskExecutor; + } + + public TestSingletonImpl(final Map 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 getMapValue() + { + return _mapValue; + } + + @Override + public TestEnum getEnumValue() + { + return _enumValue; + } + + @Override + public Set getEnumSetValues() + { + return _enumSetValues; + } + + @Override + public String getValidValue() + { + return _validValue; + } + + @Override + public int getIntValue() + { + return _intValue; + } + + @Override + public long getDerivedValue() + { + return DERIVED_VALUE; + } +} -- cgit v1.2.1