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
14 /***
15 * @author Peter Donald
16 * @version $Revision: 1.3 $ $Date: 2003/11/28 11:14:55 $
17 */
18 public class AddToPluginSetTaskTestCase
19 extends TestCase
20 {
21 public void testNullId()
22 throws Exception
23 {
24 final AddToFilterSetTask task = new AddToFilterSetTask();
25 task.setDest( null );
26 task.setSource( "boo" );
27 try
28 {
29 task.validate();
30 }
31 catch( final BuildException e )
32 {
33 return;
34 }
35 fail( "Expected to fail due to null id" );
36 }
37
38 public void testNullRefid()
39 throws Exception
40 {
41 final AddToInterceptorSetTask task = new AddToInterceptorSetTask();
42 task.setDest( "blah" );
43 task.setSource( null );
44 try
45 {
46 task.validate();
47 }
48 catch( final BuildException e )
49 {
50 return;
51 }
52 fail( "Expected to fail due to null id" );
53 }
54
55 public void testBadTypeofID()
56 throws Exception
57 {
58 final AddToInterceptorSetTask task = new AddToInterceptorSetTask();
59 final MockProject project = new MockProject();
60 project.bindReference( "myid", new FilterSet() );
61 project.bindReference( "myrefid", new InterceptorSet() );
62 task.setProject( project );
63 task.setDest( "myid" );
64 task.setSource( "myrefid" );
65 try
66 {
67 task.execute();
68 }
69 catch( final BuildException e )
70 {
71 return;
72 }
73 fail( "Expected to fail due to id referencing bad type" );
74 }
75
76 public void testBadTypeofRefID()
77 throws Exception
78 {
79 final AddToInterceptorSetTask task = new AddToInterceptorSetTask();
80 final MockProject project = new MockProject();
81 project.bindReference( "myid", new InterceptorSet() );
82 project.bindReference( "myrefid", new FilterSet() );
83 task.setProject( project );
84 task.setDest( "myid" );
85 task.setSource( "myrefid" );
86 try
87 {
88 task.execute();
89 }
90 catch( final BuildException e )
91 {
92 return;
93 }
94 fail( "Expected to fail due to refid referencing bad type" );
95 }
96
97 public void testSuccess()
98 throws Exception
99 {
100 final AddToInterceptorSetTask task = new AddToInterceptorSetTask();
101 final MockProject project = new MockProject();
102 final InterceptorSet id = new InterceptorSet();
103 project.bindReference( "myid", id );
104 final InterceptorSet refid = new InterceptorSet();
105 final PluginElement element = new PluginElement();
106 element.setName( "foo" );
107 refid.addInterceptor( element );
108 project.bindReference( "myrefid", refid );
109 task.setProject( project );
110 task.setDest( "myid" );
111 task.setSource( "myrefid" );
112 task.execute();
113
114 final Collection collection = id.toPlugins();
115 assertEquals( "plugins.length", 1, collection.size() );
116 assertEquals( "plugins(0)",
117 element,
118 collection.iterator().next() );
119 }
120 }