当前位置: 首页>>代码示例>>Java>>正文


Java FakeRequest.withFormUrlEncodedBody方法代码示例

本文整理汇总了Java中play.test.FakeRequest.withFormUrlEncodedBody方法的典型用法代码示例。如果您正苦于以下问题:Java FakeRequest.withFormUrlEncodedBody方法的具体用法?Java FakeRequest.withFormUrlEncodedBody怎么用?Java FakeRequest.withFormUrlEncodedBody使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在play.test.FakeRequest的用法示例。


在下文中一共展示了FakeRequest.withFormUrlEncodedBody方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testStudentController

import play.test.FakeRequest; //导入方法依赖的package包/类
@Test
public void testStudentController() {
  // Test GET /student on an empty database
  Result result = callAction(controllers.routes.ref.Student.index());
  assertTrue("Empty Students", contentAsString(result).contains("No students"));

  // Test GET /student on a database containing a single student
  String studentId = "Student-01";
  Student student = new Student(studentId, "John Smith", "[email protected]");
  student.save();
  result = callAction(controllers.routes.ref.Student.index());
  assertTrue("One Student", contentAsString(result).contains(studentId));

  // Test GET /student/Student-01
  result = callAction(controllers.routes.ref.Student.details(studentId));
  assertTrue("Student detail", contentAsString(result).contains(studentId));

  // Test GET /student/Student-01 and make sure we get a 404
  result = callAction(controllers.routes.ref.Student.details("BadStudentId"));
  assertEquals("Student detail (bad)", NOT_FOUND, status(result));

  // Test POST /students (with simulated, valid form data)
  Map<String, String> studentData = new HashMap<String, String>();
  studentData.put("studentId", "Student-02");
  studentData.put("studName", "Alex Doe");
  studentData.put("email", "[email protected]");
  FakeRequest request = fakeRequest();
  request.withFormUrlEncodedBody(studentData);
  result = callAction(controllers.routes.ref.Student.newStudent(), request);
  assertEquals("Create new Student", OK, status(result));

  // Test POST /students (with invalid form data)
  request = fakeRequest();
  result = callAction(controllers.routes.ref.Student.newStudent(), request);
  assertEquals("Create new Student", BAD_REQUEST, status(result));

  // Test DELETE /students/Student-01 (a valid StudentId)
  result = callAction(controllers.routes.ref.Student.delete(studentId));
  assertEquals("Delete current student OK", OK, status(result));
  result = callAction(controllers.routes.ref.Student.details(studentId));
  assertEquals("Delete student gone", NOT_FOUND, status(result));
  result = callAction(controllers.routes.ref.Student.delete(studentId));
  assertEquals("Delete missing student also OK", OK, status(result));

}
 
开发者ID:camliu89,项目名称:ICSTextBookApplication,代码行数:46,代码来源:ControllerTest.java

示例2: testOfferController

import play.test.FakeRequest; //导入方法依赖的package包/类
@Test
public void testOfferController() {
  // Test GET /offer on an empty database
  Result result = callAction(controllers.routes.ref.Offer.index());
  assertTrue("Empty Offers", contentAsString(result).contains("No offers"));

  // Test GET /offer on a database containing a single offer
  String offerId = "Offer-01";
  Book book = new Book("Book-01", "bookname", "12334", 1, 15.00);
  Student student = new Student("Student-01", "doe", "[email protected]");
  Offer offer = new Offer(offerId, "good", 13.30, book, student);
  offer.save();
  book.save();
  student.save();
  result = callAction(controllers.routes.ref.Offer.index());
  assertTrue("One Offer", contentAsString(result).contains(offerId));

  // Test GET /offer/Offer-01
  result = callAction(controllers.routes.ref.Offer.details(offerId));
  assertTrue("Offer detail", contentAsString(result).contains(offerId));

  // Test GET /offer/Offer-01 and make sure we get a 404
  result = callAction(controllers.routes.ref.Offer.details("BadOfferId"));
  assertEquals("Offer detail (bad)", NOT_FOUND, status(result));

  // Test POST /offers (with simulated, valid form data)
  Map<String, String> offerData = new HashMap<String, String>();
  Book book2 = new Book("Book-02", "bookname2", "123345", 1, 16.00);
  Student student2 = new Student("Student-02", "joe", "[email protected]");
  offerData.put("offerId", "Offer-02");
  offerData.put("condition", "good");
  offerData.put("offerPrice", "13.50");
  offerData.put("book", book2.getBookName());
  offerData.put("student", student2.getStudentId());
  book2.save();
  student2.save();
  FakeRequest request = fakeRequest();
  request.withFormUrlEncodedBody(offerData);
  result = callAction(controllers.routes.ref.Offer.newOffer(), request);
  assertEquals("Create new Offer", OK, status(result));

  // Test POST /offers (with invalid form data)
  request = fakeRequest();
  result = callAction(controllers.routes.ref.Offer.newOffer(), request);
  assertEquals("Create new Offer", BAD_REQUEST, status(result));

  // Test DELETE /offers/Offer-01 (a valid OfferId)
  result = callAction(controllers.routes.ref.Offer.delete(offerId));
  assertEquals("Delete current offer OK", OK, status(result));
  result = callAction(controllers.routes.ref.Offer.details(offerId));
  assertEquals("Delete offer gone", NOT_FOUND, status(result));
  result = callAction(controllers.routes.ref.Offer.delete(offerId));
  assertEquals("Delete missing offer also OK", OK, status(result));
}
 
