Source Code Cross Referenced for CollectionDescriptorTest.java in  » 6.0-JDK-Modules » Java-Advanced-Imaging » ca » forklabs » media » jai » 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 » 6.0 JDK Modules » Java Advanced Imaging » ca.forklabs.media.jai 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * @(#) $Header: /cvs/jai-operators/src/tests/ca/forklabs/media/jai/CollectionDescriptorTest.java,v 1.2 2007/06/13 18:54:17 forklabs Exp $
003:         *
004:         * Copyright (C) 2007  Forklabs Daniel Léonard
005:         *
006:         * This program is free software; you can redistribute it and/or
007:         * modify it under the terms of the GNU General Public License
008:         * as published by the Free Software Foundation; either version 2
009:         * of the License, or (at your option) any later version.
010:         *
011:         * This program is distributed in the hope that it will be useful,
012:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
014:         * GNU General Public License for more details.
015:         *
016:         * You should have received a copy of the GNU General Public License
017:         * along with this program; if not, write to the Free Software
018:         * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
019:         */
020:
021:        package ca.forklabs.media.jai;
022:
023:        import java.awt.image.RenderedImage;
024:        import java.awt.image.renderable.ParameterBlock;
025:        import java.awt.image.renderable.RenderableImage;
026:        import java.util.Collection;
027:        import java.util.Iterator;
028:        import java.util.Locale;
029:        import javax.media.jai.ParameterListDescriptor;
030:        import javax.media.jai.registry.CollectionRegistryMode;
031:        import javax.media.jai.registry.RenderableCollectionRegistryMode;
032:        import junit.framework.TestCase;
033:        import ca.forklabs.media.jai.mock.MockRenderableImage;
034:        import ca.forklabs.media.jai.mock.MockRenderedImage;
035:
036:        /**
037:         * Class {@code CollectionDescriptorTest} tests class
038:         * {@link CollectionDescriptor}.
039:         *
040:         * @author   <a href="mailto:forklabs at dev.java.net?subject=ca.forklabs.media.jai.CollectionDescriptorTest">Daniel Léonard</a>
041:         * @version $Revision: 1.2 $
042:         */
043:        @SuppressWarnings("nls")
044:        public class CollectionDescriptorTest extends TestCase {
045:
046:            //---------------------------
047:            // Constructors
048:            //---------------------------
049:
050:            /**
051:             * Constructor.
052:             * @param   name   the name of this test.
053:             */
054:            public CollectionDescriptorTest(String name) {
055:                super (name);
056:            }
057:
058:            //---------------------------
059:            // Test methods
060:            //---------------------------
061:
062:            @SuppressWarnings("serial")
063:            private static class NullCollectionDescriptor extends
064:                    CollectionDescriptor {
065:                private static final String[][] resources = {
066:                        { "GlobalName", "nullcollection", },
067:                        { "LocalName", "nullcollection", },
068:                        { "Vendor", "no vendor", },
069:                        { "Description", "does nothing", },
070:                        { "DocURL", "n/a", }, { "Version", "0.0", }, };
071:
072:                private static final String[] modes = {
073:                        CollectionRegistryMode.MODE_NAME,
074:                        RenderableCollectionRegistryMode.MODE_NAME, };
075:
076:                private static final String[] names = null;
077:
078:                private static final Class<?>[][] classes = new Class<?>[][] {
079:                        { Collection.class, }, { Collection.class, }, };
080:
081:                private static final ParameterListDescriptor parameter_list_descriptor = new CollectionDescriptor.EmptyParameterListDescriptor();
082:                private static final ParameterListDescriptor[] parameter_list_descriptors = new ParameterListDescriptor[] {
083:                        parameter_list_descriptor, parameter_list_descriptor, };
084:
085:                /** Constructor. */
086:                public NullCollectionDescriptor() {
087:                    super (resources, modes, names, classes,
088:                            parameter_list_descriptors);
089:                }
090:
091:            }
092:
093:            /**
094:             * Tests
095:             * {@link CollectionDescriptor#validateSources(String, ParameterBlock, StringBuffer)}
096:             * when all the source are {@link RenderedImage}s.
097:             */
098:            public void testValidateSourcesAllRendered() {
099:                RenderedImage[] images = new RenderedImage[] {
100:                        new MockRenderedImage(), new MockRenderedImage(),
101:                        new MockRenderedImage(), new MockRenderedImage(),
102:                        new MockRenderedImage(), new MockRenderedImage(), };
103:
104:                String mode = "collection";
105:                ParameterBlock pb = new ParameterBlock().addSource(images[0])
106:                        .addSource(images[1]).addSource(images[2]).addSource(
107:                                images[3]).addSource(images[4]).addSource(
108:                                images[5]);
109:                StringBuffer sb = new StringBuffer();
110:
111:                CollectionDescriptor descriptor = new NullCollectionDescriptor();
112:                assertTrue(descriptor.validateSources(mode, pb, sb));
113:                Collection<?> sources = (Collection<?>) pb.getSource(0);
114:                assertEquals(images.length, sources.size());
115:
116:                Iterator<?> iterator = sources.iterator();
117:                assertSame(images[0], iterator.next());
118:                assertSame(images[1], iterator.next());
119:                assertSame(images[2], iterator.next());
120:                assertSame(images[3], iterator.next());
121:                assertSame(images[4], iterator.next());
122:                assertSame(images[5], iterator.next());
123:
124:                assertEquals("", sb.toString());
125:            }
126:
127:            /**
128:             * Tests
129:             * {@link CollectionDescriptor#validateSources(String, ParameterBlock, StringBuffer)}
130:             * when all the source are {@link RenderableImage}s.
131:             */
132:            public void testValidateSourcesAllRenderable() {
133:                RenderableImage[] images = new RenderableImage[] {
134:                        new MockRenderableImage(), new MockRenderableImage(),
135:                        new MockRenderableImage(), new MockRenderableImage(),
136:                        new MockRenderableImage(), new MockRenderableImage(), };
137:
138:                String mode = "renderablecollection";
139:                ParameterBlock pb = new ParameterBlock().addSource(images[0])
140:                        .addSource(images[1]).addSource(images[2]).addSource(
141:                                images[3]).addSource(images[4]).addSource(
142:                                images[5]);
143:                StringBuffer sb = new StringBuffer();
144:
145:                CollectionDescriptor descriptor = new NullCollectionDescriptor();
146:                assertTrue(descriptor.validateSources(mode, pb, sb));
147:                Collection<?> sources = (Collection<?>) pb.getSource(0);
148:                assertEquals(images.length, sources.size());
149:
150:                Iterator<?> iterator = sources.iterator();
151:                assertSame(images[0], iterator.next());
152:                assertSame(images[1], iterator.next());
153:                assertSame(images[2], iterator.next());
154:                assertSame(images[3], iterator.next());
155:                assertSame(images[4], iterator.next());
156:                assertSame(images[5], iterator.next());
157:
158:                assertEquals("", sb.toString());
159:            }
160:
161:            /**
162:             * Tests
163:             * {@link CollectionDescriptor#validateSources(String, ParameterBlock, StringBuffer)}
164:             * when not all the sources are of the same type.
165:             */
166:            public void testValidateNotAllSameType() {
167:                Object[] images = new Object[] { new MockRenderableImage(),
168:                        new MockRenderedImage(), };
169:
170:                ParameterBlock pb = new ParameterBlock().addSource(images[0])
171:                        .addSource(images[1]);
172:
173:                CollectionDescriptor descriptor = new NullCollectionDescriptor();
174:
175:                Locale locale = Locale.getDefault();
176:                Locale.setDefault(Locale.ENGLISH);
177:                try {
178:                    {
179:                        String mode = "collection";
180:                        StringBuffer sb = new StringBuffer();
181:                        assertFalse(descriptor.validateSources(mode, pb, sb));
182:                        assertEquals("Not all the sources are RenderedImage's",
183:                                sb.toString());
184:                    }
185:                    {
186:                        String mode = "renderablecollection";
187:                        StringBuffer sb = new StringBuffer();
188:                        assertFalse(descriptor.validateSources(mode, pb, sb));
189:                        assertEquals(
190:                                "Not all the sources are RenderableImage's", sb
191:                                        .toString());
192:                    }
193:                    {
194:                        String mode = "godmode";
195:                        StringBuffer sb = new StringBuffer();
196:                        assertFalse(descriptor.validateSources(mode, pb, sb));
197:                        assertEquals(
198:                                "Expected mode \"collection\" or mode \"renderedablecollection\" but got \"godmode\"",
199:                                sb.toString());
200:                    }
201:                } finally {
202:                    Locale.setDefault(locale);
203:                }
204:            }
205:
206:            /**
207:             * Tests the English error messages.
208:             */
209:            public void testEnglishErrorMessages() {
210:                Locale locale = Locale.getDefault();
211:                Locale.setDefault(Locale.ENGLISH);
212:
213:                try {
214:                    String[] expected = new String[] {
215:                            "This operator does not have enumerated parameters",
216:                            "This operator does not have a parameter named \"foo\"",
217:                            "Not all the sources are RenderedImage's",
218:                            "Not all the sources are RenderableImage's",
219:                            "Expected mode \"collection\" or mode \"renderedablecollection\" but got \"foomode\"", };
220:
221:                    CollectionDescriptor descriptor = new NullCollectionDescriptor();
222:                    String[] got = new String[] {
223:                            CollectionDescriptor
224:                                    .getNoEnumeratedParametersErrorMessage(),
225:                            CollectionDescriptor
226:                                    .getUnknownParameterErrorMessage("foo"),
227:                            descriptor.getNotAllRenderedErrorMessage(),
228:                            descriptor.getNotAllRenderableErrorMessage(),
229:                            descriptor
230:                                    .getNeitherCollectionNorRenderableCollectionModeErrorMessage("foomode"), };
231:
232:                    assertEquals(expected.length, got.length);
233:
234:                    for (int i = 0; i < expected.length; i++) {
235:                        assertEquals("[" + i + "]", expected[i], got[i]);
236:                    }
237:                } finally {
238:                    Locale.setDefault(locale);
239:                }
240:            }
241:
242:            /**
243:             * Tests the French error messages.
244:             */
245:            public void testFrenchErrorMessages() {
246:                Locale locale = Locale.getDefault();
247:                Locale.setDefault(Locale.FRENCH);
248:
249:                try {
250:                    String[] expected = new String[] {
251:                            "Cet opérateur n'a pas de paramêtres énumérés",
252:                            "Cet opérateur n'a pas un paramêtre nommé \"toto\"",
253:                            "Toutes les images sources ne sont pas des \"RenderedImage\"",
254:                            "Toutes les images sources ne sont pas des \"RenderableImage\"",
255:                            "Attendait le mode \"collection\" ou le mode \"renderedablecollection\" mais le mode est \"modetoto\"", };
256:
257:                    CollectionDescriptor descriptor = new NullCollectionDescriptor();
258:                    String[] got = new String[] {
259:                            CollectionDescriptor
260:                                    .getNoEnumeratedParametersErrorMessage(),
261:                            CollectionDescriptor
262:                                    .getUnknownParameterErrorMessage("toto"),
263:                            descriptor.getNotAllRenderedErrorMessage(),
264:                            descriptor.getNotAllRenderableErrorMessage(),
265:                            descriptor
266:                                    .getNeitherCollectionNorRenderableCollectionModeErrorMessage("modetoto"), };
267:
268:                    assertEquals(expected.length, got.length);
269:
270:                    for (int i = 0; i < expected.length; i++) {
271:                        assertEquals("[" + i + "]", expected[i], got[i]);
272:                    }
273:                } finally {
274:                    Locale.setDefault(locale);
275:                }
276:            }
277:
278:            //---------------------------
279:            // Class methods
280:            //---------------------------
281:
282:            /**
283:             * Runs only this test.
284:             * @param   args   ignored.
285:             */
286:            public static void main(String... args) {
287:                junit.swingui.TestRunner.run(CollectionDescriptorTest.class);
288:            }
289:
290:        }
291:
292:        /*
293:         * $Log: CollectionDescriptorTest.java,v $
294:         * Revision 1.2  2007/06/13 18:54:17  forklabs
295:         * Changed the mission from helping collection descriptor to helping descriptors using collection sources.
296:         *
297:         * Revision 1.1  2007/06/11 22:21:00  forklabs
298:         * A class to help descriptors in collection and renderable collection mode.
299:         *
300:         */
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.