Skip to content

Commit a9d97be

Browse files
committed
initial commit
0 parents  commit a9d97be

File tree

8 files changed

+368
-0
lines changed

8 files changed

+368
-0
lines changed

README.md

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# java-cli-maven-surefire-findbugs-cucumber-junit-hello-world
2+
3+
## Description
4+
Analyze source code for potential bugs.
5+
A POC for maven app using JUnit5
6+
and cucumber framework with surefire plugin.
7+
8+
## Tech stack
9+
- java
10+
- maven
11+
- findbugs
12+
- junit
13+
- surefire
14+
- cucumber
15+
16+
## Docker stack
17+
- maven:3-openjdk-17
18+
19+
## To run
20+
`sudo ./install.sh -u`
21+
- findbugs report at bin/target/findbugs
22+
23+
## To stop
24+
`sudo ./install.sh -d`
25+
26+
## For help
27+
`sudo ./install.sh -h`
28+
29+
## Credit
30+
[Code concept](https://stackoverflow.com/questions/67847818/maven-junit-5-cucumber-not-running-tests)

bin/pom.xml

+137
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
<?xml version="1.0" ?>
2+
<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">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>surefire</groupId>
5+
<artifactId>junit-cucumber</artifactId>
6+
<version>0.0.1</version>
7+
<packaging>jar</packaging>
8+
<name>Junit-Cucumber</name>
9+
<properties>
10+
<cucumber.bom.version>7.0.0</cucumber.bom.version>
11+
<java.version>1.8</java.version>
12+
<junit.bom.version>5.8.1</junit.bom.version>
13+
<maven.compiler.version>3.8.1</maven.compiler.version>
14+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
15+
<surefire.version>3.0.0-M5</surefire.version>
16+
</properties>
17+
<dependencyManagement>
18+
<dependencies>
19+
<dependency>
20+
<groupId>org.junit</groupId>
21+
<artifactId>junit-bom</artifactId>
22+
<version>${junit.bom.version}</version>
23+
<type>pom</type>
24+
<scope>import</scope>
25+
</dependency>
26+
<dependency>
27+
<groupId>io.cucumber</groupId>
28+
<artifactId>cucumber-bom</artifactId>
29+
<version>${cucumber.bom.version}</version>
30+
<type>pom</type>
31+
<scope>import</scope>
32+
</dependency>
33+
</dependencies>
34+
</dependencyManagement>
35+
<dependencies>
36+
<dependency>
37+
<groupId>io.cucumber</groupId>
38+
<artifactId>cucumber-java</artifactId>
39+
<scope>test</scope>
40+
</dependency>
41+
<dependency>
42+
<groupId>io.cucumber</groupId>
43+
<artifactId>cucumber-junit-platform-engine</artifactId>
44+
<scope>test</scope>
45+
</dependency>
46+
<dependency>
47+
<groupId>org.junit.platform</groupId>
48+
<artifactId>junit-platform-suite</artifactId>
49+
<scope>test</scope>
50+
</dependency>
51+
<dependency>
52+
<groupId>org.junit.jupiter</groupId>
53+
<artifactId>junit-jupiter</artifactId>
54+
<scope>test</scope>
55+
</dependency>
56+
</dependencies>
57+
<build>
58+
<plugins>
59+
<plugin>
60+
<groupId>org.apache.maven.plugins</groupId>
61+
<artifactId>maven-compiler-plugin</artifactId>
62+
<version>${maven.compiler.version}</version>
63+
<configuration>
64+
<encoding>${project.build.sourceEncoding}</encoding>
65+
<source>${java.version}</source>
66+
<target>${java.version}</target>
67+
</configuration>
68+
</plugin>
69+
<plugin>
70+
<groupId>org.apache.maven.plugins</groupId>
71+
<artifactId>maven-surefire-plugin</artifactId>
72+
<version>${surefire.version}</version>
73+
<configuration>
74+
<properties>
75+
<configurationParameters> cucumber.plugin=pretty,html:target/site/cucumber-pretty.html cucumber.publish.quiet=true cucumber.publish.enabled=false </configurationParameters>
76+
</properties>
77+
</configuration>
78+
</plugin>
79+
<plugin>
80+
<groupId>org.codehaus.mojo</groupId>
81+
<artifactId>findbugs-maven-plugin</artifactId>
82+
<version>3.0.5</version>
83+
<configuration>
84+
<effort>Max</effort>
85+
<failOnError>false</failOnError>
86+
<threshold>Low</threshold>
87+
<xmlOutput>true</xmlOutput>
88+
<findbugsXmlOutputDirectory>${project.build.directory}/findbugs</findbugsXmlOutputDirectory>
89+
</configuration>
90+
<executions>
91+
<execution>
92+
<id>analysis-compile</id>
93+
<phase>compile</phase>
94+
<goals>
95+
<goal>check</goal>
96+
</goals>
97+
</execution>
98+
</executions>
99+
</plugin>
100+
<plugin>
101+
<groupId>org.codehaus.mojo</groupId>
102+
<artifactId>xml-maven-plugin</artifactId>
103+
<version>1.0</version>
104+
<configuration>
105+
<transformationSets>
106+
<transformationSet>
107+
<dir>${project.build.directory}/findbugs</dir>
108+
<outputDir>${project.build.directory}/findbugs</outputDir>
109+
<stylesheet>default.xsl</stylesheet>
110+
<fileMappers>
111+
<fileMapper implementation="org.codehaus.plexus.components.io.filemappers.FileExtensionMapper">
112+
<targetExtension>.html</targetExtension>
113+
</fileMapper>
114+
</fileMappers>
115+
</transformationSet>
116+
</transformationSets>
117+
</configuration>
118+
<executions>
119+
<execution>
120+
<id>transform-compile</id>
121+
<phase>compile</phase>
122+
<goals>
123+
<goal>transform</goal>
124+
</goals>
125+
</execution>
126+
</executions>
127+
<dependencies>
128+
<dependency>
129+
<groupId>com.google.code.findbugs</groupId>
130+
<artifactId>findbugs</artifactId>
131+
<version>2.0.1</version>
132+
</dependency>
133+
</dependencies>
134+
</plugin>
135+
</plugins>
136+
</build>
137+
</project>
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package example;
2+
3+
public class Greeting {
4+
public static String greeting(String value){
5+
return "Hello World, " + value;
6+
}
7+
8+
public static void main(String[] args){
9+
System.out.println(greeting("Spiderman"));
10+
}
11+
}

bin/src/test/java/Greeting.java

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import io.cucumber.java.en.Given;
2+
import io.cucumber.java.en.Then;
3+
import io.cucumber.java.en.When;
4+
5+
import org.junit.jupiter.api.Assertions;
6+
7+
//import static org.hamcrest.MatcherAssert.assertThat;
8+
//import static org.hamcrest.core.IsEqual.equalTo;
9+
10+
public class Greeting {
11+
12+
String name, res;
13+
14+
@Given("^Name$")
15+
public void createName() {
16+
name = "Steve";
17+
}
18+
19+
@When("^Pass name to function$")
20+
public void passName() {
21+
res = example.Greeting.greeting(name);
22+
}
23+
24+
@Then("^Response should be hello world Steve$")
25+
public void checkMessage() {
26+
Assertions.assertEquals(res, "Hello World, Steve");
27+
}
28+
}
+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
import io.cucumber.junit.platform.engine.Cucumber;
3+
4+
@Cucumber
5+
public class RunCucumberTest {
6+
}
+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Feature: Greeting
2+
3+
Scenario: Greet with name
4+
Given Name
5+
When Pass name to function
6+
Then Response should be hello world Steve

general.log

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[2021-10-13 10:28:40 INFO]: install::setup-logging ended
2+
================
3+
[2021-10-13 10:28:40 INFO]: install::start-up started
4+
[2021-10-13 10:28:40 INFO]: install::start-up build image
5+
[2021-10-13 10:28:40 INFO]: install::start-up running image
6+
[2021-10-13 10:28:40 INFO]: install::start-up ended
7+
================

install.sh

+143
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
#!/usr/bin/env bash
2+
basefile="install"
3+
logfile="general.log"
4+
timestamp=`date '+%Y-%m-%d %H:%M:%S'`
5+
6+
if [ "$#" -ne 1 ]; then
7+
msg="[ERROR]: $basefile failed to receive enough args"
8+
echo "$msg"
9+
echo "$msg" >> $logfile
10+
exit 1
11+
fi
12+
13+
function setup-logging(){
14+
scope="setup-logging"
15+
info_base="[$timestamp INFO]: $basefile::$scope"
16+
17+
echo "$info_base started" >> $logfile
18+
19+
echo "$info_base removing old logs" >> $logfile
20+
21+
rm -f $logfile
22+
23+
echo "$info_base ended" >> $logfile
24+
25+
echo "================" >> $logfile
26+
}
27+
28+
function root-check(){
29+
scope="root-check"
30+
info_base="[$timestamp INFO]: $basefile::$scope"
31+
32+
echo "$info_base started" >> $logfile
33+
34+
#Make sure the script is running as root.
35+
if [ "$UID" -ne "0" ]; then
36+
echo "[$timestamp ERROR]: $basefile::$scope you must be root to run $0" >> $logfile
37+
echo "==================" >> $logfile
38+
echo "You must be root to run $0. Try the following"
39+
echo "sudo $0"
40+
exit 1
41+
fi
42+
43+
echo "$info_base ended" >> $logfile
44+
echo "================" >> $logfile
45+
}
46+
47+
function docker-check() {
48+
scope="docker-check"
49+
info_base="[$timestamp INFO]: $basefile::$scope"
50+
cmd=`docker -v`
51+
52+
echo "$info_base started" >> $logfile
53+
54+
if [ -z "$cmd" ]; then
55+
echo "$info_base docker not installed"
56+
echo "$info_base docker not installed" >> $logfile
57+
fi
58+
59+
echo "$info_base ended" >> $logfile
60+
echo "================" >> $logfile
61+
62+
}
63+
64+
function docker-compose-check() {
65+
scope="docker-compose-check"
66+
info_base="[$timestamp INFO]: $basefile::$scope"
67+
cmd=`docker-compose -v`
68+
69+
echo "$info_base started" >> $logfile
70+
71+
if [ -z "$cmd" ]; then
72+
echo "$info_base docker-compose not installed"
73+
echo "$info_base docker-compose not installed" >> $logfile
74+
fi
75+
76+
echo "$info_base ended" >> $logfile
77+
echo "================" >> $logfile
78+
79+
}
80+
function usage() {
81+
echo ""
82+
echo "Usage: "
83+
echo ""
84+
echo "-u: start."
85+
echo "-d: tear down."
86+
echo "-h: Display this help and exit."
87+
echo ""
88+
}
89+
90+
function start-up(){
91+
92+
scope="start-up"
93+
docker_img_name=`head -n 1 README.md | sed 's/# //'`
94+
info_base="[$timestamp INFO]: $basefile::$scope"
95+
96+
echo "$info_base started" >> $logfile
97+
98+
echo "$info_base build image" >> $logfile
99+
100+
docker run -it --rm --name mvn-test \
101+
-v $(pwd)/bin:/usr/src/mymaven \
102+
-w /usr/src/mymaven \
103+
maven:3-openjdk-17 \
104+
mvn clean install compile package test
105+
106+
echo "$info_base running image" >> $logfile
107+
108+
echo "$info_base ended" >> $logfile
109+
110+
echo "================" >> $logfile
111+
}
112+
function tear-down(){
113+
114+
scope="tear-down"
115+
info_base="[$timestamp INFO]: $basefile::$scope"
116+
117+
echo "$info_base started" >> $logfile
118+
119+
echo "$info_base starting services" >> $logfile
120+
121+
echo "$info_base ended" >> $logfile
122+
123+
}
124+
125+
root-check
126+
docker-check
127+
docker-compose-check
128+
129+
while getopts ":udh" opts; do
130+
case $opts in
131+
u)
132+
setup-logging
133+
start-up ;;
134+
d)
135+
tear-down ;;
136+
h)
137+
usage
138+
exit 0 ;;
139+
/?)
140+
usage
141+
exit 1 ;;
142+
esac
143+
done

0 commit comments

Comments
 (0)