Created task 02.
This commit is contained in:
commit
691eecb411
4 changed files with 140 additions and 0 deletions
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
**/.idea
|
||||||
|
**/target
|
48
task02/pom.xml
Normal file
48
task02/pom.xml
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
<?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>
|
||||||
|
|
||||||
|
<groupId>org.example</groupId>
|
||||||
|
<artifactId>task02</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.source>18</maven.compiler.source>
|
||||||
|
<maven.compiler.target>18</maven.compiler.target>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.javalin</groupId>
|
||||||
|
<artifactId>javalin</artifactId>
|
||||||
|
<version>5.4.2</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.slf4j</groupId>
|
||||||
|
<artifactId>slf4j-simple</artifactId>
|
||||||
|
<version>2.0.6</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.fasterxml.jackson.core</groupId>
|
||||||
|
<artifactId>jackson-databind</artifactId>
|
||||||
|
<version>2.14.2</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.junit.jupiter</groupId>
|
||||||
|
<artifactId>junit-jupiter-engine</artifactId>
|
||||||
|
<version>5.9.2</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.rest-assured</groupId>
|
||||||
|
<artifactId>rest-assured</artifactId>
|
||||||
|
<version>5.3.0</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
</project>
|
45
task02/src/main/java/de/hftstuttgart/vs/task02/Main.java
Normal file
45
task02/src/main/java/de/hftstuttgart/vs/task02/Main.java
Normal file
|
@ -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<User> 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")));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
45
task02/src/test/java/de/hftstuttgart/vs/task02/MainTest.java
Normal file
45
task02/src/test/java/de/hftstuttgart/vs/task02/MainTest.java
Normal file
|
@ -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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue