1 package org.sapia.regis.prevayler; 2 3 import java.io.File ; 4 import java.io.FileInputStream ; 5 import java.util.HashMap ; 6 import java.util.Map ; 7 import java.util.Properties ; 8 9 import org.sapia.regis.Node; 10 import org.sapia.regis.Path; 11 import org.sapia.regis.RegisSession; 12 import org.sapia.regis.Registry; 13 import org.sapia.regis.RegistryContext; 14 import org.sapia.regis.remote.RegistryServer; 15 import org.sapia.regis.util.Utils; 16 import org.sapia.ubik.rmi.Consts; 17 import org.sapia.ubik.rmi.server.Hub; 18 import org.sapia.ubik.util.Localhost; 19 20 import junit.framework.TestCase; 21 22 public class PrevaylerRegistryTest extends TestCase { 23 24 private PrevaylerRegistry reg; 25 26 public PrevaylerRegistryTest(String arg0) { 27 super(arg0); 28 } 29 30 protected void setUp() throws Exception { 31 PrevaylerRegistryFactory fac = new PrevaylerRegistryFactory(); 32 Properties props = new Properties (); 33 props.setProperty(PrevaylerRegistryFactory.DELETE_ON_STARTUP, "true"); 34 reg = (PrevaylerRegistry)fac.connect(props); 35 } 36 37 protected void tearDown() throws Exception { 38 reg.close(); 39 Utils.deleteRecurse(new File (PrevaylerRegistryFactory.DEFAULT_BASE_DIR)); 40 } 41 42 public void testLoad() throws Exception { 43 reg.load(Path.parse(Node.ROOT_NAME), null, null, 44 Utils.loadAsString(new FileInputStream ("etc/configCreateExample.xml")), null); 45 reg.close(); 46 PrevaylerRegistryFactory fac = new PrevaylerRegistryFactory(); 47 Properties props = new Properties (); 48 props.setProperty(PrevaylerRegistryFactory.DELETE_ON_STARTUP, "false"); 49 reg = (PrevaylerRegistry)fac.connect(props); 50 String username = reg.getRoot().getChild(Path.parse("databases/000")).getProperty("username").asString(); 51 assertEquals("jsmith", username); 52 } 53 54 public void testPrevaylerServer() throws Exception { 55 System.setProperty(Consts.IP_PATTERN_KEY, "localhost"); 56 RegistryServer.startThread = false; 57 RegistryServer.main(new String []{"etc/prevaylerServer.properties"}); 58 59 Thread.sleep(2000); 60 61 Properties props = new Properties (); 62 props.setProperty("registry.address", Localhost.getLocalAddress().getHostAddress()); 63 props.setProperty(RegistryContext.BOOTSTRAP, "etc/client.properties"); 64 RegistryContext ctx = new RegistryContext(props); 65 Registry regServer = ctx.connect(); 66 RegisSession s = regServer.open(); 67 assertEquals("jsmith", regServer.getRoot().getChild(Path.parse("databases/000")).getProperty("username").asString()); 68 Map params = new HashMap (); 69 params.put("param1", "value1"); 70 regServer.getRoot().getChild(Path.parse("databases/000")).getProperties(params); 71 s.close(); 72 Hub.shutdown(3000); 73 } 74 75 } 76 | Popular Tags |