View Javadoc

1   package test.crispy;
2   
3   import java.util.Hashtable;
4   import java.util.Map;
5   
6   import test.crispy.example.service.Calculator;
7   
8   import net.sf.crispy.InvocationStrategy;
9   import net.sf.crispy.strategy.ClassMethodMapInvocationStrategy;
10  import net.sf.crispy.strategy.ClassWithOutPackageInvocationStrategy;
11  import net.sf.crispy.strategy.NameSpacePlusMethodInvocationStrategy;
12  import net.sf.crispy.strategy.UrlPlusClassNameInvocationStrategy;
13  import junit.framework.TestCase;
14  
15  public class InvocationStrategyTest extends TestCase {
16  	
17  	public void testInvocationStrategyClassPlusMethod() throws Exception {
18  		InvocationStrategy lvInvocationStrategy = new NameSpacePlusMethodInvocationStrategy();
19  		Map lvPropertyMap = new Hashtable();
20  		lvPropertyMap.put(InvocationStrategy.CLASS_NAME, Calculator.class.getName());
21  		lvPropertyMap.put(InvocationStrategy.METHOD_NAME, "add");
22  		String lvResult = lvInvocationStrategy.convert(lvPropertyMap).toString();
23  		assertEquals(lvResult, Calculator.class.getName() + ".add");
24  	}
25  
26  	public void testInvocationStrategyNameSpacePlusMethod() throws Exception {
27  		InvocationStrategy lvInvocationStrategy = new NameSpacePlusMethodInvocationStrategy();
28  		Map lvPropertyMap = new Hashtable();
29  		lvPropertyMap.put(InvocationStrategy.CONST_NAMESPACE, "namespace");
30  		lvPropertyMap.put(InvocationStrategy.METHOD_NAME, "add");
31  		String lvResult = lvInvocationStrategy.convert(lvPropertyMap).toString();
32  		assertEquals(lvResult, "namespace.add");
33  	}
34  
35  	public void testInvocationStrategyUrlPlusClassName() throws Exception {
36  		InvocationStrategy lvInvocationStrategy = new UrlPlusClassNameInvocationStrategy();
37  		Map lvPropertyMap = new Hashtable();
38  		String lvUrl = "";
39  		lvPropertyMap.put(InvocationStrategy.URL, lvUrl);
40  		lvPropertyMap.put(InvocationStrategy.CLASS_NAME, Calculator.class.getName());
41  		String lvResult = lvInvocationStrategy.convert(lvPropertyMap).toString();
42  		assertEquals(lvResult, lvUrl + "/Calculator");
43  	}
44  	
45  	public void testInvocationStrategyClassMethodMap() throws Exception {
46  		ClassMethodMapInvocationStrategy lvInvocationStrategy = new ClassMethodMapInvocationStrategy();
47  		Map lvPropertyMap = new Hashtable();
48  		lvPropertyMap.put(InvocationStrategy.METHOD_NAME, "add");
49  		lvPropertyMap.put(InvocationStrategy.CLASS_NAME, Calculator.class.getName());
50  		Map lvMap = (Map) lvInvocationStrategy.convert(lvPropertyMap);
51  		assertEquals(lvMap.get(Calculator.class.getName()), "add");		
52  	}
53  	
54  	public void testInvocationStrategyClassWithOutPackage() throws Exception {
55  		ClassWithOutPackageInvocationStrategy lvStrategy = new ClassWithOutPackageInvocationStrategy();
56  		Map lvPropertyMap = new Hashtable();
57  		lvPropertyMap.put(InvocationStrategy.CLASS_NAME, Calculator.class.getName());
58  		String lvResult = (String) lvStrategy.convert(lvPropertyMap);
59  		assertEquals(lvResult, "Calculator");
60  	}
61  	
62  }