[hibernate-commits] Hibernate SVN: r18765 - in core/trunk/envers/src/test/java/org/hibernate/envers/test: integration/ids and 1 other directory.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Wed Feb 10 11:00:30 EST 2010


Author: adamw
Date: 2010-02-10 11:00:29 -0500 (Wed, 10 Feb 2010)
New Revision: 18765

Added:
   core/trunk/envers/src/test/java/org/hibernate/envers/test/entities/ids/DateIdTestEntity.java
   core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/ids/DateId.java
Log:
HHH-4899:
- test

Copied: core/trunk/envers/src/test/java/org/hibernate/envers/test/entities/ids/DateIdTestEntity.java (from rev 18762, core/trunk/envers/src/test/java/org/hibernate/envers/test/entities/ids/MulIdTestEntity.java)
===================================================================
--- core/trunk/envers/src/test/java/org/hibernate/envers/test/entities/ids/DateIdTestEntity.java	                        (rev 0)
+++ core/trunk/envers/src/test/java/org/hibernate/envers/test/entities/ids/DateIdTestEntity.java	2010-02-10 16:00:29 UTC (rev 18765)
@@ -0,0 +1,90 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors.  All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA  02110-1301  USA
+ */
+package org.hibernate.envers.test.entities.ids;
+
+import org.hibernate.envers.Audited;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import java.util.Date;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+ at Entity
+public class DateIdTestEntity {
+    @Id
+    private Date id;
+
+    @Audited
+    private String str1;
+
+    public DateIdTestEntity() {
+    }
+
+    public DateIdTestEntity(String str1) {
+        this.str1 = str1;
+    }
+
+    public DateIdTestEntity(Date id, String str1) {
+        this.id = id;
+        this.str1 = str1;
+    }
+
+    public Date getId() {
+        return id;
+    }
+
+    public void setId(Date id) {
+        this.id = id;
+    }
+
+    public String getStr1() {
+        return str1;
+    }
+
+    public void setStr1(String str1) {
+        this.str1 = str1;
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) return true;
+        if (o == null || getClass() != o.getClass()) return false;
+
+        DateIdTestEntity that = (DateIdTestEntity) o;
+
+        if (id != null ? !id.equals(that.id) : that.id != null) return false;
+        if (str1 != null ? !str1.equals(that.str1) : that.str1 != null) return false;
+
+        return true;
+    }
+
+    @Override
+    public int hashCode() {
+        int result = id != null ? id.hashCode() : 0;
+        result = 31 * result + (str1 != null ? str1.hashCode() : 0);
+        return result;
+    }
+}
\ No newline at end of file

Copied: core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/ids/DateId.java (from rev 18763, core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/ids/CompositeIds.java)
===================================================================
--- core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/ids/DateId.java	                        (rev 0)
+++ core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/ids/DateId.java	2010-02-10 16:00:29 UTC (rev 18765)
@@ -0,0 +1,83 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors.  All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA  02110-1301  USA
+ */
+package org.hibernate.envers.test.integration.ids;
+
+import org.hibernate.ejb.Ejb3Configuration;
+import org.hibernate.envers.test.AbstractEntityTest;
+import org.hibernate.envers.test.entities.ids.*;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import javax.persistence.EntityManager;
+import java.util.Arrays;
+import java.util.Date;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class DateId extends AbstractEntityTest {
+    private Date id1;
+
+    public void configure(Ejb3Configuration cfg) {
+        cfg.addAnnotatedClass(DateIdTestEntity.class);
+    }
+
+    @BeforeClass(dependsOnMethods = "init")
+    public void initData() {
+
+        // Revision 1
+        EntityManager em = getEntityManager();
+        em.getTransaction().begin();
+
+        DateIdTestEntity dite = new DateIdTestEntity(new Date(), "x");
+        em.persist(dite);
+
+        id1 = dite.getId();
+
+        em.getTransaction().commit();
+
+        // Revision 2
+        em = getEntityManager();
+        em.getTransaction().begin();
+
+        dite = em.find(DateIdTestEntity.class, id1);
+        dite.setStr1("y");
+
+        em.getTransaction().commit();
+    }
+
+    @Test
+    public void testRevisionsCounts() {
+        assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(DateIdTestEntity.class, id1));
+    }
+
+    @Test
+    public void testHistoryOfId1() {
+        DateIdTestEntity ver1 = new DateIdTestEntity(id1, "x");
+        DateIdTestEntity ver2 = new DateIdTestEntity(id1, "y");
+
+        assert getAuditReader().find(DateIdTestEntity.class, id1, 1).getStr1().equals("x");
+        assert getAuditReader().find(DateIdTestEntity.class, id1, 2).getStr1().equals("y");
+    }
+}
\ No newline at end of file



More information about the hibernate-commits mailing list