Source Code Cross Referenced for AppSuiteDataStoreTest.java in  » 6.0-JDK-Modules » j2me » com » sun » midp » jump » push » executive » persistence » 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 » j2me » com.sun.midp.jump.push.executive.persistence 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright  1990-2006 Sun Microsystems, Inc. All Rights Reserved.
003:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
004:         *
005:         * This program is free software; you can redistribute it and/or
006:         * modify it under the terms of the GNU General Public License version
007:         * 2 only, as published by the Free Software Foundation.
008:         *
009:         * This program is distributed in the hope that it will be useful, but
010:         * WITHOUT ANY WARRANTY; without even the implied warranty of
011:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012:         * General Public License version 2 for more details (a copy is
013:         * included at /legal/license.txt).
014:         *
015:         * You should have received a copy of the GNU General Public License
016:         * version 2 along with this work; if not, write to the Free Software
017:         * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
018:         * 02110-1301 USA
019:         *
020:         * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
021:         * Clara, CA 95054 or visit www.sun.com if you need additional
022:         * information or have any questions.
023:         */
024:        package com.sun.midp.jump.push.executive.persistence;
025:
026:        import com.sun.jump.module.contentstore.InMemoryContentStore;
027:        import junit.framework.*;
028:        import java.io.IOException;
029:        import java.util.HashMap;
030:        import java.util.Map;
031:
032:        public final class AppSuiteDataStoreTest extends TestCase {
033:
034:            public AppSuiteDataStoreTest(String testName) {
035:                super (testName);
036:            }
037:
038:            /** Dir for AppSuiteDataStore. */
039:            private static final String DIR = "./dir";
040:
041:            /**
042:             * Data converter.
043:             *
044:             * <p>As plaing <code>String</code>s are used, it quite simple</p>
045:             */
046:            private static final AppSuiteDataStore.DataConverter DATA_CONVERTER = new AppSuiteDataStore.DataConverter() {
047:                public String dataToString(final Object obj) {
048:                    return (String) obj;
049:                }
050:
051:                public Object stringToData(final String s) {
052:                    return s;
053:                }
054:            };
055:
056:            /**
057:             * Creates a handle for <code>JUMPStore</code>.
058:             *
059:             * @returns a handle
060:             */
061:            private static StoreOperationManager createStoreManager()
062:                    throws IOException {
063:                return StoreUtils.createInMemoryManager(new String[] { DIR });
064:            }
065:
066:            private AppSuiteDataStore createAppSuiteDataStore(
067:                    final StoreOperationManager storeManager)
068:                    throws IOException {
069:                return new AppSuiteDataStore(storeManager, DIR, DATA_CONVERTER);
070:            }
071:
072:            private void _testCtorThrowsIllegalArgumentException(
073:                    final StoreOperationManager storeManager, final String dir,
074:                    final AppSuiteDataStore.DataConverter dataConverter,
075:                    final String paramName) throws IOException {
076:                try {
077:                    new AppSuiteDataStore(storeManager, dir, dataConverter);
078:                    fail("AppSuiteDataStore.<init> doesn't throw"
079:                            + " IllegalArgumentException for null " + paramName);
080:                } catch (IllegalArgumentException _) {
081:                }
082:            }
083:
084:            /**
085:             * Tests that AppSuiteDataStore constructor throws an exception
086:             * when fed with <code>null</code> as store handler.
087:             */
088:            public void testCtorNullStoreHandler() throws IOException {
089:                _testCtorThrowsIllegalArgumentException(null, DIR,
090:                        DATA_CONVERTER, "store handle");
091:            }
092:
093:            /**
094:             * Tests that AppSuiteDataStore constructor throws an exception
095:             * when fed with <code>null</code> as store handler.
096:             */
097:            public void testCtorNullDir() throws IOException {
098:                _testCtorThrowsIllegalArgumentException(createStoreManager(),
099:                        null, DATA_CONVERTER, "dir");
100:            }
101:
102:            /**
103:             * Tests that AppSuiteDataStore constructor throws an exception
104:             * when fed with <code>null</code> as store handler.
105:             */
106:            public void testCtorNullDataConverter() throws IOException {
107:                _testCtorThrowsIllegalArgumentException(createStoreManager(),
108:                        DIR, null, "data converter");
109:            }
110:
111:            /**
112:             * Tests that <code>updateSuiteData</code> throws
113:             * <code>IllegalArgumentException</code> when fed with <code>null</code>.
114:             */
115:            public void testUpdateSuiteDataThrows() throws IOException {
116:                try {
117:                    createAppSuiteDataStore(createStoreManager())
118:                            .updateSuiteData(0, null);
119:                    fail("should throw IllegalArgumentException");
120:                } catch (IllegalArgumentException _) {
121:                }
122:            }
123:
124:            /** Bundle of suite id and data. */
125:            private static final class SuiteData {
126:                private final int suiteId;
127:                private final String data;
128:
129:                SuiteData(final int suiteId, final String data) {
130:                    this .suiteId = suiteId;
131:                    this .data = data;
132:                }
133:
134:                void updateStore(final AppSuiteDataStore store)
135:                        throws IOException {
136:                    if (data != null) {
137:                        store.updateSuiteData(suiteId, data);
138:                    } else {
139:                        store.removeSuiteData(suiteId);
140:                    }
141:                }
142:
143:                static void updateStore(final AppSuiteDataStore store,
144:                        final SuiteData[] dataToUpdate) throws IOException {
145:                    for (int i = 0; i < dataToUpdate.length; i++) {
146:                        dataToUpdate[i].updateStore(store);
147:                    }
148:                }
149:            }
150:
151:            private void checkTestData(final AppSuiteDataStore store,
152:                    final SuiteData[] expected) {
153:                /*
154:                 * NB: it's ok for expected to have several records
155:                 * for the same suite: only the last one will be picked
156:                 * (following AppSuiteDataStore semantics)
157:                 */
158:                final Map e = new HashMap();
159:                for (int i = 0; i < expected.length; i++) {
160:                    final SuiteData d = expected[i];
161:                    e.put(new Integer(d.suiteId), d.data);
162:                }
163:
164:                final Map actual = new HashMap();
165:
166:                store.listData(new AppSuiteDataStore.DataConsumer() {
167:                    public void consume(final int suiteId, final Object data) {
168:                        assertNull("reported twice: " + suiteId, actual.put(
169:                                new Integer(suiteId), data));
170:                    }
171:                });
172:
173:                assertEquals(e, actual);
174:            }
175:
176:            private void checkTestData(final SuiteData[] dataToUpdate,
177:                    final SuiteData[] expected) throws IOException {
178:                final StoreOperationManager storeManager = createStoreManager();
179:
180:                final AppSuiteDataStore store = createAppSuiteDataStore(storeManager);
181:                SuiteData.updateStore(store, dataToUpdate);
182:                checkTestData(store, expected);
183:                // And reread it afresh (to emulate real persistence)
184:                checkTestData(createAppSuiteDataStore(storeManager), expected);
185:            }
186:
187:            private void checkGetSuiteData(final AppSuiteDataStore store)
188:                    throws IOException {
189:                store.listData(new AppSuiteDataStore.DataConsumer() {
190:                    public void consume(final int suiteId, final Object data) {
191:                        assertEquals(data, store.getSuiteData(suiteId));
192:                    }
193:                });
194:            }
195:
196:            private void checkGetSuiteData(final SuiteData[] dataToUpdate)
197:                    throws IOException {
198:                final StoreOperationManager storeManager = createStoreManager();
199:
200:                final AppSuiteDataStore store = createAppSuiteDataStore(storeManager);
201:                SuiteData.updateStore(store, dataToUpdate);
202:                checkGetSuiteData(store);
203:                // And reread it afresh (to emulate real persistence)
204:                checkGetSuiteData(createAppSuiteDataStore(storeManager));
205:            }
206:
207:            private final static SuiteData[] NO_UPDATES = new SuiteData[] {};
208:
209:            private final static SuiteData[] ADD_AND_REMOVE = new SuiteData[] {
210:                    new SuiteData(0, "foo"), new SuiteData(0, null), };
211:
212:            private final static SuiteData[] SEVERAL_SUITES = new SuiteData[] {
213:                    new SuiteData(0, "foo"), new SuiteData(239, "bar"),
214:                    new SuiteData(1024, "qux"), };
215:
216:            private final static SuiteData[] OVERWRITTES = new SuiteData[] {
217:                    new SuiteData(17, "foo"), new SuiteData(17, "bar") };
218:
219:            public void testGetSuiteDataNO_UPDATES() throws IOException {
220:                checkGetSuiteData(NO_UPDATES);
221:            }
222:
223:            public void testGetSuiteDataADD_AND_REMOVE() throws IOException {
224:                checkGetSuiteData(ADD_AND_REMOVE);
225:            }
226:
227:            public void testGetSuiteDataSEVERAL_SUITES() throws IOException {
228:                checkGetSuiteData(SEVERAL_SUITES);
229:            }
230:
231:            public void testGetSuiteDataOVERWRITTES() throws IOException {
232:                checkGetSuiteData(OVERWRITTES);
233:            }
234:
235:            public void testNO_UPDATES() throws IOException {
236:                checkTestData(NO_UPDATES, NO_UPDATES);
237:            }
238:
239:            public void testADD_AND_REMOVE() throws IOException {
240:                checkTestData(ADD_AND_REMOVE, new SuiteData[] {});
241:            }
242:
243:            public void testSEVERAL_SUITES() throws IOException {
244:                checkTestData(SEVERAL_SUITES, SEVERAL_SUITES);
245:            }
246:
247:            public void testOVERWRITTES() throws IOException {
248:                checkTestData(OVERWRITTES, OVERWRITTES);
249:            }
250:        }
w__ww__._ja__v___a2_s___.___c_o_m__ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.