Author: ron.sigal(a)jboss.com
Date: 2010-06-22 16:28:30 -0400 (Tue, 22 Jun 2010)
New Revision: 5873
Added:
remoting3/trunk/jboss-remoting/src/main/resources/META-INF/services/org.jboss.marshalling.ProviderDescriptor
remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/EndpointConfigurationTestCase.java
remoting3/trunk/jboss-remoting/src/test/resources/protocols.test.remoting.properties
Log:
JBREM-1228: Added unit tests for Endpoint configuration.
Added:
remoting3/trunk/jboss-remoting/src/main/resources/META-INF/services/org.jboss.marshalling.ProviderDescriptor
===================================================================
---
remoting3/trunk/jboss-remoting/src/main/resources/META-INF/services/org.jboss.marshalling.ProviderDescriptor
(rev 0)
+++
remoting3/trunk/jboss-remoting/src/main/resources/META-INF/services/org.jboss.marshalling.ProviderDescriptor 2010-06-22
20:28:30 UTC (rev 5873)
@@ -0,0 +1,5 @@
+#
+# MockMarshaller provider descriptor
+#
+
+org.jboss.remoting3.test.EndpointConfigurationTestCase$MockMarshallerProviderDescriptor
Added:
remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/EndpointConfigurationTestCase.java
===================================================================
---
remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/EndpointConfigurationTestCase.java
(rev 0)
+++
remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/EndpointConfigurationTestCase.java 2010-06-22
20:28:30 UTC (rev 5873)
@@ -0,0 +1,395 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.jboss.remoting3.test;
+
+import static org.testng.Assert.assertSame;
+import static org.testng.Assert.assertTrue;
+
+import java.io.IOException;
+import java.lang.reflect.Field;
+import java.net.URI;
+import java.util.Properties;
+import java.util.concurrent.ArrayBlockingQueue;
+import java.util.concurrent.Executor;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+
+import javax.security.auth.callback.CallbackHandler;
+
+import org.jboss.marshalling.ClassExternalizerFactory;
+import org.jboss.marshalling.ClassResolver;
+import org.jboss.marshalling.ClassTable;
+import org.jboss.marshalling.Externalizer;
+import org.jboss.marshalling.Marshaller;
+import org.jboss.marshalling.MarshallerFactory;
+import org.jboss.marshalling.ObjectResolver;
+import org.jboss.marshalling.ObjectTable;
+import org.jboss.marshalling.ProviderDescriptor;
+import org.jboss.marshalling.Unmarshaller;
+import org.jboss.remoting3.Endpoint;
+import org.jboss.remoting3.Registration;
+import org.jboss.remoting3.Remoting;
+import org.jboss.remoting3.spi.ConnectionHandlerFactory;
+import org.jboss.remoting3.spi.ConnectionProvider;
+import org.jboss.remoting3.spi.ConnectionProviderContext;
+import org.jboss.remoting3.spi.ConnectionProviderFactory;
+import org.jboss.remoting3.spi.ProtocolServiceType;
+import org.jboss.remoting3.spi.RemotingServiceDescriptor;
+import org.jboss.xnio.Cancellable;
+import org.jboss.xnio.OptionMap;
+import org.jboss.xnio.Result;
+import org.jboss.xnio.log.Logger;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+/**
+ * EndpointConfigurationTestCase tests various ways of configuring an Endpoint with
transport protocols
+ * and marshalling components.
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.1 $
+ * <p>
+ * Copyright Jun 21, 2010
+ */
+@Test(suiteName = "EndpointConfiguration")
+public class EndpointConfigurationTestCase {
+
+ private static final Logger log =
Logger.getLogger(EndpointConfigurationTestCase.class);
+
+ static void enter() {
+ final StackTraceElement e = new Throwable().getStackTrace()[1];
+ log.info("Entering: %s#%s", e.getClassName(), e.getMethodName());
+ }
+
+ static void exit() {
+ final StackTraceElement e = new Throwable().getStackTrace()[1];
+ log.info("Exiting: %s#%s", e.getClassName(), e.getMethodName());
+
log.info("-------------------------------------------------------------");
+ }
+
+ @BeforeMethod
+ public void setUp() {
+ System.clearProperty("remoting.property.file");
+ try {
+ Field configuredEndpoint =
Remoting.class.getDeclaredField("configuredEndpoint");
+ configuredEndpoint.setAccessible(true);
+ configuredEndpoint.set(null, null);
+ System.out.println(configuredEndpoint.get(null));
+ } catch (NoSuchFieldException e) {
+ throw new RuntimeException(e);
+ } catch (IllegalAccessException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @AfterMethod
+ public void tearDown() throws IOException {
+ }
+
+ /**
+ * Tests configuration of Endpoint by programmatically adding a transport and
marshalling components.
+ */
+ @Test
+ public void testProgrammaticConfiguration() throws Exception {
+ enter();
+ Endpoint endpoint = null;
+ Registration regConnectionProvider = null;
+ Registration regMarshallerProvider = null;
+ Registration regClassExternalizerFactoryProvider = null;
+ Registration regClassResolverProvider = null;
+ Registration regClassTableProvider = null;
+ Registration regObjectResolverProvider = null;
+ Registration regObjectTableProvider = null;
+
+ ProviderDescriptor marshallerProviderDescriptor = new
MockMarshallerProviderDescriptor();
+ MockClassExternalizerFactory mockClassExternalizerFactory = new
MockClassExternalizerFactory();
+ MockClassResolver mockClassResolver = new MockClassResolver();
+ MockClassTable mockClassTable = new MockClassTable();
+ MockObjectResolver mockObjectResolver = new MockObjectResolver();
+ MockObjectTable mockObjectTable = new MockObjectTable();
+
+ try {
+ Executor executor = new ThreadPoolExecutor(8, 64, 30, TimeUnit.SECONDS, new
ArrayBlockingQueue<Runnable>(64));
+ endpoint = Remoting.createEndpoint("endpoint", executor,
OptionMap.EMPTY);
+ regConnectionProvider =
endpoint.addConnectionProvider("mockTransport", new
MockConnectionProviderFactory());
+ regMarshallerProvider =
endpoint.addProtocolService(ProtocolServiceType.MARSHALLER_PROVIDER_DESCRIPTOR,
"mockMarshaller", marshallerProviderDescriptor);
+ regClassExternalizerFactoryProvider =
endpoint.addProtocolService(ProtocolServiceType.CLASS_EXTERNALIZER_FACTORY,
"mockClassExternalizerFactory", mockClassExternalizerFactory);
+ regClassResolverProvider =
endpoint.addProtocolService(ProtocolServiceType.CLASS_RESOLVER,
"mockClassResolver", mockClassResolver);
+ regClassTableProvider =
endpoint.addProtocolService(ProtocolServiceType.CLASS_TABLE, "mockClassTable",
mockClassTable);
+ regObjectResolverProvider =
endpoint.addProtocolService(ProtocolServiceType.OBJECT_RESOLVER,
"mockObjectResolver", mockObjectResolver);
+ regObjectTableProvider =
endpoint.addProtocolService(ProtocolServiceType.OBJECT_TABLE, "mockObjectTable",
mockObjectTable);
+
+ assertSame(MockConnectionProviderFactory.providerInterface,
endpoint.getConnectionProviderInterface("mockTransport",
MockConnectionProviderFactory.MockProviderInterface.class));
+ ConnectionProviderContext context = MockConnectionProviderFactory.context;
+ assertSame(marshallerProviderDescriptor,
context.getProtocolServiceProvider(ProtocolServiceType.MARSHALLER_PROVIDER_DESCRIPTOR,
"mockMarshaller"));
+ assertSame(mockClassExternalizerFactory,
context.getProtocolServiceProvider(ProtocolServiceType.CLASS_EXTERNALIZER_FACTORY,
"mockClassExternalizerFactory"));
+ assertSame(mockClassResolver,
context.getProtocolServiceProvider(ProtocolServiceType.CLASS_RESOLVER,
"mockClassResolver"));
+ assertSame(mockClassTable,
context.getProtocolServiceProvider(ProtocolServiceType.CLASS_TABLE,
"mockClassTable"));
+ assertSame(mockObjectResolver,
context.getProtocolServiceProvider(ProtocolServiceType.OBJECT_RESOLVER,
"mockObjectResolver"));
+ assertSame(mockObjectTable,
context.getProtocolServiceProvider(ProtocolServiceType.OBJECT_TABLE,
"mockObjectTable"));
+ log.info("testProgrammaticConfiguration() PASSES");
+
+ } finally {
+ if (regClassExternalizerFactoryProvider != null) {
+ regClassExternalizerFactoryProvider.close();
+ }
+ if (regClassResolverProvider != null) {
+ regClassResolverProvider.close();
+ }
+ if (regClassTableProvider != null) {
+ regClassTableProvider.close();
+ }
+ if (regObjectResolverProvider != null) {
+ regObjectResolverProvider.close();
+ }
+ if (regObjectTableProvider != null) {
+ regObjectTableProvider.close();
+ }
+ if (regMarshallerProvider != null) {
+ regMarshallerProvider.close();
+ }
+ if (regConnectionProvider != null) {
+ regConnectionProvider.close();
+ }
+ if (endpoint != null) {
+ endpoint.close();
+ }
+ exit();
+ }
+ }
+
+ /**
+ * Tests configuration of Endpoint by listing transport and marshalling components
descriptions in a RemotingServiceDescriptor file.
+ */
+ @Test
+ public void testConfigurationByServiceDescriptorFile() throws Exception {
+ enter();
+
+ try {
+ Endpoint endpoint = Remoting.getConfiguredEndpoint();
+ assertSame(MockConnectionProviderFactory.providerInterface,
endpoint.getConnectionProviderInterface("mockTransport",
MockConnectionProviderFactory.MockProviderInterface.class));
+ ConnectionProviderContext context = MockConnectionProviderFactory.context;
+
assertTrue(context.getProtocolServiceProvider(ProtocolServiceType.CLASS_EXTERNALIZER_FACTORY,
"mockClassExternalizerFactory_sd") instanceof MockClassExternalizerFactory);
+
assertTrue(context.getProtocolServiceProvider(ProtocolServiceType.CLASS_RESOLVER,
"mockClassResolver_sd") instanceof MockClassResolver);
+ assertTrue(context.getProtocolServiceProvider(ProtocolServiceType.CLASS_TABLE,
"mockClassTable_sd") instanceof MockClassTable);
+
assertTrue(context.getProtocolServiceProvider(ProtocolServiceType.OBJECT_RESOLVER,
"mockObjectResolver_sd") instanceof MockObjectResolver);
+ assertTrue(context.getProtocolServiceProvider(ProtocolServiceType.OBJECT_TABLE,
"mockObjectTable_sd") instanceof MockObjectTable);
+ log.info("testConfigurationByServiceDescriptorFile() PASSES");
+ } finally {
+ exit();
+ }
+ }
+
+ /**
+ * Tests configuration of Endpoint by listing transport and marshalling components
descriptions in a properties file.
+ * Note that the properties file includes examples of multiple instances in the object
table list.
+ */
+ @Test
+ public void testConfigurationByPropertiesFile() throws Exception {
+ enter();
+
+ try {
+ System.setProperty("remoting.property.file",
"protocols.test.remoting.properties");
+ @SuppressWarnings("unused")
+ Endpoint endpoint = Remoting.getConfiguredEndpoint();
+ ConnectionProviderContext context = MockConnectionProviderFactory.context;
+
assertTrue(context.getProtocolServiceProvider(ProtocolServiceType.CLASS_EXTERNALIZER_FACTORY,
"mockClassExternalizerFactory_pf") instanceof MockClassExternalizerFactory);
+
assertTrue(context.getProtocolServiceProvider(ProtocolServiceType.CLASS_RESOLVER,
"mockClassResolver_pf") instanceof MockClassResolver);
+ assertTrue(context.getProtocolServiceProvider(ProtocolServiceType.CLASS_TABLE,
"mockClassTable_pf") instanceof MockClassTable);
+
assertTrue(context.getProtocolServiceProvider(ProtocolServiceType.OBJECT_RESOLVER,
"mockObjectResolver_pf") instanceof MockObjectResolver);
+ assertTrue(context.getProtocolServiceProvider(ProtocolServiceType.OBJECT_TABLE,
"mockObjectTable_pf") instanceof MockObjectTable);
+ assertTrue(context.getProtocolServiceProvider(ProtocolServiceType.OBJECT_TABLE,
"mockObjectTable_pf1") instanceof MockObjectTable);
+ assertTrue(context.getProtocolServiceProvider(ProtocolServiceType.OBJECT_TABLE,
"mockObjectTable_pf2") instanceof MockObjectTable2);
+ log.info("testConfigurationByPropertiesFile() PASSES");
+ } finally {
+ exit();
+ }
+ }
+
+ /**
+ * This class is used to gain access to the Endpoint's ConnectionProviderContext.
+ */
+ public static class MockConnectionProviderFactory implements ConnectionProviderFactory
{
+ public static ConnectionProviderContext context;
+ public interface MockProviderInterface {};
+ public static MockProviderInterface providerInterface = new MockProviderInterface()
{};
+
+ public ConnectionProvider createInstance(ConnectionProviderContext context) {
+ MockConnectionProviderFactory.context = context;
+ return new ConnectionProvider() {
+ public Cancellable connect(URI uri, OptionMap connectOptions,
Result<ConnectionHandlerFactory> result, CallbackHandler callbackHandler) throws
IllegalArgumentException {
+ return null;
+ }
+ public Object getProviderInterface() {
+ return providerInterface;
+ }
+ };
+ }
+ }
+
+ public static class MockProtocolDescriptor implements
RemotingServiceDescriptor<ConnectionProviderFactory> {
+ public Class<ConnectionProviderFactory> getType() {
+ return ConnectionProviderFactory.class;
+ }
+ public String getName() {
+ return "mockTransport";
+ }
+ public ConnectionProviderFactory getService(final Properties properties) throws
IOException {
+ return new MockConnectionProviderFactory();
+ }
+ }
+
+ public static class MockMarshallerProviderDescriptor implements ProviderDescriptor {
+ public MarshallerFactory getMarshallerFactory() {
+ return null;
+ }
+ public String getName() {
+ return "mockMarshaller";
+ }
+ public int[] getSupportedVersions() {
+ return new int[]{0};
+ }
+ }
+
+ public static class MockClassExternalizerFactory implements ClassExternalizerFactory
{
+ public Externalizer getExternalizer(Class<?> type) {
+ return null;
+ }
+ }
+
+ public static class MockClassResolver implements ClassResolver {
+ public void annotateClass(Marshaller marshaller, Class<?> clazz) throws
IOException {
+ }
+ public void annotateProxyClass(Marshaller marshaller, Class<?> proxyClass)
throws IOException {
+ }
+ public String getClassName(Class<?> clazz) throws IOException {
+ return null;
+ }
+ public String[] getProxyInterfaces(Class<?> proxyClass) throws IOException {
+ return null;
+ }
+ public Class<?> resolveClass(Unmarshaller unmarshaller, String name, long
serialVersionUID) throws IOException, ClassNotFoundException {
+ return null;
+ }
+ public Class<?> resolveProxyClass(Unmarshaller unmarshaller, String[]
interfaces) throws IOException, ClassNotFoundException {
+ return null;
+ }
+ }
+
+ public static class MockClassTable implements ClassTable {
+ public Writer getClassWriter(Class<?> clazz) throws IOException {
+ return null;
+ }
+ public Class<?> readClass(Unmarshaller unmarshaller) throws IOException,
ClassNotFoundException {
+ return null;
+ }
+ }
+
+ public static class MockObjectResolver implements ObjectResolver {
+ public Object readResolve(Object replacement) {
+ return null;
+ }
+ public Object writeReplace(Object original) {
+ return null;
+ }
+ }
+
+ public static class MockObjectTable implements ObjectTable {
+ public Writer getObjectWriter(Object object) throws IOException {
+ return null;
+ }
+ public Object readObject(Unmarshaller unmarshaller) throws IOException,
ClassNotFoundException {
+ return null;
+ }
+ }
+
+ public static class MockObjectTable2 implements ObjectTable {
+ public Writer getObjectWriter(Object object) throws IOException {
+ return null;
+ }
+ public Object readObject(Unmarshaller unmarshaller) throws IOException,
ClassNotFoundException {
+ return null;
+ }
+ }
+
+ public static class MockClassExternalizerFactoryServiceDescriptor implements
RemotingServiceDescriptor<ClassExternalizerFactory> {
+ public Class<ClassExternalizerFactory> getType() {
+ return ClassExternalizerFactory.class;
+ }
+ public String getName() {
+ return "mockClassExternalizerFactory_sd";
+ }
+ public ClassExternalizerFactory getService(final Properties properties) throws
IOException {
+ return new MockClassExternalizerFactory();
+ }
+ }
+
+ public static class MockClassResolverServiceDescriptor implements
RemotingServiceDescriptor<ClassResolver> {
+ public Class<ClassResolver> getType() {
+ return ClassResolver.class;
+ }
+ public String getName() {
+ return "mockClassResolver_sd";
+ }
+ public ClassResolver getService(final Properties properties) throws IOException {
+ return new MockClassResolver();
+ }
+ }
+
+ public static class MockClassTableServiceDescriptor implements
RemotingServiceDescriptor<ClassTable> {
+ public Class<ClassTable> getType() {
+ return ClassTable.class;
+ }
+ public String getName() {
+ return "mockClassTable_sd";
+ }
+ public ClassTable getService(final Properties properties) throws IOException {
+ return new MockClassTable();
+ }
+ }
+
+ public static class MockObjectResolverServiceDescriptor implements
RemotingServiceDescriptor<ObjectResolver> {
+ public Class<ObjectResolver> getType() {
+ return ObjectResolver.class;
+ }
+ public String getName() {
+ return "mockObjectResolver_sd";
+ }
+ public ObjectResolver getService(final Properties properties) throws IOException {
+ return new MockObjectResolver();
+ }
+ }
+
+ public static class MockObjectTableServiceDescriptor implements
RemotingServiceDescriptor<ObjectTable> {
+ public Class<ObjectTable> getType() {
+ return ObjectTable.class;
+ }
+ public String getName() {
+ return "mockObjectTable_sd";
+ }
+ public ObjectTable getService(final Properties properties) throws IOException {
+ return new MockObjectTable();
+ }
+ }
+}
Added:
remoting3/trunk/jboss-remoting/src/test/resources/protocols.test.remoting.properties
===================================================================
--- remoting3/trunk/jboss-remoting/src/test/resources/protocols.test.remoting.properties
(rev 0)
+++
remoting3/trunk/jboss-remoting/src/test/resources/protocols.test.remoting.properties 2010-06-22
20:28:30 UTC (rev 5873)
@@ -0,0 +1,36 @@
+#
+# JBoss, Home of Professional Open Source
+# Copyright 2010, JBoss Inc., and individual contributors as indicated
+# by the @authors tag. See the copyright.txt in the distribution for a
+# full listing of individual contributors.
+#
+# This is free software; you can redistribute it and/or modify it
+# under the terms of the GNU Lesser General Public License as
+# published by the Free Software Foundation; either version 2.1 of
+# the License, or (at your option) any later version.
+#
+# This software is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this software; if not, write to the Free
+# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+# 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+#
+
+endpoint.name=protocols.test
+protocols.test.class_externalizer_factory_list=mockClassExternalizerFactory_pf
+protocols.test.class_resolver_list=mockClassResolver_pf
+protocols.test.class_table_list=mockClassTable_pf
+protocols.test.object_resolver_list=mockObjectResolver_pf
+protocols.test.object_table_list=mockObjectTable_pf,mockObjectTable_pf1,mockObjectTable_pf2
+
+mockClassExternalizerFactory_pf.class_externalizer_factory.mockClassExternalizerFactory_pf.class=org.jboss.remoting3.test.EndpointConfigurationTestCase$MockClassExternalizerFactory
+mockClassResolver_pf.class_resolver.mockClassResolver_pf.class=org.jboss.remoting3.test.EndpointConfigurationTestCase$MockClassResolver
+mockClassTable_pf.class_table.mockClassTable_pf.class=org.jboss.remoting3.test.EndpointConfigurationTestCase$MockClassTable
+mockObjectResolver_pf.object_resolver.mockObjectResolver_pf.class=org.jboss.remoting3.test.EndpointConfigurationTestCase$MockObjectResolver
+mockObjectTable_pf.object_table.mockObjectTable_pf.class=org.jboss.remoting3.test.EndpointConfigurationTestCase$MockObjectTable
+mockObjectTable_pf1.object_table.mockObjectTable_pf1.class=org.jboss.remoting3.test.EndpointConfigurationTestCase$MockObjectTable
+mockObjectTable_pf2.object_table.mockObjectTable_pf2.class=org.jboss.remoting3.test.EndpointConfigurationTestCase$MockObjectTable2
\ No newline at end of file