Commit 06a50233 authored by Fjen Undso's avatar Fjen Undso
Browse files

test: add more modeltests

parent d371be3f
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.fasterxml.jackson.databind.JsonNode;
import org.junit.*;
import play.mvc.*;
import play.test.*;
import play.data.DynamicForm;
import play.data.validation.ValidationError;
import play.data.validation.Constraints.RequiredValidator;
import play.i18n.Lang;
import play.libs.F;
import play.libs.F.*;
import play.twirl.api.Content;
import static play.test.Helpers.*;
import static org.fest.assertions.Assertions.*;
/**
*
* Simple (JUnit) tests that can call all parts of a play app.
* If you are interested in mocking a whole application, see the wiki for more details.
*
*/
public class ApplicationTest {
@Test
public void simpleCheck() {
int a = 1 + 1;
assertThat(a).isEqualTo(2);
}
@Test
public void renderTemplate() {
Content html = views.html.index.render("Your new application is ready.");
assertThat(contentType(html)).isEqualTo("text/html");
assertThat(contentAsString(html)).contains("Your new application is ready.");
}
}
import org.junit.*;
import play.mvc.*;
import play.test.*;
import play.libs.F.*;
import static play.test.Helpers.*;
import static org.fest.assertions.Assertions.*;
import static org.fluentlenium.core.filter.FilterConstructor.*;
public class IntegrationTest {
/**
* add your integration test here
* in this example we just check if the welcome page is being shown
*/
@Test
public void test() {
running(testServer(3333, fakeApplication(inMemoryDatabase())), HTMLUNIT, new Callback<TestBrowser>() {
public void invoke(TestBrowser browser) {
browser.goTo("http://localhost:3333");
assertThat(browser.pageSource()).contains("Your new application is ready.");
}
});
}
}
import static org.junit.Assert.assertEquals;
import models.QuestionAnswer;
import models.Session;
import models.Vote;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import play.test.FakeApplication;
......@@ -17,33 +18,98 @@ public class ModelTest {
public static DdlGenerator ddl;
public static EbeanServer server;
@BeforeClass
public static void setup() {
@Before
public void setup() {
app = Helpers.fakeApplication(Helpers.inMemoryDatabase());
Helpers.start(app);
}
@AfterClass
public static void stopApp() {
@After
public void stopApp() {
Helpers.stop(app);
}
@Test
public void testModel() {
// Sessions and votes
public void testSessionVotes() {
// Sessions and Votes
Session s1 = new Session("owner1", "Session1");
Vote v1 = new Vote(s1, "owner2", Vote.Type.SPEED, 1);
Vote v2 = new Vote(s1, "owner2", Vote.Type.UNDERSTANDABILITY, -1);
s1.votes.add(v1);
s1.votes.add(v2);
s1.addVote(v1);
s1.addVote(v2);
s1.save();
v1.save();
v2.save();
assertEquals(Session.find.all().size(), 1);
assertEquals(Vote.find.all().size(), 2);
assertEquals(1, Session.find.all().size());
assertEquals(2, Vote.find.all().size());
assertEquals(2, s1.votes.size());
s1.delete();
assertEquals(0, Session.find.all().size());
assertEquals(0, Vote.find.all().size());
}
@Test
public void testSessionAnswers() {
// Sessions and QuestionAnswers
Session s1 = new Session("owner1", "Session1");
QuestionAnswer q1 = new QuestionAnswer(s1, "owner2",
QuestionAnswer.Answer.A);
QuestionAnswer q2 = new QuestionAnswer(s1, "owner3",
QuestionAnswer.Answer.B);
s1.addQuestionAnswer(q1);
s1.addQuestionAnswer(q2);
s1.save();
assertEquals(1, Session.find.all().size());
assertEquals(2, QuestionAnswer.find.all().size());
assertEquals(2, s1.questionAnswers.size());
s1.delete();
assertEquals(0, Session.find.all().size());
assertEquals(0, QuestionAnswer.find.all().size());
}
@Test
public void testSessionResetAnswers() {
// Reset Answers from a Session
Session s1 = new Session("owner1", "Session1");
QuestionAnswer q1 = new QuestionAnswer(s1, "owner2",
QuestionAnswer.Answer.A);
QuestionAnswer q2 = new QuestionAnswer(s1, "owner3",
QuestionAnswer.Answer.B);
s1.addQuestionAnswer(q1);
s1.addQuestionAnswer(q2);
s1.save();
assertEquals(1, Session.find.all().size());
assertEquals(2, QuestionAnswer.find.all().size());
assertEquals(2, s1.questionAnswers.size());
s1.resetAnswers();
assertEquals(1, Session.find.all().size());
assertEquals(0, QuestionAnswer.find.all().size());
}
@Test
public void testSessionFindFromOwner() {
// Find Sessions from a given owner
Session s1 = new Session("owner1", "Session1");
Session s2 = new Session("owner1", "Session2");
Session s3 = new Session("owner2", "Session3");
s1.save();
s2.save();
s3.save();
assertEquals(3, Session.find.all().size());
assertEquals(2, Session.findFromOwner("owner1").size());
assertEquals(1, Session.findFromOwner("owner2").size());
s1.delete();
assertEquals(Session.find.all().size(), 0);
assertEquals(Vote.find.all().size(), 0);
assertEquals(1, Session.findFromOwner("owner1").size());
}
@Test
public void testSessionId() {
Session s1 = new Session("owner1", "Session1");
Session s2 = new Session("owner1", "Session2");
s1.save();
s2.save();
assertEquals(5, s1.id.length());
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment