1 22 package org.objectweb.petals.util; 23 24 import java.io.FileOutputStream ; 25 import java.io.IOException ; 26 import java.net.URL ; 27 import java.util.Properties ; 28 29 import org.objectweb.petals.PetalsException; 30 31 import junit.framework.TestCase; 32 33 38 public class PropertyUtilTest extends TestCase { 39 40 public void testRetrieveJNDIProperties() { 41 SystemUtil.setJndiPort("16400"); 42 SystemUtil.setJndiFactory("test"); 43 SystemUtil.setHost("127.0.0.1"); 44 Properties props = PropertyUtil.retrieveJNDIProperties(); 45 assertEquals(props.getProperty("java.naming.factory.host"), "127.0.0.1"); 46 assertEquals(props.getProperty("java.naming.factory.port"), "16400"); 47 assertEquals(props.getProperty("java.naming.factory.host"), "127.0.0.1"); 48 } 49 50 public void testUpdateContainerProperties() throws IOException , 51 PetalsException { 52 URL url = PropertyUtil.class.getResource(PropertyUtil.SERVER_PROPS); 53 Properties properties = new Properties (); 54 properties.load(url.openStream()); 55 properties.setProperty("joram.id", "-1"); 56 properties.store(new FileOutputStream (url.getFile()), "Test"); 57 PropertyUtil.updateContainerProperties("0", "16200", "16300", "8081", 58 "8082", "16400", 1); 59 assertEquals(PropertyUtil.getProperty(PropertyUtil.SERVER_PROPS, 60 "joram.id"), "0"); 61 } 62 63 public void testGetPropertyExceptionFile() { 64 try { 65 PropertyUtil.getProperty("test", "foo"); 66 fail(); 67 } catch (PetalsException e) { 68 } 70 } 71 72 public void testGetPropertyExceptionKey() { 73 try { 74 PropertyUtil.getProperty(PropertyUtil.SERVER_PROPS, "foo"); 75 fail(); 76 } catch (PetalsException e) { 77 } 79 } 80 } 81 | Popular Tags |