personservicetest.java

来自「用struts ,hibernate,spring三大框架整合的结构」· Java 代码 · 共 58 行

JAVA
58
字号
package junit.test;

import java.util.List;

import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import cn.itcast.bean.Person;
import cn.itcast.service.PersonService;


public class PersonServiceTest {
	private static PersonService personService;
	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
		try{
		ApplicationContext applicationContext=new ClassPathXmlApplicationContext("beans.xml");
		personService=(PersonService)applicationContext.getBean("personService");
		}catch(RuntimeException e){
			e.printStackTrace();
		}
	}

	@Test
	public void testSave() {
		personService.save(new Person("ping"));
	}

	@Test
	public void testUpdate() {
		Person person=personService.getPerson(3);
		person.setName("hong");
		personService.update(person);
	}

	@Test
	public void testGetPerson() {
		Person person=personService.getPerson(1);
		System.out.print(person.getName());
	}

	@Test
	public void testDelete() {
		personService.delete(1);
	}

	@Test
	public void testGetPersons() {
		List<Person> persons=personService.getPersons();
		for(Person p:persons){
			System.out.println(p.getName());
		}
	}

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?