HHH-12612 - Added embeddable TYPE_USE test case coverage.

(cherry picked from commit 0d79bc0)
This commit is contained in:
Chris Cranford 2018-05-24 17:00:39 -04:00
parent c344860f19
commit c6f8e7edee
3 changed files with 133 additions and 0 deletions

View File

@ -0,0 +1,35 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.jpamodelgen.test.embeddable;
import org.hibernate.jpamodelgen.test.util.CompilationTest;
import org.hibernate.jpamodelgen.test.util.TestForIssue;
import org.hibernate.jpamodelgen.test.util.TestUtil;
import org.hibernate.jpamodelgen.test.util.WithClasses;
import org.junit.Test;
import static org.hibernate.jpamodelgen.test.util.TestUtil.assertAttributeTypeInMetaModelFor;
import static org.hibernate.jpamodelgen.test.util.TestUtil.assertMetamodelClassGeneratedFor;
/**
* @author Chris Cranford
*/
@TestForIssue(jiraKey = "HHH-12612")
public class EmbeddableTypeUseTest extends CompilationTest {
@Test
@WithClasses({SimpleEntity.class})
public void testAnnotatedEmbeddable() {
System.out.println( TestUtil.getMetaModelSourceAsString( SimpleEntity.class ) );
assertMetamodelClassGeneratedFor( SimpleEntity.class );
assertAttributeTypeInMetaModelFor(
SimpleEntity.class,
"simpleEmbeddable",
SimpleEmbeddable.class,
"Wrong type for embeddable attribute."
);
}
}

View File

@ -0,0 +1,45 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.jpamodelgen.test.embeddable;
import java.io.Serializable;
import java.util.Objects;
import javax.persistence.Embeddable;
/**
* @author Chris Cranford
*/
@Embeddable
public class SimpleEmbeddable implements Serializable {
private String data;
public String getData() {
return data;
}
public void setData(String data) {
this.data = data;
}
@Override
public boolean equals(Object o) {
if ( this == o ) {
return true;
}
if ( o == null || getClass() != o.getClass() ) {
return false;
}
SimpleEmbeddable that = (SimpleEmbeddable) o;
return Objects.equals( data, that.data );
}
@Override
public int hashCode() {
return Objects.hash( data );
}
}

View File

@ -0,0 +1,53 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.jpamodelgen.test.embeddable;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
/**
* @author Chris Cranford
*/
@Entity
public class SimpleEntity {
@Id
@GeneratedValue
private Integer id;
@NotNullAllowed
@Embedded
private SimpleEmbeddable simpleEmbeddable;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public SimpleEmbeddable getSimpleEmbeddable() {
return simpleEmbeddable;
}
public void setSimpleEmbeddable(SimpleEmbeddable simpleEmbeddable) {
this.simpleEmbeddable = simpleEmbeddable;
}
// represents a mock TYPE_USE based annotation
@Target({ ElementType.TYPE_USE })
@Retention(RetentionPolicy.RUNTIME)
public @interface NotNullAllowed {
}
}