Giter Site home page Giter Site logo

axon-cqrs-demo's Introduction

๐Ÿ‘‹ Hi I'm Juntao, I help people write better code.

I love the feeling of convert messy code into something more readable and maintainable, and I also enjoy the feeling of teach other to do so.

@JuntaoQiu

axon-cqrs-demo's People

Contributors

abruzzi avatar

Watchers

 avatar  avatar  avatar

axon-cqrs-demo's Issues

AppConfiguration

@Configuration
public class AppConfiguration {
    @Bean
    public AnnotationEventListenerBeanPostProcessor annotationEventListenerBeanPostProcessor() {
        AnnotationEventListenerBeanPostProcessor processor = new AnnotationEventListenerBeanPostProcessor();
        processor.setEventBus(eventBus());
        return processor;
    }

    @Bean
    public AnnotationCommandHandlerBeanPostProcessor annotationCommandHandlerBeanPostProcessor() {
        AnnotationCommandHandlerBeanPostProcessor processor = new AnnotationCommandHandlerBeanPostProcessor();
        processor.setCommandBus(commandBus());
        return processor;
    }

    @Bean
    public CommandBus commandBus() {
        SimpleCommandBus commandBus = new SimpleCommandBus();
        commandBus.setHandlerInterceptors(Arrays.asList(new BeanValidationInterceptor()));
        return commandBus;
    }

    @Bean
    public DefaultCommandGateway commandGateway() {
        return new DefaultCommandGateway(commandBus());
    }

    @Bean
    public EventBus eventBus() {
        return new SimpleEventBus();
    }

    @Bean
    public Repository<License> eventSourcingRepository() {
        FileSystemEventStore eventStore = new FileSystemEventStore(new SimpleEventFileResolver(new File("data/evenstore")));

        EventSourcingRepository<License> eventSourcingRepository = new EventSourcingRepository<>(License.class, eventStore);
        eventSourcingRepository.setEventBus(eventBus());

        return eventSourcingRepository;
    }

    @Bean
    public AggregateAnnotationCommandHandler<License> licenseCommandHandler() {
        return AggregateAnnotationCommandHandler.subscribe(License.class, eventSourcingRepository(), commandBus());
    }
}

LicenseTest

public class LicenseTest {
    private FixtureConfiguration fixture;

    @Before
    public void setUp() throws Exception {
        fixture = Fixtures.newGivenWhenThenFixture(License.class);
    }

    @Test
    public void import_license_command_and_event() throws Exception {
        fixture.given()
                .when(new ImportLicenseCommand("004c97", "desc"))
                .expectEvents(new LicenseImportedEvent("004c97", "desc"));
    }

    @Test
    public void import_license_and_activate_it() {
        fixture.given(new LicenseImportedEvent("004c97", "desc"))
                .when(new ActivateLicenseCommand("004c97"))
                .expectEvents(new LicenseActivatedEvent("004c97"));
    }

    @Test
    public void deactivate_license_after_activate() {
        fixture.given(Arrays.asList(new LicenseImportedEvent("004c97", "desc"), new LicenseActivatedEvent("004c97")))
                .when(new DeactivateLicenseCommand("004c97"))
                .expectEvents(new LicenseDeactivatedEvent("004c97"));
    }
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.