📄 objectfactorytest.java
字号:
/**
* $Log: ObjectFactoryTest.java,v $
* Revision 1.1 2003/01/16 13:07:32 mwulff
* initial version
*
* Revision 1.19 2003/01/13 12:49:27 mwulff
* adjusted to methods in ParameterTester
*
* Revision 1.18 2003/01/11 17:00:21 willaxt
* added further tests
*
* Revision 1.17 2002/12/15 16:50:48 mwulff
* adjusted to reorganisation of the client logging system
*
* Revision 1.16 2002/12/14 22:41:16 mwulff
* no message
*
* Revision 1.15 2002/12/13 20:05:35 mwulff
* no message
*
* Revision 1.14 2002/12/12 11:37:29 mwulff
* no message
*
* Revision 1.13 2002/12/09 18:04:21 mwulff
* no message
*
* Revision 1.12 2002/12/05 21:25:20 mwulff
* no message
*
* Revision 1.11 2002/11/30 11:51:54 mwulff
* no message
*
* Revision 1.10 2002/11/24 13:15:15 mwulff
* code reorganisation
*
* Revision 1.9 2002/11/22 16:25:40 mwulff
* adjusted to changed method in JKFClient.configure() to JKFClient.configure(String)
*
* Revision 1.8 2002/11/17 17:44:56 mwulff
* changed call ObjectFactory.create(...) to new method signature
* in ObjectFactory
*
* Revision 1.7 2002/11/16 12:25:14 mwulff
* organized imports
*
* Revision 1.6 2002/11/15 18:16:53 mwulff
* adapted to changes in ObjectFactory
*
* Revision 1.5 2002/11/08 19:13:37 mwulff
* no message
*
* Revision 1.4 2002/11/07 16:21:52 mwulff
* adapted changes of other classes
*
* Revision 1.3 2002/11/05 19:42:23 mwulff
* adapted the test to modified framework
*
* Revision 1.2 2002/11/03 21:00:31 mwulff
* added logging
*
*/
package de.fhm.jkf.test.cl;
import junit.framework.TestCase;
import junit.framework.TestResult;
import de.fhm.jkf.comm.cl.JKFFactory;
import de.fhm.jkf.comm.cl.ObjectFactory;
import de.fhm.jkf.comm.clsv.RemoteObjectCreationException;
import de.fhm.jkf.resource.cl.JKFClient;
import de.fhm.jkf.resource.cl.JKFClientLogger;
import de.fhm.jkf.test.clsv.Hello;
import de.fhm.jkf.test.clsv.ParameterTester;
import de.fhm.jkf.test.clsv.TimeReceiver;
/**
* @author marten wulff
*
* <br><br><center><table border="1" width="80%"><hr>
* <strong><a href="http://jkf.sourceforge.net">The JKF Project</a></strong>
* <p>
* Copyright (C) 2002 by Marten Wulff
* <p>
* This library 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.
* <p>
* This library 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.
* <p>
* You should have received a copy of the <a href="http://www.gnu.org/copyleft/lesser.html">
* GNU Lesser General Public License</a> along with this library; if not, write to
* the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
* <hr></table></center>
*/
public class ObjectFactoryTest extends TestCase {
private ObjectFactory factory = null;
public ObjectFactoryTest(String name) {
super(name);
}
protected void setUp() {
// configure jkf
JKFClient.configure();
}
public TestResult run() {
TestResult result = new TestResult();
factory = JKFFactory.instance().getFactory();
if (JKFClientLogger.isDebugEnabled()) {
JKFClientLogger.debug(
"\n\n******************** "
+ this.getClass().getName()
+ " ***************************");
}
try {
JKFClientLogger.debug("========== Creating TimerImpl ==========");
// simply a remote object with a default constructor
TimeReceiver time =
(TimeReceiver) factory.createObject(
TimeReceiver.class,
"de.fhm.jkf.test.sv.TimeReceiverImpl",
null);
JKFClientLogger.debug("========== TimerImpl created ==========");
JKFClientLogger.debug("========== Calling Timer.getTime() ==========");
JKFClientLogger.debug(new java.util.Date((time.getTime()).longValue()));
// set the reference to null, to check remote gc
time = null;
} catch (RemoteObjectCreationException roce) {
JKFClientLogger.debug("", roce);
}
// testing a remote Object with constructor that takes a parameter
Object[] p = new Object[1];
p[0] = new String("Marten");
JKFClientLogger.debug("========== Creating HelloImpl with param (Marten) ==========");
try {
Hello hello =
(Hello) factory.createObject(
Hello.class,
"de.fhm.jkf.test.sv.HelloImpl",
p);
// assertEquals("Hello Marten", hello.sayHello());
JKFClientLogger.debug("========== " + hello.sayHello() + " ==========");
JKFClientLogger.debug("========== Testing SessionHandling --> calling same object again ==========");
JKFClientLogger.debug("========== " + hello.sayHello() + " ==========");
// test the session handling and let's see if we get
//the same object againg
// assertEquals("Hello Marten", hello.sayHello());
JKFClientLogger.debug("========== Calling Hello.sayHello(\"Dude\") ==========");
JKFClientLogger.debug("========== " + hello.sayHello("Dude") + " ==========");
// test if a method call with parameters works
// assertEquals("Hello Dude", hello.sayHello("Dude"));
} catch (RemoteObjectCreationException roce) {
JKFClientLogger.debug(roce.getMessage());
}
// Testing parameter stuff
p = new Object[1];
p[0] = new Integer(5);
try{
ParameterTester tester = (ParameterTester)factory.createObject(
ParameterTester.class,
"de.fhm.jkf.test.sv.ParameterTesterImpl",
p);
JKFClientLogger.debug("========== Calling ParameterTester.takeIntAndGiveInt(1) ==========");
int res1 = tester.takeIntAndGiveInt(1);
JKFClientLogger.debug("========== Result: " + res1 + " ==========");
JKFClientLogger.debug("========== Calling ParameterTester.takeIntAndGiveInteger(2) ==========");
Integer res2 = tester.takeIntAndGiveInteger(2);
JKFClientLogger.debug("========== Result: " + res2 + " ==========");
JKFClientLogger.debug("========== Calling ParameterTester.takeIntegerAndGiveInt(3) ==========");
int res3 = tester.takeIntegerAndGiveInt(new Integer(3));
JKFClientLogger.debug("========== Result: " + res3 + " ==========");
JKFClientLogger.debug("========== Calling ParameterTester.takeIntegerAndGiveInteger(4) ==========");
Integer res4 = tester.takeIntegerAndGiveInteger(new Integer(4));
JKFClientLogger.debug("========== Result: " + res4 + " ==========");
JKFClientLogger.debug("========== Calling ParameterTester.noArg() ==========");
String res = tester.noArg();
JKFClientLogger.debug("========== Result: " + res + " ==========");
JKFClientLogger.debug("========== Calling ParameterTester..takeBooleanAndGiveBooleanObject(boolean) ==========");
Boolean bo = tester.takeBooleanAndGiveBooleanObject(true);
JKFClientLogger.debug("========== Result: " + bo + " ==========");
JKFClientLogger.debug("========== Calling ParameterTester.takeBooleanObjectAndGiveBoolean(Boolean) ==========");
boolean b = tester.takeBooleanObjectAndGiveBoolean(new Boolean(true));
JKFClientLogger.debug("========== Result: " + b + " ==========");
JKFClientLogger.debug("========== Calling ParameterTester.doubleName(Integer, String) ==========");
res = tester.doubleName(new Integer(4), "Marten");
JKFClientLogger.debug("========== Result: " + res + " ==========");
JKFClientLogger.debug("========== Calling ParameterTester.doubleName(Boolean, String) ==========");
res = tester.doubleName(new Boolean(true), "Marten");
JKFClientLogger.debug("========== Result: " + res + " ==========");
JKFClientLogger.debug("========== Calling ParameterTester.doubleName(boolean, String) ==========");
res = tester.doubleName(true, "Marten");
JKFClientLogger.debug("========== Result: " + res + " ==========");
JKFClientLogger.debug("========== Calling ParameterTester.methodName(short, String) ==========");
res = tester.methodName((short)1, "Marten");
JKFClientLogger.debug("========== Result: " + res + " ==========");
JKFClientLogger.debug("========== Calling ParameterTester.methodName(int, String) ==========");
res = tester.methodName(5, "Marten");
JKFClientLogger.debug("========== Result: " + res + " ==========");
JKFClientLogger.debug("========== Calling ParameterTester.methodName(long, String) ==========");
res = tester.methodName((long)5, "Marten");
JKFClientLogger.debug("========== Result: " + res + " ==========");
JKFClientLogger.debug("========== Calling ParameterTester.methodName(float, String) ==========");
res = tester.methodName((float)5.5, "Marten");
JKFClientLogger.debug("========== Result: " + res + " ==========");
JKFClientLogger.debug("========== Calling ParameterTester.methodName(double, String) ==========");
res = tester.methodName((double)5.5, "Marten");
JKFClientLogger.debug("========== Result: " + res + " ==========");
JKFClientLogger.debug("========== Calling ParameterTester.methodName(char, String) ==========");
res = tester.methodName('5', "Marten");
JKFClientLogger.debug("========== Result: " + res + " ==========");
JKFClientLogger.debug("========== Calling ParameterTester.methodName(boolean, String) ==========");
res = tester.methodName(false, "Marten");
JKFClientLogger.debug("========== Result: " + res + " ==========");
JKFClientLogger.debug("========== Calling ParameterTester.methodName(byte, String) ==========");
res = tester.methodName((byte)5, "Marten");
JKFClientLogger.debug("========== Result: " + res + " ==========");
JKFClientLogger.debug("========== Calling ParameterTester.toString() in superclass ==========");
res = tester.toString();
JKFClientLogger.debug("========== Result: " + res + " ==========");
} catch(Exception ex) {
ex.printStackTrace();
}
return result;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -