Source Code Cross Referenced for XMLGroupDatabaseTest.java in  » Wiki-Engine » JSPWiki » com » ecyrd » jspwiki » auth » authorize » 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 » Wiki Engine » JSPWiki » com.ecyrd.jspwiki.auth.authorize 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.ecyrd.jspwiki.auth.authorize;
002:
003:        import java.security.Principal;
004:        import java.util.Properties;
005:
006:        import junit.framework.TestCase;
007:
008:        import com.ecyrd.jspwiki.TestEngine;
009:        import com.ecyrd.jspwiki.WikiEngine;
010:        import com.ecyrd.jspwiki.WikiException;
011:        import com.ecyrd.jspwiki.auth.NoSuchPrincipalException;
012:        import com.ecyrd.jspwiki.auth.WikiPrincipal;
013:        import com.ecyrd.jspwiki.auth.WikiSecurityException;
014:
015:        /**
016:         * @author Andrew Jaquith
017:         */
018:        public class XMLGroupDatabaseTest extends TestCase {
019:
020:            private XMLGroupDatabase m_db;
021:
022:            private String m_wiki;
023:
024:            /**
025:             * @see junit.framework.TestCase#setUp()
026:             */
027:            protected void setUp() throws Exception {
028:                super .setUp();
029:                Properties props = new Properties();
030:                props.load(TestEngine.findTestProperties());
031:                WikiEngine engine = new TestEngine(props);
032:                m_db = new XMLGroupDatabase();
033:                m_db.initialize(engine, props);
034:                m_wiki = engine.getApplicationName();
035:            }
036:
037:            public void testDelete() throws WikiException {
038:                // First, count the number of groups in the db now.
039:                int oldUserCount = m_db.groups().length;
040:
041:                // Create a new group with random name
042:                String name = "TestGroup"
043:                        + String.valueOf(System.currentTimeMillis());
044:                Group group = new Group(name, m_wiki);
045:                Principal al = new WikiPrincipal("Al");
046:                Principal bob = new WikiPrincipal("Bob");
047:                group.add(al);
048:                group.add(bob);
049:                m_db.save(group, new WikiPrincipal("Tester"));
050:
051:                // Make sure the profile saved successfully
052:                group = backendGroup(name);
053:                assertEquals(name, group.getName());
054:                assertEquals(oldUserCount + 1, m_db.groups().length);
055:
056:                // Now delete the profile; should be back to old count
057:                m_db.delete(group);
058:                assertEquals(oldUserCount, m_db.groups().length);
059:            }
060:
061:            public void testGroups() throws WikiSecurityException {
062:                // Test file has 4 groups in it: TV, Literature, Art, and Admin
063:                Group[] groups = m_db.groups();
064:                assertEquals(4, groups.length);
065:
066:                Group group;
067:
068:                // Group TV has 3 members
069:                group = backendGroup("TV");
070:                assertEquals("TV", group.getName());
071:                assertEquals(3, group.members().length);
072:
073:                // Group Literature has 2 members
074:                group = backendGroup("Literature");
075:                assertEquals("Literature", group.getName());
076:                assertEquals(2, group.members().length);
077:
078:                // Group Art has no members
079:                group = backendGroup("Art");
080:                assertEquals("Art", group.getName());
081:                assertEquals(0, group.members().length);
082:
083:                // Group Admin has 1 member (Administrator)
084:                group = backendGroup("Admin");
085:                assertEquals("Admin", group.getName());
086:                assertEquals(1, group.members().length);
087:                assertEquals("Administrator", group.members()[0].getName());
088:
089:                // Group Archaeology doesn't exist
090:                try {
091:                    group = backendGroup("Archaeology");
092:                    // We should never get here
093:                    assertTrue(false);
094:                } catch (NoSuchPrincipalException e) {
095:                    assertTrue(true);
096:                }
097:            }
098:
099:            public void testSave() throws Exception {
100:                // Create a new group with random name
101:                String name = "TestGroup"
102:                        + String.valueOf(System.currentTimeMillis());
103:                Group group = new Group(name, m_wiki);
104:                Principal al = new WikiPrincipal("Al");
105:                Principal bob = new WikiPrincipal("Bob");
106:                Principal cookie = new WikiPrincipal("Cookie");
107:                group.add(al);
108:                group.add(bob);
109:                group.add(cookie);
110:                m_db.save(group, new WikiPrincipal("Tester"));
111:
112:                // Make sure the profile saved successfully
113:                group = backendGroup(name);
114:                assertEquals(name, group.getName());
115:                assertEquals(3, group.members().length);
116:                assertTrue(group.isMember(new WikiPrincipal("Al")));
117:                assertTrue(group.isMember(new WikiPrincipal("Bob")));
118:                assertTrue(group.isMember(new WikiPrincipal("Cookie")));
119:
120:                // The back-end should have timestamped the create/modify fields
121:                assertNotNull(group.getCreator());
122:                assertEquals("Tester", group.getCreator());
123:                assertNotNull(group.getCreated());
124:                assertNotNull(group.getModifier());
125:                assertEquals("Tester", group.getModifier());
126:                assertNotNull(group.getLastModified());
127:                assertNotSame(group.getCreated(), group.getLastModified());
128:
129:                // Remove the group
130:                m_db.delete(group);
131:            }
132:
133:            public void testResave() throws Exception {
134:                // Create a new group with random name & 3 members
135:                String name = "TestGroup"
136:                        + String.valueOf(System.currentTimeMillis());
137:                Group group = new Group(name, m_wiki);
138:                Principal al = new WikiPrincipal("Al");
139:                Principal bob = new WikiPrincipal("Bob");
140:                Principal cookie = new WikiPrincipal("Cookie");
141:                group.add(al);
142:                group.add(bob);
143:                group.add(cookie);
144:                m_db.save(group, new WikiPrincipal("Tester"));
145:
146:                // Make sure the profile saved successfully
147:                group = backendGroup(name);
148:                assertEquals(name, group.getName());
149:
150:                // Modify the members by adding the group; re-add Al while we're at it
151:                Principal dave = new WikiPrincipal("Dave");
152:                group.add(al);
153:                group.add(dave);
154:                m_db.save(group, new WikiPrincipal("SecondTester"));
155:
156:                // We should see 4 members and new timestamp info
157:                Principal[] members = group.members();
158:                assertEquals(4, members.length);
159:                assertNotNull(group.getCreator());
160:                assertEquals("Tester", group.getCreator());
161:                assertNotNull(group.getCreated());
162:                assertNotNull(group.getModifier());
163:                assertEquals("SecondTester", group.getModifier());
164:                assertNotNull(group.getLastModified());
165:
166:                // Check the back-end; We should see the same thing
167:                group = backendGroup(name);
168:                members = group.members();
169:                assertEquals(4, members.length);
170:                assertNotNull(group.getCreator());
171:                assertEquals("Tester", group.getCreator());
172:                assertNotNull(group.getCreated());
173:                assertNotNull(group.getModifier());
174:                assertEquals("SecondTester", group.getModifier());
175:                assertNotNull(group.getLastModified());
176:
177:                // Remove the group
178:                m_db.delete(group);
179:            }
180:
181:            private Group backendGroup(String name)
182:                    throws WikiSecurityException {
183:                Group[] groups = m_db.groups();
184:                for (int i = 0; i < groups.length; i++) {
185:                    Group group = groups[i];
186:                    if (group.getName().equals(name)) {
187:                        return group;
188:                    }
189:                }
190:                throw new NoSuchPrincipalException("No group named " + name);
191:            }
192:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.