开发者ID:camliu89,项目名称:ICSTextBookApplication,代码行数:55,代码来源:ControllerTest.java

示例3: testRequestController

import play.test.FakeRequest; //导入方法依赖的package包/类
@Test
public void testRequestController() {
  // Test GET /request on an empty database
  Result result = callAction(controllers.routes.ref.Request.index());
  assertTrue("Empty Requests", contentAsString(result).contains("No requests"));

  // Test GET /request on a database containing a single request
  String requestId = "Request-01";
  Book book = new Book("Book-01", "bookname", "12334", 1, 15.00);
  Student student = new Student("Student-01", "doe", "[email protected]");
  Request bookRequest = new Request(requestId, "good", 13.30, book, student);
  bookRequest.save();
  book.save();
  student.save();
  result = callAction(controllers.routes.ref.Request.index());
  assertTrue("One request", contentAsString(result).contains(requestId));

  // Test GET /requests/Request-01
  result = callAction(controllers.routes.ref.Request.details(requestId));
  assertTrue("Request detail", contentAsString(result).contains(requestId));

  // Test GET /requests/Request-01 and make sure we get a 404
  result = callAction(controllers.routes.ref.Request.details("BadRequestId"));
  assertEquals("Request detail (bad)", NOT_FOUND, status(result));

  // Test POST /offers (with simulated, valid form data)
  Map<String, String> requestData = new HashMap<String, String>();
  Book book2 = new Book("Book-02", "bookname2", "123345", 1, 16.00);
  Student student2 = new Student("Student-02", "joe", "[email protected]");
  requestData.put("requestId", "Request-02");
  requestData.put("condition", "good");
  requestData.put("requestPrice", "13.50");
  requestData.put("book", book2.getBookId());
  requestData.put("student", student2.getStudentId());
  book2.save();
  student2.save();
  FakeRequest request = fakeRequest();
  request.withFormUrlEncodedBody(requestData);
  result = callAction(controllers.routes.ref.Request.newRequest(), request);
  assertEquals("Create new Request", OK, status(result));

  // Test POST /requests (with invalid form data)
  request = fakeRequest();
  result = callAction(controllers.routes.ref.Request.newRequest(), request);
  assertEquals("Create new a Request", BAD_REQUEST, status(result));

  // Test DELETE /requests/Request-01 (a valid OfferId)
  result = callAction(controllers.routes.ref.Request.delete(requestId));
  assertEquals("Delete current request OK", OK, status(result));
  result = callAction(controllers.routes.ref.Request.details(requestId));
  assertEquals("Delete request gone", NOT_FOUND, status(result));
  result = callAction(controllers.routes.ref.Request.delete(requestId));
  assertEquals("Delete missing request also OK", OK, status(result));

}
 
开发者ID:camliu89,项目名称:ICSTextBookApplication,代码行数:56,代码来源:ControllerTest.java

示例4: testBookController

import play.test.FakeRequest; //导入方法依赖的package包/类
@Test
public void testBookController() {
  // Test GET /book on an empty database
  Result result = callAction(controllers.routes.ref.Book.index());
  assertTrue("Empty Books", contentAsString(result).contains("No books"));

  // Test GET /book on a database containing a single book
  String bookId = "Book-01";
  Book book = new Book(bookId, "Java", "1234", 2, 13.44);
  book.save();
  result = callAction(controllers.routes.ref.Book.index());
  assertTrue("One Book", contentAsString(result).contains(bookId));

  // Test GET /books/Book-01
  result = callAction(controllers.routes.ref.Book.details(bookId));
  assertTrue("Book detail", contentAsString(result).contains(bookId));

  // Test GET /book/Book-01 and make sure we get a 404
  result = callAction(controllers.routes.ref.Book.details("BadBookId"));
  assertEquals("Bad detail (bad)", NOT_FOUND, status(result));
  
  // Test POST /books (with simulated, valid form data)
  Map<String, String> bookData = new HashMap<String, String>();
  bookData.put("bookId", "Student-02");
  bookData.put("bookName", "Play");
  bookData.put("isbn", "213324");
  bookData.put("defaultPrice", "14.43");
  FakeRequest request = fakeRequest();
  request.withFormUrlEncodedBody(bookData);
  result = callAction(controllers.routes.ref.Book.newBook(), request);
  assertEquals("Create new Book", OK, status(result));

  // Test POST /books (with invalid form data)
  request = fakeRequest();
  result = callAction(controllers.routes.ref.Book.newBook(), request);
  assertEquals("Create new bad Book", BAD_REQUEST, status(result));

  // Test DELETE /books/Book-01 (a valid Book-Id)
  result = callAction(controllers.routes.ref.Book.delete(bookId));
  assertEquals("Delete current book OK", OK, status(result));
  result = callAction(controllers.routes.ref.Book.details(bookId));
  assertEquals("Delete book gone", NOT_FOUND, status(result));
  result = callAction(controllers.routes.ref.Book.delete(bookId));
  assertEquals("Delete missing book also OK", OK, status(result));

}
 
