/* ****************************************************************************
*
* xml_ok - 
*/
TEST(NotifyContextRequest, xml_ok)
{
  ParseData              reqData;
  ConnectionInfo         ci("", "POST", "1.1");
  std::string            rendered;
  const char*            infile   = "ngsi10.notifyContextRequest.ok.valid.xml";
  const char*            outfile  = "ngsi10.notifyContextResponse.ok.valid.xml";
  NotifyContextRequest*  ncrP     = &reqData.ncr.res;

  utInit();
  
  ci.outFormat = XML;

  EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), infile)) << "Error getting test data from '" << infile << "'";

  lmTraceLevelSet(LmtDump, true);
  std::string result = xmlTreat(testBuf, &ci, &reqData, NotifyContext, "notifyContextRequest", NULL);
  EXPECT_EQ("OK", result);
  lmTraceLevelSet(LmtDump, false);

  ncrP->present("");

  rendered = ncrP->render(&ci, NotifyContext, "");
  EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile)) << "Error getting test data from '" << outfile << "'";
  EXPECT_STREQ(expectedBuf, rendered.c_str());

  ncrP->present("");
  ncrP->release();

  utExit();
}
/* ****************************************************************************
*
* json_ok - 
*/
TEST(NotifyContextRequest, json_ok)
{
  ParseData              reqData;
  ConnectionInfo         ci("", "POST", "1.1");
  NotifyContextRequest*  ncrP      = &reqData.ncr.res;
  const char*            infile    = "notifyContextRequest_ok.json";
  const char*            outfile   = "ngsi10.notifyContextRequest_ok.expected1.valid.json";
  std::string            rendered;

  utInit();

  ci.outFormat = JSON;

  EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), infile)) << "Error getting test data from '" << infile << "'";
  
  ci.inFormat  = JSON;
  ci.outFormat = JSON;

  lmTraceLevelSet(LmtDump, true);
  std::string result = jsonTreat(testBuf, &ci, &reqData, NotifyContext, "notifyContextRequest", NULL);
  EXPECT_EQ("OK", result);
  lmTraceLevelSet(LmtDump, false);

  //
  // With the data obtained, render, present and release methods are exercised
  //
  ncrP->present("");
  EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile)) << "Error getting test data from '" << outfile << "'";
  rendered = ncrP->render(&ci, NotifyContext, "");
  EXPECT_STREQ(expectedBuf, rendered.c_str());

  ncrP->release();

  utExit();
}
/* ****************************************************************************
*
* json_render - 
*/
TEST(NotifyContextRequest, json_render)
{
  const char*              filename1  = "ngsi10.notifyContextRequest.jsonRender1.valid.json";
  const char*              filename2  = "ngsi10.notifyContextRequest.jsonRender2.valid.json";
  const char*              filename3  = "ngsi10.notifyContextRequest.jsonRender3.valid.json";
  NotifyContextRequest*    ncrP;
  ContextElementResponse*  cerP;
  std::string              rendered;
  ConnectionInfo           ci(JSON);

  utInit();
  
  // Preparation 
  ncrP = new NotifyContextRequest();
  ncrP->subscriptionId.set("012345678901234567890123");
  ncrP->originator.set("http://www.tid.es/NotifyContextRequestUnitTest");

  // 1. Without ContextResponseList
  EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), filename1)) << "Error getting test data from '" << filename1 << "'";
  rendered = ncrP->render(&ci, QueryContext, "");
  EXPECT_STREQ(expectedBuf, rendered.c_str());


  // 2. With ContextResponseList
  cerP = new ContextElementResponse();
  cerP->contextElement.entityId.fill("E01", "EType", "false");
  ncrP->contextElementResponseVector.push_back(cerP);
  cerP->statusCode.fill(SccOk);

  EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), filename2)) << "Error getting test data from '" << filename2 << "'";
  rendered = ncrP->render(&ci, QueryContext, "");
  EXPECT_STREQ(expectedBuf, rendered.c_str());


  // 3. ContextResponseList with two instances
  cerP = new ContextElementResponse();
  cerP->contextElement.entityId.fill("E02", "EType", "false");
  ncrP->contextElementResponseVector.push_back(cerP);
  cerP->statusCode.fill(SccOk);

  EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), filename3)) << "Error getting test data from '" << filename3 << "'";
  rendered = ncrP->render(&ci, QueryContext, "");
  EXPECT_STREQ(expectedBuf, rendered.c_str());

  utExit();
}