Source Code Cross Referenced for SectionSortTest.java in  » ERP-CRM-Financial » sakai » org » sakaiproject » test » section » 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 » ERP CRM Financial » sakai » org.sakaiproject.test.section 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**********************************************************************************
002:         * $URL: https://source.sakaiproject.org/svn/sections/tags/sakai_2-4-1/sections-app/src/test/org/sakaiproject/test/section/SectionSortTest.java $
003:         * $Id: SectionSortTest.java 20161 2007-01-08 19:20:34Z jholtzman@berkeley.edu $
004:         ***********************************************************************************
005:         *
006:         * Copyright (c) 2005, 2006 The Regents of the University of California and The Regents of the University of Michigan
007:         * 
008:         * Licensed under the Educational Community License, Version 1.0 (the "License"); 
009:         * you may not use this file except in compliance with the License. 
010:         * You may obtain a copy of the License at
011:         * 
012:         *      http://www.opensource.org/licenses/ecl1.php
013:         * 
014:         * Unless required by applicable law or agreed to in writing, software 
015:         * distributed under the License is distributed on an "AS IS" BASIS, 
016:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
017:         * See the License for the specific language governing permissions and 
018:         * limitations under the License.
019:         *
020:         **********************************************************************************/package org.sakaiproject.test.section;
021:
022:        import java.sql.Time;
023:        import java.util.ArrayList;
024:        import java.util.Calendar;
025:        import java.util.Collections;
026:        import java.util.Comparator;
027:        import java.util.GregorianCalendar;
028:        import java.util.List;
029:
030:        import junit.framework.Assert;
031:        import junit.framework.TestCase;
032:
033:        import org.sakaiproject.section.api.coursemanagement.CourseSection;
034:        import org.sakaiproject.component.section.CourseImpl;
035:        import org.sakaiproject.component.section.CourseSectionImpl;
036:        import org.sakaiproject.tool.section.decorator.SectionDecorator;
037:
038:        public class SectionSortTest extends TestCase {
039:            private CourseSection sectionA;
040:            private CourseSection sectionB;
041:
042:            private CourseSection sectionC;
043:            private CourseSection sectionD;
044:
045:            private CourseSection sectionE;
046:            private CourseSection sectionF;
047:
048:            private List<String> instructorsA;
049:            private List<String> instructorsB;
050:
051:            private List<String> categoryNames;
052:            private List<String> categoryIds;
053:
054:            protected void setUp() throws Exception {
055:                categoryNames = new ArrayList<String>();
056:                categoryNames.add("Category A");
057:                categoryNames.add("Category B");
058:
059:                categoryIds = new ArrayList<String>();
060:                categoryIds.add("a category");
061:                categoryIds.add("b category");
062:
063:                CourseImpl course = new CourseImpl();
064:                course.setUuid("course 1 uuid");
065:                course.setTitle("course 1 title");
066:
067:                Calendar startCal = new GregorianCalendar();
068:                startCal.set(Calendar.HOUR_OF_DAY, 8);
069:
070:                Calendar endCal = new GregorianCalendar();
071:                endCal.set(Calendar.HOUR_OF_DAY, 9);
072:
073:                sectionA = new CourseSectionImpl(course, "a section",
074:                        "a section uuid", "a category", new Integer(10),
075:                        "a section location", new Time(startCal
076:                                .getTimeInMillis()), new Time(endCal
077:                                .getTimeInMillis()), true, true, false, false,
078:                        false, false, false);
079:
080:                startCal.set(Calendar.HOUR_OF_DAY, 9);
081:                endCal.set(Calendar.HOUR_OF_DAY, 10);
082:
083:                sectionB = new CourseSectionImpl(course, "B section",
084:                        "b section uuid", "a category", new Integer(20),
085:                        "b section location", new Time(startCal
086:                                .getTimeInMillis()), new Time(endCal
087:                                .getTimeInMillis()), false, true, false, false,
088:                        false, false, false);
089:
090:                startCal.set(Calendar.HOUR_OF_DAY, 10);
091:                endCal.set(Calendar.HOUR_OF_DAY, 11);
092:
093:                sectionC = new CourseSectionImpl(course, "c section",
094:                        "c section uuid", "b category", new Integer(5),
095:                        "c section location", new Time(startCal
096:                                .getTimeInMillis()), new Time(endCal
097:                                .getTimeInMillis()), false, true, false, false,
098:                        false, false, false);
099:
100:                startCal.set(Calendar.HOUR_OF_DAY, 11);
101:                endCal.set(Calendar.HOUR_OF_DAY, 12);
102:
103:                sectionD = new CourseSectionImpl(course, "D section",
104:                        "d section uuid", "b category", new Integer(15),
105:                        "d section location", new Time(startCal
106:                                .getTimeInMillis()), new Time(endCal
107:                                .getTimeInMillis()), false, false, true, true,
108:                        false, false, false);
109:
110:                startCal.set(Calendar.HOUR_OF_DAY, 12);
111:                endCal.set(Calendar.HOUR_OF_DAY, 13);
112:
113:                sectionE = new CourseSectionImpl(course, "E section",
114:                        "e section uuid", "b category", new Integer(15),
115:                        "e section location", new Time(startCal
116:                                .getTimeInMillis()), new Time(endCal
117:                                .getTimeInMillis()), false, false, false, true,
118:                        true, false, false);
119:
120:                // Keep these times the same as sectionE
121:
122:                sectionF = new CourseSectionImpl(course, "F section",
123:                        "f section uuid", "b category", new Integer(15),
124:                        "f section location", new Time(startCal
125:                                .getTimeInMillis()), new Time(endCal
126:                                .getTimeInMillis()), false, false, false,
127:                        false, true, true, true);
128:
129:                instructorsA = new ArrayList<String>();
130:                instructorsA.add("Schmoe, Joe");
131:                instructorsA.add("Adams, Sally");
132:
133:                instructorsB = new ArrayList<String>();
134:                instructorsA.add("Schmoe, Joe");
135:            }
136:
137:            public void testSectionDecoratorSorting() throws Exception {
138:                SectionDecorator secA = new SectionDecorator(sectionA,
139:                        "Category A", instructorsA, 10, true);
140:                SectionDecorator secB = new SectionDecorator(sectionB,
141:                        "Category A", instructorsB, 20, true);
142:                SectionDecorator secC = new SectionDecorator(sectionC,
143:                        "Category B", new ArrayList<String>(), 10, true);
144:                SectionDecorator secD = new SectionDecorator(sectionD,
145:                        "Category B", new ArrayList<String>(), 20, true);
146:                SectionDecorator secE = new SectionDecorator(sectionE,
147:                        "Category B", new ArrayList<String>(), 20, true);
148:                SectionDecorator secF = new SectionDecorator(sectionF,
149:                        "Category B", new ArrayList<String>(), 20, true);
150:
151:                Comparator<SectionDecorator> mgrComp = SectionDecorator
152:                        .getManagersComparator(true);
153:
154:                // Compare managers in sections of the same category
155:                Assert.assertTrue(mgrComp.compare(secA, secB) > 0);
156:                Assert.assertTrue(mgrComp.compare(secC, secD) < 0); // Using the title, since managers are equal
157:
158:                // Compare managers in sections in different categories.  The one with no managers sorts first
159:                Assert.assertTrue(mgrComp.compare(secC, secA) > 0);
160:
161:                mgrComp = SectionDecorator
162:                        .getEnrollmentsComparator(true, false);
163:
164:                // Compare the max enrollments in sections of the same category
165:                Assert.assertTrue(mgrComp.compare(secB, secA) > 0);
166:
167:                // Compare the max enrollments in different categories
168:                Assert.assertTrue(mgrComp.compare(secB, secC) < 0);
169:
170:                // Compare the days in a meeting.
171:                Comparator<SectionDecorator> dayComp = SectionDecorator
172:                        .getDayComparator(true);
173:
174:                Assert.assertTrue(dayComp.compare(secA, secB) < 0);
175:                Assert.assertTrue(dayComp.compare(secC, secD) < 0);
176:                Assert.assertTrue(dayComp.compare(secD, secE) < 0);
177:                Assert.assertTrue(dayComp.compare(secE, secF) < 0);
178:
179:                // Compare the times in meetings
180:                Comparator<SectionDecorator> timeComp = SectionDecorator
181:                        .getTimeComparator(true);
182:
183:                Assert.assertTrue(timeComp.compare(secA, secB) < 0);
184:                Assert.assertTrue(timeComp.compare(secA, secC) < 0);
185:                Assert.assertTrue(timeComp.compare(secA, secD) < 0);
186:                Assert.assertTrue(timeComp.compare(secA, secE) < 0);
187:                Assert.assertTrue(timeComp.compare(secA, secF) < 0);
188:
189:                Assert.assertTrue(timeComp.compare(secB, secA) > 0);
190:                Assert.assertTrue(timeComp.compare(secB, secC) < 0);
191:                Assert.assertTrue(timeComp.compare(secB, secD) < 0);
192:                Assert.assertTrue(timeComp.compare(secB, secE) < 0);
193:                Assert.assertTrue(timeComp.compare(secB, secF) < 0);
194:
195:                Assert.assertTrue(timeComp.compare(secC, secA) > 0);
196:                Assert.assertTrue(timeComp.compare(secC, secB) > 0);
197:                Assert.assertTrue(timeComp.compare(secC, secD) < 0);
198:                Assert.assertTrue(timeComp.compare(secC, secE) < 0);
199:                Assert.assertTrue(timeComp.compare(secC, secF) < 0);
200:
201:                Assert.assertTrue(timeComp.compare(secD, secE) < 0);
202:                Assert.assertTrue(timeComp.compare(secE, secF) < 0); // Even though the times and categories are equal, the titles should sort e before f
203:
204:                // Sort a list and ensure that it's in the correct order.
205:                List<SectionDecorator> list = new ArrayList<SectionDecorator>();
206:                list.add(secA);
207:                list.add(secB);
208:                list.add(secC);
209:                list.add(secD);
210:                list.add(secE);
211:                list.add(secF);
212:                Collections.sort(list, timeComp);
213:                Assert.assertEquals(0, list.indexOf(secA));
214:                Assert.assertEquals(1, list.indexOf(secB));
215:                Assert.assertEquals(2, list.indexOf(secC));
216:                Assert.assertEquals(3, list.indexOf(secD));
217:                Assert.assertEquals(4, list.indexOf(secE));
218:                Assert.assertEquals(5, list.indexOf(secF));
219:            }
220:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.