From dc650c014c52c136d5c88e41c32f1a670fb3a363 Mon Sep 17 00:00:00 2001
From: Otto Dvalishvili <29176362+sparrowV@users.noreply.github.com>
Date: Fri, 26 Feb 2021 08:00:21 +0400
Subject: [PATCH] Bael 4781: Introduction to ZeroCode (#10482)
* small example of hexagonal architecture in java
* Bael-4781: Introduction to ZeroCode
* add readme
* Revert "small example of hexagonal architecture in java"
This reverts commit c0f96441
* refactoring
* refactoring
---
testing-modules/README.md | 3 -
testing-modules/pom.xml | 7 +-
testing-modules/zerocode/pom.xml | 102 ++++++++++++++++++
.../main/java/com/baeldung/zerocode/User.java | 31 ++++++
.../zerocode/ZerocodeApplication.java | 38 +++++++
.../zerocode/rest/UserEndpointIT.java | 18 ++++
.../test/resources/rest/user_create_test.json | 39 +++++++
.../src/test/resources/rest_api.properties | 3 +
8 files changed, 235 insertions(+), 6 deletions(-)
delete mode 100644 testing-modules/README.md
create mode 100644 testing-modules/zerocode/pom.xml
create mode 100644 testing-modules/zerocode/src/main/java/com/baeldung/zerocode/User.java
create mode 100644 testing-modules/zerocode/src/main/java/com/baeldung/zerocode/ZerocodeApplication.java
create mode 100644 testing-modules/zerocode/src/test/java/com/baeldung/zerocode/rest/UserEndpointIT.java
create mode 100644 testing-modules/zerocode/src/test/resources/rest/user_create_test.json
create mode 100644 testing-modules/zerocode/src/test/resources/rest_api.properties
diff --git a/testing-modules/README.md b/testing-modules/README.md
deleted file mode 100644
index c6098d1210..0000000000
--- a/testing-modules/README.md
+++ /dev/null
@@ -1,3 +0,0 @@
-## Testing Modules
-
-This is an aggregator module containing multiple modules focused on testing libraries.
diff --git a/testing-modules/pom.xml b/testing-modules/pom.xml
index 0416423239..fd4a13d026 100644
--- a/testing-modules/pom.xml
+++ b/testing-modules/pom.xml
@@ -31,7 +31,7 @@
rest-assured
rest-testing
selenium-junit-testng
- spring-testing
+ spring-testing
spring-testing-2
test-containers
testing-assertions
@@ -41,9 +41,10 @@
junit-5-advanced
xmlunit-2
junit-4
- testing-libraries
- testing-libraries-2
+ testing-libraries
+ testing-libraries-2
powermock
+ zerocode
diff --git a/testing-modules/zerocode/pom.xml b/testing-modules/zerocode/pom.xml
new file mode 100644
index 0000000000..9d765e6cb4
--- /dev/null
+++ b/testing-modules/zerocode/pom.xml
@@ -0,0 +1,102 @@
+
+
+ 4.0.0
+
+ testing-modules
+ com.baeldung
+ 1.0.0-SNAPSHOT
+
+
+ zerocode
+ 1.0-SNAPSHOT
+
+
+
+ org.springframework.boot
+ spring-boot-starter-web
+ ${spring.boot.version}
+
+
+
+ org.springframework.boot
+ spring-boot-starter-test
+ ${spring.boot.version}
+ test
+
+
+
+
+ org.jsmart
+ zerocode-tdd
+ 1.3.27
+ test
+
+
+
+
+
+
+ org.springframework.boot
+ spring-boot-maven-plugin
+
+
+ it
+
+
+
+
+ pre-integration-test
+
+ start
+
+
+ ${skip.it}
+
+
+
+ post-integration-test
+
+ stop
+
+
+ ${skip.it}
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-failsafe-plugin
+ 3.0.0-M5
+
+ ${skip.it}
+
+
+
+ org.apache.maven.surefire
+ surefire-junit47
+ 3.0.0-M5
+
+
+
+
+
+ integration-test
+ verify
+
+
+
+
+
+
+
+
+ UTF-8
+ 8
+ 8
+ 2.4.2
+ true
+
+
+
diff --git a/testing-modules/zerocode/src/main/java/com/baeldung/zerocode/User.java b/testing-modules/zerocode/src/main/java/com/baeldung/zerocode/User.java
new file mode 100644
index 0000000000..3a2a853220
--- /dev/null
+++ b/testing-modules/zerocode/src/main/java/com/baeldung/zerocode/User.java
@@ -0,0 +1,31 @@
+package com.baeldung.zerocode;
+
+public class User {
+ private String id;
+ private String firstName;
+ private String lastName;
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public String getFirstName() {
+ return firstName;
+ }
+
+ public void setFirstName(String firstName) {
+ this.firstName = firstName;
+ }
+
+ public String getLastName() {
+ return lastName;
+ }
+
+ public void setLastName(String lastName) {
+ this.lastName = lastName;
+ }
+}
diff --git a/testing-modules/zerocode/src/main/java/com/baeldung/zerocode/ZerocodeApplication.java b/testing-modules/zerocode/src/main/java/com/baeldung/zerocode/ZerocodeApplication.java
new file mode 100644
index 0000000000..3218e97400
--- /dev/null
+++ b/testing-modules/zerocode/src/main/java/com/baeldung/zerocode/ZerocodeApplication.java
@@ -0,0 +1,38 @@
+package com.baeldung.zerocode;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.UUID;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.util.StringUtils;
+import org.springframework.web.bind.annotation.*;
+
+@SpringBootApplication
+@RestController
+@RequestMapping("/api/users")
+public class ZerocodeApplication {
+ private List users = new ArrayList<>();
+
+ public static void main(String[] args) {
+ SpringApplication.run(ZerocodeApplication.class, args);
+ }
+
+ @PostMapping
+ public ResponseEntity create(@RequestBody User user) {
+ if (!StringUtils.hasText(user.getFirstName())) {
+ return new ResponseEntity("firstName can't be empty!", HttpStatus.BAD_REQUEST);
+ }
+ if (!StringUtils.hasText(user.getLastName())) {
+ return new ResponseEntity("lastName can't be empty!", HttpStatus.BAD_REQUEST);
+ }
+ user.setId(UUID.randomUUID()
+ .toString());
+ users.add(user);
+ return new ResponseEntity(user, HttpStatus.CREATED);
+ }
+
+}
diff --git a/testing-modules/zerocode/src/test/java/com/baeldung/zerocode/rest/UserEndpointIT.java b/testing-modules/zerocode/src/test/java/com/baeldung/zerocode/rest/UserEndpointIT.java
new file mode 100644
index 0000000000..cc461fd0fc
--- /dev/null
+++ b/testing-modules/zerocode/src/test/java/com/baeldung/zerocode/rest/UserEndpointIT.java
@@ -0,0 +1,18 @@
+package com.baeldung.zerocode.rest;
+
+import org.jsmart.zerocode.core.domain.Scenario;
+import org.jsmart.zerocode.core.domain.TargetEnv;
+import org.jsmart.zerocode.core.runner.ZeroCodeUnitRunner;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@RunWith(ZeroCodeUnitRunner.class)
+@TargetEnv("rest_api.properties")
+public class UserEndpointIT {
+
+ @Test
+ @Scenario("rest/user_create_test.json")
+ public void test_user_creation_endpoint() {
+ }
+
+}
diff --git a/testing-modules/zerocode/src/test/resources/rest/user_create_test.json b/testing-modules/zerocode/src/test/resources/rest/user_create_test.json
new file mode 100644
index 0000000000..0e8ee66196
--- /dev/null
+++ b/testing-modules/zerocode/src/test/resources/rest/user_create_test.json
@@ -0,0 +1,39 @@
+{
+ "scenarioName": "test user creation endpoint",
+ "steps": [
+ {
+ "name": "test_successful_creation",
+ "url": "/api/users",
+ "method": "POST",
+ "request": {
+ "body": {
+ "firstName": "John",
+ "lastName": "Doe"
+ }
+ },
+ "verify": {
+ "status": 201,
+ "body": {
+ "id": "$NOT.NULL",
+ "firstName": "John",
+ "lastName": "Doe"
+ }
+ }
+ },
+ {
+ "name": "test_firstname_validation",
+ "url": "/api/users",
+ "method": "POST",
+ "request": {
+ "body": {
+ "firstName": "",
+ "lastName": "Doe"
+ }
+ },
+ "assertions": {
+ "status": 400,
+ "rawBody": "firstName can't be empty!"
+ }
+ }
+ ]
+}
diff --git a/testing-modules/zerocode/src/test/resources/rest_api.properties b/testing-modules/zerocode/src/test/resources/rest_api.properties
new file mode 100644
index 0000000000..724042ade7
--- /dev/null
+++ b/testing-modules/zerocode/src/test/resources/rest_api.properties
@@ -0,0 +1,3 @@
+web.application.endpoint.host=http://localhost
+web.application.endpoint.port=8080
+web.application.endpoint.context=
\ No newline at end of file