Source Code Cross Referenced for TestDateElement.java in  » ERP-CRM-Financial » Kuali-Financial-System » edu » iu » uis » eden » services » docelements » 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 » Kuali Financial System » edu.iu.uis.eden.services.docelements 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package edu.iu.uis.eden.services.docelements;
002:
003:        import java.io.StringReader;
004:        import java.text.SimpleDateFormat;
005:        import java.util.Date;
006:
007:        import junit.framework.TestCase;
008:
009:        import org.jdom.Document;
010:        import org.jdom.Element;
011:
012:        import edu.iu.uis.eden.exception.InvalidXmlException;
013:        import edu.iu.uis.eden.services.IDocElement;
014:        import edu.iu.uis.eden.services.InconsistentDocElementStateException;
015:        import edu.iu.uis.eden.services.ServiceErrorConstants;
016:        import edu.iu.uis.eden.util.XmlHelper;
017:
018:        public class TestDateElement extends TestCase {
019:            private DateElement dateElement;
020:
021:            public TestDateElement(String s) {
022:                super (s);
023:            }
024:
025:            protected void setUp() {
026:                this .dateElement = new DateElement();
027:            }
028:
029:            protected void tearDown() {
030:            }
031:
032:            /**
033:             * test the xml content for to_date, from_date and date
034:             */
035:            public void testGetXMLContent() throws Exception {
036:                SimpleDateFormat df = new SimpleDateFormat("MM/dd/yyyy");
037:                Date daDate = df.parse("11/05/2102");
038:
039:                //    String xmlDate = "<date value=\"" + daDate.toString() + "\" />";
040:                DateElement date = new DateElement();
041:
042:                //set to toDate
043:                date.setDate(daDate);
044:                assertNotNull("Returned null when loaded", date.getXMLContent());
045:            }
046:
047:            /**
048:             * can this guy populate himself w/ xml he made.
049:             */
050:            public void testCanFeedOnOwnXML() {
051:                //start w/ to date
052:                DateElement date = new DateElement();
053:
054:                //    String daDate = "11/05/2102";
055:                //    date.setDate(new Date(daDate));
056:                date.setDate(new Date());
057:
058:                Element dateEl = date.getXMLContent();
059:
060:                try {
061:                    date.loadFromXMLContent(dateEl, false);
062:                    assertNotNull(
063:                            "didn't properly load props from valid element",
064:                            date.getDate());
065:                } catch (Exception ex) {
066:                    fail("threw exception loading from self generated xml");
067:                }
068:            }
069:
070:            /**
071:             * given a jdom element of the correct type it should load itself to the value
072:             * of the given jdom element
073:             *
074:             * if the jdom element is null and allowBlanks true it should return
075:             *
076:             * if the jdom element is null and allowBlanks is false its should throw
077:             * an InconsistentDocElementStateException
078:             *
079:             * if the element is of the incorrect type it should throw an
080:             * InvalidXmlException
081:             */
082:            public void testLoadFromXMLContent() throws Exception {
083:                //test loading a normal date
084:                SimpleDateFormat df = new SimpleDateFormat("MM/dd/yyyy");
085:                Date daDate = df.parse("9/9/99");
086:
087:                Element dateEl = new Element("date");
088:                dateEl.setAttribute("value", new Long(daDate.getTime())
089:                        .toString());
090:
091:                try {
092:                    dateElement.loadFromXMLContent(dateEl, false);
093:                    assertEquals(
094:                            "didn't properly load props from valid element",
095:                            daDate, dateElement.getDate());
096:                } catch (Exception ex) {
097:                    fail("threw exception loading from valid element");
098:                }
099:
100:                //test implementation of interface
101:                this .nonClassSpecificLoadFromXMLTests(dateElement);
102:            }
103:
104:            /**
105:             * an object with a blank date should give a blank error specific to the
106:             * type of date it is
107:             *
108:             * a loaded object w/ a bad date should give an invalid error specific to the
109:             * type of date it is
110:             */
111:            public void testValidate() {
112:                try {
113:                    //check for blank
114:                    assertEquals(
115:                            "gave an error object with an incorrect error constant",
116:                            ServiceErrorConstants.DATE_BLANK, dateElement
117:                                    .validate().getKey());
118:
119:                    //make valid and check types should all be null
120:                    dateElement.setDate(new Date());
121:                    assertNull("valid date didn't return null on validate",
122:                            dateElement.validate());
123:                } catch (Exception ex) {
124:                    fail("threw exception validating");
125:                }
126:            }
127:
128:            /**
129:             * this should not be a route control according to now business rules
130:             */
131:            public void testIsRouteControl() {
132:                assertEquals("This should not be a routeControl", false,
133:                        this .dateElement.isRouteControl());
134:            }
135:
136:            /**
137:             * utility method that is not object specific
138:             *
139:             * @param docElement the docElement being tested
140:             */
141:            public void nonClassSpecificLoadFromXMLTests(IDocElement docElement) {
142:                //give null allow blanks
143:                try {
144:                    docElement.loadFromXMLContent(null, true);
145:                } catch (Exception ex) {
146:                    fail("threw exception loading null element set to allow blanks");
147:                }
148:
149:                //give null dont allow blanks
150:                try {
151:                    docElement.loadFromXMLContent(null, false);
152:                    fail("didn't throw InconsistentDocElementStateException "
153:                            + "loaded with null element allowBlanks set to false");
154:                } catch (InconsistentDocElementStateException ex) {
155:                } catch (InvalidXmlException ex) {
156:                    fail("didn't throw InconsistentDocElementStateException "
157:                            + "loaded with null element allowBlanks set to false");
158:                }
159:
160:                //give element of wrong type
161:                try {
162:                    docElement.loadFromXMLContent(new Element("Imbad"), false);
163:                    fail("Didn't throw InvalidXmlException when loaded with "
164:                            + "element of the wrong type");
165:                } catch (InconsistentDocElementStateException ex) {
166:                    fail("Didn't throw InvalidXmlException when loaded with "
167:                            + "element of the wrong type");
168:                } catch (InvalidXmlException ex) {
169:                }
170:            }
171:
172:            public Element makeStringElement(String xmlContent) {
173:                Document doc = null;
174:
175:                try {
176:                    doc = new Document(XmlHelper.buildJDocument(
177:                            new StringReader(xmlContent), false)
178:                            .getRootElement());
179:                } catch (InvalidXmlException ex) {
180:                    fail("Generated invalid xml");
181:                }
182:
183:                return doc.getRootElement();
184:            }
185:        }
186:
187:        /*
188:         * Copyright 2003 The Trustees of Indiana University.  All rights reserved.
189:         *
190:         * This file is part of the EDEN software package.
191:         * For license information, see the LICENSE file in the top level directory
192:         * of the EDEN source distribution.
193:         */
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.