From 66bfe560cdfa6787a9c28232305dbb5561bfd0fa Mon Sep 17 00:00:00 2001 From: dex_moth Date: Tue, 30 Apr 2024 12:37:08 +0400 Subject: [PATCH] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D1=8B=20=D0=BD=D0=BE=D0=B2=D1=8B=D0=B5=20=D1=82=D0=B5?= =?UTF-8?q?=D1=81=D1=82=D1=8B=20=D0=BA=20=D0=BA=D0=B0=D0=B6=D0=B4=D0=BE?= =?UTF-8?q?=D0=B9=20=D1=81=D1=83=D1=89=D0=BD=D0=BE=D1=81=D1=82=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/example/demo/DemoApplication.java | 4 +-- .../example/demo/news/api/NewController.java | 2 -- .../com/example/demo/CommentServiceTest.java | 35 ++++++++++++------- .../com/example/demo/NewsServiceTest.java | 22 ++++++++---- .../com/example/demo/TageServiceTest.java | 17 ++++++++- 5 files changed, 56 insertions(+), 24 deletions(-) diff --git a/lab2/src/main/java/com/example/demo/DemoApplication.java b/lab2/src/main/java/com/example/demo/DemoApplication.java index aec787a..ec7bb60 100644 --- a/lab2/src/main/java/com/example/demo/DemoApplication.java +++ b/lab2/src/main/java/com/example/demo/DemoApplication.java @@ -42,7 +42,7 @@ public class DemoApplication implements CommandLineRunner { @Override public void run(String... args) throws Exception { - // if (args.length > 0 && Objects.equals("--populate", args[0])) { + if (args.length > 0 && Objects.equals("--populate", args[0])) { log.info("Create default news values"); // tage @@ -67,6 +67,6 @@ public class DemoApplication implements CommandLineRunner { // comment commentService.create(new CommentEntity(null, new Date(2024-4-04), "очень интересно", new1, user1)); commentService.create(new CommentEntity(null, new Date(2024-4-04), "очень интересно", new2, user2)); - // } + } } } diff --git a/lab2/src/main/java/com/example/demo/news/api/NewController.java b/lab2/src/main/java/com/example/demo/news/api/NewController.java index 404e542..dac914d 100644 --- a/lab2/src/main/java/com/example/demo/news/api/NewController.java +++ b/lab2/src/main/java/com/example/demo/news/api/NewController.java @@ -15,7 +15,6 @@ import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; -import com.example.demo.DemoApplication; import com.example.demo.core.configuration.Constants; import com.example.demo.news.model.NewEntity; import com.example.demo.news.service.NewService; @@ -30,7 +29,6 @@ public class NewController { private final NewService newService; private final TageService tageService; private final ModelMapper modelMapper; - private final Logger log = LoggerFactory.getLogger(NewController.class); public NewController(NewService newService, TageService tageService, ModelMapper modelMapper) { this.newService = newService; diff --git a/lab2/src/test/java/com/example/demo/CommentServiceTest.java b/lab2/src/test/java/com/example/demo/CommentServiceTest.java index 76d2299..d7c8810 100644 --- a/lab2/src/test/java/com/example/demo/CommentServiceTest.java +++ b/lab2/src/test/java/com/example/demo/CommentServiceTest.java @@ -14,11 +14,8 @@ import com.example.demo.comment.model.CommentEntity; import com.example.demo.comment.service.CommentService; import com.example.demo.core.error.NotFoundException; import com.example.demo.news.model.NewEntity; -import com.example.demo.news.service.NewService; import com.example.demo.tage.model.TageEntity; -import com.example.demo.tage.service.TageService; import com.example.demo.users.model.UserEntity; -import com.example.demo.users.service.UserService; @SpringBootTest @TestMethodOrder(OrderAnnotation.class) @@ -26,9 +23,6 @@ public class CommentServiceTest { @Autowired private CommentService commentService; - private NewService newService; - private UserService userService; - private TageService tageService; @Test void getTest() { @@ -36,16 +30,31 @@ public class CommentServiceTest { } @Test - void createTest() { - var tage1 = tageService.create(new TageEntity(null, "праздник")); + void Test() { + //create + var tage1 = new TageEntity(null, "пасха"); + + var new1 = new NewEntity(null, "Чемпионат ICPC", new Date(), Arrays.asList(tage1), + "Студенты выступят на Чемпионате мира по программированию в Северной Евразии."); + + var user1 = new UserEntity(null, "beko", "111", "ddwwdd", "beko@mail.ru", new Date()); - NewEntity new1 = newService.create(new NewEntity(null, "Чемпионат ICPC", new Date(), Arrays.asList(tage1), - "Студенты выступят на Чемпионате мира по программированию в Северной Евразии.")); - var user1 = userService.create(new UserEntity(null, "beko", "111", "ddwwdd", - "beko@mail.ru", new Date())); commentService.create(new CommentEntity(null, new Date(), "как красиво весной", new1, user1)); var last = commentService.create(new CommentEntity(null, new Date(), "и ещё птицы поют", new1, user1)); - Assertions.assertEquals(2L, commentService.getAll(null).size()); + + Assertions.assertEquals(2L, commentService.getAll(0L).size()); Assertions.assertEquals(last, commentService.get(2L)); + + //update + final var newComment = commentService.update(1L, new CommentEntity(1L, new Date(), "это измененный коммент", new1, user1)); + Assertions.assertEquals(2L, commentService.getAll(0L).size()); + Assertions.assertEquals(newComment, commentService.get(1L)); + + //delete + commentService.delete(1L); + Assertions.assertEquals(1L, commentService.getAll(0L).size()); + final var lastComm = commentService.get(2L); + Assertions.assertEquals(2L, lastComm.getId()); + } } diff --git a/lab2/src/test/java/com/example/demo/NewsServiceTest.java b/lab2/src/test/java/com/example/demo/NewsServiceTest.java index 360ec00..c1338b0 100644 --- a/lab2/src/test/java/com/example/demo/NewsServiceTest.java +++ b/lab2/src/test/java/com/example/demo/NewsServiceTest.java @@ -28,17 +28,27 @@ class NewsServiceTest { } @Test - void createTest() { + void Test() { + // create List list1 = Arrays.asList (new TageEntity(null, "праздник"), new TageEntity(null, "сессия")); - List list2 = Arrays.asList - (new TageEntity(null, "конкурс"), new TageEntity(null, "программирование")); newsService.create(new NewEntity(null, "Название", new Date(), list1, "текст новости")); final NewEntity last = newsService.create - (new NewEntity(null, "9 апреля", new Date(), list2, "просто наступил апрель")); + (new NewEntity(null, "9 апреля", new Date(), null, "просто наступил апрель")); - Assertions.assertEquals(4L, newsService.getAll().size()); - Assertions.assertEquals(last, newsService.get(4L)); + Assertions.assertEquals(2L, newsService.getAll().size()); + Assertions.assertEquals(last, newsService.get(2L)); + + // update + final var newNew = newsService.update(2L, new NewEntity(2L, "9 мая", new Date(), list1, "уже май!!!!!!!!!")); + Assertions.assertEquals(2L, newsService.getAll().size()); + Assertions.assertEquals(newNew, newsService.get(2L)); + + // delete + newsService.delete(1L); + Assertions.assertEquals(1L, newsService.getAll().size()); + final var lastNew = newsService.get(2L); + Assertions.assertEquals(2L, lastNew.getId()); } } \ No newline at end of file diff --git a/lab2/src/test/java/com/example/demo/TageServiceTest.java b/lab2/src/test/java/com/example/demo/TageServiceTest.java index 01df544..34be25b 100644 --- a/lab2/src/test/java/com/example/demo/TageServiceTest.java +++ b/lab2/src/test/java/com/example/demo/TageServiceTest.java @@ -10,6 +10,7 @@ import org.springframework.boot.test.context.SpringBootTest; import com.example.demo.core.error.NotFoundException; import com.example.demo.tage.model.TageEntity; import com.example.demo.tage.service.TageService; +import com.example.demo.users.model.UserEntity; @SpringBootTest @TestMethodOrder(OrderAnnotation.class) @@ -23,11 +24,25 @@ public class TageServiceTest { } @Test - void createTest() { + void Test() { + //create tageService.create(new TageEntity(null, "праздник")); final var last = tageService.create(new TageEntity(null, "конкурс")); Assertions.assertEquals(2L, tageService.getAll().size()); Assertions.assertEquals(last, tageService.get(2L)); + + //update + final String test = "TEST"; + final var newTage = tageService.update(1L, new TageEntity(1L, test)); + Assertions.assertEquals(2L, tageService.getAll().size()); + Assertions.assertEquals(newTage, tageService.get(1L)); + + //delete + tageService.delete(1L); + Assertions.assertEquals(1L, tageService.getAll().size()); + final var lastTage = tageService.get(2L); + Assertions.assertEquals(2L, lastTage.getId()); + } }