Skip to content

Commit

Permalink
Getting started with the project
Browse files Browse the repository at this point in the history
  • Loading branch information
luizgustavocosta committed Apr 5, 2021
1 parent c830109 commit 9e56dcd
Show file tree
Hide file tree
Showing 15 changed files with 413 additions and 0 deletions.
58 changes: 58 additions & 0 deletions .github/workflows/bcn-jug-allure-junit5.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: allure-junit5-maven

on:
push:
branches-ignore:
- '!main'
jobs:
autotests:
name: Run tests and generate Allure Report
runs-on: Ubuntu-20.04
steps:
- uses: actions/checkout@v2

- uses: actions/cache@v1
with:
path: |
~/.m2/repository
key: ${{ runner.os }}-${{ github.workflow }}-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-${{ github.workflow }}-
- name: Set up JDK
uses: actions/setup-java@v1
with:
java-version: 11

- name: Install dependencies
run: mvn dependency:go-offline compile compiler:testCompile

- name: Run Test
if: always()
run: mvn package
continue-on-error: true

- name: Get Allure history
uses: actions/checkout@v2
if: always()
continue-on-error: true
with:
ref: gh-pages
path: gh-pages

- name: Allure Report action from marketplace
uses: simple-elf/allure-report-action@master
if: always()
id: allure-report
with:
allure_results: target/allure-results
gh_pages: gh-pages
allure_report: allure-report
allure_history: allure-history

- name: Deploy report to Github Pages
if: always()
uses: peaceiris/actions-gh-pages@v2
env:
PERSONAL_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PUBLISH_BRANCH: gh-pages
PUBLISH_DIR: allure-history
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,8 @@

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*

.idea
.allure
target
*.iml
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
# bcn-jug-allure-junit5
Informes con Allure y JUnit5

