diff --git a/lab2.2/Лекция2-src/src/test/java/com/example/demo/ItemServiceTests.java b/lab2.2/Лекция2-src/src/test/java/com/example/demo/ItemServiceTests.java index 409d4d9..2247b22 100644 --- a/lab2.2/Лекция2-src/src/test/java/com/example/demo/ItemServiceTests.java +++ b/lab2.2/Лекция2-src/src/test/java/com/example/demo/ItemServiceTests.java @@ -9,52 +9,57 @@ 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.items.model.ItemEntity; import com.example.demo.types.model.TypeEntity; +import com.example.demo.items.service.ItemService; import com.example.demo.types.service.TypeService; @SpringBootTest @TestMethodOrder(OrderAnnotation.class) -class TypeServiceTests { +class ItemServiceTests { @Autowired + private ItemService itemService; private TypeService typeService; @Test void getTest() { - Assertions.assertThrows(NotFoundException.class, () -> typeService.get(0L)); + Assertions.assertThrows(NotFoundException.class, () -> itemService.get(0L)); } @Test @Order(1) void createTest() { - typeService.create(new TypeEntity(null, "Ноутбук")); - typeService.create(new TypeEntity(null, "Телефон")); - final TypeEntity last = typeService.create(new TypeEntity(null, "Игровая приставка")); - Assertions.assertEquals(3, typeService.getAll().size()); - Assertions.assertEquals(last, typeService.get(3L)); + final TypeEntity type = typeService.create(new TypeEntity(null, "specialType")); + itemService.create(new ItemEntity(null, type, 100.00,1)); + itemService.create(new ItemEntity(null, type, 200.00,5)); + final ItemEntity last = itemService.create(new ItemEntity(null, type, 5000.00,10)); + Assertions.assertEquals(3, itemService.getAll(0L).size()); + Assertions.assertEquals(last, itemService.get(3L)); } @Test @Order(2) void updateTest() { - final String test = "TEST"; - final TypeEntity entity = typeService.get(3L); - final String oldName = entity.getName(); - final TypeEntity newEntity = typeService.update(3L, new TypeEntity(1L, test)); - Assertions.assertEquals(3, typeService.getAll().size()); - Assertions.assertEquals(newEntity, typeService.get(3L)); - Assertions.assertEquals(test, newEntity.getName()); - Assertions.assertNotEquals(oldName, newEntity.getName()); + final TypeEntity type = typeService.create(new TypeEntity(null, "specialType2")); + + final ItemEntity entity = itemService.get(3L); + final Double oldPrice = entity.getPrice(); + final ItemEntity newEntity = itemService.update(3L, new ItemEntity(null, type, 8000.00,10)); + Assertions.assertEquals(3, itemService.getAll(0L).size()); + Assertions.assertEquals(newEntity, itemService.get(3L)); + Assertions.assertEquals(8000.00, newEntity.getPrice()); + Assertions.assertNotEquals(oldPrice, newEntity.getPrice()); } @Test @Order(3) void deleteTest() { - typeService.delete(3L); - Assertions.assertEquals(2, typeService.getAll().size()); - final TypeEntity last = typeService.get(2L); - Assertions.assertEquals(2L, last.getId()); + itemService.delete(3L); + Assertions.assertEquals(2, itemService.getAll(0L).size()); + + final TypeEntity type = typeService.create(new TypeEntity(null, "specialType3")); + final ItemEntity newEntity = itemService.create(new ItemEntity(null, type, 300.00, 7)); - final TypeEntity newEntity = typeService.create(new TypeEntity(null, "Игровая приставка")); Assertions.assertEquals(3, typeService.getAll().size()); Assertions.assertEquals(4L, newEntity.getId()); } diff --git a/lab2.2/Лекция2-src/src/test/java/com/example/demo/ReviewServiceTests.java b/lab2.2/Лекция2-src/src/test/java/com/example/demo/ReviewServiceTests.java index 409d4d9..21f93bf 100644 --- a/lab2.2/Лекция2-src/src/test/java/com/example/demo/ReviewServiceTests.java +++ b/lab2.2/Лекция2-src/src/test/java/com/example/demo/ReviewServiceTests.java @@ -1,5 +1,8 @@ package com.example.demo; +import java.util.Calendar; +import java.util.GregorianCalendar; + import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.MethodOrderer.OrderAnnotation; import org.junit.jupiter.api.Order; @@ -9,53 +12,65 @@ 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.reviews.model.ReviewEntity; +import com.example.demo.reviews.service.ReviewService; 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 TypeServiceTests { +class ReviewServiceTests { @Autowired - private TypeService typeService; + private ReviewService reviewService; + private UserService userService; + private Calendar calendar = new GregorianCalendar(2017, 0 , 25); @Test void getTest() { - Assertions.assertThrows(NotFoundException.class, () -> typeService.get(0L)); + Assertions.assertThrows(NotFoundException.class, () -> reviewService.get(0L)); } @Test @Order(1) void createTest() { - typeService.create(new TypeEntity(null, "Ноутбук")); - typeService.create(new TypeEntity(null, "Телефон")); - final TypeEntity last = typeService.create(new TypeEntity(null, "Игровая приставка")); - Assertions.assertEquals(3, typeService.getAll().size()); - Assertions.assertEquals(last, typeService.get(3L)); + final UserEntity userSpecial = userService.create(new UserEntity(null, "userSpecial","userspecial@gmail.com", "userSpecial")); + + reviewService.create(new ReviewEntity(null,userSpecial, calendar.getTime(), "все было супер")); + reviewService.create(new ReviewEntity(null, userSpecial,calendar.getTime(),"all is ok")); + final ReviewEntity last = reviewService.create(new ReviewEntity(null, userSpecial, calendar.getTime(), "fantastic")); + + Assertions.assertEquals(3, reviewService.getAll(0L).size()); + Assertions.assertEquals(last, reviewService.get(3L)); } @Test @Order(2) void updateTest() { + final UserEntity userSpecial1 = userService.create(new UserEntity(null, "userSpecial1","userspecial@gmail.com", "userSpecial1")); final String test = "TEST"; - final TypeEntity entity = typeService.get(3L); - final String oldName = entity.getName(); - final TypeEntity newEntity = typeService.update(3L, new TypeEntity(1L, test)); - Assertions.assertEquals(3, typeService.getAll().size()); - Assertions.assertEquals(newEntity, typeService.get(3L)); - Assertions.assertEquals(test, newEntity.getName()); - Assertions.assertNotEquals(oldName, newEntity.getName()); + final ReviewEntity entity = reviewService.get(3L); + final String oldText = entity.getText(); + final ReviewEntity newEntity = reviewService.update(3L, new ReviewEntity(null,userSpecial1, calendar.getTime(), test)); + Assertions.assertEquals(3, reviewService.getAll(0L).size()); + Assertions.assertEquals(newEntity, reviewService.get(3L)); + Assertions.assertEquals(test, newEntity.getText()); + Assertions.assertNotEquals(oldText, newEntity.getText()); } @Test @Order(3) void deleteTest() { - typeService.delete(3L); - Assertions.assertEquals(2, typeService.getAll().size()); - final TypeEntity last = typeService.get(2L); + final UserEntity userSpecial2 = userService.create(new UserEntity(null, "userSpecial2","userspecial@gmail.com", "userSpecial2")); + + reviewService.delete(3L); + Assertions.assertEquals(2, reviewService.getAll(0L).size()); + final ReviewEntity last = reviewService.get(2L); Assertions.assertEquals(2L, last.getId()); - final TypeEntity newEntity = typeService.create(new TypeEntity(null, "Игровая приставка")); - Assertions.assertEquals(3, typeService.getAll().size()); + final ReviewEntity newEntity = reviewService.update(3L, new ReviewEntity(null,userSpecial2, calendar.getTime(), "nice")); + Assertions.assertEquals(3, reviewService.getAll(0L).size()); Assertions.assertEquals(4L, newEntity.getId()); } } diff --git a/lab2.2/Лекция2-src/src/test/java/com/example/demo/TypeServiceTests.java b/lab2.2/Лекция2-src/src/test/java/com/example/demo/TypeServiceTests.java index 409d4d9..a0d5866 100644 --- a/lab2.2/Лекция2-src/src/test/java/com/example/demo/TypeServiceTests.java +++ b/lab2.2/Лекция2-src/src/test/java/com/example/demo/TypeServiceTests.java @@ -26,9 +26,9 @@ class TypeServiceTests { @Test @Order(1) void createTest() { - typeService.create(new TypeEntity(null, "Ноутбук")); - typeService.create(new TypeEntity(null, "Телефон")); - final TypeEntity last = typeService.create(new TypeEntity(null, "Игровая приставка")); + typeService.create(new TypeEntity(null, "type1")); + typeService.create(new TypeEntity(null, "type2")); + final TypeEntity last = typeService.create(new TypeEntity(null, "type3")); Assertions.assertEquals(3, typeService.getAll().size()); Assertions.assertEquals(last, typeService.get(3L)); } @@ -54,7 +54,7 @@ class TypeServiceTests { final TypeEntity last = typeService.get(2L); Assertions.assertEquals(2L, last.getId()); - final TypeEntity newEntity = typeService.create(new TypeEntity(null, "Игровая приставка")); + final TypeEntity newEntity = typeService.create(new TypeEntity(null, "type3")); Assertions.assertEquals(3, typeService.getAll().size()); Assertions.assertEquals(4L, newEntity.getId()); } diff --git a/lab2.2/Лекция2-src/src/test/java/com/example/demo/UserServiceTests.java b/lab2.2/Лекция2-src/src/test/java/com/example/demo/UserServiceTests.java index 409d4d9..a35a188 100644 --- a/lab2.2/Лекция2-src/src/test/java/com/example/demo/UserServiceTests.java +++ b/lab2.2/Лекция2-src/src/test/java/com/example/demo/UserServiceTests.java @@ -9,53 +9,53 @@ 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.users.model.UserEntity; +import com.example.demo.users.service.UserService; @SpringBootTest @TestMethodOrder(OrderAnnotation.class) -class TypeServiceTests { +class UserServiceTests { @Autowired - private TypeService typeService; + private UserService userService; @Test void getTest() { - Assertions.assertThrows(NotFoundException.class, () -> typeService.get(0L)); + Assertions.assertThrows(NotFoundException.class, () -> userService.get(0L)); } @Test @Order(1) void createTest() { - typeService.create(new TypeEntity(null, "Ноутбук")); - typeService.create(new TypeEntity(null, "Телефон")); - final TypeEntity last = typeService.create(new TypeEntity(null, "Игровая приставка")); - Assertions.assertEquals(3, typeService.getAll().size()); - Assertions.assertEquals(last, typeService.get(3L)); + userService.create(new UserEntity(null, "user1","user1@gmail.com", "user1")); + userService.create(new UserEntity(null, "user2","user2@gmail.com", "user2")); + final UserEntity last = userService.create(new UserEntity(null, "user3","user3@gmail.com", "user3")); + Assertions.assertEquals(3, userService.getAll().size()); + Assertions.assertEquals(last, userService.get(3L)); } @Test @Order(2) void updateTest() { final String test = "TEST"; - final TypeEntity entity = typeService.get(3L); - final String oldName = entity.getName(); - final TypeEntity newEntity = typeService.update(3L, new TypeEntity(1L, test)); - Assertions.assertEquals(3, typeService.getAll().size()); - Assertions.assertEquals(newEntity, typeService.get(3L)); - Assertions.assertEquals(test, newEntity.getName()); - Assertions.assertNotEquals(oldName, newEntity.getName()); + final UserEntity entity = userService.get(3L); + final String oldHandle = entity.getHandle(); + final UserEntity newEntity = userService.update(3L, new UserEntity(1L, test, "user3@gmail.com", "user3")); + Assertions.assertEquals(3, userService.getAll().size()); + Assertions.assertEquals(newEntity, userService.get(3L)); + Assertions.assertEquals(test, newEntity.getHandle()); + Assertions.assertNotEquals(oldHandle, newEntity.getHandle()); } @Test @Order(3) void deleteTest() { - typeService.delete(3L); - Assertions.assertEquals(2, typeService.getAll().size()); - final TypeEntity last = typeService.get(2L); + userService.delete(3L); + Assertions.assertEquals(2, userService.getAll().size()); + final UserEntity last = userService.get(2L); Assertions.assertEquals(2L, last.getId()); - final TypeEntity newEntity = typeService.create(new TypeEntity(null, "Игровая приставка")); - Assertions.assertEquals(3, typeService.getAll().size()); + final UserEntity newEntity = userService.create(new UserEntity(null, "user3","user3@gmail.com", "user3")); + Assertions.assertEquals(3, userService.getAll().size()); Assertions.assertEquals(4L, newEntity.getId()); } }