Beispiel #1
0
func (s *service) Track(id string) (Cargo, error) {
	if id == "" {
		return Cargo{}, ErrInvalidArgument
	}
	c, err := s.cargos.Find(cargo.TrackingID(id))
	if err != nil {
		return Cargo{}, err
	}
	return assemble(c, s.handlingEvents), nil
}
Beispiel #2
0
func (s *S) TestInspectUnloadedCargo(c *C) {

	var (
		cargoRepository         = repository.NewInMemcargo()
		handlingEventRepository = repository.NewInMemHandlingEvent()
		cargoEventHandler       = &stubEventHandler{make([]interface{}, 0)}

		inspectionService = &service{
			cargoRepository:         cargoRepository,
			handlingEventRepository: handlingEventRepository,
			cargoEventHandler:       cargoEventHandler,
		}
	)

	trackingID := cargo.TrackingID("ABC123")
	unloadedCargo := cargo.New(trackingID, cargo.RouteSpecification{
		Origin:      location.SESTO,
		Destination: location.CNHKG,
	})

	var voyageNumber voyage.Number = "001A"

	unloadedCargo.AssignToRoute(cargo.Itinerary{Legs: []cargo.Leg{
		{VoyageNumber: voyageNumber, LoadLocation: location.SESTO, UnloadLocation: location.AUMEL},
		{VoyageNumber: voyageNumber, LoadLocation: location.AUMEL, UnloadLocation: location.CNHKG},
	}})

	cargoRepository.Store(unloadedCargo)

	storeEvent(handlingEventRepository, trackingID, voyageNumber, cargo.Receive, location.SESTO)
	storeEvent(handlingEventRepository, trackingID, voyageNumber, cargo.Load, location.SESTO)
	storeEvent(handlingEventRepository, trackingID, voyageNumber, cargo.Unload, location.AUMEL)
	storeEvent(handlingEventRepository, trackingID, voyageNumber, cargo.Load, location.AUMEL)
	storeEvent(handlingEventRepository, trackingID, voyageNumber, cargo.Unload, location.CNHKG)

	c.Check(len(cargoEventHandler.handledEvents), Equals, 0)

	inspectionService.InspectCargo(trackingID)

	c.Check(len(cargoEventHandler.handledEvents), Equals, 1)
}