package se.citerus.dddsample.scenario;
import junit.framework.TestCase;
import se.citerus.dddsample.application.ApplicationEvents;
import se.citerus.dddsample.application.BookingService;
import se.citerus.dddsample.application.CargoInspectionService;
import se.citerus.dddsample.application.HandlingEventService;
import se.citerus.dddsample.application.impl.BookingServiceImpl;
import se.citerus.dddsample.application.impl.CargoInspectionServiceImpl;
import se.citerus.dddsample.application.impl.HandlingEventServiceImpl;
import static se.citerus.dddsample.application.util.DateTestUtil.toDate;
import se.citerus.dddsample.domain.model.cargo.*;
import static se.citerus.dddsample.domain.model.cargo.RoutingStatus.*;
import static se.citerus.dddsample.domain.model.cargo.TransportStatus.*;
import se.citerus.dddsample.domain.model.handling.CannotCreateHandlingEventException;
import static se.citerus.dddsample.domain.model.handling.HandlingEvent.Type.*;
import se.citerus.dddsample.domain.model.handling.HandlingEventFactory;
import se.citerus.dddsample.domain.model.handling.HandlingEventRepository;
import se.citerus.dddsample.domain.model.location.Location;
import se.citerus.dddsample.domain.model.location.LocationRepository;
import static se.citerus.dddsample.domain.model.location.SampleLocations.*;
import se.citerus.dddsample.domain.model.location.UnLocode;
import static se.citerus.dddsample.domain.model.voyage.SampleVoyages.*;
import static se.citerus.dddsample.domain.model.voyage.Voyage.NONE;
import se.citerus.dddsample.domain.model.voyage.VoyageNumber;
import se.citerus.dddsample.domain.model.voyage.VoyageRepository;
import se.citerus.dddsample.domain.service.RoutingService;
import se.citerus.dddsample.infrastructure.messaging.stub.SynchronousApplicationEventsStub;
import se.citerus.dddsample.infrastructure.persistence.inmemory.CargoRepositoryInMem;
import se.citerus.dddsample.infrastructure.persistence.inmemory.HandlingEventRepositoryInMem;
import se.citerus.dddsample.infrastructure.persistence.inmemory.LocationRepositoryInMem;
import se.citerus.dddsample.infrastructure.persistence.inmemory.VoyageRepositoryInMem;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
public class CargoLifecycleScenarioTest extends TestCase {
/**
* Repository implementations are part of the infrastructure layer,
* which in this test is stubbed out by in-memory replacements.
*/
HandlingEventRepository handlingEventRepository;
CargoRepository cargoRepository;
LocationRepository locationRepository;
VoyageRepository voyageRepository;
/**
* This interface is part of the application layer,
* and defines a number of events that occur during
* aplication execution. It is used for message-driving
* and is implemented using JMS.
*
* In this test it is stubbed with synchronous calls.
*/
ApplicationEvents applicationEvents;
/**
* These three components all belong to the application layer,
* and map against use cases of the application. The "real"
* implementations are used in this lifecycle test,
* but wired with stubbed infrastructure.
*/
BookingService bookingService;
HandlingEventService handlingEventService;
CargoInspectionService cargoInspectionService;
/**
* This factory is part of the handling aggregate and belongs to
* the domain layer. Similar to the application layer components,
* the "real" implementation is used here too,
* wired with stubbed infrastructure.
*/
HandlingEventFactory handlingEventFactory;
/**
* This is a domain service interface, whose implementation
* is part of the infrastructure layer (remote call to external system).
*
* It is stubbed in this test.
*/
RoutingService routingService;
public void testCargoFromHongkongToStockholm() throws Exception {
/* Test setup: A cargo should be shipped from Hongkong to Stockholm,
and it should arrive in no more than two weeks. */
Location origin = HONGKONG;
Location destination = STOCKHOLM;
Date arrivalDeadline = toDate("2009-03-18");
/* Use case 1: booking
A new cargo is booked, and the unique tracking id is assigned to the cargo. */
TrackingId trackingId = bookingService.bookNewCargo(
origin.unLocode(), destination.unLocode(), arrivalDeadline
);
/* The tracking id can be used to lookup the cargo in the repository.
Important: The cargo, and thus the domain model, is responsible for determining
the status of the cargo, whether it is on the right track or not and so on.
This is core domain logic.
Tracking the cargo basically amounts to presenting information extracted from
the cargo aggregate in a suitable way. */
Cargo cargo = cargoRepository.find(trackingId);
assertNotNull(cargo);
assertEquals(NOT_RECEIVED, cargo.delivery().transportStatus());
assertEquals(NOT_ROUTED, cargo.delivery().routingStatus());
assertFalse(cargo.delivery().isMisdirected());
assertNull(cargo.delivery().estimatedTimeOfArrival());
assertNull(cargo.delivery().nextExpectedActivity());
/* Use case 2: routing
A number of possible routes for this cargo is requested and may be
presented to the customer in some way for him/her to choose from.
Selection could be affected by things like price and time of delivery,
but this test simply uses an arbitrary selection to mimic that process.
The cargo is then assigned to the selected route, described by an itinerary. */
List<Itinerary> itineraries = bookingService.requestPossibleRoutesForCargo(trackingId);
Itinerary itinerary = selectPreferedItinerary(itineraries);
cargo.assignToRoute(itinerary);
assertEquals(NOT_RECEIVED, cargo.delivery().transportStatus());
assertEquals(ROUTED, cargo.delivery().routingStatus());
assertNotNull(cargo.delivery().estimatedTimeOfArrival());
assertEquals(new HandlingActivity(RECEIVE, HONGKONG), cargo.delivery().nextExpectedActivity());
/*
Use case 3: handling
A handling event registration attempt will be formed from parsing
the data coming in as a handling report either via
the web service interface or as an uploaded CSV file.
The handling event factory tries to create a HandlingEvent from the attempt,
and if the factory decides that this is a plausible handling event, it is stored.
If the attempt is invalid, for example if no cargo exists for the specfied tracking id,
the attempt is rejected.
Handling begins: cargo is received in Hongkong.
*/
handlingEventService.registerHandlingEvent(
toDate("2009-03-01"), trackingId, null, HONGKONG.unLocode(), RECEIVE
);
assertEquals(IN_PORT, cargo.delivery().transportStatus());
assertEquals(HONGKONG, cargo.delivery().lastKnownLocation());
// Next event: Load onto voyage CM003 in Hongkong
handlingEventService.registerHandlingEvent(
toDate("2009-03-03"), trackingId, v100.voyageNumber(), HONGKONG.unLocode(), LOAD
);
// Check current state - should be ok
assertEquals(v100, cargo.delivery().currentVoyage());
assertEquals(HONGKONG, cargo.delivery().lastKnownLocation());
assertEquals(ONBOARD_CARRIER, cargo.delivery().transportStatus());
assertFalse(cargo.delivery().isMisdirected());
assertEquals(new HandlingActivity(UNLOAD, NEWYORK, v100), cargo.delivery().nextExpectedActivity());
/*
Here's an attempt to register a handling event that's not valid
because there is no voyage with the specified voyage number,
and there's no location with the specified UN Locode either.
This attempt will be rejected and will not affect the cargo delivery in any way.
*/
final VoyageNumber noSuchVoyageNumber = new VoyageNumber("XX000");
final UnLocode noSuchUnLocode = new UnLocode("ZZZZZ");
try {
handlingEventService.registerHandlingEvent(
toDate("2009-03-05"), track
没有合适的资源?快使用搜索试试~ 我知道了~
dddsample 领域模型驱动事例 DDD
共239个文件
java:142个
html:28个
xml:22个
5星 · 超过95%的资源 需积分: 34 22 下载量 27 浏览量
2010-03-22
10:12:12
上传
评论
收藏 615KB ZIP 举报
温馨提示
领域模型驱动事例 DDD 想要从事开发设计的快下,解决贫血型设计的经典源代码
资源推荐
资源详情
资源评论
收起资源包目录
dddsample 领域模型驱动事例 DDD (239个子文件)
characterization.apt 12KB
download.apt 5KB
architecture.apt 3KB
index.apt 3KB
patterns-reference.apt 2KB
changelog.apt 1KB
roadmap.apt 465B
handlingEventRegistration.apt 113B
style.css 4KB
calendar.css 1KB
admin.css 599B
site.css 0B
handling_events.csv 168B
calendarTrigger.gif 1KB
package.html 3KB
package.html 600B
package.html 467B
package.html 440B
package.html 254B
package.html 241B
package.html 231B
package.html 152B
package.html 132B
package.html 124B
package.html 103B
package.html 102B
package.html 101B
package.html 97B
package.html 97B
package.html 96B
package.html 95B
package.html 92B
package.html 92B
package.html 90B
package.html 86B
package.html 84B
package.html 83B
package.html 83B
package.html 80B
package.html 70B
package.html 59B
package.html 56B
CargoLifecycleScenarioTest.java 15KB
SampleDataGenerator.java 14KB
CargoTest.java 14KB
Delivery.java 10KB
HandlingEvent.java 7KB
Cargo.java 7KB
CargoRepositoryTest.java 6KB
CargoTrackingViewAdapter.java 6KB
CargoAdminController.java 6KB
SampleVoyages.java 5KB
UploadDirectoryScanner.java 5KB
BookingServiceFacadeImpl.java 5KB
HandlingEventFactoryTest.java 5KB
HandlingReport.java 4KB
HandlingEventTest.java 4KB
ItineraryTest.java 4KB
Itinerary.java 4KB
CargoTrackingControllerTest.java 4KB
ExternalRoutingService.java 4KB
ObjectFactory.java 3KB
BookingServiceImpl.java 3KB
ItineraryCandidateDTOAssemblerTest.java 3KB
HandlingEventFactory.java 3KB
JmsApplicationEventsImpl.java 3KB
CargoRepositoryInMem.java 3KB
DeliveryTest.java 3KB
CargoTrackingController.java 3KB
ExternalRoutingServiceTest.java 3KB
RouteSpecification.java 3KB
HandlingReportServiceImpl.java 3KB
CarrierMovement.java 3KB
GraphTraversalServiceImpl.java 3KB
CargoTrackingViewAdapterTest.java 3KB
HandlingEventServiceImpl.java 3KB
HandlingEventServiceTest.java 3KB
HandlingReportParser.java 3KB
Voyage.java 3KB
AbstractRepositoryTest.java 3KB
ItineraryCandidateDTOAssembler.java 3KB
HandlingActivity.java 2KB
HandlingReportServiceService.java 2KB
RouteSpecificationTest.java 2KB
HandlingEventRepositoryTest.java 2KB
Leg.java 2KB
HandlingHistory.java 2KB
CargoRoutingDTOAssemblerTest.java 2KB
HandlingEventRegistrationAttempt.java 2KB
CargoInspectionServiceImpl.java 2KB
SampleLocations.java 2KB
Location.java 2KB
EntitySupport.java 2KB
BookingServiceTest.java 2KB
EntitySupportTest.java 2KB
CarrierMovementTest.java 2KB
HandlingHistoryTest.java 2KB
UnLocode.java 2KB
RouteAssignmentCommand.java 2KB
ValueObjectSupport.java 2KB
共 239 条
- 1
- 2
- 3
资源评论
- lyai0072014-08-07还没有看呢,下下来又不会看了
- lawbc2014-08-23正打算看呢
- LeftyYL2015-04-28东西应该没问题,看了一遍,云里雾里的
duzunwu512
- 粉丝: 0
- 资源: 15
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功