@Test
public void testModelElementToDomElement() throws Exception
{
final MasterConversionService service = Sapphire.service( MasterConversionService.class );
final XmlResourceStore xmlResourceStore = new XmlResourceStore();
final RootXmlResource xmlResource = new RootXmlResource( xmlResourceStore );
final XmlConversionTestElement elementOnXml = XmlConversionTestElement.TYPE.instantiate( xmlResource );
xmlResource.save();
final Element xmlElement = service.convert( elementOnXml, Element.class );
assertNotNull( xmlElement );
assertSame( xmlElement, xmlResource.getXmlElement().getDomNode() );
assertSame( xmlElement, elementOnXml.adapt( Element.class ) );
final XmlConversionTestElement.ListEntry childElement = elementOnXml.getList().insert();
final Element childXmlElement = service.convert( childElement, Element.class );
assertNotNull( childXmlElement );
assertSame( childXmlElement, ( (XmlResource) childElement.resource() ).getXmlElement().getDomNode() );
assertSame( childXmlElement, childElement.adapt( Element.class ) );
assertNotSame( childXmlElement, xmlElement );
final XmlConversionTestElement elementNotOnXml = XmlConversionTestElement.TYPE.instantiate();
assertNull( service.convert( elementNotOnXml, Element.class ) );
assertNull( service.convert( elementNotOnXml.getList().insert(), Element.class ) );
}