-
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.
Make the test with a mocked server actually work
- Loading branch information
Showing
4 changed files
with
49 additions
and
53 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
34 changes: 0 additions & 34 deletions
34
...ng-boot-2-test/src/test/java/org/zalando/nakadiproducer/tests/MockNakadiServerConfig.java
This file was deleted.
Oops, something went wrong.
33 changes: 33 additions & 0 deletions
33
...ot-2-test/src/test/java/org/zalando/nakadiproducer/tests/NakadiServerMockInitializer.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,33 @@ | ||
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.zalando.nakadi_mock.NakadiMock; | ||
|
||
import java.net.URL; | ||
|
||
|
||
/** | ||
* An application context initializer which sets up a NakadiMock bean and registers the server URL as a property. | ||
*/ | ||
class NakadiServerMockInitializer implements ApplicationContextInitializer<ConfigurableApplicationContext>{ | ||
|
||
private static final Logger LOG = LoggerFactory.getLogger(NakadiServerMockInitializer.class); | ||
|
||
@Override | ||
public void initialize(ConfigurableApplicationContext context) { | ||
// 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-uri="+url).applyTo(context); | ||
} | ||
} |