ЛР3 доп задание
This commit is contained in:
parent
8baede6bca
commit
3e57102a6d
BIN
data.mv.db
BIN
data.mv.db
Binary file not shown.
@ -93,4 +93,11 @@ public class FilmService {
|
||||
}
|
||||
|
||||
//сделать запрос отбора фильмов по жанру
|
||||
@Transactional
|
||||
public List<Film> findFilmOnGenre(Genre genre){
|
||||
List filmList = em.createQuery("SELECT DISTINCT f FROM Film f where :filmsGenres MEMBER OF f.genres")
|
||||
.setParameter("filmsGenres", genre)
|
||||
.getResultList();
|
||||
return filmList;
|
||||
}
|
||||
}
|
||||
|
@ -29,11 +29,11 @@ public class JpaCollectionTests {
|
||||
filmService.deleteAllFilms();
|
||||
final Film film1 = filmService.addFilm("Джокер");
|
||||
final Film film2 = filmService.addFilm("Учитель на замену");
|
||||
final Collection collection1 = collectionService.addCollection("Грустное");
|
||||
collection1.addFilm(film1);
|
||||
collection1.addFilm(film2);
|
||||
final Collection collection2 = collectionService.addCollection("Об антигерое");
|
||||
collection2.addFilm(film1);
|
||||
Collection collection1 = collectionService.addCollection("Грустное");
|
||||
collection1 = collectionService.addFilm(collection1.getId(), film1.getId());
|
||||
collection1 = collectionService.addFilm(collection1.getId(), film2.getId());
|
||||
Collection collection2 = collectionService.addCollection("Об антигерое");
|
||||
collection2 = collectionService.addFilm(collection2.getId(), film1.getId());
|
||||
log.info("testCreateCollection " + collection1.toString());
|
||||
log.info("testCreateCollection " + collection2.toString());
|
||||
Assertions.assertNotNull(collection1.getId());
|
||||
@ -44,8 +44,8 @@ public class JpaCollectionTests {
|
||||
collectionService.deleteAllCollections();
|
||||
filmService.deleteAllFilms();
|
||||
final Film film = filmService.addFilm("Астрал");
|
||||
final Collection collection = collectionService.addCollection("Пугающее");
|
||||
collection.addFilm(film);
|
||||
Collection collection = collectionService.addCollection("Пугающее");
|
||||
collection = collectionService.addFilm(collection.getId(), film.getId());
|
||||
log.info("testCollectionRead[0]: " + collection.toString());
|
||||
final Collection findCollection = collectionService.findCollection(collection.getId());
|
||||
log.info("testCollectionRead[1]: " + findCollection.toString());
|
||||
@ -58,10 +58,10 @@ public class JpaCollectionTests {
|
||||
final Film film1 = filmService.addFilm("Начало");
|
||||
final Film film2 = filmService.addFilm("Пункт назначения");
|
||||
final Film film3 = filmService.addFilm("День сурка");
|
||||
final Collection collection = collectionService.addCollection("Избранное");
|
||||
collection.addFilm(film1);
|
||||
collection.addFilm(film2);
|
||||
collection.addFilm(film3);
|
||||
Collection collection = collectionService.addCollection("Избранное");
|
||||
collection = collectionService.addFilm(collection.getId(), film1.getId());
|
||||
collection = collectionService.addFilm(collection.getId(), film2.getId());
|
||||
collection = collectionService.addFilm(collection.getId(), film3.getId());
|
||||
log.info("testAddFilms[0]: " + collection.toString());
|
||||
Assertions.assertEquals(collection.getFilms().size(), 3);
|
||||
}
|
||||
|
@ -28,11 +28,11 @@ public class JpaFilmTests {
|
||||
genreService.deleteAllGenres();
|
||||
final Genre genre1 = genreService.addGenre("Фантастика");
|
||||
final Genre genre2 = genreService.addGenre("Комедия");
|
||||
final Film film1 = filmService.addFilm("Сапожник");
|
||||
film1.addGenre(genre1);
|
||||
film1.addGenre(genre2);
|
||||
final Film film2 = filmService.addFilm("Маска");
|
||||
film2.addGenre(genre1);
|
||||
Film film1 = filmService.addFilm("Сапожник");
|
||||
film1 = filmService.addGenre(film1.getId(), genre1.getId());
|
||||
film1 = filmService.addGenre(film1.getId(), genre2.getId());
|
||||
Film film2 = filmService.addFilm("Маска");
|
||||
film2 = filmService.addGenre(film2.getId(), genre1.getId());
|
||||
log.info("testCreateFilm " + film1.toString());
|
||||
log.info("testCreateFilm " + film2.toString());
|
||||
Assertions.assertNotNull(film1.getId());
|
||||
@ -43,8 +43,8 @@ public class JpaFilmTests {
|
||||
filmService.deleteAllFilms();
|
||||
genreService.deleteAllGenres();
|
||||
final Genre genre = genreService.addGenre("Ужасы");
|
||||
final Film film = filmService.addFilm("Оно");
|
||||
film.addGenre(genre);
|
||||
Film film = filmService.addFilm("Оно");
|
||||
film = filmService.addGenre(film.getId(), genre.getId());
|
||||
log.info("testFilmRead[0]: " + film.toString());
|
||||
final Film findFilm = filmService.findFilm(film.getId());
|
||||
log.info("testFilmRead[1]: " + findFilm.toString());
|
||||
@ -57,10 +57,10 @@ public class JpaFilmTests {
|
||||
final Genre genre1 = genreService.addGenre("Драма");
|
||||
final Genre genre2 = genreService.addGenre("Триллер");
|
||||
final Genre genre3 = genreService.addGenre("Боевик");
|
||||
final Film film = filmService.addFilm("Брат");
|
||||
film.addGenre(genre1);
|
||||
film.addGenre(genre2);
|
||||
film.addGenre(genre3);
|
||||
Film film = filmService.addFilm("Брат");
|
||||
film = filmService.addGenre(film.getId(), genre1.getId());
|
||||
film = filmService.addGenre(film.getId(), genre2.getId());
|
||||
film = filmService.addGenre(film.getId(), genre3.getId());
|
||||
log.info("testAddGenres[0]: " + film.toString());
|
||||
Assertions.assertEquals(film.getGenres().size(), 3);
|
||||
}
|
||||
@ -76,4 +76,21 @@ public class JpaFilmTests {
|
||||
log.info("testFilmReadAllEmpty: " + films.toString());
|
||||
Assertions.assertEquals(films.size(), 0);
|
||||
}
|
||||
@Test
|
||||
void testSelect() {
|
||||
filmService.deleteAllFilms();
|
||||
genreService.deleteAllGenres();
|
||||
final Genre genre1 = genreService.addGenre("Драма");
|
||||
final Genre genre2 = genreService.addGenre("Триллер");
|
||||
final Genre genre3 = genreService.addGenre("Боевик");
|
||||
Film film = filmService.addFilm("Брат");
|
||||
Film film2 = filmService.addFilm("Маска");
|
||||
film = filmService.addGenre(film.getId(), genre1.getId());
|
||||
film = filmService.addGenre(film.getId(), genre2.getId());
|
||||
film = filmService.addGenre(film.getId(), genre3.getId());
|
||||
film2 = filmService.addGenre(film2.getId(), genre1.getId());
|
||||
List<Film> list = filmService.findFilmOnGenre(genre1);
|
||||
log.info("findFilmOnGenre: " + list.toString());
|
||||
Assertions.assertEquals(list.size(), 2);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user