KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > oddjob > monitor > action > SetPropertyActionTest


1 /*
2  * (c) Rob Gordon 2005
3  */

4 package org.oddjob.monitor.action;
5
6 import junit.framework.TestCase;
7
8 import org.apache.commons.beanutils.BeanUtilsBean;
9 import org.oddjob.arooa.ArooaConstants;
10 import org.oddjob.arooa.ArooaContext;
11 import org.oddjob.arooa.SimpleObjectFactory;
12 import org.oddjob.designer.model.DesignDefinition;
13 import org.oddjob.designer.view.DummyView;
14 import org.oddjob.designer.view.DummyViewFactory;
15 import org.oddjob.monitor.model.ExplorerContext;
16 import org.oddjob.monitor.model.ExplorerModel;
17
18 public class SetPropertyActionTest extends TestCase {
19 // private static final Logger logger = Logger.getLogger(SetPropertyActionTest.class);
20

21     public static class Component {
22         String JavaDoc fruit;
23         public void setFruit(String JavaDoc fruit) {
24             this.fruit = fruit;
25         }
26     }
27     
28     public void testSetProperty() throws Exception JavaDoc {
29         Component component = new Component();
30         
31         SimpleObjectFactory factory = new SimpleObjectFactory();
32         factory.addResource("/org/oddjob/values/types.properties");
33         
34         ArooaContext arooaContext = new ArooaContext();
35         arooaContext.set(ArooaConstants.VALUE_FACTORY, factory);
36         arooaContext.set(ArooaConstants.BEAN_UTILS_BEAN, BeanUtilsBean.getInstance());
37         ExplorerModel explorerModel = new ExplorerModel();
38         explorerModel.setRoot(component);
39         explorerModel.setArooaContext(arooaContext);
40         ExplorerContext ec = new ExplorerContext(explorerModel);
41         
42         SetPropertyAction test = new SetPropertyAction();
43         assertFalse(test.enabled());
44         
45         test.select(component, ec);
46         
47         assertTrue(test.enabled());
48
49         DesignDefinition dd = test.form();
50         
51         DummyView dv = DummyViewFactory.create(dd);
52         
53         dv.get("Name").attribute("fruit");
54         dv.get("Name").attribute("fruit");
55         dv.get("Type").create("value");
56         dv.get("Type").get("Text").attribute("apples");
57         
58         test.action();
59         
60         assertEquals("apples", component.fruit);
61     }
62
63 }
64
Popular Tags