-
Notifications
You must be signed in to change notification settings - Fork 859
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #160 from nsteps/test-containres-feature
Add test containers
- Loading branch information
Showing
5 changed files
with
97 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package kafdrop; | ||
|
||
import org.junit.runner.RunWith; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.context.ApplicationContextInitializer; | ||
import org.springframework.context.ConfigurableApplicationContext; | ||
import org.springframework.core.env.MapPropertySource; | ||
import org.springframework.test.context.ContextConfiguration; | ||
import org.springframework.test.context.junit4.SpringRunner; | ||
import org.testcontainers.containers.KafkaContainer; | ||
import org.testcontainers.lifecycle.Startables; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
@RunWith(SpringRunner.class) | ||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) | ||
@ContextConfiguration(initializers = AbstractIntegrationTest.Initializer.class) | ||
abstract class AbstractIntegrationTest { | ||
static class Initializer implements ApplicationContextInitializer<ConfigurableApplicationContext> { | ||
static KafkaContainer kafka = new KafkaContainer(); | ||
|
||
public static Map<String, String> getProperties() { | ||
Startables.deepStart(List.of(kafka)).join(); | ||
return Map.of("kafka.brokerConnect", kafka.getBootstrapServers()); | ||
} | ||
|
||
@Override | ||
@SuppressWarnings("unchecked, rawtypes") | ||
public void initialize(ConfigurableApplicationContext context) { | ||
var env = context.getEnvironment(); | ||
env.getPropertySources().addFirst(new MapPropertySource( | ||
"testcontainers", (Map) getProperties() | ||
)); | ||
} | ||
} | ||
} |
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,8 @@ | ||
package kafdrop; | ||
|
||
import org.junit.Test; | ||
|
||
public class KafdropTest extends AbstractIntegrationTest { | ||
@Test | ||
public void contextTest(){} | ||
} |
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,13 @@ | ||
package kafdrop; | ||
|
||
/** | ||
* Use this class for local development. | ||
* It will run local kafka in docker with test containers. | ||
*/ | ||
public class LocalRunner { | ||
public static void main(String[] args) { | ||
Kafdrop.createApplicationBuilder() | ||
.initializers(new AbstractIntegrationTest.Initializer()) | ||
.run(args); | ||
} | ||
} |