diff --git a/web_frameworks/SpringBoot/docker/docker-compose.yml b/web_frameworks/SpringBoot/docker/docker-compose.yml
deleted file mode 100644
index a2b5a55..0000000
--- a/web_frameworks/SpringBoot/docker/docker-compose.yml
+++ /dev/null
@@ -1,13 +0,0 @@
-services:
- db:
- image: lcaohoanq/sample-mysql-db:2.0
- container_name: demo-crud-springboot-application
- ports:
- - "3311:3306"
- env_file:
- - ../.env
- volumes:
- - db_data:/var/lib/mysql
-
-volumes:
- db_data:
\ No newline at end of file
diff --git a/web_frameworks/SpringBoot/pom.xml b/web_frameworks/SpringBoot/pom.xml
index 4965e27..29d9b9c 100644
--- a/web_frameworks/SpringBoot/pom.xml
+++ b/web_frameworks/SpringBoot/pom.xml
@@ -107,7 +107,25 @@
com.h2database
h2
-
+
+
+ io.rest-assured
+ rest-assured
+ 5.4.0
+ test
+
+
+ org.springframework.boot
+ spring-boot-starter-test
+ test
+
+
+
+ org.junit.jupiter
+ junit-jupiter-api
+ 5.11.4
+ test
+
diff --git a/web_frameworks/SpringBoot/src/main/java/com/lcaohoanq/demo/domain/user/UserController.java b/web_frameworks/SpringBoot/src/main/java/com/lcaohoanq/demo/domain/user/UserController.java
index 2c87cdf..d3e082d 100644
--- a/web_frameworks/SpringBoot/src/main/java/com/lcaohoanq/demo/domain/user/UserController.java
+++ b/web_frameworks/SpringBoot/src/main/java/com/lcaohoanq/demo/domain/user/UserController.java
@@ -34,7 +34,7 @@ public ResponseEntity> findAll(
@RequestParam(defaultValue = "0") int page,
@RequestParam(defaultValue = "10") int size)
{
- return ResponseEntity.ok(userRepository.findAll(PageRequest.of(page, size)));
+ return ResponseEntity.ok(userRepository.findAll(PageRequest.of(page, size)).getContent());
}
@Operation(
@@ -100,6 +100,6 @@ public ResponseEntity updateUser(
@DeleteMapping("/{id}")
public ResponseEntity deleteUser(@PathVariable Long id) {
userService.delete(id);
- return ResponseEntity.ok().build();
+ return ResponseEntity.noContent().build();
}
}
\ No newline at end of file
diff --git a/web_frameworks/SpringBoot/src/test/java/com/lcaohoanq/demo/file/FileUploadTest.java b/web_frameworks/SpringBoot/src/test/java/com/lcaohoanq/demo/domain/file/FileUploadTest.java
similarity index 96%
rename from web_frameworks/SpringBoot/src/test/java/com/lcaohoanq/demo/file/FileUploadTest.java
rename to web_frameworks/SpringBoot/src/test/java/com/lcaohoanq/demo/domain/file/FileUploadTest.java
index 56d9e88..018f395 100644
--- a/web_frameworks/SpringBoot/src/test/java/com/lcaohoanq/demo/file/FileUploadTest.java
+++ b/web_frameworks/SpringBoot/src/test/java/com/lcaohoanq/demo/domain/file/FileUploadTest.java
@@ -1,4 +1,4 @@
-package com.lcaohoanq.demo.file;
+package com.lcaohoanq.demo.domain.file;
import java.io.IOException;
import java.nio.file.Files;
diff --git a/web_frameworks/SpringBoot/src/test/java/com/lcaohoanq/demo/domain/user/UserControllerIT.java b/web_frameworks/SpringBoot/src/test/java/com/lcaohoanq/demo/domain/user/UserControllerIT.java
new file mode 100644
index 0000000..43dbcfb
--- /dev/null
+++ b/web_frameworks/SpringBoot/src/test/java/com/lcaohoanq/demo/domain/user/UserControllerIT.java
@@ -0,0 +1,22 @@
+package com.lcaohoanq.demo.domain.user;
+
+import org.junit.jupiter.api.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.boot.test.web.client.TestRestTemplate;
+import org.springframework.http.ResponseEntity;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
+public class UserControllerIT {
+
+ @Autowired
+ private TestRestTemplate template;
+
+ @Test
+ public void getAllUser() throws Exception {
+ ResponseEntity response = template.getForEntity("/", String.class);
+ assertThat(response.getBody()).isEqualTo("[]");
+ }
+}
\ No newline at end of file
diff --git a/web_frameworks/SpringBoot/src/test/java/com/lcaohoanq/demo/domain/user/UserControllerRestAssuredTest.java b/web_frameworks/SpringBoot/src/test/java/com/lcaohoanq/demo/domain/user/UserControllerRestAssuredTest.java
new file mode 100644
index 0000000..4476b4d
--- /dev/null
+++ b/web_frameworks/SpringBoot/src/test/java/com/lcaohoanq/demo/domain/user/UserControllerRestAssuredTest.java
@@ -0,0 +1,39 @@
+package com.lcaohoanq.demo;
+
+import static io.restassured.RestAssured.given;
+import static org.hamcrest.Matchers.empty;
+import static org.hamcrest.Matchers.hasItems;
+
+import io.restassured.RestAssured;
+import io.restassured.http.ContentType;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.boot.test.web.server.LocalServerPort;
+import org.springframework.test.context.ActiveProfiles;
+
+@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) // Ensures random port
+@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE)
+@ActiveProfiles("test") // Ensures the test profile is used
+public class UserControllerRestAssuredTest {
+
+ @LocalServerPort
+ private int port;
+
+ @BeforeEach
+ public void setUp() {
+ RestAssured.port = port;
+ }
+
+ @Test
+ void getAll() {
+ given()
+ .when()
+ .get("/api/v1/users")
+ .then()
+ .statusCode(200)
+ .contentType(ContentType.JSON)
+ .body("", empty()); // Asserting the body is an empty array
+ }
+}
diff --git a/web_frameworks/SpringBoot/src/test/java/com/lcaohoanq/demo/domain/user/UserControllerTest.java b/web_frameworks/SpringBoot/src/test/java/com/lcaohoanq/demo/domain/user/UserControllerTest.java
new file mode 100644
index 0000000..f374291
--- /dev/null
+++ b/web_frameworks/SpringBoot/src/test/java/com/lcaohoanq/demo/domain/user/UserControllerTest.java
@@ -0,0 +1,32 @@
+package com.lcaohoanq.demo.domain.user;
+
+import static org.hamcrest.Matchers.equalTo;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
+
+import org.junit.jupiter.api.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.http.MediaType;
+import org.springframework.test.context.ActiveProfiles;
+import org.springframework.test.web.servlet.MockMvc;
+import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
+
+@SpringBootTest
+@ActiveProfiles("test")
+@AutoConfigureMockMvc
+public class UserControllerTest {
+
+ @Autowired
+ private MockMvc mvc;
+
+
+ @Test
+ public void getAllUser() throws Exception {
+ mvc.perform(MockMvcRequestBuilders.get("/api/v1/users").accept(MediaType.APPLICATION_JSON))
+ .andExpect(status().isOk())
+ .andExpect(content().string(equalTo("[]")));
+ }
+
+}
\ No newline at end of file