/* * 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: ContactInfoTest.cpp 720 2006-05-06 21:40:46Z koji $$ */ #include #include #include "libepp_nicbr.H" #include "StrUtil.H" #include "ContactInfoTest.H" #include "ContactInfo.H" #include "FileUtil.H" #include "IoException.H" #include "XmlException.H" using std::auto_ptr; LIBEPP_NICBR_NS_USE CPPUNIT_TEST_SUITE_REGISTRATION(ContactInfoTest); ContactInfoTest::ContactInfoTest() {} ContactInfoTest::~ContactInfoTest() {} void ContactInfoTest::setUp() {} void ContactInfoTest::tearDown() {} void ContactInfoTest::set_xml_template_test() { string to_be_parsed = "" "" "" "$(id)$" "$(auth_info)$" "" "" "$(clTRID)$" ""; ContactInfo contact_info; ContactInfoCmd* contact_info_cmd = contact_info.get_command(); contact_info_cmd->set_id("cem456"); AuthInfo authInfo; authInfo.set_roid("SH8013-REP"); authInfo.set_pw("2fooBAR"); contact_info_cmd->set_authInfo(authInfo); contact_info.get_command()->set_clTRID("ABC-12345"); contact_info.set_xml_template(to_be_parsed); string expected = "" "" "" "cem456" "" "2fooBAR" "" "" "" "ABC-12345" ""; CPPUNIT_ASSERT_EQUAL(expected, contact_info.get_xml()); // tests reset method CPPUNIT_ASSERT(contact_info_cmd->get_id() != ""); CPPUNIT_ASSERT(contact_info_cmd->get_authInfo().get_roid() != ""); CPPUNIT_ASSERT(contact_info_cmd->get_authInfo().get_pw() != ""); contact_info_cmd->reset(); CPPUNIT_ASSERT(contact_info_cmd->get_id() == ""); CPPUNIT_ASSERT(contact_info_cmd->get_authInfo().get_roid() == ""); CPPUNIT_ASSERT(contact_info_cmd->get_authInfo().get_pw() == ""); // parent attribute CPPUNIT_ASSERT(contact_info_cmd->get_clTRID() == ""); } void ContactInfoTest::command_test() { ContactInfo contact_info; ContactInfoCmd *contact_info_cmd = contact_info.get_command(); contact_info_cmd->set_id("cem456"); AuthInfo authInfo; authInfo.set_roid("SH8013-REP"); authInfo.set_pw("2fooBAR"); contact_info_cmd->set_authInfo(authInfo); bool exception_caught = false; try { string xml_template = FileUtil::read_file("../docs/templates/contact_info.xml"); contact_info.get_command()->set_clTRID("ABC-12345"); contact_info.set_xml_template(xml_template); DomParser parser; parser.enable_validation("../docs/schemas"); parser.parse_command(contact_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 ContactInfoTest::response_test() { string expected = "" "" "" "" "Command completed successfully" "" "" "" "cme254" "SH8013-REP" "" "" "" "John Doe" "Example Inc." "" "123 Example Dr." "Suite 100" "Dulles" "VA" "20166-6503" "US" "" "" "" "John Doe" "Other Inc." "" "123 Street" "7th floor" "Suite 123" "Miami" "US" "" "" "+1.7035555555" "+1.7035555556" "jdoe@example.com" "ClientY" "ClientX" "1999-04-03T22:00:00.0Z" "ClientX" "1999-12-03T09:00:00.0Z" "2000-04-08T09:00:00.0Z" "" "2fooBAR" "" "" "" "" "" "" "" "" "ABC-12345" "DEF-54321" "" "" ""; DomParser parser; parser.enable_validation("../docs/schemas"); ContactInfo contact_info; CPPUNIT_ASSERT_NO_THROW(contact_info.set_response(expected, &parser)); ContactInfoRsp* rsp = contact_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() + "" "" + rsp->get_trDate() + ""; AuthInfo authInfo; authInfo = rsp->get_authInfo(); string auth_info_str; response += ""; if (strcmp(authInfo.get_roid().c_str(), "") == 0) { response += "" + authInfo.get_pw() + ""; } else { response += "" + authInfo.get_pw() + ""; } response += ""; 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 + "" "" "" "" + rsp->get_clTRID() + "" "" + rsp->get_svTRID() + "" "" "" ""; CPPUNIT_ASSERT_EQUAL(expected, response); /* Reset Test */ rsp->reset(); 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()); }