Compare commits
1 Commits
main
...
playlist_s
| Author | SHA1 | Date | |
|---|---|---|---|
| 7d365f5a5d |
13
pom.xml
13
pom.xml
@@ -81,6 +81,11 @@
|
|||||||
<version>26.1.0</version>
|
<version>26.1.0</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.h2database</groupId>
|
||||||
|
<artifactId>h2</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
@@ -100,6 +105,14 @@
|
|||||||
<cleanDisabled>false</cleanDisabled>
|
<cleanDisabled>false</cleanDisabled>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<source>9</source>
|
||||||
|
<target>9</target>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
|
|||||||
@@ -37,8 +37,15 @@ public class VideoController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping(path = "/videos")
|
@PostMapping(path = "/videos")
|
||||||
public Video saveNewVideo(@RequestBody SaveNewVideoRequest request){
|
//https://www.baeldung.com/exception-handling-for-rest-with-spring
|
||||||
return videoService.saveNewVideo(request);
|
//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")
|
@PostMapping(path = "/playlists")
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
spring.application.name=video_downloader
|
spring.application.name=video_downloader
|
||||||
spring.datasource.url = jdbc:postgresql://127.0.0.1:5432/videos
|
spring.datasource.url = jdbc:postgresql://postgres.local:5432/video
|
||||||
spring.datasource.username = postgres
|
spring.datasource.username = istvan
|
||||||
spring.datasource.password = 5995
|
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
|
spring.jpa.hibernate.ddl-auto = none
|
||||||
logging.level.org.flywaydb=DEBUG
|
logging.level.org.flywaydb=DEBUG
|
||||||
logging.level.org.springframework.boot.autoconfigure.flyway=DEBUG
|
logging.level.org.springframework.boot.autoconfigure.flyway=DEBUG
|
||||||
|
|||||||
@@ -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<Video> findByStatusList = videoRepository.findByStatus(StatusEnum.NEW);
|
||||||
|
Assert.isTrue(findByStatusList.size() == 10,"Anyad");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void insertListIntoVideoTest() throws Exception {
|
||||||
|
mockMvc.perform(post("/v2/videos").contentType(MediaType.APPLICATION_JSON)
|
||||||
|
.content("{\"url\":\"https://www.youtube.com/watch?v=swiGWilMqeQ&list=RDswiGWilMqeQ\"}")).andDo(MockMvcResultHandlers.print())
|
||||||
|
.andExpect(status().isBadRequest())
|
||||||
|
.andReturn();;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void insertVideoTest() throws Exception {
|
||||||
|
MvcResult mvcResult = mockMvc.perform(post("/v2/videos").contentType(MediaType.APPLICATION_JSON)
|
||||||
|
.content("{\"url\":\"https://www.youtube.com/watch?v=pOq0pJ6QLhE\"}")).andDo(print())
|
||||||
|
.andExpect(status().isOk())
|
||||||
|
.andReturn();
|
||||||
|
System.out.println(mvcResult.getResponse().getContentAsString());
|
||||||
|
}
|
||||||
|
}
|
||||||
11
src/test/resources/application.properties
Normal file
11
src/test/resources/application.properties
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
spring.application.name=video_downloader
|
||||||
|
spring.datasource.url=jdbc:h2:mem:testdb
|
||||||
|
spring.datasource.driverClassName=org.h2.Driver
|
||||||
|
spring.datasource.username=sa
|
||||||
|
spring.datasource.password=password
|
||||||
|
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
|
||||||
|
spring.jpa.hibernate.ddl-auto = update
|
||||||
|
logging.level.org.flywaydb=DEBUG
|
||||||
|
logging.level.org.springframework.boot.autoconfigure.flyway=DEBUG
|
||||||
|
spring.flyway.enabled=false
|
||||||
|
spring.flyway.baseline-on-migrate=true
|
||||||
Reference in New Issue
Block a user