добавлены новые тесты к каждой сущности

This commit is contained in:
dex_moth 2024-04-30 12:37:08 +04:00
parent 55284eacbc
commit 66bfe560cd
5 changed files with 56 additions and 24 deletions

View File

@ -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));
// }
}
}
}

View File

@ -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;

View File

@ -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());
}
}

View File

@ -28,17 +28,27 @@ class NewsServiceTest {
}
@Test
void createTest() {
void Test() {
// create
List<TageEntity> list1 = Arrays.asList
(new TageEntity(null, "праздник"), new TageEntity(null, "сессия"));
List<TageEntity> 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());
}
}

View File

@ -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());
}
}