indexing description: "Tests the peer group advertisement" license: "MIT license (see ../../license.txt)" author: "Beat Strasser " date: "$Date$" revision: "$Revision$" deferred class TEST_PEERGROUP_ADVERTISEMENT inherit T_ADVERTISEMENT feature -- Tests test_setters is -- Test setters/getters local pga: P2P_PEERGROUP_ADVERTISEMENT tdesc, tname: STRING tmcid: P2P_MODULE_CLASS_ID tmsid: P2P_MODULE_SPECIFICATION_ID txmlcache: P2P_XML_CACHE do -- create peer advertisement tmsid := a_msid create pga.make (gid, tmsid) assert_equal ("group_id", gid, pga.group_id) assert_equal ("unique_id", gid.out_short, pga.unique_id) assert_same ("index_elements.count 1", 2, pga.index_elements.count) assert_true ("match MSID", pga.match ("MSID", tmsid.out)) assert_true ("match MSID", pga.match ("MSID", Void)) assert_true ("match GID", pga.match ("GID", gid.out)) assert_true ("match GID", pga.match ("GID", Void)) assert_false ("match Name", pga.match ("Name", Void)) assert_false ("match Desc", pga.match ("Desc", Void)) -- set name tname := "a Name" pga.set_name (tname) assert_equal ("name", tname, pga.name) assert_same ("index_elements.count 2", 3, pga.index_elements.count) assert_true ("match Name", pga.match ("Name", tname)) assert_true ("match Name", pga.match ("Name", Void)) -- set description tdesc := "a Description" pga.set_description (tdesc) assert_equal ("description", tdesc, pga.description) assert_true ("match Desc", pga.match ("Desc", tdesc)) assert_true ("match Desc", pga.match ("Desc", Void)) -- add service parameter tmcid := a_mcid txmlcache := a_xml_doc pga.add_service_parameter (tmcid, txmlcache) assert ("has_service_parameter 1", pga.has_service_parameter (tmcid)) assert_equal ("service_parameter 1", txmlcache, pga.service_parameter (tmcid)) assert_equal ("service_parameters 1", txmlcache, pga.service_parameters.item (tmcid)) assert_equal ("service_parameters.count 1", 1, pga.service_parameters.count) -- replace service parameter txmlcache := a_xml_doc pga.replace_service_parameter (tmcid, txmlcache) assert_true ("has_service_parameter 2", pga.has_service_parameter (tmcid)) assert_equal ("service_parameter 2", txmlcache, pga.service_parameter (tmcid)) assert_equal ("service_parameters 2", txmlcache, pga.service_parameters.item (tmcid)) assert_equal ("service_parameters.count 2", 1, pga.service_parameters.count) -- remove service parameter pga.remove_service_parameter (tmcid) assert_false ("has_service_parameter 3", pga.has_service_parameter (tmcid)) assert_equal ("service_parameter 3", Void, pga.service_parameter (tmcid)) assert_equal ("service_parameters.count 3", 0, pga.service_parameters.count) end test_document is -- Test document parsing/creating local pga: P2P_PEERGROUP_ADVERTISEMENT source, tname, tdesc, txmldocout: STRING tmsid: P2P_MODULE_SPECIFICATION_ID tmcid: P2P_MODULE_CLASS_ID txmldoc: P2P_XML_CACHE do tname := "Peer Group Name" tdesc := "Peer Group Description" tmsid := a_msid tmcid := a_mcid txmldoc := a_xml_doc txmldoc.document.document.root_element.set_name ("Parm") txmldoc.document.document.root_element.set_namespace (txmldoc.document.namespace_empty) txmldocout := txmldoc.out txmldocout := txmldocout.substring (txmldoc.document.xml_header.count + 1, txmldocout.count) source := "%N% %" + gid.out + "" + tmsid.out + "% %" + tname + "" + tdesc + "% %" + tmcid.out + "" + txmldocout + "" -- parse create pga.parse_from_string (source) assert_true ("is_valid", pga.is_valid) assert_equal ("group_id", gid, pga.group_id) assert_equal ("msid", tmsid, pga.module_specification_id) assert_equal ("name", tname, pga.name) assert_equal ("description", tdesc, pga.description) assert_equal ("service_parameter", txmldoc.out, pga.service_parameter (tmcid).out) -- create pga.clear_document pga.replace_service_parameter (tmcid, txmldoc) assert_equal ("document", source, pga.document.out) end test_general is -- Test general advertisement local pga: P2P_PEERGROUP_ADVERTISEMENT do create pga.make (gid, a_msid) dtest_lifetime (pga) end end