Source Code Cross Referenced for DNAAttributeInterceptorTestCase.java in  » Inversion-of-Control » DNA » org » codehaus » dna » tools » metaclass » 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 » Inversion of Control » DNA » org.codehaus.dna.tools.metaclass 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (C) The DNA Group. All rights reserved.
003:         *
004:         * This software is published under the terms of the DNA
005:         * Software License version 1.1, a copy of which has been included
006:         * with this distribution in the LICENSE.txt file.
007:         */
008:        package org.codehaus.dna.tools.metaclass;
009:
010:        import com.thoughtworks.qdox.model.JavaMethod;
011:        import java.util.Properties;
012:        import junit.framework.TestCase;
013:
014:        import org.codehaus.dna.tools.metaclass.DNAAttributeInterceptor;
015:        import org.codehaus.metaclass.model.Attribute;
016:
017:        /**
018:         *
019:         * @author Peter Donald
020:         * @version $Revision: 1.2 $ $Date: 2004/05/01 09:51:48 $
021:         */
022:        public class DNAAttributeInterceptorTestCase extends TestCase {
023:            public void testProcessClassAttributeWithoutTransformations()
024:                    throws Exception {
025:                final DNAAttributeInterceptor interceptor = new DNAAttributeInterceptor();
026:                final Attribute attribute = new Attribute("ignored");
027:                final Attribute result = interceptor.processClassAttribute(
028:                        new MockJavaClass(), attribute);
029:                assertNotNull("attribute", result);
030:                assertEquals("attribute.name", "ignored", result.getName());
031:                assertEquals("attribute.value", null, result.getValue());
032:                assertEquals("attribute.parameterCount", 0, result
033:                        .getParameterCount());
034:            }
035:
036:            public void testProcessClassAttributeWithDNAService()
037:                    throws Exception {
038:                final DNAAttributeInterceptor interceptor = new DNAAttributeInterceptor();
039:                final Properties parameters = new Properties();
040:                parameters.setProperty("type", "X");
041:                final Attribute attribute = new Attribute("dna.service",
042:                        parameters);
043:                final Attribute result = interceptor.processClassAttribute(
044:                        new MockJavaClass(), attribute);
045:                assertNotNull("attribute", result);
046:                assertEquals("attribute.name", "dna.service", result.getName());
047:                assertEquals("attribute.value", null, result.getValue());
048:                assertEquals("attribute.parameterCount", 1, result
049:                        .getParameterCount());
050:                assertEquals("attribute.parameter(type)", MockJavaSource.PREFIX
051:                        + "X", result.getParameter("type"));
052:            }
053:
054:            public void testProcessClassAttributeWithDNAServiceMissingType()
055:                    throws Exception {
056:                final DNAAttributeInterceptor interceptor = new DNAAttributeInterceptor();
057:                final Attribute attribute = new Attribute("dna.service");
058:                try {
059:                    final MockJavaClass clazz = new MockJavaClass();
060:                    clazz.setName("Blah");
061:                    interceptor.processClassAttribute(clazz, attribute);
062:                } catch (final IllegalArgumentException iae) {
063:                    return;
064:                }
065:                fail("Expected to fail to process dna.service "
066:                        + "attribute missing type parameter");
067:            }
068:
069:            public void testProcessMethodAttributeWithDNAConfigurationWith()
070:                    throws Exception {
071:                final DNAAttributeInterceptor interceptor = new DNAAttributeInterceptor();
072:                final Attribute attribute = new Attribute("ignored");
073:                final Attribute result = interceptor.processMethodAttribute(
074:                        new JavaMethod(), attribute);
075:                assertNotNull("attribute", result);
076:                assertEquals("attribute.name", "ignored", result.getName());
077:                assertEquals("attribute.value", null, result.getValue());
078:                assertEquals("attribute.parameterCount", 0, result
079:                        .getParameterCount());
080:            }
081:
082:            public void testProcessMethodAttributeWithoutTransformations()
083:                    throws Exception {
084:                final DNAAttributeInterceptor interceptor = new DNAAttributeInterceptor();
085:                final Attribute attribute = new Attribute("ignored");
086:                final Attribute result = interceptor.processMethodAttribute(
087:                        new JavaMethod(), attribute);
088:                assertNotNull("attribute", result);
089:                assertEquals("attribute.name", "ignored", result.getName());
090:                assertEquals("attribute.value", null, result.getValue());
091:                assertEquals("attribute.parameterCount", 0, result
092:                        .getParameterCount());
093:            }
094:
095:            public void testProcessMethodForConfiguration() throws Exception {
096:                final DNAAttributeInterceptor interceptor = new DNAAttributeInterceptor();
097:
098:                final MockJavaClass clazz = new MockJavaClass();
099:                clazz.setName("Blah");
100:
101:                final JavaMethod javaMethod = new JavaMethod();
102:                javaMethod.setParentClass(clazz);
103:                final Attribute attribute = new Attribute("dna.configuration");
104:                final Attribute result = interceptor.processMethodAttribute(
105:                        javaMethod, attribute);
106:                assertNotNull("attribute", result);
107:                assertEquals("attribute.name", "dna.configuration", result
108:                        .getName());
109:                assertEquals("attribute.value", null, result.getValue());
110:                assertEquals("attribute.parameterCount", 1, result
111:                        .getParameterCount());
112:                assertEquals("attribute.parameter(location)",
113:                        "Blah-schema.xml", result.getParameter("location"));
114:            }
115:
116:            public void testProcessMethodForParameters() throws Exception {
117:                final DNAAttributeInterceptor interceptor = new DNAAttributeInterceptor();
118:
119:                final MockJavaClass clazz = new MockJavaClass();
120:                clazz.setName("Blah");
121:
122:                final JavaMethod javaMethod = new JavaMethod();
123:                javaMethod.setParentClass(clazz);
124:                final Attribute attribute = new Attribute("dna.parameters");
125:                final Attribute result = interceptor.processMethodAttribute(
126:                        javaMethod, attribute);
127:                assertNotNull("attribute", result);
128:                assertEquals("attribute.name", "dna.parameters", result
129:                        .getName());
130:                assertEquals("attribute.value", null, result.getValue());
131:                assertEquals("attribute.parameterCount", 1, result
132:                        .getParameterCount());
133:                assertEquals("attribute.parameter(location)",
134:                        "Blah-schema.xml", result.getParameter("location"));
135:            }
136:
137:            public void testProcessMethodForDependencySpecifyingOptionalAttribute()
138:                    throws Exception {
139:                final DNAAttributeInterceptor interceptor = new DNAAttributeInterceptor();
140:                final Properties parameters = new Properties();
141:                parameters.setProperty("type", "Foo");
142:                parameters.setProperty("optional", "true");
143:                final Attribute attribute = new Attribute("dna.dependency",
144:                        parameters);
145:                final JavaMethod method = new JavaMethod();
146:                method.setParentClass(new MockJavaClass());
147:                final Attribute result = interceptor.processMethodAttribute(
148:                        method, attribute);
149:                assertNotNull("attribute", result);
150:                assertEquals("attribute.name", "dna.dependency", result
151:                        .getName());
152:                assertEquals("attribute.value", null, result.getValue());
153:                assertEquals("attribute.parameterCount", 3, result
154:                        .getParameterCount());
155:                assertEquals("attribute.parameter(type)", MockJavaSource.PREFIX
156:                        + "Foo", result.getParameter("type"));
157:                assertEquals("attribute.parameter(key)", MockJavaSource.PREFIX
158:                        + "Foo", result.getParameter("key"));
159:                assertEquals("attribute.parameter(optional)", "true", result
160:                        .getParameter("optional"));
161:            }
162:
163:            public void testProcessMethodForDependencyNotSpecifyingType()
164:                    throws Exception {
165:                final DNAAttributeInterceptor interceptor = new DNAAttributeInterceptor();
166:                final Properties parameters = new Properties();
167:                final Attribute attribute = new Attribute("dna.dependency",
168:                        parameters);
169:                final JavaMethod method = new JavaMethod();
170:                method.setParentClass(new MockJavaClass());
171:                try {
172:                    interceptor.processMethodAttribute(method, attribute);
173:                } catch (final IllegalArgumentException iae) {
174:                    return;
175:                }
176:                fail("Expected to fail as dna.dependency is missing typ[e parameter");
177:            }
178:
179:            public void testProcessMethodForDependencySpecifyingJustType()
180:                    throws Exception {
181:                final DNAAttributeInterceptor interceptor = new DNAAttributeInterceptor();
182:                final Properties parameters = new Properties();
183:                parameters.setProperty("type", "Foo");
184:                final Attribute attribute = new Attribute("dna.dependency",
185:                        parameters);
186:                final JavaMethod method = new JavaMethod();
187:                method.setParentClass(new MockJavaClass());
188:                final Attribute result = interceptor.processMethodAttribute(
189:                        method, attribute);
190:                assertNotNull("attribute", result);
191:                assertEquals("attribute.name", "dna.dependency", result
192:                        .getName());
193:                assertEquals("attribute.value", null, result.getValue());
194:                assertEquals("attribute.parameterCount", 3, result
195:                        .getParameterCount());
196:                assertEquals("attribute.parameter(type)", MockJavaSource.PREFIX
197:                        + "Foo", result.getParameter("type"));
198:                assertEquals("attribute.parameter(key)", MockJavaSource.PREFIX
199:                        + "Foo", result.getParameter("key"));
200:                assertEquals("attribute.parameter(optional)", "false", result
201:                        .getParameter("optional"));
202:            }
203:
204:            public void testProcessConfigurationAttributeWithoutLocationOrType()
205:                    throws Exception {
206:                final DNAAttributeInterceptor interceptor = new DNAAttributeInterceptor();
207:
208:                final MockJavaClass clazz = new MockJavaClass();
209:                clazz.setName("Blah");
210:
211:                final Attribute attribute = new Attribute("dna.configuration");
212:                final Attribute result = interceptor
213:                        .processConfigurationAttribute(clazz, attribute);
214:                assertNotNull("attribute", result);
215:                assertEquals("attribute.name", "dna.configuration", result
216:                        .getName());
217:                assertEquals("attribute.value", null, result.getValue());
218:                assertEquals("attribute.parameterCount", 1, result
219:                        .getParameterCount());
220:                assertEquals("attribute.parameter(location)",
221:                        "Blah-schema.xml", result.getParameter("location"));
222:            }
223:
224:            public void testProcessConfigurationAttributeWithLocation()
225:                    throws Exception {
226:                final DNAAttributeInterceptor interceptor = new DNAAttributeInterceptor();
227:
228:                final MockJavaClass clazz = new MockJavaClass();
229:                clazz.setName("Blah");
230:
231:                final Properties parameters = new Properties();
232:                parameters.setProperty("location", "Meep.xml");
233:                final Attribute attribute = new Attribute("dna.configuration",
234:                        parameters);
235:                final Attribute result = interceptor
236:                        .processConfigurationAttribute(clazz, attribute);
237:                assertNotNull("attribute", result);
238:                assertEquals("attribute.name", "dna.configuration", result
239:                        .getName());
240:                assertEquals("attribute.value", null, result.getValue());
241:                assertEquals("attribute.parameterCount", 1, result
242:                        .getParameterCount());
243:                assertEquals("attribute.parameter(location)", "Meep.xml",
244:                        result.getParameter("location"));
245:            }
246:
247:            public void testProcessConfigurationAttributeWithType()
248:                    throws Exception {
249:                final DNAAttributeInterceptor interceptor = new DNAAttributeInterceptor();
250:
251:                final MockJavaClass clazz = new MockJavaClass();
252:                clazz.setName("Blah");
253:
254:                final Properties parameters = new Properties();
255:                parameters.setProperty("type", "MeepSchemaLanguage");
256:                final Attribute attribute = new Attribute("dna.configuration",
257:                        parameters);
258:                final Attribute result = interceptor
259:                        .processConfigurationAttribute(clazz, attribute);
260:                assertNotNull("attribute", result);
261:                assertEquals("attribute.name", "dna.configuration", result
262:                        .getName());
263:                assertEquals("attribute.value", null, result.getValue());
264:                assertEquals("attribute.parameterCount", 2, result
265:                        .getParameterCount());
266:                assertEquals("attribute.parameter(location)",
267:                        "Blah-schema.xml", result.getParameter("location"));
268:                assertEquals("attribute.parameter(type)", "MeepSchemaLanguage",
269:                        result.getParameter("type"));
270:            }
271:
272:            public void testDetermineKeyWhenNothingSpecified() throws Exception {
273:                final DNAAttributeInterceptor interceptor = new DNAAttributeInterceptor();
274:                final Properties parameters = new Properties();
275:                final Attribute attribute = new Attribute("dna.dependency",
276:                        parameters);
277:                final String key = interceptor.determineKey(attribute,
278:                        "com.biz.Foo");
279:                assertEquals("key", "com.biz.Foo", key);
280:            }
281:
282:            public void testDetermineKeyWhenQualifierSpecified()
283:                    throws Exception {
284:                final DNAAttributeInterceptor interceptor = new DNAAttributeInterceptor();
285:                final Properties parameters = new Properties();
286:                parameters.setProperty("qualifier", "x");
287:                final Attribute attribute = new Attribute("dna.dependency",
288:                        parameters);
289:                final String key = interceptor.determineKey(attribute,
290:                        "com.biz.Foo");
291:                assertEquals("key", "com.biz.Foo/x", key);
292:            }
293:
294:            public void testDetermineKeyWhenKeySpecified() throws Exception {
295:                final DNAAttributeInterceptor interceptor = new DNAAttributeInterceptor();
296:                final Properties parameters = new Properties();
297:                parameters.setProperty("key", "x");
298:                final Attribute attribute = new Attribute("dna.dependency",
299:                        parameters);
300:                final String key = interceptor.determineKey(attribute,
301:                        "com.biz.Foo");
302:                assertEquals("key", "x", key);
303:            }
304:
305:            public void testGetSchemaLocationForClassInDefaultPackage()
306:                    throws Exception {
307:                final DNAAttributeInterceptor interceptor = new DNAAttributeInterceptor();
308:                final String location = interceptor.getSchemaLocationFor("Foo");
309:                assertEquals("location", "Foo-schema.xml", location);
310:            }
311:
312:            public void testGetSchemaLocationForClassInNonDefaultPackage()
313:                    throws Exception {
314:                final DNAAttributeInterceptor interceptor = new DNAAttributeInterceptor();
315:                final String location = interceptor
316:                        .getSchemaLocationFor("com.biz.Foo");
317:                assertEquals("location", "Foo-schema.xml", location);
318:            }
319:
320:            public void testResolveType() throws Exception {
321:                final DNAAttributeInterceptor interceptor = new DNAAttributeInterceptor();
322:                final String type = interceptor.resolveType(
323:                        new MockJavaClass(), "X");
324:                assertEquals("type", MockJavaSource.PREFIX + "X", type);
325:            }
326:
327:            public void testResolveTypeOnArray() throws Exception {
328:                final DNAAttributeInterceptor interceptor = new DNAAttributeInterceptor();
329:                final String type = interceptor.resolveType(
330:                        new MockJavaClass(), "X[]");
331:                assertEquals("type", MockJavaSource.PREFIX + "X[]", type);
332:            }
333:
334:            public void testResolveTypeOnMap() throws Exception {
335:                final DNAAttributeInterceptor interceptor = new DNAAttributeInterceptor();
336:                final String type = interceptor.resolveType(
337:                        new MockJavaClass(), "X{}");
338:                assertEquals("type", MockJavaSource.PREFIX + "X{}", type);
339:            }
340:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.