-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: trying to use an external Nakadi mock
- Loading branch information
Showing
7 changed files
with
135 additions
and
14 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
73 changes: 73 additions & 0 deletions
73
...ot-2-test/src/test/java/org/zalando/nakadiproducer/tests/ApplicationWithMockNakadiIT.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,73 @@ | ||
package org.zalando.nakadiproducer.tests; | ||
|
||
import org.junit.BeforeClass; | ||
import org.junit.ClassRule; | ||
import org.junit.Test; | ||
import org.junit.contrib.java.lang.system.EnvironmentVariables; | ||
import org.junit.runner.RunWith; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.actuate.autoconfigure.web.server.LocalManagementPort; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.test.context.ContextConfiguration; | ||
import org.springframework.test.context.junit4.SpringRunner; | ||
import org.zalando.nakadi_mock.EventSubmissionCallback.CollectingCallback; | ||
import org.zalando.nakadi_mock.NakadiMock; | ||
import org.zalando.nakadiproducer.tests.Application.Data; | ||
import org.zalando.nakadiproducer.transmission.impl.EventTransmitter; | ||
|
||
import java.io.File; | ||
import java.util.List; | ||
|
||
import static io.restassured.RestAssured.given; | ||
import static org.hamcrest.Matchers.hasSize; | ||
import static org.junit.Assert.assertThat; | ||
|
||
@RunWith(SpringRunner.class) | ||
@SpringBootTest( | ||
// This line looks like that by intention: We want to test that the MockNakadiPublishingClient will be picked up | ||
// by our starter *even if* it has been defined *after* the application itself. This has been a problem until | ||
// this commit. | ||
classes = { MockNakadiServerConfig.class, Application.class }, | ||
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT | ||
) | ||
@ContextConfiguration(initializers=MockNakadiServerConfig.MockPropertyInitializer.class) | ||
public class ApplicationWithMockNakadiIT { | ||
@LocalManagementPort | ||
private int localManagementPort; | ||
|
||
@ClassRule | ||
public static final EnvironmentVariables environmentVariables | ||
= new EnvironmentVariables(); | ||
|
||
@BeforeClass | ||
public static void fakeCredentialsDir() { | ||
environmentVariables.set("CREDENTIALS_DIR", new File("src/test/resources/tokens").getAbsolutePath()); | ||
} | ||
|
||
@Autowired | ||
EventTransmitter transmitter; | ||
|
||
@Autowired | ||
NakadiMock nakadiMock; | ||
|
||
@Test | ||
public void shouldSuccessfullyStartAndSnapshotCanBeTriggered() throws InterruptedException { | ||
CollectingCallback<Application.Data> collector = new CollectingCallback<Application.Data>() {}; | ||
nakadiMock.eventType("eventtype").setSubmissionCallback(collector); | ||
|
||
given().baseUri("http://localhost:" + localManagementPort) | ||
.contentType("application/json") | ||
.body("{'filter':'Example filter'}".replace('\'', '"')) | ||
.when().post("/actuator/snapshot-event-creation/eventtype") | ||
.then().statusCode(204); | ||
|
||
Thread.sleep(500); | ||
|
||
transmitter.sendEvents(); | ||
|
||
Thread.sleep(500); | ||
|
||
List<Data> events = collector.getSubmittedEvents(); | ||
assertThat(events, hasSize(2)); | ||
} | ||
} |
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
34 changes: 34 additions & 0 deletions
34
...ng-boot-2-test/src/test/java/org/zalando/nakadiproducer/tests/MockNakadiServerConfig.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,34 @@ | ||
package org.zalando.nakadiproducer.tests; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.boot.test.util.TestPropertyValues; | ||
import org.springframework.context.ApplicationContextInitializer; | ||
import org.springframework.context.ConfigurableApplicationContext; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.zalando.nakadi_mock.NakadiMock; | ||
|
||
import java.net.URL; | ||
|
||
@Configuration | ||
public class MockNakadiServerConfig { | ||
|
||
static class MockPropertyInitializer implements ApplicationContextInitializer<ConfigurableApplicationContext>{ | ||
|
||
private static final Logger LOG = LoggerFactory.getLogger(MockPropertyInitializer.class); | ||
|
||
@Override | ||
public void initialize(ConfigurableApplicationContext context) { | ||
// TODO: setup NakadiMock, inject URL into nakadi-producer | ||
|
||
NakadiMock mock = NakadiMock.make(); | ||
context.getBeanFactory().registerSingleton("nakadiMock", mock); | ||
mock.start(); | ||
URL url = mock.getRootUrl(); | ||
|
||
LOG.info("started mock nakadi on {}", url); | ||
|
||
TestPropertyValues.of("nakadi-producer.nakadi-base-url="+url).applyTo(context); | ||
} | ||
} | ||
} |
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