开发者ID:camliu89,项目名称:ICSTextBookApplication,代码行数:47,代码来源:ControllerTest.java

示例5: testProductController

import play.test.FakeRequest; //导入方法依赖的package包/类
@Test
public void testProductController() {
  // Test GET /product on an empty database.
  Result result = callAction(controllers.routes.ref.Product.index());
  assertTrue("Empty products", contentAsString(result).contains("No products"));
  
  // Test GET /product on a database containing a single product.
  String productId = "Product-01";
  Product product = new Product(productId, "French Press", "Coffee Maker");
  product.save();
  result = callAction(controllers.routes.ref.Product.index());
  assertTrue("One product", contentAsString(result).contains(productId));
  
  // Test GET /product/Product-01
  result = callAction(controllers.routes.ref.Product.details(productId));
  assertTrue("Product detail", contentAsString(result).contains(productId));
  
  // Test GET /product/BadProductId and make sure we get a 404
  result = callAction(controllers.routes.ref.Product.details("BadProductId"));
  assertEquals("Product detail (bad)", NOT_FOUND, status(result));
      
  // Test POST /products (with simulated, valid form data).
  Map<String, String> productData = new HashMap<String, String>();
  productData.put("productId", "Product-02");
  productData.put("name", "Baby Gaggia");
  productData.put("description", "Espresso machine");
  FakeRequest request = fakeRequest();
  request.withFormUrlEncodedBody(productData);
  result = callAction(controllers.routes.ref.Product.newProduct(), request);
  assertEquals("Create new product", OK, status(result));
  
  // Test POST /products (with simulated, invalid form data).
  request = fakeRequest();
  result = callAction(controllers.routes.ref.Product.newProduct(), request);
  
  // Test DELETE /product/Product-01 (a valid ProductId)
  result = callAction(controllers.routes.ref.Product.delete(productId));
  assertEquals("Delete current product OK", OK, status(result));
  result = callAction(controllers.routes.ref.Product.details(productId));
  assertEquals("Deleted product gone", NOT_FOUND, status(result));
  result = callAction(controllers.routes.ref.Product.delete(productId));
  assertEquals("Deleted missing product also OK", OK, status(result));
}
 
开发者ID:justinslee,项目名称:GitHub-Play-Warehouse,代码行数:44,代码来源:ControllerTest.java

示例6: testTagController

import play.test.FakeRequest; //导入方法依赖的package包/类
@Test
public void testTagController() {
  // Test GET /tag on an empty database.
  Result result = callAction(controllers.routes.ref.Tag.index());
  assertTrue("Empty tags", contentAsString(result).contains("No Tags"));
  
  // Test GET /tag on a database containing a single tag.
  String tagId = "Tag-01";
  Tag tag = new Tag(tagId);
  tag.save();
  result = callAction(controllers.routes.ref.Tag.index());
  assertTrue("One tag", contentAsString(result).contains(tagId));
  
  // Test GET /tag/Tag-01
  result = callAction(controllers.routes.ref.Tag.details(tagId));
  assertTrue("Tag detail", contentAsString(result).contains(tagId));
  
  // Test GET /tag/BadTagId and make sure we get a 404
  result = callAction(controllers.routes.ref.Tag.details("BadTagId"));
  assertEquals("Tag detail (bad)", NOT_FOUND, status(result));
      
  // Test POST /tags (with simulated, valid form data).
  Map<String, String> tagData = new HashMap<String, String>();
  tagData.put("tagId", "Tag-02");
  FakeRequest request = fakeRequest();
  request.withFormUrlEncodedBody(tagData);
  result = callAction(controllers.routes.ref.Tag.newTag(), request);
  assertEquals("Create new tag", OK, status(result));
  
  // Test POST /tags (with invalid tag: tags cannot be named "Tag").
  // Illustrates use of validate() method in models.Tag.
  request = fakeRequest();
  tagData.put("tagId", "Tag");
  request.withFormUrlEncodedBody(tagData);
  result = callAction(controllers.routes.ref.Tag.newTag(), request);
  assertEquals("Create bad tag fails", BAD_REQUEST, status(result));
  
  // Test DELETE /tag/Tag-01 (a valid TagId)
  result = callAction(controllers.routes.ref.Tag.delete(tagId));
  assertEquals("Delete current tag OK", OK, status(result));
  result = callAction(controllers.routes.ref.Tag.details(tagId));
  assertEquals("Deleted tag gone", NOT_FOUND, status(result));
  result = callAction(controllers.routes.ref.Tag.delete(tagId));
  assertEquals("Deleted missing tag also OK", OK, status(result));
}
 
