use of de.flapdoodle.embed.mongo.MongodStarter in project pac4j by pac4j.
the class MongoServer method start.
public void start(final int port) {
MongodStarter starter = MongodStarter.getDefaultInstance();
try {
IMongodConfig mongodConfig = new MongodConfigBuilder().version(Version.Main.PRODUCTION).net(new Net(port, Network.localhostIsIPv6())).build();
mongodExecutable = starter.prepare(mongodConfig);
mongodExecutable.start();
// populate
final MongoClient mongo = new MongoClient("localhost", port);
final MongoDatabase db = mongo.getDatabase("users");
db.createCollection("users");
final MongoCollection<Document> collection = db.getCollection("users");
final String password = PASSWORD_ENCODER.encode(PASSWORD);
Map<String, Object> properties1 = new HashMap<>();
properties1.put(USERNAME, GOOD_USERNAME);
properties1.put(PASSWORD, password);
properties1.put(FIRSTNAME, FIRSTNAME_VALUE);
collection.insertOne(new Document(properties1));
Map<String, Object> properties2 = new HashMap<>();
properties2.put(USERNAME, MULTIPLE_USERNAME);
properties2.put(PASSWORD, password);
collection.insertOne(new Document(properties2));
Map<String, Object> properties3 = new HashMap<>();
properties3.put(USERNAME, MULTIPLE_USERNAME);
properties3.put(PASSWORD, password);
collection.insertOne(new Document(properties3));
} catch (final IOException e) {
throw new RuntimeException(e);
}
}
use of de.flapdoodle.embed.mongo.MongodStarter in project modesti by jlsalmon.
the class MongoConfig method embeddedMongo.
private Mongo embeddedMongo() throws IOException {
int port = 12345;
MongodConfigBuilder builder = new MongodConfigBuilder().version(Version.Main.PRODUCTION).net(new Net(port, Network.localhostIsIPv6()));
if (env.containsProperty("mongodb.persistent") && env.getProperty("mongodb.persistent", Boolean.class).equals(true)) {
builder.replication(new Storage("/tmp/mongodb-embedded", null, 0));
}
IRuntimeConfig runtimeConfig = new RuntimeConfigBuilder().defaultsWithLogger(Command.MongoD, log).processOutput(ProcessOutput.getDefaultInstanceSilent()).build();
MongodStarter runtime = MongodStarter.getInstance(runtimeConfig);
MongodExecutable mongodExecutable = runtime.prepare(builder.build());
mongodExecutable.start();
return new MongoClient("localhost", port);
}
use of de.flapdoodle.embed.mongo.MongodStarter in project spring-boot by spring-projects.
the class EmbeddedMongoAutoConfiguration method embeddedMongoServer.
@Bean(initMethod = "start", destroyMethod = "stop")
@ConditionalOnMissingBean
public MongodExecutable embeddedMongoServer(MongodConfig mongodConfig, RuntimeConfig runtimeConfig, ApplicationContext context) {
Integer configuredPort = this.properties.getPort();
if (configuredPort == null || configuredPort == 0) {
setEmbeddedPort(context, mongodConfig.net().getPort());
}
MongodStarter mongodStarter = getMongodStarter(runtimeConfig);
return mongodStarter.prepare(mongodConfig);
}
Aggregations