/* * 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: BrOrgInfoTest.cpp 795 2006-07-20 13:42:07Z cleber $ */ #include #include #include "libepp_nicbr.H" #include "StrUtil.H" #include "BrOrgInfoTest.H" #include "BrOrgInfo.H" #include "FileUtil.H" #include "IoException.H" #include "XmlException.H" using std::auto_ptr; LIBEPP_NICBR_NS_USE CPPUNIT_TEST_SUITE_REGISTRATION(BrOrgInfoTest); BrOrgInfoTest::BrOrgInfoTest() {} BrOrgInfoTest::~BrOrgInfoTest() {} void BrOrgInfoTest::setUp() {} void BrOrgInfoTest::tearDown() {} void BrOrgInfoTest::set_xml_template_test() { string to_be_parsed = "" "" "" "" "" "$(id)$" "$(auth_info)$" "" "" "" "" "" "$(organization)$" "" "" "" "$(clTRID)$" "" ""; BrOrgInfo br_org_info; BrOrgInfoCmd* br_org_info_cmd = br_org_info.get_command(); br_org_info_cmd->set_id("e654321"); br_org_info_cmd->set_organization("005.506.560/0001-36"); br_org_info.get_command()->set_clTRID("ABC-12345"); br_org_info.set_xml_template(to_be_parsed); string expected = "" "" "" "" "" "e654321" "" "" "" "" "" "005.506.560/0001-36" "" "" "" "ABC-12345" "" ""; CPPUNIT_ASSERT_EQUAL(expected, br_org_info.get_xml()); // tests reset method CPPUNIT_ASSERT(br_org_info_cmd->get_id() != ""); br_org_info_cmd->reset(); CPPUNIT_ASSERT(br_org_info_cmd->get_id() == ""); CPPUNIT_ASSERT(br_org_info_cmd->get_authInfo().get_roid() == ""); CPPUNIT_ASSERT(br_org_info_cmd->get_authInfo().get_pw() == ""); CPPUNIT_ASSERT_EQUAL((string)"", br_org_info_cmd->get_organization()); } void BrOrgInfoTest::command_test() { BrOrgInfo br_org_info; BrOrgInfoCmd *br_org_info_cmd = br_org_info.get_command(); br_org_info_cmd->set_id("cem456"); AuthInfo authInfo; authInfo.set_roid("SH8013-REP"); authInfo.set_pw("2fooBAR"); br_org_info_cmd->set_authInfo(authInfo); br_org_info_cmd->set_organization("005.506.560/0001-36"); bool exception_caught = false; try { string xml_template = FileUtil::read_file("../docs/templates/br_org_info.xml"); br_org_info.get_command()->set_clTRID("ABC-12345"); br_org_info.set_xml_template(xml_template); DomParser parser; parser.enable_validation("../docs/schemas"); parser.parse_command(br_org_info.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 BrOrgInfoTest::response_test() { string expected = "" "" "" "" "Command completed successfully" "" "" "" "e654321" "e654321-REP" "" "" "John Doe" "Example Inc." "" "" "Av. Nações Unidas, 11541" "" "7º andar" "São Paulo" "SP" "04578-000" "BR" "" "" "+55.1155093500" "+55.1155093501" "jdoe@example.com.br" "ClientY" "ClientX" "2005-12-05T12:00:00.0Z" "ClientX" "2005-12-05T12:00:00.0Z" "" "" "" "" "" "" "" "" "" "005.506.560/0001-36" "" "fan" "João Cláudio da Silva" "EDS279" "nic.br" "ptt.br" "registro.br" "" "" "" "ABC-12345" "54322-XYZ" "" "" ""; string utf8_expected; StrUtil::iso88591_to_utf8(expected, utf8_expected); DomParser parser; parser.enable_validation("../docs/schemas"); BrOrgInfo br_org_info; CPPUNIT_ASSERT_NO_THROW(br_org_info.set_response(utf8_expected, &parser)); BrOrgInfoRsp* rsp = br_org_info.get_response(); CommonData::Disclose disclose; CPPUNIT_ASSERT(rsp != 0); string result_code = "1000"; map results; map ::const_iterator r_it; results = rsp->get_result_list(); r_it = results.begin(); CPPUNIT_ASSERT(r_it != results.end()); CPPUNIT_ASSERT_EQUAL(Response::OK, r_it->first); string response = "" "" "" "" "get_result_lang(); if (result_lang != "en") { response += " lang='" + result_lang + "'"; } response += ">" + r_it->second.msg + "" "" "" "" "" + rsp->get_common_data().get_id() + "" "" + rsp->get_roid() + ""; set status_list = rsp->get_status_set(); set::const_iterator it; for (it = status_list.begin(); it != status_list.end(); it++) { response += ""; } vector postal_info = rsp->get_common_data().get_postal_info(); string org; string str2; string str3; string sp; string pc; for (int i = 0; i < (int) postal_info.size(); i++) { if (postal_info[i].get_org() == "") { org = ""; } else { org = "" + postal_info[i].get_org() + ""; } if (postal_info[i].get_str2() == "") { str2 = ""; } else { str2 = "" + postal_info[i].get_str2() + ""; } if (postal_info[i].get_str3() == "") { str3 = ""; } else { str3 = "" + postal_info[i].get_str3() + ""; } if (postal_info[i].get_sp() == "") { sp = ""; } else { sp = "" + postal_info[i].get_sp() + ""; } if (postal_info[i].get_pc() == "") { pc = ""; } else { pc = "" + postal_info[i].get_pc() + ""; } response += "" + "" + postal_info[i].get_name() + "" + org + "" + postal_info[i].get_str1() + "" + str2 + str3 + "" + postal_info[i].get_city() + "" + sp + pc + "" + postal_info[i].get_cc() + ""; } CommonData::Phone voice; voice = rsp->get_common_data().get_voice(); string voice_str; if (strcmp(voice.number.c_str(), "") == 0) { voice_str = ""; } else { if (strcmp(voice.ext.c_str(), "") == 0) voice_str = "" + voice.number + ""; else voice_str = "" + voice.number + ""; response += voice_str; } CommonData::Phone fax; fax = rsp->get_common_data().get_fax(); string fax_str; if (strcmp(fax.number.c_str(), "") == 0) { fax_str = ""; } else { if (strcmp(fax.ext.c_str(), "") == 0) fax_str = "" + fax.number + ""; else fax_str = "" + fax.number + ""; response += fax_str; } response += "" + rsp->get_common_data().get_email() + "" "" + rsp->get_clID() + "" "" + rsp->get_crID() + "" "" + rsp->get_crDate() + "" "" + rsp->get_upID() + "" "" + rsp->get_upDate() + ""; disclose = rsp->get_common_data().get_disclose(); string disclose_str(""); if (disclose.name_int) { disclose_str += ""; } if (disclose.name_loc) { disclose_str += ""; } if (disclose.org_int) { disclose_str += ""; } if (disclose.org_loc) { disclose_str += ""; } if (disclose.addr_int) { disclose_str += ""; } if (disclose.addr_loc) { disclose_str += ""; } if (disclose.voice) { disclose_str += ""; } if (disclose.fax) { disclose_str += ""; } if (disclose.email) { disclose_str += ""; } if (disclose_str != "") { disclose_str = "" + disclose_str + ""; } response += disclose_str + "" ""; //BrOrgInfoRsp extension info response += "" "" //organization "" + rsp->get_organization() + ""; //contacts map< string, string, less > contacts; map< string, string, less >::const_iterator it_contacts; contacts = rsp->get_contact_list(); for (it_contacts = contacts.begin(); it_contacts != contacts.end(); it_contacts++) { response += "" + (*it_contacts).second + ""; } //responsible response += "" + rsp->get_responsible() + ""; //proxy if (rsp->get_proxy() != "") { response += "" + rsp->get_proxy() + ""; } //domain list set fqdns; set::const_iterator it_fqdns; fqdns = rsp->get_domainName_list(); for (it_fqdns = fqdns.begin(); it_fqdns != fqdns.end(); it_fqdns++) { response += "" + (*it_fqdns) + ""; } response += "" ""; response += "" "" + rsp->get_clTRID() + "" "" + rsp->get_svTRID() + "" "" "" ""; CPPUNIT_ASSERT_EQUAL(expected, response); //reset test rsp->reset(); //parent information CPPUNIT_ASSERT_EQUAL((string) "", rsp->get_roid()); CPPUNIT_ASSERT(rsp->get_status_set().empty()); CPPUNIT_ASSERT_EQUAL((string) "", rsp->get_clID()); CPPUNIT_ASSERT_EQUAL((string) "", rsp->get_crID()); CPPUNIT_ASSERT_EQUAL((string) "", rsp->get_crDate()); CPPUNIT_ASSERT_EQUAL((string) "", rsp->get_upID()); CPPUNIT_ASSERT_EQUAL((string) "", rsp->get_upDate()); CPPUNIT_ASSERT_EQUAL((string) "", rsp->get_trDate()); //BrOrgInfoRsp specific information CPPUNIT_ASSERT_EQUAL((string) "", rsp->get_organization()); CPPUNIT_ASSERT_EQUAL((string) "", rsp->get_responsible()); CPPUNIT_ASSERT(rsp->get_contact_list().empty()); CPPUNIT_ASSERT_EQUAL((string) "", rsp->get_proxy()); }