Source Code Cross Referenced for AbstractUserTest.java in  » Net » DrFTPD » org » drftpd » usermanager » 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 » Net » DrFTPD » org.drftpd.usermanager 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * This file is part of DrFTPD, Distributed FTP Daemon.
003:         *
004:         * DrFTPD is free software; you can redistribute it and/or modify
005:         * it under the terms of the GNU General Public License as published by
006:         * the Free Software Foundation; either version 2 of the License, or
007:         * (at your option) any later version.
008:         *
009:         * DrFTPD is distributed in the hope that it will be useful,
010:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
011:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
012:         * GNU General Public License for more details.
013:         *
014:         * You should have received a copy of the GNU General Public License
015:         * along with DrFTPD; if not, write to the Free Software
016:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
017:         */
018:        package org.drftpd.usermanager;
019:
020:        import junit.framework.TestCase;
021:
022:        import net.sf.drftpd.event.Event;
023:        import net.sf.drftpd.event.UserEvent;
024:        import net.sf.drftpd.util.CalendarUtils;
025:
026:        import org.apache.log4j.BasicConfigurator;
027:        import org.apache.log4j.Logger;
028:
029:        import org.drftpd.tests.DummyGlobalContext;
030:        import org.drftpd.tests.DummyUser;
031:
032:        import java.util.ArrayList;
033:        import java.util.Arrays;
034:        import java.util.Calendar;
035:        import java.util.Date;
036:        import java.util.Iterator;
037:        import java.util.List;
038:
039:        /**
040:         * @author mog
041:         * @version $Id: AbstractUserTest.java 1013 2005-02-15 03:12:11Z zubov $
042:         */
043:        public class AbstractUserTest extends TestCase {
044:            private static final Logger logger = Logger
045:                    .getLogger(AbstractUserTest.class);
046:
047:            /**
048:             * Mon Dec 15 23:59:59 CET 2003
049:             */
050:            private static final long RESETTIME = 1071519356421L;
051:            private GCtx _gctx;
052:            private Calendar _resetCal;
053:            private DummyUser _user;
054:
055:            public AbstractUserTest(String fName) {
056:                super (fName);
057:            }
058:
059:            private static void verifyEvents(ArrayList eventNames,
060:                    ArrayList events) {
061:                logger.debug(events);
062:                i1: for (Iterator i1 = events.iterator(); i1.hasNext();) {
063:                    UserEvent event1 = (UserEvent) i1.next();
064:                    String eventName2 = null;
065:
066:                    for (Iterator i2 = eventNames.iterator(); i2.hasNext();) {
067:                        eventName2 = (String) i2.next();
068:
069:                        if (event1.getCommand().equals(eventName2)) {
070:                            i2.remove();
071:
072:                            //if(eventNames.size() == 0) return;
073:                            continue i1;
074:                        }
075:                    }
076:
077:                    if (eventName2 == null) {
078:                        throw new RuntimeException(
079:                                "no eventNames to look for when looking for "
080:                                        + event1.getCommand());
081:                    }
082:
083:                    throw new RuntimeException(eventName2
084:                            + " was expected but wasn't found in " + events);
085:                }
086:
087:                if (eventNames.size() != 0) {
088:                    throw new RuntimeException("The events " + eventNames
089:                            + " were not in the list of expected events ("
090:                            + events + ")");
091:                }
092:            }
093:
094:            public void resetSetUp() {
095:                _gctx = new GCtx();
096:
097:                _user = new DummyUser("junit", null);
098:                _user.setLastReset(RESETTIME - 10000);
099:
100:                _resetCal = Calendar.getInstance();
101:                _resetCal.setTimeInMillis(RESETTIME);
102:            }
103:
104:            public void setUp() {
105:                BasicConfigurator.configure();
106:            }
107:
108:            public void testResetDay() throws UserFileException {
109:                resetSetUp();
110:                _resetCal.add(Calendar.DAY_OF_MONTH, 1);
111:                CalendarUtils.floorAllLessThanDay(_resetCal);
112:                logger.debug("resetDay lastreset "
113:                        + new Date(_user.getLastReset()));
114:                logger.debug("resetDay date " + _resetCal.getTime());
115:                _user.reset(_gctx, _resetCal);
116:                verifyEvents(new ArrayList<String>(Arrays
117:                        .asList(new String[] { "RESETDAY" })), _gctx.events);
118:            }
119:
120:            public void testResetMonth() throws UserFileException {
121:                resetSetUp();
122:                _resetCal.add(Calendar.MONTH, 1);
123:                CalendarUtils.floorDayOfMonth(_resetCal);
124:                CalendarUtils.floorAllLessThanDay(_resetCal);
125:                logger.debug("resetMonth lastreset "
126:                        + new Date(_user.getLastReset()));
127:                logger.debug("resetMonth date " + _resetCal.getTime());
128:                _user.reset(_gctx, _resetCal);
129:                verifyEvents(new ArrayList<String>(Arrays.asList(new String[] {
130:                        "RESETDAY", "RESETWEEK", "RESETMONTH" })), _gctx.events);
131:            }
132:
133:            public void testResetNone1() throws UserFileException {
134:                resetSetUp();
135:                CalendarUtils.ceilAllLessThanDay(_resetCal);
136:                _user.reset(_gctx, _resetCal);
137:            }
138:
139:            public void testResetNone2() throws UserFileException {
140:                resetSetUp();
141:                CalendarUtils.floorAllLessThanDay(_resetCal);
142:                _user.reset(_gctx, _resetCal);
143:            }
144:
145:            public void testResetWeek() throws UserFileException {
146:                resetSetUp();
147:                _resetCal.add(Calendar.WEEK_OF_MONTH, 1);
148:                CalendarUtils.floorDayOfWeek(_resetCal);
149:                CalendarUtils.floorAllLessThanDay(_resetCal);
150:                logger.debug("resetWeek lastreset "
151:                        + new Date(_user.getLastReset()));
152:                logger.debug("resetWeek date " + _resetCal.getTime());
153:                _user.reset(_gctx, _resetCal);
154:                verifyEvents(new ArrayList<String>(Arrays.asList(new String[] {
155:                        "RESETDAY", "RESETWEEK" })), _gctx.events);
156:            }
157:
158:            private static class GCtx extends DummyGlobalContext {
159:                public ArrayList<Event> events = new ArrayList<Event>();
160:
161:                public void dispatchFtpEvent(Event event) {
162:                    events.add(event);
163:                }
164:            }
165:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.