CargoTrackingViewAdapterTest.java 3.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. package se.citerus.dddsample.interfaces.tracking;
  2. import junit.framework.TestCase;
  3. import org.springframework.context.support.StaticApplicationContext;
  4. import se.citerus.dddsample.domain.model.cargo.Cargo;
  5. import se.citerus.dddsample.domain.model.cargo.RouteSpecification;
  6. import se.citerus.dddsample.domain.model.cargo.TrackingId;
  7. import se.citerus.dddsample.domain.model.handling.HandlingEvent;
  8. import se.citerus.dddsample.domain.model.handling.HandlingHistory;
  9. import java.util.*;
  10. import static org.assertj.core.api.Assertions.assertThat;
  11. import static se.citerus.dddsample.domain.model.location.SampleLocations.HANGZOU;
  12. import static se.citerus.dddsample.domain.model.location.SampleLocations.HELSINKI;
  13. import static se.citerus.dddsample.domain.model.voyage.SampleVoyages.CM001;
  14. public class CargoTrackingViewAdapterTest extends TestCase {
  15. public void testCreate() {
  16. Cargo cargo = new Cargo(new TrackingId("XYZ"), new RouteSpecification(HANGZOU, HELSINKI, new Date()));
  17. List<HandlingEvent> events = new ArrayList<HandlingEvent>();
  18. events.add(new HandlingEvent(cargo, new Date(1), new Date(2), HandlingEvent.Type.RECEIVE, HANGZOU));
  19. events.add(new HandlingEvent(cargo, new Date(3), new Date(4), HandlingEvent.Type.LOAD, HANGZOU, CM001));
  20. events.add(new HandlingEvent(cargo, new Date(5), new Date(6), HandlingEvent.Type.UNLOAD, HELSINKI, CM001));
  21. cargo.deriveDeliveryProgress(new HandlingHistory(events));
  22. StaticApplicationContext applicationContext = new StaticApplicationContext();
  23. applicationContext.addMessage("cargo.status.IN_PORT", Locale.GERMAN, "In port {0}");
  24. applicationContext.refresh();
  25. CargoTrackingViewAdapter adapter = new CargoTrackingViewAdapter(cargo, applicationContext, Locale.GERMAN, events, TimeZone.getTimeZone("Europe/Stockholm"));
  26. assertThat(adapter.getTrackingId()).isEqualTo("XYZ");
  27. assertThat(adapter.getOrigin()).isEqualTo("Hangzhou");
  28. assertThat(adapter.getDestination()).isEqualTo("Helsinki");
  29. assertThat(adapter.getStatusText()).isEqualTo("In port Helsinki");
  30. Iterator<CargoTrackingViewAdapter.HandlingEventViewAdapter> it = adapter.getEvents().iterator();
  31. CargoTrackingViewAdapter.HandlingEventViewAdapter event = it.next();
  32. assertThat(event.getType()).isEqualTo("RECEIVE");
  33. assertThat(event.getLocation()).isEqualTo("Hangzhou");
  34. assertThat(event.getTime()).isEqualTo("1970-01-01 01:00");
  35. assertThat(event.getVoyageNumber()).isEqualTo("");
  36. assertThat(event.isExpected()).isTrue();
  37. event = it.next();
  38. assertThat(event.getType()).isEqualTo("LOAD");
  39. assertThat(event.getLocation()).isEqualTo("Hangzhou");
  40. assertThat(event.getTime()).isEqualTo("1970-01-01 01:00");
  41. assertThat(event.getVoyageNumber()).isEqualTo("CM001");
  42. assertThat(event.isExpected()).isTrue();
  43. event = it.next();
  44. assertThat(event.getType()).isEqualTo("UNLOAD");
  45. assertThat(event.getLocation()).isEqualTo("Helsinki");
  46. assertThat(event.getTime()).isEqualTo("1970-01-01 01:00");
  47. assertThat(event.getVoyageNumber()).isEqualTo("CM001");
  48. assertThat(event.isExpected()).isTrue();
  49. }
  50. }