FileDocCategorySizeDatePackage
Dom4jAccessorTest.javaAPI DocHibernate 3.2.55100Tue Dec 12 16:22:26 GMT 2006org.hibernate.test.entitymode.dom4j.accessors

Dom4jAccessorTest

public class Dom4jAccessorTest extends TestCase
Unit test of dom4j-based accessors
author
Steve Ebersole

Fields Summary
public static final org.dom4j.Element
DOM
Constructors Summary
public Dom4jAccessorTest(String name)


	   
		super( name );
	
Methods Summary
private org.hibernate.mapping.PropertygenerateAccountIdProperty()

		SimpleValue value = new SimpleValue();
		value.setTypeName( "long" );

		Property property = new Property();
		property.setName( "number" );
		property.setNodeName( "account/@num" );
		property.setValue( value );

		return property;
	
private org.hibernate.mapping.PropertygenerateIdProperty()

		SimpleValue value = new SimpleValue();
		value.setTypeName( "long" );

		Property property = new Property();
		property.setName( "id" );
		property.setNodeName( "@id" );
		property.setValue( value );

		return property;
	
private org.hibernate.mapping.PropertygenerateNameProperty()

		SimpleValue value = new SimpleValue();
		value.setTypeName( "string" );

		Property property = new Property();
		property.setName( "name" );
		property.setNodeName( "name" );
		property.setValue( value );

		return property;
	
private static org.dom4j.ElementgenerateRootTestElement()

		return DocumentFactory.getInstance().createElement( "company" );
	
private static org.dom4j.ElementgenerateTestElement()

		Element company = generateRootTestElement();
		company.addAttribute( "id", "123" );
		company.setText( "description..." );
		company.addElement( "name" ).setText( "JBoss" );
		company.addElement( "account" ).addAttribute( "num", "456" );

		return company;
	
private org.hibernate.mapping.PropertygenerateTextProperty()

		SimpleValue value = new SimpleValue();
		value.setTypeName( "string" );

		Property property = new Property();
		property.setName( "text" );
		property.setNodeName( "." );
		property.setValue( value );

		return property;
	
private org.hibernate.engine.SessionFactoryImplementorgetSFI()

		return null;
	
public static junit.framework.Testsuite()

		return new TestSuite( Dom4jAccessorTest.class );
	
public voidtestCompanyElementGeneration()

		Setter idSetter = PropertyAccessorFactory.getPropertyAccessor( generateIdProperty(), EntityMode.DOM4J )
				.getSetter( null, null );
		Setter nameSetter = PropertyAccessorFactory.getPropertyAccessor( generateNameProperty(), EntityMode.DOM4J )
				.getSetter( null, null );
		Setter textSetter = PropertyAccessorFactory.getPropertyAccessor( generateTextProperty(), EntityMode.DOM4J )
				.getSetter( null, null );
		Setter accountIdSetter = PropertyAccessorFactory.getPropertyAccessor(
				generateAccountIdProperty(), EntityMode.DOM4J
		)
				.getSetter( null, null );

		Element root = generateRootTestElement();

		idSetter.set( root, new Long( 123 ), getSFI() );
		textSetter.set( root, "description...", getSFI() );
		nameSetter.set( root, "JBoss", getSFI() );
		accountIdSetter.set( root, new Long( 456 ), getSFI() );

		assertTrue( "DOMs not equal", new NodeComparator().compare( DOM, root ) == 0 );
	
public voidtestLongAttributeExtraction()

		Property property = generateIdProperty();
		Getter getter = PropertyAccessorFactory.getPropertyAccessor( property, EntityMode.DOM4J )
				.getGetter( null, null );
		Long id = ( Long ) getter.get( DOM );
		assertEquals( "Not equals", new Long( 123 ), id );
	
public voidtestLongElementAttributeExtraction()

		Property property = generateAccountIdProperty();
		Getter getter = PropertyAccessorFactory.getPropertyAccessor( property, EntityMode.DOM4J )
				.getGetter( null, null );
		Long id = ( Long ) getter.get( DOM );
		assertEquals( "Not equals", new Long( 456 ), id );
	
public voidtestStringElementExtraction()

		Property property = generateNameProperty();
		Getter getter = PropertyAccessorFactory.getPropertyAccessor( property, EntityMode.DOM4J )
				.getGetter( null, null );
		String name = ( String ) getter.get( DOM );
		assertEquals( "Not equals", "JBoss", name );
	
public voidtestStringTextExtraction()

		Property property = generateTextProperty();
		Getter getter = PropertyAccessorFactory.getPropertyAccessor( property, EntityMode.DOM4J )
				.getGetter( null, null );
		String name = ( String ) getter.get( DOM );
		assertEquals( "Not equals", "description...", name );