Externalize handling of command serialization

This commit is contained in:
Dirkjan Ochtman 2022-03-10 12:50:09 +01:00 committed by masalachai
parent dd3c60f50e
commit dd07ecc4b8
28 changed files with 110 additions and 293 deletions

View File

@ -126,11 +126,11 @@ impl<C: Connector> EppClient<C> {
Ext: Extension + 'e,
{
let data = data.into();
let epp_xml =
<Cmd as Transaction<Ext>>::serialize_request(data.command, data.extension, id)?;
let document = <Cmd as Transaction<Ext>>::command(data.command, data.extension, id);
let xml = document.serialize()?;
debug!("{}: request: {}", self.connection.registry, &epp_xml);
let response = self.connection.transact(&epp_xml)?.await?;
debug!("{}: request: {}", self.connection.registry, &xml);
let response = self.connection.transact(&xml)?.await?;
debug!("{}: response: {}", self.connection.registry, &response);
match Cmd::deserialize_response(&response) {
@ -169,8 +169,8 @@ impl<C: Connector> EppClient<C> {
#[derive(Debug)]
pub struct RequestData<'c, 'e, C, E> {
command: &'c C,
extension: Option<&'e E>,
pub(crate) command: &'c C,
pub(crate) extension: Option<&'e E>,
}
impl<'c, C: Command> From<&'c C> for RequestData<'c, 'static, C, NoExtension> {

View File

@ -58,19 +58,14 @@ mod tests {
use crate::common::NoExtension;
use crate::request::Transaction;
use crate::response::ResultCode;
use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID};
use crate::tests::{assert_serialized, get_xml, CLTRID, SUCCESS_MSG, SVTRID};
#[test]
fn command() {
let xml = get_xml("request/contact/check.xml").unwrap();
let object = ContactCheck {
contact_ids: &["eppdev-contact-1", "eppdev-contact-2"],
};
let serialized =
<ContactCheck as Transaction<NoExtension>>::serialize_request(&object, None, CLTRID)
.unwrap();
assert_eq!(xml, serialized);
assert_serialized("request/contact/check.xml", &object);
}
#[test]

View File

@ -106,12 +106,10 @@ mod tests {
use crate::contact::Address;
use crate::request::Transaction;
use crate::response::ResultCode;
use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID};
use crate::tests::{assert_serialized, get_xml, CLTRID, SUCCESS_MSG, SVTRID};
#[test]
fn command() {
let xml = get_xml("request/contact/create.xml").unwrap();
let street = &["58", "Orchid Road"];
let address = Address::new(street, "Paris", "Paris", "392374", "FR".parse().unwrap());
let postal_info = PostalInfo::new("int", "John Doe", "Acme Widgets", address);
@ -129,11 +127,7 @@ mod tests {
);
object.set_fax(fax);
let serialized =
<ContactCreate as Transaction<NoExtension>>::serialize_request(&object, None, CLTRID)
.unwrap();
assert_eq!(xml, serialized);
assert_serialized("request/contact/create.xml", &object);
}
#[test]

View File

@ -48,19 +48,12 @@ mod tests {
use crate::common::NoExtension;
use crate::request::Transaction;
use crate::response::ResultCode;
use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID};
use crate::tests::{assert_serialized, get_xml, CLTRID, SUCCESS_MSG, SVTRID};
#[test]
fn command() {
let xml = get_xml("request/contact/delete.xml").unwrap();
let object = ContactDelete::new("eppdev-contact-3");
let serialized =
<ContactDelete as Transaction<NoExtension>>::serialize_request(&object, None, CLTRID)
.unwrap();
assert_eq!(xml, serialized);
assert_serialized("request/contact/delete.xml", &object);
}
#[test]

View File

@ -110,19 +110,12 @@ mod tests {
use crate::common::NoExtension;
use crate::request::Transaction;
use crate::response::ResultCode;
use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID};
use crate::tests::{assert_serialized, get_xml, CLTRID, SUCCESS_MSG, SVTRID};
#[test]
fn command() {
let xml = get_xml("request/contact/info.xml").unwrap();
let object = ContactInfo::new("eppdev-contact-3", "eppdev-387323");
let serialized =
<ContactInfo as Transaction<NoExtension>>::serialize_request(&object, None, CLTRID)
.unwrap();
assert_eq!(xml, serialized);
assert_serialized("request/contact/info.xml", &object);
}
#[test]

View File

@ -112,12 +112,10 @@ mod tests {
use crate::contact::Address;
use crate::request::Transaction;
use crate::response::ResultCode;
use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID};
use crate::tests::{assert_serialized, get_xml, CLTRID, SUCCESS_MSG, SVTRID};
#[test]
fn command() {
let xml = get_xml("request/contact/update.xml").unwrap();
let mut object = ContactUpdate::new("eppdev-contact-3");
let street = &["58", "Orchid Road"];
@ -135,11 +133,7 @@ mod tests {
}];
object.remove(remove_statuses);
let serialized =
<ContactUpdate as Transaction<NoExtension>>::serialize_request(&object, None, CLTRID)
.unwrap();
assert_eq!(xml, serialized);
assert_serialized("request/contact/update.xml", &object);
}
#[test]

View File

@ -56,21 +56,14 @@ mod tests {
use crate::common::NoExtension;
use crate::request::Transaction;
use crate::response::ResultCode;
use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID};
use crate::tests::{assert_serialized, get_xml, CLTRID, SUCCESS_MSG, SVTRID};
#[test]
fn command() {
let xml = get_xml("request/domain/check.xml").unwrap();
let object = DomainCheck {
domains: &["eppdev.com", "eppdev.net"],
};
let serialized =
<DomainCheck as Transaction<NoExtension>>::serialize_request(&object, None, CLTRID)
.unwrap();
assert_eq!(xml, serialized);
assert_serialized("request/domain/check.xml", &object);
}
#[test]

View File

@ -113,12 +113,10 @@ mod tests {
use crate::domain::{HostAttr, HostAttrList, HostObjList};
use crate::request::Transaction;
use crate::response::ResultCode;
use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID};
use crate::tests::{assert_serialized, get_xml, CLTRID, SUCCESS_MSG, SVTRID};
#[test]
fn command() {
let xml = get_xml("request/domain/create.xml").unwrap();
let contacts = &[
DomainContact {
contact_type: "admin".into(),
@ -143,17 +141,11 @@ mod tests {
Some(contacts),
);
let serialized =
<DomainCreate as Transaction<NoExtension>>::serialize_request(&object, None, CLTRID)
.unwrap();
assert_eq!(xml, serialized);
assert_serialized("request/domain/create.xml", &object);
}
#[test]
fn command_with_host_obj() {
let xml = get_xml("request/domain/create_with_host_obj.xml").unwrap();
let contacts = &[
DomainContact {
contact_type: "admin".into(),
@ -179,17 +171,11 @@ mod tests {
Some(contacts),
);
let serialized =
<DomainCreate as Transaction<NoExtension>>::serialize_request(&object, None, CLTRID)
.unwrap();
assert_eq!(xml, serialized);
assert_serialized("request/domain/create_with_host_obj.xml", &object);
}
#[test]
fn command_with_host_attr() {
let xml = get_xml("request/domain/create_with_host_attr.xml").unwrap();
let contacts = &[
DomainContact {
contact_type: "admin".into(),
@ -228,11 +214,7 @@ mod tests {
Some(contacts),
);
let serialized =
<DomainCreate as Transaction<NoExtension>>::serialize_request(&object, None, CLTRID)
.unwrap();
assert_eq!(xml, serialized);
assert_serialized("request/domain/create_with_host_attr.xml", &object);
}
#[test]

View File

@ -48,19 +48,12 @@ mod tests {
use crate::common::NoExtension;
use crate::request::Transaction;
use crate::response::ResultCode;
use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID};
use crate::tests::{assert_serialized, get_xml, CLTRID, SUCCESS_MSG, SVTRID};
#[test]
fn command() {
let xml = get_xml("request/domain/delete.xml").unwrap();
let object = DomainDelete::new("eppdev.com");
let serialized =
<DomainDelete as Transaction<NoExtension>>::serialize_request(&object, None, CLTRID)
.unwrap();
assert_eq!(xml, serialized);
assert_serialized("request/domain/delete.xml", &object);
}
#[test]

View File

@ -136,20 +136,13 @@ mod tests {
use crate::common::NoExtension;
use crate::request::Transaction;
use crate::response::ResultCode;
use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID};
use crate::tests::{assert_serialized, get_xml, CLTRID, SUCCESS_MSG, SVTRID};
use chrono::{TimeZone, Utc};
#[test]
fn command() {
let xml = get_xml("request/domain/info.xml").unwrap();
let object = DomainInfo::new("eppdev.com", Some("2fooBAR"));
let serialized =
<DomainInfo as Transaction<NoExtension>>::serialize_request(&object, None, CLTRID)
.unwrap();
assert_eq!(xml, serialized);
assert_serialized("request/domain/info.xml", &object);
}
#[test]

View File

@ -81,22 +81,15 @@ mod tests {
use crate::common::NoExtension;
use crate::request::Transaction;
use crate::response::ResultCode;
use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID};
use crate::tests::{assert_serialized, get_xml, CLTRID, SUCCESS_MSG, SVTRID};
use chrono::{NaiveDate, TimeZone, Utc};
#[test]
fn command() {
let xml = get_xml("request/domain/renew.xml").unwrap();
let exp_date = NaiveDate::from_ymd(2022, 7, 23);
let object = DomainRenew::new("eppdev.com", exp_date, Period::years(1).unwrap());
let serialized =
<DomainRenew as Transaction<NoExtension>>::serialize_request(&object, None, CLTRID)
.unwrap();
assert_eq!(xml, serialized);
assert_serialized("request/domain/renew.xml", &object);
}
#[test]

View File

@ -139,72 +139,37 @@ mod tests {
use crate::common::NoExtension;
use crate::request::Transaction;
use crate::response::ResultCode;
use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID};
use crate::tests::{assert_serialized, get_xml, CLTRID, SUCCESS_MSG, SVTRID};
#[test]
fn request_command() {
let xml = get_xml("request/domain/transfer_request.xml").unwrap();
let object =
DomainTransfer::new("testing.com", Some(Period::years(1).unwrap()), "epP4uthd#v");
let serialized =
<DomainTransfer as Transaction<NoExtension>>::serialize_request(&object, None, CLTRID)
.unwrap();
assert_eq!(xml, serialized);
assert_serialized("request/domain/transfer_request.xml", &object);
}
#[test]
fn approve_command() {
let xml = get_xml("request/domain/transfer_approve.xml").unwrap();
let object = DomainTransfer::approve("testing.com");
let serialized =
<DomainTransfer as Transaction<NoExtension>>::serialize_request(&object, None, CLTRID)
.unwrap();
assert_eq!(xml, serialized);
assert_serialized("request/domain/transfer_approve.xml", &object);
}
#[test]
fn reject_command() {
let xml = get_xml("request/domain/transfer_reject.xml").unwrap();
let object = DomainTransfer::reject("testing.com");
let serialized =
<DomainTransfer as Transaction<NoExtension>>::serialize_request(&object, None, CLTRID)
.unwrap();
assert_eq!(xml, serialized);
assert_serialized("request/domain/transfer_reject.xml", &object);
}
#[test]
fn cancel_command() {
let xml = get_xml("request/domain/transfer_cancel.xml").unwrap();
let object = DomainTransfer::cancel("testing.com");
let serialized =
<DomainTransfer as Transaction<NoExtension>>::serialize_request(&object, None, CLTRID)
.unwrap();
assert_eq!(xml, serialized);
assert_serialized("request/domain/transfer_cancel.xml", &object);
}
#[test]
fn query_command() {
let xml = get_xml("request/domain/transfer_query.xml").unwrap();
let object = DomainTransfer::query("testing.com", "epP4uthd#v");
let serialized =
<DomainTransfer as Transaction<NoExtension>>::serialize_request(&object, None, CLTRID)
.unwrap();
assert_eq!(xml, serialized);
assert_serialized("request/domain/transfer_query.xml", &object);
}
#[test]

View File

@ -105,12 +105,10 @@ mod tests {
use crate::common::{NoExtension, ObjectStatus};
use crate::request::Transaction;
use crate::response::ResultCode;
use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID};
use crate::tests::{assert_serialized, get_xml, CLTRID, SUCCESS_MSG, SVTRID};
#[test]
fn command() {
let xml = get_xml("request/domain/update.xml").unwrap();
let mut object = DomainUpdate::new("eppdev.com");
let statuses = &[ObjectStatus {
@ -142,12 +140,7 @@ mod tests {
object.add(add);
object.remove(remove);
object.info(change_info);
let serialized =
<DomainUpdate as Transaction<NoExtension>>::serialize_request(&object, None, CLTRID)
.unwrap();
assert_eq!(xml, serialized);
assert_serialized("request/domain/update.xml", &object);
}
#[test]

View File

@ -118,13 +118,10 @@ mod tests {
use super::{GMonthDay, Update};
use crate::domain::update::{DomainChangeInfo, DomainUpdate};
use crate::extensions::consolidate::UpdateWithNameStore;
use crate::request::Transaction;
use crate::tests::{get_xml, CLTRID};
use crate::tests::assert_serialized;
#[test]
fn command() {
let xml = get_xml("request/extensions/consolidate.xml").unwrap();
let exp = GMonthDay::new(5, 31, None).unwrap();
let consolidate_ext = Update::new(exp);
@ -136,20 +133,14 @@ mod tests {
auth_info: None,
});
let serialized = <DomainUpdate as Transaction<Update>>::serialize_request(
&object,
Some(&consolidate_ext),
CLTRID,
)
.unwrap();
assert_eq!(xml, serialized);
assert_serialized(
"request/extensions/consolidate.xml",
(&object, &consolidate_ext),
);
}
#[test]
fn command_with_namestore() {
let xml = get_xml("request/extensions/consolidate_namestore.xml").unwrap();
let exp = GMonthDay::new(5, 31, None).unwrap();
let consolidate_ext = UpdateWithNameStore::new(exp, "com");
@ -161,13 +152,9 @@ mod tests {
auth_info: None,
});
let serialized = <DomainUpdate as Transaction<UpdateWithNameStore>>::serialize_request(
&object,
Some(&consolidate_ext),
CLTRID,
)
.unwrap();
assert_eq!(xml, serialized);
assert_serialized(
"request/extensions/consolidate_namestore.xml",
(&object, &consolidate_ext),
);
}
}

View File

@ -98,26 +98,20 @@ mod tests {
use super::NameStore;
use crate::domain::check::DomainCheck;
use crate::request::Transaction;
use crate::tests::{get_xml, CLTRID};
use crate::tests::{assert_serialized, get_xml};
#[test]
fn command() {
let xml = get_xml("request/extensions/namestore.xml").unwrap();
let namestore_ext = NameStore::new("com");
let object = DomainCheck {
domains: &["example1.com", "example2.com", "example3.com"],
};
let serialized = <DomainCheck as Transaction<NameStore>>::serialize_request(
&object,
Some(&namestore_ext),
CLTRID,
)
.unwrap();
assert_eq!(xml, serialized);
assert_serialized(
"request/extensions/namestore.xml",
(&object, &namestore_ext),
);
}
#[test]

View File

@ -104,13 +104,10 @@ mod tests {
use super::{RgpRestoreReport, Update};
use crate::domain::update::{DomainChangeInfo, DomainUpdate};
use crate::request::Transaction;
use crate::tests::{get_xml, CLTRID};
use crate::tests::assert_serialized;
#[test]
fn command() {
let xml = get_xml("request/extensions/rgp_restore_report.xml").unwrap();
let pre_data =
"Pre-delete registration data goes here. Both XML and free text are allowed.";
let post_data =
@ -119,9 +116,9 @@ mod tests {
let restored_at = DateTime::from_str("2021-07-20T22:00:00.0Z").unwrap();
let restore_reason = "Registrant error.";
let statements = &[
"This registrar has not restored the Registered Name in order to assume the rights to use or sell the Registered Name for itself or for any third party.",
"The information in this report is true to best of this registrar's knowledge, and this registrar acknowledges that intentionally supplying false information in this report shall constitute an incurable material breach of the Registry-Registrar Agreement.",
];
"This registrar has not restored the Registered Name in order to assume the rights to use or sell the Registered Name for itself or for any third party.",
"The information in this report is true to best of this registrar's knowledge, and this registrar acknowledges that intentionally supplying false information in this report shall constitute an incurable material breach of the Registry-Registrar Agreement.",
];
let other = "Supporting information goes here.";
let domain_restore_report = Update {
@ -142,14 +139,9 @@ mod tests {
auth_info: None,
});
let serialized =
<DomainUpdate as Transaction<Update<RgpRestoreReport>>>::serialize_request(
&object,
Some(&domain_restore_report),
CLTRID,
)
.unwrap();
assert_eq!(xml, serialized);
assert_serialized(
"request/extensions/rgp_restore_report.xml",
(&object, &domain_restore_report),
);
}
}

View File

@ -72,12 +72,10 @@ mod tests {
use crate::domain::update::{DomainChangeInfo, DomainUpdate};
use crate::request::Transaction;
use crate::response::ResultCode;
use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID};
use crate::tests::{assert_serialized, get_xml, SUCCESS_MSG, SVTRID};
#[test]
fn request_command() {
let xml = get_xml("request/extensions/rgp_restore_request.xml").unwrap();
let domain_restore_request = Update {
data: RgpRestoreRequest::default(),
};
@ -91,15 +89,10 @@ mod tests {
object.info(change_info);
let serialized =
<DomainUpdate as Transaction<Update<RgpRestoreRequest>>>::serialize_request(
&object,
Some(&domain_restore_request),
CLTRID,
)
.unwrap();
assert_eq!(xml, serialized);
assert_serialized(
"request/extensions/rgp_restore_request.xml",
(&object, &domain_restore_request),
);
}
#[test]

View File

@ -60,21 +60,14 @@ mod tests {
use crate::common::NoExtension;
use crate::request::Transaction;
use crate::response::ResultCode;
use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID};
use crate::tests::{assert_serialized, get_xml, CLTRID, SUCCESS_MSG, SVTRID};
#[test]
fn command() {
let xml = get_xml("request/host/check.xml").unwrap();
let object = HostCheck {
hosts: &["ns1.eppdev-1.com", "host1.eppdev-1.com"],
};
let serialized =
<HostCheck as Transaction<NoExtension>>::serialize_request(&object, None, CLTRID)
.unwrap();
assert_eq!(xml, serialized);
assert_serialized("request/host/check.xml", &object);
}
#[test]

View File

@ -80,24 +80,17 @@ mod tests {
use crate::common::NoExtension;
use crate::request::Transaction;
use crate::response::ResultCode;
use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID};
use crate::tests::{assert_serialized, get_xml, CLTRID, SUCCESS_MSG, SVTRID};
#[test]
fn command() {
let xml = get_xml("request/host/create.xml").unwrap();
let addresses = &[
IpAddr::from([29, 245, 122, 14]),
IpAddr::from([0x2404, 0x6800, 0x4001, 0x801, 0, 0, 0, 0x200e]),
];
let object = HostCreate::new("host1.eppdev-1.com", Some(addresses));
let serialized =
<HostCreate as Transaction<NoExtension>>::serialize_request(&object, None, CLTRID)
.unwrap();
assert_eq!(xml, serialized);
assert_serialized("request/host/create.xml", &object);
}
#[test]

View File

@ -48,19 +48,12 @@ mod tests {
use crate::common::NoExtension;
use crate::request::Transaction;
use crate::response::ResultCode;
use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID};
use crate::tests::{assert_serialized, get_xml, CLTRID, SUCCESS_MSG, SVTRID};
#[test]
fn command() {
let xml = get_xml("request/host/delete.xml").unwrap();
let object = HostDelete::new("ns1.eppdev-1.com");
let serialized =
<HostDelete as Transaction<NoExtension>>::serialize_request(&object, None, CLTRID)
.unwrap();
assert_eq!(xml, serialized);
assert_serialized("request/host/delete.xml", &object);
}
#[test]

View File

@ -112,19 +112,12 @@ mod tests {
use crate::common::NoExtension;
use crate::request::Transaction;
use crate::response::ResultCode;
use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID};
use crate::tests::{assert_serialized, get_xml, CLTRID, SUCCESS_MSG, SVTRID};
#[test]
fn command() {
let xml = get_xml("request/host/info.xml").unwrap();
let object = HostInfo::new("ns1.eppdev-1.com");
let serialized =
<HostInfo as Transaction<NoExtension>>::serialize_request(&object, None, CLTRID)
.unwrap();
assert_eq!(xml, serialized);
assert_serialized("request/host/info.xml", &object);
}
#[test]

View File

@ -97,12 +97,10 @@ mod tests {
use crate::common::{NoExtension, ObjectStatus};
use crate::request::Transaction;
use crate::response::ResultCode;
use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID};
use crate::tests::{assert_serialized, get_xml, CLTRID, SUCCESS_MSG, SVTRID};
#[test]
fn command() {
let xml = get_xml("request/host/update.xml").unwrap();
let addr = &[IpAddr::from([
0x2404, 0x6800, 0x4001, 0x801, 0, 0, 0, 0x200e,
])];
@ -129,11 +127,7 @@ mod tests {
name: "host2.eppdev-1.com".into(),
});
let serialized =
<HostUpdate as Transaction<NoExtension>>::serialize_request(&object, None, CLTRID)
.unwrap();
assert_eq!(xml, serialized);
assert_serialized("request/host/update.xml", &object);
}
#[test]

View File

@ -69,17 +69,13 @@ mod tests {
use super::Login;
use crate::request::Transaction;
use crate::response::ResultCode;
use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID};
use crate::tests::{assert_serialized, get_xml, CLTRID, SUCCESS_MSG, SVTRID};
#[test]
fn command() {
let ext_uris = Some(&["http://schema.ispapi.net/epp/xml/keyvalue-1.0"][..]);
let xml = get_xml("request/login.xml").unwrap();
let object = Login::new("username", "password", ext_uris);
let serialized = object.serialize_request(None, CLTRID).unwrap();
assert_eq!(xml, serialized);
assert_serialized("request/login.xml", &object);
}
#[test]

View File

@ -23,15 +23,12 @@ mod tests {
use super::Logout;
use crate::request::Transaction;
use crate::response::ResultCode;
use crate::tests::{get_xml, CLTRID, SVTRID};
use crate::tests::{assert_serialized, get_xml, CLTRID, SVTRID};
#[test]
fn command() {
let xml = get_xml("request/logout.xml").unwrap();
let object = Logout;
let serialized = object.serialize_request(None, CLTRID).unwrap();
assert_eq!(xml, serialized);
assert_serialized("request/logout.xml", &object);
}
#[test]

View File

@ -36,17 +36,12 @@ mod tests {
use super::MessageAck;
use crate::request::Transaction;
use crate::response::ResultCode;
use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID};
use crate::tests::{assert_serialized, get_xml, SUCCESS_MSG, SVTRID};
#[test]
fn command() {
let xml = get_xml("request/message/ack.xml").unwrap();
let object = MessageAck::new(12345);
let serialized = object.serialize_request(None, CLTRID).unwrap();
assert_eq!(xml, serialized);
assert_serialized("request/message/ack.xml", &object);
}
#[test]

View File

@ -54,20 +54,15 @@ mod tests {
use crate::message::poll::MessageData;
use crate::request::Transaction;
use crate::response::ResultCode;
use crate::tests::{get_xml, CLTRID, SVTRID};
use crate::tests::{assert_serialized, get_xml, CLTRID, SVTRID};
use chrono::{TimeZone, Utc};
use std::net::IpAddr;
#[test]
fn command() {
let xml = get_xml("request/message/poll.xml").unwrap();
let object = MessagePoll::default();
let serialized = object.serialize_request(None, CLTRID).unwrap();
assert_eq!(xml, serialized);
assert_serialized("request/message/poll.xml", &object);
}
#[test]

View File

@ -15,17 +15,17 @@ pub const EPP_LANG: &str = "en";
/// Trait to set correct value for xml tags when tags are being generated from generic types
pub trait Transaction<Ext: Extension>: Command + Sized {
fn serialize_request(
&self,
extension: Option<&Ext>,
client_tr_id: &str,
) -> Result<String, Error> {
<CommandDocument<Self, Ext> as EppXml>::serialize(&CommandDocument::new(CommandWrapper {
fn command<'c, 'e: 'c, 'i: 'c>(
&'c self,
extension: Option<&'e Ext>,
client_tr_id: &'i str,
) -> CommandDocument<'c, Self, Ext> {
CommandDocument::new(CommandWrapper {
command: Self::COMMAND,
data: self,
extension,
client_tr_id: client_tr_id.into(),
}))
})
}
fn deserialize_response(

View File

@ -1,8 +1,15 @@
//! Module for automated tests
use regex::Regex;
use std::{error::Error, fs::File, io::Read};
use regex::Regex;
use crate::{
client::RequestData,
request::{Command, Extension, Transaction},
xml::EppXml,
};
pub(crate) const RESOURCES_DIR: &str = "./tests/resources";
pub(crate) const CLTRID: &str = "cltrid:1626454866";
pub(crate) const SVTRID: &str = "RO-6879-1627224678242975";
@ -27,3 +34,17 @@ pub(crate) fn get_xml(path: &str) -> Result<String, Box<dyn Error>> {
}
Ok(buf)
}
pub(crate) fn assert_serialized<'c, 'e, Cmd, Ext>(
path: &str,
req: impl Into<RequestData<'c, 'e, Cmd, Ext>>,
) where
Cmd: Transaction<Ext> + Command + 'c,
Ext: Extension + 'e,
{
let expected = get_xml(path).unwrap();
let req = req.into();
let document = <Cmd as Transaction<Ext>>::command(req.command, req.extension, CLTRID);
let actual = EppXml::serialize(&document).unwrap();
assert_eq!(expected, actual);
}