package de.thpeetz.kontor.media.services;

import de.thpeetz.kontor.media.TestConstants;
import de.thpeetz.kontor.media.data.MediaArticle;
import de.thpeetz.kontor.media.data.MediaVideo;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.List;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

@Slf4j
@SpringBootTest
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
public class MediaVideoServiceTest {

    @Autowired
    private MediaVideoService mediaVideoService;

    @Test
    void findAllMediaVideos() {
        assertTrue(mediaVideoService.findAllMediaVideos(null).isEmpty());
    }

    @Test
    void saveMediaVideo() {
        int mediaVideoCount = mediaVideoService.findAllMediaVideos(null).size();
        MediaVideo mediaVideo = new MediaVideo();
        mediaVideo.setUrl(TestConstants.URL);
        mediaVideoService.saveMediaVideo(mediaVideo);
        assertEquals(++mediaVideoCount, mediaVideoService.findAllMediaVideos(null).size());
    }

    @Test
    void deleteMediaVideo() {
        int mediaVideoCount = mediaVideoService.findAllMediaVideos(null).size();
        List<MediaVideo> mediaVideoList = mediaVideoService.findAllMediaVideos(TestConstants.URL);
        assertEquals(1, mediaVideoList.size());
        mediaVideoService.deleteMediaVideo(mediaVideoList.get(0));
        assertEquals(--mediaVideoCount, mediaVideoService.findAllMediaVideos(null).size());
    }
}
