From 90b023af3e084b01eb77938c72204e3c7d5540c5 Mon Sep 17 00:00:00 2001 From: Hardy Ferentschik Date: Mon, 3 Dec 2012 12:10:28 +0100 Subject: [PATCH] METAGEN-90 Adding testcase --- .../jpamodelgen/test/embeddable/Base.java | 27 ++++++++++++ .../embeddable/EmbeddableAccessTypeTest.java | 43 +++++++++++++++++++ .../test/embeddable/EmbeddableEntity.java | 34 +++++++++++++++ .../jpamodelgen/test/embeddable/IStuff.java | 20 +++++++++ .../jpamodelgen/test/embeddable/MyEntity.java | 26 +++++++++++ .../jpamodelgen/test/embeddable/Stuff.java | 23 ++++++++++ 6 files changed, 173 insertions(+) create mode 100644 tooling/metamodel-generator/src/test/java/org/hibernate/jpamodelgen/test/embeddable/Base.java create mode 100644 tooling/metamodel-generator/src/test/java/org/hibernate/jpamodelgen/test/embeddable/EmbeddableAccessTypeTest.java create mode 100644 tooling/metamodel-generator/src/test/java/org/hibernate/jpamodelgen/test/embeddable/EmbeddableEntity.java create mode 100644 tooling/metamodel-generator/src/test/java/org/hibernate/jpamodelgen/test/embeddable/IStuff.java create mode 100644 tooling/metamodel-generator/src/test/java/org/hibernate/jpamodelgen/test/embeddable/MyEntity.java create mode 100644 tooling/metamodel-generator/src/test/java/org/hibernate/jpamodelgen/test/embeddable/Stuff.java diff --git a/tooling/metamodel-generator/src/test/java/org/hibernate/jpamodelgen/test/embeddable/Base.java b/tooling/metamodel-generator/src/test/java/org/hibernate/jpamodelgen/test/embeddable/Base.java new file mode 100644 index 0000000000..e81624aad5 --- /dev/null +++ b/tooling/metamodel-generator/src/test/java/org/hibernate/jpamodelgen/test/embeddable/Base.java @@ -0,0 +1,27 @@ +/* + * JBoss, Home of Professional Open Source + * Copyright 2012, Red Hat Middleware LLC, and individual contributors + * by the @authors tag. See the copyright.txt in the distribution for a + * full listing of individual contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.hibernate.jpamodelgen.test.embeddable; + +import javax.persistence.Id; +import javax.persistence.MappedSuperclass; + +@MappedSuperclass +public class Base { + + @Id + protected String uuid; +} diff --git a/tooling/metamodel-generator/src/test/java/org/hibernate/jpamodelgen/test/embeddable/EmbeddableAccessTypeTest.java b/tooling/metamodel-generator/src/test/java/org/hibernate/jpamodelgen/test/embeddable/EmbeddableAccessTypeTest.java new file mode 100644 index 0000000000..19d59bc060 --- /dev/null +++ b/tooling/metamodel-generator/src/test/java/org/hibernate/jpamodelgen/test/embeddable/EmbeddableAccessTypeTest.java @@ -0,0 +1,43 @@ +/* + * JBoss, Home of Professional Open Source + * Copyright 2012, Red Hat Middleware LLC, and individual contributors + * by the @authors tag. See the copyright.txt in the distribution for a + * full listing of individual contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.hibernate.jpamodelgen.test.embeddable; + +import org.testng.annotations.Test; + +import org.hibernate.jpamodelgen.test.util.CompilationTest; + +import static org.hibernate.jpamodelgen.test.util.TestUtil.assertAttributeTypeInMetaModelFor; + +/** + * @author Hardy Ferentschik + */ +public class EmbeddableAccessTypeTest extends CompilationTest { + @Test + public void testCorrectAccessTypeUsedForEmbeddable() { + assertAttributeTypeInMetaModelFor( + EmbeddableEntity.class, + "stuffs", + Stuff.class, + "The target annotation set the type to Stuff" + ); + } + + @Override + protected String getPackageNameOfCurrentTest() { + return EmbeddableAccessTypeTest.class.getPackage().getName(); + } +} \ No newline at end of file diff --git a/tooling/metamodel-generator/src/test/java/org/hibernate/jpamodelgen/test/embeddable/EmbeddableEntity.java b/tooling/metamodel-generator/src/test/java/org/hibernate/jpamodelgen/test/embeddable/EmbeddableEntity.java new file mode 100644 index 0000000000..d3edca30bc --- /dev/null +++ b/tooling/metamodel-generator/src/test/java/org/hibernate/jpamodelgen/test/embeddable/EmbeddableEntity.java @@ -0,0 +1,34 @@ +/* + * JBoss, Home of Professional Open Source + * Copyright 2012, Red Hat Middleware LLC, and individual contributors + * by the @authors tag. See the copyright.txt in the distribution for a + * full listing of individual contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.hibernate.jpamodelgen.test.embeddable; + +import java.util.HashSet; +import java.util.Set; +import javax.persistence.Embeddable; +import javax.persistence.OneToMany; + +/* Here the getter is mandatory to reproduce the issue. No @Access(FIELD) annotation. */ +@Embeddable +//@Access(AccessType.FIELD) +public class EmbeddableEntity { + @OneToMany(targetEntity = Stuff.class) + Set stuffs = new HashSet(); + + public Set getStuffs() { + return stuffs; + } +} diff --git a/tooling/metamodel-generator/src/test/java/org/hibernate/jpamodelgen/test/embeddable/IStuff.java b/tooling/metamodel-generator/src/test/java/org/hibernate/jpamodelgen/test/embeddable/IStuff.java new file mode 100644 index 0000000000..3c1a262a62 --- /dev/null +++ b/tooling/metamodel-generator/src/test/java/org/hibernate/jpamodelgen/test/embeddable/IStuff.java @@ -0,0 +1,20 @@ +/* + * JBoss, Home of Professional Open Source + * Copyright 2012, Red Hat Middleware LLC, and individual contributors + * by the @authors tag. See the copyright.txt in the distribution for a + * full listing of individual contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.hibernate.jpamodelgen.test.embeddable; + +public interface IStuff { +} diff --git a/tooling/metamodel-generator/src/test/java/org/hibernate/jpamodelgen/test/embeddable/MyEntity.java b/tooling/metamodel-generator/src/test/java/org/hibernate/jpamodelgen/test/embeddable/MyEntity.java new file mode 100644 index 0000000000..02c53ddcf9 --- /dev/null +++ b/tooling/metamodel-generator/src/test/java/org/hibernate/jpamodelgen/test/embeddable/MyEntity.java @@ -0,0 +1,26 @@ +/* + * JBoss, Home of Professional Open Source + * Copyright 2012, Red Hat Middleware LLC, and individual contributors + * by the @authors tag. See the copyright.txt in the distribution for a + * full listing of individual contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.hibernate.jpamodelgen.test.embeddable; + +import javax.persistence.Embedded; +import javax.persistence.Entity; + +@Entity +public class MyEntity extends Base { + @Embedded + private EmbeddableEntity emb; +} diff --git a/tooling/metamodel-generator/src/test/java/org/hibernate/jpamodelgen/test/embeddable/Stuff.java b/tooling/metamodel-generator/src/test/java/org/hibernate/jpamodelgen/test/embeddable/Stuff.java new file mode 100644 index 0000000000..55613e827d --- /dev/null +++ b/tooling/metamodel-generator/src/test/java/org/hibernate/jpamodelgen/test/embeddable/Stuff.java @@ -0,0 +1,23 @@ +/* + * JBoss, Home of Professional Open Source + * Copyright 2012, Red Hat Middleware LLC, and individual contributors + * by the @authors tag. See the copyright.txt in the distribution for a + * full listing of individual contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.hibernate.jpamodelgen.test.embeddable; + +import javax.persistence.Entity; + +@Entity +public class Stuff extends Base implements IStuff { +}