*/
// Required element not in TransferObject
try
{
m_formatter.format(message, m_patient, new WriterOutput(writer));
fail("Expected IntegrationException");
}
catch (IntegrationException ex)
{
IntegrationException inner = (IntegrationException)ex.getCause();
assertEquals("err.integration.minPartCount", inner.getErrorCode());
}
// Required element null in TransferObject
player.setValue("lastName", null);
writer = new StringWriter();
try
{
m_formatter.format(message, m_patient, new WriterOutput(writer));
fail("Expected IntegrationException");
}
catch (IntegrationException ex)
{
IntegrationException inner = (IntegrationException)ex.getCause();
assertEquals("err.integration.minPartCount", inner.getErrorCode());
}
// Required element present in TransferObject
player.setValue("lastName", "Test");
writer = new StringWriter();
m_formatter.format(message, m_patient, new WriterOutput(writer));
assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"<a:Patient xmlns:a=\"urn:com.nexjsystems:ns:test:a\" " +
"xmlns:b=\"urn:com.nexjsystems:ns:test:b\" " +
"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:com.nexjsystems:ns:test:a http://www.nexjsystems.com/nexj/integration.xsd urn:com.nexjsystems:ns:test:b http://www.nexjsystems.com/nexj/b.xsd\">" +
"<player><firstName>My1</firstName><lastName>Test</lastName><guid>AQIDBAUGBwgJEBESExQVFg==</guid>" +
"<id type=\"OHIP\" b:id=\"111222333\"/></player></a:Patient>", writer.toString());
// Required element present, Optional element ""
player.setValue("firstName", "");
writer = new StringWriter();
m_formatter.format(message, m_patient, new WriterOutput(writer));
assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"<a:Patient xmlns:a=\"urn:com.nexjsystems:ns:test:a\" " +
"xmlns:b=\"urn:com.nexjsystems:ns:test:b\" " +
"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:com.nexjsystems:ns:test:a http://www.nexjsystems.com/nexj/integration.xsd urn:com.nexjsystems:ns:test:b http://www.nexjsystems.com/nexj/b.xsd\">" +
"<player><firstName></firstName><lastName>Test</lastName><guid>AQIDBAUGBwgJEBESExQVFg==</guid>" +
"<id type=\"OHIP\" b:id=\"111222333\"/></player></a:Patient>", writer.toString());
// Required element present, Optional element null
player.setValue("firstName", null);
writer = new StringWriter();
m_formatter.format(message, m_patient, new WriterOutput(writer));
assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"<a:Patient xmlns:a=\"urn:com.nexjsystems:ns:test:a\" " +
"xmlns:b=\"urn:com.nexjsystems:ns:test:b\" " +
"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:com.nexjsystems:ns:test:a http://www.nexjsystems.com/nexj/integration.xsd urn:com.nexjsystems:ns:test:b http://www.nexjsystems.com/nexj/b.xsd\">" +
"<player><lastName>Test</lastName><guid>AQIDBAUGBwgJEBESExQVFg==</guid>" +
"<id type=\"OHIP\" b:id=\"111222333\"/></player></a:Patient>", writer.toString());
// Required element present, Optional element not present
player.removeValue("firstName");
writer = new StringWriter();
m_formatter.format(message, m_patient, new WriterOutput(writer));
assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"<a:Patient xmlns:a=\"urn:com.nexjsystems:ns:test:a\" " +
"xmlns:b=\"urn:com.nexjsystems:ns:test:b\" " +
"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:com.nexjsystems:ns:test:a http://www.nexjsystems.com/nexj/integration.xsd urn:com.nexjsystems:ns:test:b http://www.nexjsystems.com/nexj/b.xsd\">" +
"<player><lastName>Test</lastName><guid>AQIDBAUGBwgJEBESExQVFg==</guid>" +
"<id type=\"OHIP\" b:id=\"111222333\"/></player></a:Patient>", writer.toString());
/*
* Tests of formatting an element marked nillable.
*/
player.removeValue("lastName");
player.setValue("firstName", "My1");
player.removeValue("title");
// NILLABLE: Optional Nillable element not present
writer = new StringWriter();
m_formatter.format(message, m_patientNillable, new WriterOutput(writer));
assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"<a:Patient xmlns:a=\"urn:com.nexjsystems:ns:test:a\" " +
"xmlns:b=\"urn:com.nexjsystems:ns:test:b\" " +
"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:com.nexjsystems:ns:test:a http://www.nexjsystems.com/nexj/integration.xsd urn:com.nexjsystems:ns:test:b http://www.nexjsystems.com/nexj/b.xsd\">" +
"<player><firstName>My1</firstName><title xsi:nil=\"1\"/><guid>AQIDBAUGBwgJEBESExQVFg==</guid>" +
"<id type=\"OHIP\" b:id=\"111222333\"/><telcom xsi:nil=\"1\"/><telcom2 xsi:nil=\"1\"/></player></a:Patient>", writer.toString());
// NILLABLE: Optional Nillable element set to null
player.setValue("title", null);
writer = new StringWriter();
m_formatter.format(message, m_patientNillable, new WriterOutput(writer));
assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"<a:Patient xmlns:a=\"urn:com.nexjsystems:ns:test:a\" " +
"xmlns:b=\"urn:com.nexjsystems:ns:test:b\" " +
"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:com.nexjsystems:ns:test:a http://www.nexjsystems.com/nexj/integration.xsd urn:com.nexjsystems:ns:test:b http://www.nexjsystems.com/nexj/b.xsd\">" +
"<player><firstName>My1</firstName><title xsi:nil=\"1\"/><guid>AQIDBAUGBwgJEBESExQVFg==</guid>" +
"<id type=\"OHIP\" b:id=\"111222333\"/><telcom xsi:nil=\"1\"/><telcom2 xsi:nil=\"1\"/></player></a:Patient>", writer.toString());
// NILLABLE: Optional Nillable element set
player.setValue("title", "Count");
writer = new StringWriter();
m_formatter.format(message, m_patientNillable, new WriterOutput(writer));
assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"<a:Patient xmlns:a=\"urn:com.nexjsystems:ns:test:a\" " +
"xmlns:b=\"urn:com.nexjsystems:ns:test:b\" " +
"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:com.nexjsystems:ns:test:a http://www.nexjsystems.com/nexj/integration.xsd urn:com.nexjsystems:ns:test:b http://www.nexjsystems.com/nexj/b.xsd\">" +
"<player><firstName>My1</firstName><title>Count</title><guid>AQIDBAUGBwgJEBESExQVFg==</guid>" +
"<id type=\"OHIP\" b:id=\"111222333\"/><telcom xsi:nil=\"1\"/><telcom2 xsi:nil=\"1\"/></player></a:Patient>", writer.toString());
player.removeValue("Count");
// NILLABLE: Composite messages, one with nil mapped, the other one nillable.
telcom = new TransferObject(2);
telcom.setValue("useCode", "HOME");
telcom.setValue("address", "adr1");
player.setValue("telcom", telcom);
telcom2 = new TransferObject(2);
telcom2.setValue("useCode", "WORK");
telcom2.setValue("address", "adr2");
player.setValue("telcom2", telcom2);
telcom3 = new TransferObject(2);
telcom3.setValue("useCode", "CELL");
telcom3.setValue("address", "adr3");
player.setValue("telcom3", telcom3);
writer = new StringWriter();
m_formatter.format(message, m_patientNillable, new WriterOutput(writer));
assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"<a:Patient xmlns:a=\"urn:com.nexjsystems:ns:test:a\" " +
"xmlns:b=\"urn:com.nexjsystems:ns:test:b\" " +
"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:com.nexjsystems:ns:test:a http://www.nexjsystems.com/nexj/integration.xsd urn:com.nexjsystems:ns:test:b http://www.nexjsystems.com/nexj/b.xsd\">" +
"<player><firstName>My1</firstName><title>Count</title><guid>AQIDBAUGBwgJEBESExQVFg==</guid>" +
"<id type=\"OHIP\" b:id=\"111222333\"/>" +
"<telcom useCode=\"HOME\">adr1</telcom>" +
"<telcom2 useCode=\"WORK\">adr2</telcom2>" +
"<telcom3 useCode=\"CELL\">adr3</telcom3>" +
"</player></a:Patient>", writer.toString());
// NILLABLE: Composite messages, one with nil mapped, the other one nillable. Values null.
telcom.setValue("address", null);
telcom2.setValue("address", null);
telcom3.setValue("address", null);
writer = new StringWriter();
m_formatter.format(message, m_patientNillable, new WriterOutput(writer));
assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"<a:Patient xmlns:a=\"urn:com.nexjsystems:ns:test:a\" " +
"xmlns:b=\"urn:com.nexjsystems:ns:test:b\" " +
"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:com.nexjsystems:ns:test:a http://www.nexjsystems.com/nexj/integration.xsd urn:com.nexjsystems:ns:test:b http://www.nexjsystems.com/nexj/b.xsd\">" +
"<player><firstName>My1</firstName><title>Count</title><guid>AQIDBAUGBwgJEBESExQVFg==</guid>" +
"<id type=\"OHIP\" b:id=\"111222333\"/>" +
"<telcom useCode=\"HOME\" xsi:nil=\"1\"/>" +
"<telcom2 useCode=\"WORK\" xsi:nil=\"1\"/>" +
"<telcom3 useCode=\"CELL\"/>" +
"</player></a:Patient>", writer.toString());
// NILLABLE: Composite messages, values not present
telcom.removeValue("address");
telcom2.removeValue("address");
telcom3.removeValue("address");
writer = new StringWriter();
m_formatter.format(message, m_patientNillable, new WriterOutput(writer));
assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"<a:Patient xmlns:a=\"urn:com.nexjsystems:ns:test:a\" " +
"xmlns:b=\"urn:com.nexjsystems:ns:test:b\" " +
"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:com.nexjsystems:ns:test:a http://www.nexjsystems.com/nexj/integration.xsd urn:com.nexjsystems:ns:test:b http://www.nexjsystems.com/nexj/b.xsd\">" +
"<player><firstName>My1</firstName><title>Count</title><guid>AQIDBAUGBwgJEBESExQVFg==</guid>" +
"<id type=\"OHIP\" b:id=\"111222333\"/>" +
"<telcom useCode=\"HOME\" xsi:nil=\"1\"/>" +
"<telcom2 useCode=\"WORK\" xsi:nil=\"1\"/>" +
"<telcom3 useCode=\"CELL\"/>" +
"</player></a:Patient>", writer.toString());
// NILLABLE: Null composite message forces nil attribute
player.setValue("telcom", null);
player.setValue("telcom2", null);
player.setValue("telcom3", null);
writer = new StringWriter();
m_formatter.format(message, m_patientNillable, new WriterOutput(writer));
assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"<a:Patient xmlns:a=\"urn:com.nexjsystems:ns:test:a\" " +
"xmlns:b=\"urn:com.nexjsystems:ns:test:b\" " +
"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:com.nexjsystems:ns:test:a http://www.nexjsystems.com/nexj/integration.xsd urn:com.nexjsystems:ns:test:b http://www.nexjsystems.com/nexj/b.xsd\">" +
"<player><firstName>My1</firstName><title>Count</title><guid>AQIDBAUGBwgJEBESExQVFg==</guid>" +
"<id type=\"OHIP\" b:id=\"111222333\"/>" +
"<telcom xsi:nil=\"1\"/>" +
"<telcom2 xsi:nil=\"1\"/>" +
"<telcom3/>" +
"</player></a:Patient>", writer.toString());
// NILLABLE: Composite messages dropped when not present
player.removeValue("telcom");
player.removeValue("telcom2");
player.removeValue("telcom3");
writer = new StringWriter();
m_formatter.format(message, m_patientNillable, new WriterOutput(writer));
assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"<a:Patient xmlns:a=\"urn:com.nexjsystems:ns:test:a\" " +
"xmlns:b=\"urn:com.nexjsystems:ns:test:b\" " +
"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:com.nexjsystems:ns:test:a http://www.nexjsystems.com/nexj/integration.xsd urn:com.nexjsystems:ns:test:b http://www.nexjsystems.com/nexj/b.xsd\">" +
"<player><firstName>My1</firstName><title>Count</title><guid>AQIDBAUGBwgJEBESExQVFg==</guid>" +