Skip to content
This repository has been archived by the owner on Oct 18, 2018. It is now read-only.

add test #25

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,11 @@ public List<Commentary> getCommentaries() {

@Override
public List<Commentary> getCommentariesByPost(Post post) {
//todo add filter criteria
return new ArrayList<>(post.getCommentaries());
}

@Override
public List<Commentary> getCommentariesByUser(User user) {
//todo add filter criteria
return new ArrayList<>(user.getCommentaries());
}

Expand Down
11 changes: 6 additions & 5 deletions src/main/resources/test_database.sql
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,10 @@ INSERT INTO `authorities` VALUES ('testUser', 'ROLE_USER');

INSERT INTO `walls` VALUES (1,'testUser');

INSERT INTO `posts` VALUES (1,'test title','test message 2','2014-11-24 15:06:39','testAdmin', 1);
INSERT INTO `posts` VALUES (2,'test title','test message 1','2014-11-24 15:06:36','testUser', 1);
INSERT INTO `posts` VALUES (3,'test title','test message 3','2014-11-24 15:06:40','testUser', 1);

INSERT INTO `commentaries` VALUES (1,'test message 1','2014-11-24 15:06:40','testAdmin', 1);
INSERT INTO `commentaries` VALUES (2,'test message 2','2014-11-24 15:06:40','testAdmin', 1);
INSERT INTO `posts` VALUES (1,'post title','post message 1','2014-11-24 15:06:36','testUser', 1);
INSERT INTO `posts` VALUES (2,'post title','post message 2','2014-11-24 15:06:39','testAdmin', 1);
INSERT INTO `posts` VALUES (3,'post title','post message 3','2014-11-24 15:06:40','testUser', 1);

INSERT INTO `commentaries` VALUES (1,'comment message 1','2014-11-24 15:06:40','testAdmin', 1);

2 changes: 1 addition & 1 deletion src/main/webapp/WEB-INF/views/post.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
</div>

<div ng-controller="postCommentsCtrl" >
<ul>
<ul class="commentariesList" >
<li ng-repeat="commentary in commentaries">
<small>{{commentary.creator.username}}</small>
{{commentary.message}}
Expand Down
19 changes: 19 additions & 0 deletions src/test/java/zlogger/integration/PostServiceTest.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
package zlogger.integration;

import org.hamcrest.Matchers;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import zlogger.logic.models.Commentary;
import zlogger.logic.models.Post;
import zlogger.logic.models.User;
import zlogger.logic.models.Wall;
import zlogger.logic.services.PostService;
import zlogger.util.TestUtilities;

import java.util.List;
import java.util.Set;

import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalToIgnoringCase;
import static org.hamcrest.Matchers.notNullValue;

@RunWith(SpringJUnit4ClassRunner.class)
Expand Down Expand Up @@ -42,4 +48,17 @@ public void shouldGetPostsForWall() {
assertThat(posts, notNullValue());
}


@Test
public void shouldGetCommentariesForPost() {
//Given
Post post = postService.list().get(0);
//When get Commentaries
Set<Commentary> postCommentaries = post.getCommentaries();
//Then it is not content of Posts
Commentary commentary = postCommentaries.iterator().next();
assertThat("test is incorrect", post.getId(), equalTo(commentary.getId()));
assertThat("post.getCommentaries possible returns posts", post.getMessage(), not(equalToIgnoringCase(commentary.getMessage())));
}

}
28 changes: 28 additions & 0 deletions src/test/java/zlogger/web/PostContollerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
import org.openqa.selenium.WebElement;
import org.openqa.selenium.phantomjs.PhantomJSDriver;

import java.util.List;

import static org.hamcrest.CoreMatchers.anything;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.MatcherAssert.assertThat;

Expand All @@ -34,7 +37,32 @@ public void shouldViewPosts() {

WebElement element = driver.findElement(By.id("postsWall"));
String title = element.findElement(By.tagName("h3")).getText();

assertThat(element, notNullValue());
assertThat(title, notNullValue());
}

@Test
public void shouldViewPostAndCommentaries() {
driver.get(baseUrl + "/list");
WebElement posts = driver.findElement(By.id("postsWall"));
List<WebElement> linksToPost = posts.findElements(By.tagName("h3"));

String firstHref = linksToPost.iterator().next().findElement(By.tagName("a")).getAttribute("href");
driver.get(firstHref);

WebElement commentariesList = driver.findElement(By.className("commentariesList"));

assertThat(commentariesList, anything());
}

@Test
public void shouldViewCommentariesById() {
long postId = 1;
driver.get(baseUrl + "/post/"+postId+"/");

WebElement commentariesList = driver.findElement(By.className("commentariesList"));

assertThat(commentariesList, anything());
}
}