Skip to content
Open
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
896fc24
adjusted build and properties to get Chromedriver working.
mmuir-accenture Apr 24, 2019
876b9d9
Added username field
mmuir-accenture Apr 29, 2019
8c6675e
Removed redundant service
mmuir-accenture May 1, 2019
82994dd
Updated HTML view test to expect (currently unwired) delete button
mmuir-accenture May 2, 2019
e7f0949
Modified travis yml
mmuir-accenture May 2, 2019
c64a851
Modified travis.yml to remove bootRun
mmuir-accenture May 2, 2019
d84f6e6
Attempting to add testing to the travis integration
mmuir-accenture May 2, 2019
94b7127
Adding scan -s flag to travis.yml
mmuir-accenture May 2, 2019
cc38591
Pew pew pew
mmuir-accenture May 2, 2019
85ae341
OK, the pew pew pew didn't work. Trying again with gradle specific st…
mmuir-accenture May 2, 2019
e5dbf8f
what are those three dots?
mmuir-accenture May 2, 2019
7dc361e
bootruntest playing with stuff
mmuir-accenture May 2, 2019
336ec2d
Removing bootRun
mmuir-accenture May 2, 2019
d5d1587
Why don't you stop using the wrapper?
mmuir-accenture May 2, 2019
e8553b5
More changes
mmuir-accenture May 2, 2019
0dab729
Why did it say test and not gradle test?
mmuir-accenture May 2, 2019
81c1f26
Oh, hey, the end to end test has a .groovy extension
mmuir-accenture May 3, 2019
619739c
Changes to remove obsolete imports and commented out statements
mmuir-accenture May 7, 2019
f7cb6ba
No more groovy. Ash will be sad.
mmuir-accenture May 14, 2019
9db7e39
Travis testing
mmuir-accenture May 14, 2019
a514b59
Modifications to remove unused code
mmuir-accenture May 14, 2019
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
18 changes: 17 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,24 @@
language: java

jdk:
- oraclejdk8
cache:
directories:
- $HOME/.gradle

addons:
chrome: stable

dist: trusty
services:
- xvfb

before_install:
- # start your web application and listen on `localhost`
- "/Applications/Google\\ Chrome.app/Contents/MacOS/Google\\ Chrome --headless --disable-gpu --remote-debugging-port=8080 http://localhost &"


script:
- ./gradlew build

