package base;

import java.util.function.Supplier;

import org.junit.AfterClass;
import org.junit.BeforeClass;

import play.libs.F;
import play.mvc.Http;
import play.mvc.Http.RequestBuilder;
import play.mvc.Result;
import play.test.FakeApplication;
import play.test.Helpers;

import com.fasterxml.jackson.databind.JsonNode;

@SuppressWarnings("javadoc")
public class BaseModelTest {
	public static FakeApplication app;

	@BeforeClass
	public static void startApp() {
		app = Helpers.fakeApplication(Helpers.inMemoryDatabase());
		Helpers.start(app);
	}

	@AfterClass
	public static void stopApp() {
		Helpers.stop(app);
	}

	protected Result controllerCall(Supplier<F.Promise<Result>> function,
			JsonNode body) {
		Result result = new Helpers().invokeWithContext(new RequestBuilder()
				.bodyJson(body).header("accept", "application/json"), () -> {
					Http.Context.current.get().args.put("role", "edoweb-admin");
					return function.get();
				}).get(5000);
		String str = Helpers.contentAsString(result);
		play.Logger.debug(str);
		return result;
	}

	protected Result controllerCall(Supplier<F.Promise<Result>> function) {
		Result result = new Helpers().invokeWithContext(
				new RequestBuilder().header("accept", "application/json"), () -> {
					Http.Context.current.get().args.put("role", "edoweb-admin");
					return function.get();
				}).get(10000);
		String str = Helpers.contentAsString(result);
		play.Logger.debug(str);
		return result;
	}
}

@@ -103,16 +103,39 @@
 reClass;
+%0Aimport org.junit.Test;
 %0A%0Aimport
@@ -341,16 +341,76 @@
 nNode;%0A%0A
+import archive.fedora.FedoraFacade;%0Aimport models.Globals;%0A%0A
 @Suppres
@@ -1536,11 +1536,79 @@
 sult;%0A%09%7D
+%0A%0A%09@Test%0A%09void testGlobals() %7B%0A%09%09FedoraFacade f = Globals.fedora;%0A%09%7D
 %0A%7D%0A

test if Globals can be initialized