001: /* Copyright 2004 The JA-SIG Collaborative. All rights reserved.
002: * See license distributed with this file and
003: * available online at http://www.uportal.org/license.html
004: */
005:
006: package org.jasig.portal.services.persondir.support.legacy;
007:
008: import org.jasig.portal.services.persondir.support.legacy.PersonDirInfo;
009: import org.jasig.portal.services.persondir.support.legacy.PersonDirXmlParserTest;
010:
011: import junit.framework.TestCase;
012:
013: /**
014: * Testcases for PersonDirInfo.
015: * @author andrew.petro@yale.edu
016: * @version $Revision: 35162 $ $Date: 2004-12-15 09:57:34 -0700 (Wed, 15 Dec 2004) $
017: */
018: public class PersonDirInfoTest extends TestCase {
019:
020: /**
021: * Test that properly identifies JDBC PersonDirInfo entries.
022: */
023: public void testJdbcRef() {
024: PersonDirInfo pdi = new PersonDirInfo();
025: pdi.setResRefName("rdbmservices_managed_datasource");
026: assertTrue(pdi.isJdbc());
027: assertFalse(pdi.isLdap());
028: }
029:
030: /**
031: * Test that JDBC configured within PersonDirInfo is properly identified
032: * as JDBC.
033: */
034: public void testJdbcUrl() {
035: PersonDirInfo pdi = new PersonDirInfo();
036: pdi.setUrl("jdbc://someserver:45");
037: assertTrue(pdi.isJdbc());
038: assertFalse(pdi.isLdap());
039: }
040:
041: /**
042: * Test that properly identifies references to LdapServices configured
043: * LDAP servers as LDAP servers.
044: */
045: public void testLdapRef() {
046: PersonDirInfo pdi = new PersonDirInfo();
047: pdi.setLdapRefName("ldapservices_managed_ldap");
048: assertTrue(pdi.isLdap());
049: assertFalse(pdi.isJdbc());
050: }
051:
052: /**
053: * Test that properly identifies LDAP urls as LDAP server entries.
054: */
055: public void testLdapUrl() {
056: PersonDirInfo pdi = new PersonDirInfo();
057: pdi.setUrl("ldap://someserver");
058: assertTrue(pdi.isLdap());
059: assertFalse(pdi.isJdbc());
060: }
061:
062: /**
063: * Test that the validate() method of an entirely new PDI
064: * throws IllegalStateException.
065: */
066: public void testValidateBare() {
067: PersonDirInfo pdi = new PersonDirInfo();
068: assertNotNull(pdi.validate());
069: }
070:
071: /**
072: * Test that a PersonDirInfo which has no uid query set throws
073: * IllegalStateException on validation attempt.
074: */
075: public void testValidateNoUid() {
076: PersonDirInfo pdi = new PersonDirInfo();
077: pdi.setLdapRefName("someserver");
078: assertNotNull(pdi.validate());
079: }
080:
081: /**
082: * Test that validating valid PDIs returns no error messages.
083: */
084: public void testValids() {
085: assertNull(PersonDirXmlParserTest.getJdbcPersonDirInfo()
086: .validate());
087: assertNull(PersonDirXmlParserTest.getJdbcRefPersonDirInfo()
088: .validate());
089: assertNull(PersonDirXmlParserTest.getLdapPersonDirInfo()
090: .validate());
091: assertNull(PersonDirXmlParserTest.getLdapRefPersonDirInfo()
092: .validate());
093: }
094:
095: /**
096: * Test that setting ldapRef after setting the url results in IllegalStateException.
097: */
098: public void testSetUrlAndLdapRef() {
099: PersonDirInfo pdi = new PersonDirInfo();
100: pdi.setUrl("jdbc://someserver:45");
101: try {
102: pdi.setLdapRefName("foo");
103: } catch (IllegalStateException ise) {
104: // good
105: return;
106: }
107: fail("Should have thrown ISE when trying to set refname on a "
108: + "PDI which already has a URL set.");
109: }
110:
111: }
|