KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > SunConfigParserTestCase


1 /*
2 * JBoss, the OpenSource J2EE webOS
3 *
4 * Distributable under LGPL license.
5 * See terms of license at gnu.org.
6 */

7 package org.jboss.test;
8
9 import java.io.InputStreamReader JavaDoc;
10 import java.net.URL JavaDoc;
11 import javax.security.auth.login.AppConfigurationEntry JavaDoc;
12 import javax.security.auth.login.AppConfigurationEntry.LoginModuleControlFlag;
13
14 import junit.framework.TestCase;
15
16 import org.jboss.security.auth.login.SunConfigParser;
17 import org.jboss.security.auth.login.XMLLoginConfigImpl;
18
19 /** Tests of the Sun login configuration file format parser
20  *
21  * @author Scott.Stark@jboss.org
22  * @version $Revision: 1.5.6.1 $
23  */

24 public class SunConfigParserTestCase extends TestCase
25 {
26
27    public SunConfigParserTestCase(String JavaDoc name)
28    {
29       super(name);
30    }
31
32    /** Test the Sun config file parser directly.
33     *
34     * @throws Exception
35     */

36    public void testParser() throws Exception JavaDoc
37    {
38       XMLLoginConfigImpl config = new XMLLoginConfigImpl();
39       ClassLoader JavaDoc loader = Thread.currentThread().getContextClassLoader();
40       URL JavaDoc configURL = loader.getResource("login-config.conf");
41       InputStreamReader JavaDoc configFile = new InputStreamReader JavaDoc(configURL.openStream());
42       SunConfigParser.doParse(configFile, config, true);
43
44       AppConfigurationEntry JavaDoc[] entry = config.getAppConfigurationEntry("case1");
45       assertTrue("case1 entry != null", entry != null);
46       assertTrue("case1.length == 2", entry.length == 2);
47       assertTrue("case1[0].module == org.jboss.test.TestLoginModule",
48          entry[0].getLoginModuleName().equals("org.jboss.test.TestLoginModule"));
49       assertTrue("case1[0].flag == required",
50          entry[0].getControlFlag() == LoginModuleControlFlag.REQUIRED);
51       assertTrue("case1[0].option(name) == 1.1",
52          entry[0].getOptions().get("name").equals("1.1"));
53       assertTrue("case1[0].option(succeed) == true",
54          entry[0].getOptions().get("succeed").equals("true"));
55       assertTrue("case1[0].option(throwEx) == false",
56          entry[0].getOptions().get("throwEx").equals("false"));
57
58       entry = config.getAppConfigurationEntry("case2");
59       assertTrue("case2 entry != null", entry != null);
60       assertTrue("case2.length == 2", entry.length == 2);
61       assertTrue("case2[0].module = org.jboss.test.TestLoginModule",
62          entry[0].getLoginModuleName().equals("org.jboss.test.TestLoginModule"));
63       assertTrue("case2[0].flag == optional",
64          entry[0].getControlFlag() == LoginModuleControlFlag.OPTIONAL);
65       assertTrue("case2[1].option(name) == 2.2",
66          entry[1].getOptions().get("name").equals("2.2"));
67       assertTrue("case2[1].option(succeed) == false",
68          entry[1].getOptions().get("succeed").equals("false"));
69       assertTrue("case2[1].option(throwEx) == true",
70          entry[1].getOptions().get("throwEx").equals("true"));
71    }
72
73    /** Test the Sun config file parser by creating a XMLLoginConfig with a
74     * URL pointing to a Sun format config file.
75     *
76     * @throws Exception
77     */

78    public void testSunLoginConfig() throws Exception JavaDoc
79    {
80       XMLLoginConfigImpl config = new XMLLoginConfigImpl();
81       ClassLoader JavaDoc loader = Thread.currentThread().getContextClassLoader();
82       URL JavaDoc configURL = loader.getResource("login-config.conf");
83       config.setConfigURL(configURL);
84       config.loadConfig();
85
86       AppConfigurationEntry JavaDoc[] entry = config.getAppConfigurationEntry("case1");
87       assertTrue("case1 entry != null", entry != null);
88       assertTrue("case1.length == 2", entry.length == 2);
89       assertTrue("case1[0].module == org.jboss.test.TestLoginModule",
90          entry[0].getLoginModuleName().equals("org.jboss.test.TestLoginModule"));
91       assertTrue("case1[0].flag == required",
92          entry[0].getControlFlag() == LoginModuleControlFlag.REQUIRED);
93       assertTrue("case1[0].option(name) == 1.1",
94          entry[0].getOptions().get("name").equals("1.1"));
95       assertTrue("case1[0].option(succeed) == true",
96          entry[0].getOptions().get("succeed").equals("true"));
97       assertTrue("case1[0].option(throwEx) == false",
98          entry[0].getOptions().get("throwEx").equals("false"));
99
100       entry = config.getAppConfigurationEntry("case2");
101       assertTrue("case2 entry != null", entry != null);
102       assertTrue("case2.length == 2", entry.length == 2);
103       assertTrue("case2[0].module = org.jboss.test.TestLoginModule",
104          entry[0].getLoginModuleName().equals("org.jboss.test.TestLoginModule"));
105       assertTrue("case2[0].flag == optional",
106          entry[0].getControlFlag() == LoginModuleControlFlag.OPTIONAL);
107       assertTrue("case2[1].option(name) == 2.2",
108          entry[1].getOptions().get("name").equals("2.2"));
109       assertTrue("case2[1].option(succeed) == false",
110          entry[1].getOptions().get("succeed").equals("false"));
111       assertTrue("case2[1].option(throwEx) == true",
112          entry[1].getOptions().get("throwEx").equals("true"));
113    }
114 }
115
Popular Tags