1   /*
2    * Copyright 2001-2004 The Apache Software Foundation.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */ 
16   
17  package org.apache.commons.betwixt.expression;
18  
19  import java.lang.reflect.Method;
20  
21  import junit.framework.Test;
22  import junit.framework.TestSuite;
23  
24  import org.apache.commons.betwixt.AbstractTestCase;
25  
26  /*** Test harness for map updating 
27    *
28    * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
29    * @version $Revision: 1.4 $
30    */
31  public class TestUpdaters extends AbstractTestCase {
32      
33      public static Test suite() {
34          return new TestSuite(TestUpdaters.class);
35      }
36      
37      public TestUpdaters(String testName) {
38          super(testName);
39      }
40      
41      public void testMapUpdate() throws Exception {	
42          Class[] params = { String.class, String.class } ;
43          Method method = AdderBean.class.getMethod("add", params);
44          MapEntryAdder adder = new MapEntryAdder(method);
45          
46          AdderBean bean = new AdderBean();
47          bean.add("UNSET", "UNSET");
48          
49          Updater keyUpdater = adder.getKeyUpdater();
50          Updater valueUpdater = adder.getValueUpdater();
51          
52          Context context = new Context();
53          context.setBean(bean);
54          
55          keyUpdater.update(context, "key");
56          valueUpdater.update(context, "value");
57          
58          assertEquals("AdderBean not updated (1)", "key", bean.getKey());
59          assertEquals("AdderBean not updated (2)", "value", bean.getValue());
60          
61          keyUpdater.update(context, "new-key");
62          valueUpdater.update(context, "new-value");
63          
64          assertEquals("AdderBean not updated (1)", "new-key", bean.getKey());
65          assertEquals("AdderBean not updated (2)", "new-value", bean.getValue());        
66          
67      }
68  }
69