Compare commits
No commits in common. "b9859be7070af46d22a08571570eb9e5b67627ed" and "431abe9c9955f4362633c0fe5611a82b167f798e" have entirely different histories.
b9859be707
...
431abe9c99
@ -21,11 +21,11 @@ import jakarta.validation.Valid;
|
|||||||
@RestController
|
@RestController
|
||||||
@RequestMapping(Constants.API_URL + "/Categories")
|
@RequestMapping(Constants.API_URL + "/Categories")
|
||||||
public class CategoriesController {
|
public class CategoriesController {
|
||||||
private final CategoriesService categoriesService;
|
private final CategoriesService CategoriesService;
|
||||||
private final ModelMapper modelMapper;
|
private final ModelMapper modelMapper;
|
||||||
|
|
||||||
public CategoriesController(CategoriesService categoriesService, ModelMapper modelMapper) {
|
public CategoriesController(CategoriesService CategoriesService, ModelMapper modelMapper) {
|
||||||
this.categoriesService = categoriesService;
|
this.CategoriesService = CategoriesService;
|
||||||
this.modelMapper = modelMapper;
|
this.modelMapper = modelMapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -39,26 +39,26 @@ public class CategoriesController {
|
|||||||
|
|
||||||
@GetMapping
|
@GetMapping
|
||||||
public List<CategoriesDto> getAll() {
|
public List<CategoriesDto> getAll() {
|
||||||
return categoriesService.getAll().stream().map(this::toDto).toList();
|
return CategoriesService.getAll().stream().map(this::toDto).toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/{id}")
|
@GetMapping("/{id}")
|
||||||
public CategoriesDto get(@PathVariable(name = "id") Long id) {
|
public CategoriesDto get(@PathVariable(name = "id") Long id) {
|
||||||
return toDto(categoriesService.get(id));
|
return toDto(CategoriesService.get(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping
|
@PostMapping
|
||||||
public CategoriesDto create(@RequestBody @Valid CategoriesDto dto) {
|
public CategoriesDto create(@RequestBody @Valid CategoriesDto dto) {
|
||||||
return toDto(categoriesService.create(toEntity(dto)));
|
return toDto(CategoriesService.create(toEntity(dto)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@PutMapping("/{id}")
|
@PutMapping("/{id}")
|
||||||
public CategoriesDto update(@PathVariable(name = "id") Long id, @RequestBody CategoriesDto dto) {
|
public CategoriesDto update(@PathVariable(name = "id") Long id, @RequestBody CategoriesDto dto) {
|
||||||
return toDto(categoriesService.update(id, toEntity(dto)));
|
return toDto(CategoriesService.update(id, toEntity(dto)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@DeleteMapping("/{id}")
|
@DeleteMapping("/{id}")
|
||||||
public CategoriesDto delete(@PathVariable(name = "id") Long id) {
|
public CategoriesDto delete(@PathVariable(name = "id") Long id) {
|
||||||
return toDto(categoriesService.delete(id));
|
return toDto(CategoriesService.delete(id));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,71 +0,0 @@
|
|||||||
package com.example.demo.itemOrders.api;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.modelmapper.ModelMapper;
|
|
||||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
|
||||||
import org.springframework.web.bind.annotation.PutMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
import com.example.demo.core.configuration.Constants;
|
|
||||||
import com.example.demo.itemOrders.model.OrdersEntity;
|
|
||||||
import com.example.demo.itemOrders.service.OrdersService;
|
|
||||||
import com.example.demo.itemProducts.model.ProductsEntity;
|
|
||||||
import com.example.demo.itemProducts.service.ProductsService;
|
|
||||||
|
|
||||||
import jakarta.validation.Valid;
|
|
||||||
|
|
||||||
@RestController
|
|
||||||
@RequestMapping(Constants.API_URL + "/Orders")
|
|
||||||
public class OrdersController {
|
|
||||||
private final OrdersService ordersService;
|
|
||||||
private final ProductsService productsService;
|
|
||||||
private final ModelMapper modelMapper;
|
|
||||||
|
|
||||||
public OrdersController(OrdersService ordersService, ProductsService productsService, ModelMapper modelMapper) {
|
|
||||||
this.ordersService = ordersService;
|
|
||||||
this.productsService = productsService;
|
|
||||||
this.modelMapper = modelMapper;
|
|
||||||
}
|
|
||||||
|
|
||||||
private OrdersDto toDto(OrdersEntity entity) {
|
|
||||||
return modelMapper.map(entity, OrdersDto.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
private OrdersEntity toEntity(OrdersDto dto) {
|
|
||||||
final OrdersEntity entity = modelMapper.map(dto, OrdersEntity.class);
|
|
||||||
entity.setProduct(productsService.get(dto.getProductId()));
|
|
||||||
return entity;
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping
|
|
||||||
public List<OrdersDto> getAll(@RequestParam(name = "typeId", defaultValue = "0") ProductsEntity product) {
|
|
||||||
return ordersService.getAll(product.getId()).stream().map(this::toDto).toList();
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping("/{id}")
|
|
||||||
public OrdersDto get(@PathVariable(name = "id") Long id) {
|
|
||||||
return toDto(ordersService.get(id));
|
|
||||||
}
|
|
||||||
|
|
||||||
@PostMapping
|
|
||||||
public OrdersDto create(@RequestBody @Valid OrdersDto dto) {
|
|
||||||
return toDto(ordersService.create(toEntity(dto)));
|
|
||||||
}
|
|
||||||
|
|
||||||
@PutMapping("/{id}")
|
|
||||||
public OrdersDto update(@PathVariable(name = "id") Long id, @RequestBody OrdersDto dto) {
|
|
||||||
return toDto(ordersService.update(id, toEntity(dto)));
|
|
||||||
}
|
|
||||||
|
|
||||||
@DeleteMapping("/{id}")
|
|
||||||
public OrdersDto delete(@PathVariable(name = "id") Long id) {
|
|
||||||
return toDto(ordersService.delete(id));
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,60 +0,0 @@
|
|||||||
package com.example.demo.itemOrders.api;
|
|
||||||
|
|
||||||
import java.text.SimpleDateFormat;
|
|
||||||
|
|
||||||
import com.example.demo.itemProducts.model.ProductsEntity;
|
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
|
||||||
|
|
||||||
import jakarta.validation.constraints.Min;
|
|
||||||
import jakarta.validation.constraints.NotNull;
|
|
||||||
|
|
||||||
public class OrdersDto {
|
|
||||||
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
|
|
||||||
private Long id;
|
|
||||||
@NotNull
|
|
||||||
private ProductsEntity product;
|
|
||||||
@NotNull
|
|
||||||
@Min(1)
|
|
||||||
private Integer count;
|
|
||||||
@NotNull
|
|
||||||
private SimpleDateFormat date;
|
|
||||||
|
|
||||||
public Long getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(Long id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ProductsEntity getProduct() {
|
|
||||||
return product;
|
|
||||||
}
|
|
||||||
public void setProduct(ProductsEntity product) {
|
|
||||||
this.product = product;
|
|
||||||
}
|
|
||||||
public Long getProductId() {
|
|
||||||
return product.getId();
|
|
||||||
}
|
|
||||||
public void setProductId(Long productId) {
|
|
||||||
productId = product.getId();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Integer getCount() {
|
|
||||||
return count;
|
|
||||||
}
|
|
||||||
public void setCount(Integer count) {
|
|
||||||
this.count = count;
|
|
||||||
}
|
|
||||||
public SimpleDateFormat getDate() {
|
|
||||||
return date;
|
|
||||||
}
|
|
||||||
public void setDate(SimpleDateFormat date) {
|
|
||||||
this.date = date;
|
|
||||||
}
|
|
||||||
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
|
|
||||||
public Double getSum() {
|
|
||||||
return count * product.getPrice();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,70 +0,0 @@
|
|||||||
package com.example.demo.itemProducts.api;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.modelmapper.ModelMapper;
|
|
||||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
|
||||||
import org.springframework.web.bind.annotation.PutMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
import com.example.demo.core.configuration.Constants;
|
|
||||||
import com.example.demo.itemProducts.model.ProductsEntity;
|
|
||||||
import com.example.demo.itemProducts.service.ProductsService;
|
|
||||||
import com.example.demo.itemCategories.service.CategoriesService;
|
|
||||||
|
|
||||||
import jakarta.validation.Valid;
|
|
||||||
|
|
||||||
@RestController
|
|
||||||
@RequestMapping(Constants.API_URL + "/Products")
|
|
||||||
public class ProductsController {
|
|
||||||
private final ProductsService productsService;
|
|
||||||
private final CategoriesService categoriesService;
|
|
||||||
private final ModelMapper modelMapper;
|
|
||||||
|
|
||||||
public ProductsController(ProductsService productsService, CategoriesService categoriesService, ModelMapper modelMapper) {
|
|
||||||
this.productsService = productsService;
|
|
||||||
this.categoriesService = categoriesService;
|
|
||||||
this.modelMapper = modelMapper;
|
|
||||||
}
|
|
||||||
|
|
||||||
private ProductsDto toDto(ProductsEntity entity) {
|
|
||||||
return modelMapper.map(entity, ProductsDto.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
private ProductsEntity toEntity(ProductsDto dto) {
|
|
||||||
final ProductsEntity entity = modelMapper.map(dto, ProductsEntity.class);
|
|
||||||
entity.setType(categoriesService.get(dto.getTypeId()));
|
|
||||||
return entity;
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping
|
|
||||||
public List<ProductsDto> getAll(@RequestParam(name = "typeId", defaultValue = "0") Long typeId) {
|
|
||||||
return productsService.getAll().stream().map(this::toDto).toList();
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping("/{id}")
|
|
||||||
public ProductsDto get(@PathVariable(name = "id") Long id) {
|
|
||||||
return toDto(productsService.get(id));
|
|
||||||
}
|
|
||||||
|
|
||||||
@PostMapping
|
|
||||||
public ProductsDto create(@RequestBody @Valid ProductsDto dto) {
|
|
||||||
return toDto(productsService.create(toEntity(dto)));
|
|
||||||
}
|
|
||||||
|
|
||||||
@PutMapping("/{id}")
|
|
||||||
public ProductsDto update(@PathVariable(name = "id") Long id, @RequestBody ProductsDto dto) {
|
|
||||||
return toDto(productsService.update(id, toEntity(dto)));
|
|
||||||
}
|
|
||||||
|
|
||||||
@DeleteMapping("/{id}")
|
|
||||||
public ProductsDto delete(@PathVariable(name = "id") Long id) {
|
|
||||||
return toDto(productsService.delete(id));
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,52 +0,0 @@
|
|||||||
package com.example.demo.itemProducts.api;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
|
||||||
|
|
||||||
import jakarta.validation.constraints.Min;
|
|
||||||
import jakarta.validation.constraints.NotBlank;
|
|
||||||
import jakarta.validation.constraints.NotNull;
|
|
||||||
|
|
||||||
public class ProductsDto {
|
|
||||||
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
|
|
||||||
private Long id;
|
|
||||||
@NotBlank
|
|
||||||
private String name;
|
|
||||||
@NotNull
|
|
||||||
@Min(1)
|
|
||||||
private Long typeId;
|
|
||||||
@NotNull
|
|
||||||
@Min(1)
|
|
||||||
private Double price;
|
|
||||||
|
|
||||||
public Long getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(Long id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Long getTypeId() {
|
|
||||||
return typeId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTypeId(Long typeId) {
|
|
||||||
this.typeId = typeId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Double getPrice() {
|
|
||||||
return price;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPrice(Double price) {
|
|
||||||
this.price = price;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setName(String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -31,9 +31,7 @@ public class ProductsEntity extends BaseEntity{
|
|||||||
public Double getPrice() {
|
public Double getPrice() {
|
||||||
return price;
|
return price;
|
||||||
}
|
}
|
||||||
public void setPrice(Double price) {
|
|
||||||
this.price = price;
|
|
||||||
}
|
|
||||||
public void setName(String name) {
|
public void setName(String name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
@ -41,6 +39,9 @@ public class ProductsEntity extends BaseEntity{
|
|||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setPrice(Double price) {
|
||||||
|
this.price = price;
|
||||||
|
}
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return Objects.hash(id, type, name, price);
|
return Objects.hash(id, type, name, price);
|
||||||
|
@ -17,17 +17,13 @@ public class ProductsService {
|
|||||||
public ProductsService(ProductsRepository repository) {
|
public ProductsService(ProductsRepository repository) {
|
||||||
this.repository = repository;
|
this.repository = repository;
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
public List<ProductsEntity> getAll(Long typeId) {
|
public List<ProductsEntity> getAll(Long typeId) {
|
||||||
if (Objects.equals(typeId, 0L)) {
|
if (Objects.equals(typeId, 0L)) {
|
||||||
return repository.getAll();
|
return repository.getAll();
|
||||||
}
|
}
|
||||||
return repository.getAll().stream().filter(item -> item.getType().getId().equals(typeId)).toList();
|
return repository.getAll().stream().filter(item -> item.getType().getId().equals(typeId)).toList();
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
public List<ProductsEntity> getAll() {
|
|
||||||
return repository.getAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
public ProductsEntity get(Long id) {
|
public ProductsEntity get(Long id) {
|
||||||
return Optional.ofNullable(repository.get(id)).orElseThrow(() -> new NotFoundException(id));
|
return Optional.ofNullable(repository.get(id)).orElseThrow(() -> new NotFoundException(id));
|
||||||
|
@ -21,11 +21,11 @@ import jakarta.validation.Valid;
|
|||||||
@RestController
|
@RestController
|
||||||
@RequestMapping(Constants.API_URL + "/Users")
|
@RequestMapping(Constants.API_URL + "/Users")
|
||||||
public class UsersController {
|
public class UsersController {
|
||||||
private final UsersService usersService;
|
private final UsersService UsersService;
|
||||||
private final ModelMapper modelMapper;
|
private final ModelMapper modelMapper;
|
||||||
|
|
||||||
public UsersController(UsersService usersService, ModelMapper modelMapper) {
|
public UsersController(UsersService UsersService, ModelMapper modelMapper) {
|
||||||
this.usersService = usersService;
|
this.UsersService = UsersService;
|
||||||
this.modelMapper = modelMapper;
|
this.modelMapper = modelMapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -39,26 +39,26 @@ public class UsersController {
|
|||||||
|
|
||||||
@GetMapping
|
@GetMapping
|
||||||
public List<UsersDto> getAll() {
|
public List<UsersDto> getAll() {
|
||||||
return usersService.getAll().stream().map(this::toDto).toList();
|
return UsersService.getAll().stream().map(this::toDto).toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/{id}")
|
@GetMapping("/{id}")
|
||||||
public UsersDto get(@PathVariable(name = "id") Long id) {
|
public UsersDto get(@PathVariable(name = "id") Long id) {
|
||||||
return toDto(usersService.get(id));
|
return toDto(UsersService.get(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping
|
@PostMapping
|
||||||
public UsersDto create(@RequestBody @Valid UsersDto dto) {
|
public UsersDto create(@RequestBody @Valid UsersDto dto) {
|
||||||
return toDto(usersService.create(toEntity(dto)));
|
return toDto(UsersService.create(toEntity(dto)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@PutMapping("/{id}")
|
@PutMapping("/{id}")
|
||||||
public UsersDto update(@PathVariable(name = "id") Long id, @RequestBody UsersDto dto) {
|
public UsersDto update(@PathVariable(name = "id") Long id, @RequestBody UsersDto dto) {
|
||||||
return toDto(usersService.update(id, toEntity(dto)));
|
return toDto(UsersService.update(id, toEntity(dto)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@DeleteMapping("/{id}")
|
@DeleteMapping("/{id}")
|
||||||
public UsersDto delete(@PathVariable(name = "id") Long id) {
|
public UsersDto delete(@PathVariable(name = "id") Long id) {
|
||||||
return toDto(usersService.delete(id));
|
return toDto(UsersService.delete(id));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package com.example.demo.itemUsers.service;
|
package com.example.demo.itemUsers.service;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
@ -16,31 +16,31 @@ import com.example.demo.itemCategories.model.CategoriesEntity;
|
|||||||
@TestMethodOrder(OrderAnnotation.class)
|
@TestMethodOrder(OrderAnnotation.class)
|
||||||
class CategoriesServiceTests {
|
class CategoriesServiceTests {
|
||||||
@Autowired
|
@Autowired
|
||||||
private CategoriesService categoriesService;
|
private CategoriesService CategoriesService;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void getTest() {
|
void getTest() {
|
||||||
Assertions.assertThrows(NotFoundException.class, () -> categoriesService.get(0L));
|
Assertions.assertThrows(NotFoundException.class, () -> CategoriesService.get(0L));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Order(1)
|
@Order(1)
|
||||||
void createTest() {
|
void createTest() {
|
||||||
categoriesService.create(new CategoriesEntity(null, "Ноутбук"));
|
CategoriesService.create(new CategoriesEntity(null, "Ноутбуки"));
|
||||||
categoriesService.create(new CategoriesEntity(null, "Телефон"));
|
final CategoriesEntity last = CategoriesService.create(new CategoriesEntity(null, "Телефоны"));
|
||||||
final CategoriesEntity last = categoriesService.create(new CategoriesEntity(null, "Игровая приставка"));
|
Assertions.assertEquals(3, CategoriesService.getAll().size());
|
||||||
Assertions.assertEquals(3, categoriesService.getAll().size());
|
Assertions.assertEquals(last, CategoriesService.get(3L));
|
||||||
Assertions.assertEquals(last, categoriesService.get(3L));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Order(2)
|
@Order(2)
|
||||||
void updateTest() {
|
void updateTest() {
|
||||||
final String test = "TEST";
|
final String test = "TEST";
|
||||||
final CategoriesEntity entity = categoriesService.get(3L);
|
final CategoriesEntity entity = CategoriesService.get(3L);
|
||||||
final String oldName = entity.getName();
|
final String oldName = entity.getName();
|
||||||
final CategoriesEntity newEntity = categoriesService.update(3L, new CategoriesEntity(1L, test));
|
final CategoriesEntity newEntity = CategoriesService.update(3L, new CategoriesEntity(1L, test));
|
||||||
Assertions.assertEquals(3, categoriesService.getAll().size());
|
Assertions.assertEquals(3, CategoriesService.getAll().size());
|
||||||
Assertions.assertEquals(newEntity, categoriesService.get(3L));
|
Assertions.assertEquals(newEntity, CategoriesService.get(3L));
|
||||||
Assertions.assertEquals(test, newEntity.getName());
|
Assertions.assertEquals(test, newEntity.getName());
|
||||||
Assertions.assertNotEquals(oldName, newEntity.getName());
|
Assertions.assertNotEquals(oldName, newEntity.getName());
|
||||||
}
|
}
|
||||||
@ -48,13 +48,13 @@ class CategoriesServiceTests {
|
|||||||
@Test
|
@Test
|
||||||
@Order(3)
|
@Order(3)
|
||||||
void deleteTest() {
|
void deleteTest() {
|
||||||
categoriesService.delete(3L);
|
CategoriesService.delete(3L);
|
||||||
Assertions.assertEquals(2, categoriesService.getAll().size());
|
Assertions.assertEquals(2, CategoriesService.getAll().size());
|
||||||
final CategoriesEntity last = categoriesService.get(2L);
|
final CategoriesEntity last = CategoriesService.get(2L);
|
||||||
Assertions.assertEquals(2L, last.getId());
|
Assertions.assertEquals(2L, last.getId());
|
||||||
|
|
||||||
final CategoriesEntity newEntity = categoriesService.create(new CategoriesEntity(null, "Игровая приставка"));
|
final CategoriesEntity newEntity = CategoriesService.create(new CategoriesEntity(null, "Игровая приставка"));
|
||||||
Assertions.assertEquals(3, categoriesService.getAll().size());
|
Assertions.assertEquals(3, CategoriesService.getAll().size());
|
||||||
Assertions.assertEquals(4L, newEntity.getId());
|
Assertions.assertEquals(4L, newEntity.getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,65 +0,0 @@
|
|||||||
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.itemCategories.model.CategoriesEntity;
|
|
||||||
import com.example.demo.itemCategories.service.CategoriesService;
|
|
||||||
import com.example.demo.itemProducts.service.ProductsService;
|
|
||||||
import com.example.demo.itemProducts.model.ProductsEntity;
|
|
||||||
|
|
||||||
@SpringBootTest
|
|
||||||
@TestMethodOrder(OrderAnnotation.class)
|
|
||||||
class ProductsServiceTests {
|
|
||||||
@Autowired
|
|
||||||
private ProductsService productsService;
|
|
||||||
private CategoriesService categoriesService;
|
|
||||||
CategoriesEntity category1 = categoriesService.create(new CategoriesEntity(null, "Телефон"));
|
|
||||||
CategoriesEntity category2 = categoriesService.create(new CategoriesEntity(null, "Игровая приставка"));
|
|
||||||
@Test
|
|
||||||
void getTest() {
|
|
||||||
Assertions.assertThrows(NotFoundException.class, () -> productsService.get(0L));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@Order(1)
|
|
||||||
void createTest() {
|
|
||||||
final CategoriesEntity category1 = categoriesService.create(new CategoriesEntity(null, "Ноутбук"));
|
|
||||||
final CategoriesEntity category2 = categoriesService.create(new CategoriesEntity(null, "Телефон"));
|
|
||||||
|
|
||||||
productsService.create(new ProductsEntity(null, category1, "Lenovo IDEA PAD 13", 15232.00));
|
|
||||||
productsService.create(new ProductsEntity(null, category1, "Acer", 20300.00));
|
|
||||||
final ProductsEntity last = productsService.create(new ProductsEntity (null, category2, "Iphone 13", 150000.00));
|
|
||||||
|
|
||||||
Assertions.assertEquals(3, productsService.getAll().size());
|
|
||||||
Assertions.assertEquals(last, productsService.get(3L));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@Order(2)
|
|
||||||
void updateTest() {
|
|
||||||
final Double newPrice = 20000.00;
|
|
||||||
final ProductsEntity entity = productsService.get(1L);
|
|
||||||
final Double oldPrice = entity.getPrice();
|
|
||||||
final ProductsEntity newEntity = productsService.update(1L, new ProductsEntity(1L,category1, "Lenovo IDEA PAD 13", newPrice));
|
|
||||||
Assertions.assertEquals(3, productsService.getAll().size());
|
|
||||||
Assertions.assertEquals(newEntity, productsService.get(1L));
|
|
||||||
Assertions.assertEquals(newPrice, newEntity.getPrice());
|
|
||||||
Assertions.assertNotEquals(oldPrice, newEntity.getPrice());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@Order(3)
|
|
||||||
void deleteTest() {
|
|
||||||
productsService.delete(3L);
|
|
||||||
Assertions.assertEquals(2, productsService.getAll().size());
|
|
||||||
final ProductsEntity last = productsService.get(2L);
|
|
||||||
Assertions.assertEquals(2L, last.getId());
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,148 +0,0 @@
|
|||||||
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.itemCategories.model.CategoriesEntity;
|
|
||||||
import com.example.demo.itemCategories.service.CategoriesService;
|
|
||||||
import com.example.demo.itemProducts.model.ProductsEntity;
|
|
||||||
import com.example.demo.itemProducts.service.ProductsService;
|
|
||||||
import com.example.demo.itemUsers.service.UsersService;
|
|
||||||
import com.example.demo.itemUsers.model.UsersEntity;
|
|
||||||
|
|
||||||
@SpringBootTest
|
|
||||||
@TestMethodOrder(OrderAnnotation.class)
|
|
||||||
class UsersServiceTests {
|
|
||||||
@Autowired
|
|
||||||
private UsersService usersService;
|
|
||||||
private CategoriesService categoriesService;
|
|
||||||
private ProductsService productsService;
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void getUsers() {
|
|
||||||
Assertions.assertThrows(NotFoundException.class, () -> usersService.get(0L));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@Order(1)
|
|
||||||
void createUsers() {
|
|
||||||
usersService.create(new UsersEntity(null, "Natalia", "1234"));
|
|
||||||
final UsersEntity last = usersService.create(new UsersEntity(null, "Revengel", "4567"));
|
|
||||||
Assertions.assertEquals(2, usersService.getAll().size());
|
|
||||||
Assertions.assertEquals(last, usersService.get(2L));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@Order(2)
|
|
||||||
void updateUsers() {
|
|
||||||
final String newPassword = "0000";
|
|
||||||
final UsersEntity entity = usersService.get(2L);
|
|
||||||
final String login = entity.getLogin();
|
|
||||||
final String oldPassword = entity.getPassword();
|
|
||||||
final UsersEntity newEntity = usersService.update(2L, new UsersEntity(1L, login, newPassword));
|
|
||||||
Assertions.assertEquals(2, usersService.getAll().size());
|
|
||||||
Assertions.assertEquals(newEntity, usersService.get(2L));
|
|
||||||
Assertions.assertEquals(newPassword, newEntity.getPassword());
|
|
||||||
Assertions.assertNotEquals(oldPassword, newEntity.getPassword());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@Order(3)
|
|
||||||
void deleteUsers() {
|
|
||||||
usersService.delete(2L);
|
|
||||||
Assertions.assertEquals(1, usersService.getAll().size());
|
|
||||||
final UsersEntity last = usersService.get(1L);
|
|
||||||
Assertions.assertEquals(1L, last.getId());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@Order(4)
|
|
||||||
void getCategories() {
|
|
||||||
Assertions.assertThrows(NotFoundException.class, () -> categoriesService.get(0L));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@Order(5)
|
|
||||||
void createCategories() {
|
|
||||||
CategoriesEntity category1 = categoriesService.create(new CategoriesEntity(null, "Телефон"));
|
|
||||||
CategoriesEntity category2 = categoriesService.create(new CategoriesEntity(null, "Игровая приставка"));
|
|
||||||
final CategoriesEntity last = categoriesService.create(new CategoriesEntity(null, "Ноутбук"));
|
|
||||||
Assertions.assertEquals(3, categoriesService.getAll().size());
|
|
||||||
Assertions.assertEquals(last, categoriesService.get(3L));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@Order(6)
|
|
||||||
void updateCategories() {
|
|
||||||
final String test = "TEST";
|
|
||||||
final CategoriesEntity entity = categoriesService.get(3L);
|
|
||||||
final String oldName = entity.getName();
|
|
||||||
final CategoriesEntity newEntity = categoriesService.update(3L, new CategoriesEntity(1L, test));
|
|
||||||
Assertions.assertEquals(3, categoriesService.getAll().size());
|
|
||||||
Assertions.assertEquals(newEntity, categoriesService.get(3L));
|
|
||||||
Assertions.assertEquals(test, newEntity.getName());
|
|
||||||
Assertions.assertNotEquals(oldName, newEntity.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@Order(7)
|
|
||||||
void deleteCategories() {
|
|
||||||
categoriesService.delete(3L);
|
|
||||||
Assertions.assertEquals(2, categoriesService.getAll().size());
|
|
||||||
final CategoriesEntity last = categoriesService.get(2L);
|
|
||||||
Assertions.assertEquals(2L, last.getId());
|
|
||||||
|
|
||||||
final CategoriesEntity newEntity = categoriesService.create(new CategoriesEntity(null, "Игровая приставка"));
|
|
||||||
Assertions.assertEquals(3, categoriesService.getAll().size());
|
|
||||||
Assertions.assertEquals(4L, newEntity.getId());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@Order(8)
|
|
||||||
void getTest() {
|
|
||||||
Assertions.assertThrows(NotFoundException.class, () -> productsService.get(0L));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@Order(9)
|
|
||||||
void createTest() {
|
|
||||||
productsService.create(new ProductsEntity(null, category1, "Lenovo IDEA PAD 13", 15232.00));
|
|
||||||
productsService.create(new ProductsEntity(null, category1, "Acer", 20300.00));
|
|
||||||
final ProductsEntity last = productsService.create(new ProductsEntity (null, category2, "Iphone 13", 150000.00));
|
|
||||||
|
|
||||||
Assertions.assertEquals(3, productsService.getAll().size());
|
|
||||||
Assertions.assertEquals(last, productsService.get(3L));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@Order(10)
|
|
||||||
void updateTest() {
|
|
||||||
final Double newPrice = 20000.00;
|
|
||||||
final ProductsEntity entity = productsService.get(1L);
|
|
||||||
final Double oldPrice = entity.getPrice();
|
|
||||||
final ProductsEntity newEntity = productsService.update(1L, new ProductsEntity(1L,category1, "Lenovo IDEA PAD 13", newPrice));
|
|
||||||
Assertions.assertEquals(3, productsService.getAll().size());
|
|
||||||
Assertions.assertEquals(newEntity, productsService.get(1L));
|
|
||||||
Assertions.assertEquals(newPrice, newEntity.getPrice());
|
|
||||||
Assertions.assertNotEquals(oldPrice, newEntity.getPrice());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@Order(11)
|
|
||||||
void deleteTest() {
|
|
||||||
productsService.delete(3L);
|
|
||||||
Assertions.assertEquals(2, productsService.getAll().size());
|
|
||||||
final ProductsEntity last = productsService.get(2L);
|
|
||||||
Assertions.assertEquals(2L, last.getId());
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,57 +0,0 @@
|
|||||||
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.itemUsers.service.UsersService;
|
|
||||||
import com.example.demo.itemUsers.model.UsersEntity;
|
|
||||||
|
|
||||||
@SpringBootTest
|
|
||||||
@TestMethodOrder(OrderAnnotation.class)
|
|
||||||
class UsersServiceTests {
|
|
||||||
@Autowired
|
|
||||||
private UsersService usersService;
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void getTest() {
|
|
||||||
Assertions.assertThrows(NotFoundException.class, () -> usersService.get(0L));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@Order(1)
|
|
||||||
void createTest() {
|
|
||||||
usersService.create(new UsersEntity(null, "Natalia", "1234"));
|
|
||||||
final UsersEntity last = usersService.create(new UsersEntity(null, "Revengel", "4567"));
|
|
||||||
Assertions.assertEquals(2, usersService.getAll().size());
|
|
||||||
Assertions.assertEquals(last, usersService.get(2L));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@Order(2)
|
|
||||||
void updateTest() {
|
|
||||||
final String newPassword = "0000";
|
|
||||||
final UsersEntity entity = usersService.get(2L);
|
|
||||||
final String login = entity.getLogin();
|
|
||||||
final String oldPassword = entity.getPassword();
|
|
||||||
final UsersEntity newEntity = usersService.update(2L, new UsersEntity(1L, login, newPassword));
|
|
||||||
Assertions.assertEquals(2, usersService.getAll().size());
|
|
||||||
Assertions.assertEquals(newEntity, usersService.get(2L));
|
|
||||||
Assertions.assertEquals(newPassword, newEntity.getPassword());
|
|
||||||
Assertions.assertNotEquals(oldPassword, newEntity.getPassword());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@Order(3)
|
|
||||||
void deleteTest() {
|
|
||||||
usersService.delete(1L);
|
|
||||||
Assertions.assertEquals(1, usersService.getAll().size());
|
|
||||||
final UsersEntity last = usersService.get(0L);
|
|
||||||
Assertions.assertEquals(1L, last.getId());
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user