Skip to content

Commit

Permalink
Adding validation to PublishBlogPostCommand
Browse files Browse the repository at this point in the history
Date must be in the future.
Upgrading the version to 1.1.1
  • Loading branch information
Ivan Dugalic committed Dec 21, 2017
1 parent faae24b commit ec6429a
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 5 deletions.
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<packaging>jar</packaging>
<name>my company blog domain</name>
<description>Blog project domain - Command side</description>
<version>1.1.0</version>
<version>1.1.1</version>

<parent>
<groupId>com.idugalic</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit ec6429a

Please sign in to comment.