BAEL-2275: Fill the test. Rename package.
This commit is contained in:
parent
b7c0761241
commit
6d1caf8026
|
@ -1,4 +1,4 @@
|
|||
package com.baeldung.ddd.layers;
|
||||
package com.baeldung.dddhexagonalspring;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|
@ -1,9 +1,9 @@
|
|||
package com.baeldung.ddd.layers.application.controller;
|
||||
package com.baeldung.dddhexagonalspring.application.controller;
|
||||
|
||||
import com.baeldung.ddd.layers.application.request.AddProductRequest;
|
||||
import com.baeldung.ddd.layers.application.request.CreateOrderRequest;
|
||||
import com.baeldung.ddd.layers.application.response.CreateOrderResponse;
|
||||
import com.baeldung.ddd.layers.domain.service.OrderService;
|
||||
import com.baeldung.dddhexagonalspring.application.request.AddProductRequest;
|
||||
import com.baeldung.dddhexagonalspring.application.request.CreateOrderRequest;
|
||||
import com.baeldung.dddhexagonalspring.application.response.CreateOrderResponse;
|
||||
import com.baeldung.dddhexagonalspring.domain.service.OrderService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.web.bind.annotation.*;
|
|
@ -1,6 +1,6 @@
|
|||
package com.baeldung.ddd.layers.application.request;
|
||||
package com.baeldung.dddhexagonalspring.application.request;
|
||||
|
||||
import com.baeldung.ddd.layers.domain.Product;
|
||||
import com.baeldung.dddhexagonalspring.domain.Product;
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
package com.baeldung.ddd.layers.application.request;
|
||||
package com.baeldung.dddhexagonalspring.application.request;
|
||||
|
||||
import com.baeldung.ddd.layers.domain.Product;
|
||||
import com.baeldung.dddhexagonalspring.domain.Product;
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package com.baeldung.ddd.layers.application.response;
|
||||
package com.baeldung.dddhexagonalspring.application.response;
|
||||
|
||||
import java.util.UUID;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package com.baeldung.ddd.layers.domain;
|
||||
package com.baeldung.dddhexagonalspring.domain;
|
||||
|
||||
class DomainException extends RuntimeException {
|
||||
DomainException(final String message) {
|
|
@ -1,4 +1,4 @@
|
|||
package com.baeldung.ddd.layers.domain;
|
||||
package com.baeldung.dddhexagonalspring.domain;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
|
@ -1,4 +1,4 @@
|
|||
package com.baeldung.ddd.layers.domain;
|
||||
package com.baeldung.dddhexagonalspring.domain;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Objects;
|
|
@ -1,4 +1,4 @@
|
|||
package com.baeldung.ddd.layers.domain;
|
||||
package com.baeldung.dddhexagonalspring.domain;
|
||||
|
||||
public enum OrderStatus {
|
||||
CREATED, COMPLETED
|
|
@ -1,4 +1,4 @@
|
|||
package com.baeldung.ddd.layers.domain;
|
||||
package com.baeldung.dddhexagonalspring.domain;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
|
@ -1,6 +1,6 @@
|
|||
package com.baeldung.ddd.layers.domain.repository;
|
||||
package com.baeldung.dddhexagonalspring.domain.repository;
|
||||
|
||||
import com.baeldung.ddd.layers.domain.Order;
|
||||
import com.baeldung.dddhexagonalspring.domain.Order;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
|
@ -1,8 +1,8 @@
|
|||
package com.baeldung.ddd.layers.domain.service;
|
||||
package com.baeldung.dddhexagonalspring.domain.service;
|
||||
|
||||
import com.baeldung.ddd.layers.domain.Order;
|
||||
import com.baeldung.ddd.layers.domain.Product;
|
||||
import com.baeldung.ddd.layers.domain.repository.OrderRepository;
|
||||
import com.baeldung.dddhexagonalspring.domain.Order;
|
||||
import com.baeldung.dddhexagonalspring.domain.Product;
|
||||
import com.baeldung.dddhexagonalspring.domain.repository.OrderRepository;
|
||||
|
||||
import java.util.UUID;
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
package com.baeldung.ddd.layers.domain.service;
|
||||
package com.baeldung.dddhexagonalspring.domain.service;
|
||||
|
||||
import com.baeldung.ddd.layers.domain.Product;
|
||||
import com.baeldung.dddhexagonalspring.domain.Product;
|
||||
|
||||
import java.util.UUID;
|
||||
|
|
@ -1,9 +1,9 @@
|
|||
package com.baeldung.ddd.layers.infrastracture.configuration;
|
||||
package com.baeldung.dddhexagonalspring.infrastracture.configuration;
|
||||
|
||||
import com.baeldung.ddd.layers.DomainLayerApplication;
|
||||
import com.baeldung.ddd.layers.domain.repository.OrderRepository;
|
||||
import com.baeldung.ddd.layers.domain.service.DomainOrderService;
|
||||
import com.baeldung.ddd.layers.domain.service.OrderService;
|
||||
import com.baeldung.dddhexagonalspring.DomainLayerApplication;
|
||||
import com.baeldung.dddhexagonalspring.domain.repository.OrderRepository;
|
||||
import com.baeldung.dddhexagonalspring.domain.service.DomainOrderService;
|
||||
import com.baeldung.dddhexagonalspring.domain.service.OrderService;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
|
@ -1,6 +1,6 @@
|
|||
package com.baeldung.ddd.layers.infrastracture.configuration;
|
||||
package com.baeldung.dddhexagonalspring.infrastracture.configuration;
|
||||
|
||||
import com.baeldung.ddd.layers.infrastracture.repository.SpringDataOrderRepository;
|
||||
import com.baeldung.dddhexagonalspring.infrastracture.repository.SpringDataOrderRepository;
|
||||
import org.springframework.data.mongodb.repository.config.EnableMongoRepositories;
|
||||
|
||||
@EnableMongoRepositories(basePackageClasses = SpringDataOrderRepository.class)
|
|
@ -1,7 +1,7 @@
|
|||
package com.baeldung.ddd.layers.infrastracture.repository;
|
||||
package com.baeldung.dddhexagonalspring.infrastracture.repository;
|
||||
|
||||
import com.baeldung.ddd.layers.domain.Order;
|
||||
import com.baeldung.ddd.layers.domain.repository.OrderRepository;
|
||||
import com.baeldung.dddhexagonalspring.domain.Order;
|
||||
import com.baeldung.dddhexagonalspring.domain.repository.OrderRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
package com.baeldung.ddd.layers.infrastracture.repository;
|
||||
package com.baeldung.dddhexagonalspring.infrastracture.repository;
|
||||
|
||||
import com.baeldung.ddd.layers.domain.Order;
|
||||
import com.baeldung.dddhexagonalspring.domain.Order;
|
||||
import org.springframework.data.mongodb.repository.MongoRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
package com.baeldung.ddd.layers.infrastracture.repository;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class MongoDbOrderRepositoryUnitTest {
|
||||
|
||||
private SpringDataOrderRepository springDataOrderRepository;
|
||||
private MongoDbOrderRepository tested;
|
||||
|
||||
@BeforeEach
|
||||
void setUp(){
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
void findById() {
|
||||
}
|
||||
|
||||
@Test
|
||||
void save() {
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package com.baeldung.ddd.layers.domain;
|
||||
package com.baeldung.dddhexagonalspring.domain;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.UUID;
|
|
@ -1,4 +1,4 @@
|
|||
package com.baeldung.ddd.layers.domain;
|
||||
package com.baeldung.dddhexagonalspring.domain;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
|
@ -1,9 +1,9 @@
|
|||
package com.baeldung.ddd.layers.domain.service;
|
||||
package com.baeldung.dddhexagonalspring.domain.service;
|
||||
|
||||
import com.baeldung.ddd.layers.domain.Order;
|
||||
import com.baeldung.ddd.layers.domain.OrderProvider;
|
||||
import com.baeldung.ddd.layers.domain.Product;
|
||||
import com.baeldung.ddd.layers.domain.repository.OrderRepository;
|
||||
import com.baeldung.dddhexagonalspring.domain.Order;
|
||||
import com.baeldung.dddhexagonalspring.domain.OrderProvider;
|
||||
import com.baeldung.dddhexagonalspring.domain.Product;
|
||||
import com.baeldung.dddhexagonalspring.domain.repository.OrderRepository;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.function.Executable;
|
|
@ -0,0 +1,51 @@
|
|||
package com.baeldung.dddhexagonalspring.infrastracture.repository;
|
||||
|
||||
import com.baeldung.dddhexagonalspring.domain.Order;
|
||||
import com.baeldung.dddhexagonalspring.domain.Product;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
class MongoDbOrderRepositoryUnitTest {
|
||||
|
||||
private SpringDataOrderRepository springDataOrderRepository;
|
||||
private MongoDbOrderRepository tested;
|
||||
|
||||
@BeforeEach
|
||||
void setUp(){
|
||||
springDataOrderRepository = mock(SpringDataOrderRepository.class);
|
||||
|
||||
tested = new MongoDbOrderRepository(springDataOrderRepository);
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldFindById_thenReturnOrder() {
|
||||
final UUID id = UUID.randomUUID();
|
||||
final Order order = createOrder(id);
|
||||
when(springDataOrderRepository.findById(id)).thenReturn(Optional.of(order));
|
||||
|
||||
final Optional<Order> result = tested.findById(id);
|
||||
|
||||
assertEquals(order, result.get());
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldSaveOrder_viaSpringDataOrderRepository() {
|
||||
final UUID id = UUID.randomUUID();
|
||||
final Order order = createOrder(id);
|
||||
|
||||
tested.save(order);
|
||||
|
||||
verify(springDataOrderRepository).save(order);
|
||||
}
|
||||
|
||||
private Order createOrder(UUID id) {
|
||||
return new Order(id, new Product(UUID.randomUUID(), BigDecimal.TEN, "product"));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue