package com.manage;

import com.manage.dao.Power_MenuMapper;
import com.manage.dao.T_MenuMapper;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;


public class MapperTest {
	/**
	 * 测试角色mapper
	 */
		public static void main(String[] arg){
			JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
			Client client = dcf.createClient("http://192.168.1.3:8081/WebService/PowerWebService?wsdl");
			Object[] objects = new Object[0];
			String error = null;
			try {
				// invoke("方法名",参数1,参数2,参数3....);
				objects = client.invoke("getInfosByUserId",token,"0");
				Result result = JSON.parseObject(objects[0].toString()
						, new TypeReference<Result>() {});
				String permStrs = "";
				if(null != result.getPowerMenuList() && !result.getPowerMenuList().isEmpty()){
					for (Power_Menu p: result.getPowerMenuList()) {
						if(StringUtils.isNoneBlank(p.getMenuName())){
							permStrs+=p.getMenuName() + ",";
						}
					}
				}
				Power_User powerUser = result.getPowerUser();
				if(powerUser != null){
					Power_User admin = (Power_User)SecurityUtils.getSubject().getPrincipal();
					UserToken userToken = new UserToken(powerUser.getUserName(),powerUser.getUserPwd(),true,powerUser.getRoleId(),permStrs);
					Subject subject = SecurityUtils.getSubject();
					subject.login(userToken);
				}
				String msg = "";
				if (error != null) {//出错了，返回登录页面
					return "redirect://http:192.168.1.3:8080/login";
				}
		}
}
