From ec6429aadb7b6caab4cc4655855a9244cad8bc82 Mon Sep 17 00:00:00 2001 From: Ivan Dugalic Date: Thu, 21 Dec 2017 11:24:05 +0100 Subject: [PATCH] Adding validation to PublishBlogPostCommand Date must be in the future. Upgrading the version to 1.1.1 --- CHANGELOG.md | 10 +++++++++- pom.xml | 2 +- .../blog/command/CreateBlogPostCommand.java | 2 +- .../blog/command/PublishBlogPostCommand.java | 5 +++++ .../blog/aggregate/BlogPostAggregateTest.java | 4 ++-- 5 files changed, 18 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ab7dc52..c24a4fc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,15 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased][] -[Unreleased]: https://github.com/ivans-innovation-lab/my-company-blog-domain/compare/1.1.0...HEAD +[Unreleased]: https://github.com/ivans-innovation-lab/my-company-blog-domain/compare/1.1.1...HEAD + +## [1.1.1][] - 2017-12-21 + +[1.1.1]: https://github.com/ivans-innovation-lab/my-company-blog-domain/compare/1.1.0...1.1.1 + +### Changed + +- Added validation to the Publish blog post command `PublishBlogPostCommand.java`. Date must be in the future. ## [1.1.0][] - 2017-12-10 diff --git a/pom.xml b/pom.xml index 5473172..943c975 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ jar my company blog domain Blog project domain - Command side - 1.1.0 + 1.1.1 com.idugalic diff --git a/src/main/java/com/idugalic/commandside/blog/command/CreateBlogPostCommand.java b/src/main/java/com/idugalic/commandside/blog/command/CreateBlogPostCommand.java index cb1005a..ce60034 100644 --- a/src/main/java/com/idugalic/commandside/blog/command/CreateBlogPostCommand.java +++ b/src/main/java/com/idugalic/commandside/blog/command/CreateBlogPostCommand.java @@ -36,7 +36,7 @@ public class CreateBlogPostCommand extends AuditableAbstractCommand { private Boolean draft; @NotNull private Boolean broadcast; - @Future(message = "Publish at date must be the future") + @Future(message = "'Publish at' date must be in the future") @NotNull private Date publishAt; @NotNull diff --git a/src/main/java/com/idugalic/commandside/blog/command/PublishBlogPostCommand.java b/src/main/java/com/idugalic/commandside/blog/command/PublishBlogPostCommand.java index a775d9f..50eafe7 100644 --- a/src/main/java/com/idugalic/commandside/blog/command/PublishBlogPostCommand.java +++ b/src/main/java/com/idugalic/commandside/blog/command/PublishBlogPostCommand.java @@ -7,6 +7,9 @@ import org.axonframework.commandhandling.TargetAggregateIdentifier; +import javax.validation.constraints.Future; +import javax.validation.constraints.NotNull; + /** * A command for publishing a blog post. * @@ -17,6 +20,8 @@ public class PublishBlogPostCommand extends AuditableAbstractCommand { @TargetAggregateIdentifier private String id; + @Future(message = "'Publish at' date must be in the future") + @NotNull private Date publishAt; public PublishBlogPostCommand(String id, AuditEntry auditEntry, Date publishAt) { diff --git a/src/test/java/com/idugalic/commandside/blog/aggregate/BlogPostAggregateTest.java b/src/test/java/com/idugalic/commandside/blog/aggregate/BlogPostAggregateTest.java index d4cc17f..54ac4c1 100644 --- a/src/test/java/com/idugalic/commandside/blog/aggregate/BlogPostAggregateTest.java +++ b/src/test/java/com/idugalic/commandside/blog/aggregate/BlogPostAggregateTest.java @@ -58,14 +58,14 @@ public void createBlogPostWithWrongTitleTest() { @Test public void publishBlogPostTest() throws Exception { - PublishBlogPostCommand command = new PublishBlogPostCommand("id", auditEntry, new Date()); + PublishBlogPostCommand command = new PublishBlogPostCommand("id", auditEntry, future.getTime()); fixture.given(new BlogPostCreatedEvent(command.getId(), command.getAuditEntry(), "title", "rawContent", "publicSlug", Boolean.TRUE, Boolean.TRUE, command.getPublishAt(), BlogPostCategory.ENGINEERING, WHO)).when(command).expectEvents(new BlogPostPublishedEvent("id", auditEntry, command.getPublishAt())); } @Test public void publishBlogPostWithWrongIdTest() throws Exception { - PublishBlogPostCommand command = new PublishBlogPostCommand(null, auditEntry, new Date()); + PublishBlogPostCommand command = new PublishBlogPostCommand(null, auditEntry, future.getTime()); fixture.given(new BlogPostCreatedEvent(command.getId(), command.getAuditEntry(), "title", "rawContent", "publicSlug", Boolean.TRUE, Boolean.TRUE, command.getPublishAt(), BlogPostCategory.ENGINEERING, WHO)).when(command).expectException(IllegalArgumentException.class); }