开发者ID:justinslee,项目名称:GitHub-Play-Warehouse,代码行数:46,代码来源:ControllerTest.java

示例7: testStockItemController

import play.test.FakeRequest; //导入方法依赖的package包/类
@Test
public void testStockItemController() {
  // Test GET /stockItem on an empty database.
  Result result = callAction(controllers.routes.ref.StockItem.index());
  assertTrue("Empty stockitems", contentAsString(result).contains("No stockitems"));
  
  // Test GET /stockItem on a database containing a single stockItem.
  String stockItemId = "StockItem-01";
  String warehouseId = "Warehouse-01";
  Warehouse warehouse = new Warehouse(warehouseId, "Storage");
  warehouse.save();
  Product product = new Product("Product-01", "soda", "pop");
  product.save();  
  StockItem stockitem = new StockItem(stockItemId, null, null, 100);
  stockitem.save();
  result = callAction(controllers.routes.ref.StockItem.index());
  assertTrue("One stockItem", contentAsString(result).contains(stockItemId));
      
  // Test GET /stockItem/StockItem-01
  result = callAction(controllers.routes.ref.StockItem.details(stockItemId));
  assertTrue("StockItem detail", contentAsString(result).contains(stockItemId));
  
  // Test GET /stockItem/BadStockItemId and make sure we get a 404
  result = callAction(controllers.routes.ref.StockItem.details("BadStockItemId"));
  assertEquals("StockItem detail (bad)", NOT_FOUND, status(result));
      
  // Test POST /stockItems (with simulated, invalid form data).
  Map<String, String> stockItemData = new HashMap<String, String>();
  stockItemData.put("stockItemId", "StockItem-02");
  stockItemData.put("warehouseId", null);
  stockItemData.put("productId", null);
  stockItemData.put("quantity", "500");
  FakeRequest request = fakeRequest();
  request.withFormUrlEncodedBody(stockItemData);
  result = callAction(controllers.routes.ref.StockItem.newStockItem(), request);
  assertEquals("Create new stockItem", BAD_REQUEST, status(result));
  
  // Test for current StockItem count after bad form input
  List<StockItem> stockitems = StockItem.find().findList();
  assertEquals("Checking stockitems", stockitems.size(), 1);
  
  // Test POST /stockItems (with simulated, valid form data).
  stockItemData.put("warehouseId", "Warehouse-01");
  stockItemData.put("productId", "Product-01");    
  request = fakeRequest();
  request.withFormUrlEncodedBody(stockItemData);
  result = callAction(controllers.routes.ref.StockItem.newStockItem(), request);
  assertEquals("Create new stockItem", OK, status(result));
  
  // Check for valid insertion
  stockitems = StockItem.find().findList();
  assertEquals("Checking stockitems", stockitems.size(), 2);
     
  // Test DELETE /stockItem/StockItem-01 (a valid StockItemId)
  result = callAction(controllers.routes.ref.StockItem.delete(stockItemId));
  assertEquals("Delete current stockItem OK", OK, status(result));
  result = callAction(controllers.routes.ref.StockItem.details(stockItemId));
  assertEquals("Deleted stockItem gone", NOT_FOUND, status(result));
  result = callAction(controllers.routes.ref.StockItem.delete(stockItemId));
  assertEquals("Deleted missing stockItem also OK", OK, status(result));
}
 
开发者ID:justinslee,项目名称:GitHub-Play-Warehouse,代码行数:62,代码来源:ControllerTest.java

示例8: TestCondtionController

