[jboss-envers-commits] JBoss Envers SVN: r119 - in trunk/src: main/org/jboss/envers/entities/mapper/id and 3 other directories.

jboss-envers-commits at lists.jboss.org jboss-envers-commits at lists.jboss.org
Thu Aug 21 09:56:27 EDT 2008


Author: adamw
Date: 2008-08-21 09:56:27 -0400 (Thu, 21 Aug 2008)
New Revision: 119

Added:
   trunk/src/test/org/jboss/envers/test/entities/onetomany/unidirectional/ids/
   trunk/src/test/org/jboss/envers/test/entities/onetomany/unidirectional/ids/SetRefCollEntityEmbId.java
   trunk/src/test/org/jboss/envers/test/entities/onetomany/unidirectional/ids/SetRefCollEntityMulId.java
   trunk/src/test/org/jboss/envers/test/integration/onetomany/unidirectional/BasicNotOwnedSetWithEmbId.java
   trunk/src/test/org/jboss/envers/test/integration/onetomany/unidirectional/BasicNotOwnedSetWithMulId.java
Modified:
   trunk/src/main/org/jboss/envers/configuration/EntitiesConfigurator.java
   trunk/src/main/org/jboss/envers/entities/mapper/id/AbstractCompositeIdMapper.java
   trunk/src/main/org/jboss/envers/entities/mapper/id/AbstractIdMapper.java
   trunk/src/main/org/jboss/envers/entities/mapper/id/EmbeddedIdMapper.java
   trunk/src/main/org/jboss/envers/entities/mapper/id/IdMapper.java
   trunk/src/main/org/jboss/envers/entities/mapper/id/MultipleIdMapper.java
   trunk/src/main/org/jboss/envers/entities/mapper/id/SingleIdMapper.java
Log:
ENVERS-26: tests + bug fix

