3

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","atmospherian@gmail.com").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.

Peter Hilton
  • 17,211
  • 6
  • 50
  • 75
Jason Miesionczek
  • 14,268
  • 17
  • 76
  • 108

2 Answers2

2

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

Model.all(User.class).delete();
plunchete
  • 486
  • 4
  • 12
2

I don't know if it's already to late but I've added some Fixture support for Siena (tested with play 1.1, gae 1.4, siena 1.3, crudsiena 1.2).

It supports deleteAll() and load():

SienaFixture.java http://pastie.org/1367878

I am pretty new to play and siena (1 week) so there is probably a better way of doing it (especially deleteAll()).

CSchulz
  • 10,882
  • 11
  • 60
  • 114
spreiter301
  • 314
  • 1
  • 12