红联Linux门户
Linux帮助

Arquillian Spring框架扩展1.0.0.Beta1

发布时间:2012-08-18 15:48:48来源:红联作者:empast
Arquillian Spring 框架扩展 1.0.0.Beta1 发布了,这也是该扩展首次发布的版本,支持客户端应用上下文注册以及 Spring 事务处理。

Arquillian 可让你在远程或者嵌入式的容器里测试业务逻辑,同时可作为一个压缩包发布到容器中,并通过客户端来进行交互测试。

Arquillian 是一个可以方便的在现有类基础性扩展测试用例,基于 JUnit 。

客户端测试:[code]@RunWith(Arquillian.class)
@SpringClientConfiguration("applicationContext-rest.xml")
public class ClientRestServiceTestCase {


@Deployment(testable = false)
@OverProtocol("Servlet 3.0")
public static Archive createTestArchive() {
return Deployments.createWebApplication()
.addAsWebInfResource("mvc/web.xml", "web.xml")
.addAsWebInfResource("service-servlet.xml");
}


@ArquillianResource
private URL contextPath;


@Autowired
private RestTemplate restTemplate;


@Test
public void testGetEmployees() {


Employee result = restTemplate.getForObject(contextPath + "/Employees/1", Employee.class);


assertEquals("The returned employee has invalid name.", "John Smith", result.getName());
}
}[/code]Spring 事务测试[code]@RunWith(Arquillian.class)
@Transactional(manager = "txManager")
@SpringConfiguration("applicationContext.xml")
public class JpaEmployeeRepositoryTestCase {


@Autowired
private EmployeeRepository employeeRepository;


@PersistenceContext
private EntityManager entityManager;


@Test
public void testSave() {


Employee employee = new Employee();
employee.setName("Test employee");


employeeRepository.save(employee);


List result = entityManager.createQuery("from Employee").getResultList();


assertEquals("Two employees were expected.", 1, result.size());
}
}[/code]主页:http://www.jboss.org/arquillian.html

来自:开源中国社区
文章评论

共有 0 条评论