## References
* [Allure](https://docs.qameta.io/allure/)
* [Allure example](https://github.com/allure-examples/allure-junit5-example)
* [Payment domain](http://tfig.unece.org/contents/intro-domain-payment.htm)
138 changes: 138 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.costa.luiz</groupId>
<artifactId>allure-junit5</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>bcn-jug-allure-junit5</name>

<properties>
<java.version>11</java.version>
<junit.jupiter.version>5.6.2</junit.jupiter.version>
<junit.maven.surefire.plugin.version>2.19.1</junit.maven.surefire.plugin.version>
<junit.platform.commons.version>1.7.0</junit.platform.commons.version>
<junit.platform.surefire.provider.version>1.1.0</junit.platform.surefire.provider.version>
<maven.compiler.plugin.version>3.8.1</maven.compiler.plugin.version>
<mockito.core.version>2.24.0</mockito.core.version>
<mockito.junit.jupiter.vesion>3.3.0</mockito.junit.jupiter.vesion>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<reflections.version>0.9.10</reflections.version>
<aspectj.version>1.9.4</aspectj.version>
<allure.version>2.13.6</allure.version>
<allure.maven.version>2.10.0</allure.maven.version>
</properties>

<dependencies>
<dependency>
<groupId>org.reflections</groupId>
<artifactId>reflections</artifactId>
<version>${reflections.version}</version>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-commons</artifactId>
<version>${junit.platform.commons.version}</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit.jupiter.version}</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.jupiter.version}</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>${junit.jupiter.version}</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>${mockito.junit.jupiter.vesion}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>${mockito.core.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
<version>1.6.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.qameta.allure</groupId>
<artifactId>allure-junit5</artifactId>
<version>${allure.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.compiler.plugin.version}</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${junit.maven.surefire.plugin.version}</version>
<configuration>
<includes>
<include>**Test**.java</include>
<include>**Should.java</include>
</includes>
<testFailureIgnore>false</testFailureIgnore>
<argLine>
-Dfile.encoding=UTF-8
-javaagent:${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar
</argLine>
<systemPropertyVariables>
<allure.results.directory>${project.build.directory}/allure-results</allure.results.directory>
<junit.jupiter.extensions.autodetection.enabled>true</junit.jupiter.extensions.autodetection.enabled>
<junit.jupiter.execution.parallel.enabled>true</junit.jupiter.execution.parallel.enabled>
<junit.jupiter.execution.parallel.config.strategy>dynamic</junit.jupiter.execution.parallel.config.strategy>
</systemPropertyVariables>
</configuration>
<dependencies>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
<version>${junit.platform.surefire.provider.version}</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.jupiter.version}</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>${aspectj.version}</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>io.qameta.allure</groupId>
<artifactId>allure-maven</artifactId>
<version>${allure.maven.version}</version>
<configuration>
<reportVersion>${allure.version}</reportVersion>
<resultsDirectory>${project.build.directory}/allure-results</resultsDirectory>
</configuration>
</plugin>
</plugins>
</build>
</project>
45 changes: 45 additions & 0 deletions src/main/java/com/costa/luiz/domain/payment/Account.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.costa.luiz.domain.payment;

public class Account {

private String name;
private String iban;
// Just to simplify
private double balance;

public Account(String name, String iban, double balance) {
this.name = name;
this.iban = iban;
this.balance = balance;
}

public String getName() {
return name;
}

public String getIban() {
return iban;
}

public double getBalance() {
return balance;
}

public double balanceOperation(Operation operation, double value) {
if (value < 0d) {
throw new IllegalArgumentException("The value should be greater than zero");
}
switch (operation) {
case DEBIT:
this.balance -= value;
break;
case CREDIT:
this.balance += value;
break;
default:
throw new IllegalArgumentException("The Operation should be "+Operation.CREDIT+" or "+Operation.DEBIT);
}
return this.balance;
}

}
4 changes: 4 additions & 0 deletions src/main/java/com/costa/luiz/domain/payment/Buyer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.costa.luiz.domain.payment;

public class Buyer {
}
32 changes: 32 additions & 0 deletions src/main/java/com/costa/luiz/domain/payment/InMemoryStore.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.costa.luiz.domain.payment;

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

public class InMemoryStore<T> {

private final List<T> data;

public InMemoryStore() {
this.data = new ArrayList<>();
}

public void save(T t) {
data.add(t);
}

public void delete(T t) {
int indexToDelete = -1;
for (int index = 0; index < data.size(); index++) {
if (data.get(index).equals(t)) {
indexToDelete = index;
}
}
data.remove(indexToDelete);
}

public List<T> findAll() {
return data;
}
}
7 changes: 7 additions & 0 deletions src/main/java/com/costa/luiz/domain/payment/Operation.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.costa.luiz.domain.payment;

public enum Operation {

DEBIT,
CREDIT
}
4 changes: 4 additions & 0 deletions src/main/java/com/costa/luiz/domain/payment/Payment.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.costa.luiz.domain.payment;

public class Payment {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.costa.luiz.domain.payment;

import java.util.List;

public class PaymentBuyerRepository implements PaymentRepository<Buyer> {

InMemoryStore<Buyer> store = new InMemoryStore<>();

@Override
public void save(Buyer buyer) {
store.save(buyer);
}

@Override
public void delete(Buyer buyer) {
store.delete(buyer);
}

@Override
public List<Buyer> findAll() {
return store.findAll();
}
}
22 changes: 22 additions & 0 deletions src/main/java/com/costa/luiz/domain/payment/PaymentController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.costa.luiz.domain.payment;

/**
* This is a fake controller
*/
public class PaymentController {

private final PaymentService service;

public PaymentController(PaymentService service) {
this.service = service;
}

String transferFunds(Account buyer, Account seller, double amount) {
service.debitAccountAndTransferFunds(buyer, seller, amount);
return "Operation successfully";
}

String requestPayment() {
throw new UnsupportedOperationException("Not available");
}
}
10 changes: 10 additions & 0 deletions src/main/java/com/costa/luiz/domain/payment/PaymentRepository.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.costa.luiz.domain.payment;

import java.util.List;

interface PaymentRepository<T> {

void save(T t);
void delete(T t);
List<T> findAll();
}
25 changes: 25 additions & 0 deletions src/main/java/com/costa/luiz/domain/payment/PaymentService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.costa.luiz.domain.payment;

public class PaymentService {

void prepareForPayment(){}
void requestPayment() {}
void authorizePayment() {}
void initiatePayment() {}
void sendPayment() { }
void sendPaymentInstructions() { }

void debitAccountAndTransferFunds(Account buyer, Account seller, double amount){
buyer.balanceOperation(Operation.DEBIT, amount);
creditAccount(seller, amount);
}

void creditAccount(Account account, double amount) {
account.balanceOperation(Operation.CREDIT, amount);
}

void advicePaymentCredit(){}
void advicePaymentDebit(){}
void acknowledgeDebitAndReconcile(){}
void acknowledgeCreditAndReconcile(){}
}
Loading

0 comments on commit 9e56dcd

Please sign in to comment.