Source Code Cross Referenced for TestColumnLayout.java in  » Portal » jetspeed-2.1.3 » org » apache » jetspeed » portlets » layout » 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 » jetspeed 2.1.3 » org.apache.jetspeed.portlets.layout 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         * 
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         * 
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:        package org.apache.jetspeed.portlets.layout;
018:
019:        import java.util.Iterator;
020:
021:        import org.apache.jetspeed.om.page.Fragment;
022:        import org.apache.jetspeed.om.page.psml.FragmentImpl;
023:        import org.jmock.Mock;
024:        import org.jmock.MockObjectTestCase;
025:
026:        public class TestColumnLayout extends MockObjectTestCase {
027:            private static final String[] widths = new String[] { "25%", "50%",
028:                    "25%" };
029:
030:            private ColumnLayout layout;
031:
032:            private FragmentImpl f1;
033:
034:            private FragmentImpl f2;
035:
036:            private FragmentImpl f3;
037:
038:            private FragmentImpl f4;
039:
040:            private FragmentImpl f5;
041:
042:            private FragmentImpl f6;
043:
044:            private FragmentImpl f8;
045:
046:            public void testBasics() throws Exception {
047:                assertEquals(f1, layout.getFirstColumn().iterator().next());
048:
049:                // The last column is currently empty
050:                //  assertTrue(layout.getLastColumn().isEmpty());
051:
052:                assertEquals(3, layout.getNumberOfColumns());
053:                Iterator column0 = layout.getColumn(0).iterator();
054:                assertNotNull(column0);
055:                Iterator column1 = layout.getColumn(1).iterator();
056:                assertNotNull(column1);
057:                assertNotNull(layout.getColumn(2));
058:
059:                int idx = 0;
060:                while (column0.hasNext()) {
061:                    idx++;
062:                    Fragment fragment = (Fragment) column0.next();
063:                    assertEquals("f" + idx, fragment.getId());
064:                }
065:
066:                assertEquals(3, idx);
067:
068:                assertEquals(f4, column1.next());
069:                assertEquals(f5, column1.next());
070:                assertEquals(f6, column1.next());
071:
072:                Fragment testFragment = layout
073:                        .getFragmentAt(new LayoutCoordinate(0, 0));
074:                assertNotNull(testFragment);
075:                assertEquals(f1, testFragment);
076:
077:                testFragment = layout.getFragmentAt(new LayoutCoordinate(0, 1));
078:                assertNotNull(testFragment);
079:                assertEquals(f2, testFragment);
080:
081:                testFragment = layout.getFragmentAt(1, 0);
082:                assertNotNull(testFragment);
083:                assertEquals(f4, testFragment);
084:
085:                assertEquals(3, layout.getColumns().size());
086:
087:                assertEquals(2, layout.getLastRowNumber(0));
088:                assertEquals(2, layout.getLastRowNumber(1));
089:
090:                // test widths
091:                assertEquals("25%", layout.getColumnWidth(0));
092:                assertEquals("50%", layout.getColumnWidth(1));
093:                assertEquals("24.99%", layout.getColumnWidth(2));
094:                assertEquals("0", layout.getColumnWidth(3));
095:
096:                assertEquals("left", layout.getColumnFloat(0));
097:                assertEquals("left", layout.getColumnFloat(1));
098:                assertEquals("right", layout.getColumnFloat(2));
099:                assertEquals("none", layout.getColumnFloat(3));
100:            }
101:
102:            public void testSameRowSameColumn() throws Exception {
103:                FragmentImpl f1 = new FragmentImpl();
104:                f1.setId("f1");
105:                f1.setName("test");
106:                f1.setLayoutRow(0);
107:                f1.setLayoutColumn(0);
108:
109:                FragmentImpl f2 = new FragmentImpl();
110:                f2.setId("f2");
111:                f2.setName("test");
112:                f2.setLayoutRow(0);
113:                f2.setLayoutColumn(0);
114:
115:                ColumnLayout layout = new ColumnLayout(3, "test", null);
116:                layout.addFragment(f1);
117:                layout.addFragment(f2);
118:
119:                Iterator column0 = layout.getColumn(0).iterator();
120:                // all subsequent fragments that go into the same row will push
121:                // the existing fragment down.
122:                assertEquals(f2, column0.next());
123:                assertEquals(f1, column0.next());
124:
125:                Fragment testFragment = layout.getFragmentAt(0, 1);
126:                assertNotNull(testFragment);
127:                assertEquals(f1, testFragment);
128:
129:                testFragment = layout.getFragmentAt(0, 0);
130:                assertNotNull(testFragment);
131:                assertEquals(f2, testFragment);
132:
133:            }
134:
135:            public void testColumnNotSet() throws Exception {
136:                FragmentImpl f1 = new FragmentImpl();
137:                f1.setId("f1");
138:                f1.setName("test");
139:                f1.setLayoutRow(0);
140:                f1.setLayoutColumn(0);
141:
142:                FragmentImpl f2 = new FragmentImpl();
143:                f2.setId("f2");
144:                f2.setName("test");
145:                f2.setLayoutRow(0);
146:
147:                ColumnLayout layout = new ColumnLayout(3, "test", null);
148:                layout.addFragment(f1);
149:                layout.addFragment(f2);
150:
151:                Fragment testFragment = layout.getFragmentAt(0, 0);
152:                assertNotNull(testFragment);
153:                assertEquals(f1, testFragment);
154:
155:                testFragment = layout.getFragmentAt(2, 0);
156:                assertNotNull(testFragment);
157:                assertEquals(f2, testFragment);
158:
159:                assertNotNull(layout.getFirstColumn());
160:                assertNotNull(layout.getLastColumn());
161:            }
162:
163:            public void testRowNotSet() throws Exception {
164:                FragmentImpl f1 = new FragmentImpl();
165:                f1.setId("f1");
166:                f1.setName("test");
167:                f1.setLayoutRow(0);
168:                f1.setLayoutColumn(0);
169:
170:                FragmentImpl f2 = new FragmentImpl();
171:                f2.setId("f2");
172:                f2.setName("test");
173:                f2.setLayoutColumn(0);
174:
175:                ColumnLayout layout = new ColumnLayout(3, "test", null);
176:                layout.addFragment(f1);
177:                layout.addFragment(f2);
178:
179:                Fragment testFragment = layout.getFragmentAt(0, 0);
180:                assertNotNull(testFragment);
181:                assertEquals(f1, testFragment);
182:
183:                testFragment = layout.getFragmentAt(0, 1);
184:                assertNotNull(testFragment);
185:                assertEquals(f2, testFragment);
186:            }
187:
188:            public void testColumnLimitExceeded() throws Exception {
189:                FragmentImpl f1 = new FragmentImpl();
190:                f1.setId("f1");
191:                f1.setLayoutRow(0);
192:                f1.setLayoutColumn(5);
193:
194:                ColumnLayout layout = new ColumnLayout(3, "test", null);
195:                layout.addFragment(f1);
196:
197:                // Exceeded columns just get dumped into the last column
198:                Fragment testFragment = layout.getFragmentAt(2, 0);
199:                assertNotNull(testFragment);
200:                assertEquals(f1, testFragment);
201:            }
202:
203:            public void testMovingRight() throws Exception {
204:
205:                Fragment movingFragment = layout
206:                        .getFragmentAt(new LayoutCoordinate(0, 0));
207:                assertEquals(f1, movingFragment);
208:                assertEquals(f4, layout
209:                        .getFragmentAt(new LayoutCoordinate(1, 0)));
210:
211:                Mock listenerMock = mock(LayoutEventListener.class);
212:                layout
213:                        .addLayoutEventListener((LayoutEventListener) listenerMock
214:                                .proxy());
215:                listenerMock.expects(once()).method("handleEvent").with(
216:                        eq(createEvent(f1, layout, LayoutEvent.MOVED_RIGHT)));
217:                listenerMock.expects(once()).method("handleEvent").with(
218:                        eq(createEvent(f2, layout, LayoutEvent.MOVED_UP)));
219:                listenerMock.expects(once()).method("handleEvent").with(
220:                        eq(createEvent(f3, layout, LayoutEvent.MOVED_UP)));
221:                listenerMock.expects(once()).method("handleEvent").with(
222:                        eq(createEvent(f4, layout, LayoutEvent.MOVED_DOWN)));
223:                listenerMock.expects(once()).method("handleEvent").with(
224:                        eq(createEvent(f5, layout, LayoutEvent.MOVED_DOWN)));
225:                listenerMock.expects(once()).method("handleEvent").with(
226:                        eq(createEvent(f6, layout, LayoutEvent.MOVED_DOWN)));
227:
228:                // moving right
229:                layout.moveRight(movingFragment);
230:
231:                assertEquals(f1, layout
232:                        .getFragmentAt(new LayoutCoordinate(1, 0)));
233:                assertEquals(f2, layout
234:                        .getFragmentAt(new LayoutCoordinate(0, 0)));
235:                assertEquals(f3, layout
236:                        .getFragmentAt(new LayoutCoordinate(0, 1)));
237:                assertEquals(f4, layout
238:                        .getFragmentAt(new LayoutCoordinate(1, 1)));
239:                assertEquals(f5, layout
240:                        .getFragmentAt(new LayoutCoordinate(1, 2)));
241:                assertEquals(f6, layout
242:                        .getFragmentAt(new LayoutCoordinate(1, 3)));
243:            }
244:
245:            public void testMovingLeft() throws Exception {
246:                Fragment movingFragment = layout
247:                        .getFragmentAt(new LayoutCoordinate(1, 0));
248:                assertEquals(f4, movingFragment);
249:                assertEquals(f1, layout
250:                        .getFragmentAt(new LayoutCoordinate(0, 0)));
251:
252:                Mock listenerMock = mock(LayoutEventListener.class);
253:                layout
254:                        .addLayoutEventListener((LayoutEventListener) listenerMock
255:                                .proxy());
256:                listenerMock.expects(once()).method("handleEvent").with(
257:                        eq(createEvent(f4, layout, LayoutEvent.MOVED_LEFT)));
258:                listenerMock.expects(once()).method("handleEvent").with(
259:                        eq(createEvent(f5, layout, LayoutEvent.MOVED_UP)));
260:                listenerMock.expects(once()).method("handleEvent").with(
261:                        eq(createEvent(f6, layout, LayoutEvent.MOVED_UP)));
262:                listenerMock.expects(once()).method("handleEvent").with(
263:                        eq(createEvent(f1, layout, LayoutEvent.MOVED_DOWN)));
264:                listenerMock.expects(once()).method("handleEvent").with(
265:                        eq(createEvent(f2, layout, LayoutEvent.MOVED_DOWN)));
266:                listenerMock.expects(once()).method("handleEvent").with(
267:                        eq(createEvent(f3, layout, LayoutEvent.MOVED_DOWN)));
268:
269:                layout.moveLeft(f4);
270:
271:                assertEquals(f1, layout
272:                        .getFragmentAt(new LayoutCoordinate(0, 1)));
273:                assertEquals(f2, layout
274:                        .getFragmentAt(new LayoutCoordinate(0, 2)));
275:                assertEquals(f3, layout
276:                        .getFragmentAt(new LayoutCoordinate(0, 3)));
277:                assertEquals(f4, layout
278:                        .getFragmentAt(new LayoutCoordinate(0, 0)));
279:                assertEquals(f5, layout
280:                        .getFragmentAt(new LayoutCoordinate(1, 0)));
281:                assertEquals(f6, layout
282:                        .getFragmentAt(new LayoutCoordinate(1, 1)));
283:
284:                listenerMock.reset();
285:                listenerMock.expects(once()).method("handleEvent").with(
286:                        eq(createEvent(f6, layout, LayoutEvent.MOVED_LEFT)));
287:                listenerMock.expects(once()).method("handleEvent").with(
288:                        eq(createEvent(f1, layout, LayoutEvent.MOVED_DOWN)));
289:                listenerMock.expects(once()).method("handleEvent").with(
290:                        eq(createEvent(f2, layout, LayoutEvent.MOVED_DOWN)));
291:                listenerMock.expects(once()).method("handleEvent").with(
292:                        eq(createEvent(f3, layout, LayoutEvent.MOVED_DOWN)));
293:
294:                layout.moveLeft(f6);
295:
296:                assertEquals(f1, layout
297:                        .getFragmentAt(new LayoutCoordinate(0, 2)));
298:                assertEquals(f2, layout
299:                        .getFragmentAt(new LayoutCoordinate(0, 3)));
300:                assertEquals(f3, layout
301:                        .getFragmentAt(new LayoutCoordinate(0, 4)));
302:                assertEquals(f4, layout
303:                        .getFragmentAt(new LayoutCoordinate(0, 0)));
304:                assertEquals(f5, layout
305:                        .getFragmentAt(new LayoutCoordinate(1, 0)));
306:                assertEquals(f6, layout
307:                        .getFragmentAt(new LayoutCoordinate(0, 1)));
308:
309:                listenerMock.reset();
310:                listenerMock.expects(once()).method("handleEvent").with(
311:                        eq(createEvent(f5, layout, LayoutEvent.MOVED_LEFT)));
312:                listenerMock.expects(once()).method("handleEvent").with(
313:                        eq(createEvent(f4, layout, LayoutEvent.MOVED_DOWN)));
314:                listenerMock.expects(once()).method("handleEvent").with(
315:                        eq(createEvent(f6, layout, LayoutEvent.MOVED_DOWN)));
316:                listenerMock.expects(once()).method("handleEvent").with(
317:                        eq(createEvent(f1, layout, LayoutEvent.MOVED_DOWN)));
318:                listenerMock.expects(once()).method("handleEvent").with(
319:                        eq(createEvent(f2, layout, LayoutEvent.MOVED_DOWN)));
320:                listenerMock.expects(once()).method("handleEvent").with(
321:                        eq(createEvent(f3, layout, LayoutEvent.MOVED_DOWN)));
322:
323:                layout.moveLeft(f5);
324:
325:                assertEquals(f1, layout
326:                        .getFragmentAt(new LayoutCoordinate(0, 3)));
327:                assertEquals(f2, layout
328:                        .getFragmentAt(new LayoutCoordinate(0, 4)));
329:                assertEquals(f3, layout
330:                        .getFragmentAt(new LayoutCoordinate(0, 5)));
331:                assertEquals(f4, layout
332:                        .getFragmentAt(new LayoutCoordinate(0, 1)));
333:                assertEquals(f5, layout
334:                        .getFragmentAt(new LayoutCoordinate(0, 0)));
335:                assertEquals(f6, layout
336:                        .getFragmentAt(new LayoutCoordinate(0, 2)));
337:
338:                // This is a test to make sure the next row pointer is being decremented
339:                // correctly
340:                FragmentImpl f7 = new FragmentImpl();
341:                f7.setId("f7");
342:                f7.setName("test");
343:                f7.setLayoutRow(0);
344:                f7.setLayoutColumn(1);
345:
346:                listenerMock.reset();
347:                LayoutCoordinate coordinate = new LayoutCoordinate(1, 0);
348:                LayoutEvent event = new LayoutEvent(LayoutEvent.ADDED, f7,
349:                        coordinate, coordinate);
350:                listenerMock.expects(once()).method("handleEvent").with(
351:                        eq(event));
352:
353:                layout.addFragment(f7);
354:
355:                assertEquals(f1, layout
356:                        .getFragmentAt(new LayoutCoordinate(0, 3)));
357:                assertEquals(f2, layout
358:                        .getFragmentAt(new LayoutCoordinate(0, 4)));
359:                assertEquals(f3, layout
360:                        .getFragmentAt(new LayoutCoordinate(0, 5)));
361:                assertEquals(f4, layout
362:                        .getFragmentAt(new LayoutCoordinate(0, 1)));
363:                assertEquals(f5, layout
364:                        .getFragmentAt(new LayoutCoordinate(0, 0)));
365:                assertEquals(f6, layout
366:                        .getFragmentAt(new LayoutCoordinate(0, 2)));
367:                assertEquals(f7, layout
368:                        .getFragmentAt(new LayoutCoordinate(1, 0)));
369:
370:                // test that column consistency is maitained
371:                Iterator itr1 = layout.getColumn(1).iterator();
372:
373:                itr1.next().equals(f7);
374:
375:                Iterator itr0 = layout.getColumn(0).iterator();
376:
377:                itr0.next().equals(f5);
378:                itr0.next().equals(f4);
379:                itr0.next().equals(f6);
380:                itr0.next().equals(f1);
381:                itr0.next().equals(f2);
382:                itr0.next().equals(f3);
383:            }
384:
385:            public void testInvalidOperations() throws Exception {
386:                // Create a mock that veridies events are NOT being fired on invalid operations
387:                Mock listenerMock = mock(LayoutEventListener.class);
388:                layout
389:                        .addLayoutEventListener((LayoutEventListener) listenerMock
390:                                .proxy());
391:                listenerMock.expects(never()).method("handleEvent")
392:                        .withAnyArguments();
393:
394:                layout.moveUp(f1); // Nothing at all should happen, not even exceptions
395:
396:                assertEquals(f1, layout
397:                        .getFragmentAt(new LayoutCoordinate(0, 0)));
398:                assertEquals(f2, layout
399:                        .getFragmentAt(new LayoutCoordinate(0, 1)));
400:                assertEquals(f3, layout
401:                        .getFragmentAt(new LayoutCoordinate(0, 2)));
402:                assertEquals(f4, layout
403:                        .getFragmentAt(new LayoutCoordinate(1, 0)));
404:                assertEquals(f5, layout
405:                        .getFragmentAt(new LayoutCoordinate(1, 1)));
406:                assertEquals(f6, layout
407:                        .getFragmentAt(new LayoutCoordinate(1, 2)));
408:
409:                layout.moveDown(f3); // Nothing at all should happen, not even
410:                // exceptions
411:
412:                assertEquals(f1, layout
413:                        .getFragmentAt(new LayoutCoordinate(0, 0)));
414:                assertEquals(f2, layout
415:                        .getFragmentAt(new LayoutCoordinate(0, 1)));
416:                assertEquals(f3, layout
417:                        .getFragmentAt(new LayoutCoordinate(0, 2)));
418:                assertEquals(f4, layout
419:                        .getFragmentAt(new LayoutCoordinate(1, 0)));
420:                assertEquals(f5, layout
421:                        .getFragmentAt(new LayoutCoordinate(1, 1)));
422:                assertEquals(f6, layout
423:                        .getFragmentAt(new LayoutCoordinate(1, 2)));
424:
425:                layout.moveLeft(f1); // Nothing at all should happen, not even
426:                // exceptions
427:
428:                assertEquals(f1, layout
429:                        .getFragmentAt(new LayoutCoordinate(0, 0)));
430:                assertEquals(f2, layout
431:                        .getFragmentAt(new LayoutCoordinate(0, 1)));
432:                assertEquals(f3, layout
433:                        .getFragmentAt(new LayoutCoordinate(0, 2)));
434:                assertEquals(f4, layout
435:                        .getFragmentAt(new LayoutCoordinate(1, 0)));
436:                assertEquals(f5, layout
437:                        .getFragmentAt(new LayoutCoordinate(1, 1)));
438:                assertEquals(f6, layout
439:                        .getFragmentAt(new LayoutCoordinate(1, 2)));
440:            }
441:
442:            public void testMoveDown() throws Exception {
443:                Mock listenerMock = mock(LayoutEventListener.class);
444:                layout
445:                        .addLayoutEventListener((LayoutEventListener) listenerMock
446:                                .proxy());
447:                listenerMock.expects(once()).method("handleEvent").with(
448:                        eq(createEvent(f1, layout, LayoutEvent.MOVED_DOWN)));
449:                listenerMock.expects(once()).method("handleEvent").with(
450:                        eq(createEvent(f2, layout, LayoutEvent.MOVED_UP)));
451:
452:                layout.moveDown(f1);
453:
454:                assertEquals(f1, layout
455:                        .getFragmentAt(new LayoutCoordinate(0, 1)));
456:                assertEquals(f2, layout
457:                        .getFragmentAt(new LayoutCoordinate(0, 0)));
458:                assertEquals(f3, layout
459:                        .getFragmentAt(new LayoutCoordinate(0, 2)));
460:                assertEquals(f4, layout
461:                        .getFragmentAt(new LayoutCoordinate(1, 0)));
462:                assertEquals(f5, layout
463:                        .getFragmentAt(new LayoutCoordinate(1, 1)));
464:                assertEquals(f6, layout
465:                        .getFragmentAt(new LayoutCoordinate(1, 2)));
466:
467:                listenerMock.expects(once()).method("handleEvent").with(
468:                        eq(createEvent(f1, layout, LayoutEvent.MOVED_DOWN)));
469:                listenerMock.expects(once()).method("handleEvent").with(
470:                        eq(createEvent(f3, layout, LayoutEvent.MOVED_UP)));
471:
472:                layout.moveDown(f1);
473:
474:                assertEquals(f1, layout
475:                        .getFragmentAt(new LayoutCoordinate(0, 2)));
476:                assertEquals(f2, layout
477:                        .getFragmentAt(new LayoutCoordinate(0, 0)));
478:                assertEquals(f3, layout
479:                        .getFragmentAt(new LayoutCoordinate(0, 1)));
480:                assertEquals(f4, layout
481:                        .getFragmentAt(new LayoutCoordinate(1, 0)));
482:                assertEquals(f5, layout
483:                        .getFragmentAt(new LayoutCoordinate(1, 1)));
484:                assertEquals(f6, layout
485:                        .getFragmentAt(new LayoutCoordinate(1, 2)));
486:
487:                //try moving a fragment below the bottom-most row.
488:                listenerMock.expects(never()).method("handleEvent")
489:                        .withAnyArguments();
490:                layout.moveDown(f6);
491:                assertEquals(f6, layout
492:                        .getFragmentAt(new LayoutCoordinate(1, 2)));
493:
494:            }
495:
496:            public void testMoveUp() throws Exception {
497:
498:                Mock listenerMock = mock(LayoutEventListener.class);
499:                layout
500:                        .addLayoutEventListener((LayoutEventListener) listenerMock
501:                                .proxy());
502:                listenerMock.expects(once()).method("handleEvent").with(
503:                        eq(createEvent(f3, layout, LayoutEvent.MOVED_UP)));
504:                listenerMock.expects(once()).method("handleEvent").with(
505:                        eq(createEvent(f2, layout, LayoutEvent.MOVED_DOWN)));
506:                layout.moveUp(f3);
507:
508:                assertEquals(f1, layout
509:                        .getFragmentAt(new LayoutCoordinate(0, 0)));
510:                assertEquals(f2, layout
511:                        .getFragmentAt(new LayoutCoordinate(0, 2)));
512:                assertEquals(f3, layout
513:                        .getFragmentAt(new LayoutCoordinate(0, 1)));
514:                assertEquals(f4, layout
515:                        .getFragmentAt(new LayoutCoordinate(1, 0)));
516:                assertEquals(f5, layout
517:                        .getFragmentAt(new LayoutCoordinate(1, 1)));
518:                assertEquals(f6, layout
519:                        .getFragmentAt(new LayoutCoordinate(1, 2)));
520:            }
521:
522:            protected void setUp() throws Exception {
523:                f1 = new FragmentImpl();
524:                f1.setId("f1");
525:                f1.setName("test");
526:                f1.setLayoutRow(0);
527:                f1.setLayoutColumn(0);
528:
529:                f2 = new FragmentImpl();
530:                f2.setId("f2");
531:                f2.setName("test");
532:                f2.setLayoutRow(1);
533:                f2.setLayoutColumn(0);
534:
535:                f3 = new FragmentImpl();
536:                f3.setId("f3");
537:                f3.setName("test");
538:                f3.setLayoutRow(2);
539:                f3.setLayoutColumn(0);
540:
541:                f4 = new FragmentImpl();
542:                f4.setId("f4");
543:                f4.setName("test");
544:                f4.setLayoutRow(0);
545:                f4.setLayoutColumn(1);
546:
547:                f5 = new FragmentImpl();
548:                f5.setId("f5");
549:                f5.setName("test");
550:                f5.setLayoutRow(1);
551:                f5.setLayoutColumn(1);
552:
553:                f6 = new FragmentImpl();
554:                f6.setId("f6");
555:                f6.setName("test");
556:                f6.setLayoutRow(2);
557:                f6.setLayoutColumn(1);
558:
559:                f8 = new FragmentImpl();
560:                f8.setId("f8");
561:                f8.setName("test");
562:                f8.setLayoutRow(1);
563:                f8.setLayoutColumn(2);
564:
565:                layout = new ColumnLayout(3, "test", widths);
566:                layout.addFragment(f1);
567:                layout.addFragment(f2);
568:                layout.addFragment(f3);
569:                layout.addFragment(f4);
570:                layout.addFragment(f5);
571:                layout.addFragment(f6);
572:                layout.addFragment(f8);
573:            }
574:
575:            protected LayoutEvent createEvent(Fragment fragment,
576:                    ColumnLayout layout, int eventType) throws Exception {
577:                LayoutCoordinate fragmentOriginal = layout
578:                        .getCoordinate(fragment);
579:                LayoutCoordinate fragmentNew;
580:
581:                switch (eventType) {
582:                case LayoutEvent.MOVED_UP:
583:                    fragmentNew = new LayoutCoordinate(fragmentOriginal.getX(),
584:                            fragmentOriginal.getY() - 1);
585:                    break;
586:                case LayoutEvent.MOVED_DOWN:
587:                    fragmentNew = new LayoutCoordinate(fragmentOriginal.getX(),
588:                            fragmentOriginal.getY() + 1);
589:                    break;
590:                case LayoutEvent.MOVED_LEFT:
591:                    fragmentNew = new LayoutCoordinate(
592:                            fragmentOriginal.getX() - 1, fragmentOriginal
593:                                    .getY());
594:                    break;
595:                case LayoutEvent.MOVED_RIGHT:
596:                    fragmentNew = new LayoutCoordinate(
597:                            fragmentOriginal.getX() + 1, fragmentOriginal
598:                                    .getY());
599:                    break;
600:                default:
601:                    fragmentNew = new LayoutCoordinate(fragmentOriginal.getX(),
602:                            fragmentOriginal.getY());
603:                    break;
604:                }
605:
606:                return new LayoutEvent(eventType, fragment, fragmentOriginal,
607:                        fragmentNew);
608:
609:            }
610:
611:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.