import play.test.FakeRequest; //导入方法依赖的package包/类
@Test
  public void TestCondtionController() {
  //Test Get 
  Result result = callAction(controllers.routes.ref.Condition.index());
  assertTrue("Empty Condtions", contentAsString(result).contains("No Conditions"));
  
  //Test GET /product/on a database containing a single product
  String name = "Condition-01";
    
  models.Condition condition = new Condition(name);
  condition.save();
  
  result = callAction(controllers.routes.ref.Condition.index());
  assertTrue("One Condtion", contentAsString(result).contains(name));

 
  
  Map<String,String> condtionData = new HashMap<String, String>();
  condtionData.put("name", "Condition-02");
  condtionData.put("password", "!Fred3");
  FakeRequest request = fakeRequest(); 
  request.withFormUrlEncodedBody(condtionData);
  result = callAction(controllers.routes.ref.Condition.newCondition(),request);
  assertEquals("Create new Condition",OK, status(result));
  
  //request duplicate addition
  request = fakeRequest();
  request.withFormUrlEncodedBody(condtionData);
  result = callAction(controllers.routes.ref.Condition.newCondition(),request);
  assertEquals("Create duplicate Condition should fail",BAD_REQUEST, status(result));
  
  // Test POST /products (with simulated, invalid form data
  request = fakeRequest();
  result = callAction(controllers.routes.ref.Condition.newCondition(),request);
  assertEquals("Create bad new Condition fails",BAD_REQUEST, status(result));
  
   
  // Test DELETE /products/Product-01(a valid ProductId)
  result = callAction(controllers.routes.ref.Condition.  delete(name));
  assertEquals("Delete current product OK",OK, status(result));
  result = callAction(controllers.routes.ref.Condition.index());
  assertFalse("Name deleted of condition", contentAsString(result).contains(name));
    
  result = callAction(controllers.routes.ref.Condition.delete(name));
  assertEquals("Delete current product OK",OK, status(result));
}
 
开发者ID:rward,项目名称:BookSkateMate,代码行数:47,代码来源:ControllerTest.java

示例9: testProductController

import play.test.FakeRequest; //导入方法依赖的package包/类
@Test
public void testProductController() {
  // Test GET /product on an empty database
  Result result = callAction(controllers.routes.ref.Product.index());
  assertTrue("Empty products", contentAsString(result).contains("No products"));
  
  // Test GET /product on a database containing a single product.
  String productId = "Product-01";
  Product product = new Product(productId, "French Press", "Coffee Maker");
  product.save();
  result = callAction(controllers.routes.ref.Product.index());
  assertTrue("One Product", contentAsString(result).contains(productId));
  
  // Test GET /product/Product-01
  result = callAction(controllers.routes.ref.Product.details(productId));
  assertTrue("Product detail", contentAsString(result).contains(productId));
  
  // Test GET /product/BadProductId and make sure we get a 404
  result = callAction(controllers.routes.ref.Product.details("BadProductId"));
  assertEquals("Product detail (bad)", NOT_FOUND, status(result));
  
  // Test POST /products (with simulated, valid from data).
  Map<String, String> productData = new HashMap<>();
  productData.put("productId", "Product-02");
  productData.put("name", "Baby Gaggia");
  productData.put("description", "Expresso machine");
  FakeRequest request = fakeRequest();
  request.withFormUrlEncodedBody(productData);
  result = callAction(controllers.routes.ref.Product.newProduct(), request);
  assertEquals("Create new product", OK, status(result));
  
  // Test POST /products (with simulated, invalid form data).
  request = fakeRequest();
  result = callAction(controllers.routes.ref.Product.newProduct(), request);
  assertEquals("Create bad product fails", BAD_REQUEST, status(result));
  
  // Test DELETE /products/Product-01 (a valid ProductId).
  result = callAction(controllers.routes.ref.Product.delete(productId));
  assertEquals("Delete current product OK", OK, status(result));
  result = callAction(controllers.routes.ref.Product.details(productId));
  assertEquals("Deleted product gone", NOT_FOUND, status(result));
  result = callAction(controllers.routes.ref.Product.delete(productId));
  assertEquals("Delete missing product also OK", OK, status(result));
}
 
开发者ID:anthonyjchriste,项目名称:warehouse,代码行数:45,代码来源:ControllerTest.java

示例10: testTagController

import play.test.FakeRequest; //导入方法依赖的package包/类
@Test
public void testTagController() {
  // Test GET /tags on an empty database.
  Result result = callAction(controllers.routes.ref.Tag.index());
  assertTrue("Empty tags", contentAsString(result).contains("No Tags"));
  
  // Test GET /tag on a database containing a single Tag.
  String tagId = "Tag-01";
  Tag tag = new Tag(tagId);
  tag.save();
  result = callAction(controllers.routes.ref.Tag.index());
  assertTrue("One tag", contentAsString(result).contains(tagId));
  
  // Test GET /tags/Tag-01
  result = callAction(controllers.routes.ref.Tag.details(tagId));
  assertTrue("Tag detail", contentAsString(result).contains(tagId));
  
  // Test GET /tags/BadTagId and make sure we get a 404.
  result = callAction(controllers.routes.ref.Tag.details("BadTagId"));
  assertEquals("Tag detail (bad)", NOT_FOUND, status(result));
  
  // Test POST /tags (with simulated, valid form data).
  Map<String, String> tagData = new HashMap<>();
  tagData.put("tagId", "Tag-02");
  FakeRequest request = fakeRequest();
  request.withFormUrlEncodedBody(tagData);
  result = callAction(controllers.routes.ref.Tag.newTag(), request);
  assertEquals("Create new tag", OK, status(result));
  
  // Test POST /tags (with invalid tag: tags cannot be named "Tag").
  // Illustrates use of the validate() method in models.Tag.
  request = fakeRequest();
  tagData.put("tagId", "Tag");
  request.withFormUrlEncodedBody(tagData);
  result = callAction(controllers.routes.ref.Tag.newTag(), request);
  assertEquals("Create bad tag fails", BAD_REQUEST, status(result));
  
  // Test DELETE /tags/Tag-01 (a valid TagID).
  result = callAction(controllers.routes.ref.Tag.delete(tagId));
  assertEquals("Delete current tag OK", OK, status(result));
  result = callAction(controllers.routes.ref.Tag.details(tagId));
  assertEquals("Deleted tag gone", NOT_FOUND, status(result));
  result = callAction(controllers.routes.ref.Tag.delete(tagId));
  assertEquals("Delete missing tag also OK", OK, status(result));
}
 
