├── .gitignore ├── .travis.yml ├── README.md ├── env └── default │ ├── default.properties │ └── java.properties ├── install_latest_gauge.sh ├── manifest.json ├── pom.xml ├── specs └── paymentService.spec └── src └── test └── java └── com └── thoughtworks └── gauge └── example └── java ├── DebitCard.java ├── DebitCardProcessor.java ├── PaymentService.java ├── PaypalDebitCardProcessor.java ├── Receipt.java ├── ReceiptStatus.java ├── RegisterIOC.java └── SpringGaugeTestApp.java /.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | reports/ 3 | gauge_bin/ 4 | logs/ 5 | .idea/* 6 | out 7 | *.iml 8 | .gauge/ 9 | target/ 10 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | os: 2 | - osx 3 | 4 | language: java 5 | 6 | before_install: 7 | - brew update 8 | 9 | install: 10 | - brew cask install google-chrome 11 | - brew cask install chromedriver 12 | - brew install gauge 13 | - gauge install java 14 | - gauge install html-report 15 | 16 | cache: 17 | directories: 18 | - $HOME/.m2 19 | 20 | script: 21 | - mvn clean 22 | - mvn test 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Gauge with Spring 2 | 3 | [![Build Status](https://travis-ci.org/getgauge-examples/ioc-spring.svg?branch=master)](https://travis-ci.org/getgauge-examples/ioc-spring) 4 | 5 | This is a sample Gauge project demonstrating the use of Spring IOC framework with [Gauge](http://getgauge.io). 6 | 7 | ## Usage 8 | 9 | * [Install Gauge](https://docs.gauge.org/getting_started/installing-gauge.html) 10 | * Install Gauge java plugin `gauge install java` 11 | * Install Maven 12 | * Clone this repository 13 | * Run `mvn test` 14 | 15 | This executes the Gauge specs. Reports can be found under `reports` directory after execution. 16 | 17 | Refer [Gauge documentation](https://docs.gauge.org/latest/index.html) for more. 18 | -------------------------------------------------------------------------------- /env/default/default.properties: -------------------------------------------------------------------------------- 1 | # default.properties 2 | # properties set here will be available to the test execution as environment variables 3 | 4 | # sample_key = sample_value 5 | 6 | #The path to the gauge reports directory. Should be either relative to the project directory or an absolute path 7 | gauge_reports_dir = reports 8 | 9 | #Set as false if gauge reports should not be overwritten on each execution. A new time-stamped directory will be created on each execution. 10 | overwrite_reports = true 11 | 12 | # Set to false to disable screenshots on failure in reports. 13 | screenshot_on_failure = true 14 | 15 | # The path to the gauge logs directory. Should be either relative to the project directory or an absolute path 16 | logs_directory = logs 17 | 18 | # The path the gauge specifications directory. Takes a comma separated list of specification files/directories. 19 | gauge_specs_dir = specs 20 | 21 | # The default delimiter used read csv files. 22 | csv_delimiter = , 23 | -------------------------------------------------------------------------------- /env/default/java.properties: -------------------------------------------------------------------------------- 1 | 2 | # Specify an alternate Java home if you want to use a custom version 3 | gauge_java_home = 4 | 5 | # IntelliJ and Eclipse out directory will be usually autodetected 6 | # Use the below property if you need to override the build path 7 | gauge_custom_build_path = 8 | 9 | # specify the directory where additional libs are kept 10 | # you can specify multiple directory names separated with a comma (,) 11 | gauge_additional_libs = libs/* 12 | 13 | # JVM argument passed to java while launching 14 | gauge_jvm_args = 15 | 16 | # specify the directory containing java files to be compiled 17 | # you can specify multiple directory names separated with a comma (,) 18 | gauge_custom_compile_dir = 19 | 20 | # specify the level at which the objects should be cleared 21 | # Possible values are suite, spec and scenario. Default value is suite. 22 | gauge_clear_state_level = scenario 23 | 24 | -------------------------------------------------------------------------------- /install_latest_gauge.sh: -------------------------------------------------------------------------------- 1 | GAUGE_LATEST=`curl -w "%{url_effective}\n" -L -s -S https://github.com/getgauge/gauge/releases/latest -o /dev/null` 2 | 3 | GAUGE_LATEST_VERSION=`echo $GAUGE_LATEST | sed 's/.*\/v//'` 4 | 5 | BIT=`uname -m` 6 | 7 | if [ "$BIT"=="x86_64" ]; 8 | then 9 | GAUGE_FILE_NAME="gauge-$GAUGE_LATEST_VERSION-linux.x86_64.zip" 10 | else 11 | GAUGE_FILE_NAME="gauge-$GAUGE_LATEST_VERSION-linux.x86.zip" 12 | fi 13 | 14 | GAUGE_DOWNLOAD_URL="https://github.com/getgauge/gauge/releases/download/v$GAUGE_LATEST_VERSION/$GAUGE_FILE_NAME" 15 | 16 | wget $GAUGE_DOWNLOAD_URL 17 | 18 | OUTPUT_DIR="./gauge_$GAUGE_LATEST_VERSION" 19 | 20 | unzip $GAUGE_FILE_NAME -d $OUTPUT_DIR 21 | 22 | cd $OUTPUT_DIR 23 | 24 | /bin/bash install.sh $1 25 | -------------------------------------------------------------------------------- /manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "Language": "java", 3 | "Plugins": [ 4 | "html-report" 5 | ] 6 | } -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | sample 6 | gaugeWithSpring 7 | 1.0-SNAPSHOT 8 | 9 | 10 | 11 | bintray-repo-maven-example 12 | https://dl.bintray.com/gauge/maven-gauge-java 13 | 14 | 15 | 16 | 17 | 18 | 19 | org.springframework 20 | spring-framework-bom 21 | 5.1.18.RELEASE 22 | pom 23 | import 24 | 25 | 26 | 27 | 28 | 29 | 30 | com.thoughtworks.gauge 31 | gauge-java 32 | 0.6.9 33 | test 34 | 35 | 36 | junit 37 | junit 38 | 4.12 39 | test 40 | 41 | 42 | org.springframework 43 | spring-core 44 | 45 | 46 | org.springframework 47 | spring-context 48 | 49 | 50 | 51 | 52 | 53 | 54 | org.apache.maven.plugins 55 | maven-compiler-plugin 56 | 3.1 57 | 58 | 1.8 59 | 1.8 60 | 61 | 62 | 63 | com.thoughtworks.gauge.maven 64 | gauge-maven-plugin 65 | 1.3.4 66 | 67 | 68 | test 69 | 70 | specs 71 | 72 | 73 | execute 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | -------------------------------------------------------------------------------- /specs/paymentService.spec: -------------------------------------------------------------------------------- 1 | Payment Service 2 | =============== 3 | 4 | * Set debit card balance as "1000" rupees 5 | 6 | Successfull payment 7 | ------------------- 8 | * Pay amount "500" rupees 9 | * Pay amount "500" rupees 10 | 11 | Unsuccessful payment 12 | -------------------- 13 | * Fail to pay "2000" rupees 14 | -------------------------------------------------------------------------------- /src/test/java/com/thoughtworks/gauge/example/java/DebitCard.java: -------------------------------------------------------------------------------- 1 | package com.thoughtworks.gauge.example.java; 2 | 3 | import com.thoughtworks.gauge.Step; 4 | import org.junit.Assert; 5 | import org.springframework.stereotype.Component; 6 | 7 | @Component 8 | public class DebitCard { 9 | 10 | static final int MAX_AMOUNT = 10000; 11 | private static int balance = MAX_AMOUNT; 12 | 13 | @Step("Set debit card balance as rupees") 14 | public void setLimit(String amount) { 15 | try { 16 | balance = Integer.parseInt(amount); 17 | } catch (NumberFormatException e) { 18 | Assert.fail(String.format("Failed to parse the amount %s", amount)); 19 | } 20 | } 21 | 22 | public static boolean hasBalance(int amount) { 23 | return amount <= balance; 24 | } 25 | 26 | public static void debit(int amount) { 27 | balance -= amount; 28 | } 29 | } -------------------------------------------------------------------------------- /src/test/java/com/thoughtworks/gauge/example/java/DebitCardProcessor.java: -------------------------------------------------------------------------------- 1 | package com.thoughtworks.gauge.example.java; 2 | 3 | public interface DebitCardProcessor { 4 | Receipt charge(int amount); 5 | } 6 | -------------------------------------------------------------------------------- /src/test/java/com/thoughtworks/gauge/example/java/PaymentService.java: -------------------------------------------------------------------------------- 1 | package com.thoughtworks.gauge.example.java; 2 | 3 | import com.thoughtworks.gauge.Step; 4 | import org.springframework.stereotype.Component; 5 | 6 | import static junit.framework.TestCase.assertEquals; 7 | 8 | @Component 9 | public class PaymentService { 10 | private DebitCardProcessor processor; 11 | 12 | public PaymentService(DebitCardProcessor processor) { 13 | this.processor = processor; 14 | } 15 | 16 | @Step("Pay amount rupees") 17 | public void payMoney(String amount) { 18 | int rupees = Integer.parseInt(amount); 19 | Receipt receipt = this.processor.charge(rupees); 20 | 21 | assertEquals(receipt.getPaymentStatus(), ReceiptStatus.SUCCESS); 22 | } 23 | 24 | @Step("Fail to pay <100> rupees") 25 | public void failurePayment(String amount) { 26 | int rupees = Integer.parseInt(amount); 27 | Receipt receipt = this.processor.charge(rupees); 28 | 29 | assertEquals(receipt.getPaymentStatus(), ReceiptStatus.FAILURE); 30 | } 31 | } -------------------------------------------------------------------------------- /src/test/java/com/thoughtworks/gauge/example/java/PaypalDebitCardProcessor.java: -------------------------------------------------------------------------------- 1 | package com.thoughtworks.gauge.example.java; 2 | 3 | import org.springframework.stereotype.Component; 4 | 5 | @Component 6 | public class PaypalDebitCardProcessor implements DebitCardProcessor { 7 | 8 | @Override 9 | public Receipt charge(int amount) { 10 | if (DebitCard.hasBalance(amount)) { 11 | DebitCard.debit(amount); 12 | return new Receipt(ReceiptStatus.SUCCESS, String.format("Successfully charged rupees %d through Paypal!\n", amount)); 13 | } 14 | return new Receipt(ReceiptStatus.FAILURE, String.format("No balance to charge %d rupees\n", amount)); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/test/java/com/thoughtworks/gauge/example/java/Receipt.java: -------------------------------------------------------------------------------- 1 | package com.thoughtworks.gauge.example.java; 2 | 3 | public class Receipt { 4 | 5 | private String message; 6 | private ReceiptStatus paymentStatus; 7 | 8 | 9 | public Receipt(ReceiptStatus status, String message) { 10 | this.paymentStatus = status; 11 | this.message = message; 12 | } 13 | 14 | public ReceiptStatus getPaymentStatus() { 15 | return this.paymentStatus; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/test/java/com/thoughtworks/gauge/example/java/ReceiptStatus.java: -------------------------------------------------------------------------------- 1 | package com.thoughtworks.gauge.example.java; 2 | 3 | public enum ReceiptStatus { 4 | SUCCESS, FAILURE 5 | } 6 | -------------------------------------------------------------------------------- /src/test/java/com/thoughtworks/gauge/example/java/RegisterIOC.java: -------------------------------------------------------------------------------- 1 | package com.thoughtworks.gauge.example.java; 2 | 3 | import com.thoughtworks.gauge.ClassInitializer; 4 | import org.springframework.beans.factory.NoSuchBeanDefinitionException; 5 | import org.springframework.context.ApplicationContext; 6 | import org.springframework.context.annotation.AnnotationConfigApplicationContext; 7 | 8 | public class RegisterIOC implements ClassInitializer { 9 | 10 | private static final ApplicationContext applicationContext; 11 | 12 | static { 13 | // Initiate the application context only one-time 14 | applicationContext = new AnnotationConfigApplicationContext(SpringGaugeTestApp.class); 15 | } 16 | 17 | /** 18 | * Determine beans from Spring context when initializing. 19 | */ 20 | @Override 21 | public Object initialize(Class aClass) throws Exception { 22 | String[] beanNames = applicationContext.getBeanNamesForType(aClass); 23 | if (beanNames.length == 0) { 24 | throw new NoSuchBeanDefinitionException(aClass.getName()); 25 | } 26 | String s = beanNames[0]; 27 | return aClass.cast(applicationContext.getBean(s)); 28 | } 29 | } -------------------------------------------------------------------------------- /src/test/java/com/thoughtworks/gauge/example/java/SpringGaugeTestApp.java: -------------------------------------------------------------------------------- 1 | package com.thoughtworks.gauge.example.java; 2 | 3 | import org.springframework.context.annotation.ComponentScan; 4 | import org.springframework.context.annotation.Configuration; 5 | 6 | /** 7 | * Component scan finds all components/beans/... below this package. 8 | */ 9 | @Configuration 10 | @ComponentScan 11 | public class SpringGaugeTestApp { 12 | } 13 | --------------------------------------------------------------------------------