From 896fc244b2cae0c534a045ea296bd45a68587e32 Mon Sep 17 00:00:00 2001 From: Max Muir Date: Wed, 24 Apr 2019 11:05:55 -0400 Subject: [PATCH 01/21] adjusted build and properties to get Chromedriver working. --- build.gradle | 6 +++--- gradle/wrapper/gradle-wrapper.properties | 4 ++-- src/test/resources/GebConfig.groovy | 3 ++- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/build.gradle b/build.gradle index dd94235..afaa5bb 100644 --- a/build.gradle +++ b/build.gradle @@ -1,7 +1,7 @@ buildscript { ext { springBootVersion = '2.0.0.RELEASE' - seleniumVersion = '3.0.1' + seleniumVersion = '3.141.59' } repositories { mavenCentral() @@ -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.3.0") { exclude group: 'org.seleniumhq.selenium' } } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 3bba7fc..83eafb6 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -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 diff --git a/src/test/resources/GebConfig.groovy b/src/test/resources/GebConfig.groovy index 0cd397f..590985f 100644 --- a/src/test/resources/GebConfig.groovy +++ b/src/test/resources/GebConfig.groovy @@ -1,4 +1,5 @@ import io.github.bonigarcia.wdm.ChromeDriverManager +import io.github.bonigarcia.wdm.WebDriverManager import org.openqa.selenium.chrome.ChromeDriver // Location where Geb saves the screenshots and HTML dumps at the end of each test @@ -9,7 +10,7 @@ atCheckWaiting = true // Run tests in Chrome by default driver = { // Download and configure Marionette using https://github.com/bonigarcia/webdrivermanager - ChromeDriverManager.getInstance().setup() + WebDriverManager.chromedriver().setup() new ChromeDriver() } From 876b9d9f1dfeaf49bcbf727f03d1fdf90063c1ea Mon Sep 17 00:00:00 2001 From: Max Muir Date: Mon, 29 Apr 2019 13:25:55 -0400 Subject: [PATCH 02/21] Added username field --- build.gradle | 2 +- .../pillarLearningCenter/model/Post.java | 29 ++++++++++++------- src/main/resources/templates/new.html | 1 + src/main/resources/templates/posts.html | 1 + .../endToEndTests/CreatePostTest.groovy | 2 ++ .../controller/PostControllerTest.java | 2 ++ .../unitTest/service/ServiceTest.java | 1 + src/test/resources/GebConfig.groovy | 7 +++-- src/test/resources/posts/new.thtest | 1 + src/test/resources/posts/posts.thtest | 4 +++ 10 files changed, 36 insertions(+), 14 deletions(-) diff --git a/build.gradle b/build.gradle index afaa5bb..ffc1d26 100644 --- a/build.gradle +++ b/build.gradle @@ -37,7 +37,7 @@ dependencies { testCompile('org.gebish:geb-junit4:2.3') testCompile("org.seleniumhq.selenium:selenium-chrome-driver:${seleniumVersion}") - testCompile("io.github.bonigarcia:webdrivermanager:3.3.0") { + testCompile("io.github.bonigarcia:webdrivermanager:3.4.0") { exclude group: 'org.seleniumhq.selenium' } } diff --git a/src/main/java/com/pillar/pillarLearningCenter/model/Post.java b/src/main/java/com/pillar/pillarLearningCenter/model/Post.java index f5bdba8..f6bf398 100644 --- a/src/main/java/com/pillar/pillarLearningCenter/model/Post.java +++ b/src/main/java/com/pillar/pillarLearningCenter/model/Post.java @@ -1,6 +1,7 @@ package com.pillar.pillarLearningCenter.model; import javax.persistence.*; +import java.util.Objects; @Entity @Table(name = "posts") @@ -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; @@ -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; } @@ -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); } + } \ No newline at end of file diff --git a/src/main/resources/templates/new.html b/src/main/resources/templates/new.html index efbb67f..0be2219 100644 --- a/src/main/resources/templates/new.html +++ b/src/main/resources/templates/new.html @@ -2,6 +2,7 @@

Create a New Post!

+
diff --git a/src/main/resources/templates/posts.html b/src/main/resources/templates/posts.html index 5c4ea88..f6bf55f 100644 --- a/src/main/resources/templates/posts.html +++ b/src/main/resources/templates/posts.html @@ -2,6 +2,7 @@

Posts

+

diff --git a/src/test/java/com/pillar/pillarLearningCenter/endToEndTests/CreatePostTest.groovy b/src/test/java/com/pillar/pillarLearningCenter/endToEndTests/CreatePostTest.groovy index c034ece..e507128 100644 --- a/src/test/java/com/pillar/pillarLearningCenter/endToEndTests/CreatePostTest.groovy +++ b/src/test/java/com/pillar/pillarLearningCenter/endToEndTests/CreatePostTest.groovy @@ -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 p")[-1].text() == "Content here" + assert $("div h3")[-1].text() == "Max" //teardown() } } diff --git a/src/test/java/com/pillar/pillarLearningCenter/unitTest/controller/PostControllerTest.java b/src/test/java/com/pillar/pillarLearningCenter/unitTest/controller/PostControllerTest.java index 73b82b2..bf0707d 100644 --- a/src/test/java/com/pillar/pillarLearningCenter/unitTest/controller/PostControllerTest.java +++ b/src/test/java/com/pillar/pillarLearningCenter/unitTest/controller/PostControllerTest.java @@ -42,8 +42,10 @@ 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 expected = new ArrayList<>(); expected.add(onePost); expected.add(twoPost); diff --git a/src/test/java/com/pillar/pillarLearningCenter/unitTest/service/ServiceTest.java b/src/test/java/com/pillar/pillarLearningCenter/unitTest/service/ServiceTest.java index d30fee8..beb9e54 100644 --- a/src/test/java/com/pillar/pillarLearningCenter/unitTest/service/ServiceTest.java +++ b/src/test/java/com/pillar/pillarLearningCenter/unitTest/service/ServiceTest.java @@ -45,6 +45,7 @@ public void testCreatePost(){ Post post = new Post(); post.setTitle("Title One"); post.setContent("Content is Here"); + post.setUsername("max"); postService.createPost(post); diff --git a/src/test/resources/GebConfig.groovy b/src/test/resources/GebConfig.groovy index 590985f..c3fd1bb 100644 --- a/src/test/resources/GebConfig.groovy +++ b/src/test/resources/GebConfig.groovy @@ -1,6 +1,7 @@ -import io.github.bonigarcia.wdm.ChromeDriverManager + import io.github.bonigarcia.wdm.WebDriverManager import org.openqa.selenium.chrome.ChromeDriver +import static io.github.bonigarcia.wdm.DriverManagerType.CHROME // Location where Geb saves the screenshots and HTML dumps at the end of each test reportsDir = 'build/test-reports' @@ -10,7 +11,7 @@ atCheckWaiting = true // Run tests in Chrome by default driver = { // Download and configure Marionette using https://github.com/bonigarcia/webdrivermanager - WebDriverManager.chromedriver().setup() - +// WebDriverManager.chromedriver().setup() + WebDriverManager.getInstance(CHROME).setup() new ChromeDriver() } diff --git a/src/test/resources/posts/new.thtest b/src/test/resources/posts/new.thtest index 8175011..63fa7d1 100644 --- a/src/test/resources/posts/new.thtest +++ b/src/test/resources/posts/new.thtest @@ -5,6 +5,7 @@

Create a New Post!

+
diff --git a/src/test/resources/posts/posts.thtest b/src/test/resources/posts/posts.thtest index 82ddfac..4552c89 100644 --- a/src/test/resources/posts/posts.thtest +++ b/src/test/resources/posts/posts.thtest @@ -1,9 +1,11 @@ %CONTEXT postOne = new com.pillar.pillarLearningCenter.model.Post() postOne.title = 'Title' +postOne.username = 'Max' postOne.content = 'Content' postTwo = new com.pillar.pillarLearningCenter.model.Post() postTwo.title = 'Title Two' +postTwo.username = 'Max' postTwo.content = 'Content Two' postList = {postOne, postTwo} %INPUT (classpath:templates/posts.html) @@ -12,10 +14,12 @@ postList = {postOne, postTwo}

Posts

Title

+

Max

Content

Title Two

+

Max

Content Two

\ No newline at end of file From 8c6675e31884c886642ee123e1f56ae4c2f2d6a3 Mon Sep 17 00:00:00 2001 From: Max Muir Date: Wed, 1 May 2019 15:24:06 -0400 Subject: [PATCH 03/21] Removed redundant service --- .../controller/PostController.java | 9 +-- .../repository/PostRepository.java | 3 +- .../service/PostService.java | 13 ---- .../service/PostServiceImpl.java | 27 -------- src/main/resources/templates/posts.html | 1 + .../controller/PostControllerTest.java | 9 +-- .../unitTest/service/ServiceTest.java | 62 +++++++++++++++++-- .../unitTest/view/CreatePostViewTest.java | 5 +- .../unitTest/view/PostViewTest.java | 7 ++- src/test/resources/GebConfig.groovy | 1 + 10 files changed, 79 insertions(+), 58 deletions(-) delete mode 100644 src/main/java/com/pillar/pillarLearningCenter/service/PostService.java delete mode 100644 src/main/java/com/pillar/pillarLearningCenter/service/PostServiceImpl.java diff --git a/src/main/java/com/pillar/pillarLearningCenter/controller/PostController.java b/src/main/java/com/pillar/pillarLearningCenter/controller/PostController.java index 6e2eaef..e2b2faf 100644 --- a/src/main/java/com/pillar/pillarLearningCenter/controller/PostController.java +++ b/src/main/java/com/pillar/pillarLearningCenter/controller/PostController.java @@ -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; @@ -13,11 +14,11 @@ public class PostController { @Autowired - private PostService postService; + private PostRepository postService; @GetMapping("/posts") public String posts(Model model) { - List allPosts = postService.getAllPosts(); + List allPosts = postService.findAll(); model.addAttribute("postList", allPosts); return "posts"; } @@ -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"; } diff --git a/src/main/java/com/pillar/pillarLearningCenter/repository/PostRepository.java b/src/main/java/com/pillar/pillarLearningCenter/repository/PostRepository.java index f7a2838..5dd7fd7 100644 --- a/src/main/java/com/pillar/pillarLearningCenter/repository/PostRepository.java +++ b/src/main/java/com/pillar/pillarLearningCenter/repository/PostRepository.java @@ -6,6 +6,5 @@ @Repository public interface PostRepository extends JpaRepository{ - //public Post getOne(Long id); - public Post save(Post post); + } \ No newline at end of file diff --git a/src/main/java/com/pillar/pillarLearningCenter/service/PostService.java b/src/main/java/com/pillar/pillarLearningCenter/service/PostService.java deleted file mode 100644 index bff8d6c..0000000 --- a/src/main/java/com/pillar/pillarLearningCenter/service/PostService.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.pillar.pillarLearningCenter.service; - -import com.pillar.pillarLearningCenter.model.Post; - -import java.util.List; - -public interface PostService { - public List getAllPosts(); - - //public Post getPostById(Long id); - - public void createPost(Post post); -} diff --git a/src/main/java/com/pillar/pillarLearningCenter/service/PostServiceImpl.java b/src/main/java/com/pillar/pillarLearningCenter/service/PostServiceImpl.java deleted file mode 100644 index 0315ab3..0000000 --- a/src/main/java/com/pillar/pillarLearningCenter/service/PostServiceImpl.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.pillar.pillarLearningCenter.service; - -import com.pillar.pillarLearningCenter.model.Post; -import com.pillar.pillarLearningCenter.repository.PostRepository; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -import java.util.List; - -@Service -public class PostServiceImpl implements PostService { - - @Autowired - private PostRepository postRepository; - - @Override - public List getAllPosts() { - return postRepository.findAll(); - } - - /*public Post getPostById(Long id) { - return postRepository.getOne(id); - }*/ - - @Override - public void createPost(Post post){ postRepository.save(post); } -} \ No newline at end of file diff --git a/src/main/resources/templates/posts.html b/src/main/resources/templates/posts.html index f6bf55f..5601d83 100644 --- a/src/main/resources/templates/posts.html +++ b/src/main/resources/templates/posts.html @@ -4,5 +4,6 @@

Posts

+ diff --git a/src/test/java/com/pillar/pillarLearningCenter/unitTest/controller/PostControllerTest.java b/src/test/java/com/pillar/pillarLearningCenter/unitTest/controller/PostControllerTest.java index bf0707d..7fb3476 100644 --- a/src/test/java/com/pillar/pillarLearningCenter/unitTest/controller/PostControllerTest.java +++ b/src/test/java/com/pillar/pillarLearningCenter/unitTest/controller/PostControllerTest.java @@ -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; @@ -28,7 +29,7 @@ public class PostControllerTest { private PostController postController; @Mock - private PostService postService; + private PostRepository postService; private Model model = new ExtendedModelMap(); @@ -49,7 +50,7 @@ public void posts_ShouldPopulateModelWithPostData_WhenServiceReturnsPostData() { List expected = new ArrayList<>(); expected.add(onePost); expected.add(twoPost); - Mockito.when(postService.getAllPosts()).thenReturn(expected); + Mockito.when(postService.findAll()).thenReturn(expected); postController.posts(model); @@ -93,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); } } \ No newline at end of file diff --git a/src/test/java/com/pillar/pillarLearningCenter/unitTest/service/ServiceTest.java b/src/test/java/com/pillar/pillarLearningCenter/unitTest/service/ServiceTest.java index beb9e54..a7a2b57 100644 --- a/src/test/java/com/pillar/pillarLearningCenter/unitTest/service/ServiceTest.java +++ b/src/test/java/com/pillar/pillarLearningCenter/unitTest/service/ServiceTest.java @@ -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 postList = postService.findAll(); + + postService.deleteById(postList.get(0).getId()); + List 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(); @@ -34,7 +87,7 @@ public void testGetAllPosts(){ entityManager.persist(post2); entityManager.flush(); - List postList = postService.getAllPosts(); + List postList = postService.findAll(); assertEquals(postList.get(0), post); assertEquals(postList.get(1), post2); @@ -47,11 +100,12 @@ public void testCreatePost(){ 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); } + } diff --git a/src/test/java/com/pillar/pillarLearningCenter/unitTest/view/CreatePostViewTest.java b/src/test/java/com/pillar/pillarLearningCenter/unitTest/view/CreatePostViewTest.java index ee39615..88dbecb 100644 --- a/src/test/java/com/pillar/pillarLearningCenter/unitTest/view/CreatePostViewTest.java +++ b/src/test/java/com/pillar/pillarLearningCenter/unitTest/view/CreatePostViewTest.java @@ -1,7 +1,8 @@ package com.pillar.pillarLearningCenter.unitTest.view; import com.pillar.pillarLearningCenter.controller.PostController; -import com.pillar.pillarLearningCenter.service.PostService; +//import com.pillar.pillarLearningCenter.service.PostService; +import com.pillar.pillarLearningCenter.repository.PostRepository; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; @@ -22,7 +23,7 @@ public class CreatePostViewTest { MockMvc mockMvc; @MockBean - PostService postServiceMock; + PostRepository postServiceMock; @Test public void testPostNewRouteLoadsSuccessfully() throws Exception { diff --git a/src/test/java/com/pillar/pillarLearningCenter/unitTest/view/PostViewTest.java b/src/test/java/com/pillar/pillarLearningCenter/unitTest/view/PostViewTest.java index d60c4db..6633b2c 100644 --- a/src/test/java/com/pillar/pillarLearningCenter/unitTest/view/PostViewTest.java +++ b/src/test/java/com/pillar/pillarLearningCenter/unitTest/view/PostViewTest.java @@ -2,7 +2,9 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.pillar.pillarLearningCenter.controller.PostController; -import com.pillar.pillarLearningCenter.service.PostServiceImpl; +//import com.pillar.pillarLearningCenter.service.PostServiceImpl; +import com.pillar.pillarLearningCenter.repository.PostRepository; +import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; @@ -23,7 +25,7 @@ public class PostViewTest { MockMvc mockMvc; @MockBean - PostServiceImpl postServiceMock; + PostRepository postServiceMock; @Autowired ObjectMapper objectMapper; @@ -35,6 +37,7 @@ public void testPostRouteLoadsSuccessfullyWhenNoPostsArePresent() throws Excepti } @Test + @Ignore public void testPostsHtmlView(){ TestExecutor testExecutor = new TestExecutor(); testExecutor.execute("classpath:posts/posts.thtest"); diff --git a/src/test/resources/GebConfig.groovy b/src/test/resources/GebConfig.groovy index c3fd1bb..78f28bc 100644 --- a/src/test/resources/GebConfig.groovy +++ b/src/test/resources/GebConfig.groovy @@ -13,5 +13,6 @@ driver = { // Download and configure Marionette using https://github.com/bonigarcia/webdrivermanager // WebDriverManager.chromedriver().setup() WebDriverManager.getInstance(CHROME).setup() + new ChromeDriver() } From 82994dd56c5e351b4bdc862d287d7ae9d6312ec0 Mon Sep 17 00:00:00 2001 From: Max Muir Date: Thu, 2 May 2019 09:19:19 -0400 Subject: [PATCH 04/21] Updated HTML view test to expect (currently unwired) delete button --- .../pillar/pillarLearningCenter/unitTest/view/PostViewTest.java | 1 - src/test/resources/posts/posts.thtest | 2 ++ 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/test/java/com/pillar/pillarLearningCenter/unitTest/view/PostViewTest.java b/src/test/java/com/pillar/pillarLearningCenter/unitTest/view/PostViewTest.java index 6633b2c..9981cd5 100644 --- a/src/test/java/com/pillar/pillarLearningCenter/unitTest/view/PostViewTest.java +++ b/src/test/java/com/pillar/pillarLearningCenter/unitTest/view/PostViewTest.java @@ -37,7 +37,6 @@ public void testPostRouteLoadsSuccessfullyWhenNoPostsArePresent() throws Excepti } @Test - @Ignore public void testPostsHtmlView(){ TestExecutor testExecutor = new TestExecutor(); testExecutor.execute("classpath:posts/posts.thtest"); diff --git a/src/test/resources/posts/posts.thtest b/src/test/resources/posts/posts.thtest index 4552c89..89cd917 100644 --- a/src/test/resources/posts/posts.thtest +++ b/src/test/resources/posts/posts.thtest @@ -16,10 +16,12 @@ postList = {postOne, postTwo}

Title

Max

Content

+

Title Two

Max

Content Two

+
\ No newline at end of file From e7f094938c7de4acf76d910603ff361704bdbf71 Mon Sep 17 00:00:00 2001 From: Max Muir Date: Thu, 2 May 2019 11:15:06 -0400 Subject: [PATCH 05/21] Modified travis yml --- .travis.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 3cdee28..20a26aa 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,11 @@ language: java +jdk: + - oraclejdk8 cache: directories: - $HOME/.gradle script: - - ./gradlew build \ No newline at end of file + - ./gradlew build + - ./gradlew bootRun \ No newline at end of file From c64a851cc001bd4b3477e3859409a39f7dfd7bd2 Mon Sep 17 00:00:00 2001 From: Max Muir Date: Thu, 2 May 2019 11:20:43 -0400 Subject: [PATCH 06/21] Modified travis.yml to remove bootRun --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 20a26aa..baf11d4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,4 +8,3 @@ cache: script: - ./gradlew build - - ./gradlew bootRun \ No newline at end of file From d84f6e681e69d7636ce6c3c2673f7a3054dfeef6 Mon Sep 17 00:00:00 2001 From: Max Muir Date: Thu, 2 May 2019 13:06:49 -0400 Subject: [PATCH 07/21] Attempting to add testing to the travis integration --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index baf11d4..f0d54ce 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,3 +8,4 @@ cache: script: - ./gradlew build + - ./gradlew test \ No newline at end of file From 94b71275721a85b98167e19ef368a5ae34d33716 Mon Sep 17 00:00:00 2001 From: Max Muir Date: Thu, 2 May 2019 14:06:22 -0400 Subject: [PATCH 08/21] Adding scan -s flag to travis.yml --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index f0d54ce..c906eae 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,5 +7,5 @@ cache: - $HOME/.gradle script: - - ./gradlew build + - ./gradlew build --scan -s - ./gradlew test \ No newline at end of file From cc385917f2dc5d9f27b180e448272c8bb1d10821 Mon Sep 17 00:00:00 2001 From: Max Muir Date: Thu, 2 May 2019 15:00:28 -0400 Subject: [PATCH 09/21] Pew pew pew --- .travis.yml | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index c906eae..e46d9bf 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,6 +6,21 @@ cache: directories: - $HOME/.gradle +addons: + chrome: stable + +dist: trusty +services: + - xvfb + +before_script: + - "export DISPLAY=:99.0" + - "sh -e /etc/init.d/xvfb start" + - sleep 3 + - rackup +# - ./gradlew bootRun + - sleep 5 script: - - ./gradlew build --scan -s + - xvfb-run make test + - ./gradlew build - ./gradlew test \ No newline at end of file From 85ae3415ef1d7c7d2d7a90fbf8c19f396f5f6984 Mon Sep 17 00:00:00 2001 From: Max Muir Date: Thu, 2 May 2019 15:05:40 -0400 Subject: [PATCH 10/21] OK, the pew pew pew didn't work. Trying again with gradle specific stuff in the yml --- .travis.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index e46d9bf..06eaf97 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,13 +12,17 @@ addons: 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=9222 http://localhost &" + ⋮ before_script: - "export DISPLAY=:99.0" - "sh -e /etc/init.d/xvfb start" - sleep 3 - - rackup -# - ./gradlew bootRun + - ./gradlew bootRun - sleep 5 script: - xvfb-run make test From e5dbf8f1d5bc68fa0ace212388a19f0d2f880f57 Mon Sep 17 00:00:00 2001 From: Max Muir Date: Thu, 2 May 2019 15:12:02 -0400 Subject: [PATCH 11/21] what are those three dots? --- .travis.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 06eaf97..5bf8715 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,11 +12,10 @@ addons: 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=9222 http://localhost &" - ⋮ before_script: - "export DISPLAY=:99.0" From 7dc361ec3ebbb2fa8166b65b8e9a65032c3beac4 Mon Sep 17 00:00:00 2001 From: Max Muir Date: Thu, 2 May 2019 15:27:19 -0400 Subject: [PATCH 12/21] bootruntest playing with stuff --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5bf8715..3ffc897 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,8 +21,8 @@ before_script: - "export DISPLAY=:99.0" - "sh -e /etc/init.d/xvfb start" - sleep 3 - - ./gradlew bootRun - - sleep 5 + - ./gradlew bootRunTest + script: - xvfb-run make test - ./gradlew build From 336ec2dd2986111c89f4a8f4138232eed9e6b808 Mon Sep 17 00:00:00 2001 From: Max Muir Date: Thu, 2 May 2019 15:42:58 -0400 Subject: [PATCH 13/21] Removing bootRun --- .travis.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 3ffc897..497ec88 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,14 +15,13 @@ services: before_install: - # start your web application and listen on `localhost` - - "/Applications/Google\\ Chrome.app/Contents/MacOS/Google\\ Chrome --headless --disable-gpu --remote-debugging-port=9222 http://localhost &" + - "/Applications/Google\\ Chrome.app/Contents/MacOS/Google\\ Chrome --headless --disable-gpu --remote-debugging-port=8080 http://localhost &" before_script: - "export DISPLAY=:99.0" - "sh -e /etc/init.d/xvfb start" - sleep 3 - - ./gradlew bootRunTest - + script: - xvfb-run make test - ./gradlew build From d5d1587b39d8e044b553f49407e974f4bb661d68 Mon Sep 17 00:00:00 2001 From: Max Muir Date: Thu, 2 May 2019 16:12:53 -0400 Subject: [PATCH 14/21] Why don't you stop using the wrapper? --- .travis.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 497ec88..2934fd8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,8 +10,7 @@ addons: chrome: stable dist: trusty -services: - - xvfb + before_install: - # start your web application and listen on `localhost` @@ -23,6 +22,5 @@ before_script: - sleep 3 script: - - xvfb-run make test - ./gradlew build - - ./gradlew test \ No newline at end of file + - gradle test \ No newline at end of file From e8553b5a89f9a4b2dc6014de2b5f209954f19a65 Mon Sep 17 00:00:00 2001 From: Max Muir Date: Thu, 2 May 2019 16:16:56 -0400 Subject: [PATCH 15/21] More changes --- .travis.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 2934fd8..175385a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,7 +10,8 @@ addons: chrome: stable dist: trusty - +services: + - xvfb before_install: - # start your web application and listen on `localhost` @@ -22,5 +23,6 @@ before_script: - sleep 3 script: + - xvfb-run make test - ./gradlew build - - gradle test \ No newline at end of file + - test \ No newline at end of file From 0dab729afed9dc5a10242976c367406a76116d42 Mon Sep 17 00:00:00 2001 From: Max Muir Date: Thu, 2 May 2019 16:20:50 -0400 Subject: [PATCH 16/21] Why did it say test and not gradle test? ; --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 175385a..0fb5cfa 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,4 +25,4 @@ before_script: script: - xvfb-run make test - ./gradlew build - - test \ No newline at end of file + - gradle test \ No newline at end of file From 81c1f26fd7d94a71de32bbba04b3156caa4f30ce Mon Sep 17 00:00:00 2001 From: Max Muir Date: Fri, 3 May 2019 09:21:41 -0400 Subject: [PATCH 17/21] Oh, hey, the end to end test has a .groovy extension --- .travis.yml | 8 ++------ .../endToEndTests/CreatePostTest.groovy | 2 +- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index 0fb5cfa..1fd8ff6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,12 +17,8 @@ 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 &" -before_script: - - "export DISPLAY=:99.0" - - "sh -e /etc/init.d/xvfb start" - - sleep 3 script: - - xvfb-run make test + - ./gradlew build - - gradle test \ No newline at end of file + - ./gradlew bootRun & groovy CreatePostTest \ No newline at end of file diff --git a/src/test/java/com/pillar/pillarLearningCenter/endToEndTests/CreatePostTest.groovy b/src/test/java/com/pillar/pillarLearningCenter/endToEndTests/CreatePostTest.groovy index e507128..51cdcac 100644 --- a/src/test/java/com/pillar/pillarLearningCenter/endToEndTests/CreatePostTest.groovy +++ b/src/test/java/com/pillar/pillarLearningCenter/endToEndTests/CreatePostTest.groovy @@ -26,7 +26,7 @@ class CreatePostTest extends GebTest { $("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() From 619739cf2a8b0be6dbcca448f68983468fb7cfc0 Mon Sep 17 00:00:00 2001 From: Max Muir Date: Tue, 7 May 2019 14:49:36 -0400 Subject: [PATCH 18/21] Changes to remove obsolete imports and commented out statements --- .travis.yml | 2 +- build.gradle | 70 +++++++++---------- .../endToEndTests/CreatePostTest.groovy | 2 +- .../controller/PostControllerTest.java | 1 - .../unitTest/service/ServiceTest.java | 7 -- .../unitTest/view/CreatePostViewTest.java | 1 - .../unitTest/view/PostViewTest.java | 2 - 7 files changed, 37 insertions(+), 48 deletions(-) diff --git a/.travis.yml b/.travis.yml index 1fd8ff6..041a624 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,4 +21,4 @@ before_install: script: - ./gradlew build - - ./gradlew bootRun & groovy CreatePostTest \ No newline at end of file + - ./gradlew bootRun && groovy CreatePostTest \ No newline at end of file diff --git a/build.gradle b/build.gradle index ffc1d26..faa751d 100644 --- a/build.gradle +++ b/build.gradle @@ -1,14 +1,14 @@ buildscript { - ext { - springBootVersion = '2.0.0.RELEASE' - seleniumVersion = '3.141.59' - } - repositories { - mavenCentral() - } - dependencies { - classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") - } + ext { + springBootVersion = '2.0.0.RELEASE' + seleniumVersion = '3.141.59' + } + repositories { + mavenCentral() + } + dependencies { + classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") + } } apply plugin: 'java' @@ -21,41 +21,41 @@ version = '0.0.1-SNAPSHOT' sourceCompatibility = 1.8 repositories { - mavenCentral() + mavenCentral() } dependencies { - compile('org.springframework.boot:spring-boot-starter-data-jpa') - compile('org.springframework.boot:spring-boot-starter-web') - compile(group: 'com.h2database', name: 'h2', version: '1.4.194') + compile('org.springframework.boot:spring-boot-starter-data-jpa') + compile('org.springframework.boot:spring-boot-starter-web') + compile(group: 'com.h2database', name: 'h2', version: '1.4.194') - compile(group: 'org.springframework.boot', name: 'spring-boot-starter-thymeleaf') + compile(group: 'org.springframework.boot', name: 'spring-boot-starter-thymeleaf') - 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.3') - testCompile("org.seleniumhq.selenium:selenium-chrome-driver:${seleniumVersion}") + 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.3') + testCompile("org.seleniumhq.selenium:selenium-chrome-driver:${seleniumVersion}") - testCompile("io.github.bonigarcia:webdrivermanager:3.4.0") { - exclude group: 'org.seleniumhq.selenium' - } + testCompile("io.github.bonigarcia:webdrivermanager:3.4.0") { + exclude group: 'org.seleniumhq.selenium' + } } task bootRunTest(type: org.springframework.boot.gradle.tasks.run.BootRun, dependsOn: build) { - group= 'Application' - doFirst() { - main = bootJar.mainClassName - classpath = sourceSets.main.runtimeClasspath - systemProperty 'spring.profiles.active', 'test' - } + group= 'Application' + doFirst() { + main = bootJar.mainClassName + classpath = sourceSets.main.runtimeClasspath + systemProperty 'spring.profiles.active', 'test' + } } task bootRunProd(type: org.springframework.boot.gradle.tasks.run.BootRun, dependsOn: build) { - group= 'Application' - doFirst() { - main = bootJar.mainClassName - classpath = sourceSets.main.runtimeClasspath - systemProperty 'spring.profiles.active', 'prod' - } + group= 'Application' + doFirst() { + main = bootJar.mainClassName + classpath = sourceSets.main.runtimeClasspath + systemProperty 'spring.profiles.active', 'prod' + } } \ No newline at end of file diff --git a/src/test/java/com/pillar/pillarLearningCenter/endToEndTests/CreatePostTest.groovy b/src/test/java/com/pillar/pillarLearningCenter/endToEndTests/CreatePostTest.groovy index 51cdcac..e507128 100644 --- a/src/test/java/com/pillar/pillarLearningCenter/endToEndTests/CreatePostTest.groovy +++ b/src/test/java/com/pillar/pillarLearningCenter/endToEndTests/CreatePostTest.groovy @@ -26,7 +26,7 @@ class CreatePostTest extends GebTest { $("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() diff --git a/src/test/java/com/pillar/pillarLearningCenter/unitTest/controller/PostControllerTest.java b/src/test/java/com/pillar/pillarLearningCenter/unitTest/controller/PostControllerTest.java index 7fb3476..00d3b1e 100644 --- a/src/test/java/com/pillar/pillarLearningCenter/unitTest/controller/PostControllerTest.java +++ b/src/test/java/com/pillar/pillarLearningCenter/unitTest/controller/PostControllerTest.java @@ -3,7 +3,6 @@ import com.pillar.pillarLearningCenter.controller.PostController; import com.pillar.pillarLearningCenter.model.Post; 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; diff --git a/src/test/java/com/pillar/pillarLearningCenter/unitTest/service/ServiceTest.java b/src/test/java/com/pillar/pillarLearningCenter/unitTest/service/ServiceTest.java index a7a2b57..f269a9e 100644 --- a/src/test/java/com/pillar/pillarLearningCenter/unitTest/service/ServiceTest.java +++ b/src/test/java/com/pillar/pillarLearningCenter/unitTest/service/ServiceTest.java @@ -2,22 +2,16 @@ import com.pillar.pillarLearningCenter.model.Post; 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 @@ -42,7 +36,6 @@ public void testGetPostById(){ assertEquals(post, postSaved); } - //(expected = javax.persistence.EntityNotFoundException.class) @Test public void getPostAndThenDeletePostRemovesPostFromList() { Post post = new Post(); diff --git a/src/test/java/com/pillar/pillarLearningCenter/unitTest/view/CreatePostViewTest.java b/src/test/java/com/pillar/pillarLearningCenter/unitTest/view/CreatePostViewTest.java index 88dbecb..5922e54 100644 --- a/src/test/java/com/pillar/pillarLearningCenter/unitTest/view/CreatePostViewTest.java +++ b/src/test/java/com/pillar/pillarLearningCenter/unitTest/view/CreatePostViewTest.java @@ -1,7 +1,6 @@ package com.pillar.pillarLearningCenter.unitTest.view; import com.pillar.pillarLearningCenter.controller.PostController; -//import com.pillar.pillarLearningCenter.service.PostService; import com.pillar.pillarLearningCenter.repository.PostRepository; import org.junit.Test; import org.junit.runner.RunWith; diff --git a/src/test/java/com/pillar/pillarLearningCenter/unitTest/view/PostViewTest.java b/src/test/java/com/pillar/pillarLearningCenter/unitTest/view/PostViewTest.java index 9981cd5..9593d91 100644 --- a/src/test/java/com/pillar/pillarLearningCenter/unitTest/view/PostViewTest.java +++ b/src/test/java/com/pillar/pillarLearningCenter/unitTest/view/PostViewTest.java @@ -2,9 +2,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.pillar.pillarLearningCenter.controller.PostController; -//import com.pillar.pillarLearningCenter.service.PostServiceImpl; import com.pillar.pillarLearningCenter.repository.PostRepository; -import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; From f7cb6ba46020356ebdda0fe44b923aa3dfa5064d Mon Sep 17 00:00:00 2001 From: Max Muir Date: Tue, 14 May 2019 14:53:27 -0400 Subject: [PATCH 19/21] No more groovy. Ash will be sad. --- .travis.yml | 3 +- build.gradle | 24 ++++++++- .../endToEndTests/CreatePostTest.java | 51 +++++++++++++++++++ ...tTest.groovy => CreatePostTestDEAD.groovy} | 3 +- 4 files changed, 77 insertions(+), 4 deletions(-) create mode 100644 src/test/java/com/pillar/pillarLearningCenter/endToEndTests/CreatePostTest.java rename src/test/java/com/pillar/pillarLearningCenter/endToEndTests/{CreatePostTest.groovy => CreatePostTestDEAD.groovy} (95%) diff --git a/.travis.yml b/.travis.yml index 041a624..c2b67d9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,4 +21,5 @@ before_install: script: - ./gradlew build - - ./gradlew bootRun && groovy CreatePostTest \ No newline at end of file + - ./gradlew bootRun & + - ./gradlew \ No newline at end of file diff --git a/build.gradle b/build.gradle index faa751d..965ea0b 100644 --- a/build.gradle +++ b/build.gradle @@ -1,3 +1,4 @@ + buildscript { ext { springBootVersion = '2.0.0.RELEASE' @@ -5,16 +6,20 @@ buildscript { } repositories { mavenCentral() + maven { url 'http://dl.bintray.com/vermeulen-mp/gradle-plugins' } } dependencies { classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") + classpath 'com.wiredforcode:gradle-spawn-plugin:0.8.0' } + } apply plugin: 'java' apply plugin: 'eclipse' apply plugin: 'org.springframework.boot' apply plugin: 'io.spring.dependency-management' +apply plugin: 'com.wiredforcode.spawn' group = 'com.pillar' version = '0.0.1-SNAPSHOT' @@ -28,13 +33,14 @@ dependencies { compile('org.springframework.boot:spring-boot-starter-data-jpa') compile('org.springframework.boot:spring-boot-starter-web') compile(group: 'com.h2database', name: 'h2', version: '1.4.194') - compile(group: 'org.springframework.boot', name: 'spring-boot-starter-thymeleaf') + compile('org.apache.ivy:ivy:2.4.0') 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.3') + testCompile("org.seleniumhq.selenium:selenium-java:${seleniumVersion}") testCompile("org.seleniumhq.selenium:selenium-chrome-driver:${seleniumVersion}") testCompile("io.github.bonigarcia:webdrivermanager:3.4.0") { @@ -42,6 +48,12 @@ dependencies { } } +bootRun { + if (project.hasProperty('args')) { + args project.args.split(',') + } +} + task bootRunTest(type: org.springframework.boot.gradle.tasks.run.BootRun, dependsOn: build) { group= 'Application' doFirst() { @@ -58,4 +70,12 @@ task bootRunProd(type: org.springframework.boot.gradle.tasks.run.BootRun, depend classpath = sourceSets.main.runtimeClasspath systemProperty 'spring.profiles.active', 'prod' } -} \ No newline at end of file +} + + +task startServer(type: SpawnProcessTask, dependsOn: 'assemble') { + command "java -jar ${projectDir}/build/libs/zim-service.jar" + ready 'Started Application' +} + +task stopServer(type: KillProcessTask) \ No newline at end of file diff --git a/src/test/java/com/pillar/pillarLearningCenter/endToEndTests/CreatePostTest.java b/src/test/java/com/pillar/pillarLearningCenter/endToEndTests/CreatePostTest.java new file mode 100644 index 0000000..23065ab --- /dev/null +++ b/src/test/java/com/pillar/pillarLearningCenter/endToEndTests/CreatePostTest.java @@ -0,0 +1,51 @@ +package com.pillar.pillarLearningCenter.endToEndTests; + +import io.github.bonigarcia.wdm.WebDriverManager; +import static org.junit.Assert.assertEquals; + +import org.junit.After; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.chrome.ChromeDriver; + + +import java.util.List; + +public class CreatePostTest { + private WebDriver driver; + + @BeforeClass + public static void setupClass() { + WebDriverManager.chromedriver().setup(); + } + + @Before + public void setupTest() { + driver = new ChromeDriver(); + } + + @After + public void teardown() { + if (driver != null) { + driver.quit(); + } + } + + @Test + public void ThisThingCreatesAPost() { + driver.navigate().to("http://localhost:8080/posts/new"); + driver.findElement(By.name("title")).sendKeys("New Title - in memory"); + driver.findElement(By.name("content")).sendKeys("Content here"); + driver.findElement(By.name("username")).sendKeys("Max"); + driver.findElement(By.name("submit")).click(); + + List results = driver.findElements(By.xpath("//h1")); + String result = results.get(1).getText(); + + assertEquals("New Title - in memory", result); + } +} diff --git a/src/test/java/com/pillar/pillarLearningCenter/endToEndTests/CreatePostTest.groovy b/src/test/java/com/pillar/pillarLearningCenter/endToEndTests/CreatePostTestDEAD.groovy similarity index 95% rename from src/test/java/com/pillar/pillarLearningCenter/endToEndTests/CreatePostTest.groovy rename to src/test/java/com/pillar/pillarLearningCenter/endToEndTests/CreatePostTestDEAD.groovy index e507128..dd4c6de 100644 --- a/src/test/java/com/pillar/pillarLearningCenter/endToEndTests/CreatePostTest.groovy +++ b/src/test/java/com/pillar/pillarLearningCenter/endToEndTests/CreatePostTestDEAD.groovy @@ -1,12 +1,13 @@ package com.pillar.pillarLearningCenter.endToEndTests + import geb.junit4.GebTest import org.junit.Test import org.junit.runner.RunWith import org.junit.runners.JUnit4 @RunWith(JUnit4) -class CreatePostTest extends GebTest { +class CreatePostTestDEAD extends GebTest { //teardown method here /* @Autowired private TestEntityManager entityManager; From 9db7e39ae6a8361d420061026d974880bf484c74 Mon Sep 17 00:00:00 2001 From: Max Muir Date: Tue, 14 May 2019 15:25:50 -0400 Subject: [PATCH 20/21] Travis testing --- .travis.yml | 6 +++--- .../pillarLearningCenter/endToEndTests/CreatePostTest.java | 5 ++++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index c2b67d9..9f18a8e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,6 +20,6 @@ before_install: script: - - ./gradlew build - - ./gradlew bootRun & - - ./gradlew \ No newline at end of file + - gradle build + - gradle bootRun & + - gradle test \ No newline at end of file diff --git a/src/test/java/com/pillar/pillarLearningCenter/endToEndTests/CreatePostTest.java b/src/test/java/com/pillar/pillarLearningCenter/endToEndTests/CreatePostTest.java index 23065ab..26cdd68 100644 --- a/src/test/java/com/pillar/pillarLearningCenter/endToEndTests/CreatePostTest.java +++ b/src/test/java/com/pillar/pillarLearningCenter/endToEndTests/CreatePostTest.java @@ -11,12 +11,15 @@ import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; +import org.openqa.selenium.chrome.ChromeOptions; + import java.util.List; public class CreatePostTest { private WebDriver driver; + private ChromeOptions options = new ChromeOptions().addArguments("--headless"); @BeforeClass public static void setupClass() { @@ -25,7 +28,7 @@ public static void setupClass() { @Before public void setupTest() { - driver = new ChromeDriver(); + driver = new ChromeDriver(options); } @After From a514b591a6b80de3d4a91f1cb305a0bb66ff91f1 Mon Sep 17 00:00:00 2001 From: Max Muir Date: Tue, 14 May 2019 15:42:03 -0400 Subject: [PATCH 21/21] Modifications to remove unused code --- .travis.yml | 5 ++--- build.gradle | 31 ------------------------------- 2 files changed, 2 insertions(+), 34 deletions(-) diff --git a/.travis.yml b/.travis.yml index 9f18a8e..1c84452 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,7 +19,6 @@ before_install: script: - - - gradle build - gradle bootRun & - - gradle test \ No newline at end of file + - gradle test + - gradle --stop \ No newline at end of file diff --git a/build.gradle b/build.gradle index 965ea0b..944f9da 100644 --- a/build.gradle +++ b/build.gradle @@ -48,34 +48,3 @@ dependencies { } } -bootRun { - if (project.hasProperty('args')) { - args project.args.split(',') - } -} - -task bootRunTest(type: org.springframework.boot.gradle.tasks.run.BootRun, dependsOn: build) { - group= 'Application' - doFirst() { - main = bootJar.mainClassName - classpath = sourceSets.main.runtimeClasspath - systemProperty 'spring.profiles.active', 'test' - } -} - -task bootRunProd(type: org.springframework.boot.gradle.tasks.run.BootRun, dependsOn: build) { - group= 'Application' - doFirst() { - main = bootJar.mainClassName - classpath = sourceSets.main.runtimeClasspath - systemProperty 'spring.profiles.active', 'prod' - } -} - - -task startServer(type: SpawnProcessTask, dependsOn: 'assemble') { - command "java -jar ${projectDir}/build/libs/zim-service.jar" - ready 'Started Application' -} - -task stopServer(type: KillProcessTask) \ No newline at end of file