This commit is contained in:
bekodeg 2024-06-07 18:40:45 +04:00
parent 7406e766e7
commit 027d5f4455
2 changed files with 1 additions and 65 deletions

View File

@ -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<Play, Long> {
public interface PlayRepository extends JpaRepository<Play, Long> {
@Query("select distinct p from Play p left join fetch p.customers c where p.id = ?1")
Optional<Play> findById(Long id);

View File

@ -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<TageEntity> 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());
}
}
}