bool DummyDAImpl::DoExec(Context &context, ParameterMapper *in, ResultMapper *out) {
	StartTrace(DummyDAImpl.DoExecRecordOrTest);
	DAAccessTimer("DummyDAImpl.Exec", "DummyDAImpl.Exec writing", context);

	Anything tmpStore = context.GetTmpStore();

	// open test config file
	Anything recording;
	String str("Recording");
	Recording::ReadinRecording(str, recording);

	Trace("name: " << fName);

	String request;
	if (!BuildRequest(request, context, in)) {
		return false;
	}

	String theReply = GetReplyMatchingRequest(recording, context, request);
	if (TriggerEnabled(DummyDAImpl.DoExecRecordOrTest)) {
		String infoMsg = "\r\nReply from server ";
		infoMsg << theReply;
		SystemLog::Info(infoMsg); // perhaps enable this line with an entry in RequestLineRenderer.any.... future
	}
	if (!RenderReply(theReply, context, out)) {
		return false;
	}
	return true;
}
void FlowController::DoCleanupAfterStep(Context &ctx, ROAnything roaStepConfig) {
	StartTrace(FlowController.DoCleanupAfterStep);
	Anything tmpStore(ctx.GetTmpStore());
	SubTraceAny(TmpStore, ctx.GetTmpStore(), "TmpStore before");
	if (!roaStepConfig.IsNull()) {
		long sz = roaStepConfig.GetSize();
		for (long i = 0; i < sz; i++) {
			String slotName = roaStepConfig.SlotName(i);
			if (slotName) {
				Trace("Slotname to remove : " << slotName);
				tmpStore.Remove(slotName);
			}
		}
	}
	SubTraceAny(TmpStore, tmpStore, "TmpStore after");
}
String DummyDAImpl::GetReplyMatchingRequest(Anything &recording, Context &context, String &request) {
	long testStepNo = 0;
	Anything tmpStore(context.GetTmpStore());

	if (tmpStore.IsDefined("TestStepNo")) {
		testStepNo = tmpStore["TestStepNo"].AsLong(-1L);
		++testStepNo;
	}
	tmpStore["TestStepNo"] = testStepNo;

	Anything conv = Anything(testStepNo);
	String index = conv.AsString();

	if (recording[index].IsDefined("Request")) {
		String recordedRequest = recording[index]["Request"].AsString("");

		if (!recordedRequest.IsEqual(request)) {
			String eMsg = "Error: at index ";
			eMsg << index << " request did not match recorded request:" << request;
			SystemLog::Warning("Error: request did not match recorded request");
		}

		String eMsg = "Reply not found, index:";
		eMsg << index << " Request:" << request;
		// done this way because you don't write to any if you check first... which might be important in future...not now..
		if (!recording[index].IsDefined("Reply")) {
			return eMsg;
		}
		return recording[index]["Reply"].AsString(eMsg);
	} else {
		String eMsg = "Request not found, index:";
		eMsg << index << " Request:" << request;
		return eMsg;
	}
}
bool FlowController::PrepareRequest(Context &ctx) {
	StartTrace(FlowController.PrepareRequest);

	long reqNr = GetRequestNr(ctx);

	// number of runs of pre depends on number of slots in anything
	long nrOfPreRunRequests = fConfig["PreRun"].GetSize();

	Anything tmpStore = ctx.GetTmpStore();
	Anything flowState = tmpStore["FlowState"];
	if (!flowState["PreRunDone"].AsBool(1)) {
		Trace("PRE RUN NOT DONE ");

		if (reqNr < nrOfPreRunRequests) {
			DoPrepare(tmpStore, fConfig["PreRun"][reqNr]);
			flowState["RequestNr"] = ++reqNr;
			TraceAny(tmpStore["FlowState"], "Flow State on exit");
			return true;
		} else {
			// PreRun done , reset for normal run
			reqNr = 0;
			flowState["RunNr"] = 0L;
			flowState["PreRunDone"] = true;
		}
	}

	long nrOfRuns = 0;
	String appName;
	Application *application = Application::GetGlobalApplication(appName);
	if (application) {
		nrOfRuns = application->Lookup("NumberOfRuns", fConfig["NumberOfRuns"].AsLong(1));
		Trace(appName << " application found" );
	} else {
		nrOfRuns = fConfig["NumberOfRuns"].AsLong(1);
	}

	long runNr = flowState["RunNr"].AsLong(0);
	Trace("INIT Number of Run: " << runNr << " of " << nrOfRuns);

	while (runNr < nrOfRuns) { // loop thru steps and incr. runNr after each batch has been processed
		Trace("Number of Run: " << runNr << " of " << nrOfRuns);
		TraceAny(fConfig["Run"], "Config Run");
		long nrOfRequests = fConfig["Run"].GetSize();
		if (reqNr < nrOfRequests) {
			DoPrepare(tmpStore, fConfig["Run"][reqNr]);
			flowState["RequestNr"] = ++reqNr;
			TraceAny(tmpStore, "tmpStore on exit");
			TraceAny(tmpStore["FlowState"], "Flow State on exit");
			return true;
		}
		reqNr = 0; // reset request number
		flowState["RunNr"] = ++runNr;
	}

	TraceAny(tmpStore["FlowState"], "Flow State on exit with false");
	return false;
}
void FileAccessControllerTests::FileUDACTest() {
	StartTrace(FileAccessControllerTests.FileUDACTest);

	// create test file
	t_assertm(FileCreator::CreateFile("WriteUserData", GetConfig()["InitData"]["UDACTest"]), "Creation of test file failed");

	// do generic tests
	UserDataAccessController *fudac = UserDataAccessController::FindUserDataAccessController("UserDataFile");
	doTestUDAC(fudac);

	// check results
	Context c;
	t_assert(DataAccess("ReadUserData").StdExec(c));
	TraceAny(c.GetTmpStore()["FileContent"], "FileContentAfterTest");
	assertAnyEqual(GetConfig()["FileContent"]["UDACTest"], c.GetTmpStore()["FileContent"]);

	// clean up
	coast::system::io::unlink("config/FileTestUserDB.any");
}
void ConfiguredActionTest::DoTestWithContext(Anything testCase, const String &testCaseName, Context &ctx) {
	StartTrace(ConfiguredActionTest.DoTestWithContext);
	TraceAny(testCase, "Config of " << testCaseName);

	AlterTestStoreHook(testCase);
	coast::testframework::PutInStore(testCase["SessionStore"], ctx.GetSessionStore());
	coast::testframework::PutInStore(testCase["RoleStore"], ctx.GetRoleStoreGlobal());
	// Can not use real Session Store because Lookup does not find it ! - fix me
	TraceAny(ctx.GetRoleStoreGlobal(), "SessionStore");
	coast::testframework::PutInStore(testCase["TmpStore"], ctx.GetTmpStore());
	coast::testframework::PutInStore(testCase["Query"], ctx.GetQuery());
	coast::testframework::PutInStore(testCase["Env"], ctx.GetEnvStore());

	if (!testCase.IsDefined("Server") && GetConfig().IsDefined("Server")) {
		testCase["Server"] = GetConfig()["Server"].DeepClone();
	}
	if (testCase.IsDefined("Server")) {
		Server *s = Server::FindServer(testCase["Server"].AsCharPtr("Server"));
		ctx.SetServer(s);
	}
	if (testCase.IsDefined("Page")) {
		ctx.Push(testCase["Page"].AsCharPtr("Page"), Page::FindPage(testCase["Page"].AsCharPtr("Page")));
	}
	if (testCase.IsDefined("Role")) {
		ctx.Push(testCase["Role"].AsCharPtr("Role"), Role::FindRole(testCase["Role"].AsCharPtr("Role")));
	}
	TraceAny(testCase["TmpStore"], "Language");
	if (testCase["TmpStore"].IsDefined("Language")) {
		ctx.SetLanguage(testCase["TmpStore"]["Language"].AsCharPtr("D"));
	}

	bool expected = testCase["ExpectedResult"].AsBool(true);

	String token = testCase["StartToken"].AsString("TheAction");
	t_assertm(expected == Action::ExecAction(token, ctx, testCase["TheAction"]), (const char *)testCaseName);
	TraceAny(ctx.GetTmpStore(), "tmp store after action");
	String expectedToken = testCase["ExpectedToken"].AsString("TheAction");
	assertEqualm(expectedToken, token, (const char *)testCaseName);
}
void HTTPResponseMapperTest::TestBadResponseLine() {
	StartTrace(HTTPResponseMapperTest.TestBadResponseLine);
	String strIn("HTTP/1.1 ");
	IStringStream is(strIn);
	HTTPResponseMapper m("HTTPResponseMapper");
	m.Initialize("ResultMapper");
	Context ctx;
	t_assert(!m.Put("", is, ctx));
	Anything result(ctx.GetTmpStore()["Mapper"]["HTTPResponse"]);
	assertEqual(-1L, result[coast::http::constants::protocolCodeSlotname].AsLong(-1));
	assertEqual("undefined", result[coast::http::constants::protocolMsgSlotname].AsCharPtr("undefined"));
	assertEqual("HTTP/1.1", result[coast::http::constants::protocolVersionSlotname].AsCharPtr());
}
bool DummyDAImpl::BuildRequest(String &request, Context &context, ParameterMapper *in) {
	Anything tmpStore(context.GetTmpStore());
	StartTrace(DummyDAImpl.BuildRequest);
	{
		OStringStream os(&request);
		if (!in->Get("Input", os, context)) {
			return HandleError("Input Collection of ", context);
		}
	}
	if (TriggerEnabled(DummyDAImpl.BuildRequest)) {
		tmpStore["ParameterMapper"]["RequestMade"] = request;
	}
	return true; // request built successfully
}
void CookieToServerRenderer::RenderAll(std::ostream &reply, Context &c, const ROAnything &config) {
	StartTrace(CookieToServerRenderer.Render);
	//TraceAny(config, "config");
	// config not so interesting - does this renderer even have one??
	TraceAny( c.GetTmpStore(), "<<- Overall TMP Store" );

	String explicitDomainName = c.Lookup("CurrentServer.ServerName", "");
	explicitDomainName.ToUpper();
	// without Port part
	OutputCookies(explicitDomainName, reply, c);

	explicitDomainName << ":" << c.Lookup("CurrentServer.Port", "");

	// with Port part
	OutputCookies(explicitDomainName, reply, c);
}
void DataAccess::HandleError(Context &context, String mapperName, const char *file, long line, String msg)
{
	StartTrace(DataAccess.HandleError);
	// cut off path in file string (only output file)
	String filePath(file);
	long pos = filePath.StrRChr('\\');			// windows path?
	if (pos < 0) {
		pos = filePath.StrRChr('/');    // unix path?
	}

	String logMsg = (pos < 0) ? filePath : filePath.SubString(pos + 1);
	logMsg << ":" << line << " " << msg << " for [" << mapperName << "]";
	SystemLog::Error(logMsg);
	Trace(logMsg);
	context.GetTmpStore()["DataAccess"][mapperName]["Error"].Append(logMsg);
}
bool CallLDAPDAICacheAction::DoExecAction(String &action, Context &ctx, const ROAnything &config)
{
	// this is the new method that also gets a config ( similar to Renderer::RenderAll )
	// write the action code here - you don't have to override DoAction anymore
	StartTrace(CallLDAPDAICacheAction.DoExecAction);
	TraceAny(config, "config");

	ROAnything result;
	String key(config["Key"].AsString());
	String daName(config["Da"].AsString());
	bool ret = true;
	if (key == "*") {
		result = LDAPDAICacheGetter::GetAll(daName);
	} else {
		ret = LDAPDAICacheGetter::Get(result, daName, key);
	}
	ctx.GetTmpStore() = result.DeepClone();
	return ret;
}
bool HTTPHeaderParameterMapper::DoGetStream(const char *key, std::ostream &os, Context &ctx, ROAnything info) {
	StartTrace1(HTTPHeaderParameterMapper.DoGetStream, "Key:<" << NotNull(key) << ">");
	bool mapSuccess = true;
	ROAnything headerfields(ctx.Lookup(key));
	TraceAny(headerfields, "Headerfields available for key " << key);
	if (!headerfields.IsNull()) {
		String strFieldName;
		ROAnything roaValue;
		AnyExtensions::Iterator<ROAnything> headerIterator(headerfields);
		while (headerIterator.Next(roaValue)) {
			if (headerIterator.SlotName(strFieldName)) {
				strFieldName.ToUpper();
				String strKey(constants::suppressName);
				strKey.Append('.').Append(strFieldName);
				Trace("trying to Lookup [" << strKey << "] in own or config");
				// map non suppressed headerfields
				if (Lookup(strKey).AsLong(0L) == 0L) {
					Anything value;
					ROAnything rvalue;
					Trace("slot: " << strFieldName);
					if (!Get(strFieldName, value, ctx)) {
						rvalue = roaValue;
					} else {
						rvalue = value;
					}
					coast::http::putHeaderFieldToStream(os, ctx, strFieldName, rvalue);
				}
			}
		}
	} else {
		TraceAny(ctx.GetTmpStore(), "no headers, get ReqHeader in tmp store:");
		String strHeaderfields;
		if ((mapSuccess = Get("ReqHeader", strHeaderfields, ctx))) {
			os << strHeaderfields;
		}
	}
	Trace("retval: " << mapSuccess);
	return mapSuccess;
}
long FlowController::GetRequestNr(Context &ctx) {
	StartTrace(FlowController.GetRequestNr);
	// retrieve state from tempStore -- this is done to be thread safe
	// State contains
	// {
	//	/PreRunDone		True if prerun has run
	//	/RunNr			Number of the actual run
	//	/RequestNr		Number of the next request
	// }
	Anything tmpStore = ctx.GetTmpStore();

	// default built in tmpStore if no tmpStore built by previous step
	if (!tmpStore.IsDefined("FlowState")) {
		tmpStore["FlowState"]["RequestNr"] = 0L;
		tmpStore["FlowState"]["PreRunDone"] = false;
		tmpStore["FlowState"]["RunNr"] = 0L;
		//TraceAny(tmpStore["FlowState"],"Flow State initialized");
	}
	Anything flowState = tmpStore["FlowState"];

	// Check PreRun
	return flowState["RequestNr"].AsLong(0);

}
void LogTimerTest::MethodTimerTest() {
	StartTrace(LogTimerTest.MethodTimerTest);
	Context ctx;
	TimeLoggingModule::fgDoTiming = true;
	String msg("Test MethodTimer");
	{
		Anything expected = Anything(Anything::ArrayMarker());
		MethodTimer(NoResult, msg, ctx);
		assertAnyEqual(expected, ctx.GetTmpStore());
	}
	{
		Anything setup;
		setup["EnabledValues"]["Method"]["Test"] = true;
		setup["SimulatedValues"]["Method"]["Test"] = 10;
		Context::PushPopEntry<Anything> aEntry(ctx, "setup", setup);
		Anything expected;
		Anything data;
		data[TimeLogger::eSection] = "Method";
		data[TimeLogger::eKey] = "Test";
		data[TimeLogger::eTime] = 10L;
		data[TimeLogger::eMsg] = "Test MethodTimer";
		data[TimeLogger::eUnit] = "ms";
		data[TimeLogger::eNestingLevel] = 0L;
		expected["Log"]["Times"].Append(data);

		{
			// trigger the destructor by defining its own scope
			MethodTimer(Test, msg, ctx)
			;
		}
		assertAnyEqual(expected, ctx.GetTmpStore());
		TraceAny(ctx.GetTmpStore(), "TmpStore");
	}
	{
		ctx.GetTmpStore() = Anything(Anything::ArrayMarker());
		Anything setup;
		setup["EnabledValues"]["Method"]["Test"] = true;
		setup["SimulatedValues"]["Method"]["Test"] = 10;
		Context::PushPopEntry<Anything> aEntry(ctx, "setup", setup);
		Anything expected;
		Anything data;
		data[TimeLogger::eSection] = "Method";
		data[TimeLogger::eKey] = "Test";
		data[TimeLogger::eTime] = 10L;
		data[TimeLogger::eMsg] = "Test MethodTimer";
		data[TimeLogger::eUnit] = "ms";
		data[TimeLogger::eNestingLevel] = 0L;
		expected["Log"]["Times"].Append(data.DeepClone());
		expected["Log"]["Times"].Append(data.DeepClone());

		//call a method twice
		{
			// trigger the destructor by defining its own scope
			MethodTimer(Test, msg, ctx)
			;
		}
		{
			// trigger the destructor by defining its own scope
			MethodTimer(Test, msg, ctx)
			;
		}
		TraceAny(ctx.GetTmpStore(), "TmpStore");
		assertAnyEqual(expected, ctx.GetTmpStore());
	}
	{
		ctx.GetTmpStore() = Anything(Anything::ArrayMarker());
		Anything setup;
		setup["EnabledValues"]["Method"]["Test"]["SubA"] = true;
		setup["EnabledValues"]["Method"]["Test"]["SubB"] = true;
		setup["SimulatedValues"]["Method"]["Test"]["SubA"] = 10;
		setup["SimulatedValues"]["Method"]["Test"]["SubB"] = 10;
		Context::PushPopEntry<Anything> aEntry(ctx, "setup", setup);
		Anything expected;
		Anything dataA;
		dataA[TimeLogger::eSection] = "Method";
		dataA[TimeLogger::eKey] = "Test.SubA";
		dataA[TimeLogger::eTime] = 10L;
		dataA[TimeLogger::eMsg] = "Test MethodTimer";
		dataA[TimeLogger::eUnit] = "ms";
		dataA[TimeLogger::eNestingLevel] = 0L;
		Anything dataB(dataA.DeepClone());
		dataB[TimeLogger::eKey] = "Test.SubB";
		expected["Log"]["Times"].Append(dataA.DeepClone());
		expected["Log"]["Times"].Append(dataB.DeepClone());

		//call different methods of a class
		{
			// trigger the destructor by defining its own scope
			MethodTimer(Test.SubA, msg, ctx)
			;
		}
		{
			// trigger the destructor by defining its own scope
			MethodTimer(Test.SubB, msg, ctx)
			;
		}
		TraceAny(ctx.GetTmpStore(), "TmpStore");
		assertAnyEqual(expected, ctx.GetTmpStore());
	}
}
bool FileCreator::CreateFile(String dataAccessName, ROAnything data) {
	Context c;
	c.GetTmpStore()["FileContent"] = data.DeepClone();
	return DataAccess(dataAccessName).StdExec(c);
}