/* ****************************************************************************
*
* check_json -
*/
TEST(ContextAttributeResponseVector, check_json)
{
    ContextAttributeResponseVector  carV;
    ContextAttribute                ca("caName", "caType", "caValue");
    ContextAttributeResponse        car;
    std::string                     out;
    const char*                     outfile1 = "ngsi10.contextAttributeResponse.check1.valid.json";
    const char*                     outfile2 = "ngsi10.contextAttributeResponse.check2.valid.json";
    ConnectionInfo                  ci(JSON);

    // 1. ok
    car.contextAttributeVector.push_back(&ca);
    carV.push_back(&car);
    out = carV.check(&ci, UpdateContextAttribute, "", "", 0);
    EXPECT_STREQ("OK", out.c_str());

    // 2. Predetected Error
    out = carV.check(&ci, UpdateContextAttribute, "", "PRE ERROR", 0);
    EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile1)) << "Error getting test data from '" << outfile1 << "'";
    EXPECT_STREQ(expectedBuf, out.c_str());


    // 3. Bad ContextAttribute
    ContextAttribute  ca2("", "caType", "caValue");

    car.contextAttributeVector.push_back(&ca2);
    out = carV.check(&ci, UpdateContextAttribute, "", "", 0);
    EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile2)) << "Error getting test data from '" << outfile2 << "'";
    EXPECT_STREQ(expectedBuf, out.c_str());
}
/* ****************************************************************************
*
* present - just exercise the code
*/
TEST(ContextAttributeResponseVector, present)
{
    ContextAttributeResponseVector  carV;
    ContextAttribute                ca("caName", "caType", "caValue");
    ContextAttributeResponse        car;

    car.contextAttributeVector.push_back(&ca);
    carV.push_back(&car);

    carV.present("");
}
/* ****************************************************************************
*
* release - just exercise the code
*/
TEST(ContextAttributeResponseVector, release)
{
    ContextAttribute*               caP  = new ContextAttribute("caName", "caType", "caValue");
    ContextAttributeResponse*       carP = new ContextAttributeResponse();
    ContextAttributeResponseVector  carV;

    carP->contextAttributeVector.push_back(caP);
    carP->statusCode.fill(SccOk);

    carV.push_back(carP);

    carV.release();
}
/* ****************************************************************************
*
* getAndSize -
*/
TEST(ContextAttributeResponseVector, getAndSize)
{
    ContextAttributeResponse         car;
    ContextAttribute                 ca("caName", "caType", "caValue");
    ContextAttributeResponseVector   carV;

    car.contextAttributeVector.push_back(&ca);

    EXPECT_EQ(0, carV.size());
    carV.push_back(&car);
    ASSERT_EQ(1, carV.size());

    ContextAttributeResponse* carP = carV[0];
    EXPECT_TRUE(carP != NULL);
}
/* ****************************************************************************
*
* render_xml - 
*/
TEST(ContextAttributeResponseVector, render_xml)
{
  ContextAttributeResponseVector  carV;
  ContextAttribute                ca("caName", "caType", "caValue");
  ContextAttributeResponse        car;  
  std::string                     out;
  const char*                     outfile = "ngsi10.contextResponseList.render.invalid.xml";
  ConnectionInfo                  ci;

  // 1. empty vector
  car.statusCode.fill(SccBadRequest, "Empty Vector");
  out = carV.render(&ci, ContextEntityAttributes, "");
  EXPECT_STREQ("", out.c_str());

  // 2. normal case
  car.contextAttributeVector.push_back(&ca);
  carV.push_back(&car);

  out = carV.render(&ci, ContextEntityAttributes, "");
  EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile)) << "Error getting test data from '" << outfile << "'";
  EXPECT_STREQ(expectedBuf, out.c_str());
}