Exemplo n.º 1
0
/* ****************************************************************************
*
* parseError - 
*/
TEST(xmlRequest, parseError)
{
  ConnectionInfo  ci("/ngsi/registerContext", "POST", "1.1");
  ConnectionInfo  ci2("/ngsi/registerContext123", "POST", "1.1");
  ConnectionInfo  ci3("/ngsi/registerContext", "POST", "1.1");
  ConnectionInfo  ci4("/version", "POST", "1.1");
  ParseData       parseData;
  const char*     infile1  = "ngsi9.registerContextRequest.parseError.invalid.xml"; 
  const char*     infile2  = "ngsi9.registerContextRequest.ok.valid.xml"; 
  const char*     infile3  = "ngsi9.registerContextRequest.errorInFirstLine.invalid.xml";
  const char*     outfile1 = "orion.error.parseError.valid.xml";
  const char*     outfile2 = "orion.error.noRequestTreatingObjectFound.valid.xml";
  const char*     outfile3 = "orion.error.parseError.valid.xml";
  const char*     outfile4 = "ngsi9.registerContextResponse.invalidPayload.valid.xml";
  std::string     out;

  utInit();

  // Parse Error
  EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), infile1)) << "Error getting test data from '" << infile1 << "'";
  EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile1)) << "Error getting test data from '" << outfile1 << "'";
  ci.inFormat  = XML;
  ci.outFormat = XML;
  out  = xmlTreat(testBuf, &ci, &parseData, RegisterContext, "registerContextRequest", NULL);
  EXPECT_STREQ(expectedBuf, out.c_str());

  // Request not found
  EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), infile2)) << "Error getting test data from '" << infile2 << "'";
  EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile2)) << "Error getting test data from '" << outfile2 << "'";
  ci2.inFormat  = XML;
  ci2.outFormat = XML;
  out  = xmlTreat(testBuf, &ci2, &parseData, (RequestType) (RegisterContext + 1000), "registerContextRequest", NULL);
  EXPECT_STREQ(expectedBuf, out.c_str());

  // Error in first line '<?xml version="1.0" encoding="UTF-8"?>'
  EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), infile3)) << "Error getting test data from '" << infile3 << "'";
  EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile3)) << "Error getting test data from '" << outfile3 << "'";
  ci3.inFormat  = XML;
  ci3.outFormat = XML;
  out  = xmlTreat(testBuf, &ci3, &parseData, RegisterContext, "registerContextRequest", NULL);
  EXPECT_STREQ(expectedBuf, out.c_str());

  // Payload word differs
  EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), infile2)) << "Error getting test data from '" << infile2 << "'";
  EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile4)) << "Error getting test data from '" << outfile4 << "'";
  ci.inFormat  = XML;
  ci.outFormat = XML;
  out  = xmlTreat(testBuf, &ci, &parseData, RegisterContext, "discovery", NULL);
  EXPECT_STREQ(expectedBuf, out.c_str());

  utExit();
}
/* ****************************************************************************
*
* ok_xml - 
*/
TEST(QueryContextRequest, ok_xml)
{
  ParseData       reqData;
  ConnectionInfo  ci("", "POST", "1.1");
  const char*     infile = "ngsi10.queryContextRequest.ok.valid.xml";

  utInit();

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

  lmTraceLevelSet(LmtDump, true);
  std::string out = xmlTreat(testBuf, &ci, &reqData, QueryContext, "queryContextRequest", NULL);
  lmTraceLevelSet(LmtDump, false);

  EXPECT_EQ("OK", out) << "this test should be OK";

  //
  // With the data obtained, render, present and release methods are exercised
  //
  QueryContextRequest*  qcrP = &reqData.qcr.res;
  const char*  outfile = "ngsi10.queryContextRequest.ok2.valid.xml";
  
  qcrP->present(""); // No output

  EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile)) << "Error getting test data from '" << outfile << "'";
  out = qcrP->render(QueryContext, XML, "");
  EXPECT_STREQ(expectedBuf, out.c_str());

  qcrP->release();

  utExit();
}
/* ****************************************************************************
*
* ok_xml - 
*/
TEST(SubscribeContextRequest, ok_xml)
{
  ParseData       reqData;
  ConnectionInfo  ci("", "POST", "1.1");
  const char*     fileName = "ngsi10.subscribeContextRequest.ok.valid.xml";

  utInit();

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

  lmTraceLevelSet(LmtDump, true);
  std::string result = xmlTreat(testBuf, &ci, &reqData, SubscribeContext, "subscribeContextRequest", NULL);
  lmTraceLevelSet(LmtDump, false);

  EXPECT_EQ("OK", result);

  //
  // With the data obtained, render, present and release methods are exercised
  //
  SubscribeContextRequest*  scrP = &reqData.scr.res;
  const char*               outfile = "ngsi10.subscribeContextRequest.rendered.valid.xml";

  scrP->present(""); // No output

  EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile)) << "Error getting test data from '" << outfile << "'";
  std::string out = scrP->render(SubscribeContext, XML, "");
  EXPECT_STREQ(expectedBuf, out.c_str());

  scrP->release();

  utExit();
}
/* ****************************************************************************
*
* 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();
}
Exemplo n.º 5
0
/* ****************************************************************************
*
* payloadParse -
*/
std::string payloadParse(ConnectionInfo* ciP, ParseData* parseDataP, RestService* service, XmlRequest** reqPP, JsonRequest** jsonPP)
{
    std::string result = "NONE";

    LM_T(LmtParsedPayload, ("parsing data for service '%s'. Method: '%s'", requestType(service->request), ciP->method.c_str()));
    LM_T(LmtParsedPayload, ("outFormat: %s", formatToString(ciP->outFormat)));

    if (ciP->inFormat == XML)
    {
        LM_T(LmtParsedPayload, ("Calling xmlTreat for service request %d, payloadWord '%s'", service->request, service->payloadWord.c_str()));
        result = xmlTreat(ciP->payload, ciP, parseDataP, service->request, service->payloadWord, reqPP);
    }
    else if (ciP->inFormat == JSON)
        result = jsonTreat(ciP->payload, ciP, parseDataP, service->request, service->payloadWord, jsonPP);
    else
    {
        LM_W(("Bad Input (payload mime-type is neither JSON nor XML)"));
        return "Bad inFormat";
    }

    LM_T(LmtParsedPayload, ("result: '%s'", result.c_str()));
    LM_T(LmtParsedPayload, ("outFormat: %s", formatToString(ciP->outFormat)));

    if (result != "OK")
    {
        restReply(ciP, result);
    }

    return result;
}
/* ****************************************************************************
*
* ok_xml - 
*/
TEST(NotifyContextAvailabilityRequest, ok_xml)
{
  ParseData       parseData;
  const char*     inFile  = "ngsi9.notifyContextAvailabilityRequest.ok.valid.xml";
  const char*     outFile = "ngsi9.notifyContextAvailabilityRequestRendered.ok.valid.xml";
  ConnectionInfo  ci("", "POST", "1.1");
  std::string     rendered;

  utInit();

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

  lmTraceLevelSet(LmtDump, true);
  std::string result = xmlTreat(testBuf, &ci, &parseData, NotifyContextAvailability, "notifyContextAvailabilityRequest", NULL);
  EXPECT_EQ("OK", result);
  lmTraceLevelSet(LmtDump, false);

  NotifyContextAvailabilityRequest* ncarP = &parseData.ncar.res;

  rendered = ncarP->render(NotifyContext, XML, "");
  EXPECT_STREQ(expectedBuf, rendered.c_str());

  ncarP->release();
  
  utExit();
}
/* ****************************************************************************
*
* noEntityIdList - 
*/
TEST(RegisterContextRequest, noEntityIdList)
{
  ParseData       parseData;
  const char*     inFile = "ngsi9.registerContextRequest.noEntityIdList.valid.xml";
  ConnectionInfo  ci("", "POST", "1.1");

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

  std::string result = xmlTreat(testBuf, &ci, &parseData, RegisterContext, "registerContextRequest", NULL);
  EXPECT_EQ("OK", result) << "No EntityId List error";
}
/* ****************************************************************************
*
* okNoRestrictions_xml - 
*/
TEST(DiscoverContextAvailabilityRequest, okNoRestrictions_xml)
{
  ParseData       reqData;
  const char*     inFile = "ngsi9.discoverContextAvailabilityRequest.noRestriction.valid.xml";
  ConnectionInfo  ci("", "POST", "1.1");

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

  std::string result = xmlTreat(testBuf, &ci, &reqData, DiscoverContextAvailability, "discoverContextAvailabilityRequest", NULL);
  EXPECT_EQ("OK", result) << "OK with no Restriction";
}
/* ****************************************************************************
*
* entityIdIsPattern_xml - 
*/
TEST(DiscoverContextAvailabilityRequest, entityIdIsPattern_xml)
{
  ParseData       reqData;
  const char*     inFile = "ngsi9.discoverContextAvailabilityRequest.entityIdIsPatternAsField.valid.xml";
  ConnectionInfo  ci("", "POST", "1.1");

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

  std::string result = xmlTreat(testBuf, &ci, &reqData, DiscoverContextAvailability, "discoverContextAvailabilityRequest", NULL);
  EXPECT_EQ("OK", result) << "invalid 'isPattern' value";
}
/* ****************************************************************************
*
* emptyAttributeExpression_xml - 
*/
TEST(DiscoverContextAvailabilityRequest, emptyAttributeExpression_xml)
{
  ParseData       reqData;
  const char*     inFile = "ngsi9.discoverContextAvailabilityRequest.emptyAttributeExpression.invalid.xml";
  const char*     expect   = "OK";
  ConnectionInfo  ci("", "POST", "1.1");

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

  std::string result = xmlTreat(testBuf, &ci, &reqData, DiscoverContextAvailability, "discoverContextAvailabilityRequest", NULL);
  EXPECT_EQ(expect, result) << "Empty Attribute Expression";
}
/* ****************************************************************************
*
* emptyRegistrationMetadataValue - 
*/
TEST(RegisterContextRequest, emptyRegistrationMetadataValue)
{
  ParseData       parseData;
  const char*     inFile  = "ngsi9.registerContextRequest.emptyRegistrationMetadataValue.invalid.xml";
  const char*     outFile = "ngsi9.registerContextResponse.emptyRegistrationMetadataValue.valid.xml";
  ConnectionInfo  ci("", "POST", "1.1");

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

  std::string result = xmlTreat(testBuf, &ci, &parseData, RegisterContext, "registerContextRequest", NULL);
  EXPECT_STREQ(expectedBuf, result.c_str());
}
/* ****************************************************************************
*
* emptyScopeValue_xml - 
*/
TEST(DiscoverContextAvailabilityRequest, emptyScopeValue_xml)
{
  ParseData       reqData;
  const char*     inFile  = "ngsi9.discoverContextAvailabilityRequest.emptyScopeValue.invalid.xml";
  const char*     outFile = "ngsi9.discoverContextAvailabilityResponse.emptyScopeValue.valid.xml";
  ConnectionInfo  ci("", "POST", "1.1");

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

  std::string result = xmlTreat(testBuf, &ci, &reqData, DiscoverContextAvailability, "discoverContextAvailabilityRequest", NULL);
  EXPECT_STREQ(expectedBuf, result.c_str());
}
/* ****************************************************************************
*
* present - 
*/
TEST(RegisterContextRequest, present)
{
  ParseData       parseData;
  const char*     inFile = "ngsi9.registerContextRequest.ok.valid.xml";
  ConnectionInfo  ci("", "POST", "1.1");

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

  lmTraceLevelSet(LmtDump, true);
  std::string result = xmlTreat(testBuf, &ci, &parseData, RegisterContext, "registerContextRequest", NULL);
  EXPECT_EQ("OK", result) << "this test should be OK";
  lmTraceLevelSet(LmtDump, false);
}
/* ****************************************************************************
*
* ok_xml - 
*/
TEST(DiscoverContextAvailabilityRequest, ok_xml)
{
  ParseData       reqData;
  const char*     inFile = "ngsi9.discoverContextAvailabilityRequest.ok.valid.xml";
  ConnectionInfo  ci("", "POST", "1.1");

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

  lmTraceLevelSet(LmtDump, true);
  std::string result = xmlTreat(testBuf, &ci, &reqData, DiscoverContextAvailability, "discoverContextAvailabilityRequest", NULL);
  EXPECT_EQ("OK", result) << "this test should be OK";
  lmTraceLevelSet(LmtDump, false);
}
/* ****************************************************************************
*
* overwriteEntityIdIsPattern_xml - 
*/
TEST(QueryContextRequest, overwriteEntityIdIsPattern_xml)
{
  ParseData       reqData;
  ConnectionInfo  ci("", "POST", "1.1");
  const char*     infile = "ngsi10.queryContextRequest.isPatternAsField.invalid.xml";

  utInit();

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

  std::string out = xmlTreat(testBuf, &ci, &reqData, QueryContext, "queryContextRequest", NULL);
  EXPECT_EQ("OK", out);

  utExit();
}
/* ****************************************************************************
*
* scopeGeolocationPolygonOk - 
*/
TEST(SubscribeContextRequest, scopeGeolocationPolygonOk)
{
  ParseData       parseData;
  const char*     inFile  = "ngsi10.subscribeContextRequest.polygonOk.postponed.xml";
  ConnectionInfo  ci("/ngsi10/subscribeContext", "POST", "1.1");
  std::string     result;

  utInit();

  EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), inFile)) << "Error getting test data from '" << inFile << "'";
  result = xmlTreat(testBuf, &ci, &parseData, SubscribeContext, "subscribeContextRequest", NULL);
  EXPECT_STREQ("OK", result.c_str());

  utExit();
}
/* ****************************************************************************
*
* emptyAttributeExpression_xml - 
*/
TEST(QueryContextRequest, emptyAttributeExpression_xml)
{
  ParseData       reqData;
  ConnectionInfo  ci("", "POST", "1.1");
  const char*     infile = "ngsi10.queryContextRequest.emptyAttributeExpression.invalid.xml";
  const char*     expect = "OK";

  utInit();

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

  std::string out = xmlTreat(testBuf, &ci, &reqData, QueryContext, "queryContextRequest", NULL);
  EXPECT_EQ(expect, out);

  utExit();
}
/* ****************************************************************************
*
* xml_badIsPattern - 
*/
TEST(NotifyContextRequest, xml_badIsPattern)
{
  ParseData       reqData;
  ConnectionInfo  ci("", "POST", "1.1");
  const char*     infile  = "ngsi10.notifyContextRequest.isPattern.invalid.xml";
  const char*     outfile = "ngsi10.notifyContextResponse.isPatternError.valid.xml";

  utInit();

  EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), infile)) << "Error getting test data from '" << infile << "'";
  EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile)) << "Error getting test data from '" << outfile << "'";
  std::string result = xmlTreat(testBuf, &ci, &reqData, NotifyContext, "notifyContextRequest", NULL);
  EXPECT_STREQ(expectedBuf, result.c_str());

  utExit();
}
/* ****************************************************************************
*
* noScopeValue_xml - 
*/
TEST(QueryContextRequest, noScopeValue_xml)
{
  ParseData       reqData;
  ConnectionInfo  ci("", "POST", "1.1");
  const char*     infile  = "ngsi10.queryContextRequest.noScopeValue.invalid.xml";
  const char*     outfile = "ngsi10.queryContextResponse.noScopeValue.valid.xml";

  utInit();

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

  std::string out = xmlTreat(testBuf, &ci, &reqData, QueryContext, "queryContextRequest", NULL);
  EXPECT_STREQ(expectedBuf, out.c_str());

  utExit();
}
/* ****************************************************************************
*
* scopeGeolocationCircleZeroRadius - 
*/
TEST(SubscribeContextRequest, scopeGeolocationCircleZeroRadius)
{
  ParseData       reqData;
  const char*     inFile  = "ngsi10.subscribeContextRequest.circleZeroRadius.postponed.xml";
  const char*     outFile = "ngsi10.subscribeContextResponse.circleZeroRadius.postponed.xml";
  ConnectionInfo  ci("/ngsi10/subscribeContext", "POST", "1.1");
  std::string     result;

  utInit();

  EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), inFile)) << "Error getting test data from '" << inFile << "'";
  EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outFile)) << "Error getting test data from '" << outFile << "'";
  result = xmlTreat(testBuf, &ci, &reqData, SubscribeContext, "subscribeContextRequest", NULL);
  EXPECT_STREQ(expectedBuf, result.c_str());

  utExit();
}
/* ****************************************************************************
*
* badEntityAttribute_xml - 
*/
TEST(NotifyContextAvailabilityRequest, badEntityAttribute_xml)
{
  ParseData       parseData;
  const char*     infile  = "ngsi9.notifyContextAvailabilityRequest.entityAttribute.invalid.xml";
  const char*     outfile = "ngsi9.notifyContextAvailabilityResponse.invalidEntityAttribute.valid.xml";
  ConnectionInfo  ci("", "POST", "1.1");

  utInit();

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

  std::string out = xmlTreat(testBuf, &ci, &parseData, NotifyContextAvailability, "notifyContextAvailabilityRequest", NULL);
  EXPECT_STREQ(expectedBuf, out.c_str());
  
  utExit();
}
/* ****************************************************************************
*
* xml_ok -
*/
TEST(UpdateContextAvailabilitySubscriptionRequest, xml_ok)
{
    ParseData       reqData;
    const char*     infile = "ngsi9.updateContextAvailabilitySubscriptionRequest.ok2.valid.xml";
    ConnectionInfo  ci("", "POST", "1.1");

    utInit();

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

    lmTraceLevelSet(LmtDump, true);
    std::string out = xmlTreat(testBuf, &ci, &reqData, UpdateContextAvailabilitySubscription, "updateContextAvailabilitySubscriptionRequest", NULL);
    lmTraceLevelSet(LmtDump, false);
    EXPECT_EQ("OK", out) << "this test should be OK";

    utExit();
}
/* ****************************************************************************
*
* ok_xml - 
*/
TEST(UpdateContextRequest, ok_xml)
{
  ParseData       reqData;
  ConnectionInfo  ci("", "POST", "1.1");
  const char*     infile = "ngsi10.updateContext.valid.xml";

  utInit();

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

  lmTraceLevelSet(LmtDump, true);
  std::string result = xmlTreat(testBuf, &ci, &reqData, UpdateContext, "updateContextRequest", NULL);
  lmTraceLevelSet(LmtDump, false);

  EXPECT_EQ("OK", result);

  //
  // With the data obtained, render, present and release methods are exercised
  //
  UpdateContextRequest*  upcrP = &reqData.upcr.res;
  
  upcrP->present(""); // No output

  std::string out;
  const char* outfile1 = "ngsi10.updateContextRequest.rendered1.valid.xml";
  const char* outfile2 = "ngsi10.updateContextRequest.checked.valid.xml";
  const char* outfile3 = "ngsi10.updateContextRequest.badUpdateActionType.invalid.xml";

  out = upcrP->render(&ci, UpdateContext, "");
  EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile1)) << "Error getting test data from '" << outfile1;
  EXPECT_STREQ(expectedBuf, out.c_str());

  out  = upcrP->check(&ci, UpdateContext, "", "FORCED ERROR", 0);
  EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile2)) << "Error getting test data from '" << outfile2;
  EXPECT_STREQ(expectedBuf, out.c_str());

  upcrP->updateActionType.set("invalid");
  out  = upcrP->check(&ci, RegisterContext, "", "", 0);
  EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile3)) << "Error getting test data from '" << outfile3;
  EXPECT_STREQ(expectedBuf, out.c_str());

  upcrP->release();

  utExit();
}
/* ****************************************************************************
*
* xml_ok - 
*/
TEST(RegisterContextRequest, xml_ok)
{
  ParseData                parseData;
  const char*              inFile  = "ngsi9.registerContextRequest.ok.valid.xml";
  const char*              outFile = "ngsi9.registerContextRequestRendered.ok.valid.xml";
  RegisterContextRequest*  rcrP    = &parseData.rcr.res;
  ConnectionInfo           ci("", "POST", "1.1");
  std::string              out;
  
  EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), inFile)) << "Error getting test data from '" << inFile << "'";
  EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outFile)) << "Error getting test data from '" << outFile << "'";

  std::string result = xmlTreat(testBuf, &ci, &parseData, RegisterContext, "registerContextRequest", NULL);
  EXPECT_EQ("OK", result) << "this test should be OK";

  out = rcrP->render(RegisterContext, XML, "");
  EXPECT_STREQ(expectedBuf, out.c_str());
}
/* ****************************************************************************
*
* ok - 
*/
TEST(xmlUpdateContextRequest, ok)
{
  ConnectionInfo  ci("/ngsi10/updateContext", "POST", "1.1");
  const char*     fileName = "ngsi10.updateContextRequestWithMetadata.valid.xml";
  ParseData       parseData;
  std::string     out;

  utInit();

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

  ci.inFormat  = XML;
  ci.outFormat = XML;
  out  = xmlTreat(testBuf, &ci, &parseData, UpdateContext, "updateContextRequest", NULL);
  EXPECT_EQ("OK", out);

  utExit();
}
/* ****************************************************************************
*
* noRestriction_xml - 
*/
TEST(QueryContextRequest, noRestriction_xml)
{
  ParseData       reqData;
  ConnectionInfo  ci("", "POST", "1.1");
  const char*     infile = "ngsi10.queryContextRequest.noRestriction.valid.xml";

  utInit();

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

  lmTraceLevelSet(LmtDump, true);
  std::string out = xmlTreat(testBuf, &ci, &reqData, QueryContext, "queryContextRequest", NULL);
  lmTraceLevelSet(LmtDump, false);

  EXPECT_EQ("OK", out);

  utExit();
}
/* ****************************************************************************
*
* xml_invalidEntityIdAttribute - 
*
* FIXME P5 #1862: _json counterpart?
*/
TEST(NotifyContextRequest, DISABLED_xml_invalidEntityIdAttribute)
{
#if 0
  ParseData       reqData;
  ConnectionInfo  ci("", "POST", "1.1");
  const char*     infile  = "ngsi10.notifyContextRequest.entityIdAttribute.invalid.xml";
  const char*     outfile = "ngsi10.notifyContextResponse.entityIdAttribute.valid.xml";

  utInit();

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

  std::string out = xmlTreat(testBuf, &ci, &reqData, NotifyContext, "notifyContextRequest", NULL);
  EXPECT_STREQ(expectedBuf, out.c_str());

  utExit();
#endif
}
/* ****************************************************************************
*
* xml_entityIdIsPatternAsBothFieldAndAttribute - 
*
* FIME P5 #1862: _json counterpart?
*/
TEST(SubscribeContextAvailabilityRequest, DISABLED_xml_entityIdIsPatternAsBothFieldAndAttribute)
{
#if 0
  ParseData       reqData;
  const char*     inFile  = "ngsi9.subscribeContextAvailabilityRequest.entityIdIsPatternAsBothFieldAndAttribute.invalid.xml";
  const char*     outFile = "ngsi9.subscribeContextAvailabilityResponse.entityIdIsPatternAsBothFieldAndAttribute.valid.xml";
  ConnectionInfo  ci("", "POST", "1.1");

  utInit();

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

  std::string out = xmlTreat(testBuf, &ci, &reqData, SubscribeContextAvailability, "subscribeContextAvailabilityRequest", NULL);
  EXPECT_STREQ(expectedBuf, out.c_str());

  utExit();
#endif
}
/* ****************************************************************************
*
* invalidEntityIdAttribute_xml - 
*
* FIXME P5: invalid attributes in EntityId are found but not reported
*/
TEST(SubscribeContextRequest, invalidEntityIdAttribute_xml)
{
  ParseData       parseData;
  ConnectionInfo  ci("", "POST", "1.1");
  const char*     infile = "ngsi10.subscribeContextRequest.entityIdAttribute.invalid.xml";
  const char*     expected = "OK";
  XmlRequest*     reqP;

  utInit();

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

  std::string result = xmlTreat(testBuf, &ci, &parseData, SubscribeContext, "subscribeContextRequest", &reqP);

  reqP->release(&parseData);
  EXPECT_STREQ(expected, result.c_str());

  utExit();
}
/* ****************************************************************************
*
* xml_invalidEntityAttribute -
*/
TEST(UpdateContextAvailabilitySubscriptionRequest, xml_invalidEntityAttribute)
{
    ParseData       reqData;
    const char*     infile  = "ngsi9.updateContextAvailabilitySubscriptionRequest.entityIdAttribute.invalid.xml";
    const char*     outfile = "ngsi9.updateContextAvailabilitySubscriptionResponse.entityIdAttribute.valid.xml";
    ConnectionInfo  ci("", "POST", "1.1");

    utInit();

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

    lmTraceLevelSet(LmtDump, true);
    std::string out = xmlTreat(testBuf, &ci, &reqData, UpdateContextAvailabilitySubscription, "updateContextAvailabilitySubscriptionRequest", NULL);
    lmTraceLevelSet(LmtDump, false);
    EXPECT_STREQ(expectedBuf, out.c_str());

    utExit();
}