Created
September 24, 2010 17:51
-
-
Save qoelet/595743 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// view | |
public class Application extends Controller { | |
public static void index() { | |
System.out.println("Incoming request..."); | |
List<ToDo> todos = ToDo.find("byDone", false).fetch(); | |
render(todos); | |
} | |
} | |
// model | |
public class ToDo extends Model | |
{ | |
public String title; | |
public Date added; | |
public Boolean done = false; | |
public String grid; | |
// Lob tests JPA to use a large text database type | |
@Lob | |
public String todo_item; | |
@ManyToOne | |
public Owner owner; | |
public ToDo(Owner o, String t, String td, String g) | |
{ | |
this.title = t; | |
this.todo_item = td; | |
this.owner = o; | |
this.added = new Date(); | |
this.grid = g; | |
} | |
} | |
// test | |
public void createToDo() | |
{ | |
// Create a new user and save it | |
Owner kenny = new Owner("kennyshen","123","Kenny Shen").save(); | |
// Create a new todo | |
new ToDo(kenny, "Hello Grid!", "Finish the basics tonight!", "A").save(); | |
// Assert that a todo has been created | |
assertEquals(1, ToDo.count()); | |
// Locate all posts created by Kenny | |
List<ToDo> kennyToDos = ToDo.find("byOwner", kenny).fetch(); | |
// Tests | |
assertEquals(1, kennyToDos.size()); | |
ToDo firstToDo = kennyToDos.get(0); | |
assertNotNull(firstToDo); | |
assertEquals(kenny, firstToDo.owner); | |
assertEquals("Hello Grid!", firstToDo.title); | |
assertEquals("Finish the basics tonight!", firstToDo.todo_item); | |
assertNotNull(firstToDo.added); | |
assertEquals(false, firstToDo.done); | |
} | |
// bootstrap | |
public class BootStrap extends Job { | |
public void doJob() { | |
// Check if the database is empty | |
if(Owner.count() == 0) { | |
Fixtures.load("initial-data.yml"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment