KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > petals > util > PropertyUtilTest


1 /**
2  * PETALS - PETALS Services Platform.
3  * Copyright (c) 2005 EBM Websourcing, http://www.ebmwebsourcing.com/
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * -------------------------------------------------------------------------
19  * $Id: PropertyUtilTest.java 9:37:14 AM ddesjardins $
20  * -------------------------------------------------------------------------
21  */

22 package org.objectweb.petals.util;
23
24 import java.io.FileOutputStream JavaDoc;
25 import java.io.IOException JavaDoc;
26 import java.net.URL JavaDoc;
27 import java.util.Properties JavaDoc;
28
29 import org.objectweb.petals.PetalsException;
30
31 import junit.framework.TestCase;
32
33 /**
34  * Test of the PropertyUtil
35  *
36  * @author ddesjardins - eBMWebsourcing
37  */

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 JavaDoc 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 JavaDoc,
51         PetalsException {
52         URL JavaDoc url = PropertyUtil.class.getResource(PropertyUtil.SERVER_PROPS);
53         Properties JavaDoc properties = new Properties JavaDoc();
54         properties.load(url.openStream());
55         properties.setProperty("joram.id", "-1");
56         properties.store(new FileOutputStream JavaDoc(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             // do nothing
69
}
70     }
71     
72     public void testGetPropertyExceptionKey() {
73         try {
74             PropertyUtil.getProperty(PropertyUtil.SERVER_PROPS, "foo");
75             fail();
76         } catch (PetalsException e) {
77             // do nothing
78
}
79     }
80 }
81
Popular Tags