summaryrefslogtreecommitdiff
path: root/qpid/java/broker-core/src/test/java/org/apache
diff options
context:
space:
mode:
Diffstat (limited to 'qpid/java/broker-core/src/test/java/org/apache')
-rw-r--r--qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/ConfigureObjectTypeRegistryTest.java95
-rw-r--r--qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/Test2RootCategory.java35
-rw-r--r--qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/Test2RootCategoryImpl.java118
-rw-r--r--qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestModel.java24
4 files changed, 272 insertions, 0 deletions
diff --git a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/ConfigureObjectTypeRegistryTest.java b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/ConfigureObjectTypeRegistryTest.java
new file mode 100644
index 0000000000..8bd599f22f
--- /dev/null
+++ b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/ConfigureObjectTypeRegistryTest.java
@@ -0,0 +1,95 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.server.model;
+
+import java.util.Collection;
+
+import junit.framework.TestCase;
+
+import org.apache.qpid.server.model.testmodel.Test2RootCategory;
+import org.apache.qpid.server.model.testmodel.Test2RootCategoryImpl;
+import org.apache.qpid.server.model.testmodel.TestModel;
+import org.apache.qpid.server.model.testmodel.TestRootCategory;
+import org.apache.qpid.server.model.testmodel.TestRootCategoryImpl;
+
+public class ConfigureObjectTypeRegistryTest extends TestCase
+{
+ private ConfiguredObjectTypeRegistry _typeRegistry;
+
+ @Override
+ public void setUp() throws Exception
+ {
+ super.setUp();
+ Model model = TestModel.getInstance();
+ _typeRegistry = model.getTypeRegistry();
+ }
+
+ public void testAllTypesRegistered()
+ {
+ Collection<Class<? extends ConfiguredObject>> types =
+ _typeRegistry.getTypeSpecialisations(TestRootCategory.class);
+
+ assertEquals(2, types.size());
+ assertTrue(types.contains(TestRootCategoryImpl.class));
+
+ assertTrue(types.contains(Test2RootCategoryImpl.class));
+ }
+
+ public void testTypeSpecificAttributes()
+ {
+ Collection<ConfiguredObjectAttribute<?, ?>> special =
+ _typeRegistry.getTypeSpecificAttributes(Test2RootCategoryImpl.class);
+ assertEquals(1, special.size());
+ ConfiguredObjectAttribute attr = special.iterator().next();
+ assertEquals("derivedAttribute",attr.getName());
+ assertTrue(attr.isDerived());
+
+ special = _typeRegistry.getTypeSpecificAttributes(TestRootCategoryImpl.class);
+ assertEquals(0, special.size());
+
+ }
+
+ public void testDefaultedValues()
+ {
+ checkDefaultedValue(_typeRegistry.getAttributes((Class) TestRootCategoryImpl.class),
+ TestRootCategory.DEFAULTED_VALUE_DEFAULT);
+
+ checkDefaultedValue(_typeRegistry.getAttributes((Class) Test2RootCategoryImpl.class),
+ Test2RootCategory.DEFAULTED_VALUE_DEFAULT);
+ }
+
+ private void checkDefaultedValue(final Collection<ConfiguredObjectAttribute<?, ?>> attrs,
+ final String defaultedValueDefault)
+ {
+ boolean found = false;
+ for(ConfiguredObjectAttribute<?, ?> attr : attrs)
+ {
+ if(attr.getName().equals("defaultedValue"))
+ {
+ assertEquals(defaultedValueDefault, ((ConfiguredAutomatedAttribute)attr).defaultValue());
+ found = true;
+ break;
+ }
+
+ }
+ assertTrue("Could not find attribute defaultedValue", found);
+ }
+}
diff --git a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/Test2RootCategory.java b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/Test2RootCategory.java
new file mode 100644
index 0000000000..e47c76cbbb
--- /dev/null
+++ b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/Test2RootCategory.java
@@ -0,0 +1,35 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.server.model.testmodel;
+
+import org.apache.qpid.server.model.DerivedAttribute;
+import org.apache.qpid.server.model.ManagedAttribute;
+
+public interface Test2RootCategory<X extends Test2RootCategory<X>> extends TestRootCategory<X>
+{
+ String DEFAULTED_VALUE_DEFAULT = "differentDefault";
+ @Override
+ @ManagedAttribute( defaultValue = DEFAULTED_VALUE_DEFAULT)
+ String getDefaultedValue();
+
+ @DerivedAttribute
+ public int getDerivedAttribute();
+}
diff --git a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/Test2RootCategoryImpl.java b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/Test2RootCategoryImpl.java
new file mode 100644
index 0000000000..022e0a256f
--- /dev/null
+++ b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/Test2RootCategoryImpl.java
@@ -0,0 +1,118 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.server.model.testmodel;
+
+import java.util.Map;
+
+import org.apache.qpid.server.configuration.updater.CurrentThreadTaskExecutor;
+import org.apache.qpid.server.configuration.updater.TaskExecutor;
+import org.apache.qpid.server.model.AbstractConfiguredObject;
+import org.apache.qpid.server.model.ManagedAttributeField;
+import org.apache.qpid.server.model.ManagedObject;
+import org.apache.qpid.server.model.ManagedObjectFactoryConstructor;
+import org.apache.qpid.server.model.State;
+
+@ManagedObject( category = false , type = "test2" )
+public class Test2RootCategoryImpl extends AbstractConfiguredObject<Test2RootCategoryImpl>
+ implements Test2RootCategory<Test2RootCategoryImpl>
+{
+ @ManagedAttributeField
+ private String _automatedPersistedValue;
+
+ @ManagedAttributeField
+ private String _automatedNonPersistedValue;
+
+ @ManagedAttributeField
+ private String _defaultedValue;
+
+ @ManagedAttributeField
+ private String _stringValue;
+
+ @ManagedAttributeField
+ private Map<String,String> _mapValue;
+
+ @ManagedObjectFactoryConstructor
+ public Test2RootCategoryImpl(final Map<String, Object> attributes)
+ {
+ super(parentsMap(), attributes, newTaskExecutor(), TestModel.getInstance());
+ }
+
+ private static CurrentThreadTaskExecutor newTaskExecutor()
+ {
+ CurrentThreadTaskExecutor currentThreadTaskExecutor = new CurrentThreadTaskExecutor();
+ currentThreadTaskExecutor.start();
+ return currentThreadTaskExecutor;
+ }
+
+ public Test2RootCategoryImpl(final Map<String, Object> attributes,
+ final TaskExecutor taskExecutor)
+ {
+ super(parentsMap(), attributes, taskExecutor);
+ }
+
+ @Override
+ protected boolean setState(final State desiredState)
+ {
+ return false;
+ }
+
+ @Override
+ public String getAutomatedPersistedValue()
+ {
+ return _automatedPersistedValue;
+ }
+
+ @Override
+ public String getAutomatedNonPersistedValue()
+ {
+ return _automatedNonPersistedValue;
+ }
+
+ @Override
+ public String getDefaultedValue()
+ {
+ return _defaultedValue;
+ }
+
+ @Override
+ public int getDerivedAttribute()
+ {
+ return 0;
+ }
+
+ @Override
+ public String getStringValue()
+ {
+ return _stringValue;
+ }
+
+ @Override
+ public Map<String, String> getMapValue()
+ {
+ return _mapValue;
+ }
+
+ @Override
+ public State getState()
+ {
+ return null;
+ }
+}
diff --git a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestModel.java b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestModel.java
index a87ed710a4..fc98b51731 100644
--- a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestModel.java
+++ b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestModel.java
@@ -27,7 +27,9 @@ import java.util.Collections;
import org.apache.qpid.server.model.ConfiguredObject;
import org.apache.qpid.server.model.ConfiguredObjectFactory;
import org.apache.qpid.server.model.ConfiguredObjectFactoryImpl;
+import org.apache.qpid.server.model.ConfiguredObjectTypeRegistry;
import org.apache.qpid.server.model.Model;
+import org.apache.qpid.server.plugin.ConfiguredObjectRegistration;
public class TestModel extends Model
{
@@ -38,6 +40,7 @@ public class TestModel extends Model
};
private final ConfiguredObjectFactory _objectFactory;
+ private ConfiguredObjectTypeRegistry _registry;
private TestModel()
{
@@ -47,6 +50,21 @@ public class TestModel extends Model
public TestModel(final ConfiguredObjectFactory objectFactory)
{
_objectFactory = objectFactory == null ? new ConfiguredObjectFactoryImpl(this) : objectFactory;
+ ConfiguredObjectRegistration configuredObjectRegistration = new ConfiguredObjectRegistration()
+ {
+ @Override
+ public Collection<Class<? extends ConfiguredObject>> getConfiguredObjectClasses()
+ {
+ return Arrays.<Class<? extends ConfiguredObject>>asList(TestRootCategoryImpl.class, Test2RootCategoryImpl.class);
+ }
+
+ @Override
+ public String getType()
+ {
+ return "test";
+ }
+ };
+ _registry = new ConfiguredObjectTypeRegistry(Arrays.asList(configuredObjectRegistration), getSupportedCategories());
}
@@ -92,6 +110,12 @@ public class TestModel extends Model
return _objectFactory;
}
+ @Override
+ public ConfiguredObjectTypeRegistry getTypeRegistry()
+ {
+ return _registry;
+ }
+
public static Model getInstance()
{
return INSTANCE;