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
This commit is contained in:
Otto Dvalishvili 2021-02-26 08:00:21 +04:00 committed by GitHub
parent 91870ad48e
commit dc650c014c
8 changed files with 235 additions and 6 deletions

View File

@ -1,3 +0,0 @@
## Testing Modules
This is an aggregator module containing multiple modules focused on testing libraries.

View File

@ -31,7 +31,7 @@
<module>rest-assured</module>
<module>rest-testing</module>
<module>selenium-junit-testng</module>
<module>spring-testing</module>
<module>spring-testing</module>
<module>spring-testing-2</module>
<module>test-containers</module>
<module>testing-assertions</module>
@ -41,9 +41,10 @@
<module>junit-5-advanced</module>
<module>xmlunit-2</module>
<module>junit-4</module>
<module>testing-libraries</module>
<module>testing-libraries-2</module>
<module>testing-libraries</module>
<module>testing-libraries-2</module>
<module>powermock</module>
<module>zerocode</module>
</modules>
</project>

View File

@ -0,0 +1,102 @@
<?xml version="1.0" encoding="UTF-8"?>
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>testing-modules</artifactId>
<groupId>com.baeldung</groupId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<artifactId>zerocode</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>${spring.boot.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>${spring.boot.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jsmart</groupId>
<artifactId>zerocode-tdd</artifactId>
<version>1.3.27</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<profiles>
<profile>it</profile>
</profiles>
</configuration>
<executions>
<execution>
<id>pre-integration-test</id>
<goals>
<goal>start</goal>
</goals>
<configuration>
<skip>${skip.it}</skip>
</configuration>
</execution>
<execution>
<id>post-integration-test</id>
<goals>
<goal>stop</goal>
</goals>
<configuration>
<skip>${skip.it}</skip>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<skip>${skip.it}</skip>
</configuration>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit47</artifactId>
<version>3.0.0-M5</version>
</dependency>
</dependencies>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<spring.boot.version>2.4.2</spring.boot.version>
<skip.it>true</skip.it>
</properties>
</project>

View File

@ -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;
}
}

View File

@ -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<User> 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);
}
}

View File

@ -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() {
}
}

View File

@ -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!"
}
}
]
}

View File

@ -0,0 +1,3 @@
web.application.endpoint.host=http://localhost
web.application.endpoint.port=8080
web.application.endpoint.context=