-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
#44 flow id sending
- Loading branch information
Showing
6 changed files
with
79 additions
and
6 deletions.
There are no files selected for viewing
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
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
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
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
64 changes: 64 additions & 0 deletions
64
...r/src/test/java/org/zalando/nakadiproducer/transmission/impl/TransmissionServiceTest.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package org.zalando.nakadiproducer.transmission.impl; | ||
|
||
import static com.jayway.jsonpath.Criteria.where; | ||
import static com.jayway.jsonpath.JsonPath.read; | ||
import static java.time.Instant.now; | ||
import static org.hamcrest.Matchers.empty; | ||
import static org.hamcrest.Matchers.hasSize; | ||
import static org.hamcrest.Matchers.is; | ||
import static org.junit.Assert.assertThat; | ||
import static org.mockito.Mockito.mock; | ||
|
||
import java.util.List; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.zalando.nakadiproducer.eventlog.impl.EventLog; | ||
import org.zalando.nakadiproducer.eventlog.impl.EventLogRepository; | ||
import org.zalando.nakadiproducer.transmission.MockNakadiPublishingClient; | ||
import org.zalando.nakadiproducer.util.Fixture; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
||
public class TransmissionServiceTest { | ||
|
||
private EventTransmissionService service; | ||
private EventLogRepository repo; | ||
private MockNakadiPublishingClient publishingClient; | ||
private ObjectMapper mapper; | ||
|
||
@Before | ||
public void setUp() { | ||
repo = mock(EventLogRepository.class); | ||
publishingClient = new MockNakadiPublishingClient(); | ||
mapper = new ObjectMapper(); | ||
service = new EventTransmissionService(repo, publishingClient, mapper); | ||
} | ||
|
||
@Test | ||
public void testWithFlowId() throws JsonProcessingException { | ||
String flowId = "XYZ"; | ||
String payloadString = mapper.writeValueAsString(Fixture.mockPayload(42, "bla")); | ||
EventLog ev = new EventLog(27, "type", payloadString, flowId, now(), now(), null, null); | ||
|
||
service.sendEvent(ev); | ||
|
||
List<String> events = publishingClient.getSentEvents("type"); | ||
assertThat(events, hasSize(1)); | ||
assertThat(read(events.get(0), "$.metadata.flow_id"), is(flowId)); | ||
} | ||
|
||
@Test | ||
public void testWithoutFlowId() throws JsonProcessingException { | ||
String payloadString = mapper.writeValueAsString(Fixture.mockPayload(42, "bla")); | ||
EventLog ev = new EventLog(27, "type", payloadString, null, now(), now(), null, null); | ||
|
||
service.sendEvent(ev); | ||
|
||
List<String> events = publishingClient.getSentEvents("type"); | ||
assertThat(events, hasSize(1)); | ||
assertThat(read(events.get(0), "$.metadata.[?]", where("flow_id").exists(true)), is(empty())); | ||
} | ||
|
||
} |
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