开发者ID:anthonyjchriste,项目名称:warehouse,代码行数:46,代码来源:ControllerTest.java

示例11: testStockItemController

import play.test.FakeRequest; //导入方法依赖的package包/类
@Test
public void testStockItemController() {
  // Test GET /tags on an empty database.
  Result result = callAction(controllers.routes.ref.StockItem.index());
  assertTrue("Empty", contentAsString(result).contains("No stockItems"));
  
  // Need some extra objects in order to create our StockItem.
  Warehouse warehouse = new Warehouse("Warehouse-01", "name", "address");
  Product product = new Product("Product-01", "produce", "description");
  warehouse.save();
  product.save();
  
  // Test GET /stockitem on a database containing a single StockItem.
  String stockItemId = "StockItem-01";
  StockItem stockItem = new StockItem(stockItemId, warehouse, product, 1L);
  stockItem.save();
  result = callAction(controllers.routes.ref.StockItem.index());
  assertTrue("One StockItem", contentAsString(result).contains(stockItemId));
  
  // Test GET /stockitems/StockItem-01
  result = callAction(controllers.routes.ref.StockItem.details(stockItemId));
  assertTrue("StockItem detail", contentAsString(result).contains(stockItemId));
  
  // Test GET /stockitems/BadStockItemId and make sure we get a 404.
  result = callAction(controllers.routes.ref.StockItem.details("BadStockItemId"));
  assertEquals("StockItem detail (bad)", NOT_FOUND, status(result));

  // Test POST /stockitems (with simulated, valid form data).
  warehouse = new Warehouse("Warehouse-02", "name", "address");
  product = new Product("Product-02", "produce", "description");
  warehouse.save();
  product.save();
  Map<String, String> stockItemData = new HashMap<>();
  stockItemData.put("stockItemId", "StockItem-02");
  stockItemData.put("warehouse", "Warehouse-02");
  stockItemData.put("product", "Product-02");
  stockItemData.put("amount", "1");
  FakeRequest request = fakeRequest();
  request.withFormUrlEncodedBody(stockItemData);
  result = callAction(controllers.routes.ref.StockItem.newStockItem(), request);
  assertEquals("Create new StockItem", OK, status(result));
  
  
  // Test POST /stockitems (with invalid stockitem).
  request = fakeRequest();
  result = callAction(controllers.routes.ref.StockItem.newStockItem(), request);
  assertEquals("Create bad StockItem fails", BAD_REQUEST, status(result));
  
  
  // Test DELETE /stockitems/StockItem-01 (a valid StockItemId).
  result = callAction(controllers.routes.ref.StockItem.delete(stockItemId));
  assertEquals("Delete current StockItem OK", OK, status(result));
  result = callAction(controllers.routes.ref.StockItem.details(stockItemId));
  assertEquals("Deleted StockItem gone", NOT_FOUND, status(result));
  result = callAction(controllers.routes.ref.StockItem.delete(stockItemId));
  assertEquals("Delete missing StockItem also OK", OK, status(result));
}
 
开发者ID:anthonyjchriste,项目名称:warehouse,代码行数:58,代码来源:ControllerTest.java

示例12: testWarehouseController

