From: Kai Moritz Date: Tue, 7 Feb 2017 11:17:14 +0000 (+0100) Subject: Fixed bug with directories, that should be scanned for annotations X-Git-Tag: hibernate-maven-plugin-2.1.0~8 X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=ef0947b306d9515d6af6dbc1fdfd675efcd9eca4;p=hibernate4-maven-plugin Fixed bug with directories, that should be scanned for annotations All configuration values for and were ignored. Thanx to Thomas Mauß, how reported this bug and provided a very usefull integration test, that made it possible to find the bug in a breeze! --- diff --git a/src/it/hmp-testclasses-annotationscanning/pom.xml b/src/it/hmp-testclasses-annotationscanning/pom.xml new file mode 100644 index 00000000..32461a66 --- /dev/null +++ b/src/it/hmp-testclasses-annotationscanning/pom.xml @@ -0,0 +1,280 @@ + + 4.0.0 + + net.java.examples + hmp-testclasses-annotationscanning + 0.0.1-SNAPSHOT + + jar + + Hibernate-Maven-Plugin Scan Testclasses Example + Sample Maven Project for Testing the Annotation-Scanning from TestClasses + + + UTF-8 + 1.8 + 1.8 + + 3.3 + + 3.0.2.Final-redhat-15 + + 4.7.4 + 1.1.3 + 1.7.7 + 4.2.18.Final-redhat-2 + 4.3.2.Final-redhat-2 + + + + + + redhat-techpreview-all-repository + Red Hat Tech Preview repository (all) + http://maven.repository.redhat.com/techpreview/all/ + default + + true + never + + + false + never + + + + + + redhat-techpreview-all-repository + Red Hat Tech Preview repository (all) + http://maven.repository.redhat.com/techpreview/all/ + default + + true + never + + + false + never + + + + + + + + + org.apache.deltaspike.core + deltaspike-core-api + 1.0.1 + + + org.apache.deltaspike.core + deltaspike-core-impl + 1.0.1 + + + + + commons-beanutils + commons-beanutils + 1.8.3.redhat-6 + + + commons-collections + commons-collections + 3.2.1.redhat-3 + + + org.apache.commons + commons-lang3 + 3.4 + + + com.google.guava + guava + 13.0.1.redhat-2 + + + + + org.slf4j + slf4j-api + ${slf4j.version} + provided + + + ch.qos.logback + logback-classic + ${logback.version} + + + + + org.hibernate + hibernate-validator + ${hibernate.validator.version} + + + org.hibernate + hibernate-core + ${hibernate.version} + + + org.hibernate + hibernate-entitymanager + ${hibernate.version} + test + + + + + org.apache.openejb + arquillian-openejb-embedded-4 + ${org.apache.openejb.version} + test + + + org.apache.openejb + openejb-core + ${org.apache.openejb.version} + test + + + slf4j-jdk14 + org.slf4j + + + + + org.jboss.arquillian.extension + arquillian-persistence-impl + 1.0.0.Alpha6 + test + + + log4j + log4j + + + commons-collections + commons-collections + + + + + org.jboss.shrinkwrap.resolver + shrinkwrap-resolver-impl-maven + 2.1.0 + test + + + + + com.h2database + h2 + 1.3.168.redhat-4 + test + + + + + junit + junit + 4.12 + test + + + + + org.assertj + assertj-core + 2.0.0 + test + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + ${plugin.compiler.version} + + ${java.source} + ${java.target} + + + + de.juplo + hibernate-maven-plugin + @project.version@ + + + test-compile + + drop + create + + + + + + org.hibernate.dialect.H2Dialect + org.h2.Driver + + sa + sa + + + true + db-schema/create-schema.ddl + true + true + + + + com.h2database + h2 + 1.3.168-redhat-2 + + + + + + + + + + org.eclipse.m2e + lifecycle-mapping + 1.0.0 + + + + + + de.juplo + hibernate-maven-plugin + [2.0.0,) + + drop + create + + + + + + + + + + + + + + + diff --git a/src/it/hmp-testclasses-annotationscanning/readme.txt b/src/it/hmp-testclasses-annotationscanning/readme.txt new file mode 100644 index 00000000..17280078 --- /dev/null +++ b/src/it/hmp-testclasses-annotationscanning/readme.txt @@ -0,0 +1,19 @@ +Example-Project "Hibernate-Maven-Plugin Testclasses Annotation-Scanning" + +This is a small Exampleproject for a base Database-Integrationtest, with the use of the "Hibernate Maven Plugin" from de.juplo for the automatic Generation and the Execution of the create-schema-sql-script. + +The hibernate-maven-plugin - defined in the plugins-section in the pom.xml - scans the code for Entities to create the schema-script. Entity-Scanning is or can be done in following 3 locations: +*) Project-Classes: By default, the plugin scans for @Entitiy-Annotated classes under "target/classes". +*) Project-Testclasses: By default, the plugin scans for @Entitiy-Annotated classes under "target/test-classes". +*) Project-Dependencies: Compile-Time-Dependencies wil also be scanned. + +Test-Structure: +-) Basic Code for User-Change-Tracking over JPA EntityListener: Some basic Interfaces and Classes for a automatic tracking of the User and the Date at the Phases PRE-PERSIST and PRE-UPDATE are located under src/main/java. +-) The important Test-Entity "UserChangeInfoTest" for testing the userinfo-tracking and the Testservice-Declaration and -Implementation for storing/updating/reading such Test-Entity is located under src/test/java. +-) Integrationtest(s): The Integrationtest "UserChangeInfoTest" is based on Arquillian. Arquillian starts an OpenEJB Embedded Container, seeds the Database with Testdata, and executes the Integrationtest. +-) Dataset-Files, and different configurationfiles for Arquillian, JPA, Logback,... are located under src/test/resources. + + +Building the Project: +As usual: To build and install the project into your local maven-repository, execute "mvn install". + diff --git a/src/it/hmp-testclasses-annotationscanning/src/main/java/net/java/examples/hmp/model/domain/BaseEntity.java b/src/it/hmp-testclasses-annotationscanning/src/main/java/net/java/examples/hmp/model/domain/BaseEntity.java new file mode 100644 index 00000000..6d64c378 --- /dev/null +++ b/src/it/hmp-testclasses-annotationscanning/src/main/java/net/java/examples/hmp/model/domain/BaseEntity.java @@ -0,0 +1,61 @@ +package net.java.examples.hmp.model.domain; + +import java.io.Serializable; + +import org.hibernate.proxy.HibernateProxy; + +public abstract class BaseEntity implements IBaseEntity, Serializable { + + private static final long serialVersionUID = -5828097391861473323L; + + /** + * {@inheritDoc} + */ + @Override + public int hashCode() { + int result; + if (getId() == null) { + result = super.hashCode(); + } else { + final int prime = 31; + result = 1; + result = prime * result + ((getId() == null) ? 0 : getId().hashCode()); + } + return result; + } + + @Override + public boolean equals(final Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + + Class otherClass = null; + if (obj instanceof HibernateProxy) { + otherClass = ((HibernateProxy) obj).getHibernateLazyInitializer().getPersistentClass(); + } else { + otherClass = obj.getClass(); + } + if (getClass() != otherClass) { + return false; + } + + return compareEqualityWithThisInstance((BaseEntity) obj); + } + + private boolean compareEqualityWithThisInstance(BaseEntity otherEntity) { + if (getId() != null) { + return getId().equals(otherEntity.getId()); + } + + return false; + } + + @Override + public String toString() { + return this.getClass().getName() + "[id=" + getId() + "]"; + } +} diff --git a/src/it/hmp-testclasses-annotationscanning/src/main/java/net/java/examples/hmp/model/domain/Fachgebiet.java b/src/it/hmp-testclasses-annotationscanning/src/main/java/net/java/examples/hmp/model/domain/Fachgebiet.java new file mode 100644 index 00000000..0464a16d --- /dev/null +++ b/src/it/hmp-testclasses-annotationscanning/src/main/java/net/java/examples/hmp/model/domain/Fachgebiet.java @@ -0,0 +1,80 @@ +package net.java.examples.hmp.model.domain; + +import java.io.Serializable; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.EntityListeners; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.SequenceGenerator; +import javax.persistence.Table; +import javax.persistence.Version; +import javax.validation.constraints.Size; + +import org.hibernate.validator.constraints.NotBlank; + +import net.java.examples.hmp.model.domain.callback.UserChangeTrackListener; +import net.java.examples.hmp.model.domain.userchangeinfo.BaseUserChangeTrackedEntity; + +@Entity +@Table(name = "HMP_FACHGEBIET") +@EntityListeners(UserChangeTrackListener.class) +public class Fachgebiet extends BaseUserChangeTrackedEntity implements Serializable { + + private static final long serialVersionUID = -2362501487481778376L; + + @Id + @Column(name = "ID", nullable = false) + @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "FachgebietSeq") + @SequenceGenerator(name = "FachgebietSeq", sequenceName = "HMP_SEQ", allocationSize = 1) + private Long id; + + @NotBlank + @Size(max = 2) + @Column(name = "CODE", nullable = false) + private String code; + + @NotBlank + @Size(max = 500) + @Column(name = "NAME", nullable = false) + private String name; + + @Version + @Column(name = "VERSION") + private Long version; + + @Override + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getCode() { + return code; + } + + public void setCode(String code) { + this.code = code; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Long getVersion() { + return version; + } + + public void setVersion(Long version) { + this.version = version; + } +} diff --git a/src/it/hmp-testclasses-annotationscanning/src/main/java/net/java/examples/hmp/model/domain/IBaseEntity.java b/src/it/hmp-testclasses-annotationscanning/src/main/java/net/java/examples/hmp/model/domain/IBaseEntity.java new file mode 100644 index 00000000..d309229e --- /dev/null +++ b/src/it/hmp-testclasses-annotationscanning/src/main/java/net/java/examples/hmp/model/domain/IBaseEntity.java @@ -0,0 +1,19 @@ +package net.java.examples.hmp.model.domain; + +import java.io.Serializable; + +/** + * Basis interface fuer alle entities. Jede entity muss eine serialisierbare ID liefern. + * + * @param Klassentyp fuer ID + */ +public interface IBaseEntity { + + /** + * Liefert die Id. + * + * @return T die Id + */ + T getId(); + +} diff --git a/src/it/hmp-testclasses-annotationscanning/src/main/java/net/java/examples/hmp/model/domain/callback/UserChangeTrackListener.java b/src/it/hmp-testclasses-annotationscanning/src/main/java/net/java/examples/hmp/model/domain/callback/UserChangeTrackListener.java new file mode 100644 index 00000000..5553284f --- /dev/null +++ b/src/it/hmp-testclasses-annotationscanning/src/main/java/net/java/examples/hmp/model/domain/callback/UserChangeTrackListener.java @@ -0,0 +1,60 @@ +package net.java.examples.hmp.model.domain.callback; + +import java.util.Date; + +import javax.persistence.PrePersist; +import javax.persistence.PreUpdate; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import net.java.examples.hmp.model.domain.extension.IUserChangeInfo; +import net.java.examples.hmp.model.domain.extension.IUserChangeTrackable; + +public class UserChangeTrackListener { + + public static final String DEFAULT_USER_NAME = "System"; + + private static final Logger LOG = LoggerFactory.getLogger(UserChangeTrackListener.class); + + @PreUpdate + protected void preUpdate(IUserChangeTrackable userChangeTrackable) { + IUserChangeInfo userChangeInfo = userChangeTrackable.getUserChangeInfo(); + + if (userChangeInfo == null) { + LOG.warn("IUserChangeInfo of entity {} is null, no change tracking possible.", userChangeTrackable); + return; + } + + userChangeInfo.setChangeDate(new Date()); + userChangeInfo.setChangeUser(getCurrentUser()); + + if (LOG.isTraceEnabled()) { + LOG.trace("onPreUpdate objectType={}, userChangeInfo={}", userChangeTrackable.getClass().getName(), userChangeInfo.toString()); + } + } + + @PrePersist + protected void prePersist(IUserChangeTrackable userChangeTrackable) { + IUserChangeInfo userChangeInfo = userChangeTrackable.getUserChangeInfo(); + + userChangeInfo.setCreateDate(new Date()); + userChangeInfo.setChangeDate(userChangeInfo.getCreateDate()); + userChangeInfo.setCreateUser(getCurrentUser()); + userChangeInfo.setChangeUser(userChangeInfo.getCreateUser()); + + if (LOG.isTraceEnabled()) { + LOG.trace("onPrePersist objectType={}, userChangeInfo={}", userChangeTrackable.getClass().getName(), userChangeInfo.toString()); + } + } + + /** + * Real methodcode replaced with example-code. + * + * @return Always displays the same constant string + */ + protected String getCurrentUser() { + + return DEFAULT_USER_NAME; + } +} diff --git a/src/it/hmp-testclasses-annotationscanning/src/main/java/net/java/examples/hmp/model/domain/extension/IUserChangeInfo.java b/src/it/hmp-testclasses-annotationscanning/src/main/java/net/java/examples/hmp/model/domain/extension/IUserChangeInfo.java new file mode 100644 index 00000000..38180aeb --- /dev/null +++ b/src/it/hmp-testclasses-annotationscanning/src/main/java/net/java/examples/hmp/model/domain/extension/IUserChangeInfo.java @@ -0,0 +1,22 @@ +package net.java.examples.hmp.model.domain.extension; + +import java.util.Date; + +public interface IUserChangeInfo { + + Date getCreateDate(); + + void setCreateDate(Date createDate); + + Date getChangeDate(); + + void setChangeDate(Date changeDate); + + String getCreateUser(); + + void setCreateUser(String createUser); + + String getChangeUser(); + + void setChangeUser(String changeUser); +} diff --git a/src/it/hmp-testclasses-annotationscanning/src/main/java/net/java/examples/hmp/model/domain/extension/IUserChangeTrackable.java b/src/it/hmp-testclasses-annotationscanning/src/main/java/net/java/examples/hmp/model/domain/extension/IUserChangeTrackable.java new file mode 100644 index 00000000..18c4d4cb --- /dev/null +++ b/src/it/hmp-testclasses-annotationscanning/src/main/java/net/java/examples/hmp/model/domain/extension/IUserChangeTrackable.java @@ -0,0 +1,6 @@ +package net.java.examples.hmp.model.domain.extension; + +public interface IUserChangeTrackable { + + IUserChangeInfo getUserChangeInfo(); +} diff --git a/src/it/hmp-testclasses-annotationscanning/src/main/java/net/java/examples/hmp/model/domain/userchangeinfo/BaseUserChangeTrackedEntity.java b/src/it/hmp-testclasses-annotationscanning/src/main/java/net/java/examples/hmp/model/domain/userchangeinfo/BaseUserChangeTrackedEntity.java new file mode 100644 index 00000000..53c9364a --- /dev/null +++ b/src/it/hmp-testclasses-annotationscanning/src/main/java/net/java/examples/hmp/model/domain/userchangeinfo/BaseUserChangeTrackedEntity.java @@ -0,0 +1,31 @@ +package net.java.examples.hmp.model.domain.userchangeinfo; + +import java.io.Serializable; + +import javax.persistence.Embedded; +import javax.persistence.MappedSuperclass; + +import net.java.examples.hmp.model.domain.BaseEntity; +import net.java.examples.hmp.model.domain.extension.IUserChangeTrackable; + +@MappedSuperclass +public abstract class BaseUserChangeTrackedEntity extends BaseEntity implements IUserChangeTrackable { + + private static final long serialVersionUID = -7850597447088838323L; + + @Embedded + private UserChangeInfo userChangeInfo = new UserChangeInfo(); + + @Override + public UserChangeInfo getUserChangeInfo() { + // Workaround for Hibernate! For detailed information see this link: https://hibernate.atlassian.net/browse/HHH-7610 + if (this.userChangeInfo == null) { + this.userChangeInfo = new UserChangeInfo(); + } + return this.userChangeInfo; + } + + public void setUserChangeInfo(UserChangeInfo userChangeInfo) { + this.userChangeInfo = userChangeInfo; + } +} diff --git a/src/it/hmp-testclasses-annotationscanning/src/main/java/net/java/examples/hmp/model/domain/userchangeinfo/UserChangeInfo.java b/src/it/hmp-testclasses-annotationscanning/src/main/java/net/java/examples/hmp/model/domain/userchangeinfo/UserChangeInfo.java new file mode 100644 index 00000000..a5d10f66 --- /dev/null +++ b/src/it/hmp-testclasses-annotationscanning/src/main/java/net/java/examples/hmp/model/domain/userchangeinfo/UserChangeInfo.java @@ -0,0 +1,82 @@ +package net.java.examples.hmp.model.domain.userchangeinfo; + +import java.io.Serializable; +import java.util.Date; + +import javax.persistence.Column; +import javax.persistence.Embeddable; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; +import javax.validation.constraints.Size; + +import net.java.examples.hmp.model.domain.extension.IUserChangeInfo; + +@Embeddable +public class UserChangeInfo implements IUserChangeInfo, Serializable { + + private static final long serialVersionUID = -1372176907214369831L; + + @Temporal(TemporalType.TIMESTAMP) + @Column(name = "ERSTELLT_AM") + private Date createDate; + + @Temporal(TemporalType.TIMESTAMP) + @Column(name = "GEAENDERT_AM") + private Date changeDate; + + @Size(max = 20) + @Column(name = "ERSTELLT_VON") + private String createUser; + + @Size(max = 20) + @Column(name = "GEAENDERT_VON") + private String changeUser; + + @Override + public Date getCreateDate() { + return createDate; + } + + @Override + public void setCreateDate(Date createDate) { + this.createDate = createDate; + } + + @Override + public Date getChangeDate() { + return changeDate; + } + + @Override + public void setChangeDate(Date changeDate) { + this.changeDate = changeDate; + } + + @Override + public String getCreateUser() { + return createUser; + } + + @Override + public void setCreateUser(String createUser) { + this.createUser = createUser; + } + + @Override + public String getChangeUser() { + return changeUser; + } + + @Override + public void setChangeUser(String changeUser) { + this.changeUser = changeUser; + } + + /** + * {@inheritDoc} + */ + @Override + public String toString() { + return "UserChangeInfo [createDate=" + createDate + ", createUser=" + createUser + ", changeDate=" + changeDate + ", changeUser=" + changeUser + "]"; + } +} diff --git a/src/it/hmp-testclasses-annotationscanning/src/test/java/net/java/examples/hmp/model/domain/userchangeinfo/test/UserChangeInfoTest.java b/src/it/hmp-testclasses-annotationscanning/src/test/java/net/java/examples/hmp/model/domain/userchangeinfo/test/UserChangeInfoTest.java new file mode 100644 index 00000000..496aaf88 --- /dev/null +++ b/src/it/hmp-testclasses-annotationscanning/src/test/java/net/java/examples/hmp/model/domain/userchangeinfo/test/UserChangeInfoTest.java @@ -0,0 +1,84 @@ +package net.java.examples.hmp.model.domain.userchangeinfo.test; + +import static org.assertj.core.api.Assertions.assertThat; + +import javax.inject.Inject; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit.Arquillian; +import org.jboss.arquillian.persistence.UsingDataSet; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import net.java.examples.hmp.model.domain.callback.UserChangeTrackListener; +import net.java.examples.hmp.model.domain.extension.IUserChangeInfo; +import net.java.examples.hmp.model.test.userchangeinfo.UserChangeInfoTestEntity; +import net.java.examples.hmp.service.IUserChangeInfoTestService; +import net.java.examples.hmp.test.util.BaseDeploymentPackage; + +@RunWith(Arquillian.class) +@UsingDataSet("datasets/userchangeinfo/userchangeinfo.json") +public class UserChangeInfoTest { + + private static final Logger LOG = LoggerFactory.getLogger(UserChangeInfoTest.class); + + @Inject + private IUserChangeInfoTestService userChangeInfoTestService; + + @Deployment + public static WebArchive createDeploymentPackage() { + BaseDeploymentPackage deploymentPackage = new BaseDeploymentPackage() // + .createStandardDeploymentPackage() // + .addTestPersistence() // + .addPackagesModel() // + .addPackageTestModel() // + .addPackagesUserChangeTrack() // + .addPackagesTestServices(); + + LOG.debug(deploymentPackage.toString()); + return deploymentPackage.getWAR(); + } + + @Test + public void saveAndLoadWithDefaultUser() { + UserChangeInfoTestEntity userChangeInfoTestEntity = createAndPersistTestEntity(); + + userChangeInfoTestEntity = this.userChangeInfoTestService.getData(userChangeInfoTestEntity.getId()); + IUserChangeInfo userChangeInfo = userChangeInfoTestEntity.getUserChangeInfo(); + + assertThat("junit-test").isEqualTo(userChangeInfoTestEntity.getName()); + + assertThat(userChangeInfo.getCreateUser()).isEqualTo(UserChangeTrackListener.DEFAULT_USER_NAME); + assertThat(userChangeInfo.getChangeUser()).isEqualTo(UserChangeTrackListener.DEFAULT_USER_NAME); + + assertThat(userChangeInfo.getCreateDate()).isNotNull(); + assertThat(userChangeInfo.getChangeDate()).isNotNull(); + assertThat(userChangeInfo.getCreateDate().getTime()).isEqualTo(userChangeInfo.getChangeDate().getTime()); + } + + private UserChangeInfoTestEntity createAndPersistTestEntity() { + UserChangeInfoTestEntity userChangeInfoTestEntity = new UserChangeInfoTestEntity(); + userChangeInfoTestEntity.setName("junit-test"); + + this.userChangeInfoTestService.persistData(userChangeInfoTestEntity); + + return userChangeInfoTestEntity; + } + + @Test + public void getUserChangeInfoTestEntityExpectingUserChangeInfoObjectNotNull() { + UserChangeInfoTestEntity userChangeInfoTestEntity = this.userChangeInfoTestService.getData(new Long(1002)); + + assertThat(userChangeInfoTestEntity).isNotNull(); + assertThat(userChangeInfoTestEntity.getName()).isEqualTo("Testentity - alle UserChangeInfoFelder sind null"); + + assertThat(userChangeInfoTestEntity.getUserChangeInfo()).isNotNull(); + assertThat(userChangeInfoTestEntity.getUserChangeInfo().getCreateUser()).isNull(); + assertThat(userChangeInfoTestEntity.getUserChangeInfo().getCreateDate()).isNull(); + assertThat(userChangeInfoTestEntity.getUserChangeInfo().getChangeUser()).isNull(); + assertThat(userChangeInfoTestEntity.getUserChangeInfo().getChangeDate()).isNull(); + } +} diff --git a/src/it/hmp-testclasses-annotationscanning/src/test/java/net/java/examples/hmp/model/test/userchangeinfo/UserChangeInfoTestEntity.java b/src/it/hmp-testclasses-annotationscanning/src/test/java/net/java/examples/hmp/model/test/userchangeinfo/UserChangeInfoTestEntity.java new file mode 100644 index 00000000..7ca7234d --- /dev/null +++ b/src/it/hmp-testclasses-annotationscanning/src/test/java/net/java/examples/hmp/model/test/userchangeinfo/UserChangeInfoTestEntity.java @@ -0,0 +1,54 @@ +package net.java.examples.hmp.model.test.userchangeinfo; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.EntityListeners; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.SequenceGenerator; +import javax.persistence.Table; + +import net.java.examples.hmp.model.domain.callback.UserChangeTrackListener; +import net.java.examples.hmp.model.domain.userchangeinfo.BaseUserChangeTrackedEntity; + +/** + * Entity zum Testen der UserChangeInfo Funktionalitaet. + */ +@Entity +@Table(name = "HMP_UCI_TEST_ENTITY") +@EntityListeners(UserChangeTrackListener.class) +public class UserChangeInfoTestEntity extends BaseUserChangeTrackedEntity { + + private static final long serialVersionUID = -530295910082787747L; + + @Id + @Column(name = "ID", nullable = false) + @GeneratedValue(generator = "UserchangeInfoTestEntitySeq") + @SequenceGenerator(name = "UserchangeInfoTestEntitySeq", sequenceName = "HMP_SEQ", allocationSize = 1) + private Long id; + + @Column(name = "NAME", nullable = false) + private String name; + + @Override + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + @Override + public String toString() { + return "UserChangeInfoTestEntity [id=" + id + ", name=" + name + "]"; + } +} diff --git a/src/it/hmp-testclasses-annotationscanning/src/test/java/net/java/examples/hmp/persistence/producer/EntityManagerProducer.java b/src/it/hmp-testclasses-annotationscanning/src/test/java/net/java/examples/hmp/persistence/producer/EntityManagerProducer.java new file mode 100644 index 00000000..abcd3eed --- /dev/null +++ b/src/it/hmp-testclasses-annotationscanning/src/test/java/net/java/examples/hmp/persistence/producer/EntityManagerProducer.java @@ -0,0 +1,23 @@ +package net.java.examples.hmp.persistence.producer; + +import javax.enterprise.context.RequestScoped; +import javax.enterprise.inject.Produces; +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; + +public class EntityManagerProducer { + + @PersistenceContext(unitName = "persistence-hmp") + private EntityManager em; + + /** + * Liefert den BOA-EntityManager. + * + * @return EntityManager + */ + @Produces + @RequestScoped + public EntityManager createEntityManager() { + return em; + } +} diff --git a/src/it/hmp-testclasses-annotationscanning/src/test/java/net/java/examples/hmp/service/IUserChangeInfoTestService.java b/src/it/hmp-testclasses-annotationscanning/src/test/java/net/java/examples/hmp/service/IUserChangeInfoTestService.java new file mode 100644 index 00000000..e62b1530 --- /dev/null +++ b/src/it/hmp-testclasses-annotationscanning/src/test/java/net/java/examples/hmp/service/IUserChangeInfoTestService.java @@ -0,0 +1,32 @@ +package net.java.examples.hmp.service; + +import net.java.examples.hmp.model.test.userchangeinfo.UserChangeInfoTestEntity; + +/** + * Testservice fuer UserChangeInfo Tests + */ +public interface IUserChangeInfoTestService { + + /** + * persist ausfuehren + * + * @param entity UserChangeInfoTestEntity + */ + void persistData(UserChangeInfoTestEntity entity); + + /** + * merge+flush ausfuehren + * + * @param entity UserChangeInfoTestEntity + * @return gespeicherte Daten + */ + UserChangeInfoTestEntity mergeData(UserChangeInfoTestEntity entity); + + /** + * Find by id + * + * @param id ID fuer entity + * @return UserChangeInfoTestEntity + */ + UserChangeInfoTestEntity getData(Long id); +} diff --git a/src/it/hmp-testclasses-annotationscanning/src/test/java/net/java/examples/hmp/service/impl/UserChangeInfoTestService.java b/src/it/hmp-testclasses-annotationscanning/src/test/java/net/java/examples/hmp/service/impl/UserChangeInfoTestService.java new file mode 100644 index 00000000..040bad03 --- /dev/null +++ b/src/it/hmp-testclasses-annotationscanning/src/test/java/net/java/examples/hmp/service/impl/UserChangeInfoTestService.java @@ -0,0 +1,34 @@ +package net.java.examples.hmp.service.impl; + +import javax.ejb.Stateless; +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; + +import net.java.examples.hmp.model.test.userchangeinfo.UserChangeInfoTestEntity; +import net.java.examples.hmp.service.IUserChangeInfoTestService; + +@Stateless +public class UserChangeInfoTestService implements IUserChangeInfoTestService { + + @PersistenceContext + private EntityManager em; + + @Override + public void persistData(UserChangeInfoTestEntity entity) { + em.persist(entity); + em.flush(); + } + + @Override + public UserChangeInfoTestEntity mergeData(UserChangeInfoTestEntity entity) { + em.merge(entity); + em.flush(); + + return getData(entity.getId()); + } + + @Override + public UserChangeInfoTestEntity getData(Long id) { + return em.find(UserChangeInfoTestEntity.class, id); + } +} diff --git a/src/it/hmp-testclasses-annotationscanning/src/test/java/net/java/examples/hmp/test/util/BaseDeploymentPackage.java b/src/it/hmp-testclasses-annotationscanning/src/test/java/net/java/examples/hmp/test/util/BaseDeploymentPackage.java new file mode 100644 index 00000000..25d44687 --- /dev/null +++ b/src/it/hmp-testclasses-annotationscanning/src/test/java/net/java/examples/hmp/test/util/BaseDeploymentPackage.java @@ -0,0 +1,120 @@ +package net.java.examples.hmp.test.util; + +import org.jboss.shrinkwrap.api.ArchivePath; +import org.jboss.shrinkwrap.api.Filter; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.jboss.shrinkwrap.resolver.api.maven.Maven; +import org.jboss.shrinkwrap.resolver.api.maven.PomEquippedResolveStage; + +import net.java.examples.hmp.model.domain.BaseEntity; +import net.java.examples.hmp.model.domain.callback.UserChangeTrackListener; +import net.java.examples.hmp.model.domain.extension.IUserChangeInfo; +import net.java.examples.hmp.model.domain.extension.IUserChangeTrackable; +import net.java.examples.hmp.model.domain.userchangeinfo.BaseUserChangeTrackedEntity; +import net.java.examples.hmp.model.domain.userchangeinfo.UserChangeInfo; +import net.java.examples.hmp.model.test.userchangeinfo.UserChangeInfoTestEntity; +import net.java.examples.hmp.persistence.producer.EntityManagerProducer; +import net.java.examples.hmp.service.IUserChangeInfoTestService; +import net.java.examples.hmp.service.impl.UserChangeInfoTestService; + +public class BaseDeploymentPackage { + + private WebArchive war; + PomEquippedResolveStage resolver = createOfflineResolverForDefaultPomFile(); + + private static final IgnoreTestClassesFilter IGNORE_TEST_CLASSES_FILTER = new IgnoreTestClassesFilter(); + + public PomEquippedResolveStage createOfflineResolverForDefaultPomFile() { + return Maven.configureResolver().workOffline(true).loadPomFromFile("pom.xml"); + } + + public BaseDeploymentPackage addPackages(Package... packages) { + this.war.addPackages(false, IGNORE_TEST_CLASSES_FILTER, packages); + return this; + } + + public BaseDeploymentPackage addClasses(Class... classes) { + this.war.addClasses(classes); + + return this; + } + + public BaseDeploymentPackage addClass(Class clazz) { + this.war.addClass(clazz); + + return this; + } + + public static class IgnoreTestClassesFilter implements Filter { + + @Override + public boolean include(ArchivePath object) { + return !object.get().endsWith("Test.class"); + } + } + + public BaseDeploymentPackage createStandardDeploymentPackage() { + PomEquippedResolveStage resolver = createOfflineResolverForDefaultPomFile(); + + this.war = ShrinkWrap.create(WebArchive.class, "test.war")// + .addAsWebInfResource("beans.xml", "beans.xml")// + .addAsLibraries(resolver.resolve(// + "org.assertj:assertj-core", // Assertj must be included to use the Assertj-Assertions in the Test-Methods + "com.google.guava:guava", // + "org.apache.commons:commons-lang3", // + "commons-beanutils:commons-beanutils", // + "org.apache.deltaspike.core:deltaspike-core-api", // + "org.apache.deltaspike.core:deltaspike-core-impl").withTransitivity().asFile()); + + return this; + } + + public BaseDeploymentPackage addTestPersistence() { + this.war.addAsResource("test-persistence.xml", "META-INF/persistence.xml"); + return this; + } + + public BaseDeploymentPackage addPackagesModel() { + addClass(EntityManagerProducer.class); + + this.addPackageModelDomain(); + + return this; + } + + private BaseDeploymentPackage addPackageModelDomain() { + addPackages(BaseEntity.class.getPackage()); + addPackages(IUserChangeInfo.class.getPackage()); + + return this; + } + + public BaseDeploymentPackage addPackageTestModel() { + // Here the definition of our Test-Entity, which is located under src/test/classes + addClass(UserChangeInfoTestEntity.class); + + return this; + } + + public BaseDeploymentPackage addPackagesUserChangeTrack() { + addClass(UserChangeInfo.class); + addClass(IUserChangeInfo.class); + addClass(UserChangeTrackListener.class); + addClass(IUserChangeTrackable.class); + addClass(BaseUserChangeTrackedEntity.class); + + return this; + } + + public BaseDeploymentPackage addPackagesTestServices() { + addClass(IUserChangeInfoTestService.class); + addClass(UserChangeInfoTestService.class); + + return this; + } + + public WebArchive getWAR() { + return this.war; + } +} diff --git a/src/it/hmp-testclasses-annotationscanning/src/test/resources/META-INF/services/org.jboss.arquillian.core.spi.LoadableExtension b/src/it/hmp-testclasses-annotationscanning/src/test/resources/META-INF/services/org.jboss.arquillian.core.spi.LoadableExtension new file mode 100644 index 00000000..7d31029d --- /dev/null +++ b/src/it/hmp-testclasses-annotationscanning/src/test/resources/META-INF/services/org.jboss.arquillian.core.spi.LoadableExtension @@ -0,0 +1 @@ +org.jboss.arquillian.persistence.core.container.RemotePersistenceExtension \ No newline at end of file diff --git a/src/it/hmp-testclasses-annotationscanning/src/test/resources/arquillian.extension.persistence.dbunit.properties b/src/it/hmp-testclasses-annotationscanning/src/test/resources/arquillian.extension.persistence.dbunit.properties new file mode 100644 index 00000000..17fe2f12 --- /dev/null +++ b/src/it/hmp-testclasses-annotationscanning/src/test/resources/arquillian.extension.persistence.dbunit.properties @@ -0,0 +1,5 @@ +# can contain all dbunit properties +caseSensitiveTableNames = false +datatypeWarning = false +defaultDataSetFormat = JSON +datatypeFactory = org.dbunit.ext.h2.H2DataTypeFactory \ No newline at end of file diff --git a/src/it/hmp-testclasses-annotationscanning/src/test/resources/arquillian.extension.persistence.jpacacheeviction.properties b/src/it/hmp-testclasses-annotationscanning/src/test/resources/arquillian.extension.persistence.jpacacheeviction.properties new file mode 100644 index 00000000..e69de29b diff --git a/src/it/hmp-testclasses-annotationscanning/src/test/resources/arquillian.extension.persistence.properties b/src/it/hmp-testclasses-annotationscanning/src/test/resources/arquillian.extension.persistence.properties new file mode 100644 index 00000000..15d5f6fc --- /dev/null +++ b/src/it/hmp-testclasses-annotationscanning/src/test/resources/arquillian.extension.persistence.properties @@ -0,0 +1,4 @@ +defaultDataSeedStrategy = CLEAN_INSERT +defaultDataSource = openejb:Resource/HmpArquillianTest +dumpData = false +arquillian.extension.persistence.default.transaction.mode=DISABLED \ No newline at end of file diff --git a/src/it/hmp-testclasses-annotationscanning/src/test/resources/arquillian.extension.persistence.script.properties b/src/it/hmp-testclasses-annotationscanning/src/test/resources/arquillian.extension.persistence.script.properties new file mode 100644 index 00000000..5d3d981a --- /dev/null +++ b/src/it/hmp-testclasses-annotationscanning/src/test/resources/arquillian.extension.persistence.script.properties @@ -0,0 +1,2 @@ +# can contain all script properties +sqlStatementDelimiter = NEW_LINE \ No newline at end of file diff --git a/src/it/hmp-testclasses-annotationscanning/src/test/resources/arquillian.xml b/src/it/hmp-testclasses-annotationscanning/src/test/resources/arquillian.xml new file mode 100644 index 00000000..b9b8a6df --- /dev/null +++ b/src/it/hmp-testclasses-annotationscanning/src/test/resources/arquillian.xml @@ -0,0 +1,28 @@ + + + + DISABLED + + + + + + + + + HmpArquillianTest = new://Resource?type=DataSource + HmpArquillianTest.JdbcUrl = jdbc:h2:file:target/db/test + HmpArquillianTest.UserName = sa + HmpArquillianTest.Password = sa + HmpArquillianTest.jdbcDriver = org.h2.Driver + + org.apache.deltaspike.ProjectStage=UnitTest + file.encoding=UTF-8 + + + + diff --git a/src/it/hmp-testclasses-annotationscanning/src/test/resources/beans.xml b/src/it/hmp-testclasses-annotationscanning/src/test/resources/beans.xml new file mode 100644 index 00000000..5e1a333c --- /dev/null +++ b/src/it/hmp-testclasses-annotationscanning/src/test/resources/beans.xml @@ -0,0 +1,6 @@ + + + \ No newline at end of file diff --git a/src/it/hmp-testclasses-annotationscanning/src/test/resources/datasets/userchangeinfo/userchangeinfo.json b/src/it/hmp-testclasses-annotationscanning/src/test/resources/datasets/userchangeinfo/userchangeinfo.json new file mode 100644 index 00000000..cb18b22c --- /dev/null +++ b/src/it/hmp-testclasses-annotationscanning/src/test/resources/datasets/userchangeinfo/userchangeinfo.json @@ -0,0 +1,15 @@ +{ + "HMP_UCI_TEST_ENTITY": + [ + { + "ID":1001, + "NAME":"Test UserChangeInfo-Entity ohne UserChangeInfo", + "ERSTELLT_AM":"2014-01-01 12:12:12", + "ERSTELLT_VON":"aq-p" + }, + { + "ID":1002, + "NAME":"Testentity - alle UserChangeInfoFelder sind null" + } + ] +} \ No newline at end of file diff --git a/src/it/hmp-testclasses-annotationscanning/src/test/resources/logback-test.xml b/src/it/hmp-testclasses-annotationscanning/src/test/resources/logback-test.xml new file mode 100644 index 00000000..8d50df25 --- /dev/null +++ b/src/it/hmp-testclasses-annotationscanning/src/test/resources/logback-test.xml @@ -0,0 +1,15 @@ + + + + + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{5} - %msg%n + + + + + + + \ No newline at end of file diff --git a/src/it/hmp-testclasses-annotationscanning/src/test/resources/test-persistence.xml b/src/it/hmp-testclasses-annotationscanning/src/test/resources/test-persistence.xml new file mode 100644 index 00000000..a2e2c98c --- /dev/null +++ b/src/it/hmp-testclasses-annotationscanning/src/test/resources/test-persistence.xml @@ -0,0 +1,21 @@ + + + + org.hibernate.ejb.HibernatePersistence + + HmpArquillianTest + + net.java.examples.hmp.model.test.userchangeinfo.UserChangeInfoTestEntity + + + + + + + + + + + diff --git a/src/main/java/de/juplo/plugins/hibernate/AbstractSchemaMojo.java b/src/main/java/de/juplo/plugins/hibernate/AbstractSchemaMojo.java index c9ef2c59..6f3ff976 100644 --- a/src/main/java/de/juplo/plugins/hibernate/AbstractSchemaMojo.java +++ b/src/main/java/de/juplo/plugins/hibernate/AbstractSchemaMojo.java @@ -1179,7 +1179,7 @@ public abstract class AbstractSchemaMojo extends AbstractMojo { try { - File dir = new File(outputDirectory); + File dir = new File(path); if (dir.exists()) { getLog().info("Adding " + dir.getAbsolutePath() + " to the list of roots to scan...");