views:

133

answers:

1

I am trying to get some basic unit tests up and running on the Play! framework using the Siena persistence library with GAE as the intended deployment target.

I have the project configured properly and can deploy the app to GAE. I created a basic domain object:

public class User extends Model {

    @Id(Generator.AUTO_INCREMENT)
    public Long id;

    @Column("first_name")
    public String firstName;

    @Column("last_name")
    public String lastName;

    @Column("email")
    public String email;

    public User(String firstName, String lastName, String email) {
        this.firstName = firstName;
        this.lastName = lastName;
        this.email = email;
    }

    public static Query<User> all() {
        return Model.all(User.class);
    }

}

and a basic unit test:

public class BasicTest extends UnitTest {

    @Before
    public void setup() {
        Fixtures.deleteAll();
    }


    @Test
    public void canCreateUser() {
        new User("Jason","Miesionczek","[email protected]").insert();

        User user = User.all().fetch().get(0);

        assertNotNull(user);
        assertEquals(1,User.all().count());
    }

}

I understand that in Play! 1.0.3, Fixtures support for Siena is not there yet, which should be fixed in 1.1, but in the mean time, what should i use instead of Fixtures.deleteAll() to clear the test db before each test?

Right now my second assertion fails because the database retains the previously inserted records.

+1  A: 

You would need to do a delete per table. E.g:

Model.all(User.class).delete();
plunchete