package com.johnstarich.moviematcher.app;

import com.mongodb.Mongo;
import com.mongodb.MongoClient;
import de.flapdoodle.embed.mongo.Command;
import de.flapdoodle.embed.mongo.MongodExecutable;
import de.flapdoodle.embed.mongo.MongodProcess;
import de.flapdoodle.embed.mongo.MongodStarter;
import de.flapdoodle.embed.mongo.config.*;
import de.flapdoodle.embed.mongo.distribution.Version;
import de.flapdoodle.embed.process.config.IRuntimeConfig;
import de.flapdoodle.embed.process.extract.UserTempNaming;
import de.flapdoodle.embed.process.runtime.Network;
import junit.framework.TestCase;

/**
 * Created by johnstarich on 4/14/16.
 */
public abstract class AbstractMongoDBTest extends TestCase {
	/**
	 * EmbeddedMongo author's note:
	 * please store Starter or RuntimeConfig in a static final field
	 * if you want to use artifact store caching (or else disable caching)
	 */
	private static final MongodStarter starter;
	private static final int MONGO_PORT = 27017;
	private MongodExecutable _mongodExe;
	private MongodProcess _mongod;
	private MongoClient _mongo;

	static {
		Command command = Command.MongoD;

		IRuntimeConfig runtimeConfig = new RuntimeConfigBuilder()
			.defaults(command)
			.artifactStore(new ExtractedArtifactStoreBuilder()
				.defaults(command)
				.download(new DownloadConfigBuilder()
					.defaultsForCommand(command).build())
				.executableNaming(new UserTempNaming()))
			.build();

		starter = MongodStarter.getInstance(runtimeConfig);
	}

	@Override
	protected void setUp() throws Exception {
		_mongodExe = starter.prepare(new MongodConfigBuilder()
				.version(Version.Main.PRODUCTION)
				.net(new Net(MONGO_PORT, Network.localhostIsIPv6()))
				.build());
		_mongod = _mongodExe.start();

		super.setUp();

		_mongo = new MongoClient("localhost", MONGO_PORT);
	}

	@Override
	protected void tearDown() throws Exception {
		super.tearDown();

		_mongod.stop();
		_mongodExe.stop();
	}

	public Mongo getMongo() {
		return _mongo;
	}
}
@@ -478,30 +478,140 @@
 ess.
-extract.UserTempNaming
+config.io.ProcessOutput;%0Aimport de.flapdoodle.embed.process.extract.UserTempNaming;%0Aimport de.flapdoodle.embed.process.io.Processors
 ;%0Aim
@@ -1099,17 +1099,16 @@
 cutable 
-_
 mongodEx
@@ -1133,17 +1133,16 @@
 Process 
-_
 mongod;%0A
@@ -1162,17 +1162,16 @@
 oClient 
-_
 mongo;%0A%0A
@@ -1217,16 +1217,184 @@
 ongoD;%0A%0A
+%0A%09%09ProcessOutput processOutput = new ProcessOutput(Processors.namedConsole(%22%5Bmongod%5D%22),%0A%09%09%09Processors.namedConsole(%22%5BMONGOD%5D%22), Processors.namedConsole(%22%5Bcommand%5D%22));%0A%0A
 %09%09IRunti
@@ -1674,16 +1674,49 @@
 ing()))%0A
+%09%09%09.processOutput(processOutput)%0A
 %09%09%09.buil
@@ -1835,17 +1835,16 @@
 ion %7B%0A%09%09
-_
 mongodEx
@@ -1997,25 +1997,24 @@
 build());%0A%09%09
-_
 mongod = _mo
@@ -2010,17 +2010,16 @@
 ongod = 
-_
 mongodEx
@@ -2046,25 +2046,24 @@
 setUp();%0A%0A%09%09
-_
 mongo = new 
@@ -2184,17 +2184,16 @@
 n();%0A%0A%09%09
-_
 mongod.s
@@ -2201,17 +2201,16 @@
 op();%0A%09%09
-_
 mongodEx
@@ -2259,17 +2259,16 @@
 %09return 
-_
 mongo;%0A%09

Refactor a little and add console naming for fine-grained control of log output