コード例 #1
0
 @Test
 public void testFixture_WrongEventContents_WithNullValues() {
   List<?> givenEvents =
       Arrays.asList(
           new MyEvent("aggregateId", 1),
           new MyEvent("aggregateId", 2),
           new MyEvent("aggregateId", 3));
   MyCommandHandler commandHandler =
       new MyCommandHandler(fixture.getRepository(), fixture.getEventBus());
   try {
     fixture
         .registerAnnotatedCommandHandler(commandHandler)
         .given(givenEvents)
         .when(new TestCommand("aggregateId"))
         .expectEvents(new MyEvent("aggregateId", null)) // should be 4
         .expectVoidReturnType();
     fail("Expected an AxonAssertionError");
   } catch (AxonAssertionError e) {
     assertTrue(
         e.getMessage()
             .contains(
                 "In an event of type [MyEvent], the property [someValue] was not as expected."));
     assertTrue(e.getMessage().contains("Expected <<null>> but got <4>"));
   }
 }
コード例 #2
0
 @Test
 public void testFixture_UnexpectedReturnValue() {
   List<?> givenEvents =
       Arrays.asList(
           new MyEvent("aggregateId", 1),
           new MyEvent("aggregateId", 2),
           new MyEvent("aggregateId", 3));
   MyCommandHandler commandHandler =
       new MyCommandHandler(fixture.getRepository(), fixture.getEventBus());
   try {
     fixture
         .registerAnnotatedCommandHandler(commandHandler)
         .given(givenEvents)
         .when(new TestCommand("aggregateId"))
         .expectException(RuntimeException.class);
     fail("Expected an AxonAssertionError");
   } catch (AxonAssertionError e) {
     assertTrue(
         e.getMessage()
             .contains("The command handler returned normally, but an exception was expected"));
     assertTrue(
         e.getMessage()
             .contains("<an instance of java.lang.RuntimeException> but returned with <null>"));
   }
 }
コード例 #3
0
 @Test
 public void testFixtureDetectsStateChangeOutsideOfHandler_AggregateGeneratesIdentifier() {
   fixture
       .registerAnnotatedCommandHandler(
           new MyCommandHandler(fixture.getRepository(), fixture.getEventBus()))
       .given()
       .when(new CreateAggregateCommand(null));
 }
コード例 #4
0
 @Test
 public void testFixture_NoEventsInStore() {
   fixture
       .registerAnnotatedCommandHandler(
           new MyCommandHandler(fixture.getRepository(), fixture.getEventBus()))
       .given()
       .when(new TestCommand(UUID.randomUUID()))
       .expectException(AggregateNotFoundException.class);
 }
コード例 #5
0
 @Test
 public void testFixture_AggregateDeleted() {
   fixture
       .registerAnnotatedCommandHandler(
           new MyCommandHandler(fixture.getRepository(), fixture.getEventBus()))
       .given(new MyEvent("aggregateId", 5))
       .when(new DeleteCommand("aggregateId", false))
       .expectEvents(new MyAggregateDeletedEvent(false));
 }
コード例 #6
0
 @Test
 public void testFirstFixture() {
   ResultValidator validator =
       fixture
           .registerAnnotatedCommandHandler(
               new MyCommandHandler(fixture.getRepository(), fixture.getEventBus()))
           .given(new MyEvent("aggregateId", 1))
           .when(new TestCommand("aggregateId"));
   validator.expectReturnValue(null);
   validator.expectEvents(new MyEvent("aggregateId", 2));
 }
コード例 #7
0
 @Test
 public void testFixture_SetterInjection() {
   MyCommandHandler commandHandler = new MyCommandHandler();
   commandHandler.setRepository(fixture.getRepository());
   fixture
       .registerAnnotatedCommandHandler(commandHandler)
       .given(new MyEvent("aggregateId", 1), new MyEvent("aggregateId", 2))
       .when(new TestCommand("aggregateId"))
       .expectReturnValue(IsNull.nullValue())
       .expectEvents(new MyEvent("aggregateId", 3));
 }
コード例 #8
0
 @Test
 public void testExpectEventsIgnoresFilteredField() {
   ResultValidator validator =
       fixture
           .registerAnnotatedCommandHandler(
               new MyCommandHandler(fixture.getRepository(), fixture.getEventBus()))
           .registerFieldFilter(field -> !field.getName().equals("someBytes"))
           .given(new MyEvent("aggregateId", 1))
           .when(new TestCommand("aggregateId"));
   validator.expectReturnValue(null);
   validator.expectEvents(new MyEvent("aggregateId", 2, "ignored".getBytes()));
 }
コード例 #9
0
 @Test
 public void testFixtureGivenCommands() {
   fixture
       .registerAnnotatedCommandHandler(
           new MyCommandHandler(fixture.getRepository(), fixture.getEventBus()))
       .givenCommands(
           new CreateAggregateCommand("aggregateId"),
           new TestCommand("aggregateId"),
           new TestCommand("aggregateId"),
           new TestCommand("aggregateId"))
       .when(new TestCommand("aggregateId"))
       .expectEvents(new MyEvent("aggregateId", 4));
 }
コード例 #10
0
 @Test
 public void testFixtureDetectsStateChangeOutsideOfHandler_Ignored() {
   List<?> givenEvents =
       Arrays.asList(
           new MyEvent("aggregateId", 1),
           new MyEvent("aggregateId", 2),
           new MyEvent("aggregateId", 3));
   fixture.setReportIllegalStateChange(false);
   fixture
       .registerAnnotatedCommandHandler(
           new MyCommandHandler(fixture.getRepository(), fixture.getEventBus()))
       .given(givenEvents)
       .when(new IllegalStateChangeCommand("aggregateId", null));
 }
コード例 #11
0
 @Test
 public void testFixtureIgnoredStateChangeInFilteredField() {
   List<?> givenEvents =
       Arrays.asList(
           new MyEvent("aggregateId", 1),
           new MyEvent("aggregateId", 2),
           new MyEvent("aggregateId", 3));
   fixture.registerFieldFilter(field -> !field.getName().equals("lastNumber"));
   fixture
       .registerAnnotatedCommandHandler(
           new MyCommandHandler(fixture.getRepository(), fixture.getEventBus()))
       .given(givenEvents)
       .when(new IllegalStateChangeCommand("aggregateId", 5));
 }
コード例 #12
0
 @Test
 public void testFixtureDetectsStateChangeOutsideOfHandler_AggregateDeleted() {
   TestExecutor exec =
       fixture
           .registerAnnotatedCommandHandler(
               new MyCommandHandler(fixture.getRepository(), fixture.getEventBus()))
           .given(new MyEvent("aggregateId", 5));
   try {
     exec.when(new DeleteCommand("aggregateId", true));
     fail("Fixture should have failed");
   } catch (AssertionError error) {
     assertTrue(
         "Wrong message: " + error.getMessage(),
         error.getMessage().contains("considered deleted"));
   }
 }
コード例 #13
0
 @Test
 public void testFixture_GivenAList() {
   List<?> givenEvents =
       Arrays.asList(
           new MyEvent("aggregateId", 1),
           new MyEvent("aggregateId", 2),
           new MyEvent("aggregateId", 3));
   fixture
       .registerAnnotatedCommandHandler(
           new MyCommandHandler(fixture.getRepository(), fixture.getEventBus()))
       .given(givenEvents)
       .when(new TestCommand("aggregateId"))
       .expectEvents(new MyEvent("aggregateId", 4))
       .expectStoredEvents(new MyEvent("aggregateId", 4))
       .expectPublishedEvents(new MyEvent("aggregateId", 4))
       .expectVoidReturnType();
 }
コード例 #14
0
 @Test
 public void testFixture_ReportWrongNumberOfEvents() {
   List<?> givenEvents =
       Arrays.asList(
           new MyEvent("aggregateId", 1),
           new MyEvent("aggregateId", 2),
           new MyEvent("aggregateId", 3));
   MyCommandHandler commandHandler =
       new MyCommandHandler(fixture.getRepository(), fixture.getEventBus());
   try {
     fixture
         .registerAnnotatedCommandHandler(commandHandler)
         .given(givenEvents)
         .when(new TestCommand("aggregateId"))
         .expectEvents(new MyEvent("aggregateId", 4), new MyEvent("aggregateId", 5));
     fail("Expected an AxonAssertionError");
   } catch (AxonAssertionError e) {
     assertTrue(e.getMessage().contains("org.axonframework.test.MyEvent <|> "));
   }
 }
