开发Spring MVC应用程序(3-1)
来源:互联网 发布:ps4经典游戏知乎 编辑:程序博客网 时间:2024/06/06 03:09
package tests;
import java.util.Map;
import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletException;
import junit.framework.TestCase;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
import org.springframework.web.servlet.ModelAndView;
import web.SpringappController;
import bus.Product;
public class TestSpringappController extends TestCase {
private ApplicationContext ac;
public void setUp() throws IOException {
ac = new FileSystemXmlApplicationContext("src/tests/WEB-INF/springapp-servlet.xml");
}
public void testHandleRequest() throws ServletException, IOException {
SpringappController sc = (SpringappController) ac.getBean("springappController");
ModelAndView mav = sc.handleRequest((HttpServletRequest) null, (HttpServletResponse) null);
Map m = mav.getModel();
List pl = (List) ((Map) m.get("model")).get("products");
Product p1 = (Product) pl.get(0);
assertEquals("Lamp", p1.getDescription());
Product p2 = (Product) pl.get(1);
assertEquals("Table", p2.getDescription());
Product p3 = (Product) pl.get(2);
assertEquals("Chair", p3.getDescription());
}
}
package bus;
import java.io.Serializable;
import java.util.ListIterator;
import java.util.List;
public class ProductManager implements Serializable {
private List products;
public void setProducts(List p) {
products = p;
}
public List getProducts() {
return products;
}
public void increasePrice(int pct) {
ListIterator li = products.listIterator();
while (li.hasNext()) {
Product p = (Product) li.next();
double newPrice = p.getPrice().doubleValue() * (100 + pct)/100;
p.setPrice(new Double(newPrice));
}
}
}
package tests;
import java.util.List;
import java.util.ArrayList;
import junit.framework.TestCase;
import bus.ProductManager;
import bus.Product;
public class TestProductManager extends TestCase {
private ProductManager pm;
public void setUp() {
pm = new ProductManager();
Product p = new Product();
p.setDescription("Chair");
p.setPrice(new Double("20.50"));
ArrayList al = new ArrayList();
al.add(p);
p = new Product();
p.setDescription("Table");
p.setPrice(new Double("150.10"));
al.add(p);
pm.setProducts(al);
}
public void testGetProducs() {
List l = pm.getProducts();
Product p1 = (Product) l.get(0);
assertEquals("Chair", p1.getDescription());
Product p2 = (Product) l.get(1);
assertEquals("Table", p2.getDescription());
}
public void testIncreasePrice() {
pm.increasePrice(10);
List l = pm.getProducts();
Product p = (Product) l.get(0);
assertEquals(new Double("22.55"), p.getPrice());
p = (Product) l.get(1);
assertEquals(new Double("165.11"), p.getPrice());
}
}
- 开发Spring MVC应用程序(3-1)
- 开发Spring MVC应用程序(1)
- 开发Spring MVC应用程序(3-3)
- 开发Spring MVC应用程序(3-2)
- 开发Spring MVC应用程序(2)
- 用 Spring MVC 轻松进行应用程序开发
- 用 Spring MVC 轻松进行应用程序开发
- 用 Spring MVC 轻松进行应用程序开发
- 用 Spring MVC 轻松进行应用程序开发(图)
- spring MVC之开发简单的web应用程序(一)
- spring-richclient开发swing应用程序 3
- spring-richclient开发swing应用程序 3
- spring-richclient开发swing应用程序 3
- spring-richclient开发swing应用程序 3
- spring-richclient开发swing应用程序 3
- spring-richclient开发swing应用程序 3
- spring-richclient开发swing应用程序 3
- spring-richclient开发swing应用程序 3
- QDII制度5月1日落实 金蝶国际等港股成受益者
- 开发Spring MVC应用程序(1)
- 徐少春套现350万份股权 某基金组织买入
- rcp classpath
- 开发Spring MVC应用程序(2)
- 开发Spring MVC应用程序(3-1)
- 《经济观察报》金蝶:共生能力
- 开发Spring MVC应用程序(3-2)
- 筛法的应用
- 开发Spring MVC应用程序(3-3)
- 音序检索汉字之我见
- “英文简历常用词汇”大全(精)
- 如何关闭一个view
- 如何用C#做一个类似于桌面插件的程序