1
2
3
4
5
6
7
8 package org.codehaus.metaclass.tools.tasks;
9
10 import java.util.Collection;
11 import junit.framework.TestCase;
12 import org.apache.tools.ant.BuildException;
13 import org.apache.tools.ant.types.Reference;
14
15 /***
16 * @author Peter Donald
17 * @version $Revision: 1.4 $ $Date: 2003/11/29 00:27:42 $
18 */
19 public class PluginSetTestCase
20 extends TestCase
21 {
22 public void testAddPluginWithNullName()
23 throws Exception
24 {
25 final PluginElement element = new PluginElement();
26 final FilterSet set = new FilterSet();
27 try
28 {
29 set.addFilter( element );
30 set.toPlugins();
31 }
32 catch( BuildException e )
33 {
34 return;
35 }
36 fail( "Expected to fail due to badly specified element" );
37 }
38
39 public void testAddSinglePlugin()
40 throws Exception
41 {
42 final PluginElement element = new PluginElement();
43 element.setName( "foo" );
44 final FilterSet set = new FilterSet();
45 set.addFilter( element );
46 final Collection collection = set.toPlugins();
47 assertEquals( "collection.size()", 1, collection.size() );
48 assertEquals( "collection(0)",
49 element,
50 collection.iterator().next() );
51 }
52
53 public void testAddSinglePluginSet()
54 throws Exception
55 {
56 final PluginElement element = new PluginElement();
57 element.setName( "foo" );
58 final FilterSet set = new FilterSet();
59 set.addFilter( element );
60 final FilterSet parent = new FilterSet();
61 parent.addFilterSet( set );
62 final Collection collection = parent.toPlugins();
63 assertEquals( "collection.size()", 1, collection.size() );
64 assertEquals( "collection(0)",
65 element,
66 collection.iterator().next() );
67 }
68
69 public void testSetRefID()
70 throws Exception
71 {
72 final PluginElement element = new PluginElement();
73 element.setName( "foo" );
74 final FilterSet set = new FilterSet();
75 set.addFilter( element );
76 final FilterSet parent = new FilterSet();
77 final MockProject project = new MockProject();
78 project.bindReference( "bar", set );
79 parent.setProject( project );
80 parent.setRefid( new Reference( "bar" ) );
81
82 final Collection collection = parent.toPlugins();
83 assertEquals( "collection.size()", 1, collection.size() );
84 assertEquals( "collection(0)",
85 element,
86 collection.iterator().next() );
87 }
88
89 public void testSetRefIDOnBadType()
90 throws Exception
91 {
92 final FilterSet parent = new FilterSet();
93 final MockProject project = new MockProject();
94 project.bindReference( "bar", new Object() );
95 parent.setProject( project );
96 try
97 {
98 parent.setRefid( new Reference( "bar" ) );
99 }
100 catch( final BuildException be )
101 {
102 return;
103 }
104 fail( "Expected build exception due to bad type" );
105 }
106
107 public void testSetRefIDWithPluginAdded()
108 throws Exception
109 {
110
111 final InterceptorSet parent = new InterceptorSet();
112 final PluginElement element = new PluginElement();
113 element.setName( "foo" );
114 parent.addInterceptor( element );
115 parent.addInterceptorSet( new InterceptorSet() );
116 final MockProject project = new MockProject();
117 project.bindReference( "bar", new InterceptorSet() );
118 parent.setProject( project );
119 try
120 {
121 parent.setRefid( new Reference( "bar" ) );
122 }
123 catch( final BuildException be )
124 {
125 return;
126 }
127 fail( "Expected build exception due to too many attributes" );
128 }
129
130 public void testNullTypePassedToCtor()
131 throws Exception
132 {
133 try
134 {
135 new MalformedPluginSet();
136 }
137 catch( final NullPointerException npe )
138 {
139 assertEquals( "npe.getMessage()", "type", npe.getMessage() );
140 return;
141 }
142 fail( "Expected to fail due to null Type passed into Ctor" );
143 }
144
145 }