MethodInvokeTest.java 4.1 KB
Newer Older
T
update  
tianqiao 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
package com.ql.util.express.test;

import org.junit.Test;

import com.ql.util.express.DefaultContext;
import com.ql.util.express.ExpressRunner;
import com.ql.util.express.IExpressContext;

/**
 * @author tianqiao
 */
public class MethodInvokeTest {
	
	
	@Test
	public void testNullParameter() throws Exception {
		ExpressRunner runner = new ExpressRunner(false,false);
		
		runner.addFunctionOfClassMethod("getSearchResult", 
				MethodInvokeTest.class.getName(), 
				"getSearchResult", 
				new Class[] {PersonalShopInfo.class}, 
				null);
		
		IExpressContext<String,Object> expressContext = new DefaultContext<String,Object>();		
		try{
			Object r = runner.execute("getSearchResult(null)", 
					expressContext, null, false, false);
			System.out.print("r=" + r);
		}catch(Exception e){
			e.printStackTrace();
			throw new Exception(e);
		}
	}

	@Test
	public void testNullParameter2() throws Exception {
		ExpressRunner runner = new ExpressRunner(false,false);
		
		runner.addFunctionOfClassMethod("getOnlinePersonalShopInfo", 
				MethodInvokeTest.class.getName(), 
				"getOnlinePersonalShopInfo", 
				new Class[] {long.class}, 
				null);
		
		runner.addFunctionOfClassMethod("getSearchResult", 
				MethodInvokeTest.class.getName(), 
				"getSearchResult", 
				new Class[] {PersonalShopInfo.class}, 
				null);
		
		IExpressContext<String,Object> expressContext = new DefaultContext<String,Object>();		
		try{
			Object r = runner.execute("getSearchResult(getOnlinePersonalShopInfo(123L))", 
					expressContext, null, false, false);
			System.out.print("r=" + r);
		}catch(Exception e){
			e.printStackTrace();
			throw new Exception(e);
		}
	}
	
	@Test
	public void testNullParameter3() throws Exception {
		ExpressRunner runner = new ExpressRunner(false,true);
		
		runner.addFunctionOfClassMethod("getOnlinePersonalShopInfo", 
				MethodInvokeTest.class.getName(), 
				"getOnlinePersonalShopInfo", 
				new Class[] {long.class}, 
				null);
		String express = "info = getOnlinePersonalShopInfo(127L);";

		IExpressContext<String,Object> expressContext = new DefaultContext<String,Object>();		
		try{
			Object r = runner.execute(express, 
					expressContext, null, false, false);
			System.out.print("r=" + r);
		}catch(Exception e){
			e.printStackTrace();
			throw new Exception(e);
		}
	}
	
	@Test
	public void testNullParameter4() throws Exception {
		ExpressRunner runner = new ExpressRunner(false,true);
		
		runner.addFunctionOfClassMethod("getOnlinePersonalShopInfo", 
				MethodInvokeTest.class.getName(), 
				"getOnlinePersonalShopInfo", 
				new Class[] {long.class}, 
				null);
		String express = "info = getOnlinePersonalShopInfo(127L);";

		IExpressContext<String,Object> expressContext = new DefaultContext<String,Object>();		
		try{
			Object r = runner.execute(express, 
					expressContext, null, false, false);
			System.out.print("r=" + r);
		}catch(Exception e){
			e.printStackTrace();
			throw new Exception(e);
		}
	}
	
	@Test
	public void testNullParameter5() throws Exception {
		ExpressRunner runner = new ExpressRunner(false,true);
		
		runner.addFunctionOfClassMethod("testVoidMethod", 
				MethodInvokeTest.class.getName(), 
				"testVoidMethod", 
				new Class[] {Long.class}, 
				null);
		String express = "info = testVoidMethod(1L);";

		IExpressContext<String,Object> expressContext = new DefaultContext<String,Object>();		
		try{
			Object r = runner.execute(express, 
					expressContext, null, false, false);
			System.out.println("r=" + r);
		}catch(Exception e){
			e.printStackTrace();
			System.out.println("return void checked success!");
			return;
		}
		throw new Exception("return void exception not checked!");
	}

	
	
	//查找在线的店铺信息
	public PersonalShopInfo getOnlinePersonalShopInfo(long userId) {
		return null;
//		return new PersonalShopInfo();
	}
	
	//搜索引擎返回是否存在改店铺信息
	public boolean getSearchResult(PersonalShopInfo personalInfo) {
		if(personalInfo == null) {
			return false;
		} else {
			return true;
		}
	}
	
	public void testVoidMethod(Long id){
		System.out.println("testVoidMethod");
	}

}

class PersonalShopInfo {
	
}