Modified: trunk/src/main/org/jboss/envers/configuration/EntitiesConfigurator.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/EntitiesConfigurator.java	2008-08-21 11:30:54 UTC (rev 118)
+++ trunk/src/main/org/jboss/envers/configuration/EntitiesConfigurator.java	2008-08-21 13:56:27 UTC (rev 119)
@@ -71,11 +71,11 @@
 
             try {
                 cfg.addDocument(writer.write(mappingData.getMainMapping()));
-                writeDocument(mappingData.getMainMapping());
+                //writeDocument(mappingData.getMainMapping());
 
                 for (Document additionalMapping : mappingData.getAdditionalMappings()) {
                     cfg.addDocument(writer.write(additionalMapping));
-                    writeDocument(additionalMapping);
+                    //writeDocument(additionalMapping);
                 }
             } catch (DocumentException e) {
                 throw new MappingException(e);

Modified: trunk/src/main/org/jboss/envers/entities/mapper/id/AbstractCompositeIdMapper.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/id/AbstractCompositeIdMapper.java	2008-08-21 11:30:54 UTC (rev 118)
+++ trunk/src/main/org/jboss/envers/entities/mapper/id/AbstractCompositeIdMapper.java	2008-08-21 13:56:27 UTC (rev 119)
@@ -25,7 +25,7 @@
 import org.jboss.envers.exception.VersionsException;
 
 import java.util.Map;
-import java.util.HashMap;
+import java.util.LinkedHashMap;
 
 /**
  * @author Adam Warski (adam at warski dot org)
@@ -35,7 +35,7 @@
     protected String compositeIdClass;
 
     protected AbstractCompositeIdMapper(String compositeIdClass) {
-        ids = new HashMap<String, SingleIdMapper>();
+        ids = new LinkedHashMap<String, SingleIdMapper>();
         
         this.compositeIdClass = compositeIdClass;
     }

Modified: trunk/src/main/org/jboss/envers/entities/mapper/id/AbstractIdMapper.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/id/AbstractIdMapper.java	2008-08-21 11:30:54 UTC (rev 118)
+++ trunk/src/main/org/jboss/envers/entities/mapper/id/AbstractIdMapper.java	2008-08-21 13:56:27 UTC (rev 119)
@@ -25,15 +25,15 @@
 import org.hibernate.criterion.Criterion;
 import org.hibernate.criterion.Conjunction;
 
-import java.util.Set;
 import java.util.Iterator;
+import java.util.List;
 
 /**
  * @author Adam Warski (adam at warski dot org)
  */
 public abstract class AbstractIdMapper implements IdMapper {
     public Criterion getIdsEqualCriterion(String prefix1, String prefix2) {
-        Set<QueryParameterData> paramDatas = mapToQueryParametersFromId(null);
+        List<QueryParameterData> paramDatas = mapToQueryParametersFromId(null);
 
         if (paramDatas.size() == 1) {
             QueryParameterData paramData = paramDatas.iterator().next();
@@ -52,7 +52,7 @@
     }
 
     public String getIdsEqualQuery(String prefix1, String prefix2) {
-        Set<QueryParameterData> paramDatas = mapToQueryParametersFromId(null);
+        List<QueryParameterData> paramDatas = mapToQueryParametersFromId(null);
 
         StringBuilder query = new StringBuilder();
 
@@ -70,8 +70,8 @@
     }
 
     public String getIdsEqualQuery(String prefix1, IdMapper mapper2, String prefix2) {
-        Set<QueryParameterData> paramDatas1 = mapToQueryParametersFromId(null);
-        Set<QueryParameterData> paramDatas2 = mapper2.mapToQueryParametersFromId(null);
+        List<QueryParameterData> paramDatas1 = mapToQueryParametersFromId(null);
+        List<QueryParameterData> paramDatas2 = mapper2.mapToQueryParametersFromId(null);
 
         StringBuilder query = new StringBuilder();
 
@@ -91,7 +91,7 @@
     }
 
     public String getIdEqualsQuery(String prefix, boolean equals) {
-        Set<QueryParameterData> paramDatas = mapToQueryParametersFromId(null);
+        List<QueryParameterData> paramDatas = mapToQueryParametersFromId(null);
 
         StringBuilder query = new StringBuilder();
 
@@ -117,7 +117,7 @@
     }
 
     public Criterion getIdEqualsCriterion(Object id, String prefix, boolean equals) {
-        Set<QueryParameterData> paramDatas = mapToQueryParametersFromId(id);
+        List<QueryParameterData> paramDatas = mapToQueryParametersFromId(id);
 
         if (paramDatas.size() == 1) {
             QueryParameterData paramData = paramDatas.iterator().next();

Modified: trunk/src/main/org/jboss/envers/entities/mapper/id/EmbeddedIdMapper.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/id/EmbeddedIdMapper.java	2008-08-21 11:30:54 UTC (rev 118)
+++ trunk/src/main/org/jboss/envers/entities/mapper/id/EmbeddedIdMapper.java	2008-08-21 13:56:27 UTC (rev 119)
@@ -27,10 +27,7 @@
 import org.jboss.envers.exception.VersionsException;
 import org.jboss.envers.tools.reflection.ReflectionTools;
 
-import java.util.Map;
-import java.util.Set;
-import java.util.HashMap;
-import java.util.HashSet;
+import java.util.*;
 
 /**
  * @author Adam Warski (adam at warski dot org)
@@ -98,11 +95,11 @@
         return getter.get(data);
     }
 
-    public Set<QueryParameterData> mapToQueryParametersFromId(Object obj) {
-        Map<String, Object> data = new HashMap<String, Object>();
+    public List<QueryParameterData> mapToQueryParametersFromId(Object obj) {
+        Map<String, Object> data = new LinkedHashMap<String, Object>();
         mapToMapFromId(data, obj);
 
-        Set<QueryParameterData> ret = new HashSet<QueryParameterData>();
+        List<QueryParameterData> ret = new ArrayList<QueryParameterData>();
 
         for (String propertyName : data.keySet()) {
             ret.add(new QueryParameterData(propertyName, data.get(propertyName)));

Modified: trunk/src/main/org/jboss/envers/entities/mapper/id/IdMapper.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/id/IdMapper.java	2008-08-21 11:30:54 UTC (rev 118)
+++ trunk/src/main/org/jboss/envers/entities/mapper/id/IdMapper.java	2008-08-21 13:56:27 UTC (rev 119)
@@ -24,13 +24,12 @@
 import org.hibernate.criterion.Criterion;
 
 import java.util.Map;
-import java.util.Set;
+import java.util.List;
 
 /**
  * @author Adam Warski (adam at warski dot org)
  */
 public interface IdMapper {
-
     public void mapToMapFromId(Map<String, Object> data, Object obj);
 
     public void mapToMapFromEntity(Map<String, Object> data, Object obj);
@@ -53,7 +52,7 @@
      * @param obj Id from which to map.
      * @return A set parameter data, needed to build a query basing on the given id.
      */
-    public Set<QueryParameterData> mapToQueryParametersFromId(Object obj);
+    public List<QueryParameterData> mapToQueryParametersFromId(Object obj);
 
     /**
      * Gets a criteria object, which contains restrictions, which express the property that the id of the entity

Modified: trunk/src/main/org/jboss/envers/entities/mapper/id/MultipleIdMapper.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/id/MultipleIdMapper.java	2008-08-21 11:30:54 UTC (rev 118)
+++ trunk/src/main/org/jboss/envers/entities/mapper/id/MultipleIdMapper.java	2008-08-21 13:56:27 UTC (rev 119)
@@ -23,10 +23,7 @@
 
 import org.jboss.envers.exception.VersionsException;
 
-import java.util.Map;
-import java.util.Set;
-import java.util.HashMap;
-import java.util.HashSet;
+import java.util.*;
 
 /**
  * @author Adam Warski (adam at warski dot org)
@@ -81,11 +78,11 @@
         return ret;
     }
 
-    public Set<QueryParameterData> mapToQueryParametersFromId(Object obj) {
-        Map<String, Object> data = new HashMap<String, Object>();
+    public List<QueryParameterData> mapToQueryParametersFromId(Object obj) {
+        Map<String, Object> data = new LinkedHashMap<String, Object>();
         mapToMapFromId(data, obj);
 
-        Set<QueryParameterData> ret = new HashSet<QueryParameterData>();
+        List<QueryParameterData> ret = new ArrayList<QueryParameterData>();
 
         for (String propertyName : data.keySet()) {
             ret.add(new QueryParameterData(propertyName, data.get(propertyName)));

Modified: trunk/src/main/org/jboss/envers/entities/mapper/id/SingleIdMapper.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/id/SingleIdMapper.java	2008-08-21 11:30:54 UTC (rev 118)
+++ trunk/src/main/org/jboss/envers/entities/mapper/id/SingleIdMapper.java	2008-08-21 13:56:27 UTC (rev 119)
@@ -27,9 +27,7 @@
 import org.hibernate.property.Setter;
 import org.hibernate.property.Getter;
 
-import java.util.Map;
-import java.util.Set;
-import java.util.HashSet;
+import java.util.*;
 
 /**
  * @author Adam Warski (adam at warski dot org)
@@ -115,8 +113,8 @@
         return new SingleIdMapper(propertyName, prefix + propertyName);
     }
 
-    public Set<QueryParameterData> mapToQueryParametersFromId(Object obj) {
-        Set<QueryParameterData> ret = new HashSet<QueryParameterData>();
+    public List<QueryParameterData> mapToQueryParametersFromId(Object obj) {
+        List<QueryParameterData> ret = new ArrayList<QueryParameterData>();
 
         ret.add(new QueryParameterData(propertyName, obj));
 

Copied: trunk/src/test/org/jboss/envers/test/entities/onetomany/unidirectional/ids/SetRefCollEntityEmbId.java (from rev 117, trunk/src/test/org/jboss/envers/test/entities/onetomany/unidirectional/SetRefCollEntity.java)
===================================================================
--- trunk/src/test/org/jboss/envers/test/entities/onetomany/unidirectional/ids/SetRefCollEntityEmbId.java	                        (rev 0)
+++ trunk/src/test/org/jboss/envers/test/entities/onetomany/unidirectional/ids/SetRefCollEntityEmbId.java	2008-08-21 13:56:27 UTC (rev 119)
@@ -0,0 +1,86 @@
+package org.jboss.envers.test.entities.onetomany.unidirectional.ids;
+
+import org.jboss.envers.Versioned;
+import org.jboss.envers.test.entities.ids.EmbId;
+import org.jboss.envers.test.entities.ids.EmbIdTestEntity;
+
+import javax.persistence.Entity;
+import javax.persistence.OneToMany;
+import javax.persistence.EmbeddedId;
+import java.util.Set;
+
+/**
+ * Set collection of references entity
+ * @author Adam Warski (adam at warski dot org)
+ */
+ at Entity
+public class SetRefCollEntityEmbId {
+    @EmbeddedId
+    private EmbId id;
+
+    @Versioned
+    private String data;
+
+    @Versioned
+    @OneToMany
+    private Set<EmbIdTestEntity> collection;
+
+    public SetRefCollEntityEmbId() {
+    }
+
+    public SetRefCollEntityEmbId(EmbId id, String data) {
+        this.id = id;
+        this.data = data;
+    }
+
+    public SetRefCollEntityEmbId(String data) {
+        this.data = data;
+    }
+
+    public EmbId getId() {
+        return id;
+    }
+
+    public void setId(EmbId id) {
+        this.id = id;
+    }
+
+    public String getData() {
+        return data;
+    }
+
+    public void setData(String data) {
+        this.data = data;
+    }
+
+    public Set<EmbIdTestEntity> getCollection() {
+        return collection;
+    }
+
+    public void setCollection(Set<EmbIdTestEntity> collection) {
+        this.collection = collection;
+    }
+
+    public boolean equals(Object o) {
+        if (this == o) return true;
+        if (!(o instanceof SetRefCollEntityEmbId)) return false;
+
+        SetRefCollEntityEmbId that = (SetRefCollEntityEmbId) o;
+
+        if (data != null ? !data.equals(that.data) : that.data != null) return false;
+        if (id != null ? !id.equals(that.id) : that.id != null) return false;
+
+        return true;
+    }
+
+    public int hashCode() {
+        int result;
+        result = (id != null ? id.hashCode() : 0);
+        result = 31 * result + (data != null ? data.hashCode() : 0);
+        return result;
+    }
+
+    public String toString() {
+        return "SetRefCollEntityEmbId(id = " + id + ", data = " + data + ")";
+    }
+}
\ No newline at end of file


Property changes on: trunk/src/test/org/jboss/envers/test/entities/onetomany/unidirectional/ids/SetRefCollEntityEmbId.java
___________________________________________________________________
Name: svn:mergeinfo
   + 

Added: trunk/src/test/org/jboss/envers/test/entities/onetomany/unidirectional/ids/SetRefCollEntityMulId.java
===================================================================
--- trunk/src/test/org/jboss/envers/test/entities/onetomany/unidirectional/ids/SetRefCollEntityMulId.java	                        (rev 0)
+++ trunk/src/test/org/jboss/envers/test/entities/onetomany/unidirectional/ids/SetRefCollEntityMulId.java	2008-08-21 13:56:27 UTC (rev 119)
@@ -0,0 +1,99 @@
+package org.jboss.envers.test.entities.onetomany.unidirectional.ids;
+
+import org.jboss.envers.Versioned;
+import org.jboss.envers.test.entities.ids.MulIdTestEntity;
+import org.jboss.envers.test.entities.ids.MulId;
+
+import javax.persistence.*;
+import java.util.Set;
+
+/**
+ * Set collection of references entity
+ * @author Adam Warski (adam at warski dot org)
+ */
+ at Entity
+ at IdClass(MulId.class)
+public class SetRefCollEntityMulId {
+    @Id
+    private Integer id1;
+
+    @Id
+    private Integer id2;
+
+    @Versioned
+    private String data;
+
+    @Versioned
+    @OneToMany
+    private Set<MulIdTestEntity> collection;
+
+    public SetRefCollEntityMulId() {
+    }
+
+    public SetRefCollEntityMulId(Integer id1, Integer id2, String data) {
+        this.id1 = id1;
+        this.id2 = id2;
+        this.data = data;
+    }
+
+    public SetRefCollEntityMulId(String data) {
+        this.data = data;
+    }
+
+    public Integer getId1() {
+        return id1;
+    }
+
+    public void setId1(Integer id1) {
+        this.id1 = id1;
+    }
+
+    public Integer getId2() {
+        return id2;
+    }
+
+    public void setId2(Integer id2) {
+        this.id2 = id2;
+    }
+
+    public String getData() {
+        return data;
+    }
+
+    public void setData(String data) {
+        this.data = data;
+    }
+
+    public Set<MulIdTestEntity> getCollection() {
+        return collection;
+    }
+
+    public void setCollection(Set<MulIdTestEntity> collection) {
+        this.collection = collection;
+    }
+
+    public boolean equals(Object o) {
+        if (this == o) return true;
+        if (!(o instanceof SetRefCollEntityMulId)) return false;
+
+        SetRefCollEntityMulId that = (SetRefCollEntityMulId) o;
+
+        if (data != null ? !data.equals(that.data) : that.data != null) return false;
+        if (id1 != null ? !id1.equals(that.id1) : that.id1 != null) return false;
+        if (id2 != null ? !id2.equals(that.id2) : that.id2 != null) return false;
+
+        return true;
+    }
+
+    public int hashCode() {
+        int result;
+        result = (id1 != null ? id1.hashCode() : 0);
+        result = 31 * result + (id2 != null ? id2.hashCode() : 0);
+        result = 31 * result + (data != null ? data.hashCode() : 0);
+        return result;
+    }
+
+    public String toString() {
+        return "SetRefCollEntityMulId(id1 = " + id1 + ", id2 = " + id2 + ", data = " + data + ")";
+    }
+}
\ No newline at end of file

Copied: trunk/src/test/org/jboss/envers/test/integration/onetomany/unidirectional/BasicNotOwnedSetWithEmbId.java (from rev 118, trunk/src/test/org/jboss/envers/test/integration/onetomany/unidirectional/BasicNotOwnedSet.java)
===================================================================
--- trunk/src/test/org/jboss/envers/test/integration/onetomany/unidirectional/BasicNotOwnedSetWithEmbId.java	                        (rev 0)
+++ trunk/src/test/org/jboss/envers/test/integration/onetomany/unidirectional/BasicNotOwnedSetWithEmbId.java	2008-08-21 13:56:27 UTC (rev 119)
@@ -0,0 +1,114 @@
+package org.jboss.envers.test.integration.onetomany.unidirectional;
+
+import org.jboss.envers.test.integration.AbstractEntityTest;
+import org.jboss.envers.test.entities.onetomany.unidirectional.ids.SetRefCollEntityEmbId;
+import org.jboss.envers.test.entities.ids.EmbIdTestEntity;
+import org.jboss.envers.test.entities.ids.EmbId;
+import org.jboss.envers.test.tools.TestTools;
+import org.hibernate.ejb.Ejb3Configuration;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import javax.persistence.EntityManager;
+import java.util.Arrays;
+import java.util.HashSet;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class BasicNotOwnedSetWithEmbId extends AbstractEntityTest {
+    private EmbId str1_id;
+    private EmbId str2_id;
+
+    private EmbId coll1_id;
+
+    public void configure(Ejb3Configuration cfg) {
+        cfg.addAnnotatedClass(EmbIdTestEntity.class);
+        cfg.addAnnotatedClass(SetRefCollEntityEmbId.class);
+    }
+
+    @BeforeClass(dependsOnMethods = "init")
+    public void initData() {
+        EntityManager em = getEntityManager();
+
+        str1_id = new EmbId(1, 2);
+        str2_id = new EmbId(3, 4);
+
+        coll1_id = new EmbId(5, 6);
+
+        EmbIdTestEntity str1 = new EmbIdTestEntity(str1_id, "str1");
+        EmbIdTestEntity str2 = new EmbIdTestEntity(str2_id, "str2");
+
+        SetRefCollEntityEmbId coll1 = new SetRefCollEntityEmbId(coll1_id, "coll1");
+
+        // Revision 1
+        em.getTransaction().begin();
+
+        em.persist(str1);
+        em.persist(str2);
+
+        coll1.setCollection(new HashSet<EmbIdTestEntity>());
+        coll1.getCollection().add(str1);
+        em.persist(coll1);
+
+        em.getTransaction().commit();
+
+        // Revision 2
+        em.getTransaction().begin();
+
+        str2 = em.find(EmbIdTestEntity.class, str2.getId());
+        coll1 = em.find(SetRefCollEntityEmbId.class, coll1.getId());
+
+        coll1.getCollection().add(str2);
+
+        em.getTransaction().commit();
+
+        // Revision 3
+        em.getTransaction().begin();
+
+        str1 = em.find(EmbIdTestEntity.class, str1.getId());
+        coll1 = em.find(SetRefCollEntityEmbId.class, coll1.getId());
+
+        coll1.getCollection().remove(str1);
+
+        em.getTransaction().commit();
+
+        // Revision 4
+        em.getTransaction().begin();
+
+        coll1 = em.find(SetRefCollEntityEmbId.class, coll1.getId());
+
+        coll1.getCollection().clear();
+
+        em.getTransaction().commit();
+    }
+
+    @Test
+    public void testRevisionsCounts() {
+        assert Arrays.asList(1, 2, 3, 4).equals(getVersionsReader().getRevisions(SetRefCollEntityEmbId.class, coll1_id));
+
+        assert Arrays.asList(1).equals(getVersionsReader().getRevisions(EmbIdTestEntity.class, str1_id));
+        assert Arrays.asList(1).equals(getVersionsReader().getRevisions(EmbIdTestEntity.class, str2_id));
+    }
+
+    @Test
+    public void testHistoryOfColl1() {
+        EmbIdTestEntity str1 = getEntityManager().find(EmbIdTestEntity.class, str1_id);
+        EmbIdTestEntity str2 = getEntityManager().find(EmbIdTestEntity.class, str2_id);
+
+        SetRefCollEntityEmbId rev1 = getVersionsReader().find(SetRefCollEntityEmbId.class, coll1_id, 1);
+        SetRefCollEntityEmbId rev2 = getVersionsReader().find(SetRefCollEntityEmbId.class, coll1_id, 2);
+        SetRefCollEntityEmbId rev3 = getVersionsReader().find(SetRefCollEntityEmbId.class, coll1_id, 3);
+        SetRefCollEntityEmbId rev4 = getVersionsReader().find(SetRefCollEntityEmbId.class, coll1_id, 4);
+
+        assert rev1.getCollection().equals(TestTools.makeSet(str1));
+        assert rev2.getCollection().equals(TestTools.makeSet(str1, str2));
+        assert rev3.getCollection().equals(TestTools.makeSet(str2));
+        assert rev4.getCollection().equals(TestTools.makeSet());
+
+        assert "coll1".equals(rev1.getData());
+        assert "coll1".equals(rev2.getData());
+        assert "coll1".equals(rev3.getData());
+        assert "coll1".equals(rev4.getData());
+    }
+}
\ No newline at end of file


Property changes on: trunk/src/test/org/jboss/envers/test/integration/onetomany/unidirectional/BasicNotOwnedSetWithEmbId.java
___________________________________________________________________
Name: svn:mergeinfo
   + 

Added: trunk/src/test/org/jboss/envers/test/integration/onetomany/unidirectional/BasicNotOwnedSetWithMulId.java
===================================================================
--- trunk/src/test/org/jboss/envers/test/integration/onetomany/unidirectional/BasicNotOwnedSetWithMulId.java	                        (rev 0)
+++ trunk/src/test/org/jboss/envers/test/integration/onetomany/unidirectional/BasicNotOwnedSetWithMulId.java	2008-08-21 13:56:27 UTC (rev 119)
@@ -0,0 +1,114 @@
+package org.jboss.envers.test.integration.onetomany.unidirectional;
+
+import org.jboss.envers.test.integration.AbstractEntityTest;
+import org.jboss.envers.test.entities.onetomany.unidirectional.ids.SetRefCollEntityMulId;
+import org.jboss.envers.test.entities.ids.MulIdTestEntity;
+import org.jboss.envers.test.entities.ids.MulId;
+import org.jboss.envers.test.tools.TestTools;
+import org.hibernate.ejb.Ejb3Configuration;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import javax.persistence.EntityManager;
+import java.util.Arrays;
+import java.util.HashSet;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class BasicNotOwnedSetWithMulId extends AbstractEntityTest {
+    private MulId str1_id;
+    private MulId str2_id;
+
+    private MulId coll1_id;
+
+    public void configure(Ejb3Configuration cfg) {
+        cfg.addAnnotatedClass(MulIdTestEntity.class);
+        cfg.addAnnotatedClass(SetRefCollEntityMulId.class);
+    }
+
+    @BeforeClass(dependsOnMethods = "init")
+    public void initData() {
+        EntityManager em = getEntityManager();
+
+        str1_id = new MulId(1, 2);
+        str2_id = new MulId(3, 4);
+
+        coll1_id = new MulId(5, 6);
+
+        MulIdTestEntity str1 = new MulIdTestEntity(str1_id.getId1(), str1_id.getId2(), "str1");
+        MulIdTestEntity str2 = new MulIdTestEntity(str2_id.getId1(), str2_id.getId2(), "str2");
+
+        SetRefCollEntityMulId coll1 = new SetRefCollEntityMulId(coll1_id.getId1(), coll1_id.getId2(), "coll1");
+
+        // Revision 1
+        em.getTransaction().begin();
+
+        em.persist(str1);
+        em.persist(str2);
+
+        coll1.setCollection(new HashSet<MulIdTestEntity>());
+        coll1.getCollection().add(str1);
+        em.persist(coll1);
+
+        em.getTransaction().commit();
+
+        // Revision 2
+        em.getTransaction().begin();
+
+        str2 = em.find(MulIdTestEntity.class, str2_id);
+        coll1 = em.find(SetRefCollEntityMulId.class, coll1_id);
+
+        coll1.getCollection().add(str2);
+
+        em.getTransaction().commit();
+
+        // Revision 3
+        em.getTransaction().begin();
+
+        str1 = em.find(MulIdTestEntity.class, str1_id);
+        coll1 = em.find(SetRefCollEntityMulId.class, coll1_id);
+
+        coll1.getCollection().remove(str1);
+
+        em.getTransaction().commit();
+
+        // Revision 4
+        em.getTransaction().begin();
+
+        coll1 = em.find(SetRefCollEntityMulId.class, coll1_id);
+
+        coll1.getCollection().clear();
+
+        em.getTransaction().commit();
+    }
+
+    @Test
+    public void testRevisionsCounts() {
+        assert Arrays.asList(1, 2, 3, 4).equals(getVersionsReader().getRevisions(SetRefCollEntityMulId.class, coll1_id));
+
+        assert Arrays.asList(1).equals(getVersionsReader().getRevisions(MulIdTestEntity.class, str1_id));
+        assert Arrays.asList(1).equals(getVersionsReader().getRevisions(MulIdTestEntity.class, str2_id));
+    }
+
+    @Test
+    public void testHistoryOfColl1() {
+        MulIdTestEntity str1 = getEntityManager().find(MulIdTestEntity.class, str1_id);
+        MulIdTestEntity str2 = getEntityManager().find(MulIdTestEntity.class, str2_id);
+
+        SetRefCollEntityMulId rev1 = getVersionsReader().find(SetRefCollEntityMulId.class, coll1_id, 1);
+        SetRefCollEntityMulId rev2 = getVersionsReader().find(SetRefCollEntityMulId.class, coll1_id, 2);
+        SetRefCollEntityMulId rev3 = getVersionsReader().find(SetRefCollEntityMulId.class, coll1_id, 3);
+        SetRefCollEntityMulId rev4 = getVersionsReader().find(SetRefCollEntityMulId.class, coll1_id, 4);
+
+        assert rev1.getCollection().equals(TestTools.makeSet(str1));
+        assert rev2.getCollection().equals(TestTools.makeSet(str1, str2));
+        assert rev3.getCollection().equals(TestTools.makeSet(str2));
+        assert rev4.getCollection().equals(TestTools.makeSet());
+
+        assert "coll1".equals(rev1.getData());
+        assert "coll1".equals(rev2.getData());
+        assert "coll1".equals(rev3.getData());
+        assert "coll1".equals(rev4.getData());
+    }
+}
\ No newline at end of file




More information about the jboss-envers-commits mailing list