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