HHH-8505: Query tests
This commit is contained in:
parent
bf469ca0e4
commit
4e810effe5
|
@ -198,13 +198,34 @@ public class AuditedDynamicComponentTest extends BaseEnversFunctionalTestCase {
|
||||||
entity.getCustomFields().put("prop4", true);
|
entity.getCustomFields().put("prop4", true);
|
||||||
|
|
||||||
//when
|
//when
|
||||||
List ver1 = getAuditReader().createQuery()
|
List resultList = getAuditReader().createQuery()
|
||||||
.forEntitiesAtRevision(AuditedDynamicComponentEntity.class, 2)
|
.forEntitiesAtRevision(AuditedDynamicComponentEntity.class, 2)
|
||||||
.add(AuditEntity.property("customFields_prop1").le(20))
|
.add(AuditEntity.property("customFields_prop1").le(20))
|
||||||
.getResultList();
|
.getResultList();
|
||||||
|
|
||||||
//then
|
//then
|
||||||
Assert.assertEquals(entity, ver1.get(0));
|
Assert.assertEquals(entity, resultList.get(0));
|
||||||
|
|
||||||
|
//when
|
||||||
|
resultList = getAuditReader().createQuery()
|
||||||
|
.forEntitiesAtRevision(AuditedDynamicComponentEntity.class, 2)
|
||||||
|
.add(AuditEntity.property("customFields_prop3").eq(new SimpleEntity(1L, "Very simple entity")))
|
||||||
|
.getResultList();
|
||||||
|
|
||||||
|
|
||||||
|
//then
|
||||||
|
entity = (AuditedDynamicComponentEntity) getAuditReader().createQuery()
|
||||||
|
.forEntitiesAtRevision(AuditedDynamicComponentEntity.class, 4)
|
||||||
|
.getResultList().get(0);
|
||||||
|
entity.getCustomFields().put("prop2", null);
|
||||||
|
|
||||||
|
resultList = getAuditReader().createQuery()
|
||||||
|
.forEntitiesAtRevision(AuditedDynamicComponentEntity.class, 5)
|
||||||
|
.add(AuditEntity.property("customFields_prop2").isNull())
|
||||||
|
.getResultList();
|
||||||
|
|
||||||
|
//then
|
||||||
|
Assert.assertEquals(entity, resultList.get(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,16 +1,25 @@
|
||||||
package org.hibernate.envers.test.integration.components.dynamic;
|
package org.hibernate.envers.test.integration.components.dynamic;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
|
import com.google.common.collect.Sets;
|
||||||
import junit.framework.Assert;
|
import junit.framework.Assert;
|
||||||
import org.hibernate.Session;
|
import org.hibernate.Session;
|
||||||
|
import org.hibernate.envers.query.AuditEntity;
|
||||||
import org.hibernate.envers.test.BaseEnversFunctionalTestCase;
|
import org.hibernate.envers.test.BaseEnversFunctionalTestCase;
|
||||||
import org.hibernate.envers.test.Priority;
|
import org.hibernate.envers.test.Priority;
|
||||||
|
import org.hibernate.testing.TestForIssue;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Lukasz Zuchowski (author at zuchos dot com)
|
||||||
|
* More advanced tests for dynamic component.
|
||||||
|
*/
|
||||||
|
@TestForIssue(jiraKey = "HHH-8049")
|
||||||
public class AuditedDynamicComponentsAdvancedCasesTest extends BaseEnversFunctionalTestCase {
|
public class AuditedDynamicComponentsAdvancedCasesTest extends BaseEnversFunctionalTestCase {
|
||||||
|
|
||||||
public static final String PROP_BOOLEAN = "propBoolean";
|
public static final String PROP_BOOLEAN = "propBoolean";
|
||||||
|
@ -22,6 +31,8 @@ public class AuditedDynamicComponentsAdvancedCasesTest extends BaseEnversFunctio
|
||||||
public static final String INTERNAL_LIST = "internalList";
|
public static final String INTERNAL_LIST = "internalList";
|
||||||
public static final String INTERNAL_MAP = "internalMap";
|
public static final String INTERNAL_MAP = "internalMap";
|
||||||
public static final String INTERNAL_MAP_WITH_MANY_TO_MANY = "internalMapWithEntities";
|
public static final String INTERNAL_MAP_WITH_MANY_TO_MANY = "internalMapWithEntities";
|
||||||
|
public static final String INTERNAL_SET = "internalSet";
|
||||||
|
public static final String INTERNAL_SET_OF_COMPONENTS = "internalSetOfComponents";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String[] getMappings() {
|
protected String[] getMappings() {
|
||||||
|
@ -59,13 +70,15 @@ public class AuditedDynamicComponentsAdvancedCasesTest extends BaseEnversFunctio
|
||||||
Map<String, ManyToManyEntity> mapWithManyToMany = new HashMap<String, ManyToManyEntity>();
|
Map<String, ManyToManyEntity> mapWithManyToMany = new HashMap<String, ManyToManyEntity>();
|
||||||
mapWithManyToMany.put("entity1", manyToManyEntity);
|
mapWithManyToMany.put("entity1", manyToManyEntity);
|
||||||
advancedEntity.getDynamicConfiguration().put(INTERNAL_MAP_WITH_MANY_TO_MANY, mapWithManyToMany);
|
advancedEntity.getDynamicConfiguration().put(INTERNAL_MAP_WITH_MANY_TO_MANY, mapWithManyToMany);
|
||||||
|
advancedEntity.getDynamicConfiguration().put(INTERNAL_SET, Sets.newHashSet("Uno", "Due"));
|
||||||
|
advancedEntity.getDynamicConfiguration().put(INTERNAL_SET_OF_COMPONENTS, Sets.newHashSet(new InternalComponent("Ein"), new InternalComponent("Zwei")));
|
||||||
return advancedEntity;
|
return advancedEntity;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Priority(10)
|
@Priority(10)
|
||||||
//smoke test to make sure that hibernate & envers are working with the entity&mappings
|
//smoke test to make sure that hibernate & envers are working with the entity&mappings
|
||||||
public void shouldSaveEntity() {
|
public void shouldInitData() {
|
||||||
//given
|
//given
|
||||||
ManyToOneEntity manyToOne = getManyToOneEntity();
|
ManyToOneEntity manyToOne = getManyToOneEntity();
|
||||||
OneToOneEntity oneToOne = getOneToOneEntity();
|
OneToOneEntity oneToOne = getOneToOneEntity();
|
||||||
|
@ -118,6 +131,13 @@ public class AuditedDynamicComponentsAdvancedCasesTest extends BaseEnversFunctio
|
||||||
session.save(advancedEntity);
|
session.save(advancedEntity);
|
||||||
session.getTransaction().commit();
|
session.getTransaction().commit();
|
||||||
|
|
||||||
|
//rev 7
|
||||||
|
session.getTransaction().begin();
|
||||||
|
Set<InternalComponent> internalComponentSet = (Set) advancedEntity.getDynamicConfiguration().get(INTERNAL_SET_OF_COMPONENTS);
|
||||||
|
internalComponentSet.add(new InternalComponent("drei"));
|
||||||
|
session.save(advancedEntity);
|
||||||
|
session.getTransaction().commit();
|
||||||
|
|
||||||
AdvancedEntity advancedEntityActual = (AdvancedEntity) session.load(AdvancedEntity.class, 1L);
|
AdvancedEntity advancedEntityActual = (AdvancedEntity) session.load(AdvancedEntity.class, 1L);
|
||||||
|
|
||||||
Assert.assertEquals(advancedEntity, advancedEntityActual);
|
Assert.assertEquals(advancedEntity, advancedEntityActual);
|
||||||
|
@ -128,7 +148,7 @@ public class AuditedDynamicComponentsAdvancedCasesTest extends BaseEnversFunctio
|
||||||
public void shouldMakeRevisions() {
|
public void shouldMakeRevisions() {
|
||||||
Session session = openSession();
|
Session session = openSession();
|
||||||
session.getTransaction().begin();
|
session.getTransaction().begin();
|
||||||
//given & when shouldSaveEntity
|
//given & when shouldInitData
|
||||||
ManyToOneEntity manyToOne = getManyToOneEntity();
|
ManyToOneEntity manyToOne = getManyToOneEntity();
|
||||||
OneToOneEntity oneToOne = getOneToOneEntity();
|
OneToOneEntity oneToOne = getOneToOneEntity();
|
||||||
ManyToManyEntity manyToManyEntity = getManyToManyEntity();
|
ManyToManyEntity manyToManyEntity = getManyToManyEntity();
|
||||||
|
@ -197,10 +217,51 @@ public class AuditedDynamicComponentsAdvancedCasesTest extends BaseEnversFunctio
|
||||||
advancedEntity.getId(),
|
advancedEntity.getId(),
|
||||||
6
|
6
|
||||||
);
|
);
|
||||||
Assert.assertEquals(advancedEntity, ver6);
|
|
||||||
|
//then v7
|
||||||
|
Set<InternalComponent> internalComponentSet = (Set) advancedEntity.getDynamicConfiguration().get(INTERNAL_SET_OF_COMPONENTS);
|
||||||
|
internalComponentSet.add(new InternalComponent("drei"));
|
||||||
|
|
||||||
|
AdvancedEntity ver7 = getAuditReader().find(
|
||||||
|
AdvancedEntity.class,
|
||||||
|
advancedEntity.getId(),
|
||||||
|
7
|
||||||
|
);
|
||||||
|
Assert.assertEquals(advancedEntity, ver7);
|
||||||
|
|
||||||
session.getTransaction().commit();
|
session.getTransaction().commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testOfQueryOnDynamicComponent() {
|
||||||
|
//given (and result of shouldInitData()
|
||||||
|
AdvancedEntity entity = getAdvancedEntity(getManyToOneEntity(), getOneToOneEntity(), getManyToManyEntity());
|
||||||
|
|
||||||
|
//when
|
||||||
|
OneToOneEntity oneToOneEntity = (OneToOneEntity) entity.getDynamicConfiguration().get(PROP_ONE_TO_ONE);
|
||||||
|
List resultList = getAuditReader().createQuery()
|
||||||
|
.forEntitiesAtRevision(AuditedDynamicComponentEntity.class, 1)
|
||||||
|
.add(AuditEntity.relatedId("dynamicConfiguration_" + PROP_ONE_TO_ONE).eq(oneToOneEntity.getId()))
|
||||||
|
.getResultList();
|
||||||
|
|
||||||
|
//then
|
||||||
|
Assert.assertEquals(entity, resultList.get(0)); //when
|
||||||
|
|
||||||
|
ManyToOneEntity manyToOneEntity = (ManyToOneEntity) entity.getDynamicConfiguration().get(PROP_MANY_TO_ONE);
|
||||||
|
resultList = getAuditReader().createQuery()
|
||||||
|
.forEntitiesAtRevision(AuditedDynamicComponentEntity.class, 1)
|
||||||
|
.add(AuditEntity.relatedId("manyToOneEntity_" + PROP_MANY_TO_ONE).eq(1L))
|
||||||
|
.getResultList();
|
||||||
|
|
||||||
|
//then
|
||||||
|
Assert.assertEquals(entity, resultList.get(0));
|
||||||
|
|
||||||
|
resultList = getAuditReader().createQuery()
|
||||||
|
.forEntitiesAtRevision(AuditedDynamicComponentEntity.class, 1)
|
||||||
|
.add(AuditEntity.property("dynamicConfiguration_" + INTERNAL_LIST).eq(entity.getDynamicConfiguration().get(INTERNAL_LIST)))
|
||||||
|
.getResultList();
|
||||||
|
|
||||||
|
//then
|
||||||
|
Assert.assertEquals(entity, resultList.get(0));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,10 +29,21 @@
|
||||||
<map-key type="string" column="MAP_KEY"/>
|
<map-key type="string" column="MAP_KEY"/>
|
||||||
<element type="string" column="MAP_VALUE"/>
|
<element type="string" column="MAP_VALUE"/>
|
||||||
</map>
|
</map>
|
||||||
|
<set name="internalSet" table="INTERNAL_SET">
|
||||||
|
<key column="ADVANCED_ID"/>
|
||||||
|
<element type="string" column="SET_VALUE"/>
|
||||||
|
</set>
|
||||||
|
<set name="internalSetOfComponents" table="INTERNAL_SET_OF_COMPS">
|
||||||
|
<key column="ADVANCED_ID"/>
|
||||||
|
<composite-element class="org.hibernate.envers.test.integration.components.dynamic.InternalComponent">
|
||||||
|
<property name="property" type="string" column="PROP_VALUE"/>
|
||||||
|
</composite-element>
|
||||||
|
</set>
|
||||||
<map name="internalMapWithEntities" table="INTERNAL_MAP_WITH_ENTITIES">
|
<map name="internalMapWithEntities" table="INTERNAL_MAP_WITH_ENTITIES">
|
||||||
<key column="ADVANCED_ID"/>
|
<key column="ADVANCED_ID"/>
|
||||||
<map-key type="string" column="MAP_KEY"/>
|
<map-key type="string" column="MAP_KEY"/>
|
||||||
<many-to-many class="org.hibernate.envers.test.integration.components.dynamic.ManyToManyEntity" column="MAP_VAL_MANY_TO_MANY"/>
|
<many-to-many class="org.hibernate.envers.test.integration.components.dynamic.ManyToManyEntity"
|
||||||
|
column="MAP_VAL_MANY_TO_MANY"/>
|
||||||
</map>
|
</map>
|
||||||
</dynamic-component>
|
</dynamic-component>
|
||||||
<!--<one-to-one name="oneToOneEntity" class="org.hibernate.envers.test.integration.components.dynamic.OneToOneEntity"/>-->
|
<!--<one-to-one name="oneToOneEntity" class="org.hibernate.envers.test.integration.components.dynamic.OneToOneEntity"/>-->
|
||||||
|
|
Loading…
Reference in New Issue