KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > rift > coad > lib > security > user > xml > XMLUserParserTest


1 /*
2  * CoadunationLib: The coaduntion implementation library.
3  * Copyright (C) 2006 Rift IT Contracting
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  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  *
19  * XMLUserParserTest.java
20  *
21  * JUnit based test
22  */

23
24 package com.rift.coad.lib.security.user.xml;
25
26 import junit.framework.*;
27 import java.util.Map JavaDoc;
28 import java.util.HashMap JavaDoc;
29 import java.util.Iterator JavaDoc;
30 import java.io.BufferedReader JavaDoc;
31 import java.io.File JavaDoc;
32 import java.io.FileReader JavaDoc;
33 import javax.xml.parsers.SAXParserFactory JavaDoc;
34 import javax.xml.parsers.SAXParser JavaDoc;
35 import org.xml.sax.InputSource JavaDoc;
36 import org.xml.sax.helpers.DefaultHandler JavaDoc;
37 import org.xml.sax.SAXException JavaDoc;
38 import org.xml.sax.Attributes JavaDoc;
39 import com.rift.coad.lib.configuration.Configuration;
40 import com.rift.coad.lib.configuration.ConfigurationFactory;
41 import com.rift.coad.lib.security.user.UserException;
42
43 /**
44  *
45  * @author mincemeat
46  */

47 public class XMLUserParserTest extends TestCase {
48     
49     public XMLUserParserTest(String JavaDoc testName) {
50         super(testName);
51     }
52
53     protected void setUp() throws Exception JavaDoc {
54     }
55
56     protected void tearDown() throws Exception JavaDoc {
57     }
58
59     public static Test suite() {
60         TestSuite suite = new TestSuite(XMLUserParserTest.class);
61         
62         return suite;
63     }
64
65     /**
66      * Test of getUsers method, of class com.rift.coad.lib.security.user.xml.XMLUserParser.
67      */

68     public void testGetUsers() throws Exception JavaDoc {
69         System.out.println("getUsers");
70         
71         // the list of users
72
Map JavaDoc users = new HashMap JavaDoc();
73         
74         XMLUserParser instance = new XMLUserParser(users);
75         
76         Map JavaDoc result = instance.getUsers();
77         assertEquals(users, result);
78         
79         // retrieve the test data
80
UserData userData = (UserData)result.get("test");
81         
82         // retrieve the password
83
assertEquals("112233", userData.getPassword());
84         
85         // test the principals
86
if (userData.getPrincipals().contains("test1") == false) {
87             fail("Expecting principal test1 to be set.");
88         } else if (userData.getPrincipals().contains("test2") == false) {
89             fail("Expecting principal test2 to be set.");
90         } else if (userData.getPrincipals().contains("test3") == false) {
91             fail("Expecting principal test3 to be set.");
92         }
93         
94         userData = (UserData)result.get("test2");
95         
96         // retrieve the password
97
assertEquals("11223344", userData.getPassword());
98         
99         // test the principals
100
if (userData.getPrincipals().contains("test1") == false) {
101             fail("Expecting principal test1 to be set.");
102         } else if (userData.getPrincipals().contains("test5") == false) {
103             fail("Expecting principal test5 to be set.");
104         }
105         
106     }
107     
108 }
109
Popular Tags