Source Code Cross Referenced for CruiseControlConfigIncludeTest.java in  » Build » cruisecontrol » net » sourceforge » cruisecontrol » 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 » Build » cruisecontrol » net.sourceforge.cruisecontrol 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package net.sourceforge.cruisecontrol;
002:
003:        import java.io.ByteArrayInputStream;
004:        import java.io.InputStream;
005:
006:        import junit.framework.TestCase;
007:        import net.sourceforge.cruisecontrol.config.XmlResolver;
008:        import net.sourceforge.cruisecontrol.util.Util;
009:
010:        import org.jdom.Element;
011:
012:        public class CruiseControlConfigIncludeTest extends TestCase {
013:
014:            private Element rootElement;
015:            private Element includeElement;
016:            private XmlResolver resolver;
017:
018:            protected void setUp() throws Exception {
019:                StringBuffer configText = new StringBuffer(200);
020:                configText.append("<cruisecontrol>");
021:                configText.append("  <plugin name='foo.project'");
022:                configText
023:                        .append("  classname='net.sourceforge.cruisecontrol.MockProjectInterface'/>");
024:                configText.append("  <include.projects file='include.xml'/>");
025:                configText.append("  <foo.project name='in.root'/>");
026:                configText.append("</cruisecontrol>");
027:                rootElement = elementFromString(configText.toString());
028:
029:                StringBuffer includeText = new StringBuffer(200);
030:                includeText.append("<cruisecontrol>");
031:                includeText.append("  <foo.project name='in.include'/>");
032:                includeText.append("</cruisecontrol>");
033:                includeElement = elementFromString(includeText.toString());
034:
035:                resolver = new IncludeXmlResolver(includeElement);
036:            }
037:
038:            protected void tearDown() throws Exception {
039:                rootElement = null;
040:                includeElement = null;
041:                resolver = null;
042:            }
043:
044:            public void testShouldLoadIncludedProjects() throws Exception {
045:                CruiseControlConfig config = new CruiseControlConfig(
046:                        rootElement, resolver, null);
047:                assertEquals(2, config.getProjectNames().size());
048:                assertIsFooProject(config.getProject("in.root"));
049:                assertIsFooProject(config.getProject("in.include"));
050:            }
051:
052:            public void testShouldLoadedNestedIncludes() throws Exception {
053:                StringBuffer includeText = new StringBuffer(200);
054:                includeText.append("<cruisecontrol>");
055:                includeText.append("  <include.projects file='include.xml'/>");
056:                includeText.append("  <foo.project name='in.first.include'/>");
057:                includeText.append("</cruisecontrol>");
058:                Element includeWithNestedInclude = elementFromString(includeText
059:                        .toString());
060:
061:                Element[] elements = new Element[2];
062:                elements[0] = includeWithNestedInclude;
063:                elements[1] = includeElement;
064:                resolver = new IncludeXmlResolver(elements);
065:
066:                CruiseControlConfig config = new CruiseControlConfig(
067:                        rootElement, resolver, null);
068:                assertEquals(3, config.getProjectNames().size());
069:                assertIsFooProject(config.getProject("in.root"));
070:                assertIsFooProject(config.getProject("in.first.include"));
071:                assertIsFooProject(config.getProject("in.include"));
072:            }
073:
074:            public void testIncludesCanDefinePlugins()
075:                    throws CruiseControlException {
076:                String newProjectTag = "new.project.type";
077:
078:                Element pluginElement = new Element("plugin");
079:                pluginElement.setAttribute("name", newProjectTag);
080:                pluginElement.setAttribute("classname",
081:                        MockProjectInterface.class.getName());
082:                includeElement.addContent(pluginElement);
083:
084:                Element barElement = new Element(newProjectTag);
085:                barElement.setAttribute("name", "bar");
086:                includeElement.addContent(barElement);
087:
088:                CruiseControlConfig config = new CruiseControlConfig(
089:                        rootElement, resolver, null);
090:                assertEquals(3, config.getProjectNames().size());
091:                assertIsFooProject(config.getProject("bar"));
092:            }
093:
094:            public void testPropertiesShouldBeAvailableToIncludedProjects()
095:                    throws CruiseControlException {
096:                Element property = new Element("property");
097:                property.setAttribute("name", "baz");
098:                property.setAttribute("value", "goo");
099:                rootElement.addContent(property);
100:
101:                Element project = new Element("foo.project");
102:                project.setAttribute("name", "${baz}");
103:                includeElement.addContent(project);
104:
105:                CruiseControlConfig config = new CruiseControlConfig(
106:                        rootElement, resolver);
107:                assertEquals(3, config.getProjectNames().size());
108:                assertIsFooProject(config.getProject("goo"));
109:            }
110:
111:            public void testErrorsInIncludeShouldBeContained()
112:                    throws CruiseControlException {
113:                Element unknownPlugin = new Element("unknown.plugin.error");
114:                includeElement.addContent(unknownPlugin);
115:
116:                CruiseControlConfig config = new CruiseControlConfig(
117:                        rootElement, resolver);
118:                assertEquals(1, config.getProjectNames().size());
119:                assertIsFooProject(config.getProject("in.root"));
120:            }
121:
122:            public void testErrorsParsingIncludeShouldBeContained()
123:                    throws CruiseControlException {
124:                XmlResolver resolverHitsError = new XmlResolver() {
125:                    public Element getElement(String path)
126:                            throws CruiseControlException {
127:                        throw new CruiseControlException("simulate parse error");
128:                    }
129:                };
130:
131:                CruiseControlConfig config = new CruiseControlConfig(
132:                        rootElement, resolverHitsError);
133:                assertEquals(1, config.getProjectNames().size());
134:                assertIsFooProject(config.getProject("in.root"));
135:            }
136:
137:            public void testIncludeFilenameContainsProperty()
138:                    throws CruiseControlException {
139:                XmlResolver includeFOOXmlResolver = new XmlResolver() {
140:                    private final Element includePropertyElement;
141:                    {
142:                        StringBuffer includeText = new StringBuffer(200);
143:                        includeText.append("<cruisecontrol>");
144:                        includeText
145:                                .append("  <foo.project name='in.include.withproperty'/>");
146:                        includeText.append("</cruisecontrol>");
147:                        includePropertyElement = elementFromString(includeText
148:                                .toString());
149:                    }
150:
151:                    public Element getElement(String path)
152:                            throws CruiseControlException {
153:                        assertEquals("include_FOO_.xml", path);
154:                        return includePropertyElement;
155:                    }
156:                };
157:
158:                Element propertyElement = new Element("property");
159:                propertyElement.setAttribute("name", "filenameswitch");
160:                propertyElement.setAttribute("value", "_FOO_");
161:                rootElement.addContent(propertyElement);
162:                rootElement.removeChild("include.projects");
163:                Element includeTagElement = new Element("include.projects");
164:                includeTagElement.setAttribute("file",
165:                        "include${filenameswitch}.xml");
166:                rootElement.addContent(includeTagElement);
167:
168:                CruiseControlConfig config = new CruiseControlConfig(
169:                        rootElement, includeFOOXmlResolver);
170:                assertEquals(2, config.getProjectNames().size());
171:                assertIsFooProject(config.getProject("in.root"));
172:                assertIsFooProject(config.getProject("in.include.withproperty"));
173:            }
174:
175:            public void testIncludeFilenameContainsUnsetProperty()
176:                    throws CruiseControlException {
177:                XmlResolver includeUnknownXmlResolver = new XmlResolver() {
178:                    public Element getElement(String path)
179:                            throws CruiseControlException {
180:                        throw new CruiseControlException(
181:                                "failed to load file []");
182:                    }
183:                };
184:
185:                rootElement.removeChild("include.projects");
186:                Element includeTagElement = new Element("include.projects");
187:                includeTagElement.setAttribute("file",
188:                        "include${filenameswitch}.xml");
189:                rootElement.addContent(includeTagElement);
190:
191:                CruiseControlConfig config = new CruiseControlConfig(
192:                        rootElement, includeUnknownXmlResolver);
193:                assertEquals(1, config.getProjectNames().size());
194:                assertIsFooProject(config.getProject("in.root"));
195:            }
196:
197:            public static Element elementFromString(String text)
198:                    throws CruiseControlException {
199:                InputStream is = new ByteArrayInputStream(text.getBytes());
200:                return Util.loadRootElement(is);
201:            }
202:
203:            private void assertIsFooProject(ProjectInterface project) {
204:                assertNotNull(project);
205:                assertEquals(MockProjectInterface.class.getName(), project
206:                        .getClass().getName());
207:            }
208:
209:            private class IncludeXmlResolver implements  XmlResolver {
210:
211:                private final Element[] includeElements;
212:                private int count = 0;
213:
214:                IncludeXmlResolver(Element element) {
215:                    includeElements = new Element[] { element };
216:                }
217:
218:                IncludeXmlResolver(Element[] elements) {
219:                    includeElements = elements;
220:                }
221:
222:                public Element getElement(String path)
223:                        throws CruiseControlException {
224:                    assertEquals("include.xml", path);
225:                    Element element = includeElements[count];
226:                    count++;
227:                    return element;
228:                }
229:            }
230:
231:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.