コード例 #15
0
 @Test
 public void testFixture_CommandHandlerDispatchesNonDomainEvents() {
   List<?> givenEvents =
       Arrays.asList(
           new MyEvent("aggregateId", 1),
           new MyEvent("aggregateId", 2),
           new MyEvent("aggregateId", 3));
   MyCommandHandler commandHandler =
       new MyCommandHandler(fixture.getRepository(), fixture.getEventBus());
   // the domain events are part of the transaction, but the command handler directly dispatches an
   // application
   // event to the event bus. This event dispatched anyway. The
   fixture
       .registerAnnotatedCommandHandler(commandHandler)
       .given(givenEvents)
       .when(new StrangeCommand("aggregateId"))
       .expectStoredEvents()
       .expectPublishedEvents(new MyApplicationEvent())
       .expectException(StrangeCommandReceivedException.class);
 }
コード例 #16
0
 @Test
 public void testFixtureDetectsStateChangeOutsideOfHandler_NullValue() {
   List<?> givenEvents =
       Arrays.asList(
           new MyEvent("aggregateId", 1),
           new MyEvent("aggregateId", 2),
           new MyEvent("aggregateId", 3));
   try {
     fixture
         .registerAnnotatedCommandHandler(
             new MyCommandHandler(fixture.getRepository(), fixture.getEventBus()))
         .given(givenEvents)
         .when(new IllegalStateChangeCommand("aggregateId", null));
     fail("Expected AssertionError");
   } catch (AssertionError e) {
     assertTrue("Wrong message: " + e.getMessage(), e.getMessage().contains(".lastNumber\""));
     assertTrue("Wrong message: " + e.getMessage(), e.getMessage().contains("<null>"));
     assertTrue("Wrong message: " + e.getMessage(), e.getMessage().contains("<4>"));
   }
 }
コード例 #17
0
 @Test
 public void testFixture_WrongReturnValue() {
   List<?> givenEvents =
       Arrays.asList(
           new MyEvent("aggregateId", 1),
           new MyEvent("aggregateId", 2),
           new MyEvent("aggregateId", 3));
   MyCommandHandler commandHandler =
       new MyCommandHandler(fixture.getRepository(), fixture.getEventBus());
   try {
     fixture
         .registerAnnotatedCommandHandler(commandHandler)
         .given(givenEvents)
         .when(new TestCommand("aggregateId"))
         .expectReturnValue("some");
     fail("Expected an AxonAssertionError");
   } catch (AxonAssertionError e) {
     assertTrue(e.getMessage(), e.getMessage().contains("<\"some\"> but got <null>"));
   }
 }
コード例 #18
0
 @Test
 public void testFixture_UnexpectedException() {
   List<?> givenEvents =
       Arrays.asList(
           new MyEvent("aggregateId", 1),
           new MyEvent("aggregateId", 2),
           new MyEvent("aggregateId", 3));
   MyCommandHandler commandHandler =
       new MyCommandHandler(fixture.getRepository(), fixture.getEventBus());
   try {
     fixture
         .registerAnnotatedCommandHandler(commandHandler)
         .given(givenEvents)
         .when(new StrangeCommand("aggregateId"))
         .expectVoidReturnType();
     fail("Expected an AxonAssertionError");
   } catch (AxonAssertionError e) {
     assertTrue(
         e.getMessage().contains("but got <exception of type [StrangeCommandReceivedException]>"));
   }
 }
コード例 #19
0
 @Test
 public void testFixture_ExpectedPublishedSameAsStored() {
   List<?> givenEvents =
       Arrays.asList(
           new MyEvent("aggregateId", 1),
           new MyEvent("aggregateId", 2),
           new MyEvent("aggregateId", 3));
   MyCommandHandler commandHandler =
       new MyCommandHandler(fixture.getRepository(), fixture.getEventBus());
   try {
     fixture
         .registerAnnotatedCommandHandler(commandHandler)
         .given(givenEvents)
         .when(new StrangeCommand("aggregateId"))
         .expectEvents(new MyEvent("aggregateId", 4)) // should be 4
         .expectException(StrangeCommandReceivedException.class);
     fail("Expected an AxonAssertionError");
   } catch (AxonAssertionError e) {
     assertTrue(e.getMessage().contains("The stored events do not match the published events."));
     assertTrue(e.getMessage().contains(" <|> org.axonframework.test.MyApplicationEvent"));
     assertTrue(e.getMessage().contains("probable cause"));
   }
 }
コード例 #20
0
 @Before
 public void setUp() {
   fixture = Fixtures.newGivenWhenThenFixture(StandardAggregate.class);
   fixture.registerAggregateFactory(new StandardAggregate.Factory());
 }