Source Code Cross Referenced for MetadataTest.java in  » J2EE » ICEfaces-1.6.1 » com » icesoft » jsfmeta » 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 » ICEfaces 1.6.1 » com.icesoft.jsfmeta 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * MetadataTest.java
003:         *
004:         * Created on June 13, 2007, 11:59 AM
005:         *
006:         * To change this template, choose Tools | Template Manager
007:         * and open the template in the editor.
008:         */
009:
010:        package com.icesoft.jsfmeta;
011:
012:        import com.sun.rave.jsfmeta.beans.ComponentBean;
013:        import com.sun.rave.jsfmeta.beans.FacesConfigBean;
014:        import com.sun.rave.jsfmeta.beans.PropertyBean;
015:        import java.io.File;
016:        import java.io.IOException;
017:        import java.net.URL;
018:        import junit.framework.Test;
019:        import junit.framework.TestCase;
020:        import junit.framework.TestSuite;
021:        import org.xml.sax.SAXException;
022:
023:        /**
024:         *
025:         * @author frank
026:         */
027:        public class MetadataTest extends TestCase {
028:
029:            private String METADATA_XML = "extended-faces-config.xml";
030:            private FacesConfigBean facesConfigBean;
031:
032:            public static Test suite() {
033:                return new TestSuite(MetadataTest.class);
034:            }
035:
036:            public static void main() {
037:                junit.textui.TestRunner.run(MetadataTest.suite());
038:            }
039:
040:            protected void setUp() {
041:
042:                File confFile = getConfDir();
043:                boolean isConfFile = confFile.isDirectory();
044:                if (!isConfFile) {
045:                    System.out
046:                            .println("no conf directory in the build directory: "
047:                                    + confFile);
048:                    if (!confFile.mkdirs())
049:                        System.out
050:                                .println("conf directory could not be created");
051:                }
052:                MetadataXmlParser jsfMetaParser = new MetadataXmlParser();
053:                String filePath = confFile.getPath() + File.separatorChar
054:                        + METADATA_XML;
055:                try {
056:                    facesConfigBean = jsfMetaParser.parse(new File(filePath));
057:
058:                } catch (SAXException ex) {
059:                    ex.printStackTrace();
060:                } catch (IOException ex) {
061:                    ex.printStackTrace();
062:                }
063:            }
064:
065:            public void testMetadata() {
066:
067:                ComponentBean[] componentBeans = facesConfigBean
068:                        .getComponents();
069:                for (int i = 0; i < componentBeans.length; i++) {
070:                    PropertyBean[] propertyBeans = componentBeans[i]
071:                            .getProperties();
072:                    for (int j = 0; j < propertyBeans.length; j++) {
073:                        if (propertyBeans[j].getPropertyClass() != null
074:                                && propertyBeans[j].getPropertyClass().trim()
075:                                        .equalsIgnoreCase("boolean")) {
076:                            if (propertyBeans[j].getEditorClass() != null) {
077:                                boolean flag = propertyBeans[j]
078:                                        .getEditorClass().trim().length() > 0;
079:                                assertFalse("\ncomponent class="
080:                                        + componentBeans[i].getComponentClass()
081:                                        + "\ncomponent type="
082:                                        + componentBeans[i].getComponentType()
083:                                        + " has boolean property named="
084:                                        + propertyBeans[j].getPropertyName()
085:                                        + " \nusing wrong editor="
086:                                        + propertyBeans[j].getEditorClass(),
087:                                        flag);
088:                            }
089:                        }
090:                    }
091:                    ;
092:                }
093:            }
094:
095:            private File getConfDir() {
096:
097:                ClassLoader classLoader = Thread.currentThread()
098:                        .getContextClassLoader();
099:                URL url = classLoader.getResource(".");
100:
101:                File buildDir = new File(convertFileUrlToPath(url));
102:
103:                if (!buildDir.isDirectory()) {
104:                    System.out.println("test build directory does not exist: "
105:                            + buildDir);
106:                    System.exit(1);
107:                }
108:
109:                File confFile = new File(buildDir.getParent()
110:                        + File.separatorChar + "classes" + File.separator
111:                        + "conf");
112:
113:                return confFile;
114:            }
115:
116:            /**
117:             * Kind of hack-ish attempt at solving problem that if the directory,
118:             *  where we're building the component-metadata in,  has special
119:             *  characters in its path, like spaces, then the URL to it will be
120:             *  escaped, which will be interpretted as a different directory,
121:             *  unless we unescape it.
122:             */
123:            private static String convertFileUrlToPath(URL url) {
124:
125:                String path = url.getPath();
126:                if (url.toExternalForm().startsWith("file:")) {
127:                    StringBuffer sb = new StringBuffer(path.length());
128:                    int pathLength = path.length();
129:                    for (int i = 0; i < pathLength;) {
130:                        char c = path.charAt(i);
131:                        if (c == '%') {
132:                            if ((i + 1) < pathLength
133:                                    && isHexDigit(path.charAt(i + 1))) {
134:                                int increment = 2;
135:                                if ((i + 2) < pathLength
136:                                        && isHexDigit(path.charAt(i + 2)))
137:                                    increment++;
138:                                try {
139:                                    char unescaped = (char) Integer.parseInt(
140:                                            path
141:                                                    .substring(i + 1, i
142:                                                            + increment), 16);
143:
144:                                    sb.append(unescaped);
145:                                    i += increment;
146:                                    continue;
147:                                } catch (NumberFormatException nfe) {
148:                                    // Not a valid hex escape, so just fall through,
149:                                    //  and append it to the path
150:                                }
151:                            }
152:                        }
153:                        sb.append(c);
154:                        i++;
155:                    }
156:                    path = sb.toString();
157:                }
158:                return path;
159:            }
160:
161:            private static boolean isHexDigit(char c) {
162:                return ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z'));
163:            }
164:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.