1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.springframework.richclient.form.builder.support;
17
18 import java.util.Arrays;
19
20 import junit.framework.TestCase;
21
22 import org.springframework.binding.form.FormModel;
23 import org.springframework.binding.form.support.DefaultFormModel;
24 import org.springframework.binding.value.swing.TestableFormComponentInterceptor;
25 import org.springframework.richclient.form.builder.FormComponentInterceptor;
26
27
28
29
30
31
32 public class ConfigurableFormComponentInterceptorFactoryTests extends TestCase {
33 public void testSettingBothIncludedAndExcludedFormModelIdsMustFail() throws Exception {
34 TestableConfigurableFormComponentInterceptorFactory factory = new TestableConfigurableFormComponentInterceptorFactory();
35
36 factory.setIncludedFormModelIds( new String[] { "included-0", "included-1" } );
37 factory.setExcludedFormModelIds( new String[] { "excluded-0", "excluded-1" } );
38
39 try {
40 factory.afterPropertiesSet();
41 fail( "Should throw IllegalStateException" );
42 } catch( IllegalStateException e ) {
43
44 }
45 }
46
47 public void testSetIncludedFormModelIds() throws Exception {
48 TestableConfigurableFormComponentInterceptorFactory factory = new TestableConfigurableFormComponentInterceptorFactory();
49 factory.setCreateThis( new TestableFormComponentInterceptor() );
50
51 factory.setIncludedFormModelIds( new String[] { "included-0", "included-1" } );
52 factory.afterPropertiesSet();
53
54 assertTrue( Arrays.equals( new String[] { "included-0", "included-1" }, factory.getIncludedFormModelIds() ) );
55
56 DefaultFormModel included = new DefaultFormModel();
57 included.setId( "included-0" );
58 DefaultFormModel excluded = new DefaultFormModel();
59 excluded.setId( "excluded-0" );
60
61 assertNotNull( "FormModel should be included", factory.getInterceptor( included ) );
62 assertNull( "FormModel is not included", factory.getInterceptor( excluded ) );
63 }
64
65 public void testSetExcludedFormModelIds() throws Exception {
66 TestableConfigurableFormComponentInterceptorFactory factory = new TestableConfigurableFormComponentInterceptorFactory();
67 factory.setCreateThis( new TestableFormComponentInterceptor() );
68
69 factory.setExcludedFormModelIds( new String[] { "excluded-0", "excluded-1" } );
70 factory.afterPropertiesSet();
71
72 assertTrue( Arrays.equals( new String[] { "excluded-0", "excluded-1" }, factory.getExcludedFormModelIds() ) );
73
74 DefaultFormModel included = new DefaultFormModel();
75 included.setId( "included-0" );
76 DefaultFormModel excluded = new DefaultFormModel();
77 excluded.setId( "excluded-0" );
78
79 assertNotNull( "FormModel should be included", factory.getInterceptor( included ) );
80 assertNull( "FormModel is not included", factory.getInterceptor( excluded ) );
81 }
82
83 private class TestableConfigurableFormComponentInterceptorFactory extends ConfigurableFormComponentInterceptorFactory {
84 private FormComponentInterceptor createThis;
85 private FormModel lastFormModel;
86
87 protected FormComponentInterceptor createInterceptor( FormModel formModel ) {
88 lastFormModel = formModel;
89 return createThis;
90 }
91
92 public void reset() {
93 createThis = null;
94 lastFormModel = null;
95 }
96
97 public void setCreateThis( FormComponentInterceptor createThis ) {
98 this.createThis = createThis;
99 }
100
101 public void setLastFormModel( FormModel lastFormModel ) {
102 this.lastFormModel = lastFormModel;
103 }
104
105 public FormModel getLastFormModel() {
106 return lastFormModel;
107 }
108 }
109 }