Source Code Cross Referenced for RepositoryElementsTest.java in  » Database-ORM » db-ojb » org » apache » ojb » broker » metadata » 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 » Database ORM » db ojb » org.apache.ojb.broker.metadata 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.apache.ojb.broker.metadata;
002:
003:        import junit.framework.Test;
004:        import junit.framework.TestCase;
005:        import junit.framework.TestSuite;
006:
007:        import java.lang.reflect.Field;
008:        import java.util.Arrays;
009:
010:        /**
011:         * @author Virender Dogra
012:         * @version Apr 16, 2003 6:14:56 PM
013:         *
014:         */
015:        public class RepositoryElementsTest extends TestCase {
016:
017:            /**
018:             * Constructor for RespositoryElementsTest.
019:             * @param name
020:             */
021:            public RepositoryElementsTest(String name) {
022:                super (name);
023:            }
024:
025:            public static void main(String[] args) {
026:                junit.textui.TestRunner.run(RepositoryElementsTest.suite());
027:            }
028:
029:            public static Test suite() {
030:                // Reflection is used here to add all
031:                // the testXXX() methods to the suite.
032:                TestSuite suite = new TestSuite(RepositoryElementsTest.class);
033:                return suite;
034:
035:            }
036:
037:            /*
038:             * @see TestCase#setUp()
039:             */
040:            protected void setUp() throws Exception {
041:                super .setUp();
042:            }
043:
044:            /*
045:             * @see TestCase#tearDown()
046:             */
047:            protected void tearDown() throws Exception {
048:                super .tearDown();
049:            }
050:
051:            /**
052:             * Method testForDuplicateElements.
053:             *
054:             * This test is to check that there are no constants with the same values. This
055:             * method collates the required data and then calls another resuable method to do the
056:             * final checking
057:             */
058:
059:            public void testForDuplicateElements() throws Exception {
060:
061:                Class c = RepositoryElements.class;
062:                Field[] fields = c.getDeclaredFields();
063:
064:                //  make a string array of all the field values
065:                String[] fieldvalues = new String[fields.length];
066:
067:                for (int i = 0; i < fields.length; i++) {
068:                    try {
069:                        fieldvalues[i] = c
070:                                .getDeclaredField(fields[i].getName()).get(
071:                                        fields[i]).toString();
072:                    } catch (IllegalAccessException e) {
073:                        System.out.println(e);
074:                        throw e;
075:                    } catch (NoSuchFieldException e) {
076:                        System.out.println("No such field " + fields[i] + " "
077:                                + e);
078:                        throw e;
079:                    }
080:                }
081:
082:                Arrays.sort(fieldvalues);
083:
084:                try {
085:                    checkForDuplicateConstant(fieldvalues);
086:                    assertTrue(true);
087:                } catch (DuplicateRepositoryElementsFound e) {
088:                    // Constants with similar values found
089:                    fail(e.getMessage()
090:                            + "\n All the constants values in string sort order that i read are -> \n"
091:                            + fieldValuesToString(fieldvalues));
092:
093:                }
094:
095:            }
096:
097:            private String fieldValuesToString(String[] fieldvalues) {
098:                StringBuffer result = new StringBuffer(100);
099:
100:                for (int i = 0; i < fieldvalues.length; i++) {
101:                    result.append(fieldvalues[i].toString()).append(',');
102:                }
103:
104:                return result.substring(0, ((result.length()) - 1));
105:            }
106:
107:            /**
108:             * Method checkForDuplicateConstant.: This method checks for duplicate constant
109:             * values
110:             * @param fieldvalues
111:             * @throws DuplicateRepositoryElementsFound
112:             */
113:            private void checkForDuplicateConstant(String[] fieldvalues)
114:                    throws DuplicateRepositoryElementsFound {
115:                for (int i = 1; i < fieldvalues.length; i++) {
116:                    if (fieldvalues[i - 1].equals(fieldvalues[i])) {
117:                        throw new DuplicateRepositoryElementsFound(
118:                                fieldvalues[i]);
119:                    }
120:                }
121:            }
122:
123:        }
124:
125:        /**
126:         * This exception is for the case when constants with
127:         * similar values are found in the RepositoryElements class
128:         */
129:
130:        class DuplicateRepositoryElementsFound extends Exception {
131:
132:            /* (non-Javadoc)
133:             * @see java.lang.Throwable#Throwable(java.lang.String)
134:             */
135:            public DuplicateRepositoryElementsFound(String errorMsg) {
136:                super ("Duplicate value of " + errorMsg + " found");
137:            }
138:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.