Compare commits
No commits in common. "0a7bff0c2829a48cbab15ec4b237b6412eaeac80" and "feefeadbd34d252eba1808a648d6cc8cfe66470c" have entirely different histories.
0a7bff0c28
...
feefeadbd3
@ -17,7 +17,6 @@ dependencies {
|
||||
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
|
||||
implementation 'com.h2database:h2:2.1.210'
|
||||
implementation group: 'org.springdoc', name: 'springdoc-openapi-ui', version: '1.6.5'
|
||||
implementation 'org.hibernate.validator:hibernate-validator'
|
||||
testImplementation 'org.springframework.boot:spring-boot-starter-test'
|
||||
}
|
||||
|
||||
|
110
front/index.html
Normal file
110
front/index.html
Normal file
@ -0,0 +1,110 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>LabWork02</title>
|
||||
<script src="/node_modules/bootstrap/dist/js/bootstrap.min.js"></script>
|
||||
<link rel="stylesheet" href="/node_modules/bootstrap/dist/css/bootstrap.min.css">
|
||||
</head>
|
||||
<body class="bg-light">
|
||||
<div class="container">
|
||||
<div class="py-5 text-center"><h2>Лабораторная работа 2</h2></div>
|
||||
<div class="row">
|
||||
<div>
|
||||
<form>
|
||||
<div class="row">
|
||||
<div class="col-md-6 mb-3">
|
||||
<label for="input1">Значение 1 (string или double)</label>
|
||||
<input class="form-control" id="input1" placeholder="Введите значение 1">
|
||||
</div>
|
||||
<div class="col-md-6 mb-3">
|
||||
<label for="input1">Значение 2 (string или double)</label>
|
||||
<input class="form-control" id="input2" placeholder="Введите значение 2">
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="form-group">
|
||||
<label for="operator">Выберите функцию</label>
|
||||
<select class="form-control" id="operator">
|
||||
<option value>Выбрать...</option>
|
||||
<option value="Func1">(string, double)Сумма</option>
|
||||
<option value="Func2">(double)Минимум, (string)Сумма в верхний регистр</option>
|
||||
<option value="Func3">(double)Mаксимум, (string)Разделить</option>
|
||||
<option value="Func4">(double)Число 1 в степени числа 2, (string)Сумма в нижний регистр</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="form-group">
|
||||
<label for="operator">Выберите тип данных</label>
|
||||
<select class="form-control" id="Type">
|
||||
<option value>Выбрать...</option>
|
||||
<option value="str">String</option>
|
||||
<option value="double">Double</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="form-group">
|
||||
<label for="result">Результат</label>
|
||||
<input type="text" class="form-control result" id="result" readonly>
|
||||
<hr class="mb-4">
|
||||
<button type="button" class="btn btn-primary btn-block" onclick="calculate()">Посчитать</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!--<div class="container mt-4">-->
|
||||
<!-- <div class="row justify-content-center">-->
|
||||
<!-- <div class="col-lg-6">-->
|
||||
<!-- <h3 class="text-center font-weight-light my-2">Лабораторная работа 2</h3>-->
|
||||
<!-- <form>-->
|
||||
<!-- <div class="form-row">-->
|
||||
<!-- <div class="col">-->
|
||||
<!-- <div class="form-group">-->
|
||||
<!-- <label for="input1">Значение 1 (string или double)</label>-->
|
||||
<!-- <input class="form-control" id="input1" placeholder="Введите значение 1">-->
|
||||
<!-- </div>-->
|
||||
<!-- </div>-->
|
||||
<!-- <div class="col">-->
|
||||
<!-- <div class="form-group">-->
|
||||
<!-- <label for="input2">Значение 2 (string или double)</label>-->
|
||||
<!-- <input class="form-control" id="input2" placeholder="Введите значение 2">-->
|
||||
<!-- </div>-->
|
||||
<!-- </div>-->
|
||||
<!-- <div class="col">-->
|
||||
<!-- <div class="form-group">-->
|
||||
<!-- <label for="operator">Выбрать функцию...</label>-->
|
||||
<!-- <select class="form-control" id="operator">-->
|
||||
<!-- <option value="Func1">Сумма</option>-->
|
||||
<!-- <option value="Func2">Минимум, Сумма в верхний регистр</option>-->
|
||||
<!-- <option value="Func3">Mаксимум, Разделить</option>-->
|
||||
<!-- <option value="Func4">Число 1 в степени числа 2, Сумма в нижний регистр</option>-->
|
||||
<!-- </select>-->
|
||||
<!-- </div>-->
|
||||
<!-- </div>-->
|
||||
<!-- <div class="col">-->
|
||||
<!-- <div class="form-group">-->
|
||||
<!-- <label for="operator">Выбрать тип данных...</label>-->
|
||||
<!-- <select class="form-control" id="Type">-->
|
||||
<!-- <option value="str">String</option>-->
|
||||
<!-- <option value="double">Double</option>-->
|
||||
<!-- </select>-->
|
||||
<!-- </div>-->
|
||||
<!-- </div>-->
|
||||
<!-- </div>-->
|
||||
<!-- <div class="form-group">-->
|
||||
<!-- <label for="result">Результат</label>-->
|
||||
<!-- <input type="text" class="form-control result" id="result" readonly>-->
|
||||
<!-- </div>-->
|
||||
<!-- <button type="button" class="btn btn-primary btn-block" onclick="calculate()">Посчитать</button>-->
|
||||
<!-- </form>-->
|
||||
<!-- </div>-->
|
||||
<!-- </div>-->
|
||||
<!--</div>-->
|
||||
<script src = "script.js"></script>
|
||||
</body>
|
||||
</html>
|
15
front/package.json
Normal file
15
front/package.json
Normal file
@ -0,0 +1,15 @@
|
||||
{
|
||||
"name": "IP",
|
||||
"version": "1.0.0",
|
||||
"main": "index.html",
|
||||
"scripts": {
|
||||
"start": "http-server -p 3001 ./",
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"dependencies": {
|
||||
"bootstrap": "5.2.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"http-server": "^14.1.1"
|
||||
}
|
||||
}
|
13
front/script.js
Normal file
13
front/script.js
Normal file
@ -0,0 +1,13 @@
|
||||
'use strict'
|
||||
async function calculate(){
|
||||
let num1 = document.getElementById("input1").value
|
||||
let num2 = document.getElementById("input2").value
|
||||
let operator = document.getElementById("operator").value
|
||||
let result = document.getElementById("result")
|
||||
let type = document.getElementById("Type").value
|
||||
|
||||
|
||||
let response = await fetch(`http://localhost:8080/${operator}?Type=${type}&value1=${num1}&value2=${num2}`)
|
||||
let res = await response.text()
|
||||
result.value = res
|
||||
}
|
@ -9,21 +9,18 @@ import java.util.Objects;
|
||||
@Table(name = "album")
|
||||
public class Album {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@GeneratedValue
|
||||
private Long id;
|
||||
|
||||
@Column(name = "name")
|
||||
private String albumName;
|
||||
|
||||
@OneToMany(mappedBy = "album", cascade = CascadeType.ALL, orphanRemoval = true,fetch = FetchType.LAZY)
|
||||
private List<Song> songs = new ArrayList<>();
|
||||
|
||||
@ManyToMany(cascade = { CascadeType.PERSIST, CascadeType.MERGE }, fetch = FetchType.LAZY)
|
||||
@OneToMany(cascade = {CascadeType.MERGE})
|
||||
@JoinColumn(name = "songs", nullable = true)
|
||||
private List<Song> songs;
|
||||
@ManyToMany(cascade = { CascadeType.MERGE }, fetch = FetchType.EAGER)
|
||||
@JoinTable(name = "albums_artists",
|
||||
joinColumns = @JoinColumn(name = "album_id"),
|
||||
inverseJoinColumns = @JoinColumn(name = "artist_id"))
|
||||
private List<Artist> artists = new ArrayList<>();
|
||||
|
||||
joinColumns = @JoinColumn(name = "album_fk"),
|
||||
inverseJoinColumns = @JoinColumn(name = "artist_fk"))
|
||||
private List<Artist> artists;
|
||||
public Album(){
|
||||
}
|
||||
public Album(String albumName){
|
||||
|
@ -14,8 +14,8 @@ public class Artist {
|
||||
private String artistName;
|
||||
@Column(name = "genre")
|
||||
private String genre;
|
||||
@ManyToMany(mappedBy = "artists", cascade = CascadeType.MERGE, fetch = FetchType.LAZY)
|
||||
private List<Album> albums;
|
||||
@ManyToMany(mappedBy = "artists", cascade = CascadeType.MERGE, fetch = FetchType.EAGER)
|
||||
private List<Album> album;
|
||||
public Artist() {
|
||||
}
|
||||
|
||||
@ -44,25 +44,25 @@ public class Artist {
|
||||
this.genre = genre;
|
||||
}
|
||||
|
||||
public List<Album> getAlbums() {
|
||||
return albums;
|
||||
public List<Album> getAlbum() {
|
||||
return album;
|
||||
}
|
||||
|
||||
public void setAlbums(List<Album> albums) {
|
||||
this.albums = albums;
|
||||
public void setAlbum(List<Album> album) {
|
||||
this.album = album;
|
||||
}
|
||||
|
||||
public void addAlbum(Album album) {
|
||||
if (this.albums == null) {
|
||||
this.albums = new ArrayList<>();
|
||||
if (this.album == null) {
|
||||
this.album = new ArrayList<>();
|
||||
}
|
||||
if (!this.albums.contains(album))
|
||||
this.albums.add(album);
|
||||
if (!this.album.contains(album))
|
||||
this.album.add(album);
|
||||
}
|
||||
|
||||
public void removeAlbum(Album album) {
|
||||
if (this.albums.contains(album))
|
||||
this.albums.remove(album);
|
||||
if (this.album.contains(album))
|
||||
this.album.remove(album);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -8,17 +8,14 @@ import java.util.Objects;
|
||||
@Table(name = "song")
|
||||
public class Song {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@GeneratedValue
|
||||
private Long id;
|
||||
|
||||
@Column(name = "name")
|
||||
private String songName;
|
||||
|
||||
@Column(name = "duration")
|
||||
private Double duration;
|
||||
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "album_id")
|
||||
@ManyToOne(cascade = {CascadeType.MERGE}, fetch = FetchType.EAGER)
|
||||
@JoinColumn(name = "album", nullable = true)
|
||||
private Album album;
|
||||
public Song(){
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
package ru.ulstu.is.sbapp.database.service;
|
||||
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.StringUtils;
|
||||
@ -9,9 +8,7 @@ import ru.ulstu.is.sbapp.database.model.Song;
|
||||
import ru.ulstu.is.sbapp.database.model.Album;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
@ -41,18 +38,12 @@ public class AlbumService {
|
||||
return currentAlbum;
|
||||
}
|
||||
@Transactional
|
||||
public Album addArtist(Long AlbumId, Long ArtistId){
|
||||
final Album album = em.find(Album.class, AlbumId);
|
||||
if (album == null) {
|
||||
throw new EntityNotFoundException(String.format("Album with id [%s] is not found", AlbumId));
|
||||
public Album addArtist(Album currentAlbum, List<Artist> artists){
|
||||
for (Artist artist : artists) {
|
||||
currentAlbum.addArtist(artist);
|
||||
}
|
||||
|
||||
final Artist artist = em.find(Artist.class, ArtistId);
|
||||
if (artist == null) {
|
||||
throw new EntityNotFoundException(String.format("Artist with id [%s] is not found", ArtistId));
|
||||
}
|
||||
album.addArtist(artist);
|
||||
return em.merge(album);
|
||||
em.merge(currentAlbum);
|
||||
return currentAlbum;
|
||||
}
|
||||
@Transactional(readOnly = true)
|
||||
public Album findAlbum(Long id) {
|
||||
@ -128,7 +119,6 @@ public class AlbumService {
|
||||
em.createQuery("update Song s SET s.album = null ").executeUpdate();
|
||||
em.createQuery("delete from Album").executeUpdate();
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public List<Album> findFilteredAlbum(Long[] arr) {
|
||||
if (arr.length == 0) {
|
||||
|
@ -1,6 +1,5 @@
|
||||
package ru.ulstu.is.sbapp.database.service;
|
||||
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.StringUtils;
|
||||
@ -10,17 +9,13 @@ import ru.ulstu.is.sbapp.database.model.Album;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
public class ArtistService {
|
||||
@PersistenceContext
|
||||
private EntityManager em;
|
||||
|
||||
private SongService ss;
|
||||
|
||||
@Transactional
|
||||
public Artist addArtist(String name, String genre) {
|
||||
if (!StringUtils.hasText(name) || !StringUtils.hasText(genre)) {
|
||||
@ -71,9 +66,9 @@ public class ArtistService {
|
||||
@Transactional
|
||||
public Artist deleteArtist(Long id) {
|
||||
final Artist currentArtist = findArtist(id);
|
||||
int size = currentArtist.getAlbums().size();
|
||||
int size = currentArtist.getAlbum().size();
|
||||
for (int i = 0; i < size; i++) {
|
||||
Album temp = currentArtist.getAlbums().get(i);
|
||||
Album temp = currentArtist.getAlbum().get(i);
|
||||
temp.removeArtist(currentArtist);
|
||||
currentArtist.removeAlbum(temp);
|
||||
em.remove(temp);
|
||||
@ -81,9 +76,9 @@ public class ArtistService {
|
||||
em.remove(currentArtist);
|
||||
return currentArtist;
|
||||
}
|
||||
@Transactional
|
||||
@Transactional
|
||||
public List<Song> findAllSongsProducedArtist(Artist currentArtist){
|
||||
if(currentArtist.getAlbums().size() == 0){
|
||||
if(currentArtist.getAlbum().size() == 0){
|
||||
throw new IllegalArgumentException("Artist doesn`t produced");
|
||||
}
|
||||
List songList = em.createQuery("SELECT DISTINCT a.songs FROM Album a where :artistAlbum MEMBER OF a.artists")
|
||||
|
@ -1,57 +0,0 @@
|
||||
package ru.ulstu.is.sbapp.database.service;
|
||||
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.PersistenceContext;
|
||||
import jakarta.transaction.Transactional;
|
||||
import org.springframework.stereotype.Service;
|
||||
import ru.ulstu.is.sbapp.database.model.Album;
|
||||
import ru.ulstu.is.sbapp.database.model.Artist;
|
||||
import ru.ulstu.is.sbapp.database.model.Song;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
||||
@Service
|
||||
public class FindByNameService {
|
||||
@PersistenceContext
|
||||
private EntityManager em;
|
||||
|
||||
@Transactional
|
||||
public Map<String, List<Object>> GetResult(String name) {
|
||||
Map<String, List<Object>> resultMap = new HashMap<>();
|
||||
|
||||
// запрос для поиска песен по названию
|
||||
List<Song> songs = em.createQuery("SELECT s FROM Song s WHERE s.songName = :name", Song.class)
|
||||
.setParameter("name", name).getResultList();
|
||||
|
||||
// запрос для поиска альбомов по названию
|
||||
List<Album> albums = em.createQuery("SELECT a FROM Album a WHERE a.albumName = :name", Album.class)
|
||||
.setParameter("name", name).getResultList();
|
||||
|
||||
// запрос для поиска артистов по имени
|
||||
List<Artist> artists = em.createQuery("SELECT a FROM Artist a WHERE a.artistName = :name", Artist.class)
|
||||
.setParameter("name", name).getResultList();
|
||||
|
||||
// добавляем результаты поиска песен в resultMap
|
||||
List<Object> songsResult = new ArrayList<>();
|
||||
for (Song song : songs) {
|
||||
songsResult.add(song);
|
||||
}
|
||||
resultMap.put("songs", songsResult);
|
||||
|
||||
// добавляем результаты поиска альбомов в resultMap
|
||||
List<Object> albumsResult = new ArrayList<>();
|
||||
for (Album album : albums) {
|
||||
albumsResult.add(album);
|
||||
}
|
||||
resultMap.put("albums", albumsResult);
|
||||
|
||||
// добавляем результаты поиска артистов в resultMap
|
||||
List<Object> artistsResult = new ArrayList<>();
|
||||
for (Artist artist : artists) {
|
||||
artistsResult.add(artist);
|
||||
}
|
||||
resultMap.put("artists", artistsResult);
|
||||
return resultMap;
|
||||
}
|
||||
}
|
@ -1,18 +1,14 @@
|
||||
package ru.ulstu.is.sbapp.database.service;
|
||||
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.StringUtils;
|
||||
import ru.ulstu.is.sbapp.database.model.Artist;
|
||||
import ru.ulstu.is.sbapp.database.model.Song;
|
||||
import ru.ulstu.is.sbapp.database.model.Album;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
public class SongService {
|
||||
|
@ -1,215 +1,118 @@
|
||||
package ru.ulstu.is.sbapp;
|
||||
|
||||
import jakarta.transaction.Transactional;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.platform.commons.logging.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import ru.ulstu.is.sbapp.database.model.Artist;
|
||||
import ru.ulstu.is.sbapp.database.model.Song;
|
||||
import ru.ulstu.is.sbapp.database.model.Album;
|
||||
import ru.ulstu.is.sbapp.database.service.ArtistService;
|
||||
import ru.ulstu.is.sbapp.database.service.FindByNameService;
|
||||
import ru.ulstu.is.sbapp.database.service.SongService;
|
||||
import ru.ulstu.is.sbapp.database.service.AlbumService;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
@SpringBootTest
|
||||
public class SbappApplicationTests {
|
||||
@Autowired
|
||||
private AlbumService albumService;
|
||||
@Autowired
|
||||
private ArtistService artistService;
|
||||
@Autowired
|
||||
private SongService songService;
|
||||
@Autowired
|
||||
private FindByNameService findService;
|
||||
private ArtistService artistService;
|
||||
|
||||
@Test
|
||||
void testSongCreate(){
|
||||
void test1(){
|
||||
albumService.deleteAllAlbums();
|
||||
artistService.deleteAllArtists();
|
||||
songService.deleteAllSongs();
|
||||
final Song song = songService.addSong("Song",2.36);
|
||||
|
||||
final Song song = songService.addSong("song", 2.50);
|
||||
Assertions.assertNotNull(song.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testArtistCreate(){
|
||||
artistService.deleteAllArtists();
|
||||
final Artist artist = artistService.addArtist("Artist", "genre");
|
||||
Song song2 = songService.addSong("song2", 3.10);
|
||||
|
||||
List<Song> songs = new ArrayList<>();
|
||||
songs.add(song);
|
||||
songs.add(song2);
|
||||
|
||||
Artist artist = artistService.addArtist("artist", "genre");
|
||||
Assertions.assertNotNull(artist.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testAlbumCreate() throws IOException {
|
||||
albumService.deleteAllAlbums();
|
||||
artistService.deleteAllArtists();
|
||||
songService.deleteAllSongs();
|
||||
final Artist artist1 = artistService.addArtist("Artist", "genre");
|
||||
final Artist artist2 = artistService.addArtist("Artist", "genre");
|
||||
final Album album1= albumService.addAlbum("Album");
|
||||
final Album album2= albumService.addAlbum("Album");
|
||||
album1.addArtist(artist1);
|
||||
album2.addArtist(artist1);
|
||||
album2.addArtist(artist2);
|
||||
Assertions.assertNotNull(album1.getId());
|
||||
Assertions.assertNotNull(album2.getId());
|
||||
}
|
||||
Artist artist2 = artistService.addArtist("artist2", "genre");
|
||||
|
||||
List<Artist> artists = new ArrayList<>();
|
||||
artists.add(artist);
|
||||
artists.add(artist2);
|
||||
|
||||
Album album = albumService.addAlbum("album");
|
||||
Album album2 = albumService.addAlbum("album2");
|
||||
Assertions.assertNotNull(album.getId());
|
||||
|
||||
albumService.addArtist(album, artists);
|
||||
albumService.addSong(album, songs);
|
||||
|
||||
artist2 = artistService.updateArtist(artist2.getId(), "artist3", "genre2");
|
||||
Assertions.assertEquals("artist3", artistService.findArtist(artist2.getId()).getArtistName());
|
||||
|
||||
song2 = songService.updateSong(song2.getId(), "song3", 3.40, null);
|
||||
Assertions.assertEquals("song3", songService.findSong(song2.getId()).getSongName());
|
||||
|
||||
album = albumService.updateAlbum(album.getId(), "album3", songs, artists);
|
||||
Assertions.assertEquals("album3", albumService.findAlbum(album.getId()).getAlbumName());
|
||||
|
||||
Assertions.assertEquals(true, artistService.findAllSongsProducedArtist(artist).contains(song));
|
||||
Assertions.assertEquals(true, songService.findSongsInAlbum(song).contains(song2));
|
||||
|
||||
|
||||
@Test
|
||||
void ReadAlbum() throws IOException {
|
||||
albumService.deleteAllAlbums();
|
||||
artistService.deleteAllArtists();
|
||||
songService.deleteAllSongs();
|
||||
final Artist artist1 = artistService.addArtist("Artist", "genre");
|
||||
final Song song = songService.addSong("Song",3.28);
|
||||
final Album album2= albumService.addAlbum("Album");
|
||||
album2.addArtist(artist1);
|
||||
final Album findAlbum = albumService.findAlbum(album2.getId());
|
||||
Assertions.assertEquals(album2, findAlbum);
|
||||
}
|
||||
@Test
|
||||
void ReadAlbumTrue() throws IOException {
|
||||
albumService.deleteAllAlbums();
|
||||
artistService.deleteAllArtists();
|
||||
songService.deleteAllSongs();
|
||||
final Artist artist1 = artistService.addArtist("Artist", "genre");
|
||||
final Artist artist2 = artistService.addArtist("Artist2", "genre");
|
||||
final Song song = songService.addSong("Song",3.19);
|
||||
Album album2= albumService.addAlbum("Album");
|
||||
album2 =albumService.addArtist(album2.getId(),artist1.getId());
|
||||
album2 =albumService.addArtist(album2.getId(),artist2.getId());
|
||||
final Album findAlbum = albumService.findAlbum(album2.getId());
|
||||
Assertions.assertEquals(album2, findAlbum);
|
||||
}
|
||||
@Test
|
||||
void ReadSong(){
|
||||
songService.deleteAllSongs();
|
||||
final Song song = songService.addSong("Song",3.29);
|
||||
final Album album = albumService.addAlbum("Album");
|
||||
song.setAlbum(album);
|
||||
final Song findSong = songService.findSong(song.getId());
|
||||
Assertions.assertEquals(song, findSong);
|
||||
}
|
||||
@Test
|
||||
void ReadArtist(){
|
||||
artistService.deleteAllArtists();
|
||||
final Artist artist = artistService.addArtist("Artist", "genre");
|
||||
|
||||
final Artist findArtist = artistService.findArtist(artist.getId());
|
||||
Assertions.assertEquals(artist, findArtist);
|
||||
}
|
||||
@Test
|
||||
void testAlbumCheck() throws IOException {
|
||||
albumService.deleteAllAlbums();
|
||||
artistService.deleteAllArtists();
|
||||
songService.deleteAllSongs();
|
||||
final Artist artist1 = artistService.addArtist("Artist", "genre");
|
||||
final Artist artist2 = artistService.addArtist("Artist1", "genre1");
|
||||
final Song song = songService.addSong("Song",3.28);
|
||||
final Album album2= albumService.addAlbum("Album");
|
||||
album2.addArtist(artist1);
|
||||
album2.addArtist(artist2);
|
||||
Assertions.assertEquals(album2.getArtists().size(),2);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testAlbumPreviewCheck() throws IOException {
|
||||
final Album findAlbum = albumService.findAlbum(album.getId());
|
||||
Assertions.assertEquals(album, findAlbum);
|
||||
|
||||
|
||||
//TestReadAll
|
||||
final List<Song> songss = songService.findAllSongs();
|
||||
Assertions.assertEquals(songss.size(), 2);
|
||||
|
||||
final List<Artist> artistss = artistService.findAllArtists();
|
||||
Assertions.assertEquals(artistss.size(), 2);
|
||||
|
||||
final List<Album> albumss = albumService.findAllAlbums();
|
||||
Assertions.assertEquals(albumss.size(), 2);
|
||||
|
||||
//TestReadNotFound
|
||||
|
||||
//album2 = albumService.updateAlbum(album2.getId(), "стул",songs, artistService.findAllArtists());
|
||||
//albumService.deleteAlbum(album.getId());
|
||||
//albumService.deleteAlbum(album2.getId());
|
||||
List<Song> list = songService.findAllSongs();
|
||||
List<Artist> list2 = artistService.findAllArtists();
|
||||
|
||||
albumService.deleteAllAlbums();
|
||||
songService.deleteAllSongs();
|
||||
artistService.deleteAllArtists();
|
||||
songService.deleteAllSongs();
|
||||
final Artist artist1 = artistService.addArtist("Artist", "genre");
|
||||
final Artist artist2 = artistService.addArtist("Artist1", "genre1");
|
||||
final Song song = songService.addSong("Song",2.10);
|
||||
final Album album2= albumService.addAlbum("Album");
|
||||
album2.addArtist(artist1);
|
||||
album2.addArtist(artist2);
|
||||
Album v = albumService.findAlbum(album2.getId());
|
||||
}
|
||||
@Test
|
||||
void testSongReadNotFound() {
|
||||
songService.deleteAllSongs();
|
||||
|
||||
|
||||
Assertions.assertThrows(EntityNotFoundException.class, () -> songService.findSong(-1L));
|
||||
}
|
||||
@Test
|
||||
void testArtistReadNotFound() {
|
||||
artistService.deleteAllArtists();
|
||||
Assertions.assertThrows(EntityNotFoundException.class, () -> artistService.findArtist(-1L));
|
||||
}
|
||||
@Test
|
||||
void testAlbumReadNotFound() {
|
||||
albumService.deleteAllAlbums();
|
||||
Assertions.assertThrows(EntityNotFoundException.class, () -> albumService.findAlbum(-1L));
|
||||
}
|
||||
@Test
|
||||
void testSongCount(){
|
||||
songService.deleteAllSongs();
|
||||
final Song song1 = songService.addSong("Song",3.15);
|
||||
final Song song2 = songService.addSong("Song1",2.43);
|
||||
final List<Song> songs = songService.findAllSongs();
|
||||
Assertions.assertEquals(songs.size(),2);
|
||||
}
|
||||
@Test
|
||||
void testArtistCount(){
|
||||
artistService.deleteAllArtists();
|
||||
final Artist cat1 = artistService.addArtist("Shorts", "genre");
|
||||
final Artist ca2 = artistService.addArtist("Comedy", "genre");
|
||||
final List<Artist> categories = artistService.findAllArtists();
|
||||
assertEquals(categories.size(),2);
|
||||
}
|
||||
@Test
|
||||
void testAlbumCount() throws IOException {
|
||||
albumService.deleteAllAlbums();
|
||||
artistService.deleteAllArtists();
|
||||
songService.deleteAllSongs();
|
||||
final Artist cat1 = artistService.addArtist("Artist", "genre");
|
||||
final Song song2 = songService.addSong("Song",3.17);
|
||||
final Album album1 = albumService.addAlbum("Album");
|
||||
final Album album2 = albumService.addAlbum("Album1");
|
||||
album1.addArtist(cat1);
|
||||
album2.addArtist(cat1);
|
||||
final List<Album> albums = albumService.findAllAlbums();
|
||||
Assertions.assertEquals(albums.size(),2);
|
||||
}
|
||||
@Test
|
||||
void testDop() {
|
||||
String nameToTest = "a";
|
||||
|
||||
// создаем данные для тестирования
|
||||
albumService.deleteAllAlbums();
|
||||
artistService.deleteAllArtists();
|
||||
songService.deleteAllSongs();
|
||||
final Artist artist1 = artistService.addArtist(nameToTest, "genre");
|
||||
final Album album1= albumService.addAlbum(nameToTest);
|
||||
final Song song1 = songService.addSong(nameToTest, 3.29);
|
||||
album1.addArtist(artist1);
|
||||
artist1.addAlbum(album1);
|
||||
album1.addSong(song1);
|
||||
//TestReadAllEmpty
|
||||
final List<Song> newComponents = songService.findAllSongs();
|
||||
Assertions.assertEquals(newComponents.size(), 0);
|
||||
|
||||
Map<String, List<Object>> resultMap = findService.GetResult(nameToTest);
|
||||
final List<Album> newOrders = albumService.findAllAlbums();
|
||||
Assertions.assertEquals(newOrders.size(), 0);
|
||||
|
||||
List<Object> artistsList = resultMap.get("artists");
|
||||
assertEquals(1, artistsList.size());
|
||||
Object artistResult = artistsList.get(0);
|
||||
assertEquals(nameToTest, ((Artist) artistResult).getArtistName());
|
||||
|
||||
List<Object> albumsList = resultMap.get("albums");
|
||||
assertEquals(1, albumsList.size());
|
||||
Object albumResult = albumsList.get(0);
|
||||
assertEquals(nameToTest, ((Album) albumResult).getAlbumName());
|
||||
|
||||
List<Object> songsList = resultMap.get("songs");
|
||||
assertEquals(1, songsList.size());
|
||||
Object songResult = songsList.get(0);
|
||||
assertEquals(nameToTest, ((Song) songResult).getSongName());
|
||||
final List<Artist> newArtists = artistService.findAllArtists();
|
||||
Assertions.assertEquals(newArtists.size(), 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +0,0 @@
|
||||
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=create-drop
|
Loading…
Reference in New Issue
Block a user