Fix for #308857 (Update test suite to JUnit4 - Module jetty-jndi)
git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@1745 7e9141cc-0065-0410-87d8-b60c137991c4
This commit is contained in:
parent
c3d31d68b0
commit
390379b9e8
|
@ -1,5 +1,6 @@
|
|||
jetty-7.1.1-SNAPSHOT
|
||||
+ 304803 Remove TypeUtil Integer and Long caches
|
||||
+ 308857 Update test suite to JUnit4 - Module jetty-jndi
|
||||
|
||||
jetty-7.1.0 5 May 2010
|
||||
+ 306353 fixed cross context dispatch to root context.
|
||||
|
|
|
@ -38,7 +38,7 @@
|
|||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<configuration>
|
||||
<archive>
|
||||
<archive>
|
||||
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
|
||||
</archive>
|
||||
</configuration>
|
||||
|
@ -49,6 +49,7 @@
|
|||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>${junit4-version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
@ -80,8 +81,8 @@
|
|||
<groupId>javax.activation</groupId>
|
||||
<artifactId>activation</artifactId>
|
||||
<version>${javax-activation-version}</version>
|
||||
</dependency>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</profile>
|
||||
</profiles>
|
||||
</profiles>
|
||||
</project>
|
||||
|
|
|
@ -4,17 +4,16 @@
|
|||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
// The Eclipse Public License is available at
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
|
||||
package org.eclipse.jetty.jndi.factories;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.mail.Session;
|
||||
import javax.naming.Context;
|
||||
import javax.naming.InitialContext;
|
||||
|
@ -22,19 +21,20 @@ import javax.naming.LinkRef;
|
|||
import javax.naming.Name;
|
||||
import javax.naming.NameParser;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.eclipse.jetty.jndi.NamingUtil;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* TestMailSessionReference
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class TestMailSessionReference extends TestCase
|
||||
public class TestMailSessionReference
|
||||
{
|
||||
public void testMailSessionReference ()
|
||||
throws Exception
|
||||
@Test
|
||||
public void testMailSessionReference () throws Exception
|
||||
{
|
||||
InitialContext icontext = new InitialContext();
|
||||
MailSessionReference sref = new MailSessionReference();
|
||||
|
@ -52,20 +52,20 @@ public class TestMailSessionReference extends TestCase
|
|||
Properties sessionProps = session.getProperties();
|
||||
assertEquals(props, sessionProps);
|
||||
assertTrue (session.getDebug());
|
||||
|
||||
|
||||
Context foo = icontext.createSubcontext("foo");
|
||||
NameParser parser = icontext.getNameParser("");
|
||||
Name objectNameInNamespace = parser.parse(icontext.getNameInNamespace());
|
||||
objectNameInNamespace.addAll(parser.parse("mail/Session"));
|
||||
|
||||
|
||||
NamingUtil.bind(foo, "mail/Session", new LinkRef(objectNameInNamespace.toString()));
|
||||
|
||||
|
||||
Object o = foo.lookup("mail/Session");
|
||||
assertNotNull(o);
|
||||
Session fooSession = (Session)o;
|
||||
assertEquals(props, fooSession.getProperties());
|
||||
assertTrue(fooSession.getDebug());
|
||||
|
||||
|
||||
icontext.destroySubcontext("mail");
|
||||
icontext.destroySubcontext("foo");
|
||||
}
|
||||
|
|
|
@ -4,21 +4,19 @@
|
|||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
// The Eclipse Public License is available at
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
|
||||
package org.eclipse.jetty.jndi.java;
|
||||
|
||||
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.util.HashMap;
|
||||
import java.util.Hashtable;
|
||||
|
||||
import javax.naming.Context;
|
||||
import javax.naming.InitialContext;
|
||||
import javax.naming.LinkRef;
|
||||
|
@ -32,57 +30,31 @@ import javax.naming.Reference;
|
|||
import javax.naming.StringRefAddr;
|
||||
import javax.naming.spi.ObjectFactory;
|
||||
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestCase;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
import org.eclipse.jetty.jndi.NamingContext;
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
|
||||
public class TestJNDI extends TestCase
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class TestJNDI
|
||||
{
|
||||
|
||||
|
||||
public static class MyObjectFactory implements ObjectFactory
|
||||
{
|
||||
public static String myString = "xxx";
|
||||
|
||||
public Object getObjectInstance(Object obj,
|
||||
Name name,
|
||||
Context nameCtx,
|
||||
Hashtable environment)
|
||||
throws Exception
|
||||
{
|
||||
return myString;
|
||||
}
|
||||
public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable environment) throws Exception
|
||||
{
|
||||
return myString;
|
||||
}
|
||||
}
|
||||
|
||||
public TestJNDI (String name)
|
||||
{
|
||||
super (name);
|
||||
}
|
||||
|
||||
|
||||
public static Test suite ()
|
||||
{
|
||||
return new TestSuite (TestJNDI.class);
|
||||
}
|
||||
|
||||
public void setUp ()
|
||||
throws Exception
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
public void tearDown ()
|
||||
throws Exception
|
||||
{
|
||||
}
|
||||
|
||||
public void testIt ()
|
||||
throws Exception
|
||||
@Test
|
||||
public void testIt() throws Exception
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -99,9 +71,6 @@ public class TestJNDI extends TestCase
|
|||
initCtxA.bind ("blah", "123");
|
||||
assertEquals ("123", initCtxA.lookup("blah"));
|
||||
|
||||
|
||||
|
||||
|
||||
InitialContext initCtx = new InitialContext();
|
||||
Context sub0 = (Context)initCtx.lookup("java:");
|
||||
|
||||
|
@ -109,7 +78,6 @@ public class TestJNDI extends TestCase
|
|||
|
||||
Name n = sub0.getNameParser("").parse("/red/green/");
|
||||
|
||||
|
||||
if(Log.isDebugEnabled())Log.debug("get(0)="+n.get(0));
|
||||
if(Log.isDebugEnabled())Log.debug("getPrefix(1)="+n.getPrefix(1));
|
||||
n = n.getSuffix(1);
|
||||
|
@ -166,42 +134,35 @@ public class TestJNDI extends TestCase
|
|||
//expected exception
|
||||
}
|
||||
|
||||
|
||||
|
||||
//check bindings at comp
|
||||
Context sub1 = (Context)initCtx.lookup("java:comp");
|
||||
|
||||
Context sub2 = sub1.createSubcontext ("env");
|
||||
|
||||
initCtx.bind ("java:comp/env/rubbish", "abc");
|
||||
assertEquals ("abc", (String)initCtx.lookup("java:comp/env/rubbish"));
|
||||
|
||||
|
||||
assertEquals ("abc", initCtx.lookup("java:comp/env/rubbish"));
|
||||
|
||||
//check binding LinkRefs
|
||||
LinkRef link = new LinkRef ("java:comp/env/rubbish");
|
||||
initCtx.bind ("java:comp/env/poubelle", link);
|
||||
assertEquals ("abc", (String)initCtx.lookup("java:comp/env/poubelle"));
|
||||
assertEquals ("abc", initCtx.lookup("java:comp/env/poubelle"));
|
||||
|
||||
//check binding References
|
||||
StringRefAddr addr = new StringRefAddr("blah", "myReferenceable");
|
||||
Reference ref = new Reference (java.lang.String.class.getName(),
|
||||
addr,
|
||||
MyObjectFactory.class.getName(),
|
||||
(String)null);
|
||||
null);
|
||||
|
||||
initCtx.bind ("java:comp/env/quatsch", ref);
|
||||
assertEquals (MyObjectFactory.myString, (String)initCtx.lookup("java:comp/env/quatsch"));
|
||||
assertEquals (MyObjectFactory.myString, initCtx.lookup("java:comp/env/quatsch"));
|
||||
|
||||
//test binding something at java:
|
||||
Context sub3 = initCtx.createSubcontext("java:zero");
|
||||
initCtx.bind ("java:zero/one", "ONE");
|
||||
assertEquals ("ONE", initCtx.lookup("java:zero/one"));
|
||||
|
||||
|
||||
|
||||
|
||||
//change the current thread's classloader to check distinct naming
|
||||
//change the current thread's classloader to check distinct naming
|
||||
currentThread.setContextClassLoader(childLoader2);
|
||||
|
||||
Context otherSub1 = (Context)initCtx.lookup("java:comp");
|
||||
|
@ -215,7 +176,6 @@ public class TestJNDI extends TestCase
|
|||
//expected
|
||||
}
|
||||
|
||||
|
||||
//put the thread's classloader back
|
||||
currentThread.setContextClassLoader(childLoader1);
|
||||
|
||||
|
@ -227,11 +187,11 @@ public class TestJNDI extends TestCase
|
|||
initCtx.rebind ("java:comp/env/mullheim", "hij");
|
||||
assertEquals ("hij", initCtx.lookup("java:comp/env/mullheim"));
|
||||
|
||||
//test that the other bindings are already there
|
||||
assertEquals ("xyz", (String)initCtx.lookup("java:comp/env/poubelle"));
|
||||
//test that the other bindings are already there
|
||||
assertEquals ("xyz", initCtx.lookup("java:comp/env/poubelle"));
|
||||
|
||||
//test java:/comp/env/stuff
|
||||
assertEquals ("xyz", (String)initCtx.lookup("java:/comp/env/poubelle/"));
|
||||
assertEquals ("xyz", initCtx.lookup("java:/comp/env/poubelle/"));
|
||||
|
||||
//test list Names
|
||||
NamingEnumeration nenum = initCtx.list ("java:comp/env");
|
||||
|
@ -244,10 +204,10 @@ public class TestJNDI extends TestCase
|
|||
|
||||
assertEquals (4, results.size());
|
||||
|
||||
assertEquals ("java.lang.String", (String)results.get("rubbish"));
|
||||
assertEquals ("javax.naming.LinkRef", (String)results.get("poubelle"));
|
||||
assertEquals ("java.lang.String", (String)results.get("mullheim"));
|
||||
assertEquals ("javax.naming.Reference", (String)results.get("quatsch"));
|
||||
assertEquals ("java.lang.String", results.get("rubbish"));
|
||||
assertEquals ("javax.naming.LinkRef", results.get("poubelle"));
|
||||
assertEquals ("java.lang.String", results.get("mullheim"));
|
||||
assertEquals ("javax.naming.Reference", results.get("quatsch"));
|
||||
|
||||
//test list Bindings
|
||||
NamingEnumeration benum = initCtx.list("java:comp/env");
|
||||
|
@ -265,13 +225,11 @@ public class TestJNDI extends TestCase
|
|||
InitialContext closeInit = new InitialContext();
|
||||
closeInit.close();
|
||||
|
||||
|
||||
|
||||
//check locking the context
|
||||
Context ectx = (Context)initCtx.lookup("java:comp");
|
||||
ectx.bind("crud", "xxx");
|
||||
ectx.addToEnvironment("org.eclipse.jndi.immutable", "TRUE");
|
||||
assertEquals ("xxx", (String)initCtx.lookup("java:comp/crud"));
|
||||
assertEquals ("xxx", initCtx.lookup("java:comp/crud"));
|
||||
try
|
||||
{
|
||||
ectx.bind("crud2", "xxx2");
|
||||
|
@ -282,7 +240,7 @@ public class TestJNDI extends TestCase
|
|||
}
|
||||
|
||||
//test what happens when you close an initial context that was used
|
||||
initCtx.close();
|
||||
initCtx.close();
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
@ -290,6 +248,5 @@ public class TestJNDI extends TestCase
|
|||
Context comp = (Context)ic.lookup("java:comp");
|
||||
comp.destroySubcontext("env");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,11 +4,11 @@
|
|||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
// The Eclipse Public License is available at
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
package org.eclipse.jetty.jndi.java;
|
||||
|
||||
|
@ -18,41 +18,37 @@ import javax.naming.Name;
|
|||
import javax.naming.NameNotFoundException;
|
||||
import javax.naming.NameParser;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.eclipse.jetty.jndi.NamingUtil;
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
public class TestLocalJNDI extends TestCase
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class TestLocalJNDI
|
||||
{
|
||||
|
||||
|
||||
public void setUp ()
|
||||
throws Exception
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
public void tearDown ()
|
||||
throws Exception
|
||||
@After
|
||||
public void tearDown() throws Exception
|
||||
{
|
||||
InitialContext ic = new InitialContext();
|
||||
ic.destroySubcontext("a");
|
||||
}
|
||||
|
||||
|
||||
public void testLocal ()
|
||||
throws Exception
|
||||
|
||||
@Test
|
||||
public void testLocal () throws Exception
|
||||
{
|
||||
|
||||
InitialContext ic = new InitialContext();
|
||||
NameParser parser = ic.getNameParser("");
|
||||
ic.bind("foo", "xxx");
|
||||
|
||||
|
||||
Object o = ic.lookup("foo");
|
||||
assertNotNull(o);
|
||||
assertEquals("xxx", (String)o);
|
||||
|
||||
|
||||
ic.unbind("foo");
|
||||
try
|
||||
{
|
||||
|
@ -72,17 +68,16 @@ public class TestLocalJNDI extends TestCase
|
|||
Context c = (Context)ic.lookup("a/b/c");
|
||||
o = c.lookup("d");
|
||||
assertNotNull(o);
|
||||
assertEquals("333", (String)o);
|
||||
assertEquals("333", (String)o);
|
||||
assertEquals("333", ic.lookup(name));
|
||||
ic.destroySubcontext("a");
|
||||
|
||||
|
||||
name = parser.parse("");
|
||||
name.add("x");
|
||||
Name suffix = parser.parse("y/z");
|
||||
name.addAll(suffix);
|
||||
NamingUtil.bind(ic, name.toString(), "555");
|
||||
NamingUtil.bind(ic, name.toString(), "555");
|
||||
assertEquals("555", ic.lookup(name));
|
||||
ic.destroySubcontext("x");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue