001: /*
002: * CoadunationLib: The coaduntion implementation library.
003: * Copyright (C) 2006 Rift IT Contracting
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation; either
008: * version 2.1 of the License, or (at your option) any later version.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public
016: * License along with this library; if not, write to the Free Software
017: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
018: *
019: * XMLUserParserTest.java
020: *
021: * JUnit based test
022: */
023:
024: package com.rift.coad.lib.security.user.xml;
025:
026: import junit.framework.*;
027: import java.util.Map;
028: import java.util.HashMap;
029: import java.util.Iterator;
030: import java.io.BufferedReader;
031: import java.io.File;
032: import java.io.FileReader;
033: import javax.xml.parsers.SAXParserFactory;
034: import javax.xml.parsers.SAXParser;
035: import org.xml.sax.InputSource;
036: import org.xml.sax.helpers.DefaultHandler;
037: import org.xml.sax.SAXException;
038: import org.xml.sax.Attributes;
039: import com.rift.coad.lib.configuration.Configuration;
040: import com.rift.coad.lib.configuration.ConfigurationFactory;
041: import com.rift.coad.lib.security.user.UserException;
042:
043: /**
044: *
045: * @author mincemeat
046: */
047: public class XMLUserParserTest extends TestCase {
048:
049: public XMLUserParserTest(String testName) {
050: super (testName);
051: }
052:
053: protected void setUp() throws Exception {
054: }
055:
056: protected void tearDown() throws Exception {
057: }
058:
059: public static Test suite() {
060: TestSuite suite = new TestSuite(XMLUserParserTest.class);
061:
062: return suite;
063: }
064:
065: /**
066: * Test of getUsers method, of class com.rift.coad.lib.security.user.xml.XMLUserParser.
067: */
068: public void testGetUsers() throws Exception {
069: System.out.println("getUsers");
070:
071: // the list of users
072: Map users = new HashMap();
073:
074: XMLUserParser instance = new XMLUserParser(users);
075:
076: Map result = instance.getUsers();
077: assertEquals(users, result);
078:
079: // retrieve the test data
080: UserData userData = (UserData) result.get("test");
081:
082: // retrieve the password
083: assertEquals("112233", userData.getPassword());
084:
085: // test the principals
086: if (userData.getPrincipals().contains("test1") == false) {
087: fail("Expecting principal test1 to be set.");
088: } else if (userData.getPrincipals().contains("test2") == false) {
089: fail("Expecting principal test2 to be set.");
090: } else if (userData.getPrincipals().contains("test3") == false) {
091: fail("Expecting principal test3 to be set.");
092: }
093:
094: userData = (UserData) result.get("test2");
095:
096: // retrieve the password
097: assertEquals("11223344", userData.getPassword());
098:
099: // 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: }
|