hammant 2002/08/25 15:23:32
Modified: altrmi build.xml
altrmi/src/java/org/apache/excalibur/altrmi/server/impl/classretrievers
AbstractDynamicGeneratorClassRetriever.java
Added: altrmi/src/test/org/apache/excalibur/altrmi/test2
ClassRetrievingTestCase.java TestImpl.java
TestInterface.java
Log:
Dynamic Class Generation Unit Test.
Revision Changes Path
1.35 +28 -2 jakarta-avalon-excalibur/altrmi/build.xml
Index: build.xml
===================================================================
RCS file: /home/cvs/jakarta-avalon-excalibur/altrmi/build.xml,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -r1.34 -r1.35
--- build.xml 25 Aug 2002 20:52:14 -0000 1.34
+++ build.xml 25 Aug 2002 22:23:31 -0000 1.35
@@ -39,6 +39,12 @@
<path refid="project.class.path"/>
</path>
+ <path id="test.classpath3">
+ <pathelement location="${build.testclasses}"/>
+ <pathelement location="${junit.jar}"/>
+ <path refid="project.class.path"/>
+ </path>
+
<property name="cp" refid="test.class.path"/>
@@ -216,15 +222,16 @@
<mkdir dir="${build.tests}"/>
+ <!-- Plain tests -->
+
<junit fork="true"
haltonfailure="${junit.failonerror}"
printsummary="yes"
dir="${build.tests}">
<classpath refid="test.classpath2"/>
- <formatter type="xml"/> <!-- xml reports for junitreport -->
+ <formatter type="xml"/> <!-- xml reports for junitreport -->
<formatter type="plain" usefile="false"/> <!-- text reports for humans
-->
-
<batchtest todir="${build.tests}">
<fileset dir="${build.testclasses}">
<include name="**/test/**/*TestCase.class"/>
@@ -232,6 +239,25 @@
</fileset>
</batchtest>
</junit>
+
+ <!-- Dynamic Server Side classes -->
+
+ <junit fork="true"
+ haltonfailure="${junit.failonerror}"
+ printsummary="yes"
+ dir="${build.tests}">
+ <classpath refid="test.classpath3"/>
+
+ <formatter type="plain" usefile="false"/> <!-- text reports for humans
-->
+
+ <batchtest todir="${build.tests}">
+ <fileset dir="${build.testclasses}">
+ <include name="**/test2/**/*TestCase.class"/>
+ <exclude name="**/Abstract*"/>
+ </fileset>
+ </batchtest>
+ </junit>
+
</target>
1.5 +2 -2
jakarta-avalon-excalibur/altrmi/src/java/org/apache/excalibur/altrmi/server/impl/classretrievers/AbstractDynamicGeneratorClassRetriever.java
Index: AbstractDynamicGeneratorClassRetriever.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/altrmi/src/java/org/apache/excalibur/altrmi/server/impl/classretrievers/AbstractDynamicGeneratorClassRetriever.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- AbstractDynamicGeneratorClassRetriever.java 24 Aug 2002 11:39:06 -0000
1.4
+++ AbstractDynamicGeneratorClassRetriever.java 25 Aug 2002 22:23:31 -0000
1.5
@@ -31,7 +31,7 @@
{
private String m_altrmiClasspath;
- private String m_classGenDir;
+ private String m_classGenDir = ".";
private String m_srcGenDir;
private Class m_generatorClass;
1.1
jakarta-avalon-excalibur/altrmi/src/test/org/apache/excalibur/altrmi/test2/ClassRetrievingTestCase.java
Index: ClassRetrievingTestCase.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.excalibur.altrmi.test2;
import org.apache.excalibur.altrmi.server.impl.AbstractServer;
import
org.apache.excalibur.altrmi.server.impl.classretrievers.BcelDynamicGeneratorClassRetriever;
import
org.apache.excalibur.altrmi.server.impl.classretrievers.AbstractDynamicGeneratorClassRetriever;
import org.apache.excalibur.altrmi.server.impl.piped.PipedCustomStreamServer;
import org.apache.excalibur.altrmi.client.AltrmiFactory;
import org.apache.excalibur.altrmi.client.impl.ServerClassAltrmiFactory;
import org.apache.excalibur.altrmi.client.impl.piped.PipedCustomStreamHostContext;
import java.io.PipedInputStream;
import java.io.PipedOutputStream;
import junit.framework.TestCase;
/**
* A special test case that tests dynamic class generation on the server side.
* @author Paul Hammant
*/
public class ClassRetrievingTestCase extends TestCase
{
protected AbstractServer server;
protected TestImpl testServer;
protected TestInterface testClient;
public ClassRetrievingTestCase(String name)
{
super(name);
}
protected void setUp() throws Exception
{
super.setUp();
// server side setup.
server = new PipedCustomStreamServer();
AbstractDynamicGeneratorClassRetriever dyncgen = new
BcelDynamicGeneratorClassRetriever();
server.setClassRetriever(dyncgen);
testServer = new TestImpl();
server.publish(testServer, "Kewl", TestInterface.class);
dyncgen.generate("Kewl", TestInterface.class,
this.getClass().getClassLoader());
server.start();
// For piped, server and client can see each other
PipedInputStream in = new PipedInputStream();
PipedOutputStream out = new PipedOutputStream();
((PipedCustomStreamServer) server).makeNewConnection(in, out);
// Client side setup
AltrmiFactory af = new ServerClassAltrmiFactory(false);
af.setHostContext(new PipedCustomStreamHostContext(in, out));
testClient = (TestInterface) af.lookup("Kewl");
// just a kludge for unit testing given we are intrinsically dealing with
// threads, AltRMI being a client/server thing
Thread.yield();
}
protected void tearDown() throws Exception
{
server.stop();
Thread.yield();
server = null;
testServer = null;
super.tearDown();
}
/**
* This is the only testXX() method in this class. Other features of
* AltRMI are given a thorough test in the 'test' package.
*
* @throws Exception as per Junit contract
*/
public void testDynamicallyGeneratedProxyMethodInvocation() throws Exception
{
// lookup worked ?
assertNotNull(testClient);
// Invoke a method over AltRMI.
testClient.method0();
// test the server has logged the message.
assertEquals("called", ((TestImpl) testServer).getStoredState("method0"));
}
}
1.1
jakarta-avalon-excalibur/altrmi/src/test/org/apache/excalibur/altrmi/test2/TestImpl.java
Index: TestImpl.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.excalibur.altrmi.test2;
import java.util.HashMap;
public class TestImpl implements TestInterface
{
HashMap map = new HashMap();
public Object getStoredState(String key)
{
return map.get(key);
}
public void method0()
{
map.put("method0", "called");
}
}
1.1
jakarta-avalon-excalibur/altrmi/src/test/org/apache/excalibur/altrmi/test2/TestInterface.java
Index: TestInterface.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.excalibur.altrmi.test2;
public interface TestInterface
{
void method0();
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>