Skip to content
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
@@ -0,0 +1 @@
/target/
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<!-- Your own application should inherit from spring-boot-starter-parent -->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-samples</artifactId>
<version>1.2.0.BUILD-SNAPSHOT</version>
</parent>
<artifactId>spring-boot-sample-web-jsp</artifactId>
<packaging>war</packaging>
<name>Spring Boot Web JSP Sample</name>
<description>Spring Boot Web JSP Sample</description>
<url>http://projects.spring.io/spring-boot/</url>
<organization>
<name>Pivotal Software, Inc.</name>
<url>http://www.spring.io</url>
</organization>
<properties>
<main.basedir>${basedir}/../..</main.basedir>
<java.version>1.7</java.version>
<m2eclipse.wtp.contextRoot>/</m2eclipse.wtp.contextRoot>
</properties>
<dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.8.17</version>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<version>1.3</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>1.7.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-api</artifactId>
<version>2.44.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-firefox-driver</artifactId>
<version>2.44.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-support</artifactId>
<version>2.44.0</version>
</dependency>
<dependency>
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<useSystemClassLoader>false</useSystemClassLoader>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package sample.jsp;

public class Post {
String title;
String message;
String url;
String img;


public String getTitle(){
return title;
}
public String getMessage(){
return message;
}
public String getUrl(){
return url;
}
public String getImg(){
return img;
}


public void setTitle(String title){
this.title = title;
}
public void setMessage(String message){
this.message = message;
}
public void setUrl(String url){
this.url = url;
}
public void setImg(String img){
this.img = img;
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package sample.jsp;


import java.util.List;

public interface PostService {

List<Post> getAllPosts();
void addPost(Post post);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package sample.jsp;


import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class PostServiceImpl implements PostService {

List<Post> posts = new ArrayList<Post>();

public List<Post> getAllPosts() {
return posts;
}

public void addPost(Post post) {
posts.add(post);
}

public String getByTitle(String title) {
return title;
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright 2012-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package sample.jsp;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.web.SpringBootServletInitializer;

@SpringBootApplication
public class SampleWebJspApplication extends SpringBootServletInitializer {

@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(SampleWebJspApplication.class);
}

public static void main(String[] args) throws Exception {
SpringApplication.run(SampleWebJspApplication.class, args);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package sample.jsp;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping(value = "post")
public class WelcomeController {

@Autowired
private PostServiceImpl postService;

@RequestMapping(value = "login", method = RequestMethod.GET)
public ModelAndView getLogin(){
ModelAndView model = new ModelAndView("login");
return model;
}

@RequestMapping("registration")
public String registration(Map<String, Object> model) {
return "registration";
}

@RequestMapping("about")
public String about(Map<String, Object> model) {
return "about";
}

@RequestMapping("contact")
public String contact(Map<String, Object> model) {
return "contact";
}


@RequestMapping(value = "viewAllPost", method = RequestMethod.GET)
public ModelAndView viewAllPost(){
ModelAndView rtv = new ModelAndView();
rtv.setViewName("postViewAll");
rtv.addObject("posts", postService.getAllPosts());
return rtv;
}

@RequestMapping(value = "fillPost", method = RequestMethod.GET)
public ModelAndView newPost(){
ModelAndView rtv = new ModelAndView();
rtv.setViewName("newPost");
rtv.addObject("post", new Post());
return rtv;
}

@RequestMapping(value = "addPost", method = RequestMethod.POST)
public String add(@ModelAttribute(value = "post") Post post){
postService.addPost(post);
return "redirect:viewAllPost";
}

@RequestMapping(value = "/topic/{title}", method = RequestMethod.GET)
public String getTopicById(HttpServletRequest request, @PathVariable("title") String title){
request.setAttribute("topic", postService.getByTitle(title));
return "topic";
}

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package sample.jsp;


import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;

public class addNewPost {

public static WebElement findWebElementInAddNewPostPage(By by) {
return driver.getInstance().findElement(by);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package sample.jsp;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class driver {

private static WebDriver driver;

public static WebDriver getInstance() {
if (driver == null)
driver = new FirefoxDriver();
return driver;
}

public static void closeBrowser() {
driver.quit();
}


}

Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package sample.jsp;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;

public class loginPage {



public static void goTo() {
driver.getInstance().navigate().to("http://localhost:8080/post/login");
}

public static WebElement email() {
return driver.getInstance().findElement(By.id("inputEmail"));
}
public static WebElement password() {
return driver.getInstance().findElement(By.id("inputPassword"));
}
public static WebElement submit() {
return driver.getInstance().findElement(By.xpath("html/body/div[1]/form/button"));
}

public static WebElement findWebElementInLoginPage(By by) {
return driver.getInstance().findElement(by);
}

public static EnterCredentials login(String username) {
return new EnterCredentials(username);
}

static class EnterCredentials {
private String username;

public EnterCredentials(String username) {
this.username = username;
}

public void withPassword(String password) {
email().sendKeys(username);
password().sendKeys(password);
submit().click();
}
}

public static void enterMainPage() {
goTo();
login("any@any.any")
.withPassword("any");
mainForumPage.waitForWebElementToBeClickable(By.linkText("Spring forum"));
}



}
Loading