commit 691eecb411546bc3ad182f8337fb62b01498c6dd Author: magoeke Date: Mon Mar 27 00:12:11 2023 +0200 Created task 02. diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ad5d1b4 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +**/.idea +**/target diff --git a/task02/pom.xml b/task02/pom.xml new file mode 100644 index 0000000..6d11802 --- /dev/null +++ b/task02/pom.xml @@ -0,0 +1,48 @@ + + + 4.0.0 + + org.example + task02 + 1.0-SNAPSHOT + + + 18 + 18 + UTF-8 + + + + + io.javalin + javalin + 5.4.2 + + + org.slf4j + slf4j-simple + 2.0.6 + + + com.fasterxml.jackson.core + jackson-databind + 2.14.2 + + + + org.junit.jupiter + junit-jupiter-engine + 5.9.2 + test + + + io.rest-assured + rest-assured + 5.3.0 + test + + + + diff --git a/task02/src/main/java/de/hftstuttgart/vs/task02/Main.java b/task02/src/main/java/de/hftstuttgart/vs/task02/Main.java new file mode 100644 index 0000000..d901437 --- /dev/null +++ b/task02/src/main/java/de/hftstuttgart/vs/task02/Main.java @@ -0,0 +1,45 @@ +package de.hftstuttgart.vs.task02; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import io.javalin.Javalin; + +public class Main { + + /** + * Record that represents a user. + * + * @param id find a better type the object (There are multiple solutions) + * @param firstName first name of user + * @param lastName last name of user + */ + public record User(Object id, String firstName, String lastName) {} + + /** + * Why do we need a synchronized list? + */ + private final List users = Collections.synchronizedList(new ArrayList<>()); + + /** + * Develop a rest api which can execute the following tasks: + * - get a list of all users (return empty array if there is no user stored) + * - return a single user by their id (return 404 if user doesn't exist) + * - create a new user (return the correct http status) + * + * Beside developing the functionalities you should also define the endpoints. + * + * Further Information about http status codes: https://en.wikipedia.org/wiki/List_of_HTTP_status_codes + * + * @param args can be ignored + */ + public static void main(final String[] args) { + final var app = Javalin.create() + .start(7070); + + app.get("/", ctx -> ctx.json(new User("test_id", "Max", "Mustermann"))); + } + + +} diff --git a/task02/src/test/java/de/hftstuttgart/vs/task02/MainTest.java b/task02/src/test/java/de/hftstuttgart/vs/task02/MainTest.java new file mode 100644 index 0000000..f0ae636 --- /dev/null +++ b/task02/src/test/java/de/hftstuttgart/vs/task02/MainTest.java @@ -0,0 +1,45 @@ +package de.hftstuttgart.vs.task02; + +import static io.restassured.RestAssured.given; + +import org.junit.jupiter.api.Test; + +class MainTest { + + //TODO: Change path (and maybe the http method) + @Test + void getAllUsers() { + given() + .log().all() + .port(7070). + when(). + get(""). + then(). + log().all(); + } + + //TODO: Change path (and maybe the http method) + @Test + void getSpecificUser() { + given() + .log().all() + .port(7070). + when(). + get(""). + then(). + log().all(); + } + + //TODO: Change path (and maybe the http method) + @Test + void addUser() { + given() + .log().all() + .port(7070). + when(). + get(""). + then(). + log().all(); + } + +}