2019-10-22 07:15:35 +02:00
|
|
|
/*
|
2017-08-19 22:06:35 +03:00
|
|
|
* The MIT License
|
2019-10-12 20:05:54 +03:00
|
|
|
* Copyright © 2014-2019 Ilkka Seppälä
|
2017-08-19 22:06:35 +03:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
2019-10-22 07:15:35 +02:00
|
|
|
|
2019-12-09 22:33:30 +05:30
|
|
|
import static com.iluwatar.event.sourcing.app.App.ACCOUNT_OF_DAENERYS;
|
|
|
|
import static com.iluwatar.event.sourcing.app.App.ACCOUNT_OF_JON;
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
|
|
|
2017-09-02 21:52:02 +03:00
|
|
|
import com.iluwatar.event.sourcing.event.AccountCreateEvent;
|
|
|
|
import com.iluwatar.event.sourcing.event.MoneyDepositEvent;
|
|
|
|
import com.iluwatar.event.sourcing.event.MoneyTransferEvent;
|
2017-08-19 22:06:35 +03:00
|
|
|
import com.iluwatar.event.sourcing.processor.DomainEventProcessor;
|
|
|
|
import com.iluwatar.event.sourcing.state.AccountAggregate;
|
|
|
|
import java.math.BigDecimal;
|
2017-09-02 21:52:02 +03:00
|
|
|
import java.util.Date;
|
2019-12-09 22:33:30 +05:30
|
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
|
|
import org.junit.jupiter.api.Test;
|
2017-08-19 22:06:35 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Intergartion Test for Event Sourcing state recovery
|
2019-12-09 22:33:30 +05:30
|
|
|
* <p>
|
2017-08-19 22:06:35 +03:00
|
|
|
* Created by Serdar Hamzaogullari on 19.08.2017.
|
|
|
|
*/
|
|
|
|
public class IntegrationTest {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The Domain event processor.
|
|
|
|
*/
|
2017-09-02 21:52:02 +03:00
|
|
|
private DomainEventProcessor eventProcessor;
|
2017-08-19 22:06:35 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialize.
|
|
|
|
*/
|
2017-12-31 16:29:48 +09:00
|
|
|
@BeforeEach
|
2017-08-19 22:06:35 +03:00
|
|
|
public void initialize() {
|
2017-09-02 21:52:02 +03:00
|
|
|
eventProcessor = new DomainEventProcessor();
|
2017-08-19 22:06:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test state recovery.
|
|
|
|
*/
|
|
|
|
@Test
|
|
|
|
public void testStateRecovery() {
|
2017-09-02 21:52:02 +03:00
|
|
|
eventProcessor.reset();
|
|
|
|
|
|
|
|
eventProcessor.process(new AccountCreateEvent(
|
|
|
|
0, new Date().getTime(), ACCOUNT_OF_DAENERYS, "Daenerys Targaryen"));
|
2017-08-19 22:06:35 +03:00
|
|
|
|
2017-09-02 21:52:02 +03:00
|
|
|
eventProcessor.process(new AccountCreateEvent(
|
|
|
|
1, new Date().getTime(), ACCOUNT_OF_JON, "Jon Snow"));
|
2017-08-19 22:06:35 +03:00
|
|
|
|
2017-09-02 21:52:02 +03:00
|
|
|
eventProcessor.process(new MoneyDepositEvent(
|
2019-12-09 22:33:30 +05:30
|
|
|
2, new Date().getTime(), ACCOUNT_OF_DAENERYS, new BigDecimal("100000")));
|
2017-08-19 22:06:35 +03:00
|
|
|
|
2017-09-02 21:52:02 +03:00
|
|
|
eventProcessor.process(new MoneyDepositEvent(
|
2019-12-09 22:33:30 +05:30
|
|
|
3, new Date().getTime(), ACCOUNT_OF_JON, new BigDecimal("100")));
|
2017-09-02 21:52:02 +03:00
|
|
|
|
|
|
|
eventProcessor.process(new MoneyTransferEvent(
|
|
|
|
4, new Date().getTime(), new BigDecimal("10000"), ACCOUNT_OF_DAENERYS,
|
|
|
|
ACCOUNT_OF_JON));
|
2017-08-19 22:06:35 +03:00
|
|
|
|
2019-12-09 22:33:30 +05:30
|
|
|
var accountOfDaenerysBeforeShotDown = AccountAggregate.getAccount(ACCOUNT_OF_DAENERYS);
|
|
|
|
var accountOfJonBeforeShotDown = AccountAggregate.getAccount(ACCOUNT_OF_JON);
|
2017-08-19 22:06:35 +03:00
|
|
|
|
|
|
|
AccountAggregate.resetState();
|
|
|
|
|
2017-09-02 21:52:02 +03:00
|
|
|
eventProcessor = new DomainEventProcessor();
|
|
|
|
eventProcessor.recover();
|
2017-08-19 22:06:35 +03:00
|
|
|
|
2019-12-09 22:33:30 +05:30
|
|
|
var accountOfDaenerysAfterShotDown = AccountAggregate.getAccount(ACCOUNT_OF_DAENERYS);
|
|
|
|
var accountOfJonAfterShotDown = AccountAggregate.getAccount(ACCOUNT_OF_JON);
|
2017-08-19 22:06:35 +03:00
|
|
|
|
2017-12-31 16:29:48 +09:00
|
|
|
assertEquals(accountOfDaenerysBeforeShotDown.getMoney(),
|
2017-08-19 22:06:35 +03:00
|
|
|
accountOfDaenerysAfterShotDown.getMoney());
|
2017-12-31 16:29:48 +09:00
|
|
|
assertEquals(accountOfJonBeforeShotDown.getMoney(), accountOfJonAfterShotDown.getMoney());
|
2017-08-19 22:06:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|