ну... тесты удалила

This commit is contained in:
Елена Бакальская 2024-05-11 19:15:35 +04:00
parent 6f5fe27b71
commit 223a89a4c0
4 changed files with 0 additions and 389 deletions

@ -1,77 +0,0 @@
package com.example.backend;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.dao.DataIntegrityViolationException;
import com.example.backend.categories.model.CategorieEntity;
import com.example.backend.categories.service.CategorieService;
import com.example.backend.core.errors.NotFoundException;
@SpringBootTest
class CategorieServiceTests {
@Autowired
private CategorieService categorieService;
private CategorieEntity categorie;
@BeforeEach
void createData() {
removeData();
categorie = categorieService.create(new CategorieEntity(1, "Drama", "null"));
categorieService.create(new CategorieEntity(2, "Comedy", "null"));
}
@AfterEach
void removeData() {
categorieService.getAll().forEach(item -> categorieService.delete(item.getId()));
}
@Test
void getTest() {
Assertions.assertThrows(NotFoundException.class, () -> categorieService.get(0));
}
@Test
void createTest() {
Assertions.assertEquals(2, categorieService.getAll().size());
Assertions.assertEquals(categorie, categorieService.get(categorie.getId()));
}
@Test
void createNotUniqueTest() {
final CategorieEntity nonUniqueCategorie = new CategorieEntity(1, "Drama", "null");
Assertions.assertThrows(IllegalArgumentException.class, () -> categorieService.create(nonUniqueCategorie));
}
@Test
void createNullableTest() {
final CategorieEntity nullableCategorie = new CategorieEntity(1, null, "null");
Assertions.assertThrows(DataIntegrityViolationException.class, () -> categorieService.create(
nullableCategorie));
}
@Test
void updateTest() {
final String newName = "TEST";
final String oldName = categorie.getName();
final CategorieEntity cat = new CategorieEntity(categorie.getId(), newName, categorie.getImage());
final CategorieEntity newEntity = categorieService.update(categorie.getId(), cat);
Assertions.assertEquals(newName, newEntity.getName());
Assertions.assertNotEquals(oldName, newEntity.getName());
}
@Test
void deleteTest() {
categorieService.delete(categorie.getId());
Assertions.assertEquals(1, categorieService.getAll().size());
Assertions.assertNotEquals(3, categorieService.getAll().size());
}
}

@ -1,103 +0,0 @@
package com.example.backend;
import org.junit.jupiter.api.TestMethodOrder;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.MethodOrderer.OrderAnnotation;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import com.example.backend.categories.model.CategorieEntity;
import com.example.backend.categories.service.CategorieService;
import com.example.backend.core.errors.NotFoundException;
import com.example.backend.favorites.model.FavoriteEntity;
import com.example.backend.favorites.service.FavoriteService;
import com.example.backend.movies.model.MovieEntity;
import com.example.backend.movies.service.MovieService;
import com.example.backend.users.model.UserEntity;
import com.example.backend.users.service.UserService;
@SpringBootTest
@TestMethodOrder(OrderAnnotation.class)
public class FavoriteServiceTests {
@Autowired
private FavoriteService favoriteService;
private FavoriteEntity lastFavorite;
private FavoriteEntity lastFavorite2;
private CategorieEntity cat1;
private MovieEntity mov1;
private MovieEntity mov2;
private UserEntity us1;
@Autowired
private CategorieService categorieService;
@Autowired
private MovieService movieService;
@Autowired
private UserService userService;
@BeforeEach
void createData() {
removeData();
cat1 = categorieService.create(new CategorieEntity(null, "Драма", "123"));
mov1 = movieService.create(new MovieEntity(null, cat1, "Хатико", "какой-то фильм",
"1", "1"));
mov2 = movieService.create(new MovieEntity(null, cat1, "Унесеснные призраками",
"2", "2", "2"));
us1 = userService.create(new UserEntity(null, "elina", "123", true));
lastFavorite = favoriteService.create(new FavoriteEntity(null, us1, mov1));
lastFavorite2 = favoriteService.create(new FavoriteEntity(null, us1, mov2));
}
@AfterEach
void removeData() {
favoriteService.getAll(0).forEach(fv -> favoriteService.delete(fv.getId()));
userService.getAll().forEach(u -> userService.delete(u.getId()));
movieService.getAll(0).forEach(item -> movieService.delete(item.getId()));
categorieService.getAll().forEach(item -> categorieService.delete(item.getId()));
}
@Test
void getTest() {
Assertions.assertThrows(NotFoundException.class, () -> favoriteService.get(0));
}
@Test
void createTest() {
Assertions.assertEquals(2, favoriteService.getAll(us1.getId()).size());
}
@Test
void update() {
final FavoriteEntity fav = favoriteService.create(new FavoriteEntity(null, us1, mov2));
final FavoriteEntity oldFav = favoriteService.get(lastFavorite.getId());
final FavoriteEntity newFav = favoriteService.update(lastFavorite2.getId(), fav);
Assertions.assertNotEquals(oldFav.getMovie().getName(),
newFav.getMovie().getName());
}
@Test
@Order(3)
void delete() {
favoriteService.delete(lastFavorite.getId());
Assertions.assertEquals(1, favoriteService.getAll(us1.getId()).size());
}
}

