// Path: axon-spring-boot-starter-monitoring/src/test/java/hm/binkley/spring/axon/shared/TestAuditEventRepository.java
// public class TestAuditEventRepository
//         implements AuditEventRepository {
//     private final List<AuditEvent> trail = new ArrayList<>();
// 
//     @Override
//     public List<AuditEvent> find(final String principal, final Date after) {
//         throw new UnsupportedOperationException();
//     }
// 
//     @Override
//     public void add(final AuditEvent event) {
//         trail.add(event);
//     }
// 
//     public void reset() {
//         trail.clear();
//     }
// 
//     public int received() {
//         return trail.size();
//     }
// 
//     public AuditEvent eventAt(final int sequence) {
//         return trail.get(sequence);
//     }
// }
// 
// Path: axon-spring-boot-starter-monitoring/src/main/java/hm/binkley/spring/axon/AxonCommandAuditEvent.java
// public static final String AXON_COMMAND_AUDIT_TYPE = CommandMessage.class
//         .getName();
// 
// Path: axon-spring-boot-starter-monitoring/src/main/java/hm/binkley/spring/axon/AxonEventAuditEvent.java
// public static final String AXON_EVENT_AUDIT_TYPE = EventMessage.class
//         .getName();
// 
// Path: axon-spring-boot-starter-monitoring/src/main/java/hm/binkley/spring/axon/SpringBootAuditLogger.java
// public static final String FAILURE_CAUSE = inNamespace("failure-cause");
// 
// Path: axon-spring-boot-starter-monitoring/src/main/java/hm/binkley/spring/axon/SpringBootAuditLogger.java
// public static final String MESSAGE_TYPE = inNamespace("message-type");
// 
// Path: axon-spring-boot-starter-monitoring/src/main/java/hm/binkley/spring/axon/SpringBootAuditLogger.java
// public static final String RETURN_VALUE = inNamespace("return-value");


