diff --git a/pom.xml b/pom.xml
index b89e8e6..436478f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -81,6 +81,11 @@
26.1.0
compile
+
+ com.h2database
+ h2
+ test
+
@@ -100,6 +105,14 @@
false
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+
+ 9
+ 9
+
+
diff --git a/src/main/java/com/example/video_downloader/controllers/VideoController.java b/src/main/java/com/example/video_downloader/controllers/VideoController.java
index 7850e91..9024d5e 100644
--- a/src/main/java/com/example/video_downloader/controllers/VideoController.java
+++ b/src/main/java/com/example/video_downloader/controllers/VideoController.java
@@ -37,8 +37,15 @@ public class VideoController {
}
@PostMapping(path = "/videos")
- public Video saveNewVideo(@RequestBody SaveNewVideoRequest request){
- return videoService.saveNewVideo(request);
+ //https://www.baeldung.com/exception-handling-for-rest-with-spring
+ //global exception handling
+
+ public ResponseEntity saveNewVideo(@RequestBody SaveNewVideoRequest request){
+ try {
+ return ResponseEntity.ok(videoService.saveNewVideo(request));
+ } catch (RuntimeException e) {
+ return ResponseEntity.badRequest().build();
+ }
}
@PostMapping(path = "/playlists")
diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties
index 24808a0..3e62623 100644
--- a/src/main/resources/application.properties
+++ b/src/main/resources/application.properties
@@ -1,7 +1,7 @@
spring.application.name=video_downloader
-spring.datasource.url = jdbc:postgresql://127.0.0.1:5432/videos
-spring.datasource.username = postgres
-spring.datasource.password = 5995
+spring.datasource.url = jdbc:postgresql://postgres.local:5432/video
+spring.datasource.username = istvan
+spring.datasource.password = .b0wU?#DXKRqfkgF,oB}da:naL4e^XjbL~}@!aNK,+n>CpKYPoDZ:%BH^W!W4U%^nrso-qMjbUw)5HVCD#2Dh=8%5]~fLsRsXW?*
spring.jpa.hibernate.ddl-auto = none
logging.level.org.flywaydb=DEBUG
logging.level.org.springframework.boot.autoconfigure.flyway=DEBUG
diff --git a/src/test/java/com/example/video_downloader/VideoDownloaderApplicationTest.java b/src/test/java/com/example/video_downloader/VideoDownloaderApplicationTest.java
new file mode 100644
index 0000000..73318d9
--- /dev/null
+++ b/src/test/java/com/example/video_downloader/VideoDownloaderApplicationTest.java
@@ -0,0 +1,70 @@
+package com.example.video_downloader;
+
+import com.example.video_downloader.entity.StatusEnum;
+import com.example.video_downloader.entity.Video;
+import com.example.video_downloader.repositories.VideoRepository;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.http.MediaType;
+import org.springframework.test.web.servlet.MockMvc;
+import org.springframework.test.web.servlet.MvcResult;
+import org.springframework.test.web.servlet.result.MockMvcResultHandlers;
+import org.springframework.test.web.servlet.setup.MockMvcBuilders;
+import org.springframework.util.Assert;
+import org.springframework.web.context.WebApplicationContext;
+
+
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
+import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
+
+
+import java.util.List;
+
+@SpringBootTest
+public class VideoDownloaderApplicationTest {
+
+ @Autowired
+ VideoRepository videoRepository;
+
+
+ private MockMvc mockMvc;
+
+ @BeforeEach
+ public void setUp(WebApplicationContext webApplicationContext) {
+ this.mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext)
+ .build();
+ }
+
+ @Test
+ void contextLoads() {
+ Video v = new Video();
+ v.setStatus(StatusEnum.NEW);
+ videoRepository.save(v);
+
+ List