/* * Copyright (C) 2006 Registro.br. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * 1. Redistribution of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY REGISTRO.BR ``AS IS AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIE OF FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO * EVENT SHALL REGISTRO.BR BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * DAMAGE. */ /* $Id: PollTest.cpp 720 2006-05-06 21:40:46Z koji $ */ #include #include "libepp_nicbr.H" #include "PollTest.H" #include "Poll.H" #include "FileUtil.H" #include "IoException.H" #include "XmlException.H" using std::auto_ptr; LIBEPP_NICBR_NS_USE CPPUNIT_TEST_SUITE_REGISTRATION(PollTest); PollTest::PollTest() {} PollTest::~PollTest() {} void PollTest::setUp() {} void PollTest::tearDown() {} void PollTest::set_xml_template_test() { // tests request command string to_be_parsed = "" "" "$(clTRID)$" ""; Poll poll; PollCmd* poll_cmd = poll.get_command(); poll_cmd->set_op("req"); poll_cmd->set_msgID("12345"); poll.get_command()->set_clTRID("ABC-12345"); poll.set_xml_template(to_be_parsed); string expected = "" "" "ABC-12345" ""; // tests acknowledgement command to_be_parsed = "" "" "$(clTRID)$" ""; poll_cmd->reset(); poll_cmd->set_op("ack"); poll_cmd->set_msgID("12345"); poll.get_command()->set_clTRID("ABC-12345"); poll.set_xml_template(to_be_parsed); expected = "" "" "ABC-12345" ""; CPPUNIT_ASSERT(expected == poll.get_xml()); // tests reset method CPPUNIT_ASSERT(poll_cmd->get_op() != ""); CPPUNIT_ASSERT(poll_cmd->get_msgID() != ""); poll_cmd->reset(); CPPUNIT_ASSERT(poll_cmd->get_op() == ""); CPPUNIT_ASSERT(poll_cmd->get_msgID() == ""); // parent attribute CPPUNIT_ASSERT(poll_cmd->get_clTRID() == ""); } void PollTest::command_test() { Poll poll; PollCmd *poll_cmd = poll.get_command(); poll_cmd->set_op("req"); poll_cmd->set_msgID("12345"); bool exception_caught = false; try { string xml_template = FileUtil::read_file("../docs/templates/poll.xml"); poll.get_command()->set_clTRID("ABC-12345"); poll.set_xml_template(xml_template); DomParser parser; parser.enable_validation("../docs/schemas"); parser.parse_command(poll.get_xml()); } catch (const IoException &e) { exception_caught = true; printf("\nIO Exception: code [%d] message [%s]", e.get_code(), e.get_msg().c_str()); } catch (const XmlException &e) { exception_caught = true; printf("\nXml Exception: code [%d] message [%s] low level message [%s]\n", e.get_code(), e.get_msg().c_str(), e.get_low_level_msg().c_str()); } CPPUNIT_ASSERT(!exception_caught); } void PollTest::response_test() { string expected = "" "" "" "" "Command completed successfully; ack to dequeue" "" "" "2000-06-08T22:10:00.0Z" "" "5" "100" "Credit Balance Low" "" "" "" "" "" "btw214" "" "" "mrf348" "In use" "" "" "sht145" "" "" "" "" "ABC-12345" "DEF-54321" "" "" ""; DomParser parser; parser.enable_validation("../docs/schemas"); Poll poll; CPPUNIT_ASSERT_NO_THROW(poll.set_response(expected, &parser)); string result_code = "1301"; PollRsp* poll_rsp = poll.get_response(); map< string, PollRsp::MsgContent, less > content = poll_rsp->get_content(); map< string, PollRsp::MsgContent, less >::const_iterator it; map results; map ::const_iterator r_it; results = poll_rsp->get_result_list(); r_it = results.begin(); CPPUNIT_ASSERT(r_it != results.end()); CPPUNIT_ASSERT_EQUAL(Response::OK_ACK_DEQUEUE, r_it->first); string response = "" "" "" "" "get_result_lang(); if (result_lang != "en") { response += " lang='" + result_lang + "'"; } response += ">" + r_it->second.msg + "" "" "" "" + poll_rsp->get_qDate() + "" "" + poll_rsp->get_text(); for (it = content.begin(); it != content.end(); it++) { string elem_name = (*it).first; PollRsp::MsgContent msg_content = (*it).second; map< string, string, less > attrs = msg_content.attributes; map< string, string, less >::const_iterator attrs_it; response += "<" + elem_name; for (attrs_it = attrs.begin(); attrs_it != attrs.end(); attrs_it++) { string attr_name = (*attrs_it).first; string attr_value = (*attrs_it).second; response += " " + attr_name + "='" + attr_value + "'"; } response += ">" + msg_content.value + ""; } response += "" "" "" ""; CPPUNIT_ASSERT_EQUAL(CONTACT_CHECK, poll_rsp->get_response_type()); ContactCheckRsp *contact_check_rsp = (ContactCheckRsp *)poll_rsp->get_response(); map< string, ContactCheckRsp::Availability, less > avail = contact_check_rsp->get_availability_list(); map< string, ContactCheckRsp::Availability, less >::const_iterator avail_it; for (avail_it = avail.begin(); avail_it != avail.end(); avail_it++) { response += "" + (*avail_it).first + ""; if (strcmp((*avail_it).second.reason.c_str(), "") != 0) { response += "" + (*avail_it).second.reason + ""; } response += ""; } response += "" "" "" "" + poll_rsp->get_clTRID() + "" "" + poll_rsp->get_svTRID() + "" "" "" ""; CPPUNIT_ASSERT_EQUAL(expected, response); /* Reset Test */ CPPUNIT_ASSERT(poll_rsp->get_count() != ""); CPPUNIT_ASSERT(poll_rsp->get_id() != ""); CPPUNIT_ASSERT(poll_rsp->get_lang() != ""); CPPUNIT_ASSERT(poll_rsp->get_response_type() != UNSET_ACTION); CPPUNIT_ASSERT(!poll_rsp->get_content().empty()); poll_rsp->reset(); CPPUNIT_ASSERT(poll_rsp->get_count() == ""); CPPUNIT_ASSERT(poll_rsp->get_id() == ""); CPPUNIT_ASSERT(poll_rsp->get_lang() == "en"); CPPUNIT_ASSERT(poll_rsp->get_text() == ""); CPPUNIT_ASSERT(poll_rsp->get_response_type() == UNSET_ACTION); CPPUNIT_ASSERT(poll_rsp->get_content().empty()); } void PollTest::extension_response_test() { string expected = "" "" "" "" "Command completed successfully; ack to dequeue" "" "" "2000-06-08T22:10:00.0Z" "" "5" "100" "Credit Balance Low" "" "" "" "" "example.com.br" "EXAMPLE1-REP" "" "fan" "fan" "fan" "" "" "ns1.example.com.br" "192.0.2.1" "" "" "ns1.example.net.br" "" "" "ClientX" "ClientX" "2006-01-30T22:00:00.0Z" "ClientX" "2006-01-31T09:00:00.0Z" "" "" "" "" "123456" "" "005.506.560/0001-36" "" "" "" "CNPJ" "2006-03-01T22:00:00.0Z" "" "Cadastro Nacional da Pessoa Jurídica" "" "" "" "" "ns1.example.com.br" "" "2006-02-13T22:00:00.0Z" "" "" "2006-02-01T22:00:00.0Z" "" "" "" "123451" "" "" "123455" "" "" "" "" "ABC-12345" "DEF-54321" "" "" ""; DomParser parser; parser.enable_validation("../docs/schemas"); Poll poll; string expected_utf8; StrUtil::iso88591_to_utf8(expected, expected_utf8); CPPUNIT_ASSERT_NO_THROW(poll.set_response(expected_utf8, &parser)); string result_code = "1301"; PollRsp* poll_rsp = poll.get_response(); map< string, PollRsp::MsgContent, less > content = poll_rsp->get_content(); map< string, PollRsp::MsgContent, less >::const_iterator msg_it; map results; map ::const_iterator r_it; results = poll_rsp->get_result_list(); r_it = results.begin(); CPPUNIT_ASSERT(r_it != results.end()); CPPUNIT_ASSERT_EQUAL(Response::OK_ACK_DEQUEUE, r_it->first); string response = "" "" "" "" "get_result_lang(); if (result_lang != "en") { response += " lang='" + result_lang + "'"; } response += ">" + r_it->second.msg + "" "" "" "" + poll_rsp->get_qDate() + "" "" + poll_rsp->get_text(); for (msg_it = content.begin(); msg_it != content.end(); msg_it++) { string elem_name = (*msg_it).first; PollRsp::MsgContent msg_content = (*msg_it).second; map< string, string, less > attrs = msg_content.attributes; map< string, string, less >::const_iterator attrs_it; response += "<" + elem_name; for (attrs_it = attrs.begin(); attrs_it != attrs.end(); attrs_it++) { string attr_name = (*attrs_it).first; string attr_value = (*attrs_it).second; response += " " + attr_name + "='" + attr_value + "'"; } response += ">" + msg_content.value + ""; } response += "" "" "" ""; CPPUNIT_ASSERT_EQUAL(BR_DOMAIN_INFO, poll_rsp->get_response_type()); BrDomainInfoRsp *br_domain_info_rsp = (BrDomainInfoRsp *)poll_rsp->get_response(); //get_name //get_roid response += "" + br_domain_info_rsp->get_name() + "" "" + br_domain_info_rsp->get_roid() + ""; //get_status_set set status_set = br_domain_info_rsp->get_status_set(); set::const_iterator status_it; for (status_it = status_set.begin(); status_it != status_set.end(); status_it++) { response += ""; } //get_contacts map< string, string, less > contacts = br_domain_info_rsp->get_contacts(); map< string, string, less >::const_iterator it_map; for (it_map = contacts.begin(); it_map != contacts.end(); it_map++) { response += "" + (*it_map).second + ""; } //get_nameservers response += ""; vector nameservers = br_domain_info_rsp->get_nameservers(); vector::const_iterator it_ns; set::const_iterator it_ip; for (it_ns = nameservers.begin(); it_ns != nameservers.end(); it_ns++) { response += "" ; response += "" + it_ns->name + ""; for (it_ip = it_ns->ips.begin(); it_ip != it_ns->ips.end(); it_ip++) { response += ""; } response += ""; } response += ""; //get_clID response += "" + br_domain_info_rsp->get_clID() + ""; //get_crID //get_crDate response += "" + br_domain_info_rsp->get_crID() + "" "" + br_domain_info_rsp->get_crDate() + ""; //get_upID response += "" + br_domain_info_rsp->get_upID() + ""; //get_upDate response += "" + br_domain_info_rsp->get_upDate() + ""; response += "" ""; response += "" "" "" + StrUtil::to_string("%d", br_domain_info_rsp->get_ticketNumber()) + "" "" + br_domain_info_rsp->get_organization() + "" ""; PENDING_CONTAINER doc_pendings = br_domain_info_rsp->get_doc_pendings(); PENDING_CONTAINER::const_iterator doc_it; for (doc_it = doc_pendings.begin(); doc_it != doc_pendings.end(); doc_it++) { response += "" "" + (*doc_it).docType + "" "" + (*doc_it).limit + "" "" ""; } PENDING_CONTAINER dns_pendings = br_domain_info_rsp->get_dns_pendings(); PENDING_CONTAINER::const_iterator dns_it; for (dns_it = dns_pendings.begin(); dns_it != dns_pendings.end(); dns_it++) { response += "" "" + (*dns_it).hostName + "" "" + (*dns_it).limit + "" ""; } struct PendingReleaseProc rel_pending = br_domain_info_rsp->get_rel_pending(); if (rel_pending.status != "") { response += "" "" + rel_pending.limit + "" ""; } response += ""; set concurrent_tickets = br_domain_info_rsp->get_concurrent_tickets(); set::const_iterator tkt_it; for (tkt_it = concurrent_tickets.begin(); tkt_it != concurrent_tickets.end(); tkt_it++) { response += "" + StrUtil::to_string("%d", (*tkt_it)) + ""; } response += "" ""; response += "" "" + poll_rsp->get_clTRID() + "" "" + poll_rsp->get_svTRID() + "" "" "" ""; CPPUNIT_ASSERT_EQUAL(expected, response); } void PollTest::pandata_test() { string expected = "" "" "" "" "Command completed successfully; ack to dequeue" "" "" "1999-04-04T22:01:00.0Z" "Pending action completed successfully." "" "" "" "example.com" "" "ABC-12345" "54321-XYZ" "" "1999-04-04T22:00:00.0Z" "" "" "" "BCD-23456" "65432-WXY" "" "" ""; DomParser parser; parser.enable_validation("../docs/schemas"); Poll poll; CPPUNIT_ASSERT_NO_THROW(poll.set_response(expected, &parser)); string result_code = "1301"; PollRsp* poll_rsp = poll.get_response(); map< string, PollRsp::MsgContent, less > content = poll_rsp->get_content(); map< string, PollRsp::MsgContent, less >::const_iterator msg_it; map results; map ::const_iterator r_it; results = poll_rsp->get_result_list(); r_it = results.begin(); CPPUNIT_ASSERT(r_it != results.end()); CPPUNIT_ASSERT_EQUAL(Response::OK_ACK_DEQUEUE, r_it->first); string response = "" "" "" "" "get_result_lang(); if (result_lang != "en") { response += " lang='" + result_lang + "'"; } response += ">" + r_it->second.msg + "" "" "" "" + poll_rsp->get_qDate() + "" "" + poll_rsp->get_text(); for (msg_it = content.begin(); msg_it != content.end(); msg_it++) { string elem_name = (*msg_it).first; PollRsp::MsgContent msg_content = (*msg_it).second; map< string, string, less > attrs = msg_content.attributes; map< string, string, less >::const_iterator attrs_it; response += "<" + elem_name; for (attrs_it = attrs.begin(); attrs_it != attrs.end(); attrs_it++) { string attr_name = (*attrs_it).first; string attr_value = (*attrs_it).second; response += " " + attr_name + "='" + attr_value + "'"; } response += ">" + msg_content.value + ""; } response += "" ""; // resData CPPUNIT_ASSERT_EQUAL(DOMAIN_PANDATA, poll_rsp->get_response_type()); PanDataRsp * pandata_rsp = (PanDataRsp *)poll_rsp->get_response(); response += "" ""; // domain:name response += ""; } else { response += "0'>"; } response += pandata_rsp->get_object_id() + ""; // domain:paTRID response += ""; string clTRID_pandata = pandata_rsp->get_clTRID(); string svTRID_pandata = pandata_rsp->get_svTRID(); if (clTRID_pandata != "") { response += "" + clTRID_pandata + ""; } response += "" + svTRID_pandata + "" ""; // domain:paDate response += "" + pandata_rsp->get_paDate() + "" "" "" "" "" + poll_rsp->get_clTRID() + "" "" + poll_rsp->get_svTRID() + "" "" "" ""; CPPUNIT_ASSERT_EQUAL(expected, response); } void PollTest::brdomain_pandata_test() { string expected = "" "" "" "" "Command completed successfully; ack to dequeue" "" "" "1999-04-04T22:01:00.0Z" "Pending action completed successfully." "" "" "" "example.com.br" "" "ABC-12345" "54321-XYZ" "" "2006-01-30T22:00:00.0Z" "" "" "" "" "123456" "" "Nao obtivemos uma resposta adequada durante o prazo " "fixado do servidor de DNS (ns1.example.com.br) para o " "presente dominio." "" "" "" "" "BCD-23456" "65432-WXY" "" "" ""; DomParser parser; parser.enable_validation("../docs/schemas"); Poll poll; CPPUNIT_ASSERT_NO_THROW(poll.set_response(expected, &parser)); string result_code = "1301"; PollRsp* poll_rsp = poll.get_response(); map< string, PollRsp::MsgContent, less > content = poll_rsp->get_content(); map< string, PollRsp::MsgContent, less >::const_iterator msg_it; map results; map ::const_iterator r_it; results = poll_rsp->get_result_list(); r_it = results.begin(); CPPUNIT_ASSERT(r_it != results.end()); CPPUNIT_ASSERT_EQUAL(Response::OK_ACK_DEQUEUE, r_it->first); string response = "" "" "" "" "get_result_lang(); if (result_lang != "en") { response += " lang='" + result_lang + "'"; } response += ">" + r_it->second.msg + "" "" "" "" + poll_rsp->get_qDate() + "" "get_lang(); if(msg_lang != "en") { response += " lang='" + msg_lang + "'"; } response += ">" + poll_rsp->get_text(); for (msg_it = content.begin(); msg_it != content.end(); msg_it++) { string elem_name = (*msg_it).first; PollRsp::MsgContent msg_content = (*msg_it).second; map< string, string, less > attrs = msg_content.attributes; map< string, string, less >::const_iterator attrs_it; response += "<" + elem_name; for (attrs_it = attrs.begin(); attrs_it != attrs.end(); attrs_it++) { string attr_name = (*attrs_it).first; string attr_value = (*attrs_it).second; response += " " + attr_name + "='" + attr_value + "'"; } response += ">" + msg_content.value + ""; } response += "" ""; // resData CPPUNIT_ASSERT_EQUAL(BR_DOMAIN_PANDATA, poll_rsp->get_response_type()); BrDomainPanDataRsp * brdomain_pandata_rsp = (BrDomainPanDataRsp *)poll_rsp->get_response(); response += "" ""; // domain:name response += ""; } else { response += "0'>"; } response += brdomain_pandata_rsp->get_object_id() + ""; // domain:paTRID response += ""; string clTRID_pandata = brdomain_pandata_rsp->get_clTRID(); string svTRID_pandata = brdomain_pandata_rsp->get_svTRID(); if (clTRID_pandata != "") { response += "" + clTRID_pandata + ""; } response += "" + svTRID_pandata + "" ""; // domain:paDate response += "" + brdomain_pandata_rsp->get_paDate() + "" "" ""; // brdomain:panData extension response += "" ""; // ticket number response += "" + StrUtil::to_string("%d", brdomain_pandata_rsp->get_ticketNumber()) + ""; string reason = brdomain_pandata_rsp->get_reason(); string reason_lang = brdomain_pandata_rsp->get_reason_lang(); if (reason != "") { response += ""; } response += "" "" "" "" + poll_rsp->get_clTRID() + "" "" + poll_rsp->get_svTRID() + "" "" "" ""; CPPUNIT_ASSERT_EQUAL(expected, response); }