Commit 3108fd87 authored by Fjen Undso's avatar Fjen Undso
Browse files

ControllerTest: add missing readonly tests

parent f5fc08c8
......@@ -7,7 +7,9 @@ import static play.test.Helpers.status;
import java.util.Arrays;
import java.util.List;
import models.QuestionAnswer;
import models.Session;
import models.Vote;
import org.junit.After;
import org.junit.Before;
......@@ -71,4 +73,93 @@ public class ControllerTest {
assertEquals(2, sessionArray.length);
assertEquals(Session.find.all(), sessionList);
}
@Test
public void testGetSession() {
// Session by id
Session s1 = new Session("owner1", "Session1");
s1.save();
Session s2 = new Session("owner1", "Session2");
s2.save();
Result result = SessionController.getSession(s1.id);
assertEquals(OK, status(result));
assertEquals("application/json", contentType(result));
JsonNode json = Json.parse(contentAsString(result));
Session session = Json.fromJson(json, Session.class);
assertEquals(s1, session);
}
@Test
public void testGetSessionsbyOwner() {
// Session by owner
Session s1 = new Session("owner1", "Session1");
s1.save();
Session s2 = new Session("owner2", "Session2");
s2.save();
Result result = SessionController.getSessionsByOwner("owner1");
assertEquals(OK, status(result));
assertEquals("application/json", contentType(result));
JsonNode json = Json.parse(contentAsString(result));
Session[] sessionArray = Json.fromJson(json, Session[].class);
List<Session> sessionList = Arrays.asList(sessionArray);
assertEquals(1, sessionArray.length);
assertEquals(Session.findFromOwner("owner1"), sessionList);
}
@Test
public void testGetVotes() {
// Votes from a Session
Session s1 = new Session("owner1", "Session1");
Session s2 = new Session("owner2", "Session2");
Vote v1 = new Vote(s1, "owner3", Vote.Type.SPEED, 1);
Vote v2 = new Vote(s2, "owner3", Vote.Type.UNDERSTANDABILITY, -1);
s1.addVote(v1);
s2.addVote(v2);
s1.save();
s2.save();
Result result = SessionController.getVotes(s1.id);
assertEquals(OK, status(result));
assertEquals("application/json", contentType(result));
JsonNode json = Json.parse(contentAsString(result));
Vote[] votesArray = Json.fromJson(json, Vote[].class);
List<Vote> votesList = Arrays.asList(votesArray);
assertEquals(1, votesArray.length);
assertEquals(s1.votes, votesList);
}
@Test
public void testGetAnswers() {
// Answers from a Session
Session s1 = new Session("owner1", "Session1");
Session s2 = new Session("owner2", "Session2");
QuestionAnswer q1 = new QuestionAnswer(s1, "owner3",
QuestionAnswer.Answer.A);
QuestionAnswer q2 = new QuestionAnswer(s2, "owner3",
QuestionAnswer.Answer.B);
s1.addQuestionAnswer(q1);
s2.addQuestionAnswer(q2);
s1.save();
s2.save();
Result result = SessionController.getAnswers(s1.id);
assertEquals(OK, status(result));
assertEquals("application/json", contentType(result));
JsonNode json = Json.parse(contentAsString(result));
QuestionAnswer[] answersArray = Json.fromJson(json,
QuestionAnswer[].class);
List<QuestionAnswer> answersList = Arrays.asList(answersArray);
assertEquals(1, answersArray.length);
assertEquals(s1.questionAnswers, answersList);
}
}
\ No newline at end of file
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