/* ****************************************************************************
*
* render
*/
TEST(SubscriptionId, render)
{
  SubscriptionId  sId;
  std::string     out;
  const char*     outfile1 = "ngsi.subscriptionId.render1.middle.xml";
  const char*     outfile2 = "ngsi.subscriptionId.render2.middle.xml";
  const char*     outfile3 = "ngsi.subscriptionId.render2.middle.json";

  utInit();

  sId.set("");
  out = sId.render(UnsubscribeContext, XML, ""); // subscriptionId is MANDATORY for RegisterContext 
  EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile1)) << "Error getting test data from '" << outfile1 << "'";
  EXPECT_STREQ(expectedBuf, out.c_str());

  sId.set("012345012345012345012345");
  out = sId.render(UnsubscribeContext, XML, "");
  EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile2)) << "Error getting test data from '" << outfile2 << "'";
  EXPECT_STREQ(expectedBuf, out.c_str());
  
  out = sId.render(UnsubscribeContext, JSON, "");
  EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile3)) << "Error getting test data from '" << outfile3 << "'";
  EXPECT_STREQ(expectedBuf, out.c_str());

  sId.release(); // just to exercise the code

  utExit();
}
/* ****************************************************************************
*
* present - no output expected, just exercising the code
*/
TEST(SubscriptionId, present)
{
  SubscriptionId  sId;

  utInit();

  sId.set("SUB_123");
  sId.present("");

  sId.set("");
  sId.present("");

  utExit();
}
/* ****************************************************************************
*
* constructorsAndRender - 
*/
TEST(UnsubscribeContextAvailabilityResponse, constructorsAndRender)
{
  UnsubscribeContextAvailabilityResponse  ucar1;
  SubscriptionId                          subscriptionId;

  utInit();

  subscriptionId.set("111122223333444455556666");

  UnsubscribeContextAvailabilityResponse  ucar2(subscriptionId);
  StatusCode                              ec(SccBadRequest, "D");
  UnsubscribeContextAvailabilityResponse  ucar3(ec);
  std::string                             out;
  const char*                             outfile = "ngsi9.unsubscribeContextAvailabilityResponse.constructorsAndRender.valid.xml";

  EXPECT_EQ(0,                    ucar1.statusCode.code);
  EXPECT_EQ(subscriptionId.get(), ucar2.subscriptionId.get());
  EXPECT_EQ(SccBadRequest,        ucar3.statusCode.code);

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

  utExit();
}
/* ****************************************************************************
*
* setGetAndIsEmpty - 
*/
TEST(SubscriptionId, setGetAndIsEmpty)
{
  SubscriptionId  sId;
  std::string     out;

  utInit();

  sId.set("SUB_123");
  out = sId.get();
  EXPECT_STREQ("SUB_123", out.c_str());

  EXPECT_FALSE(sId.isEmpty());
  sId.set("");
  EXPECT_TRUE(sId.isEmpty());

  utExit();
}
/* ****************************************************************************
*
* check - 
*/
TEST(SubscriptionId, check)
{
  SubscriptionId  sId;
  std::string     checked;

  utInit();

  sId.set("SUB_123");
  checked = sId.check(RegisterContext, XML, "", "", 0);
  EXPECT_STREQ("bad length (24 chars expected)", checked.c_str());

  sId.set("SUB_12345678901234567890");
  checked = sId.check(RegisterContext, XML, "", "", 0);
  EXPECT_STREQ("invalid char in ID string", checked.c_str());

  sId.set("012345678901234567890123");
  checked = sId.check(RegisterContext, XML, "", "", 0);
  EXPECT_STREQ("OK", checked.c_str());

  utExit();
}
/* ****************************************************************************
*
* constructorsAndRender - 
*
*/
TEST(UnsubscribeContextAvailabilityResponse, constructorsAndRender)
{
  UnsubscribeContextAvailabilityResponse  ucar1;
  SubscriptionId                          subscriptionId;

  utInit();

  subscriptionId.set("111122223333444455556666");

  UnsubscribeContextAvailabilityResponse  ucar2(subscriptionId);
  StatusCode                              ec(SccBadRequest, "D");
  UnsubscribeContextAvailabilityResponse  ucar3(ec);
  std::string                             out;

  EXPECT_EQ(0,                    ucar1.statusCode.code);
  EXPECT_EQ(subscriptionId.get(), ucar2.subscriptionId.get());
  EXPECT_EQ(SccBadRequest,        ucar3.statusCode.code);

  utExit();
}