top.infra.test.containers.GenericContainerInitializer Maven / Gradle / Ivy
The newest version!
package top.infra.test.containers;
import com.google.common.collect.Maps;
import lombok.SneakyThrows;
import org.springframework.context.ApplicationContextInitializer;
import org.springframework.context.ConfigurableApplicationContext;
import org.testcontainers.containers.GenericContainer;
import java.util.Map;
import java.util.Map.Entry;
import java.util.function.BiFunction;
public class GenericContainerInitializer implements ApplicationContextInitializer {
private static final Map> //
containers = Maps.newLinkedHashMap();
public static void onInitialize(
final GenericContainer container, //
final BiFunction callback //
) {
containers.put(container, callback);
}
@SneakyThrows
@Override
public void initialize(final ConfigurableApplicationContext applicationContext) {
for (final Entry> entry :
containers.entrySet()) {
final GenericContainer container = entry.getKey();
if (container.getContainerId() != null) {
final BiFunction callback = entry.getValue();
callback.apply(container, applicationContext);
}
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy