HHH-8505: Additional test cases

This commit is contained in:
zuchos 2013-10-02 17:37:31 +02:00 committed by adamw
parent c9d4305bf1
commit 2bac8d8cbe
4 changed files with 78 additions and 0 deletions

View File

@ -320,6 +320,19 @@ public class AuditedDynamicComponentsAdvancedCasesTest extends BaseEnversFunctio
//then
Assert.assertEquals( entity, resultList.get( 0 ) );
//when
InternalComponent internalComponent = (InternalComponent) entity.getDynamicConfiguration().get( INTERNAL_COMPONENT );
resultList = getAuditReader().createQuery()
.forEntitiesAtRevision( AdvancedEntity.class, 1 )
.add(
AuditEntity.property( "dynamicConfiguration_" + INTERNAL_COMPONENT+"_property")
.eq( internalComponent.getProperty() )
)
.getResultList();
//then
Assert.assertEquals( entity, resultList.get( 0 ) );
//when
try {
OneToOneEntity oneToOneEntity = (OneToOneEntity) entity.getDynamicConfiguration().get( PROP_ONE_TO_ONE );

View File

@ -9,6 +9,8 @@ public class PlainComponent {
private List<ManyToManyEntity> manyToManyList = new ArrayList<ManyToManyEntity>();
private OneToOneEntity oneToOneEntity;
private ManyToOneEntity manyToOneEntity;
private InternalComponent internalComponent;
private List<InternalComponent> internalComponents;
public String getComponentNote() {
return componentNote;
@ -42,6 +44,22 @@ public class PlainComponent {
this.manyToOneEntity = manyToOneEntity;
}
public InternalComponent getInternalComponent() {
return internalComponent;
}
public void setInternalComponent(InternalComponent internalComponent) {
this.internalComponent = internalComponent;
}
public List<InternalComponent> getInternalComponents() {
return internalComponents;
}
public void setInternalComponents(List<InternalComponent> internalComponents) {
this.internalComponents = internalComponents;
}
@Override
public boolean equals(Object o) {
if ( this == o ) {
@ -56,6 +74,12 @@ public class PlainComponent {
if ( componentNote != null ? !componentNote.equals( that.componentNote ) : that.componentNote != null ) {
return false;
}
if ( internalComponent != null ? !internalComponent.equals( that.internalComponent ) : that.internalComponent != null ) {
return false;
}
if ( internalComponents != null ? !internalComponents.equals( that.internalComponents ) : that.internalComponents != null ) {
return false;
}
if ( manyToManyList != null ? !manyToManyList.equals( that.manyToManyList ) : that.manyToManyList != null ) {
return false;
}
@ -75,6 +99,8 @@ public class PlainComponent {
result = 31 * result + ( manyToManyList != null ? manyToManyList.hashCode() : 0 );
result = 31 * result + ( oneToOneEntity != null ? oneToOneEntity.hashCode() : 0 );
result = 31 * result + ( manyToOneEntity != null ? manyToOneEntity.hashCode() : 0 );
result = 31 * result + ( internalComponent != null ? internalComponent.hashCode() : 0 );
result = 31 * result + ( internalComponents != null ? internalComponents.hashCode() : 0 );
return result;
}
}

View File

@ -54,6 +54,10 @@ public class SanityCheckTest extends BaseEnversFunctionalTestCase {
plainComponent.setComponentNote( "Note" );
plainComponent.setOneToOneEntity( oneToOne );
plainComponent.setManyToOneEntity( manyToOne );
plainComponent.setInternalComponent( new InternalComponent( "Some val" ) );
ArrayList<InternalComponent> internalComponents = new ArrayList<InternalComponent>();
internalComponents.add( new InternalComponent( "test" ) );
plainComponent.setInternalComponents( internalComponents );
PlainEntity plainEntity = new PlainEntity();
plainEntity.setId( 1L );
@ -94,6 +98,29 @@ public class SanityCheckTest extends BaseEnversFunctionalTestCase {
Assert.assertEquals( entity, resultList.get( 0 ) );
}
@Test
public void shouldFindByInternalComponentProperty() {
ManyToOneEntity manyToOne = getManyToOneEntity();
ManyToManyEntity manyToMany = getManyToManyEntity();
OneToOneEntity oneToOne = getOneToOneEntity();
PlainEntity entity = getPlainEntity( manyToOne, manyToMany, oneToOne );
//given (and result of shouldInitData()
//when
List resultList = getAuditReader().createQuery()
.forEntitiesAtRevision( PlainEntity.class, 1 )
.add(
AuditEntity.property( "component_internalComponent_property" )
.eq( entity.getComponent().getInternalComponent().getProperty() )
)
.getResultList();
Assert.assertEquals( entity, resultList.get( 0 ) );
}
@Test
public void shouldFailWhenQueryOnManyToMany() {
ManyToManyEntity manyToMany = getManyToManyEntity();

View File

@ -20,7 +20,19 @@
<many-to-many class="org.hibernate.envers.test.integration.components.dynamic.ManyToManyEntity"
column="MANY_TO_MANY_ID"/>
</list>
<component name="internalComponent"
class="org.hibernate.envers.test.integration.components.dynamic.InternalComponent">
<property name="property" type="string"/>
</component>
<list name="internalComponents">
<key column="PLAIN_ID"/>
<index column="POSITION"/>
<composite-element class="org.hibernate.envers.test.integration.components.dynamic.InternalComponent">
<property name="property" type="string"/>
</composite-element>
</list>
</component>
</class>
<class name="org.hibernate.envers.test.integration.components.dynamic.OneToOneEntity" table="one_to_one_entity">
<id name="id" type="long" column="id"/>