1 23 24 package com.rift.coad.lib.security.user.xml; 25 26 import junit.framework.*; 27 import java.util.Map ; 28 import java.util.HashMap ; 29 import java.util.Iterator ; 30 import java.io.BufferedReader ; 31 import java.io.File ; 32 import java.io.FileReader ; 33 import javax.xml.parsers.SAXParserFactory ; 34 import javax.xml.parsers.SAXParser ; 35 import org.xml.sax.InputSource ; 36 import org.xml.sax.helpers.DefaultHandler ; 37 import org.xml.sax.SAXException ; 38 import org.xml.sax.Attributes ; 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 47 public class XMLUserParserTest extends TestCase { 48 49 public XMLUserParserTest(String testName) { 50 super(testName); 51 } 52 53 protected void setUp() throws Exception { 54 } 55 56 protected void tearDown() throws Exception { 57 } 58 59 public static Test suite() { 60 TestSuite suite = new TestSuite(XMLUserParserTest.class); 61 62 return suite; 63 } 64 65 68 public void testGetUsers() throws Exception { 69 System.out.println("getUsers"); 70 71 Map users = new HashMap (); 73 74 XMLUserParser instance = new XMLUserParser(users); 75 76 Map result = instance.getUsers(); 77 assertEquals(users, result); 78 79 UserData userData = (UserData)result.get("test"); 81 82 assertEquals("112233", userData.getPassword()); 84 85 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 assertEquals("11223344", userData.getPassword()); 98 99 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 |