Source Code Cross Referenced for OpenSessionTest.java in  » ERP-CRM-Financial » jmoney » net » sf » jmoney » test » 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 » jmoney » net.sf.jmoney.test 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *
003:         *  JMoney - A Personal Finance Manager
004:         *  Copyright (c) 2005 Johann Gyger <jgyger@users.sf.net>
005:         *
006:         *
007:         *  This program is free software; you can redistribute it and/or modify
008:         *  it under the terms of the GNU General Public License as published by
009:         *  the Free Software Foundation; either version 2 of the License, or
010:         *  (at your option) any later version.
011:         *
012:         *  This program is distributed in the hope that it will be useful,
013:         *  but WITHOUT ANY WARRANTY; without even the implied warranty of
014:         *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
015:         *  GNU General Public License for more details.
016:         *
017:         *  You should have received a copy of the GNU General Public License
018:         *  along with this program; if not, write to the Free Software
019:         *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
020:         *
021:         */
022:        package net.sf.jmoney.test;
023:
024:        import java.io.File;
025:        import java.io.IOException;
026:        import java.net.URL;
027:
028:        import javax.xml.transform.TransformerConfigurationException;
029:
030:        import junit.framework.TestCase;
031:        import net.sf.jmoney.model2.BankAccountInfo;
032:        import net.sf.jmoney.model2.TransactionInfo;
033:        import net.sf.jmoney.model2.BankAccount;
034:        import net.sf.jmoney.model2.Entry;
035:        import net.sf.jmoney.model2.Session;
036:        import net.sf.jmoney.model2.Transaction;
037:        import net.sf.jmoney.serializeddatastore.SessionManager;
038:        import net.sf.jmoney.serializeddatastore.formats.JMoneyXmlFormat;
039:
040:        import org.eclipse.core.runtime.CoreException;
041:        import org.eclipse.core.runtime.FileLocator;
042:        import org.eclipse.core.runtime.Platform;
043:        import org.osgi.framework.Bundle;
044:        import org.osgi.framework.BundleException;
045:        import org.xml.sax.SAXException;
046:
047:        /**
048:         * Tests regarding opening JMoney session files.
049:         * 
050:         * @author Johann Gyger
051:         */
052:        public class OpenSessionTest extends TestCase {
053:
054:            @Override
055:            public void setUp() {
056:                Bundle bundle = Platform.getBundle("net.sf.jmoney.test");
057:                try {
058:                    bundle.start();
059:                } catch (BundleException e) {
060:                    // TODO Auto-generated catch block
061:                    e.printStackTrace();
062:                }
063:            }
064:
065:            @Override
066:            public void tearDown() {
067:                Bundle bundle = Platform.getBundle("net.sf.jmoney.test");
068:                try {
069:                    bundle.stop();
070:                } catch (BundleException e) {
071:                    // TODO Auto-generated catch block
072:                    e.printStackTrace();
073:                }
074:            }
075:
076:            /**
077:             * Test if a JMoney file with the properties below can be opened:
078:             * - Old format (version 0.4.5 or prior)
079:             * - Empty (minimal file contents)
080:             * - Uncompressed
081:             * 
082:             * @throws CoreException
083:             * @throws IOException
084:             */
085:            public void testOldEmptyUncompressed() throws IOException,
086:                    CoreException {
087:                File file = getSessionFile("old_empty_session.xml");
088:                JMoneyXmlFormat reader = new JMoneyXmlFormat();
089:                SessionManager manager = new SessionManager(
090:                        "net.sf.jmoney.serializeddatastore.xmlFormat", reader,
091:                        file);
092:                reader.readSessionQuietly(file, manager, null);
093:                assertNotNull(manager);
094:                assertNotNull(manager.getSession());
095:            }
096:
097:            /**
098:             * Test if a JMoney file with the properties below can be opened:
099:             * - Old format (version 0.4.5 or prior)
100:             * - Empty (minimal file contents)
101:             * - Compressed
102:             * 
103:             * @throws CoreException
104:             * @throws IOException
105:             */
106:            public void testOldEmptyCompressed() throws IOException,
107:                    CoreException {
108:                File file = getSessionFile("old_empty_session.jmx");
109:                JMoneyXmlFormat reader = new JMoneyXmlFormat();
110:                SessionManager manager = new SessionManager(
111:                        "net.sf.jmoney.serializeddatastore.jmxFormat", reader,
112:                        file);
113:                reader.readSessionQuietly(file, manager, null);
114:                assertNotNull(manager);
115:                assertNotNull(manager.getSession());
116:            }
117:
118:            /**
119:             * Test if a JMoney file with the properties below can be opened:
120:             * - New format
121:             * - Empty (minimal file contents)
122:             * - Uncompressed
123:             * 
124:             * @throws CoreException
125:             * @throws IOException
126:             */
127:            public void testNewEmptyUncompressed() throws IOException,
128:                    CoreException {
129:                File file = getSessionFile("new_empty_session.xml");
130:                JMoneyXmlFormat reader = new JMoneyXmlFormat();
131:                SessionManager manager = new SessionManager(
132:                        "net.sf.jmoney.serializeddatastore.xmlFormat", reader,
133:                        file);
134:                reader.readSessionQuietly(file, manager, null);
135:                assertNotNull(manager);
136:                assertNotNull(manager.getSession());
137:            }
138:
139:            /**
140:             * Test if a JMoney file with the properties below can be opened:
141:             * - New format
142:             * - Empty (minimal file contents)
143:             * - Compressed
144:             * 
145:             * @throws CoreException
146:             * @throws IOException
147:             */
148:            public void testNewEmptyCompressed() throws IOException,
149:                    CoreException {
150:                File file = getSessionFile("new_empty_session.jmx");
151:                JMoneyXmlFormat reader = new JMoneyXmlFormat();
152:                SessionManager manager = new SessionManager(
153:                        "net.sf.jmoney.serializeddatastore.jmxFormat", reader,
154:                        file);
155:                reader.readSessionQuietly(file, manager, null);
156:                assertNotNull(manager);
157:                assertNotNull(manager.getSession());
158:            }
159:
160:            /**
161:             * Test if a JMoney file with the properties below can be opened:
162:             * - New format
163:             * - Empty (minimal file contents)
164:             * - Compressed
165:             * 
166:             * @throws CoreException
167:             * @throws IOException
168:             */
169:            public void testOpenUpdateSaveCycle() throws IOException,
170:                    CoreException {
171:                File inputFile = getSessionFile("new_empty_session.jmx");
172:                File outputFile = new File("test1.xml");
173:
174:                JMoneyXmlFormat reader = new JMoneyXmlFormat();
175:                SessionManager manager = new SessionManager(
176:                        JMoneyXmlFormat.ID_FILE_FORMAT, reader, inputFile);
177:                reader.readSessionQuietly(inputFile, manager, null);
178:                assertNotNull(manager);
179:                assertNotNull(manager.getSession());
180:
181:                // Make some updates
182:                Session session = manager.getSession();
183:
184:                BankAccount account1 = session.getAccountCollection()
185:                        .createNewElement(BankAccountInfo.getPropertySet());
186:                BankAccount account2 = session.getAccountCollection()
187:                        .createNewElement(BankAccountInfo.getPropertySet());
188:
189:                account1.setName("My Checking Account");
190:                account2.setName("My Savings Account");
191:
192:                Transaction trans = session.getTransactionCollection()
193:                        .createNewElement(TransactionInfo.getPropertySet());
194:                Entry entry1 = trans.getEntryCollection().createEntry();
195:                Entry entry2 = trans.getEntryCollection().createEntry();
196:
197:                entry1.setAccount(account1);
198:                entry2.setAccount(account2);
199:                entry1.setAmount(1234);
200:                entry2.setAmount(-1234);
201:                entry1.setMemo("transfer from savings");
202:                entry2.setMemo("transfer to checking");
203:
204:                try {
205:                    reader.writeSessionQuietly(manager, outputFile, null);
206:                } catch (TransformerConfigurationException e) {
207:                    e.printStackTrace();
208:                    fail(e.getLocalizedMessage());
209:                } catch (SAXException e) {
210:                    e.printStackTrace();
211:                    fail(e.getLocalizedMessage());
212:                }
213:
214:                // Read the file back in
215:                SessionManager manager2 = new SessionManager(
216:                        JMoneyXmlFormat.ID_FILE_FORMAT, reader, inputFile);
217:                reader.readSessionQuietly(inputFile, manager2, null);
218:                assertNotNull(manager2);
219:                assertNotNull(manager2.getSession());
220:                Session session2 = manager2.getSession();
221:                assertEquals(1, session2.getCommodityCollection().size());
222:                assertEquals(2, session2.getAccountCollection().size());
223:                assertEquals(1, session2.getTransactionCollection().size());
224:            }
225:
226:            protected File getSessionFile(String filename) throws IOException {
227:                Bundle bundle = Platform.getBundle("net.sf.jmoney.test");
228:                URL url = bundle.getEntry("resources/" + filename);
229:                return new File(FileLocator.toFileURL(url).getFile());
230:            }
231:
232:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.