import play.test.FakeRequest; //导入方法依赖的package包/类
@Test
public void testWarehouseController() {
  // Test GET /warehouses on an empty database.
  Result result = callAction(controllers.routes.ref.Warehouse.index());
  assertTrue("Empty", contentAsString(result).contains("No warehouses"));
  
  // Test GET /warehouse on a database containing a single warehouse.
  String warehouseId = "Warehouse-01";
  Warehouse warehouse = new Warehouse(warehouseId, "name", "address");
  warehouse.save();
  result = callAction(controllers.routes.ref.Warehouse.index());
  assertTrue("One warehouse", contentAsString(result).contains(warehouseId));
  
  // Test GET /warehouses/Warehouse-01
  result = callAction(controllers.routes.ref.Warehouse.details(warehouseId));
  assertTrue("Warehouse detail", contentAsString(result).contains(warehouseId));
  
  // Test GET /warehouses/BadWarehouseId and make sure we get a 404.
  result = callAction(controllers.routes.ref.Warehouse.details("BadWarehouseId"));
  assertEquals("Warehouse detail (bad)", NOT_FOUND, status(result));

  // Test POST /warehouses (with simulated, valid form data).
  Map<String, String> warehouseData = new HashMap<>();
  warehouseData.put("warehouseId", "Warehouse-02");
  warehouseData.put("name", "name2");
  // TODO: Eliminate addressField. How to bind string to address when handled by constructor
  warehouseData.put("addressField", "address");
  FakeRequest request = fakeRequest();
  request.withFormUrlEncodedBody(warehouseData);
  result = callAction(controllers.routes.ref.Warehouse.newWarehouse(), request);
  assertEquals("Create new warehouse", OK, status(result));
  
  
  // Test POST /warehouses (with invalid tag).
  request = fakeRequest();
  result = callAction(controllers.routes.ref.Warehouse.newWarehouse(), request);
  assertEquals("Create bad warehouse fails", BAD_REQUEST, status(result));
  
  
  // Test DELETE /warehouses/Warehouse-01 (a valid warehouseId).
  result = callAction(controllers.routes.ref.Warehouse.delete(warehouseId));
  assertEquals("Delete current warehouse OK", OK, status(result));
  result = callAction(controllers.routes.ref.Warehouse.details(warehouseId));
  assertEquals("Deleted warehouse gone", NOT_FOUND, status(result));
  result = callAction(controllers.routes.ref.Warehouse.delete(warehouseId));
  assertEquals("Delete missing warehouse also OK", OK, status(result));
}
 
开发者ID:anthonyjchriste,项目名称:warehouse,代码行数:48,代码来源:ControllerTest.java

示例13: testStudentController

import play.test.FakeRequest; //导入方法依赖的package包/类
@Test
public void testStudentController() {
  // Test GET /students on an empty database
  Result result = callAction(controllers.routes.ref.Student.index());
  assertTrue("Empty students", contentAsString(result).contains("Students"));

  // Test GET /students on a database containing a single student.
  String studentId = "Student-01";
  Student student = new Student(studentId, "Name", "Email");
  student.save();
  Long primaryKey = student.getPrimaryKey();
  result = callAction(controllers.routes.ref.Student.index());
  assertTrue("One student", contentAsString(result).contains(studentId));

  // Test GET /students/[primaryKey]
  result = callAction(controllers.routes.ref.Student.edit(primaryKey));
  assertTrue("Student detail", contentAsString(result).contains(studentId));

  // Test GET /students/[primaryKey + 1] (invalid primaryKey)
  result = callAction(controllers.routes.ref.Student.edit(primaryKey + 1));
  assertEquals("Student detail (bad)", NOT_FOUND, status(result));

  // Test POST /students (with simulated, valid form data).
  Map<String, String> studentData = new HashMap<String, String>();
  studentData.put("studentId", "Student-02");
  studentData.put("name", "OtherName");
  studentData.put("email", "OtherEmail");
  FakeRequest request = fakeRequest();
  request.withFormUrlEncodedBody(studentData);
  result = callAction(controllers.routes.ref.Student.save(), request);
  assertEquals("Create new student", SEE_OTHER, status(result));

  // Test POST /students (with simulated, invalid form data).
  request = fakeRequest();
  result = callAction(controllers.routes.ref.Student.save(), request);
  assertEquals("Create bad student fails", BAD_REQUEST, status(result));

  // Test DELETE /students/Student-01 (a valid studentId).
  result = callAction(controllers.routes.ref.Student.delete(primaryKey));
  assertEquals("Delete current student OK", SEE_OTHER, status(result));
  result = callAction(controllers.routes.ref.Student.edit(primaryKey));
  assertEquals("Deleted student gone", NOT_FOUND, status(result));
  result = callAction(controllers.routes.ref.Student.delete(primaryKey));
  assertEquals("Delete missing student also OK", SEE_OTHER, status(result));
}
 
开发者ID:ttaomae,项目名称:book-exchange,代码行数:46,代码来源:ControllerTest.java

示例14: testBookController

