Created
August 26, 2015 09:09
-
-
Save cer/e0af5da77e9c6401cf33 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package net.chrisrichardson.getataxi.dispatcher.services; | |
import net.chrisrichardson.getataxi.dispatcher.domain.DispatcherDriver; | |
import net.chrisrichardson.getataxi.dispatcher.domain.DriverMother; | |
import net.chrisrichardson.getataxi.dispatcher.domain.DriverRepository; | |
import net.chrisrichardson.getataxi.domain.Location; | |
import net.chrisrichardson.getataxi.domain.events.DriverAcceptedTripEvent; | |
import net.chrisrichardson.getataxi.domain.events.TripCreatedEvent; | |
import net.chrisrichardson.getataxi.domain.events.TripOfferedToDriver; | |
import net.chrisrichardson.getataxi.domain.events.TripStarted; | |
import net.chrisrichardson.getataxi.events.Event; | |
import net.chrisrichardson.getataxi.events.EventEnvelope; | |
import net.chrisrichardson.getataxi.events.QueueInitializer; | |
import net.chrisrichardson.getataxi.testutil.events.DomainEventTestPublisher; | |
import net.chrisrichardson.getataxi.testutil.events.TestMessageListener; | |
import net.chrisrichardson.getataxi.util.misc.IdGenerator; | |
import org.junit.Assert; | |
import org.junit.Test; | |
import org.junit.runner.RunWith; | |
import org.springframework.beans.factory.annotation.Autowired; | |
import org.springframework.boot.test.IntegrationTest; | |
import org.springframework.boot.test.SpringApplicationConfiguration; | |
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; | |
import static org.junit.Assert.assertEquals; | |
@RunWith(SpringJUnit4ClassRunner.class) | |
@SpringApplicationConfiguration(classes = DispatcherServiceIntegrationTestConfiguration.class) | |
@IntegrationTest | |
public class DispatcherServiceIntegrationTest { | |
{ | |
Assert.assertNotNull(System.getenv("SPRING_DATA_MONGODB_URI")); | |
Assert.assertNotNull(System.getenv("SPRING_RABBITMQ_HOST")); | |
} | |
@Autowired | |
private DomainEventTestPublisher domainEventTestPublisher; | |
@Autowired | |
private TestMessageListener testMessageListener; | |
@Autowired | |
private DriverRepository driverRepository; | |
@Autowired(required=false) | |
private QueueInitializer queueInitializer; | |
@Test | |
public void shouldHandleTripCreatedEvent() { | |
DispatcherDriver driver = DriverMother.makeDriver(); | |
driverRepository.add(driver); | |
String driverId = driver.getId(); | |
Location pickupLocation = driver.getLocation(); | |
String passengerId = IdGenerator.generateId(); | |
Event tripCreatedEvent = new TripCreatedEvent(passengerId, pickupLocation); | |
String tripId = IdGenerator.generateId(); | |
domainEventTestPublisher | |
.publishDomainEvent(tripId, "net.chrisrichardson.getataxi.tripmanagement.domain.Trip", | |
tripCreatedEvent); | |
EventEnvelope<TripOfferedToDriver> offeredEvent = testMessageListener. | |
assertMessagePublished(tripId, TripOfferedToDriver.class); | |
assertEquals(tripId, offeredEvent.getEntityId()); | |
assertEquals(driverId, offeredEvent.getEvent().getDriverId()); | |
domainEventTestPublisher.publishDomainEvent( | |
driverId, "net.chrisrichardson.getataxi.drivermanagement.domain.Driver", | |
new DriverAcceptedTripEvent(tripId)); | |
EventEnvelope<TripStarted> tripStartedEvent = | |
testMessageListener.assertMessagePublished(tripId, TripStarted.class); | |
assertEquals(tripId, tripStartedEvent.getEntityId()); | |
assertEquals(driverId, tripStartedEvent.getEvent().getDriverId()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment