1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
|
package org.biojava.naming;
import java.util.Properties;
import javax.naming.Binding;
import javax.naming.Context;
import javax.naming.NamingEnumeration;
import javax.naming.directory.Attributes;
import javax.naming.directory.DirContext;
import javax.naming.directory.InitialDirContext;
import junit.framework.TestCase;
/**
*
*
* @author Matthew Pocock
*/
public class ObdaInitialContextFactoryTest
extends TestCase
{
public void testLookup()
throws Exception
{
Properties env = new Properties();
env.put(Context.INITIAL_CONTEXT_FACTORY,
"org.biojava.naming.ObdaInitialContextFactory");
DirContext context = new InitialDirContext(env);
DirContext embl = (DirContext) context.lookup("urn:open-bio.org:format:embl");
assertNotNull("Fetched embl name", embl);
Attributes desc = embl.getAttributes("", new String[] { "description" });
assertEquals("Got one description attribute", 1, desc.size());
assertNotNull("Description is not null", desc.get("description"));
}
public void testWalk()
throws Exception
{
Properties env = new Properties();
env.put(Context.INITIAL_CONTEXT_FACTORY,
"org.biojava.naming.ObdaInitialContextFactory");
DirContext context = new InitialDirContext(env);
walk(context);
}
private void walk(DirContext context)
throws Exception
{
System.out.println("Reached " + context.getNameInNamespace());
System.out.println(" Attributes: " + context.getAttributes(""));
NamingEnumeration ne = context.listBindings("");
while(ne.hasMore()) {
Binding b = (Binding) ne.nextElement();
System.out.println("Binding: " + b.getName() + " -> " + b.getObject());
walk((DirContext) b.getObject());
}
}
}
|