import play.test.FakeRequest; //导入方法依赖的package包/类
@Test
public void testBookController() {
  // Test GET /books on an empty database
  Result result = callAction(controllers.routes.ref.Book.index());
  assertTrue("Empty books", contentAsString(result).contains("Books"));

  // Test GET /books on a database containing a single student.
  String bookId = "Book-01";
  Book book = new Book(bookId, "Title", "Edition", 1234L, 123);
  book.save();
  Long primaryKey = book.getPrimaryKey();
  result = callAction(controllers.routes.ref.Book.index());
  assertTrue("One book", contentAsString(result).contains(bookId));

  // Test GET /books/[primaryKey]
  result = callAction(controllers.routes.ref.Book.edit(primaryKey));
  assertTrue("Book detail", contentAsString(result).contains(bookId));

  // Test GET /books/[primaryKey + 1] (invalid primaryKey)
  result = callAction(controllers.routes.ref.Book.edit(primaryKey + 1));
  assertEquals("Book detail (bad)", NOT_FOUND, status(result));

  // Test POST /books (with simulated, valid form data).
  Map<String, String> bookData = new HashMap<String, String>();
  bookData.put("bookId", "Book-02");
  bookData.put("title", "OtherTitle");
  bookData.put("isbn", "4321");
  FakeRequest request = fakeRequest();
  request.withFormUrlEncodedBody(bookData);
  result = callAction(controllers.routes.ref.Book.save(), request);
  assertEquals("Create new book", SEE_OTHER, status(result));

  // Test POST /books (with simulated, invalid form data).
  request = fakeRequest();
  result = callAction(controllers.routes.ref.Book.save(), request);
  assertEquals("Create bad book fails", BAD_REQUEST, status(result));

  // Test DELETE /books/Student-01 (a valid studentId).
  result = callAction(controllers.routes.ref.Book.delete(primaryKey));
  assertEquals("Delete current book OK", SEE_OTHER, status(result));
  result = callAction(controllers.routes.ref.Book.edit(primaryKey));
  assertEquals("Deleted book gone", NOT_FOUND, status(result));
  result = callAction(controllers.routes.ref.Book.delete(primaryKey));
  assertEquals("Delete missing book also OK", SEE_OTHER, status(result));
}
 
开发者ID:ttaomae,项目名称:book-exchange,代码行数:46,代码来源:ControllerTest.java

示例15: testRequestController

import play.test.FakeRequest; //导入方法依赖的package包/类
@Test
public void testRequestController() {
  // Test GET /requests on an empty database.
  Result result = callAction(controllers.routes.ref.Request.index());
  assertTrue("Empty requests", contentAsString(result).contains("Requests"));

  // Test GET /requests on a database containing a single request.
  String requestId = "Request-01";
  Student student = new Student("Student-01", "Name", "Email");
  Book book = new Book("Book-01", "Title", "Edition", 1234L, 123);
  Request request = new Request(requestId, student, book, 123);
  student.save();
  book.save();
  request.save();
  Long primaryKey = request.getPrimaryKey();
  result = callAction(controllers.routes.ref.Request.index());
  assertTrue("One request", contentAsString(result).contains(requestId));

  // Test GET /requests/[primaryKey]
  result = callAction(controllers.routes.ref.Request.edit(primaryKey));
  assertTrue("Request detail", contentAsString(result).contains(requestId));

  // Test GET /requests/[primaryKey + 1]
  result = callAction(controllers.routes.ref.Request.edit(primaryKey + 1));
  assertEquals("Request detail (bad)", NOT_FOUND, status(result));

  // Test POST /requests (with simulated, valid form data).
  Map<String, String> requestData = new HashMap<String, String>();
  requestData.put("requestId", "Request-02");
  requestData.put("studentId", "Student-01");
  requestData.put("bookId", "Book-01");
  requestData.put("targetPrice", "321");
  FakeRequest fakeRequest = fakeRequest();
  fakeRequest.withFormUrlEncodedBody(requestData);
  result = callAction(controllers.routes.ref.Request.save(), fakeRequest);
  assertEquals("Create new request", SEE_OTHER, status(result));
  assertEquals("New request has correct student", "Name",
      Request.find().where().eq("requestId", "Request-02").findUnique().getStudent().getName());
  assertEquals("New request has correct book", "Title",
      Request.find().where().eq("requestId", "Request-02").findUnique().getBook().getTitle());

  // Test POST /requests (with simulated, invalid form data).
  fakeRequest = fakeRequest();
  result = callAction(controllers.routes.ref.Request.save(), fakeRequest);
  assertEquals("Create bad request fails", BAD_REQUEST, status(result));

  // Test DELETE /requests/Request-01 (a valid requestId).
  result = callAction(controllers.routes.ref.Request.delete(primaryKey));
  assertEquals("Delete current request OK", SEE_OTHER, status(result));
  result = callAction(controllers.routes.ref.Request.edit(primaryKey));
  assertEquals("Deleted request gone", NOT_FOUND, status(result));
  result = callAction(controllers.routes.ref.Request.delete(primaryKey));
  assertEquals("Delete missing request also OK", SEE_OTHER, status(result));
}
 
开发者ID:ttaomae,项目名称:book-exchange,代码行数:55,代码来源:ControllerTest.java


注:本文中的play.test.FakeRequest.withFormUrlEncodedBody方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。