/* * 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: BrDomainCheckTest.cpp 720 2006-05-06 21:40:46Z koji $ */ #include #include #include "libepp_nicbr.H" #include "StrUtil.H" #include "BrDomainCheckTest.H" #include "BrDomainCheck.H" #include "FileUtil.H" #include "IoException.H" #include "XmlException.H" using std::auto_ptr; using std::cout; using std::endl; LIBEPP_NICBR_NS_USE CPPUNIT_TEST_SUITE_REGISTRATION(BrDomainCheckTest); BrDomainCheckTest::BrDomainCheckTest() {} BrDomainCheckTest::~BrDomainCheckTest() {} void BrDomainCheckTest::setUp() {} void BrDomainCheckTest::tearDown() {} void BrDomainCheckTest::set_xml_template_test() { string to_be_parsed = "" "" "" "" "" "$(domains_list)$" "" "" "$(extension)$" "$(clTRID)$" "" ""; string expected = "" "" "" "" "" "example.com.br" "example.net.br" "example.org.br" "" "" "" "" "" "005.506.560/0001-36" "" "" "" "ABC-12345" "" ""; BrDomainCheck br_domain_check; BrDomainCheckCmd* br_domain_check_cmd = br_domain_check.get_command(); br_domain_check_cmd->insert_domain("example.com.br"); br_domain_check_cmd->insert_domain("example.net.br"); br_domain_check_cmd->insert_domain("example.org.br"); br_domain_check_cmd->set_organization("005.506.560/0001-36"); br_domain_check.get_command()->set_clTRID("ABC-12345"); br_domain_check.set_xml_template(to_be_parsed); CPPUNIT_ASSERT_EQUAL(expected, br_domain_check.get_xml()); //tests reset method br_domain_check_cmd->reset(); //parent attributes CPPUNIT_ASSERT(br_domain_check_cmd->get_domains_list().empty()); //BrDomainCheckCmd specific attributes CPPUNIT_ASSERT_EQUAL((string)"", br_domain_check_cmd->get_organization()); } void BrDomainCheckTest::command_test() { BrDomainCheck br_domain_check; BrDomainCheckCmd *br_domain_check_cmd = br_domain_check.get_command(); br_domain_check_cmd->insert_domain("registro.br"); br_domain_check_cmd->insert_domain("du.eti.br"); br_domain_check_cmd->insert_domain("nic.br"); br_domain_check_cmd->set_organization("005.506.560/0001-36"); bool exception_caught = false; try { string xml_template = FileUtil::read_file("../docs/templates/br_domain_check.xml"); br_domain_check.get_command()->set_clTRID("ABC-12345"); br_domain_check.set_xml_template(xml_template); DomParser parser; parser.enable_validation("../docs/schemas"); parser.parse_command(br_domain_check.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 BrDomainCheckTest::response_test() { string expected= "" "" "" "" "Command completed successfully" "" "" "" "" "e-xample.net.br" "In use" "" "" "example.com.br" "" "" "example.ind.br" "" "" "example.org.br" "" "" "" "" "" "" "e-xample.net.br" "" "example.net.br" "" "" "043.828.151/0001-45" "" "" "" "example.com.br" "123456" "" "" "example.ind.br" "" "" "example.org.br" "" "043.828.151/0001-45" "" "" "" "" "" "ABC-12345" "54322-XYZ" "" "" ""; DomParser parser; parser.enable_validation("../docs/schemas"); BrDomainCheck br_domain_check; try { br_domain_check.set_response(expected, &parser); } catch (XmlException e) { cout << "[" << e.get_low_level_msg() << "]" << endl; } CPPUNIT_ASSERT_NO_THROW(br_domain_check.set_response(expected, &parser)); BrDomainCheckRsp* br_domain_check_rsp = br_domain_check.get_response(); map results; map ::const_iterator r_it; results = br_domain_check_rsp->get_result_list(); r_it = results.begin(); CPPUNIT_ASSERT(r_it != results.end()); string response = "" "" "" "" "get_result_lang(); if (result_lang != "en") { response += " lang='" + result_lang + "'"; } response += ">" + r_it->second.msg + "" "" "" ""; map< string, DomainCheckRsp::Availability, less > avail; map< string, DomainCheckRsp::Availability, less >::const_iterator av_it; avail = br_domain_check_rsp->get_availability_list(); for (av_it = avail.begin(); av_it != avail.end(); av_it++) { response += "" + (*av_it).first + ""; if ((*av_it).second.reason != "") { response += "" + (*av_it).second.reason + ""; } response += ""; } response += "" ""; //extension job response += "" ""; map< string, BrDomainCheckRsp::Unavailability, less > unavail; map< string, BrDomainCheckRsp::Unavailability, less >::const_iterator unav_it; unavail = br_domain_check_rsp->get_unavailability_list(); for (unav_it = unavail.begin(); unav_it != unavail.end(); unav_it++) { response += "" + (*unav_it).first + ""; // equivalentName if ((*unav_it).second.equivalentName != "") { response += "" + (*unav_it).second.equivalentName + ""; } // organization if ((*unav_it).second.organization != "") { response += "" + (*unav_it).second.organization + ""; } // ticket set set tickets = (*unav_it).second.tickets; set::const_iterator tkt_it; for (tkt_it = tickets.begin(); tkt_it != tickets.end(); tkt_it++) { response += "" + StrUtil::to_string("%d",(*tkt_it)) + ""; } response += ""; } response += ""; response += "" "" + br_domain_check_rsp->get_clTRID() + "" "" + br_domain_check_rsp->get_svTRID() + "" "" "" ""; CPPUNIT_ASSERT_EQUAL(expected, response); //tests reset method br_domain_check_rsp->reset(); //parent attributes CPPUNIT_ASSERT(br_domain_check_rsp->get_availability_list().empty()); //BrDomainCheckRsp specific CPPUNIT_ASSERT(br_domain_check_rsp->get_unavailability_list().empty()); }