// 方法一:SpringJUnit4测试
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations =
{ "../spring/spring_core.xml", "../spring/spring_service.xml", "../spring/spring_qsecurity.xml", "../spring/spring_dao.xml" })
public class TestO
{
@Test
public void test()
{
System.out.println("---->"+OrganizationManagementService.findOrganizationalUnitsByOid("de03e075-cf87-4029-b5e5-82025ec10415").size());
}
}
// 方法二:main测试
public class mytest
{
public static void main(String[] args) throws IOException
{
ApplicationContext ac = new ClassPathXmlApplicationContext("../spring/*");
@SuppressWarnings("unused")
IDeviceManagerService vs = (IDeviceManagerService) ac.getBean("deviceManagerService");
}
}
// 方法三:(ApplicationContext)main测试
public class TestClass
{
private static IUserInfoService userInfoService;
private static OrganizationService organizationService;
static
{
ApplicationContext ac = new ClassPathXmlApplicationContext("classpath:spring/*");
userInfoService = (IUserInfoService) ac.getBean("userInfoService");
organizationService = (OrganizationService) ac.getBean("organizationService");
}
public static void main(String[] args)
{
List<PersonInfo> list=
ServiceUtil.getOrganizationService().queryPersonInfoByCondition("qs00001",
"702c2893-ac39-4dff-8c77-33160f485ff1", "", "孙", "", "1", null);
System.out.println(list.size()+"@@@@@@@@@@@@@@@@@");
}
}
// 方法四:spring+hibernate+junit4 测试
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"classpath:/spring-hibernate.xml","classpath:/spring-mvc.xml","classpath:/spring.xml"})
@TransactionConfiguration(transactionManager="transactionManager",defaultRollback=false)
@Transactional
public class Test
{
@Autowired
private PersonServiceI personServiceDao;
@org.junit.Test
public void testSave()
{
try
{
System.out.println("----------"+personServiceDao);
Person person = new Person();
person.setName("王五");
person.setAge(23);
person.setUpdateTime(new SimpleDateFormat("YYYY-MM-dd HH:MM:ss").parse(new SimpleDateFormat("YYYY-MM-dd HH:MM:ss").format(new Date())));
personServiceDao.save(person);
List<Object[]> objList = personServiceDao.selectAll();
for (int i = 0; i < objList.size(); i++)
{
System.out.println("--成功--"+objList.get(i)[2].toString());
}
} catch (ParseException e)
{
e.printStackTrace();
}
}
}