- ./gradlew build
- ./gradlew bootRun & groovy CreatePostTest
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
buildscript {
ext {
springBootVersion = '2.0.0.RELEASE'
seleniumVersion = '3.0.1'
seleniumVersion = '3.141.59'
}
repositories {
mavenCentral()
Expand Down Expand Up @@ -34,10 +34,10 @@ dependencies {
runtime('mysql:mysql-connector-java')
testCompile('org.springframework.boot:spring-boot-starter-test')
testCompile('org.thymeleaf:thymeleaf-testing:3.0.3.RELEASE')
testCompile('org.gebish:geb-junit4:2.1')
testCompile('org.gebish:geb-junit4:2.3')
testCompile("org.seleniumhq.selenium:selenium-chrome-driver:${seleniumVersion}")

testCompile("io.github.bonigarcia:webdrivermanager:1.5.0") {
testCompile("io.github.bonigarcia:webdrivermanager:3.4.0") {
exclude group: 'org.seleniumhq.selenium'
}
}
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Fri Mar 09 11:01:42 CST 2018
#Tue Apr 23 14:06:00 EDT 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.pillar.pillarLearningCenter.controller;

import com.pillar.pillarLearningCenter.model.Post;
import com.pillar.pillarLearningCenter.service.PostService;
//import com.pillar.pillarLearningCenter.service.PostService;
import com.pillar.pillarLearningCenter.repository.PostRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
Expand All @@ -13,11 +14,11 @@
public class PostController {

@Autowired
private PostService postService;
private PostRepository postService;

@GetMapping("/posts")
public String posts(Model model) {
List<Post> allPosts = postService.getAllPosts();
List<Post> allPosts = postService.findAll();
model.addAttribute("postList", allPosts);
return "posts";
}
Expand All @@ -30,7 +31,7 @@ public String postsNew(Model model) {

@PostMapping("/posts/new")
public String submitPost(@ModelAttribute Post post) {
postService.createPost(post);
postService.save(post);
return "redirect:/posts";
}

Expand Down
29 changes: 19 additions & 10 deletions src/main/java/com/pillar/pillarLearningCenter/model/Post.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.pillar.pillarLearningCenter.model;

import javax.persistence.*;
import java.util.Objects;

@Entity
@Table(name = "posts")
Expand All @@ -14,6 +15,9 @@ public class Post {
@Column(name = "title")
public String title;

@Column(name = "username")
public String username;

@Column(name = "content")
public String content;

Expand All @@ -25,6 +29,12 @@ public String getTitle() {
return title;
}

public void setUsername(String username) {
this.username = username;
}

public String getUsername() {return username;}

public Long getId() {
return id;
}
Expand All @@ -41,17 +51,16 @@ public void setContent(String content) {
this.content = content;
}


@Override
public boolean equals(Object o) {
if(o == this) {
return true;
}

if (!(o instanceof Post)) {
return false;
}

Post post2 = (Post) o;
return post2.getId() == this.getId() && post2.getTitle().equals(this.getTitle()) && post2.getContent().equals(this.getContent());
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Post post = (Post) o;
return Objects.equals(id, post.id) &&
Objects.equals(title, post.title) &&
Objects.equals(username, post.username) &&
Objects.equals(content, post.content);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@

@Repository
public interface PostRepository extends JpaRepository<Post, Long>{
//public Post getOne(Long id);
public Post save(Post post);

}

This file was deleted.

This file was deleted.

1 change: 1 addition & 0 deletions src/main/resources/templates/new.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<h1>Create a New Post!</h1>
<form action="#" th:action="@{/posts/new}" th:object="${post}" method="post">
<label>Title: <input name="title" /></label>
<label>Username: <input name="username"/></label>
<label>Content: <input name="content" /></label>
<input name="submit" type="submit" value="Submit" />
</form>
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/templates/posts.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<h1>Posts</h1>
<div th:each="post : ${postList}">
<h1 th:text="${post.title}"></h1>
<h3 th:text="${post.username}"></h3>
<p th:text="${post.content}"></p>
<input name = "delete" type="submit" value="Delete"/>
</div>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ class CreatePostTest extends GebTest {

$("form").title = "New Title - in memory"
$("form").content = "Content here"
$("form").username = "Max"
$("input", value: "Submit").click()

assert $("h1")[0].text() == "Posts"
assert $("div h1")[-1].text() == "New Title - in memory"
assert $("div h1")[-1].text() == "New Title - in memory"
assert $("div p")[-1].text() == "Content here"
assert $("div h3")[-1].text() == "Max"
//teardown()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

import com.pillar.pillarLearningCenter.controller.PostController;
import com.pillar.pillarLearningCenter.model.Post;
import com.pillar.pillarLearningCenter.service.PostService;
import com.pillar.pillarLearningCenter.repository.PostRepository;
//import com.pillar.pillarLearningCenter.service.PostService;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand All @@ -28,7 +29,7 @@ public class PostControllerTest {
private PostController postController;

@Mock
private PostService postService;
private PostRepository postService;


private Model model = new ExtendedModelMap();
Expand All @@ -42,12 +43,14 @@ public void initMocks(){
public void posts_ShouldPopulateModelWithPostData_WhenServiceReturnsPostData() {
Post onePost = new Post();
onePost.setTitle("Title One");
onePost.setUsername("Max");
Post twoPost = new Post();
twoPost.setTitle("Title Two");
twoPost.setUsername("Max");
List<Post> expected = new ArrayList<>();
expected.add(onePost);
expected.add(twoPost);
Mockito.when(postService.getAllPosts()).thenReturn(expected);
Mockito.when(postService.findAll()).thenReturn(expected);

postController.posts(model);

Expand Down Expand Up @@ -91,7 +94,7 @@ public void submitPost_ShouldUseServiceToCreatePost_WhenCalled(){
post.setTitle("Dummy Title");
post.setContent("Dummy Content");
postController.submitPost(post);
Mockito.verify(postService).createPost(post);
Mockito.verify(postService).save(post);
}

}
Original file line number Diff line number Diff line change
@@ -1,27 +1,80 @@
package com.pillar.pillarLearningCenter.unitTest.service;

import com.pillar.pillarLearningCenter.model.Post;
import com.pillar.pillarLearningCenter.service.PostService;
import com.pillar.pillarLearningCenter.repository.PostRepository;
import org.junit.After;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
import org.springframework.boot.test.autoconfigure.orm.jpa.TestEntityManager;
import org.springframework.dao.DataRetrievalFailureException;
import org.springframework.orm.jpa.JpaObjectRetrievalFailureException;
import org.springframework.test.context.junit4.SpringRunner;

import javax.persistence.EntityNotFoundException;
import java.util.List;

import static junit.framework.TestCase.assertTrue;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;

@RunWith(SpringRunner.class)
@DataJpaTest
public class ServiceTest {
@Autowired
PostService postService;
PostRepository postService;

@Autowired
private TestEntityManager entityManager;

@Test
public void testGetPostById(){
Post post = new Post();
post.setTitle("Title One");
post.setContent("Content is Here");

entityManager.persist(post);
entityManager.flush();

Post postSaved = postService.getOne(1L);

assertEquals(post, postSaved);
}

//(expected = javax.persistence.EntityNotFoundException.class)
@Test
public void getPostAndThenDeletePostRemovesPostFromList() {
Post post = new Post();
post.setTitle("Title One");
post.setContent("Content is Here");
Post post2 = new Post();
post2.setTitle("Title 2");
post2.setContent("Content 2 is Here");
entityManager.persist(post);
entityManager.persist(post2);
entityManager.flush();
List<Post> postList = postService.findAll();

postService.deleteById(postList.get(0).getId());
List<Post> postListAfterDelete = postService.findAll();

assertEquals(postList.size() - 1, postListAfterDelete.size());
}

@Test
public void getPostByIdThrowsExceptionWhenPostNotFound() {
String message = "";
try {
Post postSaved = postService.getOne(1L);
assertEquals(postSaved, 0);
} catch (EntityNotFoundException e) {
message = e.getMessage();
}
assertEquals("Unable to find com.pillar.pillarLearningCenter.model.Post with id 1", message);
}


@Test
public void testGetAllPosts(){
Post post = new Post();
Expand All @@ -34,7 +87,7 @@ public void testGetAllPosts(){
entityManager.persist(post2);
entityManager.flush();

List<Post> postList = postService.getAllPosts();
List<Post> postList = postService.findAll();

assertEquals(postList.get(0), post);
assertEquals(postList.get(1), post2);
Expand All @@ -45,12 +98,14 @@ public void testCreatePost(){
Post post = new Post();
post.setTitle("Title One");
post.setContent("Content is Here");
post.setUsername("max");

postService.createPost(post);
postService.save(post);

Post resultPost = entityManager.find(Post.class, post.getId());

assertEquals(resultPost, post);
}


}
Loading