import hm.binkley.spring.axon.shared.TestAuditEventRepository;
import org.axonframework.commandhandling.gateway.CommandGateway;
import org.axonframework.domain.GenericDomainEventMessage;
import org.axonframework.eventhandling.Cluster;
import org.junit.After;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.audit.AuditEvent;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import java.util.Map;
import static hm.binkley.spring.axon.AxonCommandAuditEvent.AXON_COMMAND_AUDIT_TYPE;
import static hm.binkley.spring.axon.AxonEventAuditEvent.AXON_EVENT_AUDIT_TYPE;
import static hm.binkley.spring.axon.SpringBootAuditLogger.FAILURE_CAUSE;
import static hm.binkley.spring.axon.SpringBootAuditLogger.MESSAGE_TYPE;
import static hm.binkley.spring.axon.SpringBootAuditLogger.RETURN_VALUE;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.fail;

    @Test
    public void shouldAuditFailedCommands() {
        final FailedException cause = new FailedException();
        final FailedCommand payload = new FailedCommand(cause);
        commands.send(payload);

        assertThat(trail.received()).
                isEqualTo(1);
        final AuditEvent auditEvent = trail.eventAt(0);
        assertThat(auditEvent.getType()).
                isEqualTo(AXON_COMMAND_AUDIT_TYPE);
        final Map<String, Object> data = auditEvent.getData();
        assertThat(data.get(MESSAGE_TYPE)).
                isEqualTo(payload.getClass().getName());
        assertThat(data.get(RETURN_VALUE)).
                isNull();
        assertThat(data.get(FAILURE_CAUSE)).
                isSameAs(cause);
    }

    @Test
    public void shouldAuditSuccessfulEvents() {
        final SuccessfulEvent payload = new SuccessfulEvent();
        events.publish(new GenericDomainEventMessage<>("abc", 1L, payload));

        assertThat(trail.received()).
                isEqualTo(1);
        final AuditEvent auditEvent = trail.eventAt(0);
        assertThat(auditEvent.getType()).
// Path: axon-spring-boot-starter-monitoring/src/test/java/hm/binkley/spring/axon/shared/TestAuditEventRepository.java
// public class TestAuditEventRepository
//         implements AuditEventRepository {
//     private final List<AuditEvent> trail = new ArrayList<>();
// 
//     @Override
//     public List<AuditEvent> find(final String principal, final Date after) {
//         throw new UnsupportedOperationException();
//     }
// 
//     @Override
//     public void add(final AuditEvent event) {
//         trail.add(event);
//     }
// 
//     public void reset() {
//         trail.clear();
//     }
// 
//     public int received() {
//         return trail.size();
//     }
// 
//     public AuditEvent eventAt(final int sequence) {
//         return trail.get(sequence);
//     }
// }
// 
// Path: axon-spring-boot-starter-monitoring/src/main/java/hm/binkley/spring/axon/AxonCommandAuditEvent.java
// public static final String AXON_COMMAND_AUDIT_TYPE = CommandMessage.class
//         .getName();
// 
// Path: axon-spring-boot-starter-monitoring/src/main/java/hm/binkley/spring/axon/AxonEventAuditEvent.java
// public static final String AXON_EVENT_AUDIT_TYPE = EventMessage.class
//         .getName();
// 
// Path: axon-spring-boot-starter-monitoring/src/main/java/hm/binkley/spring/axon/SpringBootAuditLogger.java
// public static final String FAILURE_CAUSE = inNamespace("failure-cause");
// 
// Path: axon-spring-boot-starter-monitoring/src/main/java/hm/binkley/spring/axon/SpringBootAuditLogger.java
// public static final String MESSAGE_TYPE = inNamespace("message-type");
// 
// Path: axon-spring-boot-starter-monitoring/src/main/java/hm/binkley/spring/axon/SpringBootAuditLogger.java
// public static final String RETURN_VALUE = inNamespace("return-value");


// Path: axon-spring-boot-starter-monitoring/src/test/java/hm/binkley/spring/axon/audit/AuditIT.java
import hm.binkley.spring.axon.shared.TestAuditEventRepository;
import org.axonframework.commandhandling.gateway.CommandGateway;
import org.axonframework.domain.GenericDomainEventMessage;
import org.axonframework.eventhandling.Cluster;
import org.junit.After;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.audit.AuditEvent;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import java.util.Map;
import static hm.binkley.spring.axon.AxonCommandAuditEvent.AXON_COMMAND_AUDIT_TYPE;
import static hm.binkley.spring.axon.AxonEventAuditEvent.AXON_EVENT_AUDIT_TYPE;
import static hm.binkley.spring.axon.SpringBootAuditLogger.FAILURE_CAUSE;
import static hm.binkley.spring.axon.SpringBootAuditLogger.MESSAGE_TYPE;
import static hm.binkley.spring.axon.SpringBootAuditLogger.RETURN_VALUE;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.fail;


    @Test
    public void shouldAuditFailedCommands() {
        final FailedException cause = new FailedException();
        final FailedCommand payload = new FailedCommand(cause);
        commands.send(payload);

        assertThat(trail.received()).
                isEqualTo(1);
        final AuditEvent auditEvent = trail.eventAt(0);
        assertThat(auditEvent.getType()).
                isEqualTo(AXON_COMMAND_AUDIT_TYPE);
        final Map<String, Object> data = auditEvent.getData();
        assertThat(data.get(MESSAGE_TYPE)).
                isEqualTo(payload.getClass().getName());
        assertThat(data.get(RETURN_VALUE)).
                isNull();
        assertThat(data.get(FAILURE_CAUSE)).
                isSameAs(cause);
    }

    @Test
    public void shouldAuditSuccessfulEvents() {
        final SuccessfulEvent payload = new SuccessfulEvent();
        events.publish(new GenericDomainEventMessage<>("abc", 1L, payload));

        assertThat(trail.received()).
                isEqualTo(1);
        final AuditEvent auditEvent = trail.eventAt(0);
        assertThat(auditEvent.getType()).
                isEqualTo(AXON_EVENT_AUDIT_TYPE);