flapdoodle-oss / de.flapdoodle.embed.mongo.spring

embedded mongo spring integration
Apache License 2.0
32 stars 7 forks source link

Configuration of download location #26

Closed sticktor closed 1 year ago

sticktor commented 1 year ago

Hey,

my Target is to download the Embedded MongoDB from an internal Source, which is defined in "downloadLocation".

For that I have the following Beans configured: ``@Bean @Primary public MongodWrapper mongodWrapper() { return new MongodWrapper(transitions()); }

@Bean
@Primary
public Mongod mongod()
{
    var mongod = Mongod.builder().distributionBaseUrl(Start.to(DistributionBaseUrl.class).initializedWith(DistributionBaseUrl.of(downloadLocation))).build();
    mongod = mongod.withPersistentBaseDir(Start.to(PersistentDir.class).providedBy(PersistentDir.inWorkingDir(absoluteExtractionPathFromRelative).mapToUncheckedException(RuntimeException::new)));
    return mongod;
}

@Bean
@Primary
public Transitions transitions()
   {
    return Mongod.instance().transitions(Version.V4_0_12).replace(Start.to(DistributionBaseUrl.class).initializedWith(DistributionBaseUrl.of(downloadLocation)));
}`

But when I start my Tests this Library still uses the pre defined Link: Caused by: java.lang.IllegalStateException: could not download https://fastdl.mongodb.org/win32/mongodb-win32-x86_64-2008plus-ssl-4.0.12.zip I cannot install a mongodb on the system, on which the Tests are primarily run.

Simple calling Code from this libraries Documentation: @ExtendWith(SpringExtension.class) @AutoConfiguration @DataMongoTest public class AutoConfigTest { @Test void example(@Autowired MongoTemplate mongoTemplate) { Assertions.assertThat(mongoTemplate.getDb()).isNotNull(); } } With the old library version 3 and Spring Boot 2.7.12 it works. But since the change to Spring Boot 3 and Version 4.7 of Flapdoodle it doesn't anymore.

Hope someone can help.

michaelmosmann commented 1 year ago

@sticktor As there is a lot of stuff happening with this spring integration you may have a look at this example: https://github.com/flapdoodle-oss/de.flapdoodle.embed.mongo.spring/blob/main/HowTo.md#customize-mongod

Some background: the Mongod-Instance holds a set of transitions(rules, configs) which are used when the mongodb ist startet. You can change and customize these rules until the mongodb is startet.. but everything is immutable so you can not just change something.. you will always create a new instance.. with your changes.. thats why you have to use a BeanPostProcessor.

michaelmosmann commented 1 year ago

@sticktor see https://github.com/flapdoodle-oss/de.flapdoodle.embed.mongo.spring/issues/24#issuecomment-1561286088

sticktor commented 1 year ago

Thanks!