01: package com.sun.portal.util.test;
02:
03: import junit.framework.TestCase;
04: import com.sun.portal.log.common.PortalLogger;
05: import junit.framework.Test;
06: import junit.framework.TestSuite;
07: import com.sun.portal.util.SystemProperties;
08:
09: import java.io.File;
10: import java.io.IOException;
11: import java.io.FileOutputStream;
12:
13: public class SystemPropertiesTest extends TestCase {
14:
15: public SystemPropertiesTest(String name) {
16: super (name);
17: }
18:
19: private static final String testData = "gateway.user=noaccess6\n"
20: + "gateway.jdk.dir=/usr/java_1.3.1_04\n"
21: + "gateway.dsame.agent=http://fresh.India.Sun.COM:80//portal/RemoteConfigServlet\n"
22: + "gateway.virtualhost=fresh.India.Sun.COM 129.158.227.144\n"
23: + "gateway.notification.url=/notification\n"
24: + "gateway.sockretries=3";
25:
26: private String createTempFile() throws IOException {
27: File f = File.createTempFile("PlatformConfig", "properties");
28: f.deleteOnExit();
29: String fileName = f.getAbsolutePath();
30:
31: FileOutputStream fOut = new FileOutputStream(fileName);
32: fOut.write(testData.getBytes());
33: fOut.flush();
34: fOut.close();
35: return fileName;
36: }
37:
38: public void setUp() throws IOException {
39: SystemProperties.init(createTempFile());
40: }
41:
42: public void testGet() {
43:
44: String expected = "noaccess6";
45: assertEquals(expected, SystemProperties.get("gateway.user"));
46: expected = "/usr/java_1.3.1_04";
47: assertEquals(expected, SystemProperties.get("gateway.jdk.dir"));
48: assertNull(SystemProperties
49: .get("gateway.something.nonexistant"));
50:
51: }
52:
53: public void testGetDefault() {
54: String expected = "defaultvalue";
55: assertEquals(expected, SystemProperties
56: .get("abc.ccc", expected));
57:
58: expected = "/usr/java_1.3.1_04";
59: assertEquals(expected, SystemProperties.get("gateway.jdk.dir",
60: "somejunk"));
61: }
62:
63: public static Test suite() {
64: TestSuite suite = new TestSuite();
65: suite.addTestSuite(SystemPropertiesTest.class);
66: return suite;
67: }
68:
69: public static void main(String[] args) {
70: junit.textui.TestRunner.run(suite());
71: }
72:
73: }
|