From 86435c3fbe330300ef2ca7b680b5632e27893192 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D0=BA=D1=81=D0=B8=D0=BC=20=D0=AF=D0=BA=D0=BE?= =?UTF-8?q?=D0=B2=D0=BB=D0=B5=D0=B2?= Date: Mon, 29 Apr 2024 18:09:24 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A1=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB=20=D1=82?= =?UTF-8?q?=D0=B5=D1=81=D1=82=D1=8B,=20=D0=BF=D1=80=D0=B0=D0=B2=D0=BA?= =?UTF-8?q?=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data.mv.db | Bin 40960 -> 45056 bytes .../com/example/demo/DemoApplication.java | 36 ++--- .../demo/games/api/GameController.java | 7 +- .../demo/games/repository/GameRepository.java | 23 ++- .../demo/games/service/GameService.java | 38 ++--- .../demo/genres/service/GenreService.java | 5 + .../demo/orders/model/OrderEntity.java | 2 +- .../orders/repository/OrderRepository.java | 2 + .../demo/orders/service/OrderService.java | 11 ++ .../demo/types/repository/TypeRepository.java | 1 + .../com/example/demo/GameServiceTests.java | 101 ++++++++++++++ .../com/example/demo/GenreServiceTests.java | 68 +++++++++ .../com/example/demo/OrderServiceTest.java | 130 +++++++++++++++++ .../com/example/demo/TypeServiceTests.java | 131 +++++++++--------- .../com/example/demo/UserServiceTests.java | 67 +++++++++ 15 files changed, 510 insertions(+), 112 deletions(-) create mode 100644 src/test/java/com/example/demo/GameServiceTests.java create mode 100644 src/test/java/com/example/demo/GenreServiceTests.java create mode 100644 src/test/java/com/example/demo/OrderServiceTest.java create mode 100644 src/test/java/com/example/demo/UserServiceTests.java diff --git a/data.mv.db b/data.mv.db index 1d0388371d319a53945723f14d7aaa3dd69e9db3..8989e4e971892ed649282e978fc22c1029f39181 100644 GIT binary patch literal 45056 zcmeHQS!^81dF~;HVv{S9(q7i?YIkQxCwE6o-v?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U{miVAXJFDeNvhIoEv%uf4Kd|jid?y3PW*{ZT=7<+* zb@w%rKUXOp1^%;p4KfBRx}P92j}PM|IT-1s4TIULFCGK7KcumGZ6;wsl~R~utiJdh zu>QSt8@?o0s=3r8%TbMcwN?*#iqG%qCCzLXeo0?|mSou7-&0HM#PC6d_Z=muA;)2u z{BV~mKIl=o-M(q{#i_%_fW&wEJSbco}%{+vzXlo_N7s zZ9=LUh#6X?2rL-uJZ$G{@D`blyjTl2Pz zx;18&9er7mE$)eQll5%k!6}$^@Kf9X>ou)DrOe5f=jM#r8B1<0PRld%)}`z9n05Tv zz#_AIWE-EmcqTT$P6Ipst{*!FF;&O+@;J?cC%B@?wpBnGq?Xw_R04# zC9oS`bNl~um%ilo|FJ;Z$24K`1;^K0;PapunH=u4v zTtlL+OkIV#w0?uuZ_xS;TEAgpYIXd-f&V8@EbO;24pm#j*i9{o-INi0Qj6e|BwFW% z@dQ0Upch)W1cJ_FqJ2D!#|~VOj070dlNCoGwS_kT$3RWK#!T#%uQ85M6H?_&G&DOW z1M#wn?T>EDna#|ulTw?B`ex^()Mj#sZmEv3Hpl-v8{7_w9RJ6ANOJriP8{q7|NnW8 z|Dzp5UmE=XM=|{0jPU=|t1O>9{D1dtn-u@&?=DP0>4O?B#MjlN-($$%x0q_j(B$y{ z-EFH7{2$%0$gYL#!T%q`whB*Ws%;ex{~zEUph58e{GQESudB(;)kw^KC5D^71o%J0 T-+354!v9qh@PFsA;Q#**GmHdS diff --git a/src/main/java/com/example/demo/DemoApplication.java b/src/main/java/com/example/demo/DemoApplication.java index 6ef2691..766cd00 100644 --- a/src/main/java/com/example/demo/DemoApplication.java +++ b/src/main/java/com/example/demo/DemoApplication.java @@ -47,29 +47,29 @@ public class DemoApplication implements CommandLineRunner { @Override public void run(String... args) throws Exception{ log.info("start"); - final var type1 = typeService.create(new TypeEntity("ААА")); - final var type2 = typeService.create(new TypeEntity("АА")); + // final var type1 = typeService.create(new TypeEntity("ААА")); + // final var type2 = typeService.create(new TypeEntity("АА")); - final var genre1 = genreService.create(new GenreEntity("Приключения")); - final var genre2 = genreService.create(new GenreEntity("Симулятор")); + // final var genre1 = genreService.create(new GenreEntity("Приключения")); + // final var genre2 = genreService.create(new GenreEntity("Симулятор")); - final List genres1 = new ArrayList(); - genres1.add(genre1); - genres1.add(genre2); + // final List genres1 = new ArrayList(); + // genres1.add(genre1); + // genres1.add(genre2); - final List genres2 = new ArrayList(); - genres2.add(genre2); + // final List genres2 = new ArrayList(); + // genres2.add(genre2); - final var game1 = gameService.create(new GameEntity(type1,"Game1",2100.0,"good game", genres1)); - final var game2 = gameService.create(new GameEntity( type2, "Game2", 1200.0,"bad game", genres2)); - final List games = new ArrayList(); - games.add(game1); - games.add(game2); + // final var game1 = gameService.create(new GameEntity(type1,"Game1",2100.0,"good game", genres1)); + // final var game2 = gameService.create(new GameEntity( type2, "Game2", 1200.0,"bad game", genres2)); + // final List games = new ArrayList(); + // games.add(game1); + // games.add(game2); - var user1 = userService.create(new UserEntity( "login1", "email@mail.com", "qwerty123")); - var user2 = userService.create(new UserEntity( "login2", "email@gmail.com", "qwerty1234")); + // var user1 = userService.create(new UserEntity( "login1", "email@mail.com", "qwerty123")); + // var user2 = userService.create(new UserEntity( "login2", "email@gmail.com", "qwerty1234")); - orderService.create(7, new OrderEntity(user1,games)); - orderService.create(8, new OrderEntity(user2,games)); + // orderService.create(7, new OrderEntity(user1,games)); + // orderService.create(8, new OrderEntity(user2,games)); } } diff --git a/src/main/java/com/example/demo/games/api/GameController.java b/src/main/java/com/example/demo/games/api/GameController.java index f45650a..7b8f82f 100644 --- a/src/main/java/com/example/demo/games/api/GameController.java +++ b/src/main/java/com/example/demo/games/api/GameController.java @@ -1,5 +1,7 @@ package com.example.demo.games.api; +import java.util.List; + import org.modelmapper.ModelMapper; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; @@ -53,8 +55,9 @@ public class GameController { final GameEntity entity = modelMapper.map(dto, GameEntity.class); entity.setType(typeService.get(dto.getTypeId())); var genres = dto.getGenres(); - for(var genre : genres){ - entity.setGenres(genreService.get(genre)); + List genresList = genreService.getAllById(genres); + for(var genre : genresList){ + entity.setGenres(genre); } return entity; } diff --git a/src/main/java/com/example/demo/games/repository/GameRepository.java b/src/main/java/com/example/demo/games/repository/GameRepository.java index ffbd8c0..f140065 100644 --- a/src/main/java/com/example/demo/games/repository/GameRepository.java +++ b/src/main/java/com/example/demo/games/repository/GameRepository.java @@ -1,5 +1,6 @@ package com.example.demo.games.repository; +import java.util.List; import java.util.Optional; import org.springframework.data.domain.Page; @@ -9,16 +10,32 @@ import org.springframework.data.repository.CrudRepository; import org.springframework.data.repository.PagingAndSortingRepository; import com.example.demo.games.model.GameEntity; -import com.example.demo.genres.model.GenreEntity; public interface GameRepository extends CrudRepository, PagingAndSortingRepository { + + @Query("select distinct g from GameEntity g join fetch g.genres ge join fetch g.type ty where g.id = ?1") Optional findOneById(long id); - Page findByTypeIdAndGenres(long typeId, GenreEntity genre, Pageable pageable); + + @Query("select distinct g from GameEntity g join fetch g.genres ge join fetch g.type ty where ge.id = ?2 and ty.id = ?1") + Page findByTypeIdAndGenres(long typeId, long genreId, Pageable pageable); + @Query("select distinct g from GameEntity g join fetch g.genres ge join fetch g.type ty where ge.id = ?2 and ty.id = ?1") + List findByTypeIdAndGenres(long typeId, long genreId); + + @Query("select distinct g from GameEntity g join fetch g.type ty where ty.id = ?1") Page findByTypeId(long typeId, Pageable pageable); - //Page findByGenres(GenreEntity genre, Pageable pageable); + @Query("select distinct g from GameEntity g join fetch g.type ty where ty.id = ?1") + List findByTypeId(long typeId); @Query("select distinct g from GameEntity g join fetch g.genres ge where ge.id = ?1") Page findByGenres(long genre, Pageable pageable); + @Query("select distinct g from GameEntity g join fetch g.genres ge where ge.id = ?1") + List findByGenres(long genre); + + @Query("select distinct g from GameEntity g join fetch g.genres join fetch g.type ty") + PagefindAll(Pageable pageable); + @Query("select distinct g from GameEntity g join fetch g.genres join fetch g.type ty") + ListfindAll(); + } /* "select " diff --git a/src/main/java/com/example/demo/games/service/GameService.java b/src/main/java/com/example/demo/games/service/GameService.java index 22974df..cd9279a 100644 --- a/src/main/java/com/example/demo/games/service/GameService.java +++ b/src/main/java/com/example/demo/games/service/GameService.java @@ -1,5 +1,6 @@ package com.example.demo.games.service; +import java.util.List; //import java.util.List; import java.util.Objects; import org.springframework.data.domain.Page; @@ -11,46 +12,37 @@ import org.springframework.data.domain.Pageable; import com.example.demo.core.error.NotFoundException; import com.example.demo.games.model.GameEntity; import com.example.demo.games.repository.GameRepository; -import com.example.demo.genres.model.GenreEntity; import com.example.demo.genres.service.GenreService; @Service public class GameService { private final GameRepository repository; - private final GenreService genreService; public GameService(GameRepository repository, GenreService genreService){ this.repository = repository; - this.genreService = genreService; } - // @Transactional(readOnly = true) - // public Page getAll(Long typeId, List genres, int page, int size){ - // final Pageable pageRequest = PageRequest.of(page, size); + @Transactional(readOnly = true) + public List getAll(long typeId, long genre){ - // if(!Objects.equals(typeId, 0L) && !Objects.equals(genres.size(), 0)){ - // return repository.findByTypeIdAndGenres(typeId, genres, pageRequest); - // } - // if(Objects.equals(typeId, 0L) && !Objects.equals(genres.size(), 0)){ - // return repository.findByGenres(genres, pageRequest); - // } - // if(!Objects.equals(typeId, 0L) && Objects.equals(genres.size(), 0)){ - // return repository.findByTypeId(typeId, pageRequest); - // } - // return repository.findAll(PageRequest.of(page, size)); - // } - //getAll.stream().filter(game -> game.getType().getId().equals(typeId)).toList(); + if(!Objects.equals(typeId, 0L) && !Objects.equals(genre, 0L)){ + return repository.findByTypeIdAndGenres(typeId, genre); + } + if(Objects.equals(typeId, 0L) && !Objects.equals(genre, 0L)){ + return repository.findByGenres(genre); + } + if(!Objects.equals(typeId, 0L) && Objects.equals(genre, 0L)){ + return repository.findByTypeId(typeId); + } + return repository.findAll(); + } @Transactional(readOnly = true) public Page getAll(long typeId, long genre, int page, int size){ final Pageable pageRequest = PageRequest.of(page, size); - GenreEntity NeedGenre = null; - if(genre != 0){ - NeedGenre = genreService.get(genre); - } if(!Objects.equals(typeId, 0L) && !Objects.equals(genre, 0L)){ - return repository.findByTypeIdAndGenres(typeId, NeedGenre, pageRequest); + return repository.findByTypeIdAndGenres(typeId, genre, pageRequest); } if(Objects.equals(typeId, 0L) && !Objects.equals(genre, 0L)){ return repository.findByGenres(genre, pageRequest); diff --git a/src/main/java/com/example/demo/genres/service/GenreService.java b/src/main/java/com/example/demo/genres/service/GenreService.java index aea07a9..bb5d62a 100644 --- a/src/main/java/com/example/demo/genres/service/GenreService.java +++ b/src/main/java/com/example/demo/genres/service/GenreService.java @@ -23,6 +23,11 @@ public class GenreService { public List getAll(){ return StreamSupport.stream(repository.findAll().spliterator(), false).toList(); } + + @Transactional(readOnly = true) + public List getAllById(List listIds){ + return StreamSupport.stream(repository.findAllById(listIds).spliterator(),false).toList(); + } @Transactional(readOnly = true) public GenreEntity get(Long id){ diff --git a/src/main/java/com/example/demo/orders/model/OrderEntity.java b/src/main/java/com/example/demo/orders/model/OrderEntity.java index 732317a..e71cd60 100644 --- a/src/main/java/com/example/demo/orders/model/OrderEntity.java +++ b/src/main/java/com/example/demo/orders/model/OrderEntity.java @@ -24,7 +24,7 @@ public class OrderEntity extends BaseEntity{ @ManyToOne @JoinColumn(name = "userId", nullable = false) private UserEntity user; - @ManyToMany() //cделать запрос jpa + @ManyToMany() private Set games = new HashSet<>(); public OrderEntity(){ diff --git a/src/main/java/com/example/demo/orders/repository/OrderRepository.java b/src/main/java/com/example/demo/orders/repository/OrderRepository.java index 5fa9925..31d4cdf 100644 --- a/src/main/java/com/example/demo/orders/repository/OrderRepository.java +++ b/src/main/java/com/example/demo/orders/repository/OrderRepository.java @@ -19,5 +19,7 @@ public interface OrderRepository extends CrudRepository, Pagi @Query("select o from OrderEntity o join fetch o.games where o.user.id = ?1") Page findByUserId(long userId, Pageable pageable); + List findAll(); + //Можно сделать запрос на сумму JPQL } diff --git a/src/main/java/com/example/demo/orders/service/OrderService.java b/src/main/java/com/example/demo/orders/service/OrderService.java index 0ef6826..af1bf3e 100644 --- a/src/main/java/com/example/demo/orders/service/OrderService.java +++ b/src/main/java/com/example/demo/orders/service/OrderService.java @@ -1,5 +1,7 @@ package com.example.demo.orders.service; +import java.util.List; + import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; @@ -30,6 +32,15 @@ public class OrderService { return repository.findByUserId(userId, pageRequest); } + @Transactional(readOnly = true) + public List getAll(long userId){ + userService.get(userId); + return repository.findByUserId(userId); + } + public List getAll(){ + return repository.findAll(); + } + @Transactional(readOnly = true) public OrderEntity get(long userId, long id){ userService.get(userId); diff --git a/src/main/java/com/example/demo/types/repository/TypeRepository.java b/src/main/java/com/example/demo/types/repository/TypeRepository.java index 9fea284..432cedc 100644 --- a/src/main/java/com/example/demo/types/repository/TypeRepository.java +++ b/src/main/java/com/example/demo/types/repository/TypeRepository.java @@ -8,4 +8,5 @@ import com.example.demo.types.model.TypeEntity; public interface TypeRepository extends CrudRepository { Optional findByNameIgnoreCase(String name); + Optional findById(long id); } diff --git a/src/test/java/com/example/demo/GameServiceTests.java b/src/test/java/com/example/demo/GameServiceTests.java new file mode 100644 index 0000000..487cee1 --- /dev/null +++ b/src/test/java/com/example/demo/GameServiceTests.java @@ -0,0 +1,101 @@ +package com.example.demo; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Order; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestMethodOrder; +import org.junit.jupiter.api.MethodOrderer.OrderAnnotation; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; + +import com.example.demo.core.error.NotFoundException; +import com.example.demo.games.model.GameEntity; +import com.example.demo.games.service.GameService; +import com.example.demo.genres.model.GenreEntity; +import com.example.demo.genres.service.GenreService; +import com.example.demo.types.model.TypeEntity; +import com.example.demo.types.service.TypeService; + +@SpringBootTest +@TestMethodOrder(OrderAnnotation.class) +class GameServiceTests { + @Autowired + private GameService gameService; + @Autowired + private TypeService typeService; + @Autowired + private GenreService genreService; + + private GenreEntity genre1; + private GenreEntity genre2; + + private TypeEntity type1; + private TypeEntity type2; + + private GameEntity game1; + private GameEntity game2; + + @BeforeEach + void createData(){ + removeData(); + + genre1 = genreService.create(new GenreEntity("Приключения")); + genre2 = genreService.create(new GenreEntity("Симулятор")); + type1 = typeService.create(new TypeEntity("Игра")); + type2 = typeService.create(new TypeEntity("Программа")); + + final List genres1 = new ArrayList(); + genres1.add(genre1); + genres1.add(genre2); + + final List genres2 = new ArrayList(); + genres2.add(genre2); + + game1 = gameService.create(new GameEntity(type1,"Game1",2100.0,"good game", genres1)); + game2 = gameService.create(new GameEntity( type2, "Game2", 1200.0,"bad game", genres2)); + + } + + @AfterEach + void removeData(){ + gameService.getAll(0,0).forEach(item -> gameService.delete(item.getId())); + typeService.getAll().forEach(item -> typeService.delete(item.getId())); + genreService.getAll().forEach(item -> genreService.delete(item.getId())); + } + + @Test + void getTest(){ + Assertions.assertThrows(NotFoundException.class, () -> gameService.get(0L)); + } + + @Test + @Order(1) + void createTest(){ + Assertions.assertEquals(2, gameService.getAll(0,0).size()); + } + + @Test + @Order(2) + void updateTest(){ + genre1 = genreService.create(new GenreEntity("Симулятор2")); + type1 = typeService.create(new TypeEntity("Игра2")); + final List genres1 = new ArrayList(); + genres1.add(genre1); + gameService.update(game1.getId(), new GameEntity(type1, "testGame", 1200.0, "hehgame", genres1)); + Assertions.assertEquals(2, gameService.getAll(0,0).size()); + } + + @Test + @Order(3) + void deleteTest(){ + gameService.delete(game1.getId()); + Assertions.assertEquals(1, gameService.getAll(0,0).size()); + final GameEntity last = gameService.get(game2.getId()); + Assertions.assertEquals(game2.getId(), last.getId()); + } +} diff --git a/src/test/java/com/example/demo/GenreServiceTests.java b/src/test/java/com/example/demo/GenreServiceTests.java new file mode 100644 index 0000000..75f94a5 --- /dev/null +++ b/src/test/java/com/example/demo/GenreServiceTests.java @@ -0,0 +1,68 @@ +package com.example.demo; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Order; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestMethodOrder; +import org.junit.jupiter.api.MethodOrderer.OrderAnnotation; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; + +import com.example.demo.core.error.NotFoundException; +import com.example.demo.genres.model.GenreEntity; +import com.example.demo.genres.service.GenreService; + +@SpringBootTest +@TestMethodOrder(OrderAnnotation.class) +class GenreServiceTests { + @Autowired + private GenreService genreService; + + private GenreEntity genre1; + private GenreEntity genre2; + + @BeforeEach + void createData(){ + removeData(); + + genre1 = genreService.create(new GenreEntity("Приключения")); + genre2 = genreService.create(new GenreEntity("Симулятор")); + } + + @AfterEach + void removeData(){ + genreService.getAll().forEach(item -> genreService.delete(item.getId())); + } + + @Test + void getTest(){ + Assertions.assertThrows(NotFoundException.class, () -> genreService.get(0L)); + } + + @Test + @Order(1) + void createTest(){ + Assertions.assertEquals(2, genreService.getAll().size()); + } + + @Test + @Order(2) + void updateTest(){ + final String test = "TEST"; + final GenreEntity newEntity = genreService.update(genre2.getId(), new GenreEntity(test)); + Assertions.assertEquals(2, genreService.getAll().size()); + Assertions.assertEquals(newEntity, genreService.get(genre2.getId())); + Assertions.assertEquals(test, newEntity.getName()); + } + + @Test + @Order(3) + void deleteTest(){ + genreService.delete(genre1.getId()); + Assertions.assertEquals(1, genreService.getAll().size()); + final GenreEntity last = genreService.get(genre2.getId()); + Assertions.assertEquals(genre2.getId(), last.getId()); + } +} diff --git a/src/test/java/com/example/demo/OrderServiceTest.java b/src/test/java/com/example/demo/OrderServiceTest.java new file mode 100644 index 0000000..9124b3d --- /dev/null +++ b/src/test/java/com/example/demo/OrderServiceTest.java @@ -0,0 +1,130 @@ +package com.example.demo; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Order; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestMethodOrder; +import org.junit.jupiter.api.MethodOrderer.OrderAnnotation; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; + +import com.example.demo.core.error.NotFoundException; +import com.example.demo.games.model.GameEntity; +import com.example.demo.games.service.GameService; +import com.example.demo.genres.model.GenreEntity; +import com.example.demo.genres.service.GenreService; +import com.example.demo.orders.model.OrderEntity; +import com.example.demo.orders.service.OrderService; +import com.example.demo.types.model.TypeEntity; +import com.example.demo.types.service.TypeService; +import com.example.demo.users.model.UserEntity; +import com.example.demo.users.service.UserService; + +@SpringBootTest +@TestMethodOrder(OrderAnnotation.class) +class OrderServiceTest { + @Autowired + private GameService gameService; + @Autowired + private TypeService typeService; + @Autowired + private GenreService genreService; + @Autowired + private UserService userService; + @Autowired + private OrderService orderService; + + private GenreEntity genre1; + private GenreEntity genre2; + + private TypeEntity type1; + private TypeEntity type2; + private List genres1 = new ArrayList<>(); + private List genres2 = new ArrayList<>(); + private GameEntity game1; + private GameEntity game2; + private List games = new ArrayList<>(); + private UserEntity user1; + private OrderEntity order1; + + @BeforeEach + void createData(){ + genre1 = genreService.create(new GenreEntity("Приключения")); + genre2 = genreService.create(new GenreEntity("Симулятор")); + type1 = typeService.create(new TypeEntity("Игра")); + type2 = typeService.create(new TypeEntity("Программа")); + + genres1 = new ArrayList(); + genres1.add(genre1); + genres1.add(genre2); + + genres2 = new ArrayList(); + genres2.add(genre2); + + game1 = gameService.create(new GameEntity(type1,"Game1",2100.0,"good game", genres1)); + game2 = gameService.create(new GameEntity( type2, "Game2", 1200.0,"bad game", genres2)); + games = new ArrayList(); + games.add(game1); + games.add(game2); + + user1 = userService.create(new UserEntity( "login1", "email@mail.com", "qwerty123")); + order1 = orderService.create(user1.getId(), new OrderEntity(user1,games)); + removeData(); + + genre1 = genreService.create(new GenreEntity("Приключения")); + genre2 = genreService.create(new GenreEntity("Симулятор")); + type1 = typeService.create(new TypeEntity("Игра")); + type2 = typeService.create(new TypeEntity("Программа")); + + genres1 = new ArrayList(); + genres1.add(genre1); + genres1.add(genre2); + + genres2 = new ArrayList(); + genres2.add(genre2); + + game1 = gameService.create(new GameEntity(type1,"Game1",2100.0,"good game", genres1)); + game2 = gameService.create(new GameEntity( type2, "Game2", 1200.0,"bad game", genres2)); + games = new ArrayList(); + games.add(game1); + games.add(game2); + + user1 = userService.create(new UserEntity( "login1", "email@mail.com", "qwerty123")); + order1 = orderService.create(user1.getId(), new OrderEntity(user1,games)); + orderService.create(user1.getId(), new OrderEntity(user1,games)); + } + + @AfterEach + void removeData(){ + orderService.getAll().forEach(item -> orderService.delete(item.getUser().getId(),item.getId())); + userService.getAll().forEach(item -> userService.delete(item.getId())); + gameService.getAll(0,0).forEach(item -> gameService.delete(item.getId())); + typeService.getAll().forEach(item -> typeService.delete(item.getId())); + genreService.getAll().forEach(item -> genreService.delete(item.getId())); + } + + @Test + void getTest(){ + Assertions.assertThrows(NotFoundException.class, () -> gameService.get(0L)); + } + + @Test + @Order(1) + void createTest(){ + Assertions.assertEquals(2, orderService.getAll(user1.getId()).size()); + } + + @Test + @Order(2) + void deleteTest(){ + orderService.delete(user1.getId(),order1.getId()); + Assertions.assertEquals(1, orderService.getAll(user1.getId()).size()); + } +} + +//зависимости, core->security, user(loadUserByUserName, userrole), core->configuration, дохуя контроллеров юзера core->session diff --git a/src/test/java/com/example/demo/TypeServiceTests.java b/src/test/java/com/example/demo/TypeServiceTests.java index 4e72ded..63e9a3d 100644 --- a/src/test/java/com/example/demo/TypeServiceTests.java +++ b/src/test/java/com/example/demo/TypeServiceTests.java @@ -1,76 +1,77 @@ -// package com.example.demo; +package com.example.demo; -// import org.junit.jupiter.api.AfterEach; -// import org.junit.jupiter.api.Assertions; -// import org.junit.jupiter.api.BeforeEach; -// import org.junit.jupiter.api.Order; -// import org.junit.jupiter.api.Test; -// import org.junit.jupiter.api.TestMethodOrder; -// import org.junit.jupiter.api.MethodOrderer.OrderAnnotation; -// import org.springframework.beans.factory.annotation.Autowired; -// import org.springframework.boot.test.context.SpringBootTest; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Order; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestMethodOrder; +import org.junit.jupiter.api.MethodOrderer.OrderAnnotation; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; -// import com.example.demo.core.error.NotFoundException; -// import com.example.demo.types.model.TypeEntity; -// import com.example.demo.types.service.TypeService; +import com.example.demo.core.error.NotFoundException; +import com.example.demo.types.model.TypeEntity; +import com.example.demo.types.service.TypeService; -// @SpringBootTest -// @TestMethodOrder(OrderAnnotation.class) -// class TypeServiceTests { -// @Autowired -// private TypeService typeService; +import jakarta.transaction.Transactional; -// private TypeEntity type; +@SpringBootTest +@TestMethodOrder(OrderAnnotation.class) +class TypeServiceTests { + @Autowired + private TypeService typeService; -// @BeforeEach -// void createData() { -// removeData(); + private TypeEntity type1; + private TypeEntity type2; -// type = typeService.create(new TypeEntity("Ноутбук")); -// typeService.create(new TypeEntity("Телефон")); -// typeService.create(new TypeEntity("Игровая приставка")); -// } + @BeforeEach + void createData() { + removeData(); -// @AfterEach -// void removeData() { -// typeService.getAll().forEach(item -> typeService.delete(item.getId())); -// } + + type2 = typeService.create(new TypeEntity("Программа")); + + type1 = typeService.create(new TypeEntity("Игра")); + } + + @AfterEach + void removeData() { + typeService.getAll().forEach(item -> typeService.delete(item.getId())); + } -// @Test -// void getTest(){ -// Assertions.assertThrows(NotFoundException.class, () -> typeService.get(0L)); -// } + @Test + @Transactional + void getTest(){ + Assertions.assertThrows(NotFoundException.class, () -> typeService.get(0L)); + } -// @Test -// @Order(1) -// void createTest(){ -// typeService.create(new TypeEntity("Игра")); -// typeService.create(new TypeEntity("Программа")); -// final TypeEntity last = typeService.create(new TypeEntity("Игра2")); -// Assertions.assertEquals(5, typeService.getAll().size()); -// Assertions.assertEquals(last, typeService.get(10L)); -// } + @Test + @Order(1) + @Transactional + void createTest(){ + final TypeEntity last = typeService.create(new TypeEntity("Игра2")); + Assertions.assertEquals(3, typeService.getAll().size()); + Assertions.assertEquals(last, typeService.get(3L)); + } -// @Test -// @Order(2) -// void updateTest(){ -// final String test = "TEST"; -// final TypeEntity newEntity = typeService.update(9L, new TypeEntity(test)); -// Assertions.assertEquals(5, typeService.getAll().size()); -// Assertions.assertEquals(newEntity, typeService.get(9L)); -// Assertions.assertEquals(test, newEntity.getName()); -// } + @Test + @Order(2) + @Transactional + void updateTest(){ + final String test = "TEST"; + final TypeEntity newEntity = typeService.update(type1.getId(), new TypeEntity(test)); + Assertions.assertEquals(2, typeService.getAll().size()); + Assertions.assertEquals(test, newEntity.getName()); + } -// @Test -// @Order(3) -// void deleteTest(){ -// typeService.delete(9L); -// Assertions.assertEquals(8, typeService.getAll().size()); -// final TypeEntity last = typeService.get(8L); -// Assertions.assertEquals(8L, last.getId()); - -// final TypeEntity newEntity = typeService.create(new TypeEntity("Игра")); -// Assertions.assertEquals(9, typeService.getAll().size()); -// Assertions.assertEquals(11L, newEntity.getId()); -// } -// } + @Test + @Order(3) + @Transactional + void deleteTest(){ + typeService.delete(type1.getId()); + Assertions.assertEquals(1, typeService.getAll().size()); + final TypeEntity last = typeService.get(type2.getId()); + Assertions.assertEquals(6L, last.getId()); + } +} diff --git a/src/test/java/com/example/demo/UserServiceTests.java b/src/test/java/com/example/demo/UserServiceTests.java new file mode 100644 index 0000000..b6b3f06 --- /dev/null +++ b/src/test/java/com/example/demo/UserServiceTests.java @@ -0,0 +1,67 @@ +package com.example.demo; + + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Order; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestMethodOrder; +import org.junit.jupiter.api.MethodOrderer.OrderAnnotation; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; + +import com.example.demo.core.error.NotFoundException; +import com.example.demo.users.model.UserEntity; +import com.example.demo.users.service.UserService; + +@SpringBootTest +@TestMethodOrder(OrderAnnotation.class) +class UserServiceTests { + @Autowired + private UserService userService; + + private UserEntity user1; + private UserEntity user2; + + @BeforeEach + void createData() { + removeData(); + + user1 = userService.create(new UserEntity( "login1", "email@mail.com", "qwerty123")); + user2 = userService.create(new UserEntity( "login2", "email@gmail.com", "qwerty1234")); + } + + @AfterEach + void removeData() { + userService.getAll().forEach(item -> userService.delete(item.getId())); + } + + @Test + void getTest(){ + Assertions.assertThrows(NotFoundException.class, () -> userService.get(0L)); + } + + @Test + @Order(1) + void createTest(){ + Assertions.assertEquals(2, userService.getAll().size()); + } + + @Test + @Order(2) + void updateTest(){ + final UserEntity newEntity = userService.update(user2.getId(), new UserEntity("user11", "mail11", "qwerty11")); + Assertions.assertEquals(2, userService.getAll().size()); + Assertions.assertEquals(newEntity.getLogin(), "user11"); + } + + @Test + @Order(3) + void deleteTest(){ + userService.delete(user2.getId()); + Assertions.assertEquals(1, userService.getAll().size()); + final UserEntity last = userService.get(user1.getId()); + Assertions.assertEquals(user1.getId(), last.getId()); + } +}