From a1837550e83c26bbcf3ea754732404c2955ee8ef Mon Sep 17 00:00:00 2001 From: Sorin Zamfir Date: Mon, 27 Jan 2020 20:40:24 +0200 Subject: [PATCH 01/13] BAEL-3777: First setup --- ddd/pom.xml | 8 ++++++- .../configuration/CassandraConfiguration.java | 10 ++++++++ .../configuration/MongoDBConfiguration.java | 4 ++-- .../CassandraDbOrderRepository.java | 23 +++++++++++++++++++ .../repository/MongoDbOrderRepository.java | 4 ++-- .../SpringDataCassandraOrderRepository.java | 11 +++++++++ ...va => SpringDataMongoOrderRepository.java} | 2 +- ddd/src/main/resources/ddd-layers.properties | 8 ++++++- .../MongoDbOrderRepositoryUnitTest.java | 4 ++-- .../dddhexagonalspring/docker-compose.yml | 7 +++++- 10 files changed, 71 insertions(+), 10 deletions(-) create mode 100644 ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/configuration/CassandraConfiguration.java create mode 100644 ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/CassandraDbOrderRepository.java create mode 100644 ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/SpringDataCassandraOrderRepository.java rename ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/{SpringDataOrderRepository.java => SpringDataMongoOrderRepository.java} (76%) diff --git a/ddd/pom.xml b/ddd/pom.xml index 9a0523a4c6..0893523c3b 100644 --- a/ddd/pom.xml +++ b/ddd/pom.xml @@ -20,14 +20,20 @@ org.springframework.boot spring-boot-starter-data-mongodb + + org.springframework.boot + spring-boot-starter-data-cassandra + org.junit.jupiter junit-jupiter-api + 5.6.0 test org.junit.jupiter junit-jupiter-engine + 5.6.0 test @@ -35,7 +41,7 @@ org.junit.platform junit-platform-launcher - ${junit-platform.version} + 1.6.0 test diff --git a/ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/configuration/CassandraConfiguration.java b/ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/configuration/CassandraConfiguration.java new file mode 100644 index 0000000000..76d7ad1aee --- /dev/null +++ b/ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/configuration/CassandraConfiguration.java @@ -0,0 +1,10 @@ +package com.baeldung.dddhexagonalspring.infrastracture.configuration; + +import org.springframework.data.cassandra.repository.config.EnableCassandraRepositories; + +import com.baeldung.dddhexagonalspring.infrastracture.repository.SpringDataCassandraOrderRepository; + +@EnableCassandraRepositories(basePackageClasses = SpringDataCassandraOrderRepository.class) +public class CassandraConfiguration { + +} diff --git a/ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/configuration/MongoDBConfiguration.java b/ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/configuration/MongoDBConfiguration.java index fd76b2eb0e..e0f5e77671 100644 --- a/ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/configuration/MongoDBConfiguration.java +++ b/ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/configuration/MongoDBConfiguration.java @@ -1,8 +1,8 @@ package com.baeldung.dddhexagonalspring.infrastracture.configuration; -import com.baeldung.dddhexagonalspring.infrastracture.repository.SpringDataOrderRepository; +import com.baeldung.dddhexagonalspring.infrastracture.repository.SpringDataMongoOrderRepository; import org.springframework.data.mongodb.repository.config.EnableMongoRepositories; -@EnableMongoRepositories(basePackageClasses = SpringDataOrderRepository.class) +@EnableMongoRepositories(basePackageClasses = SpringDataMongoOrderRepository.class) public class MongoDBConfiguration { } diff --git a/ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/CassandraDbOrderRepository.java b/ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/CassandraDbOrderRepository.java new file mode 100644 index 0000000000..f16a546576 --- /dev/null +++ b/ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/CassandraDbOrderRepository.java @@ -0,0 +1,23 @@ +package com.baeldung.dddhexagonalspring.infrastracture.repository; + +import java.util.Optional; +import java.util.UUID; + +import com.baeldung.dddhexagonalspring.domain.Order; +import com.baeldung.dddhexagonalspring.domain.repository.OrderRepository; + +public class CassandraDbOrderRepository implements OrderRepository { + + @Override + public Optional findById(UUID id) { + // TODO Auto-generated method stub + return null; + } + + @Override + public void save(Order order) { + // TODO Auto-generated method stub + + } + +} diff --git a/ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/MongoDbOrderRepository.java b/ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/MongoDbOrderRepository.java index 3123ef3e2f..bde0007ced 100644 --- a/ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/MongoDbOrderRepository.java +++ b/ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/MongoDbOrderRepository.java @@ -11,10 +11,10 @@ import java.util.UUID; @Component public class MongoDbOrderRepository implements OrderRepository { - private final SpringDataOrderRepository orderRepository; + private final SpringDataMongoOrderRepository orderRepository; @Autowired - public MongoDbOrderRepository(final SpringDataOrderRepository orderRepository) { + public MongoDbOrderRepository(final SpringDataMongoOrderRepository orderRepository) { this.orderRepository = orderRepository; } diff --git a/ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/SpringDataCassandraOrderRepository.java b/ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/SpringDataCassandraOrderRepository.java new file mode 100644 index 0000000000..9df128f035 --- /dev/null +++ b/ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/SpringDataCassandraOrderRepository.java @@ -0,0 +1,11 @@ +package com.baeldung.dddhexagonalspring.infrastracture.repository; + +import java.util.UUID; + +import org.springframework.data.cassandra.repository.CassandraRepository; + +import com.baeldung.dddhexagonalspring.domain.Order; + +public interface SpringDataCassandraOrderRepository extends CassandraRepository{ + +} diff --git a/ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/SpringDataOrderRepository.java b/ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/SpringDataMongoOrderRepository.java similarity index 76% rename from ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/SpringDataOrderRepository.java rename to ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/SpringDataMongoOrderRepository.java index 0279a5ce4a..620ecb34af 100644 --- a/ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/SpringDataOrderRepository.java +++ b/ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/SpringDataMongoOrderRepository.java @@ -7,5 +7,5 @@ import org.springframework.stereotype.Repository; import java.util.UUID; @Repository -public interface SpringDataOrderRepository extends MongoRepository { +public interface SpringDataMongoOrderRepository extends MongoRepository { } diff --git a/ddd/src/main/resources/ddd-layers.properties b/ddd/src/main/resources/ddd-layers.properties index 0479996b17..3b2aa35efe 100644 --- a/ddd/src/main/resources/ddd-layers.properties +++ b/ddd/src/main/resources/ddd-layers.properties @@ -2,4 +2,10 @@ spring.data.mongodb.host=localhost spring.data.mongodb.port=27017 spring.data.mongodb.database=order-database spring.data.mongodb.username=order -spring.data.mongodb.password=order \ No newline at end of file +spring.data.mongodb.password=order + +spring.data.cassandra.keyspaceName=order-database +spring.data.cassandra.username=cassandra +spring.data.cassandra.password=cassandra +spring.data.cassandra.contactPoints=localhost +spring.data.cassandra.port=9042 \ No newline at end of file diff --git a/ddd/src/test/java/com/baeldung/dddhexagonalspring/infrastracture/repository/MongoDbOrderRepositoryUnitTest.java b/ddd/src/test/java/com/baeldung/dddhexagonalspring/infrastracture/repository/MongoDbOrderRepositoryUnitTest.java index 8f7e8260a3..8247d7c7bd 100644 --- a/ddd/src/test/java/com/baeldung/dddhexagonalspring/infrastracture/repository/MongoDbOrderRepositoryUnitTest.java +++ b/ddd/src/test/java/com/baeldung/dddhexagonalspring/infrastracture/repository/MongoDbOrderRepositoryUnitTest.java @@ -14,12 +14,12 @@ import static org.mockito.Mockito.*; class MongoDbOrderRepositoryUnitTest { - private SpringDataOrderRepository springDataOrderRepository; + private SpringDataMongoOrderRepository springDataOrderRepository; private MongoDbOrderRepository tested; @BeforeEach void setUp(){ - springDataOrderRepository = mock(SpringDataOrderRepository.class); + springDataOrderRepository = mock(SpringDataMongoOrderRepository.class); tested = new MongoDbOrderRepository(springDataOrderRepository); } diff --git a/ddd/src/test/resources/com/baeldung/dddhexagonalspring/docker-compose.yml b/ddd/src/test/resources/com/baeldung/dddhexagonalspring/docker-compose.yml index d85ddf4a0e..dfad875a2b 100644 --- a/ddd/src/test/resources/com/baeldung/dddhexagonalspring/docker-compose.yml +++ b/ddd/src/test/resources/com/baeldung/dddhexagonalspring/docker-compose.yml @@ -11,4 +11,9 @@ services: MONGO_INITDB_ROOT_PASSWORD: admin MONGO_INITDB_DATABASE: order-database volumes: - - ./mongo-init.js:/docker-entrypoint-initdb.d/mongo-init.js:ro \ No newline at end of file + - ./mongo-init.js:/docker-entrypoint-initdb.d/mongo-init.js:ro + order-cassandra-database: + image: cassandra:3.11.5 + restart: always + ports: + - 9042:9042 \ No newline at end of file From 8144040512b45445879570c4ac2b7a331e24b287 Mon Sep 17 00:00:00 2001 From: Sorin Zamfir Date: Mon, 27 Jan 2020 21:14:55 +0200 Subject: [PATCH 02/13] BAEL-3777: Fixed some spring init issues --- .../repository/CassandraDbOrderRepository.java | 11 +++++++++++ .../repository/MongoDbOrderRepository.java | 2 ++ .../SpringDataCassandraOrderRepository.java | 2 ++ ddd/src/main/resources/ddd-layers.properties | 2 +- 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/CassandraDbOrderRepository.java b/ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/CassandraDbOrderRepository.java index f16a546576..a648a1f041 100644 --- a/ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/CassandraDbOrderRepository.java +++ b/ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/CassandraDbOrderRepository.java @@ -3,11 +3,22 @@ package com.baeldung.dddhexagonalspring.infrastracture.repository; import java.util.Optional; import java.util.UUID; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + import com.baeldung.dddhexagonalspring.domain.Order; import com.baeldung.dddhexagonalspring.domain.repository.OrderRepository; +@Component public class CassandraDbOrderRepository implements OrderRepository { + private final SpringDataCassandraOrderRepository orderRepository; + + @Autowired + public CassandraDbOrderRepository(SpringDataCassandraOrderRepository orderRepository) { + this.orderRepository = orderRepository; + } + @Override public Optional findById(UUID id) { // TODO Auto-generated method stub diff --git a/ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/MongoDbOrderRepository.java b/ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/MongoDbOrderRepository.java index bde0007ced..cf1d900821 100644 --- a/ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/MongoDbOrderRepository.java +++ b/ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/MongoDbOrderRepository.java @@ -3,12 +3,14 @@ package com.baeldung.dddhexagonalspring.infrastracture.repository; import com.baeldung.dddhexagonalspring.domain.Order; import com.baeldung.dddhexagonalspring.domain.repository.OrderRepository; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Primary; import org.springframework.stereotype.Component; import java.util.Optional; import java.util.UUID; @Component +@Primary public class MongoDbOrderRepository implements OrderRepository { private final SpringDataMongoOrderRepository orderRepository; diff --git a/ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/SpringDataCassandraOrderRepository.java b/ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/SpringDataCassandraOrderRepository.java index 9df128f035..dd7c7dbc81 100644 --- a/ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/SpringDataCassandraOrderRepository.java +++ b/ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/SpringDataCassandraOrderRepository.java @@ -3,9 +3,11 @@ package com.baeldung.dddhexagonalspring.infrastracture.repository; import java.util.UUID; import org.springframework.data.cassandra.repository.CassandraRepository; +import org.springframework.stereotype.Repository; import com.baeldung.dddhexagonalspring.domain.Order; +@Repository public interface SpringDataCassandraOrderRepository extends CassandraRepository{ } diff --git a/ddd/src/main/resources/ddd-layers.properties b/ddd/src/main/resources/ddd-layers.properties index 3b2aa35efe..d0ad343b66 100644 --- a/ddd/src/main/resources/ddd-layers.properties +++ b/ddd/src/main/resources/ddd-layers.properties @@ -4,7 +4,7 @@ spring.data.mongodb.database=order-database spring.data.mongodb.username=order spring.data.mongodb.password=order -spring.data.cassandra.keyspaceName=order-database +spring.data.cassandra.keyspaceName=order_database spring.data.cassandra.username=cassandra spring.data.cassandra.password=cassandra spring.data.cassandra.contactPoints=localhost From 1981d10ffdf1f6cf0c10547de0014274a437bdf3 Mon Sep 17 00:00:00 2001 From: Sorin Zamfir Date: Thu, 30 Jan 2020 18:55:50 +0200 Subject: [PATCH 03/13] BAEL-3777: Bumped spring boot version --- ddd/pom.xml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/ddd/pom.xml b/ddd/pom.xml index 0893523c3b..817e3b8899 100644 --- a/ddd/pom.xml +++ b/ddd/pom.xml @@ -27,13 +27,11 @@ org.junit.jupiter junit-jupiter-api - 5.6.0 test org.junit.jupiter junit-jupiter-engine - 5.6.0 test @@ -41,7 +39,6 @@ org.junit.platform junit-platform-launcher - 1.6.0 test @@ -96,7 +93,7 @@ 1.0.1 - 2.0.6.RELEASE + 2.2.4.RELEASE \ No newline at end of file From b05d42a6ea2246d803414d73a2d79dc46480bd4c Mon Sep 17 00:00:00 2001 From: Sorin Zamfir Date: Fri, 31 Jan 2020 23:32:37 +0200 Subject: [PATCH 04/13] BAEL-3777: Working version --- .../dddhexagonalspring/domain/Order.java | 17 +++++ .../CassandraDbOrderRepository.java | 15 ++-- .../repository/MongoDbOrderRepository.java | 1 - .../repository/OrderEntity.java | 75 +++++++++++++++++++ .../repository/OrderItemEntity.java | 44 +++++++++++ .../SpringDataCassandraOrderRepository.java | 2 +- ...andraDbOrderRepositoryIntegrationTest.java | 55 ++++++++++++++ ...MongoDbOrderRepositoryIntegrationTest.java | 54 +++++++++++++ .../baeldung/dddhexagonalspring/cassandra.cql | 12 +++ .../test/resources/ddd-layers-test.properties | 12 +++ 10 files changed, 280 insertions(+), 7 deletions(-) create mode 100644 ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/OrderEntity.java create mode 100644 ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/OrderItemEntity.java create mode 100644 ddd/src/test/java/com/baeldung/dddhexagonalspring/infrastracture/repository/CassandraDbOrderRepositoryIntegrationTest.java create mode 100644 ddd/src/test/java/com/baeldung/dddhexagonalspring/infrastracture/repository/MongoDbOrderRepositoryIntegrationTest.java create mode 100644 ddd/src/test/resources/com/baeldung/dddhexagonalspring/cassandra.cql create mode 100644 ddd/src/test/resources/ddd-layers-test.properties diff --git a/ddd/src/main/java/com/baeldung/dddhexagonalspring/domain/Order.java b/ddd/src/main/java/com/baeldung/dddhexagonalspring/domain/Order.java index 7d40007411..5ddc0f3500 100644 --- a/ddd/src/main/java/com/baeldung/dddhexagonalspring/domain/Order.java +++ b/ddd/src/main/java/com/baeldung/dddhexagonalspring/domain/Order.java @@ -4,6 +4,7 @@ import java.math.BigDecimal; import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.Objects; import java.util.UUID; public class Order { @@ -77,6 +78,22 @@ public class Order { return Collections.unmodifiableList(orderItems); } + + @Override + public int hashCode() { + return Objects.hash(id, orderItems, price, status); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!(obj instanceof Order)) + return false; + Order other = (Order) obj; + return Objects.equals(id, other.id) && Objects.equals(orderItems, other.orderItems) && Objects.equals(price, other.price) && status == other.status; + } + private Order() { } } diff --git a/ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/CassandraDbOrderRepository.java b/ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/CassandraDbOrderRepository.java index a648a1f041..c0aff0e11f 100644 --- a/ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/CassandraDbOrderRepository.java +++ b/ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/CassandraDbOrderRepository.java @@ -4,16 +4,18 @@ import java.util.Optional; import java.util.UUID; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Primary; import org.springframework.stereotype.Component; import com.baeldung.dddhexagonalspring.domain.Order; import com.baeldung.dddhexagonalspring.domain.repository.OrderRepository; @Component +@Primary public class CassandraDbOrderRepository implements OrderRepository { private final SpringDataCassandraOrderRepository orderRepository; - + @Autowired public CassandraDbOrderRepository(SpringDataCassandraOrderRepository orderRepository) { this.orderRepository = orderRepository; @@ -21,14 +23,17 @@ public class CassandraDbOrderRepository implements OrderRepository { @Override public Optional findById(UUID id) { - // TODO Auto-generated method stub - return null; + Optional orderEntity = orderRepository.findById(id); + if (orderEntity.isPresent()) { + return Optional.of(orderEntity.get().toOrder()); + } else { + return Optional.empty(); + } } @Override public void save(Order order) { - // TODO Auto-generated method stub - + orderRepository.save(new OrderEntity(order)); } } diff --git a/ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/MongoDbOrderRepository.java b/ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/MongoDbOrderRepository.java index cf1d900821..61ab93b707 100644 --- a/ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/MongoDbOrderRepository.java +++ b/ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/MongoDbOrderRepository.java @@ -10,7 +10,6 @@ import java.util.Optional; import java.util.UUID; @Component -@Primary public class MongoDbOrderRepository implements OrderRepository { private final SpringDataMongoOrderRepository orderRepository; diff --git a/ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/OrderEntity.java b/ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/OrderEntity.java new file mode 100644 index 0000000000..30c162a8ab --- /dev/null +++ b/ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/OrderEntity.java @@ -0,0 +1,75 @@ +package com.baeldung.dddhexagonalspring.infrastracture.repository; + +import java.math.BigDecimal; +import java.util.List; +import java.util.UUID; +import java.util.stream.Collectors; + +import org.springframework.data.cassandra.core.mapping.PrimaryKey; + +import com.baeldung.dddhexagonalspring.domain.Order; +import com.baeldung.dddhexagonalspring.domain.OrderItem; +import com.baeldung.dddhexagonalspring.domain.OrderStatus; +import com.baeldung.dddhexagonalspring.domain.Product; + +public class OrderEntity { + + @PrimaryKey + private UUID id; + private OrderStatus status; + private List orderItemEntities; + private BigDecimal price; + + public OrderEntity(UUID id, OrderStatus status, List orderItemEntities, BigDecimal price) { + this.id = id; + this.status = status; + this.orderItemEntities = orderItemEntities; + this.price = price; + } + + public OrderEntity() { + } + + public OrderEntity(Order order) { + this.id = order.getId(); + this.price = order.getPrice(); + this.status = order.getStatus(); + this.orderItemEntities = order.getOrderItems() + .stream() + .map(OrderItemEntity::new) + .collect(Collectors.toList()); + + } + + public Order toOrder() { + List orderItems = orderItemEntities.stream() + .map(OrderItemEntity::toOrderItem) + .collect(Collectors.toList()); + List namelessProducts = orderItems.stream() + .map(orderItem -> new Product(orderItem.getProductId(), orderItem.getPrice(), "")) + .collect(Collectors.toList()); + Order order = new Order(id, namelessProducts.remove(0)); + namelessProducts.forEach(product -> order.addOrder(product)); + if (status == OrderStatus.COMPLETED) { + order.complete(); + } + return order; + } + + public UUID getId() { + return id; + } + + public OrderStatus getStatus() { + return status; + } + + public List getOrderItems() { + return orderItemEntities; + } + + public BigDecimal getPrice() { + return price; + } + +} diff --git a/ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/OrderItemEntity.java b/ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/OrderItemEntity.java new file mode 100644 index 0000000000..44af65b842 --- /dev/null +++ b/ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/OrderItemEntity.java @@ -0,0 +1,44 @@ +package com.baeldung.dddhexagonalspring.infrastracture.repository; + +import java.math.BigDecimal; +import java.util.UUID; + +import org.springframework.data.cassandra.core.mapping.UserDefinedType; + +import com.baeldung.dddhexagonalspring.domain.OrderItem; +import com.baeldung.dddhexagonalspring.domain.Product; + +@UserDefinedType +public class OrderItemEntity { + + private UUID productId; + private BigDecimal price; + + public OrderItemEntity() { + } + + public OrderItemEntity(final OrderItem orderItem) { + this.productId = orderItem.getProductId(); + this.price = orderItem.getPrice(); + } + + public OrderItem toOrderItem() { + return new OrderItem(new Product(productId, price, "")); + } + + public UUID getProductId() { + return productId; + } + + public void setProductId(UUID productId) { + this.productId = productId; + } + + public BigDecimal getPrice() { + return price; + } + + public void setPrice(BigDecimal price) { + this.price = price; + } +} diff --git a/ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/SpringDataCassandraOrderRepository.java b/ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/SpringDataCassandraOrderRepository.java index dd7c7dbc81..eed265e877 100644 --- a/ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/SpringDataCassandraOrderRepository.java +++ b/ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/SpringDataCassandraOrderRepository.java @@ -8,6 +8,6 @@ import org.springframework.stereotype.Repository; import com.baeldung.dddhexagonalspring.domain.Order; @Repository -public interface SpringDataCassandraOrderRepository extends CassandraRepository{ +public interface SpringDataCassandraOrderRepository extends CassandraRepository{ } diff --git a/ddd/src/test/java/com/baeldung/dddhexagonalspring/infrastracture/repository/CassandraDbOrderRepositoryIntegrationTest.java b/ddd/src/test/java/com/baeldung/dddhexagonalspring/infrastracture/repository/CassandraDbOrderRepositoryIntegrationTest.java new file mode 100644 index 0000000000..aa1c8af43d --- /dev/null +++ b/ddd/src/test/java/com/baeldung/dddhexagonalspring/infrastracture/repository/CassandraDbOrderRepositoryIntegrationTest.java @@ -0,0 +1,55 @@ +package com.baeldung.dddhexagonalspring.infrastracture.repository; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.math.BigDecimal; +import java.util.Optional; +import java.util.UUID; + +import org.junit.After; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; + +import com.baeldung.dddhexagonalspring.domain.Order; +import com.baeldung.dddhexagonalspring.domain.Product; +import com.baeldung.dddhexagonalspring.domain.repository.OrderRepository; + +@SpringJUnitConfig +@SpringBootTest +@TestPropertySource("classpath:ddd-layers-test.properties") +class CassandraDbOrderRepositoryIntegrationTest { + + @Autowired + private SpringDataCassandraOrderRepository cassandraOrderRepository; + + @Autowired + private OrderRepository orderRepository; + + @After + void cleanUp(){ + cassandraOrderRepository.deleteAll(); + } + + @Test + void shouldFindById_thenReturnOrder() { + + // given + final UUID id = UUID.randomUUID(); + final Order order = createOrder(id); + order.complete(); + + // when + orderRepository.save(order); + + final Optional result = orderRepository.findById(id); + + assertEquals(order, result.get()); + } + + private Order createOrder(UUID id) { + return new Order(id, new Product(UUID.randomUUID(), BigDecimal.TEN, "product")); + } +} \ No newline at end of file diff --git a/ddd/src/test/java/com/baeldung/dddhexagonalspring/infrastracture/repository/MongoDbOrderRepositoryIntegrationTest.java b/ddd/src/test/java/com/baeldung/dddhexagonalspring/infrastracture/repository/MongoDbOrderRepositoryIntegrationTest.java new file mode 100644 index 0000000000..538fff0b51 --- /dev/null +++ b/ddd/src/test/java/com/baeldung/dddhexagonalspring/infrastracture/repository/MongoDbOrderRepositoryIntegrationTest.java @@ -0,0 +1,54 @@ +package com.baeldung.dddhexagonalspring.infrastracture.repository; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.math.BigDecimal; +import java.util.Optional; +import java.util.UUID; + +import org.junit.After; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; + +import com.baeldung.dddhexagonalspring.domain.Order; +import com.baeldung.dddhexagonalspring.domain.Product; +import com.baeldung.dddhexagonalspring.domain.repository.OrderRepository; + +@SpringJUnitConfig +@SpringBootTest +@TestPropertySource("classpath:ddd-layers-test.properties") +class MongoDbOrderRepositoryIntegrationTest { + + @Autowired + private SpringDataMongoOrderRepository mongoOrderRepository; + + @Autowired + private OrderRepository orderRepository; + + @After + void cleanUp(){ + mongoOrderRepository.deleteAll(); + } + + @Test + void shouldFindById_thenReturnOrder() { + + // given + final UUID id = UUID.randomUUID(); + final Order order = createOrder(id); + + // when + orderRepository.save(order); + + final Optional result = orderRepository.findById(id); + + assertEquals(order, result.get()); + } + + private Order createOrder(UUID id) { + return new Order(id, new Product(UUID.randomUUID(), BigDecimal.TEN, "product")); + } +} \ No newline at end of file diff --git a/ddd/src/test/resources/com/baeldung/dddhexagonalspring/cassandra.cql b/ddd/src/test/resources/com/baeldung/dddhexagonalspring/cassandra.cql new file mode 100644 index 0000000000..7adeda0a51 --- /dev/null +++ b/ddd/src/test/resources/com/baeldung/dddhexagonalspring/cassandra.cql @@ -0,0 +1,12 @@ +CREATE KEYSPACE IF NOT exists order_database +WITH replication = {'class':'SimpleStrategy', 'replication_factor':1}; + +CREATE TYPE order_database.orderitementity (productid uuid, price decimal); + +CREATE TABLE order_database.orderentity( + id uuid, + status text, + orderitementities list>, + price decimal, + primary key(id) +); diff --git a/ddd/src/test/resources/ddd-layers-test.properties b/ddd/src/test/resources/ddd-layers-test.properties new file mode 100644 index 0000000000..32307581aa --- /dev/null +++ b/ddd/src/test/resources/ddd-layers-test.properties @@ -0,0 +1,12 @@ +spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.mongo.embedded.EmbeddedMongoAutoConfiguration +spring.data.mongodb.host=127.0.0.1 +spring.data.mongodb.port=27017 +spring.data.mongodb.database=order-database +spring.data.mongodb.username=order +spring.data.mongodb.password=order + +spring.data.cassandra.keyspaceName=order_database +spring.data.cassandra.username=cassandra +spring.data.cassandra.password=cassandra +spring.data.cassandra.contactPoints=127.0.0.1 +spring.data.cassandra.port=9042 \ No newline at end of file From 8b49858bfe0de80b946a9666bb43f865f160cdc0 Mon Sep 17 00:00:00 2001 From: Sorin Zamfir Date: Sat, 1 Feb 2020 11:47:00 +0200 Subject: [PATCH 05/13] BAEL-3777: Fixed formatting --- .../dddhexagonalspring/domain/Order.java | 15 ++++++--------- .../configuration/CassandraConfiguration.java | 2 +- .../configuration/MongoDBConfiguration.java | 3 ++- .../CassandraDbOrderRepository.java | 2 +- .../repository/{ => cassandra}/OrderEntity.java | 2 +- .../{ => cassandra}/OrderItemEntity.java | 2 +- .../SpringDataCassandraOrderRepository.java | 2 +- .../{ => mongo}/MongoDbOrderRepository.java | 2 +- .../SpringDataMongoOrderRepository.java | 2 +- ...assandraDbOrderRepositoryIntegrationTest.java | 16 +++++++++------- .../MongoDbOrderRepositoryIntegrationTest.java | 15 ++++++++------- .../MongoDbOrderRepositoryUnitTest.java | 5 ++++- 12 files changed, 36 insertions(+), 32 deletions(-) rename ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/{ => cassandra}/CassandraDbOrderRepository.java (98%) rename ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/{ => cassandra}/OrderEntity.java (99%) rename ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/{ => cassandra}/OrderItemEntity.java (98%) rename ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/{ => cassandra}/SpringDataCassandraOrderRepository.java (96%) rename ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/{ => mongo}/MongoDbOrderRepository.java (99%) rename ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/{ => mongo}/SpringDataMongoOrderRepository.java (97%) diff --git a/ddd/src/main/java/com/baeldung/dddhexagonalspring/domain/Order.java b/ddd/src/main/java/com/baeldung/dddhexagonalspring/domain/Order.java index 5ddc0f3500..a8745eadbe 100644 --- a/ddd/src/main/java/com/baeldung/dddhexagonalspring/domain/Order.java +++ b/ddd/src/main/java/com/baeldung/dddhexagonalspring/domain/Order.java @@ -41,13 +41,11 @@ public class Order { } private OrderItem getOrderItem(final UUID id) { - return orderItems - .stream() - .filter(orderItem -> orderItem - .getProductId() - .equals(id)) - .findFirst() - .orElseThrow(() -> new DomainException("Product with " + id + " doesn't exist.")); + return orderItems.stream() + .filter(orderItem -> orderItem.getProductId() + .equals(id)) + .findFirst() + .orElseThrow(() -> new DomainException("Product with " + id + " doesn't exist.")); } private void validateState() { @@ -78,7 +76,6 @@ public class Order { return Collections.unmodifiableList(orderItems); } - @Override public int hashCode() { return Objects.hash(id, orderItems, price, status); @@ -93,7 +90,7 @@ public class Order { Order other = (Order) obj; return Objects.equals(id, other.id) && Objects.equals(orderItems, other.orderItems) && Objects.equals(price, other.price) && status == other.status; } - + private Order() { } } diff --git a/ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/configuration/CassandraConfiguration.java b/ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/configuration/CassandraConfiguration.java index 76d7ad1aee..3b5911979a 100644 --- a/ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/configuration/CassandraConfiguration.java +++ b/ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/configuration/CassandraConfiguration.java @@ -2,7 +2,7 @@ package com.baeldung.dddhexagonalspring.infrastracture.configuration; import org.springframework.data.cassandra.repository.config.EnableCassandraRepositories; -import com.baeldung.dddhexagonalspring.infrastracture.repository.SpringDataCassandraOrderRepository; +import com.baeldung.dddhexagonalspring.infrastracture.repository.cassandra.SpringDataCassandraOrderRepository; @EnableCassandraRepositories(basePackageClasses = SpringDataCassandraOrderRepository.class) public class CassandraConfiguration { diff --git a/ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/configuration/MongoDBConfiguration.java b/ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/configuration/MongoDBConfiguration.java index e0f5e77671..8ec6daf370 100644 --- a/ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/configuration/MongoDBConfiguration.java +++ b/ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/configuration/MongoDBConfiguration.java @@ -1,8 +1,9 @@ package com.baeldung.dddhexagonalspring.infrastracture.configuration; -import com.baeldung.dddhexagonalspring.infrastracture.repository.SpringDataMongoOrderRepository; import org.springframework.data.mongodb.repository.config.EnableMongoRepositories; +import com.baeldung.dddhexagonalspring.infrastracture.repository.mongo.SpringDataMongoOrderRepository; + @EnableMongoRepositories(basePackageClasses = SpringDataMongoOrderRepository.class) public class MongoDBConfiguration { } diff --git a/ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/CassandraDbOrderRepository.java b/ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/cassandra/CassandraDbOrderRepository.java similarity index 98% rename from ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/CassandraDbOrderRepository.java rename to ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/cassandra/CassandraDbOrderRepository.java index c0aff0e11f..98a69cbc88 100644 --- a/ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/CassandraDbOrderRepository.java +++ b/ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/cassandra/CassandraDbOrderRepository.java @@ -1,4 +1,4 @@ -package com.baeldung.dddhexagonalspring.infrastracture.repository; +package com.baeldung.dddhexagonalspring.infrastracture.repository.cassandra; import java.util.Optional; import java.util.UUID; diff --git a/ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/OrderEntity.java b/ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/cassandra/OrderEntity.java similarity index 99% rename from ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/OrderEntity.java rename to ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/cassandra/OrderEntity.java index 30c162a8ab..b9841a4433 100644 --- a/ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/OrderEntity.java +++ b/ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/cassandra/OrderEntity.java @@ -1,4 +1,4 @@ -package com.baeldung.dddhexagonalspring.infrastracture.repository; +package com.baeldung.dddhexagonalspring.infrastracture.repository.cassandra; import java.math.BigDecimal; import java.util.List; diff --git a/ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/OrderItemEntity.java b/ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/cassandra/OrderItemEntity.java similarity index 98% rename from ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/OrderItemEntity.java rename to ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/cassandra/OrderItemEntity.java index 44af65b842..2cf8ac7845 100644 --- a/ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/OrderItemEntity.java +++ b/ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/cassandra/OrderItemEntity.java @@ -1,4 +1,4 @@ -package com.baeldung.dddhexagonalspring.infrastracture.repository; +package com.baeldung.dddhexagonalspring.infrastracture.repository.cassandra; import java.math.BigDecimal; import java.util.UUID; diff --git a/ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/SpringDataCassandraOrderRepository.java b/ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/cassandra/SpringDataCassandraOrderRepository.java similarity index 96% rename from ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/SpringDataCassandraOrderRepository.java rename to ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/cassandra/SpringDataCassandraOrderRepository.java index eed265e877..ca460fb2c7 100644 --- a/ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/SpringDataCassandraOrderRepository.java +++ b/ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/cassandra/SpringDataCassandraOrderRepository.java @@ -1,4 +1,4 @@ -package com.baeldung.dddhexagonalspring.infrastracture.repository; +package com.baeldung.dddhexagonalspring.infrastracture.repository.cassandra; import java.util.UUID; diff --git a/ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/MongoDbOrderRepository.java b/ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/mongo/MongoDbOrderRepository.java similarity index 99% rename from ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/MongoDbOrderRepository.java rename to ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/mongo/MongoDbOrderRepository.java index 61ab93b707..f5d7b8f6c1 100644 --- a/ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/MongoDbOrderRepository.java +++ b/ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/mongo/MongoDbOrderRepository.java @@ -1,4 +1,4 @@ -package com.baeldung.dddhexagonalspring.infrastracture.repository; +package com.baeldung.dddhexagonalspring.infrastracture.repository.mongo; import com.baeldung.dddhexagonalspring.domain.Order; import com.baeldung.dddhexagonalspring.domain.repository.OrderRepository; diff --git a/ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/SpringDataMongoOrderRepository.java b/ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/mongo/SpringDataMongoOrderRepository.java similarity index 97% rename from ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/SpringDataMongoOrderRepository.java rename to ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/mongo/SpringDataMongoOrderRepository.java index 620ecb34af..73aa74e7d7 100644 --- a/ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/SpringDataMongoOrderRepository.java +++ b/ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/mongo/SpringDataMongoOrderRepository.java @@ -1,4 +1,4 @@ -package com.baeldung.dddhexagonalspring.infrastracture.repository; +package com.baeldung.dddhexagonalspring.infrastracture.repository.mongo; import com.baeldung.dddhexagonalspring.domain.Order; import org.springframework.data.mongodb.repository.MongoRepository; diff --git a/ddd/src/test/java/com/baeldung/dddhexagonalspring/infrastracture/repository/CassandraDbOrderRepositoryIntegrationTest.java b/ddd/src/test/java/com/baeldung/dddhexagonalspring/infrastracture/repository/CassandraDbOrderRepositoryIntegrationTest.java index aa1c8af43d..668d1e5e34 100644 --- a/ddd/src/test/java/com/baeldung/dddhexagonalspring/infrastracture/repository/CassandraDbOrderRepositoryIntegrationTest.java +++ b/ddd/src/test/java/com/baeldung/dddhexagonalspring/infrastracture/repository/CassandraDbOrderRepositoryIntegrationTest.java @@ -6,7 +6,7 @@ import java.math.BigDecimal; import java.util.Optional; import java.util.UUID; -import org.junit.After; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; @@ -16,6 +16,7 @@ import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import com.baeldung.dddhexagonalspring.domain.Order; import com.baeldung.dddhexagonalspring.domain.Product; import com.baeldung.dddhexagonalspring.domain.repository.OrderRepository; +import com.baeldung.dddhexagonalspring.infrastracture.repository.cassandra.SpringDataCassandraOrderRepository; @SpringJUnitConfig @SpringBootTest @@ -24,23 +25,24 @@ class CassandraDbOrderRepositoryIntegrationTest { @Autowired private SpringDataCassandraOrderRepository cassandraOrderRepository; - + @Autowired private OrderRepository orderRepository; - - @After - void cleanUp(){ + + @AfterEach + void cleanUp() { cassandraOrderRepository.deleteAll(); } @Test void shouldFindById_thenReturnOrder() { - + // given final UUID id = UUID.randomUUID(); final Order order = createOrder(id); + order.addOrder(new Product(UUID.randomUUID(), BigDecimal.TEN, "second")); order.complete(); - + // when orderRepository.save(order); diff --git a/ddd/src/test/java/com/baeldung/dddhexagonalspring/infrastracture/repository/MongoDbOrderRepositoryIntegrationTest.java b/ddd/src/test/java/com/baeldung/dddhexagonalspring/infrastracture/repository/MongoDbOrderRepositoryIntegrationTest.java index 538fff0b51..9a7736c419 100644 --- a/ddd/src/test/java/com/baeldung/dddhexagonalspring/infrastracture/repository/MongoDbOrderRepositoryIntegrationTest.java +++ b/ddd/src/test/java/com/baeldung/dddhexagonalspring/infrastracture/repository/MongoDbOrderRepositoryIntegrationTest.java @@ -6,7 +6,7 @@ import java.math.BigDecimal; import java.util.Optional; import java.util.UUID; -import org.junit.After; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; @@ -16,6 +16,7 @@ import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import com.baeldung.dddhexagonalspring.domain.Order; import com.baeldung.dddhexagonalspring.domain.Product; import com.baeldung.dddhexagonalspring.domain.repository.OrderRepository; +import com.baeldung.dddhexagonalspring.infrastracture.repository.mongo.SpringDataMongoOrderRepository; @SpringJUnitConfig @SpringBootTest @@ -24,22 +25,22 @@ class MongoDbOrderRepositoryIntegrationTest { @Autowired private SpringDataMongoOrderRepository mongoOrderRepository; - + @Autowired private OrderRepository orderRepository; - - @After - void cleanUp(){ + + @AfterEach + void cleanUp() { mongoOrderRepository.deleteAll(); } @Test void shouldFindById_thenReturnOrder() { - + // given final UUID id = UUID.randomUUID(); final Order order = createOrder(id); - + // when orderRepository.save(order); diff --git a/ddd/src/test/java/com/baeldung/dddhexagonalspring/infrastracture/repository/MongoDbOrderRepositoryUnitTest.java b/ddd/src/test/java/com/baeldung/dddhexagonalspring/infrastracture/repository/MongoDbOrderRepositoryUnitTest.java index 8247d7c7bd..4c75daaa4d 100644 --- a/ddd/src/test/java/com/baeldung/dddhexagonalspring/infrastracture/repository/MongoDbOrderRepositoryUnitTest.java +++ b/ddd/src/test/java/com/baeldung/dddhexagonalspring/infrastracture/repository/MongoDbOrderRepositoryUnitTest.java @@ -2,6 +2,9 @@ package com.baeldung.dddhexagonalspring.infrastracture.repository; import com.baeldung.dddhexagonalspring.domain.Order; import com.baeldung.dddhexagonalspring.domain.Product; +import com.baeldung.dddhexagonalspring.infrastracture.repository.mongo.MongoDbOrderRepository; +import com.baeldung.dddhexagonalspring.infrastracture.repository.mongo.SpringDataMongoOrderRepository; + import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -18,7 +21,7 @@ class MongoDbOrderRepositoryUnitTest { private MongoDbOrderRepository tested; @BeforeEach - void setUp(){ + void setUp() { springDataOrderRepository = mock(SpringDataMongoOrderRepository.class); tested = new MongoDbOrderRepository(springDataOrderRepository); From ef3570baaf9356a41867d353392caf6d37514009 Mon Sep 17 00:00:00 2001 From: Sorin Zamfir Date: Sat, 1 Feb 2020 12:47:34 +0200 Subject: [PATCH 06/13] BAEL-3777: Fixed init of cassandra --- .../{cassandra.cql => cassandra-init.cql} | 4 ++-- .../baeldung/dddhexagonalspring/docker-compose.yml | 13 ++++++++++++- ddd/src/test/resources/ddd-layers-test.properties | 2 +- 3 files changed, 15 insertions(+), 4 deletions(-) rename ddd/src/test/resources/com/baeldung/dddhexagonalspring/{cassandra.cql => cassandra-init.cql} (61%) diff --git a/ddd/src/test/resources/com/baeldung/dddhexagonalspring/cassandra.cql b/ddd/src/test/resources/com/baeldung/dddhexagonalspring/cassandra-init.cql similarity index 61% rename from ddd/src/test/resources/com/baeldung/dddhexagonalspring/cassandra.cql rename to ddd/src/test/resources/com/baeldung/dddhexagonalspring/cassandra-init.cql index 7adeda0a51..cbb22d2525 100644 --- a/ddd/src/test/resources/com/baeldung/dddhexagonalspring/cassandra.cql +++ b/ddd/src/test/resources/com/baeldung/dddhexagonalspring/cassandra-init.cql @@ -1,9 +1,9 @@ CREATE KEYSPACE IF NOT exists order_database WITH replication = {'class':'SimpleStrategy', 'replication_factor':1}; -CREATE TYPE order_database.orderitementity (productid uuid, price decimal); +CREATE TYPE IF NOT EXISTS order_database.orderitementity (productid uuid, price decimal); -CREATE TABLE order_database.orderentity( +CREATE TABLE IF NOT EXISTS order_database.orderentity( id uuid, status text, orderitementities list>, diff --git a/ddd/src/test/resources/com/baeldung/dddhexagonalspring/docker-compose.yml b/ddd/src/test/resources/com/baeldung/dddhexagonalspring/docker-compose.yml index dfad875a2b..7de0d30d43 100644 --- a/ddd/src/test/resources/com/baeldung/dddhexagonalspring/docker-compose.yml +++ b/ddd/src/test/resources/com/baeldung/dddhexagonalspring/docker-compose.yml @@ -3,6 +3,7 @@ version: '3' services: order-mongo-database: image: mongo:3.4.13 + container_name: order-mongo-db restart: always ports: - 27017:27017 @@ -14,6 +15,16 @@ services: - ./mongo-init.js:/docker-entrypoint-initdb.d/mongo-init.js:ro order-cassandra-database: image: cassandra:3.11.5 + container_name: order-cassandra-db restart: always ports: - - 9042:9042 \ No newline at end of file + - 9042:9042 + order-cassandra-init: + image: cassandra:3.11.5 + container_name: order-cassandra-db-init + depends_on: + - order-cassandra-database + volumes: + - ./cassandra-init.cql:/cassandra-init.cql:ro + command: bin/bash -c "echo Initializing cassandra schema... && sleep 30 && cqlsh -u cassandra -p cassandra -f cassandra-init.cql order-cassandra-db" + \ No newline at end of file diff --git a/ddd/src/test/resources/ddd-layers-test.properties b/ddd/src/test/resources/ddd-layers-test.properties index 32307581aa..d41689d91b 100644 --- a/ddd/src/test/resources/ddd-layers-test.properties +++ b/ddd/src/test/resources/ddd-layers-test.properties @@ -1,4 +1,4 @@ -spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.mongo.embedded.EmbeddedMongoAutoConfiguration +spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.mongo.embedded.EmbeddedMongoAutoConfiguration,org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration spring.data.mongodb.host=127.0.0.1 spring.data.mongodb.port=27017 spring.data.mongodb.database=order-database From 92640684d8e9d74f21d9b4c63cba895bbd7debd0 Mon Sep 17 00:00:00 2001 From: Sorin Zamfir Date: Sat, 1 Feb 2020 13:02:43 +0200 Subject: [PATCH 07/13] BAEL-3777: Cleanup --- .../SpringDataCassandraOrderRepository.java | 2 -- .../repository/mongo/MongoDbOrderRepository.java | 12 ++++++------ ddd/src/main/resources/ddd-layers.properties | 1 + .../com/baeldung/dddhexagonalspring/README.md | 4 +++- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/cassandra/SpringDataCassandraOrderRepository.java b/ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/cassandra/SpringDataCassandraOrderRepository.java index ca460fb2c7..3c89bd1b23 100644 --- a/ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/cassandra/SpringDataCassandraOrderRepository.java +++ b/ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/cassandra/SpringDataCassandraOrderRepository.java @@ -5,8 +5,6 @@ import java.util.UUID; import org.springframework.data.cassandra.repository.CassandraRepository; import org.springframework.stereotype.Repository; -import com.baeldung.dddhexagonalspring.domain.Order; - @Repository public interface SpringDataCassandraOrderRepository extends CassandraRepository{ diff --git a/ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/mongo/MongoDbOrderRepository.java b/ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/mongo/MongoDbOrderRepository.java index f5d7b8f6c1..e14cb88f5a 100644 --- a/ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/mongo/MongoDbOrderRepository.java +++ b/ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/mongo/MongoDbOrderRepository.java @@ -1,14 +1,14 @@ package com.baeldung.dddhexagonalspring.infrastracture.repository.mongo; -import com.baeldung.dddhexagonalspring.domain.Order; -import com.baeldung.dddhexagonalspring.domain.repository.OrderRepository; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Primary; -import org.springframework.stereotype.Component; - import java.util.Optional; import java.util.UUID; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import com.baeldung.dddhexagonalspring.domain.Order; +import com.baeldung.dddhexagonalspring.domain.repository.OrderRepository; + @Component public class MongoDbOrderRepository implements OrderRepository { diff --git a/ddd/src/main/resources/ddd-layers.properties b/ddd/src/main/resources/ddd-layers.properties index d0ad343b66..412c24eef7 100644 --- a/ddd/src/main/resources/ddd-layers.properties +++ b/ddd/src/main/resources/ddd-layers.properties @@ -1,3 +1,4 @@ +spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration spring.data.mongodb.host=localhost spring.data.mongodb.port=27017 spring.data.mongodb.database=order-database diff --git a/ddd/src/test/resources/com/baeldung/dddhexagonalspring/README.md b/ddd/src/test/resources/com/baeldung/dddhexagonalspring/README.md index e0337498fc..1355514a3d 100644 --- a/ddd/src/test/resources/com/baeldung/dddhexagonalspring/README.md +++ b/ddd/src/test/resources/com/baeldung/dddhexagonalspring/README.md @@ -4,4 +4,6 @@ To run this project, follow these steps: * Run the application database by executing `docker-compose up` in this directory. * Launch the Spring Boot Application (DomainLayerApplication). -* By default, application will connect to this database (configuration in *ddd-layers.properties*) \ No newline at end of file +* By default, the application will connect to the one of the two databases (configuration in *ddd-layers.properties*) + * check `CassandraDbOrderRepository.java` and `MongoDbOrderRepository.java` + * switch between the databases by making one of the above beans primary using the `@Primary` annotation \ No newline at end of file From a8617b62fa2d6eec253a87ed23b2736fecbc2135 Mon Sep 17 00:00:00 2001 From: Sorin Zamfir Date: Sat, 1 Feb 2020 15:50:49 +0200 Subject: [PATCH 08/13] BAEL-3777: Included CLI mode --- .../DomainLayerApplication.java | 40 ++++++++++++++++++- .../application/cli/CliOrderController.java | 38 ++++++++++++++++++ .../RestOrderController.java} | 6 +-- .../cassandra/CassandraDbOrderRepository.java | 1 - .../mongo/MongoDbOrderRepository.java | 2 + 5 files changed, 81 insertions(+), 6 deletions(-) create mode 100644 ddd/src/main/java/com/baeldung/dddhexagonalspring/application/cli/CliOrderController.java rename ddd/src/main/java/com/baeldung/dddhexagonalspring/application/{controller/OrderController.java => rest/RestOrderController.java} (91%) diff --git a/ddd/src/main/java/com/baeldung/dddhexagonalspring/DomainLayerApplication.java b/ddd/src/main/java/com/baeldung/dddhexagonalspring/DomainLayerApplication.java index 988f96042b..10fbc9c2f5 100644 --- a/ddd/src/main/java/com/baeldung/dddhexagonalspring/DomainLayerApplication.java +++ b/ddd/src/main/java/com/baeldung/dddhexagonalspring/DomainLayerApplication.java @@ -1,13 +1,49 @@ package com.baeldung.dddhexagonalspring; +import java.math.BigDecimal; +import java.util.UUID; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.CommandLineRunner; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.PropertySource; +import com.baeldung.dddhexagonalspring.application.cli.CliOrderController; +import com.baeldung.dddhexagonalspring.domain.Product; + @SpringBootApplication @PropertySource(value = { "classpath:ddd-layers.properties" }) -public class DomainLayerApplication { +public class DomainLayerApplication implements CommandLineRunner { + private static final Logger LOG = LoggerFactory.getLogger(DomainLayerApplication.class); + public static void main(final String[] args) { - SpringApplication.run(DomainLayerApplication.class, args); + SpringApplication application = new SpringApplication(DomainLayerApplication.class); + // uncomment to run just the console application + // application.setWebApplicationType(WebApplicationType.NONE); + application.run(args); + } + + @Autowired + public CliOrderController orderController; + + @Autowired + public ConfigurableApplicationContext context; + + @Override + public void run(String... args) throws Exception { + LOG.info("Placing a new CLI order with two products"); + Product mobilePhone = new Product(UUID.randomUUID(), BigDecimal.valueOf(200), "mobile"); + Product razor = new Product(UUID.randomUUID(), BigDecimal.valueOf(50), "razor"); + LOG.info("Creating order with mobile phone"); + UUID orderId = orderController.createOrder(mobilePhone); + LOG.info("Adding a razor to the order"); + orderController.addProduct(orderId, razor); + LOG.info("Completing order"); + orderController.completeOrder(orderId); + LOG.info("Order placement complete"); } } diff --git a/ddd/src/main/java/com/baeldung/dddhexagonalspring/application/cli/CliOrderController.java b/ddd/src/main/java/com/baeldung/dddhexagonalspring/application/cli/CliOrderController.java new file mode 100644 index 0000000000..cf073f61c8 --- /dev/null +++ b/ddd/src/main/java/com/baeldung/dddhexagonalspring/application/cli/CliOrderController.java @@ -0,0 +1,38 @@ +package com.baeldung.dddhexagonalspring.application.cli; + +import java.util.UUID; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import com.baeldung.dddhexagonalspring.domain.Product; +import com.baeldung.dddhexagonalspring.domain.service.OrderService; + +@Component +public class CliOrderController{ + + private final OrderService orderService; + + @Autowired + public CliOrderController(OrderService orderService) { + this.orderService = orderService; + } + + public UUID createOrder(Product product) { + return orderService.createOrder(product); + } + + public void addProduct(UUID orderId, Product product) { + orderService.addProduct(orderId, product); + } + + public void deleteProduct(UUID orderId, UUID productId) { + orderService.deleteProduct(orderId, productId); + + } + + public void completeOrder(UUID orderId) { + orderService.completeOrder(orderId); + } + +} diff --git a/ddd/src/main/java/com/baeldung/dddhexagonalspring/application/controller/OrderController.java b/ddd/src/main/java/com/baeldung/dddhexagonalspring/application/rest/RestOrderController.java similarity index 91% rename from ddd/src/main/java/com/baeldung/dddhexagonalspring/application/controller/OrderController.java rename to ddd/src/main/java/com/baeldung/dddhexagonalspring/application/rest/RestOrderController.java index 80ba36d01b..9fcec44a30 100644 --- a/ddd/src/main/java/com/baeldung/dddhexagonalspring/application/controller/OrderController.java +++ b/ddd/src/main/java/com/baeldung/dddhexagonalspring/application/rest/RestOrderController.java @@ -1,4 +1,4 @@ -package com.baeldung.dddhexagonalspring.application.controller; +package com.baeldung.dddhexagonalspring.application.rest; import com.baeldung.dddhexagonalspring.application.request.AddProductRequest; import com.baeldung.dddhexagonalspring.application.request.CreateOrderRequest; @@ -12,12 +12,12 @@ import java.util.UUID; @RestController @RequestMapping("/orders") -public class OrderController { +public class RestOrderController { private final OrderService orderService; @Autowired - public OrderController(OrderService orderService) { + public RestOrderController(OrderService orderService) { this.orderService = orderService; } diff --git a/ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/cassandra/CassandraDbOrderRepository.java b/ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/cassandra/CassandraDbOrderRepository.java index 98a69cbc88..c14792ce75 100644 --- a/ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/cassandra/CassandraDbOrderRepository.java +++ b/ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/cassandra/CassandraDbOrderRepository.java @@ -11,7 +11,6 @@ import com.baeldung.dddhexagonalspring.domain.Order; import com.baeldung.dddhexagonalspring.domain.repository.OrderRepository; @Component -@Primary public class CassandraDbOrderRepository implements OrderRepository { private final SpringDataCassandraOrderRepository orderRepository; diff --git a/ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/mongo/MongoDbOrderRepository.java b/ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/mongo/MongoDbOrderRepository.java index e14cb88f5a..b48b738cbd 100644 --- a/ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/mongo/MongoDbOrderRepository.java +++ b/ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/mongo/MongoDbOrderRepository.java @@ -4,12 +4,14 @@ import java.util.Optional; import java.util.UUID; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Primary; import org.springframework.stereotype.Component; import com.baeldung.dddhexagonalspring.domain.Order; import com.baeldung.dddhexagonalspring.domain.repository.OrderRepository; @Component +@Primary public class MongoDbOrderRepository implements OrderRepository { private final SpringDataMongoOrderRepository orderRepository; From 783e5d9b72b44757620b1f391703abe0dab81605 Mon Sep 17 00:00:00 2001 From: Sorin Zamfir Date: Sat, 1 Feb 2020 15:58:48 +0200 Subject: [PATCH 09/13] BAEL-3777: Fixed formatting --- .../repository/cassandra/CassandraDbOrderRepository.java | 4 ++-- .../cassandra/SpringDataCassandraOrderRepository.java | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/cassandra/CassandraDbOrderRepository.java b/ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/cassandra/CassandraDbOrderRepository.java index c14792ce75..686fc428e7 100644 --- a/ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/cassandra/CassandraDbOrderRepository.java +++ b/ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/cassandra/CassandraDbOrderRepository.java @@ -4,7 +4,6 @@ import java.util.Optional; import java.util.UUID; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Primary; import org.springframework.stereotype.Component; import com.baeldung.dddhexagonalspring.domain.Order; @@ -24,7 +23,8 @@ public class CassandraDbOrderRepository implements OrderRepository { public Optional findById(UUID id) { Optional orderEntity = orderRepository.findById(id); if (orderEntity.isPresent()) { - return Optional.of(orderEntity.get().toOrder()); + return Optional.of(orderEntity.get() + .toOrder()); } else { return Optional.empty(); } diff --git a/ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/cassandra/SpringDataCassandraOrderRepository.java b/ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/cassandra/SpringDataCassandraOrderRepository.java index 3c89bd1b23..93cd7ab83f 100644 --- a/ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/cassandra/SpringDataCassandraOrderRepository.java +++ b/ddd/src/main/java/com/baeldung/dddhexagonalspring/infrastracture/repository/cassandra/SpringDataCassandraOrderRepository.java @@ -6,6 +6,5 @@ import org.springframework.data.cassandra.repository.CassandraRepository; import org.springframework.stereotype.Repository; @Repository -public interface SpringDataCassandraOrderRepository extends CassandraRepository{ - +public interface SpringDataCassandraOrderRepository extends CassandraRepository { } From eec738467d66dd4af0fb5b3fe3ff0da08d1677d3 Mon Sep 17 00:00:00 2001 From: Sorin Zamfir Date: Sat, 1 Feb 2020 16:00:10 +0200 Subject: [PATCH 10/13] BAEL-3777: Fixed formatting --- .../dddhexagonalspring/application/cli/CliOrderController.java | 1 - 1 file changed, 1 deletion(-) diff --git a/ddd/src/main/java/com/baeldung/dddhexagonalspring/application/cli/CliOrderController.java b/ddd/src/main/java/com/baeldung/dddhexagonalspring/application/cli/CliOrderController.java index cf073f61c8..7f070a3415 100644 --- a/ddd/src/main/java/com/baeldung/dddhexagonalspring/application/cli/CliOrderController.java +++ b/ddd/src/main/java/com/baeldung/dddhexagonalspring/application/cli/CliOrderController.java @@ -28,7 +28,6 @@ public class CliOrderController{ public void deleteProduct(UUID orderId, UUID productId) { orderService.deleteProduct(orderId, productId); - } public void completeOrder(UUID orderId) { From c0415f763975450ef60bb38510a5aa6df09fee71 Mon Sep 17 00:00:00 2001 From: Sorin Zamfir Date: Sat, 1 Feb 2020 22:57:12 +0200 Subject: [PATCH 11/13] BAEL-3777: Improved CLI example --- .../DomainLayerApplication.java | 22 +++-------- .../application/cli/CliOrderController.java | 38 ++++++++++++------- 2 files changed, 29 insertions(+), 31 deletions(-) diff --git a/ddd/src/main/java/com/baeldung/dddhexagonalspring/DomainLayerApplication.java b/ddd/src/main/java/com/baeldung/dddhexagonalspring/DomainLayerApplication.java index 10fbc9c2f5..235021b03e 100644 --- a/ddd/src/main/java/com/baeldung/dddhexagonalspring/DomainLayerApplication.java +++ b/ddd/src/main/java/com/baeldung/dddhexagonalspring/DomainLayerApplication.java @@ -1,24 +1,18 @@ package com.baeldung.dddhexagonalspring; -import java.math.BigDecimal; -import java.util.UUID; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.CommandLineRunner; import org.springframework.boot.SpringApplication; +import org.springframework.boot.WebApplicationType; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.PropertySource; import com.baeldung.dddhexagonalspring.application.cli.CliOrderController; -import com.baeldung.dddhexagonalspring.domain.Product; @SpringBootApplication @PropertySource(value = { "classpath:ddd-layers.properties" }) public class DomainLayerApplication implements CommandLineRunner { - private static final Logger LOG = LoggerFactory.getLogger(DomainLayerApplication.class); public static void main(final String[] args) { SpringApplication application = new SpringApplication(DomainLayerApplication.class); @@ -35,15 +29,9 @@ public class DomainLayerApplication implements CommandLineRunner { @Override public void run(String... args) throws Exception { - LOG.info("Placing a new CLI order with two products"); - Product mobilePhone = new Product(UUID.randomUUID(), BigDecimal.valueOf(200), "mobile"); - Product razor = new Product(UUID.randomUUID(), BigDecimal.valueOf(50), "razor"); - LOG.info("Creating order with mobile phone"); - UUID orderId = orderController.createOrder(mobilePhone); - LOG.info("Adding a razor to the order"); - orderController.addProduct(orderId, razor); - LOG.info("Completing order"); - orderController.completeOrder(orderId); - LOG.info("Order placement complete"); + orderController.createCompleteOrder(); + orderController.createIncompleteOrder(); + // uncomment to stop the context when execution is done + // context.close(); } } diff --git a/ddd/src/main/java/com/baeldung/dddhexagonalspring/application/cli/CliOrderController.java b/ddd/src/main/java/com/baeldung/dddhexagonalspring/application/cli/CliOrderController.java index 7f070a3415..3d595533f3 100644 --- a/ddd/src/main/java/com/baeldung/dddhexagonalspring/application/cli/CliOrderController.java +++ b/ddd/src/main/java/com/baeldung/dddhexagonalspring/application/cli/CliOrderController.java @@ -1,7 +1,10 @@ package com.baeldung.dddhexagonalspring.application.cli; +import java.math.BigDecimal; import java.util.UUID; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -9,7 +12,9 @@ import com.baeldung.dddhexagonalspring.domain.Product; import com.baeldung.dddhexagonalspring.domain.service.OrderService; @Component -public class CliOrderController{ +public class CliOrderController { + + private static final Logger LOG = LoggerFactory.getLogger(CliOrderController.class); private final OrderService orderService; @@ -18,20 +23,25 @@ public class CliOrderController{ this.orderService = orderService; } - public UUID createOrder(Product product) { - return orderService.createOrder(product); - } - - public void addProduct(UUID orderId, Product product) { - orderService.addProduct(orderId, product); - } - - public void deleteProduct(UUID orderId, UUID productId) { - orderService.deleteProduct(orderId, productId); - } - - public void completeOrder(UUID orderId) { + public void createCompleteOrder() { + LOG.info("<>"); + UUID orderId = createOrder(); orderService.completeOrder(orderId); } + public void createIncompleteOrder() { + LOG.info("<>"); + UUID orderId = createOrder(); + } + + private UUID createOrder() { + LOG.info("Placing a new order with two products"); + Product mobilePhone = new Product(UUID.randomUUID(), BigDecimal.valueOf(200), "mobile"); + Product razor = new Product(UUID.randomUUID(), BigDecimal.valueOf(50), "razor"); + LOG.info("Creating order with mobile phone"); + UUID orderId = orderService.createOrder(mobilePhone); + LOG.info("Adding a razor to the order"); + orderService.addProduct(orderId, razor); + return orderId; + } } From f5f29086ba72da0cc85f4299898ff44baa234332 Mon Sep 17 00:00:00 2001 From: Sorin Zamfir Date: Tue, 4 Feb 2020 21:27:35 +0200 Subject: [PATCH 12/13] BAEL-3777: Revert naming for REST OrderController --- .../rest/{RestOrderController.java => OrderController.java} | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename ddd/src/main/java/com/baeldung/dddhexagonalspring/application/rest/{RestOrderController.java => OrderController.java} (94%) diff --git a/ddd/src/main/java/com/baeldung/dddhexagonalspring/application/rest/RestOrderController.java b/ddd/src/main/java/com/baeldung/dddhexagonalspring/application/rest/OrderController.java similarity index 94% rename from ddd/src/main/java/com/baeldung/dddhexagonalspring/application/rest/RestOrderController.java rename to ddd/src/main/java/com/baeldung/dddhexagonalspring/application/rest/OrderController.java index 9fcec44a30..12bb8ddea4 100644 --- a/ddd/src/main/java/com/baeldung/dddhexagonalspring/application/rest/RestOrderController.java +++ b/ddd/src/main/java/com/baeldung/dddhexagonalspring/application/rest/OrderController.java @@ -12,12 +12,12 @@ import java.util.UUID; @RestController @RequestMapping("/orders") -public class RestOrderController { +public class OrderController { private final OrderService orderService; @Autowired - public RestOrderController(OrderService orderService) { + public OrderController(OrderService orderService) { this.orderService = orderService; } From d1814a27112ba4f58f05c5d40e5241925bee00d7 Mon Sep 17 00:00:00 2001 From: Sorin Zamfir Date: Sun, 16 Feb 2020 21:49:31 +0200 Subject: [PATCH 13/13] BAEL-3777: Revert spring boot to previous version --- ddd/pom.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ddd/pom.xml b/ddd/pom.xml index 817e3b8899..f27f1d24a9 100644 --- a/ddd/pom.xml +++ b/ddd/pom.xml @@ -39,6 +39,7 @@ org.junit.platform junit-platform-launcher + ${junit-platform.version} test @@ -93,7 +94,7 @@ 1.0.1 - 2.2.4.RELEASE + 2.0.6.RELEASE \ No newline at end of file