This commit is contained in:
antoc0der 2024-03-07 10:28:30 +04:00
parent 258fe9378b
commit 02169d2eaa
8 changed files with 198 additions and 13 deletions

View File

@ -1,11 +1,12 @@
package com.example.demo.reviews.api;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.Date;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotNull;
public class ItemDto {
public class ReviewDto {
private Long id;
@NotNull
@Min(1)
@ -46,7 +47,7 @@ public class ItemDto {
return text;
}
public void setText(String date) {
this.date = date;
public void setText(String text) {
this.text = text;
}
}

View File

@ -1,12 +1,13 @@
package com.example.demo.reviews.model;
import java.util.Objects;
import java.util.Date;
import com.example.demo.core.model.BaseEntity;
import com.example.demo.users.model.UserEntity;
public class ReviewEntity extends BaseEntity {
private UserEntity type;
private UserEntity user;
private Date date;
private String text;
@ -41,8 +42,8 @@ public class ReviewEntity extends BaseEntity {
return text;
}
public void setText(String date) {
this.date = date;
public void setText(String text) {
this.text = text;
}
@Override

View File

@ -1,4 +1,4 @@
package com.example.demo.items.api;
package com.example.demo.users.api;
import java.util.List;
@ -21,11 +21,11 @@ import jakarta.validation.Valid;
@RestController
@RequestMapping(Constants.API_URL + "/user")
public class ItemController {
private final UserService UserService;
public class UserController {
private final UserService userService;
private final ModelMapper modelMapper;
public ItemController(UserService userService, ModelMapper modelMapper) {
public UserController(UserService userService, ModelMapper modelMapper) {
this.userService = userService;
this.modelMapper = modelMapper;
}
@ -39,7 +39,7 @@ public class ItemController {
}
@GetMapping
public List<TypeDto> getAll() {
public List<UserDto> getAll() {
return userService.getAll().stream().map(this::toDto).toList();
}

View File

@ -27,7 +27,7 @@ public class UserDto {
}
public String getHandle() {
return typeId;
return handle;
}
public void setHandle(String handle) {

View File

@ -56,7 +56,7 @@ public class UserEntity extends BaseEntity {
return true;
if (obj == null || getClass() != obj.getClass())
return false;
final ItemEntity other = (ItemEntity) obj;
final UserEntity other = (UserEntity) obj;
return Objects.equals(other.getId(), id)
&& Objects.equals(other.getHandle(), handle)
&& Objects.equals(other.getEmail(), email)

View File

@ -0,0 +1,61 @@
package com.example.demo;
import org.junit.jupiter.api.Assertions;
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 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;
@Test
void getTest() {
Assertions.assertThrows(NotFoundException.class, () -> typeService.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));
}
@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());
}
@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());
final TypeEntity newEntity = typeService.create(new TypeEntity(null, "Игровая приставка"));
Assertions.assertEquals(3, typeService.getAll().size());
Assertions.assertEquals(4L, newEntity.getId());
}
}

View File

@ -0,0 +1,61 @@
package com.example.demo;
import org.junit.jupiter.api.Assertions;
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 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;
@Test
void getTest() {
Assertions.assertThrows(NotFoundException.class, () -> typeService.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));
}
@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());
}
@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());
final TypeEntity newEntity = typeService.create(new TypeEntity(null, "Игровая приставка"));
Assertions.assertEquals(3, typeService.getAll().size());
Assertions.assertEquals(4L, newEntity.getId());
}
}

View File

@ -0,0 +1,61 @@
package com.example.demo;
import org.junit.jupiter.api.Assertions;
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 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;
@Test
void getTest() {
Assertions.assertThrows(NotFoundException.class, () -> typeService.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));
}
@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());
}
@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());
final TypeEntity newEntity = typeService.create(new TypeEntity(null, "Игровая приставка"));
Assertions.assertEquals(3, typeService.getAll().size());
Assertions.assertEquals(4L, newEntity.getId());
}
}