Skip to content

Instantly share code, notes, and snippets.

@maggandalf
maggandalf / TradingServiceSteps.java
Created April 20, 2011 17:02
Trading Service Steps for testing with JBehave
@Steps
public class TradingServiceSteps {
@Autowired
private TradingService tradingService = null;
private Stock stock;
@Given("a stock of symbol <symbol> and a threshold of <threshold>")
public void aStock(@Named("symbol")String symbol, @Named("threshold")double threshold) {
@maggandalf
maggandalf / TraderIsAlertedStories.java
Created April 20, 2011 17:03
Running All JBehave Stories
@RunWith(SpringAnnotatedEmbedderRunner.class)
@Configure(parameterConverters=ParameterConverters.EnumConverter.class)
@UsingEmbedder(embedder = Embedder.class, generateViewAfterStories = true, ignoreFailureInStories = false, ignoreFailureInView = false)
@UsingSpring(resources = { "org/jbehave/business/configuration.xml",
"org/jbehave/business/tradingService-acceptancetest.xml" })
public class TraderIsAlertedStories extends InjectableEmbedder {
@Test
public void run() throws Throwable {
injectedEmbedder().runStoriesAsPaths(storyPaths());
@maggandalf
maggandalf / configuration.xml
Created April 20, 2011 17:05
JBehave Spring Configuration File
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean class="org.jbehave.core.io.LoadFromClasspath">
<constructor-arg>
<bean class="org.jbehave.core.embedder.EmbedderClassLoader">
<constructor-arg>
<list>
@maggandalf
maggandalf / trader-test-applicationxontext.xml
Created April 20, 2011 17:06
Spring File for scanning components.
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:component-scan base-package="org.jbehave.business" />
</beans>
@maggandalf
maggandalf / HomeController.java
Created April 20, 2011 17:07
Home Controller for Trading Service.
@Controller
public class HomeController {
@Autowired
private TradingService tradingService;
/**
* Simply selects the home view to render by returning its name.
@maggandalf
maggandalf / newstock.jsp
Created April 20, 2011 17:08
New Stock Form.
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
@maggandalf
maggandalf / showstatus.jsp
Created April 20, 2011 17:08
Show stock status.
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page session="false" %>
<html>
<head>
<title>Home</title>
</head>
<body>
<h1>
Hello world!
</h1>
@maggandalf
maggandalf / TraderIsAlertedSelenium.java
Created April 20, 2011 17:10
JUnit with Selenium.
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"selenium-applicationContext.xml"})
public class TraderIsAlertedSelenium {
@Autowired
private WebDriver driver;
@Test
public void stockStatusShouldBeShowedInWebPage() {
driver.get("http://localhost:8080/JBehaveWeb/");
@maggandalf
maggandalf / selenium-applicationContext.xml
Created April 20, 2011 17:11
Selenium Spring Configuration
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<bean id="driver" class="org.openqa.selenium.firefox.FirefoxDriver"/>
@maggandalf
maggandalf / PageUtils.java
Created April 20, 2011 17:12
Utils for Selenium.
public class PageUtils {
private WebDriver webDriver;
public void open(String url) {
webDriver.get(url);
}
public void fillFormField(String fieldId, String content) {
WebElement element = webDriver.findElement(id(fieldId));