Source Code Cross Referenced for FxValueTest.java in  » J2EE » fleXive » com » flexive » tests » shared » 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 » J2EE » fleXive » com.flexive.tests.shared 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /***************************************************************
002:         *  This file is part of the [fleXive](R) project.
003:         *
004:         *  Copyright (c) 1999-2008
005:         *  UCS - unique computing solutions gmbh (http://www.ucs.at)
006:         *  All rights reserved
007:         *
008:         *  The [fleXive](R) project is free software; you can redistribute
009:         *  it and/or modify it under the terms of the GNU General Public
010:         *  License as published by the Free Software Foundation;
011:         *  either version 2 of the License, or (at your option) any
012:         *  later version.
013:         *
014:         *  The GNU General Public License can be found at
015:         *  http://www.gnu.org/copyleft/gpl.html.
016:         *  A copy is found in the textfile GPL.txt and important notices to the
017:         *  license from the author are found in LICENSE.txt distributed with
018:         *  these libraries.
019:         *
020:         *  This library is distributed in the hope that it will be useful,
021:         *  but WITHOUT ANY WARRANTY; without even the implied warranty of
022:         *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
023:         *  GNU General Public License for more details.
024:         *
025:         *  For further information about UCS - unique computing solutions gmbh,
026:         *  please see the company website: http://www.ucs.at
027:         *
028:         *  For further information about [fleXive](R), please see the
029:         *  project website: http://www.flexive.org
030:         *
031:         *
032:         *  This copyright notice MUST APPEAR in all copies of the file!
033:         ***************************************************************/package com.flexive.tests.shared;
034:
035:        import com.flexive.shared.value.*;
036:        import org.testng.annotations.DataProvider;
037:        import org.testng.annotations.Test;
038:        import org.apache.commons.lang.StringUtils;
039:
040:        import java.util.Arrays;
041:        import java.util.Collections;
042:        import java.util.List;
043:        import java.util.ArrayList;
044:
045:        /**
046:         * Generic FxValue tests
047:         *
048:         * @author Daniel Lichtenberger (daniel.lichtenberger@flexive.com), UCS - unique computing solutions gmbh (http://www.ucs.at)
049:         */
050:        @Test(groups="shared")
051:        public class FxValueTest {
052:            private static Object[][] testInstances = new Object[][] {
053:                    { new ValueTestBean<String, FxString>(new FxString(false,
054:                            "Test string"), "Element",
055:                            new String[] { "String value" }, new String[0]) },
056:                    { new ValueTestBean<Integer, FxNumber>(new FxNumber(false,
057:                            42), 1234, new String[] { "5678", "0", "-23124" },
058:                            new String[] { "6789x", "", "5.6", "-", "-0.1" }) },
059:                    { new ValueTestBean<Long, FxLargeNumber>(new FxLargeNumber(
060:                            false, (long) 42), (long) 1234, new String[] {
061:                            "5678", "0", "-23124" }, new String[] { "6789x",
062:                            "", "5.6", "-", "-0.1" }) },
063:                    { new ValueTestBean<Double, FxDouble>(new FxDouble(false,
064:                            1979.1111), 1234.5678, new String[] { "5678", "0",
065:                            "-23124", "0.0", "-5.3", "213341.314231" },
066:                            new String[] { "6789x", "", "abc", "123,456" }) },
067:                    { new ValueTestBean<Float, FxFloat>(new FxFloat(false,
068:                            1979.1111f), 1234.5678f, new String[] { "5678",
069:                            "0", "-23124", "0.0", "-5.3", "213341.314231" },
070:                            new String[] { "6789x", "", "abc", "123,456" }) },
071:                    { new ValueTestBean<Boolean, FxBoolean>(new FxBoolean(
072:                            false, true), false,
073:                            new String[] { "true", "false" }, new String[] {}) },
074:            // TODO add test instances for FxDate, FxDateRange
075:            };
076:
077:            @Test(dataProvider="testInstances")
078:            public <T, TDerived extends FxValue<T, TDerived>> void testIsValid(
079:                    ValueTestBean<T, TDerived> testBean) {
080:                FxValue<T, TDerived> value = testBean.getValue().copy();
081:                assert value.isValid() : "Test value should be valid: " + value;
082:                assert !value.isMultiLanguage() : "Value must not be multilingual: "
083:                        + value;
084:
085:                // test valid string values
086:                for (String validValue : testBean.getValidStringValues()) {
087:                    //noinspection unchecked
088:                    ((FxValue) value).setValue(validValue);
089:                    assert value.isValid() : "String value should be valid: "
090:                            + validValue;
091:                }
092:
093:                // test invalid string values
094:                for (String invalidValue : testBean.getInvalidStringValues()) {
095:                    //noinspection unchecked
096:                    ((FxValue) value).setValue(invalidValue);
097:                    assert !value.isValid() : "String value should not be valid: "
098:                            + invalidValue;
099:                }
100:                value.setValue(testBean.getValueElement());
101:                assert value.isValid() : "Value must be valid: "
102:                        + testBean.getValueElement();
103:            }
104:
105:            @Test(dataProvider="testInstances")
106:            public <T, TDerived extends FxValue<T, TDerived>> void testValidContract(
107:                    ValueTestBean<T, TDerived> testBean) {
108:                // checks the contract of FxValue#isValid() and FxValue#getErrorValue():
109:                FxValue<T, TDerived> value = testBean.getValue().copy();
110:                // if !isValid(), then getErrorValue() must return an object.
111:                for (String validValue : testBean.getValidStringValues()) {
112:                    //noinspection unchecked
113:                    ((FxValue) value).setValue(validValue);
114:                    assert value.isValid();
115:                    try {
116:                        value.getErrorValue();
117:                        assert false : "Valid values cannot return error values.";
118:                    } catch (IllegalStateException e) {
119:                        // pass
120:                    }
121:                }
122:                // check empty values
123:                value.setEmpty();
124:                if (value.isValid()) {
125:                    try {
126:                        value.getErrorValue();
127:                        assert false : "Valid values cannot return error values.";
128:                    } catch (IllegalStateException e) {
129:                        // pass
130:                    }
131:                } else {
132:                    assert value.getErrorValue() != null : "Invalid values must return an error value.";
133:                }
134:                // if isValid(), then getErrorValue() must throw an IllegalStateException.
135:                for (String invalidValue : testBean.getInvalidStringValues()) {
136:                    //noinspection unchecked
137:                    ((FxValue) value).setValue(invalidValue);
138:                    assert !value.isValid();
139:                    assert value.getErrorValue() != null : "Invalid value must return an error value.";
140:                }
141:            }
142:
143:            /**
144:             * Bug check: if a previously empty number property is updated with the same
145:             * "empty" number, the isEmpty flag is not set correctly.
146:             */
147:            @Test
148:            public void testUpdateEmptyValue() {
149:                FxNumber number = new FxNumber(0).setEmpty();
150:                assert number.isEmpty();
151:                number.setValue(0);
152:                assert !number.isEmpty() : "FxNumber still empty after explicit value update.";
153:            }
154:
155:            @DataProvider(name="testInstances")
156:            private Object[][] getTestInstances() {
157:                return testInstances;
158:            }
159:
160:            /**
161:             * Test instance for a FxValue element.
162:             */
163:            private static class ValueTestBean<T, TDerived extends FxValue<T, TDerived>> {
164:                private FxValue<T, TDerived> value;
165:                private T valueElement;
166:                private List<String> validStringValues;
167:                private List<String> invalidStringValues;
168:
169:                public ValueTestBean(FxValue<T, TDerived> value,
170:                        T valueElement, String[] validStringValues,
171:                        String[] invalidStringValues) {
172:                    super ();
173:                    this .value = value;
174:                    this .valueElement = valueElement;
175:                    this .validStringValues = Collections
176:                            .unmodifiableList(Arrays.asList(validStringValues));
177:                    this .invalidStringValues = Collections
178:                            .unmodifiableList(Arrays
179:                                    .asList(invalidStringValues));
180:                }
181:
182:                public List<String> getInvalidStringValues() {
183:                    return invalidStringValues;
184:                }
185:
186:                public List<String> getValidStringValues() {
187:                    return validStringValues;
188:                }
189:
190:                public FxValue<T, TDerived> getValue() {
191:                    return value;
192:                }
193:
194:                public T getValueElement() {
195:                    return valueElement;
196:                }
197:            }
198:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.