package org.huihoo.jfox.jndi.test;
import java.io.Serializable;
import java.rmi.RemoteException;
import javax.naming.Context;
import javax.naming.InitialContext;
import junit.framework.TestCase;
public class ContextTest extends TestCase {
private static Context ctx;
protected void setUp() throws Exception {
ctx = new InitialContext();
}
public void testSimple() {
try {
ctx.rebind("a",new Test("Hello"));
Test test = lookupTest("/a");
lookupTest("java:/a");
lookupTest("java://localhost/a");
lookupTest("java://localhost:1099/a");
assertTrue(test.get().equals("Hello"));
}
catch(Exception e){
e.printStackTrace();
fail(e.getMessage());
}
}
public static Test lookupTest(String name) throws Exception {
return (Test)javax.rmi.PortableRemoteObject.narrow(ctx.lookup(name),Test.class);
}
public static void main(String[] args) {
}
}
class Test implements Serializable{
private String word = "Hello,World!";
public Test(String word) {
this.word = word;
}
public String get() throws RemoteException {
return word;
}
}