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 80c2669fd7
commit 3b3ada68c5
8 changed files with 235 additions and 6 deletions

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=