Permalink
Browse files

added tests. cleanup

  • Loading branch information...
jamesward committed Dec 8, 2011
1 parent c634e2a commit 8d29cb2c0396e3ef3a88206bf05fbbb77edc79f1
Showing with 40 additions and 24 deletions.
  1. +1 −0 .gitignore
  2. +1 −1 app/controllers/Application.java
  3. +0 −11 app/models/Bar.java
  4. +10 −11 app/views/Application/index.html
  5. +9 −1 test/ApplicationTest.java
  6. +19 −0 test/BarTest.java
View
@@ -2,3 +2,4 @@
/lib
/.idea
/*.iml
+/test-result
@@ -22,4 +22,4 @@ public static void listBars() {
renderJSON(Bar.findAll());
}
-}
+}
View
@@ -3,21 +3,10 @@
import play.db.jpa.Model;
import javax.persistence.Entity;
-import java.util.Date;
-
-/**
- * Created by IntelliJ IDEA.
- * User: jamesw
- * Date: 11/8/11
- * Time: 2:30 PM
- * To change this template use File | Settings | File Templates.
- */
@Entity
public class Bar extends Model {
public String name;
- public int num;
-
}
@@ -1,24 +1,23 @@
#{extends 'main.html' /}
#{set title:'Home' /}
+#{form @addBar()}
+ <input type="text" name="bar.name"/>
+ <input type="submit"/>
+#{/form}
+
+<ul id="bars">
+
+</ul>
+
#{set 'moreScripts'}
<script type="text/javascript">
$(function() {
$.get("bars.json", function(data) {
$.each(data, function(index, item) {
- $("#bars").append("<li>Bar " + item.name + " " + item.num + "</li>");
+ $("#bars").append("<li>Bar " + item.name + "</li>");
});
});
});
</script>
#{/set}
-
-<div id="bars">
-
-</div>
-
-#{form @addBar()}
- <input type="text" name="bar.name"/>
- <input type="text" name="bar.num"/>
- <input type="submit"/>
-#{/form}
View
@@ -13,5 +13,13 @@ public void testThatIndexPageWorks() {
assertContentType("text/html", response);
assertCharset(play.Play.defaultWebEncoding, response);
}
+
+ @Test
+ public void barTest() {
+ Response addBarResponse = POST("/", APPLICATION_X_WWW_FORM_URLENCODED, "bar.name=foo");
+ assertStatus(302, addBarResponse);
+ Response listBarsResponse = GET("/bars.json");
+ assertIsOk(listBarsResponse);
+ }
-}
+}
View
@@ -0,0 +1,19 @@
+import org.junit.*;
+import java.util.*;
+import play.test.*;
+import models.*;
+
+public class BarTest extends UnitTest {
+
+ @Test
+ public void integrationTest() {
+ Bar bar = new Bar();
+ bar.name = "a new bar";
+ bar.save();
+ assertNotNull(bar.id);
+ assertTrue(Bar.findAll().size() >= 1);
+ bar.delete();
+ assertTrue(Bar.findAll().size() == 0);
+ }
+
+}

0 comments on commit 8d29cb2

Please sign in to comment.