- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我目前正在使用 Axon 4.2,并且我有一个聚合(Customer),它在其 @CommandHandlers 中使用注入(inject)的服务(CustomerService)
方法。
下面显示了它的简化版本(但对于本示例仍然有效)。
@Aggregate
public class Customer {
@AggregateIdentifier
private Long id;
private String name;
private String address;
@CommandHandler
public Customer(CreateCommand command, CustomerService customerService) {
log.debug( customerService.doSomething(command.getId()));
AggregateLifecycle.apply(new CreatedEvent(command.getId(), command.getName()));
}
@CommandHandler
public void on(UpdateCommand command, CustomerService customerService){
log.debug( customerService.doSomething(command.getId()));
AggregateLifecycle.apply( new UpdatedEvent(command.getId(),command.getAddress()));
}
@EventSourcingHandler
public void on(CreatedEvent event){
this.id = event.getId();
this.name = event.getName();
}
@EventSourcingHandler
public void on(UpdatedEvent event){
this.address = event.getAddress();
}
}
这是相应的测试:
@RunWith(MockitoJUnitRunner.class)
public class CustomerTest {
@Mock
private CustomerService customerService;
private FixtureConfiguration<Customer> fixture;
@Before
public void setUp() {
fixture = new AggregateTestFixture<>(Customer.class);
fixture.registerInjectableResource(customerService);
}
@Test
public void testCreation(){
final Long id = 1L;
final String name = "Elmo";
when(customerService.doSomething(id)).thenReturn("called");
fixture.givenNoPriorActivity()
.when(new CreateCommand(id, name))
.expectEvents(new CreatedEvent(id, name));
verify(customerService).doSomething(id);
verifyNoMoreInteractions(customerService);
}
@Test
public void testUpdate(){
final Long id = 1L;
final String name = "Elmo";
final String address = "Sesame street";
when(customerService.doSomething(id)).thenReturn("called");
fixture.givenState(() -> new Customer(id, name, null))
.when(new UpdateCommand(id, address))
.expectEvents(new UpdatedEvent(id, address));
verify(customerService).doSomething(id);
verifyNoMoreInteractions(customerService);
}
}
代码工作正常,但测试存在问题。事实上,testCreation() 测试通过,但 testUpdate() 测试失败并出现以下错误。
org.axonframework.test.FixtureExecutionException:
No resource of type [CustomerService] has been registered. It is required for one of the handlers being executed.
at org.axonframework.test.FixtureResourceParameterResolverFactory$FailingParameterResolver.resolveParameterValue(FixtureResourceParameterResolverFactory.java:58)
at org.axonframework.messaging.annotation.AnnotatedMessageHandlingMember.resolveParameterValues(AnnotatedMessageHandlingMember.java:156)
at org.axonframework.messaging.annotation.AnnotatedMessageHandlingMember.handle(AnnotatedMessageHandlingMember.java:132)
at org.axonframework.messaging.annotation.WrappedMessageHandlingMember.handle(WrappedMessageHandlingMember.java:61)
at org.axonframework.modelling.command.inspection.AnnotatedAggregate.handle(AnnotatedAggregate.java:427)
at org.axonframework.modelling.command.inspection.AnnotatedAggregate.lambda$handle$3(AnnotatedAggregate.java:400)
at org.axonframework.messaging.Scope.executeWithResult(Scope.java:111)
...
如果我删除 on UpdateCommand 方法中的 CustomerService 参数(以及相关代码),则 testUpdate() 测试通过,因此问题似乎出在依赖注入(inject)中。
最佳答案
聚合是 DomainDrivenDesign ( https://axoniq.io/resources/domain-driven-design ) 中的重要战术模式(主要构建 block )。在 Axon 中,聚合接受业务命令,这通常会产生与业务领域相关的事件——领域事件。首先,您不应该将逻辑委托(delegate)给某些外部 CustomerService
服务。您可以在 Axon Reference guide. 上找到有关如何设计聚合的更多详细信息。此外,this chapter提供带注释的消息处理函数的所有可能参数的详尽列表。
关于java - Axon 夹具注入(inject)在 @CommandHandler 注解的方法中失败(构造函数除外),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57937797/
是否可以设置一个夹具来创建数据库 View 而不是 CakePHP 中的数据库表?在创建表的夹具和另一个应该是数据库 View 的夹具中使用相同的数据似乎效率低下。 最佳答案 我设法这样做,其中 vi
与这个锦标赛赛程算法作斗争。 代码运行良好,但我需要帮助将数据插入 mysql我似乎无法访问 $varables.. 非常感谢 php 专家的任何调整 ... $teamnames = "Arsena
我正在尝试开始使用 Symfony2,并一直在尝试为我的应用程序的模型层设置自动化测试。 Symfony2 书讨论了 Controller 的单元测试,但我找不到很多模型测试的示例。 我希望在每次测试
我想为我的测试使用一个通用的夹具: @RunWith(JUnitPlatform::class) abstract class BaseSpek: Spek({ beforeGroup {pr
使用这个固定装置,我想根据 before 固定装置 Hook 中 API 调用的结果设置 checkoutId,这样我就可以用它来设置页面我的测试 let checkoutId; fixture`Ch
我尝试过各种尝试。这是我最新的。我只是想 stub Axios 请求并返回固定装置。 const { expect } = require('chai'); const sinon = require
我是一名优秀的程序员,十分优秀!