Source Code Cross Referenced for PersonDirXmlParserTest.java in  » Portal » uPortal_rel-2-6-1-GA » org » jasig » portal » services » persondir » support » legacy » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Portal » uPortal_rel 2 6 1 GA » org.jasig.portal.services.persondir.support.legacy 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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 java.io.IOException;
009:        import java.util.List;
010:
011:        import javax.xml.parsers.ParserConfigurationException;
012:
013:        import org.jasig.portal.ResourceMissingException;
014:        import org.jasig.portal.utils.ResourceLoader;
015:        import org.w3c.dom.Document;
016:        import org.xml.sax.SAXException;
017:
018:        import junit.framework.TestCase;
019:
020:        /**
021:         * Testcase for PersonDirXmlParser.
022:         * @author andrew.petro@yale.edu
023:         * @version $Revision: 35108 $ $Date: 2004-12-03 08:07:53 -0700 (Fri, 03 Dec 2004) $
024:         */
025:        public class PersonDirXmlParserTest extends TestCase {
026:
027:            /**
028:             * Test parsing a PersonDirInfo XML file that defines a JDBC 
029:             * attribute source.
030:             * @throws SAXException
031:             * @throws ParserConfigurationException
032:             * @throws IOException
033:             * @throws ResourceMissingException
034:             */
035:            public void testJdbc() throws ResourceMissingException,
036:                    IOException, ParserConfigurationException, SAXException {
037:                Document doc = ResourceLoader.getResourceAsDocument(this 
038:                        .getClass(), "jdbcPersonDir.xml");
039:                List personDirInfos = PersonDirXmlParser.getPersonDirInfos(doc);
040:                assertEquals(1, personDirInfos.size());
041:                PersonDirInfo pdi = (PersonDirInfo) personDirInfos.get(0);
042:
043:                assertTrue(pdi.isJdbc());
044:                assertFalse(pdi.isLdap());
045:
046:                assertEquals(getJdbcPersonDirInfo(), pdi);
047:
048:            }
049:
050:            /**
051:             * Test parsing a PersonDirInfo that defines a JDBC source that references a
052:             * DataSource configured in RDBMServices.
053:             * @throws SAXException
054:             * @throws ParserConfigurationException
055:             * @throws IOException
056:             * @throws ResourceMissingException
057:             */
058:            public void testJdbcRef() throws ResourceMissingException,
059:                    IOException, ParserConfigurationException, SAXException {
060:                Document doc = ResourceLoader.getResourceAsDocument(this 
061:                        .getClass(), "jdbcRefPersonDir.xml");
062:                List personDirInfos = PersonDirXmlParser.getPersonDirInfos(doc);
063:                assertEquals(1, personDirInfos.size());
064:                PersonDirInfo pdi = (PersonDirInfo) personDirInfos.get(0);
065:
066:                assertTrue(pdi.isJdbc());
067:                assertFalse(pdi.isLdap());
068:
069:                assertEquals(getJdbcRefPersonDirInfo(), pdi);
070:            }
071:
072:            public void testLdap() throws ResourceMissingException,
073:                    IOException, ParserConfigurationException, SAXException {
074:                Document doc = ResourceLoader.getResourceAsDocument(this 
075:                        .getClass(), "ldapPersonDir.xml");
076:                List personDirInfos = PersonDirXmlParser.getPersonDirInfos(doc);
077:                assertEquals(1, personDirInfos.size());
078:                PersonDirInfo pdi = (PersonDirInfo) personDirInfos.get(0);
079:
080:                assertFalse(pdi.isJdbc());
081:                assertTrue(pdi.isLdap());
082:
083:                assertEquals(getLdapPersonDirInfo(), pdi);
084:
085:            }
086:
087:            /**
088:             * Test parsing a PersonDirs.xml that defines an LDAP attribute source that
089:             * references LdapServices to identify the actual LDAP server.
090:             * @throws ResourceMissingException
091:             * @throws IOException
092:             * @throws ParserConfigurationException
093:             * @throws SAXException
094:             */
095:            public void testLdapRef() throws ResourceMissingException,
096:                    IOException, ParserConfigurationException, SAXException {
097:                Document doc = ResourceLoader.getResourceAsDocument(this 
098:                        .getClass(), "ldapRefPersonDir.xml");
099:                List personDirInfos = PersonDirXmlParser.getPersonDirInfos(doc);
100:                assertEquals(1, personDirInfos.size());
101:                PersonDirInfo pdi = (PersonDirInfo) personDirInfos.get(0);
102:
103:                assertFalse(pdi.isJdbc());
104:                assertTrue(pdi.isLdap());
105:
106:                assertEquals(getLdapRefPersonDirInfo(), pdi);
107:            }
108:
109:            /**
110:             * Test proper parsing of a file declaring several PersonDirInfo person
111:             * attribute sources.
112:             * @throws SAXException
113:             * @throws ParserConfigurationException
114:             * @throws IOException
115:             * @throws ResourceMissingException
116:             */
117:            public void testSeveralSources() throws ResourceMissingException,
118:                    IOException, ParserConfigurationException, SAXException {
119:                Document doc = ResourceLoader.getResourceAsDocument(this 
120:                        .getClass(), "severalPersonDir.xml");
121:                List personDirInfos = PersonDirXmlParser.getPersonDirInfos(doc);
122:
123:                assertEquals(4, personDirInfos.size());
124:
125:                assertEquals(getJdbcPersonDirInfo(), personDirInfos.get(0));
126:                assertEquals(getJdbcRefPersonDirInfo(), personDirInfos.get(1));
127:                assertEquals(getLdapPersonDirInfo(), personDirInfos.get(2));
128:                assertEquals(getLdapRefPersonDirInfo(), personDirInfos.get(3));
129:
130:            }
131:
132:            /**
133:             * Test that invoking getPersonDirInfos() on a null document
134:             * fails with an IllegalArgumentException.
135:             */
136:            public void testNullArg() {
137:                try {
138:                    PersonDirXmlParser.getPersonDirInfos(null);
139:                } catch (IllegalArgumentException iae) {
140:                    // good
141:                    return;
142:                }
143:                fail("Should have throws IAE on null argument.");
144:            }
145:
146:            /**
147:             * Test that invoking PersonDirXmlParser on a file containing
148:             * zero PersonDirInfo declarations results in the empty list.
149:             * @throws SAXException
150:             * @throws ParserConfigurationException
151:             * @throws IOException
152:             * @throws ResourceMissingException
153:             */
154:            public void testZeroPDIs() throws ResourceMissingException,
155:                    IOException, ParserConfigurationException, SAXException {
156:                Document doc = ResourceLoader.getResourceAsDocument(this 
157:                        .getClass(), "zeroPersonDir.xml");
158:                List personDirInfos = PersonDirXmlParser.getPersonDirInfos(doc);
159:                assertTrue(personDirInfos.isEmpty());
160:            }
161:
162:            /**
163:             * Test that invoking PersonDirXmlParser on a file having
164:             * nothing to do with PersonDirInfo results in empty list of PDIs.
165:             * @throws SAXException
166:             * @throws ParserConfigurationException
167:             * @throws IOException
168:             * @throws ResourceMissingException
169:             */
170:            public void testBadXml() throws ResourceMissingException,
171:                    IOException, ParserConfigurationException, SAXException {
172:                Document doc = ResourceLoader.getResourceAsDocument(this 
173:                        .getClass(), "bogus.xml");
174:                List personDirInfos = PersonDirXmlParser.getPersonDirInfos(doc);
175:                assertTrue(personDirInfos.isEmpty());
176:
177:            }
178:
179:            /**
180:             * Get a PersonDirInfo representing a query against a directly-configured
181:             * JDBC attribute source.
182:             * @return Returns the jdbcPersonDirInfo.
183:             */
184:            static PersonDirInfo getJdbcPersonDirInfo() {
185:                PersonDirInfo jdbcPersonDirInfo = new PersonDirInfo();
186:                jdbcPersonDirInfo = new PersonDirInfo();
187:                jdbcPersonDirInfo.setDriver("org.hsql.jdbcDriver");
188:                jdbcPersonDirInfo
189:                        .setUrl("jdbc:HypersonicSQL:hsql://localhost:8887");
190:                jdbcPersonDirInfo.setLogonid("username");
191:                jdbcPersonDirInfo.setLogonpassword("password");
192:                jdbcPersonDirInfo
193:                        .setUidquery("select * from schema.table where netid=?");
194:
195:                // these are the names of attributes as they will be accessed and consumed
196:                // by clients of PersonDirectory
197:                String[] jdbcAttributeAliases = { "displayName", "sn",
198:                        "uPortalAffiliation", "givenName", "email", "alias",
199:                        "personType", "YaleCollege", "ClassYear",
200:                        "StudentStatus", "uPortalTemplateUserName", "netid",
201:                        "eduPersonPrincipalName", "WorkPhone", };
202:                jdbcPersonDirInfo.setAttributealiases(jdbcAttributeAliases);
203:
204:                // in the case of JDBC, these are database column names
205:                // but PDI regards them as a generic list of names of attributes in the
206:                // attribute source
207:                String[] jdbcAttributeNames = { "first_last", "last_name",
208:                        "role", "first_name", "email_alias", "alias",
209:                        "person_type", "college", "class_year",
210:                        "student_status", "template", "netid", "netid",
211:                        "work_phone" };
212:
213:                jdbcPersonDirInfo.setAttributenames(jdbcAttributeNames);
214:
215:                return jdbcPersonDirInfo;
216:            }
217:
218:            /**
219:             * Obtain an example PersonDirInfo which represents using a query against
220:             * an RDBMServices-configured JDBC DataSource to obtain person
221:             * attribute information.
222:             * @return Returns a suitable example PersonDirInfo.
223:             */
224:            static PersonDirInfo getJdbcRefPersonDirInfo() {
225:                PersonDirInfo jdbcRefPersonDirInfo = new PersonDirInfo();
226:
227:                jdbcRefPersonDirInfo.setResRefName("PersonDb");
228:
229:                jdbcRefPersonDirInfo
230:                        .setUidquery("select * from schema.table where netid=?");
231:
232:                // in the case of JDBC, these are database column names
233:                // but PDI regards them as a generic list of names of attributes in the
234:                // attribute source
235:                String[] jdbcRefAttributeNames = { "first_last", "last_name",
236:                        "role", "first_name", "email_alias", "alias",
237:                        "person_type", "college", "class_year",
238:                        "student_status", "template", "netid", "netid",
239:                        "work_phone" };
240:
241:                jdbcRefPersonDirInfo.setAttributenames(jdbcRefAttributeNames);
242:
243:                // these are the names of attributes as they will be accessed and consumed
244:                // by clients of PersonDirectory
245:
246:                String[] jdbcRefAttributeAliases = { "displayName", "sn",
247:                        "uPortalAffiliation", "givenName", "email", "alias",
248:                        "personType", "YaleCollege", "ClassYear",
249:                        "StudentStatus", "uPortalTemplateUserName", "netid",
250:                        "eduPersonPrincipalName", "WorkPhone", };
251:
252:                jdbcRefPersonDirInfo
253:                        .setAttributealiases(jdbcRefAttributeAliases);
254:
255:                return jdbcRefPersonDirInfo;
256:            }
257:
258:            /**
259:             * Get an exple PersonDirInfo object representing an LDAP person attribute
260:             * source which is configured directly in the PersonDirInfo (as opposed to
261:             * by reference to an LdapServices LDAP connection).
262:             * @return Returns a suitable example PersonDirInfo
263:             */
264:            static PersonDirInfo getLdapPersonDirInfo() {
265:                PersonDirInfo ldapPersonDirInfo = new PersonDirInfo();
266:
267:                ldapPersonDirInfo
268:                        .setUrl("ldaps://mrfrumble.its.yale.edu:389/o=yale.edu");
269:                ldapPersonDirInfo.setLogonid("someUser");
270:                ldapPersonDirInfo.setLogonpassword("somePassword");
271:                ldapPersonDirInfo.setUidquery("(uid={0})");
272:
273:                // these are the names of attributes as they will be accessed and consumed
274:                // by clients of PersonDirectory
275:                ldapPersonDirInfo
276:                        .setAttributealiases(new String[] { "emailfromldap" });
277:
278:                // in the case of LDAP, these are attribute names in the LDAP store
279:                // but PDI regards them as a generic list of names of attributes in the
280:                // attribute source
281:                ldapPersonDirInfo.setAttributenames(new String[] { "mail" });
282:
283:                ldapPersonDirInfo.setUsercontext("");
284:                return ldapPersonDirInfo;
285:            }
286:
287:            /**
288:             * Get an example PersonDirInfo representing using an LdapServices-configured
289:             * LDAP server to obtain person attributes.
290:             * @return Returns a suitable example PersonDirInfo.
291:             */
292:            static PersonDirInfo getLdapRefPersonDirInfo() {
293:
294:                PersonDirInfo ldapRefPersonDirInfo = new PersonDirInfo();
295:
296:                ldapRefPersonDirInfo.setLdapRefName("DEFAULT_LDAP_SERVER");
297:
298:                ldapRefPersonDirInfo.setUidquery("(cn={0})");
299:
300:                // in the case of LDAP, these are names of attributes in the LDAP store
301:                // but PDI regards them as a generic list of names of attributes in the
302:                // attribute source
303:                String[] ldapRefAttributeNames = {
304:                        "eduPersonPrimaryAffiliation", "eduPersonAffiliation",
305:                        "eduPersonNickname", "eduPersonOrgDN",
306:                        "eduPersonOrgUnitDN", "eduPersonPrimaryAffiliation",
307:                        "eduPersonPrincipalName", "c", "cn", "description",
308:                        "displayName", "facsimileTelephoneNumber", "givenName" };
309:
310:                ldapRefPersonDirInfo.setAttributenames(ldapRefAttributeNames);
311:
312:                // these are the names of attributes as they will be accessed and consumed
313:                // by clients of PersonDirectory
314:
315:                String[] ldapRefAttributeAliases = { "uPortalTemplateUserName",
316:                        "eduPersonAffiliation", "eduPersonNickname",
317:                        "eduPersonOrgDN", "eduPersonOrgUnitDN",
318:                        "eduPersonPrimaryAffiliation",
319:                        "eduPersonPrincipalName", "c", "cn", "description",
320:                        "displayName", "facsimileTelephoneNumber", "givenName" };
321:
322:                ldapRefPersonDirInfo
323:                        .setAttributealiases(ldapRefAttributeAliases);
324:
325:                ldapRefPersonDirInfo.setUsercontext("cn=Users");
326:
327:                return ldapRefPersonDirInfo;
328:            }
329:
330:        }
ww___w__._j___a___v___a__2__s.___c__o__m___ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.