@ -1,135 +0,0 @@
package com.example.backend;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.MethodOrderer.OrderAnnotation;
import org.junit.jupiter.api.Order;
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 org.springframework.dao.DataIntegrityViolationException;
import com.example.backend.categories.model.CategorieEntity;
import com.example.backend.categories.service.CategorieService;
import com.example.backend.core.errors.NotFoundException;
import com.example.backend.viewed.model.ViewedEntity;
import com.example.backend.movies.model.MovieEntity;
import com.example.backend.movies.service.MovieService;
import com.example.backend.users.model.UserEntity;
import com.example.backend.users.service.UserService;
import com.example.backend.viewed.service.ViewedService;
@SpringBootTest
@TestMethodOrder(OrderAnnotation.class)
class MovieServiceTest {
@Autowired
private MovieService movieService;
private MovieEntity movie;
private MovieEntity movie2;
@Autowired
private CategorieService categorieService;
private CategorieEntity cat;
@Autowired
private UserService userService;
private UserEntity user;
private UserEntity user1;
private UserEntity user2;
private UserEntity user3;
@Autowired
private ViewedService viewedService;
@BeforeEach
void createData() {
removeData();
cat = categorieService.create(new CategorieEntity(0, "Drama", "null"));
user = userService.create(new UserEntity(0, "1", "1", true));
user1 = userService.create(new UserEntity(0, "2", "2", true));
user2 = userService.create(new UserEntity(0, "3", "3", true));
user3 = userService.create(new UserEntity(0, "4", "4", true));
movie = movieService.create(new MovieEntity(0, cat, "1", "1", "1", "1"));
movie2 = movieService.create(new MovieEntity(0, cat, "2", "2", "2", "2"));
viewedService.create(new ViewedEntity(0, user, movie));
viewedService.create(new ViewedEntity(0, user1, movie));
viewedService.create(new ViewedEntity(0, user2, movie));
viewedService.create(new ViewedEntity(0, user3, movie));
}
@AfterEach
void removeData() {
viewedService.getAll(0).forEach(vs -> viewedService.delete(vs.getId()));
userService.getAll().forEach(u -> userService.delete(u.getId()));
movieService.getAll(0).forEach(item -> movieService.delete(item.getId()));
categorieService.getAll().forEach(item -> categorieService.delete(item.getId()));
}
@Test
@Order(1)
void getTest() {
Assertions.assertThrows(NotFoundException.class, () -> movieService.get(10));
}
@Test
@Order(2)
void createTest() {
Assertions.assertEquals(2, movieService.getAll(cat.getId()).size());
Assertions.assertEquals(movie, movieService.get(movie.getId()));
}
@Test
@Order(3)
void createNotUniqueTest() {
final MovieEntity nonUniqueCategorie = new MovieEntity(3, cat, "1", "1", "1",
"1");
Assertions.assertThrows(IllegalArgumentException.class, () -> movieService.create(nonUniqueCategorie));
}
@Test
@Order(4)
void createNullableTest() {
final MovieEntity nullableCategorie = new MovieEntity(1, cat, null, "1", "1",
"1");
Assertions.assertThrows(DataIntegrityViolationException.class, () -> movieService.create(
nullableCategorie));
}
@Test
@Order(5)
void updateTest() {
final String newName = "TEST";
final String oldName = movie.getName();
final MovieEntity mov = new MovieEntity(movie.getId(), movie.getCategorie(),
newName, movie.getDescription(),
movie.getDuration(), movie.getImage());
final MovieEntity newEntity = movieService.update(movie.getId(), mov);
Assertions.assertEquals(newName, newEntity.getName());
Assertions.assertNotEquals(oldName, newEntity.getName());
}
@Test
@Order(6)
void deleteTest() {
movieService.delete(movie2.getId());
Assertions.assertEquals(1, movieService.getAll(cat.getId()).size());
Assertions.assertNotEquals(3, movieService.getAll(cat.getId()).size());
}
@Test
@Order(7)
void countViewedTest() {
Assertions.assertEquals(movieService.countView(movie.getId()), 4);
}
}

@ -1,74 +0,0 @@
package com.example.backend;
import org.junit.jupiter.api.TestMethodOrder;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.MethodOrderer.OrderAnnotation;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import com.example.backend.core.errors.NotFoundException;
import com.example.backend.users.model.UserEntity;
import com.example.backend.users.service.UserService;
@SpringBootTest
@TestMethodOrder(OrderAnnotation.class)
public class UserServiceTests {
@Autowired
private UserService userService;
private UserEntity firstUser;
@BeforeEach
void createData() {
removeData();
firstUser = userService.create(new UserEntity(null, "elina", "123", true));
userService.create(new UserEntity(null, "oleg", "789", false));
userService.create(new UserEntity(null, "nikita", "456", false));
}
@AfterEach
void removeData() {
userService.getAll().forEach(item -> userService.delete(item.getId()));
}
@Test
void getTest() {
Assertions.assertThrows(NotFoundException.class, () -> userService.get(0));
}
@Test
@Order(1)
void createTest() {
Assertions.assertEquals(firstUser, userService.get(firstUser.getId()));
Assertions.assertEquals(3, userService.getAll().size());
}
@Test
@Order(2)
void update() {
final String newPassword = "000";
final UserEntity existEntity = userService.get(firstUser.getId());
final String oldPassword = existEntity.getPassword();
final UserEntity entity = new UserEntity(null, existEntity.getUsername(), newPassword,
existEntity.getIsAdmin());
final UserEntity newEntity = userService.update(firstUser.getId(), entity);
Assertions.assertEquals(newPassword, newEntity.getPassword());
Assertions.assertNotEquals(oldPassword, newEntity.getPassword());
}
@Test
@Order(3)
void delete() {
userService.delete(firstUser.getId());
Assertions.assertEquals(2, userService.getAll().size());
}
}