/* ****************************************************************************
*
* RegisterProviderRequest::check - 
*/
std::string RegisterProviderRequest::check
(
  ConnectionInfo* ciP,
  RequestType     requestType,  
  std::string     indent,
  std::string     predetectedError,
  int             counter
)
{
  DiscoverContextAvailabilityResponse  response;
  std::string                          res;

  if (predetectedError != "")
  {
    response.errorCode.fill(SccBadRequest, predetectedError);
  }
  else if (((res = metadataVector.check(ciP, requestType, indent, "", counter))  != "OK") ||
           ((res = duration.check(requestType, indent, "", 0))              != "OK") ||
           ((res = providingApplication.check(requestType, indent, "", 0))  != "OK") ||
           ((res = registrationId.check(requestType, indent, "", 0))        != "OK"))
  {
    response.errorCode.fill(SccBadRequest, res);
  }
  else
  {
    return "OK";
  }

  std::string details = std::string("RegisterProviderRequest Error: '") + res + "'";
  alarmMgr.badInput(clientIp, details);

  return response.render(DiscoverContextAvailability, indent);
}
/* ****************************************************************************
*
* RegisterProviderRequest::check - 
*/
std::string RegisterProviderRequest::check
(
  ApiVersion          apiVersion,
  RequestType         requestType,
  const std::string&  predetectedError
)
{
  DiscoverContextAvailabilityResponse  response;
  std::string                          res;

  if (predetectedError != "")
  {
    response.errorCode.fill(SccBadRequest, predetectedError);
  }
  else if (((res = duration.check())                 != "OK") ||
           ((res = providingApplication.check())     != "OK") ||
           ((res = registrationId.check())           != "OK"))
  {
    response.errorCode.fill(SccBadRequest, res);
  }
  else
  {
    return "OK";
  }

  std::string details = std::string("RegisterProviderRequest Error: '") + res + "'";
  alarmMgr.badInput(clientIp, details);

  return response.toJsonV1();
}
/* ****************************************************************************
*
* RegisterProviderRequest::check - 
*/
std::string RegisterProviderRequest::check
(
  RequestType  requestType,
  Format       format,
  std::string  indent,
  std::string  predetectedError,
  int          counter
)
{
  DiscoverContextAvailabilityResponse  response;
  std::string                          res;

  if (predetectedError != "")
  {
    response.errorCode.fill(SccBadRequest, predetectedError);
  }
  else if (((res = metadataVector.check(requestType, format, indent, "", counter))  != "OK") ||
           ((res = duration.check(requestType, format, indent, "", 0))              != "OK") ||
           ((res = providingApplication.check(requestType, format, indent, "", 0))  != "OK") ||
           ((res = registrationId.check(requestType, format, indent, "", 0))        != "OK"))
  {
    response.errorCode.fill(SccBadRequest, res);
  }
  else
  {
    return "OK";
  }

  LM_W(("Bad Input (RegisterProviderRequest Error: %s)", res.c_str()));

  return response.render(DiscoverContextAvailability, format, indent);
}
/* ****************************************************************************
*
* getContextEntityTypes - 
*/
std::string getContextEntityTypes(ConnectionInfo* ciP, int components, std::vector<std::string>& compV, ParseData* parseDataP)
{
  std::string                          typeName     = compV[2];
  std::string                          answer;
  DiscoverContextAvailabilityResponse  response;

  LM_T(LmtConvenience, ("CONVENIENCE: got a  'GET' request for entity type '%s'", typeName.c_str()));
  ciP->httpStatusCode = mapGetContextEntityTypes(typeName, &response, ciP);
  answer = response.render(DiscoverContextAvailability, ciP->outFormat, "");
  response.release();
  
  return answer;
}
/* ****************************************************************************
*
* postDiscoverContextAvailability - 
*/
std::string postDiscoverContextAvailability
(
  ConnectionInfo*            ciP,
  int                        components,
  std::vector<std::string>&  compV,
  ParseData*                 parseDataP
)
{
  DiscoverContextAvailabilityResponse*  dcarP = &parseDataP->dcars.res;
  std::string                           answer;

  ciP->httpStatusCode = mongoDiscoverContextAvailability(&parseDataP->dcar.res, dcarP, ciP->tenant, ciP->uriParam, ciP->servicePathV);
  answer = dcarP->render(DiscoverContextAvailability, ciP->outFormat, "");

  return answer;
}
/* ****************************************************************************
*
* getEntityByIdAttributeByName -
*/
std::string getEntityByIdAttributeByName
(
  ConnectionInfo*            ciP,
  int                        components,
  std::vector<std::string>&  compV,
  ParseData*                 parseDataP
)
{
  std::string                          entityId      = (compV[0] == "v1")? compV[3] : compV[2];
  std::string                          attributeName = (compV[0] == "v1")? compV[5] : compV[4];
  std::string                          answer;
  DiscoverContextAvailabilityResponse  response;

  LM_T(LmtConvenience, ("CONVENIENCE: got a  'GET' request for entityId '%s', attribute '%s'",
                        entityId.c_str(), attributeName.c_str()));

  ciP->httpStatusCode = mapGetEntityByIdAttributeByName(entityId, "", attributeName, &response, ciP);
  answer = response.render(DiscoverContextAvailability, ciP->outFormat, "");
  response.release();

  return answer;
}
/* ****************************************************************************
*
* DiscoverContextAvailabilityRequest::check - 
*/
std::string DiscoverContextAvailabilityRequest::check(ConnectionInfo* ciP, RequestType requestType, Format format, const std::string& indent, const std::string& predetectedError, int counter)
{
  DiscoverContextAvailabilityResponse  response;
  std::string                          res;

  if (predetectedError != "")
  {
    response.errorCode.fill(SccBadRequest, predetectedError);
  }
  else if (entityIdVector.size() == 0)
  {
    response.errorCode.fill(SccContextElementNotFound);
  }
  else if (((res = entityIdVector.check(ciP, DiscoverContextAvailability, format, indent, predetectedError, restrictions))                      != "OK") ||
           ((res = attributeList.check(DiscoverContextAvailability, format, indent, predetectedError, restrictions))                       != "OK") ||
           ((restrictions != 0) && ((res = restriction.check(DiscoverContextAvailability, format, indent, predetectedError, restrictions)) != "OK")))
  {
    response.errorCode.fill(SccBadRequest, res);
  }
  else
    return "OK";

  return response.render(DiscoverContextAvailability, format, indent);
}
/* ****************************************************************************
*
* jsonRender - 
*
* NOTE
*   - providingApplication is MANDATORY inside ContextRegistration
*/
TEST(DiscoverContextAvailabilityResponse, jsonRender)
{
  const char*                           filename1  = "ngsi9.discoverContextAvailabilityResponse.jsonRender1.valid.json";
  const char*                           filename2  = "ngsi9.discoverContextAvailabilityResponse.jsonRender2.valid.json";
  const char*                           filename3  = "ngsi9.discoverContextAvailabilityResponse.jsonRender3.valid.json";
  const char*                           filename4  = "ngsi9.discoverContextAvailabilityResponse.jsonRender4.valid.json";
  const char*                           filename5  = "ngsi9.discoverContextAvailabilityResponse.jsonRender5.valid.json";
  const char*                           filename6  = "ngsi9.discoverContextAvailabilityResponse.jsonRender6.valid.json";
  const char*                           filename7  = "ngsi9.discoverContextAvailabilityResponse.jsonRender7.valid.json";
  const char*                           filename8  = "ngsi9.discoverContextAvailabilityResponse.jsonRender8.valid.json";
  const char*                           filename9  = "ngsi9.discoverContextAvailabilityResponse.jsonRender9.valid.json";
  const char*                           filename10 = "ngsi9.discoverContextAvailabilityResponse.jsonRender10.valid.json";
  const char*                           filename11 = "ngsi9.discoverContextAvailabilityResponse.jsonRender11.valid.json";
  const char*                           filename12 = "ngsi9.discoverContextAvailabilityResponse.jsonRender12.valid.json";
  const char*                           filename13 = "ngsi9.discoverContextAvailabilityResponse.jsonRender13.valid.json";
  const char*                           filename14 = "ngsi9.discoverContextAvailabilityResponse.jsonRender14.valid.json";
  const char*                           filename15 = "ngsi9.discoverContextAvailabilityResponse.jsonRender15.valid.json";
  const char*                           filename16 = "ngsi9.discoverContextAvailabilityResponse.jsonRender16.valid.json";
  const char*                           filename17 = "ngsi9.discoverContextAvailabilityResponse.jsonRender17.valid.json";
  const char*                           filename18 = "ngsi9.discoverContextAvailabilityResponse.jsonRender18.valid.json";
  const char*                           filename19 = "ngsi9.discoverContextAvailabilityResponse.jsonRender19.valid.json";
  const char*                           filename20 = "ngsi9.discoverContextAvailabilityResponse.jsonRender20.valid.json";
  const char*                           emptyFilename = "ngsi9.discoverContextAvailabilityResponse.jsonRender.empty.valid.json";
  std::string                           rendered;
  DiscoverContextAvailabilityResponse*  dcarP      = new DiscoverContextAvailabilityResponse();
  ContextRegistrationResponse*          crrP;
  EntityId*                             eidP;
  ContextRegistrationAttribute*         attrP;
  Metadata*                             mdP;
  
  utInit();

  // 1. One contextRegistrationResponse - no errorCode inside ContextRegistrationResponse
  crrP = new ContextRegistrationResponse();
  eidP = new EntityId("E01", "EType", "false");

  crrP->contextRegistration.entityIdVector.push_back(eidP);
  crrP->contextRegistration.providingApplication.set("http://tid.test.com/unitTest");
  dcarP->responseVector.push_back(crrP);

  EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), filename1)) << "Error getting test data from '" << filename1 << "'";
  rendered = dcarP->render(DiscoverContextAvailability, JSON, "");
  EXPECT_STREQ(expectedBuf, rendered.c_str());

  dcarP->release();
  dcarP->release();
  EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), emptyFilename)) << "Error getting test data from '" << emptyFilename << "'";
  rendered = dcarP->render(DiscoverContextAvailability, JSON, "");
  EXPECT_STREQ(expectedBuf, rendered.c_str());
  dcarP->release();  // ... otherwise the 500 remains and "pollutes" next tests
  free(dcarP);


  // 2. One contextRegistrationResponse - errorCode inside ContextRegistrationResponse - only providingApplication in ContextRegistration
  dcarP = new DiscoverContextAvailabilityResponse();
  crrP  = new ContextRegistrationResponse();

  crrP->contextRegistration.providingApplication.set("http://tid.test.com/unitTest2");
  crrP->errorCode.fill(SccBadRequest, "errorCode inside ContextRegistrationResponse");
  dcarP->responseVector.push_back(crrP);

  EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), filename2)) << "Error getting test data from '" << filename2 << "'";
  rendered = dcarP->render(DiscoverContextAvailability, JSON, "");
  EXPECT_STREQ(expectedBuf, rendered.c_str());
  // No release here - the data stays - to be used in the following test scenario


  
  // 3. Two contextRegistrationResponses - one with errorCode and one without errorCode
  //    We're reusing the ContextRegistrationResponse from test 2 (it has StatusCode set
  crrP  = new ContextRegistrationResponse();
  crrP->contextRegistration.providingApplication.set("http://tid.test.com/unitTest3");

  dcarP->responseVector.push_back(crrP);

  EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), filename3)) << "Error getting test data from '" << filename3 << "'";
  rendered = dcarP->render(DiscoverContextAvailability, JSON, "");
  EXPECT_STREQ(expectedBuf, rendered.c_str());

  dcarP->release();
  EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), emptyFilename)) << "Error getting test data from '" << emptyFilename << "'";
  rendered = dcarP->render(DiscoverContextAvailability, JSON, "");
  EXPECT_STREQ(expectedBuf, rendered.c_str());
  dcarP->release();  // ... otherwise the 500 remains and "pollutes" next tests


  // 4.  ContextRegistration: One entityId inside entityIdVector
  crrP  = new ContextRegistrationResponse();
  eidP  = new EntityId("E04", "EType", "false");

  crrP->contextRegistration.entityIdVector.push_back(eidP);
  crrP->contextRegistration.providingApplication.set("http://tid.test.com/unitTest4");
  dcarP->responseVector.push_back(crrP);
  
  EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), filename4)) << "Error getting test data from '" << filename4 << "'";
  rendered = dcarP->render(DiscoverContextAvailability, JSON, "");
  EXPECT_STREQ(expectedBuf, rendered.c_str());
  // No release here - the data stays - to be used in the following test scenario
  

  // 5.  ContextRegistration: Two entityIds inside entityIdVector
  eidP  = new EntityId("E05", "EType", "false");

  crrP->contextRegistration.entityIdVector.push_back(eidP);
  crrP->contextRegistration.providingApplication.set("http://tid.test.com/unitTest5");

  EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), filename5)) << "Error getting test data from '" << filename5 << "'";
  rendered = dcarP->render(DiscoverContextAvailability, JSON, "");
  EXPECT_STREQ(expectedBuf, rendered.c_str());

  dcarP->release();
  EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), emptyFilename)) << "Error getting test data from '" << emptyFilename << "'";
  rendered = dcarP->render(DiscoverContextAvailability, JSON, "");
  EXPECT_STREQ(expectedBuf, rendered.c_str());
  dcarP->release();  // ... otherwise the 500 remains and "pollutes" next tests


  // 6.  ContextRegistration: one attribute in contextRegistrationAttributeVector
  crrP  = new ContextRegistrationResponse();
  attrP = new ContextRegistrationAttribute("Attr1", "AType", "false");

  crrP->contextRegistration.contextRegistrationAttributeVector.push_back(attrP);
  crrP->contextRegistration.providingApplication.set("http://tid.test.com/unitTest6");
  dcarP->responseVector.push_back(crrP);
  
  EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), filename6)) << "Error getting test data from '" << filename6 << "'";
  rendered = dcarP->render(DiscoverContextAvailability, JSON, "");
  EXPECT_STREQ(expectedBuf, rendered.c_str());
  // No release here - the data stays - to be used in the following test scenario



  // 7.  ContextRegistration: two attributes in contextRegistrationAttributeVector
  attrP = new ContextRegistrationAttribute("Attr2", "AType", "true");

  crrP->contextRegistration.contextRegistrationAttributeVector.push_back(attrP);
  crrP->contextRegistration.providingApplication.set("http://tid.test.com/unitTest7");

  EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), filename7)) << "Error getting test data from '" << filename7 << "'";
  rendered = dcarP->render(DiscoverContextAvailability, JSON, "");
  EXPECT_STREQ(expectedBuf, rendered.c_str());

  dcarP->release();
  EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), emptyFilename)) << "Error getting test data from '" << emptyFilename << "'";
  rendered = dcarP->render(DiscoverContextAvailability, JSON, "");
  EXPECT_STREQ(expectedBuf, rendered.c_str());
  dcarP->release();  // ... otherwise the 500 remains and "pollutes" next tests


  // 8.  ContextRegistration: one metadata in registrationMetadataVector
  crrP  = new ContextRegistrationResponse();
  mdP = new Metadata("M1", "string", "test 8");
  
  crrP->contextRegistration.registrationMetadataVector.push_back(mdP);
  crrP->contextRegistration.providingApplication.set("http://tid.test.com/unitTest8");
  dcarP->responseVector.push_back(crrP);

  EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), filename8)) << "Error getting test data from '" << filename8 << "'";
  rendered = dcarP->render(DiscoverContextAvailability, JSON, "");
  EXPECT_STREQ(expectedBuf, rendered.c_str());
  // No release here - the data stays - to be used in the following test scenario



  // 9.  ContextRegistration: two metadatas in registrationMetadataVector
  mdP = new Metadata("M2", "string", "test 9");

  crrP->contextRegistration.registrationMetadataVector.push_back(mdP);
  crrP->contextRegistration.providingApplication.set("http://tid.test.com/unitTest9");

  EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), filename9)) << "Error getting test data from '" << filename9 << "'";
  rendered = dcarP->render(DiscoverContextAvailability, JSON, "");
  EXPECT_STREQ(expectedBuf, rendered.c_str());

  dcarP->release();
  EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), emptyFilename)) << "Error getting test data from '" << emptyFilename << "'";
  rendered = dcarP->render(DiscoverContextAvailability, JSON, "");
  EXPECT_STREQ(expectedBuf, rendered.c_str());
  dcarP->release();  // ... otherwise the 500 remains and "pollutes" next tests


  // 10. !entityIdVector !contextRegistrationAttributeVector !registrationMetadataVector +providingApplication
  crrP = new ContextRegistrationResponse();

  crrP->contextRegistration.providingApplication.set("http://tid.test.com/unitTest10");
  dcarP->responseVector.push_back(crrP);

  EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), filename10)) << "Error getting test data from '" << filename10 << "'";
  rendered = dcarP->render(DiscoverContextAvailability, JSON, "");
  EXPECT_STREQ(expectedBuf, rendered.c_str());
  // No release here - the data stays - to be used in the following test scenario



  // 11. !entityIdVector !contextRegistrationAttributeVector +registrationMetadataVector +providingApplication
  mdP = new Metadata("M11", "string", "test 11");

  crrP->contextRegistration.registrationMetadataVector.push_back(mdP);
  crrP->contextRegistration.providingApplication.set("http://tid.test.com/unitTest11");

  EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), filename11)) << "Error getting test data from '" << filename11 << "'";
  rendered = dcarP->render(DiscoverContextAvailability, JSON, "");
  EXPECT_STREQ(expectedBuf, rendered.c_str());

  dcarP->release();
  EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), emptyFilename)) << "Error getting test data from '" << emptyFilename << "'";
  rendered = dcarP->render(DiscoverContextAvailability, JSON, "");
  EXPECT_STREQ(expectedBuf, rendered.c_str());
  dcarP->release();  // ... otherwise the 500 remains and "pollutes" next tests


  // 12. !entityIdVector +contextRegistrationAttributeVector !registrationMetadataVector +providingApplication
  crrP  = new ContextRegistrationResponse();
  attrP = new ContextRegistrationAttribute("Attr12", "AType", "true");

  crrP->contextRegistration.contextRegistrationAttributeVector.push_back(attrP);
  crrP->contextRegistration.providingApplication.set("http://tid.test.com/unitTest12");
  dcarP->responseVector.push_back(crrP);

  EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), filename12)) << "Error getting test data from '" << filename12 << "'";
  rendered = dcarP->render(DiscoverContextAvailability, JSON, "");
  EXPECT_STREQ(expectedBuf, rendered.c_str());
  // No release here - the data stays - to be used in the following test scenario



  // 13. !entityIdVector +contextRegistrationAttributeVector +registrationMetadataVector +providingApplication
  mdP = new Metadata("M13", "string", "test 13");

  crrP->contextRegistration.registrationMetadataVector.push_back(mdP);

  EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), filename13)) << "Error getting test data from '" << filename13 << "'";
  rendered = dcarP->render(DiscoverContextAvailability, JSON, "");
  EXPECT_STREQ(expectedBuf, rendered.c_str());

  dcarP->release();
  EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), emptyFilename)) << "Error getting test data from '" << emptyFilename << "'";
  rendered = dcarP->render(DiscoverContextAvailability, JSON, "");
  EXPECT_STREQ(expectedBuf, rendered.c_str());
  dcarP->release();  // ... otherwise the 500 remains and "pollutes" next tests


  // 14. +entityIdVector !contextRegistrationAttributeVector !registrationMetadataVector +providingApplication
  crrP  = new ContextRegistrationResponse();
  eidP  = new EntityId("E14", "EType", "false");

  crrP->contextRegistration.entityIdVector.push_back(eidP);
  crrP->contextRegistration.providingApplication.set("http://tid.test.com/unitTest14");
  dcarP->responseVector.push_back(crrP);

  EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), filename14)) << "Error getting test data from '" << filename14 << "'";
  rendered = dcarP->render(DiscoverContextAvailability, JSON, "");
  EXPECT_STREQ(expectedBuf, rendered.c_str());
  // No release here - the data stays - to be used in the following test scenario



  // 15. +entityIdVector !contextRegistrationAttributeVector +registrationMetadataVector +providingApplication
  mdP = new Metadata("M15", "string", "test 15");

  crrP->contextRegistration.registrationMetadataVector.push_back(mdP);
  crrP->contextRegistration.providingApplication.set("http://tid.test.com/unitTest15");

  EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), filename15)) << "Error getting test data from '" << filename15 << "'";
  rendered = dcarP->render(DiscoverContextAvailability, JSON, "");
  EXPECT_STREQ(expectedBuf, rendered.c_str());
  // No release here - the data stays - to be used in the following test scenario 17


  // 17. +entityIdVector +contextRegistrationAttributeVector +registrationMetadataVector +providingApplication
  attrP = new ContextRegistrationAttribute("Attr17", "AType", "true");

  crrP->contextRegistration.contextRegistrationAttributeVector.push_back(attrP);
  crrP->contextRegistration.providingApplication.set("http://tid.test.com/unitTest17");

  EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), filename17)) << "Error getting test data from '" << filename17 << "'";
  rendered = dcarP->render(DiscoverContextAvailability, JSON, "");
  EXPECT_STREQ(expectedBuf, rendered.c_str());

  dcarP->release();
  EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), emptyFilename)) << "Error getting test data from '" << emptyFilename << "'";
  rendered = dcarP->render(DiscoverContextAvailability, JSON, "");
  EXPECT_STREQ(expectedBuf, rendered.c_str());
  dcarP->release();  // ... otherwise the 500 remains and "pollutes" next tests


  // 16. +entityIdVector +contextRegistrationAttributeVector !registrationMetadataVector +providingApplication
  crrP  = new ContextRegistrationResponse();
  eidP  = new EntityId("E16", "EType", "false");
  attrP = new ContextRegistrationAttribute("Attr16", "AType", "true");

  crrP->contextRegistration.entityIdVector.push_back(eidP);
  crrP->contextRegistration.contextRegistrationAttributeVector.push_back(attrP);
  crrP->contextRegistration.providingApplication.set("http://tid.test.com/unitTest16");
  dcarP->responseVector.push_back(crrP);

  EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), filename16)) << "Error getting test data from '" << filename16 << "'";
  rendered = dcarP->render(DiscoverContextAvailability, JSON, "");
  EXPECT_STREQ(expectedBuf, rendered.c_str());

  dcarP->release();
  EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), emptyFilename)) << "Error getting test data from '" << emptyFilename << "'";
  rendered = dcarP->render(DiscoverContextAvailability, JSON, "");
  EXPECT_STREQ(expectedBuf, rendered.c_str());
  dcarP->release();  // ... otherwise the 500 remains and "pollutes" next tests


  // 18. StatusCode
  dcarP->errorCode.fill(SccBadRequest, "DiscoverContextAvailabilityResponse Unit Test 18");

  EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), filename18)) << "Error getting test data from '" << filename18 << "'";
  rendered = dcarP->render(DiscoverContextAvailability, JSON, "");
  EXPECT_STREQ(expectedBuf, rendered.c_str());

  dcarP->release();
  rendered = dcarP->render(DiscoverContextAvailability, JSON, "");
  EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), emptyFilename)) << "Error getting test data from '" << emptyFilename << "'";
  EXPECT_STREQ(expectedBuf, rendered.c_str());
  dcarP->release();  // ... otherwise the 500 remains and "pollutes" next tests


  // 19. StatusCode
  dcarP->errorCode.fill(SccBadRequest);

  EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), filename19)) << "Error getting test data from '" << filename19 << "'";
  rendered = dcarP->render(DiscoverContextAvailability, JSON, "");
  EXPECT_STREQ(expectedBuf, rendered.c_str());

  dcarP->release();
  EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), emptyFilename)) << "Error getting test data from '" << emptyFilename << "'";
  rendered = dcarP->render(DiscoverContextAvailability, JSON, "");
  EXPECT_STREQ(expectedBuf, rendered.c_str());
  dcarP->release();  // ... otherwise the 500 remains and "pollutes" next tests


  // 20. Two ContextRegistrationResponses
  crrP = new ContextRegistrationResponse();
  eidP = new EntityId("E01", "EType", "false");

  crrP->contextRegistration.entityIdVector.push_back(eidP);
  crrP->contextRegistration.providingApplication.set("http://tid.test.com/unitTest");
  dcarP->responseVector.push_back(crrP);

  crrP = new ContextRegistrationResponse();
  eidP = new EntityId("E02", "EType", "false");

  crrP->contextRegistration.entityIdVector.push_back(eidP);
  crrP->contextRegistration.providingApplication.set("http://tid.test.com/unitTest2");
  dcarP->responseVector.push_back(crrP);

  EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), filename20)) << "Error getting test data from '" << filename20 << "'";
  rendered = dcarP->render(DiscoverContextAvailability, JSON, "");
  EXPECT_STREQ(expectedBuf, rendered.c_str());

  dcarP->release();
  EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), emptyFilename)) << "Error getting test data from '" << emptyFilename << "'";
  rendered = dcarP->render(DiscoverContextAvailability, JSON, "");
  EXPECT_STREQ(expectedBuf, rendered.c_str());

  free(dcarP);

  utExit();
}