-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModelTest.java
More file actions
49 lines (36 loc) · 1.18 KB
/
Copy pathModelTest.java
File metadata and controls
49 lines (36 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import static org.junit.Assert.*;
import java.sql.Date;
import models.Comment;
import models.Post;
import models.User;
import org.junit.Test;
import play.test.UnitTest;
public class ModelTest extends UnitTest {
@Test
public void modelTest(){
User user = new User("Diego","Ramirez","diego","1234");
assertNotNull(user);
user.save();
//retrieve user data
User newUser = User.find("username = ?", "diego").first();
assertNotNull(newUser);
assertEquals("Diego", newUser.firstname);
//Post
Date createdAt = new Date(System.currentTimeMillis()/1000);
Post post = new Post("Un post de prueba", "Lorem Ipsum", newUser, createdAt);
assertNotNull(post);
post.save();
//Retrieve post data
Post newPost = Post.find("author = ? ", newUser).first();
assertNotNull(newPost);
assertEquals("Diego", newPost.author.firstname);
//Comment
Comment comment = new Comment(newPost, newUser,"Diego", "este blog no me cabe ni un poco", createdAt);
assertNotNull(comment);
comment.save();
//retrieve comment data
Comment newComment = Comment.find("post = ?", newPost).first();
assertNotNull(newComment);
assertEquals("Diego", newComment.post.author.firstname);
}
}