提交 acac42d4 编写于 作者: C Calvin

#62 补充功能测试

上级 b2aca92b
......@@ -26,6 +26,7 @@
<junit.version>4.10</junit.version>
<mockito.version>1.9.0</mockito.version>
<selenium.version>2.24.1</selenium.version>
<jersey.version>1.13</jersey.version>
<!-- Plugin的属性定义 -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
......@@ -302,6 +303,20 @@
<version>2.4.8</version>
<scope>test</scope>
</dependency>
<!-- restful client -->
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-client</artifactId>
<version>${jersey.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.jaxrs</groupId>
<artifactId>jackson-jaxrs-json-provider</artifactId>
<version>${jackson.version}</version>
<scope>test</scope>
</dependency>
<!-- jetty -->
<dependency>
......
......@@ -5,6 +5,7 @@ import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
......@@ -23,4 +24,10 @@ public class TaskRestController {
List<Task> list(Model model) {
return taskManager.getAllTask();
}
@RequestMapping(value = "/{id}", method = RequestMethod.GET, produces = "application/json")
public @ResponseBody
Task get(@PathVariable("id") Long id) {
return taskManager.getTask(id);
}
}
......@@ -20,8 +20,9 @@ import org.springside.examples.miniweb.service.TaskManager;
* Update action : POST /task/save/{id}
* Delete action : POST /task/delete/{id}
*
* 其中Update page/action在TaskDetailController,其余在本Controller。
*
* @author calvin
*
*/
@Controller
@RequestMapping(value = "/task")
......@@ -46,7 +47,7 @@ public class TaskController {
@RequestMapping(value = "save")
public String save(Task task, RedirectAttributes redirectAttributes) {
taskManager.saveTask(task);
redirectAttributes.addFlashAttribute("message", "创建任务" + task.getTitle() + "成功");
redirectAttributes.addFlashAttribute("message", "创建任务成功");
return "redirect:/task/";
}
......@@ -56,5 +57,4 @@ public class TaskController {
redirectAttributes.addFlashAttribute("message", "删除任务成功");
return "redirect:/task/";
}
}
......@@ -31,7 +31,7 @@ public class TaskDetailController {
@RequestMapping(value = "save/{id}")
public String save(@ModelAttribute("task") Task task, RedirectAttributes redirectAttributes) {
taskManager.saveTask(task);
redirectAttributes.addFlashAttribute("message", "修改任务" + task.getTitle() + "成功");
redirectAttributes.addFlashAttribute("message", "更新任务成功");
return "redirect:/task/";
}
......
......@@ -21,12 +21,10 @@
<input type="hidden" name="id" value="${task.id}"/>
<fieldset>
<legend><small>管理任务</small></legend>
<div id="messageBox" class="alert alert-error" style="display:none">输入有误,请先更正。</div>
<div class="control-group">
<label for="title" class="control-label">任务名称:</label>
<div class="controls">
<input type="text" id="title" name="title" size="50" value="${task.title}" class="required"/>
<input type="text" id="task.title" name="title" size="50" value="${task.title}" class="required"/>
</div>
</div>
<div class="form-actions">
......
......@@ -12,15 +12,12 @@
</c:if>
<table id="contentTable" class="table table-striped table-bordered table-condensed">
<thead><tr><th>任务编号</th><th>任务标题</th><th>操作</th></tr></thead>
<thead><tr><th>任务标题</th><th>管理</th></tr></thead>
<tbody>
<c:forEach items="${tasks}" var="task">
<tr>
<td>${task.id}</td>
<td>${task.title}</td>
<td>
<a href="update/${task.id}" id="update-${task.id}-btn">修改</a> <a href="delete/${task.id}">删除</a>
</td>
<td><a href="update/${task.id}">${task.title}</a></td>
<td><a href="delete/${task.id}">删除</a></td>
</tr>
</c:forEach>
</tbody>
......
package org.springside.examples.miniweb.functional;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.springside.modules.test.category.Smoke;
/**
* 任务管理的功能测试, 测试页面JavaScript及主要用户故事流程.
*
* @author calvin
*/
public class TaskManageIT extends BaseFunctionalTestCase {
/**
* 查看任务列表.
*/
@Test
@Category(Smoke.class)
public void viewTaskList() {
s.open("/task/");
}
}
package org.springside.examples.miniweb.functional.gui;
import static org.junit.Assert.*;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.springside.examples.miniweb.data.TaskData;
import org.springside.examples.miniweb.entity.Task;
import org.springside.examples.miniweb.functional.BaseFunctionalTestCase;
import org.springside.modules.test.category.Smoke;
/**
* 任务管理的功能测试, 测试页面JavaScript及主要用户故事流程.
*
* @author calvin
*/
public class TaskGuiIT extends BaseFunctionalTestCase {
/**
* 浏览用户列表.
*/
@Test
@Category(Smoke.class)
public void viewTaskList() {
s.open("/task/");
WebElement table = s.findElement(By.id("contentTable"));
assertEquals("Study PlayFramework 2.0", s.getTable(table, 0, 0));
}
/**
* 创建并更新任务.
*/
@Test
@Category(Smoke.class)
public void createAndUpdateTask() {
s.open("/task/");
//create
s.click(By.linkText("创建任务"));
Task task = TaskData.randomTask();
s.type(By.id("task.title"), task.getTitle());
s.click(By.id("submit"));
assertTrue(s.isTextPresent("创建任务成功"));
//update
s.click(By.linkText(task.getTitle()));
assertEquals(task.getTitle(), s.getValue(By.id("task.title")));
String newTitle = TaskData.randomTitle();
s.type(By.id("task.title"), newTitle);
s.click(By.id("submit"));
assertTrue(s.isTextPresent("更新任务成功"));
}
@Test
public void inputInValidateValue() {
s.open("/task/");
s.click(By.linkText("创建任务"));
s.click(By.id("submit"));
assertEquals("必选字段", s.getText(By.xpath("//fieldset/div/div/label")));
}
}
package org.springside.examples.miniweb.functional.rest;
import static org.junit.Assert.*;
import java.util.List;
import javax.ws.rs.core.MediaType;
import org.junit.Before;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.springside.examples.miniweb.entity.Task;
import org.springside.examples.miniweb.functional.BaseFunctionalTestCase;
import org.springside.modules.test.category.Smoke;
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.GenericType;
import com.sun.jersey.api.client.WebResource;
/**
* 任务管理的功能测试, 测试页面JavaScript及主要用户故事流程.
*
* @author calvin
*/
public class TaskRestIT extends BaseFunctionalTestCase {
private WebResource client;
private final GenericType<List<Task>> taskListType = new GenericType<List<Task>>() {
};
@Before
public void setupClient() {
client = Client.create().resource(baseUrl);
}
/**
* 查看任务列表.
*/
@Test
@Category(Smoke.class)
public void listTasks() {
WebResource wr = client.path("/api/task");
List<Task> tasks = wr.get(taskListType);
assertEquals(5, tasks.size());
assertEquals("Study PlayFramework 2.0", tasks.get(0).getTitle());
}
/**
* 获取任务.
*/
@Test
@Category(Smoke.class)
public void getTask() {
Long id = 1L;
Task task = client.path("/api/task/" + id).accept(MediaType.APPLICATION_JSON).get(Task.class);
assertEquals("Study PlayFramework 2.0", task.getTitle());
}
}
......@@ -10,11 +10,14 @@ import org.springside.modules.test.data.RandomData;
*/
public class TaskData {
public static Task getRandomTask() {
public static Task randomTask() {
Task task = new Task();
task.setTitle(RandomData.randomName("Task"));
task.setTitle(randomTitle());
return task;
}
public static String randomTitle() {
return RandomData.randomName("Task");
}
}
com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider
\ No newline at end of file
com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册