diff --git a/demo/src/main/java/com/example/demo/repositories/PlayRepository.java b/demo/src/main/java/com/example/demo/repositories/PlayRepository.java index dc40c40..84c77e2 100644 --- a/demo/src/main/java/com/example/demo/repositories/PlayRepository.java +++ b/demo/src/main/java/com/example/demo/repositories/PlayRepository.java @@ -4,12 +4,11 @@ import com.example.demo.models.Game; import com.example.demo.models.Play; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; -import org.springframework.data.repository.CrudRepository; import java.util.List; import java.util.Optional; -public interface PlayRepository extends CrudRepository { +public interface PlayRepository extends JpaRepository { @Query("select distinct p from Play p left join fetch p.customers c where p.id = ?1") Optional findById(Long id); diff --git a/demo/src/test/java/com/example/demo/DemoApplicationTests/CustomerTests.java b/demo/src/test/java/com/example/demo/DemoApplicationTests/CustomerTests.java deleted file mode 100644 index 01c9493..0000000 --- a/demo/src/test/java/com/example/demo/DemoApplicationTests/CustomerTests.java +++ /dev/null @@ -1,63 +0,0 @@ -package com.example.demo.DemoApplicationTests; - -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; - -import java.util.ArrayList; - - @SpringBootTest - class PostsServiceTest { - @Autowired - private PostService newsService; - - @Autowired - private TageService tageService; - - List tages = new ArrayList<>(); - - @AfterEach - void removeData() { - newsService.getAll().forEach(item -> newsService.delete(item.getId())); - tageService.getAll().forEach(i -> tageService.delete(i.getId())); - } - - @Test - void getTest() { - Assertions.assertThrows(NotFoundException.class, () -> newsService.get(0L)); - } - - @Test - void CreateUpdateDelete() { - //create - removeData(); - - var tage1 = tageService.create(new TageEntity("праздник")); - var tage2 = tageService.create(new TageEntity("сессия")); - tages.add(tage1); - tages.add(tage2); - - // create - var post1 = newsService.create(new PostEntity( - "Название", new Date(), "текст новости", tages)); - var post2 = newsService.create(new PostEntity( - "9 апреля", new Date(), "просто наступил апрель", tages)); - - Assertions.assertEquals(2L, newsService.getAll().size()); - - //update - var post2new = newsService.update(post2.getId(), new PostEntity( - "2 июня", new Date(), "просто наступил ИЮНЬ" - )); - Assertions.assertEquals(2L, newsService.getAll().size()); - - // delete - newsService.delete(post2new.getId()); - Assertions.assertEquals(1L, newsService.getAll().size()); - final var lastNew = newsService.get(post1.getId()); - Assertions.assertEquals(lastNew.getText(), post1.getText()); - } - } -}