User: d_jencks
Date: 01/09/11 21:55:40
Added: src/main/org/jboss/test/naming/test ENCUnitTestCase.java
ExternalContextUnitTestCase.java
SimpleUnitTestCase.java
Removed: src/main/org/jboss/test/naming/test SimpleTestCase.java
TestENC.java TestExternalContext.java
Log:
Changed naming scheme of tests to *UnitTestCase.java for short running tests and
*StressTestCase.java for lengthy tests. Made tests-unit and tests-stress targets in
build.xml
Revision Changes Path
1.1
jbosstest/src/main/org/jboss/test/naming/test/ENCUnitTestCase.java
Index: ENCUnitTestCase.java
===================================================================
package org.jboss.test.naming.test;
import java.io.IOException;
import java.rmi.RemoteException;
import javax.ejb.CreateException;
import javax.ejb.EJBObject;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.rmi.PortableRemoteObject;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.jboss.test.util.Deploy;
import org.jboss.test.naming.interfaces.TestENCHome;
import org.jboss.test.naming.interfaces.TestENCHome2;
/** Tests of the secure access to EJBs.
@author [EMAIL PROTECTED]
*/
public class ENCUnitTestCase extends TestCase
{
public ENCUnitTestCase(String name)
{
super(name);
}
/** Deploy the security ejb jar one time
*/
protected void setUp() throws Exception
{
// Deploy.deploy("naming.jar");
}
public void testENC() throws Exception
{
InitialContext jndiContext = new InitialContext();
Object obj = jndiContext.lookup("ENCBean");
obj = PortableRemoteObject.narrow(obj, TestENCHome.class);
TestENCHome home = (TestENCHome) obj;
System.out.println("Found TestENCHome");
EJBObject bean = home.create();
System.out.println("Created ENCBean");
bean.remove();
}
public void testENC2() throws Exception
{
InitialContext jndiContext = new InitialContext();
Object obj = jndiContext.lookup("ENCBean0");
obj = PortableRemoteObject.narrow(obj, TestENCHome2.class);
TestENCHome2 home = (TestENCHome2) obj;
System.out.println("Found TestENCHome2");
EJBObject bean = home.create();
System.out.println("Created ENCBean0");
bean.remove();
}
public static void main(java.lang.String[] args)
{
System.setErr(System.out);
Test suite = suite();
junit.textui.TestRunner.run(suite);
}
/**
* Setup the test suite.
*/
public static Test suite() {
TestSuite suite = new TestSuite();
// add a test case to deploy our support applications
String filename = "naming.jar";
suite.addTest(new Deploy.Deployer(filename));
suite.addTest(new TestSuite(ENCUnitTestCase.class));
// add a test case to undeploy our support applications
suite.addTest(new Deploy.Undeployer(filename));
return suite;
}
}
1.1
jbosstest/src/main/org/jboss/test/naming/test/ExternalContextUnitTestCase.java
Index: ExternalContextUnitTestCase.java
===================================================================
package org.jboss.test.naming.test;
import java.net.InetAddress;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Set;
import javax.management.ObjectInstance;
import javax.management.ObjectName;
import javax.management.RuntimeMBeanException;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import org.jboss.jmx.interfaces.JMXAdaptor;
/** A test of the ExternalContext naming mbean. To test there needs to be
one or more ExternalContex mbeans setup. An example filesystem context
setup would be:
<mbean code="org.jboss.naming.ExternalContext"
name="JBOSS-SYSTEM:service=ExternalContext,jndiName=external/fs/tmp">
<attribute name="JndiName">external/fs/Scott</attribute>
<attribute name="Properties">tmp.fs</attribute>
<attribute name="RemoteAccess">true</attribute>
</mbean>
where tmp.fs is a Properties file containing:
# JNDI properties for /Scott filesystem directory
java.naming.factory.initial=com.sun.jndi.fscontext.RefFSContextFactory
java.naming.provider.url=file:/tmp
@author [EMAIL PROTECTED]
@version $Revision: 1.1 $
*/
public class ExternalContextUnitTestCase extends junit.framework.TestCase
{
private ObjectName[] contextNames;
private JMXAdaptor server;
public ExternalContextUnitTestCase(String name)
{
super(name);
}
protected void setUp() throws Exception
{
try
{
contextNames = null;
String serverName = InetAddress.getLocalHost().getHostName();
JMXAdaptor server = (JMXAdaptor) new InitialContext().lookup("jmx");
ObjectName pattern = new ObjectName("*:service=ExternalContext,*");
Set names = server.queryMBeans(pattern, null);
Iterator iter = names.iterator();
ArrayList tmp = new ArrayList();
while( iter.hasNext() )
{
ObjectInstance oi = (ObjectInstance) iter.next();
ObjectName name = oi.getObjectName();
System.out.println(name);
tmp.add(name);
}
if( tmp.size() > 0 )
{
contextNames = new ObjectName[tmp.size()];
tmp.toArray(contextNames);
}
}
catch(Exception x)
{
x.printStackTrace();
if (x instanceof RuntimeMBeanException)
{
((RuntimeMBeanException)x).getTargetException().printStackTrace();
}
}
}
public void testExternalContexts() throws Exception
{
if( contextNames == null )
{
System.out.println("No ExternalContext names exist");
return;
}
InitialContext iniCtx = new InitialContext();
for(int n = 0; n < contextNames.length; n ++)
{
ObjectName name = contextNames[n];
String jndiName = name.getKeyProperty("jndiName");
if( jndiName == null )
{
System.out.println("Skipping "+name+" as it has no jndiName
property");
continue;
}
Context ctx = (Context) iniCtx.lookup(jndiName);
System.out.println("+++ Listing for: "+ctx);
list(ctx);
}
}
private void list(Context ctx) throws NamingException
{
NamingEnumeration enum = ctx.list("");
while( enum.hasMore() )
System.out.println(enum.next());
enum.close();
}
public static void main(String[] args) throws Exception
{
System.setErr(System.out);
System.setSecurityManager(new SecurityManager());
ExternalContextUnitTestCase test = new ExternalContextUnitTestCase("main");
test.setUp();
test.testExternalContexts();
}
}
1.1
jbosstest/src/main/org/jboss/test/naming/test/SimpleUnitTestCase.java
Index: SimpleUnitTestCase.java
===================================================================
package org.jboss.test.naming.test;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.naming.NameAlreadyBoundException;
import junit.framework.Test;
import junit.framework.TestCase;
public class SimpleUnitTestCase extends TestCase
{
public SimpleUnitTestCase(String name)
{
super(name);
}
public void testCreateSubcontext() throws Exception
{
InitialContext ctx = new InitialContext();
ctx.createSubcontext("foo");
try
{
ctx.createSubcontext("foo");
fail("Second createSubcontext(foo) did NOT fail");
}
catch(NameAlreadyBoundException e)
{
System.out.println("Second createSubcontext(foo) failed as expected");
}
ctx.createSubcontext("foo/bar");
ctx.unbind("foo/bar");
ctx.unbind("foo");
}
}
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development