From 86ced8bbf4ce5c62013dea484e267e207124e4aa Mon Sep 17 00:00:00 2001 From: Hardy Ferentschik Date: Thu, 7 Jul 2011 17:34:51 +0200 Subject: [PATCH] METAGEN-66 Adding testcase --- .../test/xmlembeddable/BusinessEntity.java | 32 +++++++++ .../EmbeddableConfiguredInXmlTest.java | 72 +++++++++++++++++++ .../jpamodelgen/test/xmlembeddable/Foo.java | 31 ++++++++ .../test/xmlembeddable/foo/BusinessId.java | 28 ++++++++ .../jpamodelgen/test/xmlembeddable/orm.xml | 25 +++++++ 5 files changed, 188 insertions(+) create mode 100644 tooling/metamodel-generator/src/test/java/org/hibernate/jpamodelgen/test/xmlembeddable/BusinessEntity.java create mode 100644 tooling/metamodel-generator/src/test/java/org/hibernate/jpamodelgen/test/xmlembeddable/EmbeddableConfiguredInXmlTest.java create mode 100644 tooling/metamodel-generator/src/test/java/org/hibernate/jpamodelgen/test/xmlembeddable/Foo.java create mode 100644 tooling/metamodel-generator/src/test/java/org/hibernate/jpamodelgen/test/xmlembeddable/foo/BusinessId.java create mode 100644 tooling/metamodel-generator/src/test/resources/org/hibernate/jpamodelgen/test/xmlembeddable/orm.xml diff --git a/tooling/metamodel-generator/src/test/java/org/hibernate/jpamodelgen/test/xmlembeddable/BusinessEntity.java b/tooling/metamodel-generator/src/test/java/org/hibernate/jpamodelgen/test/xmlembeddable/BusinessEntity.java new file mode 100644 index 0000000000..6c7128b315 --- /dev/null +++ b/tooling/metamodel-generator/src/test/java/org/hibernate/jpamodelgen/test/xmlembeddable/BusinessEntity.java @@ -0,0 +1,32 @@ +/* + * JBoss, Home of Professional Open Source + * Copyright 2010, 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.xmlembeddable; + +import java.io.Serializable; + +import org.hibernate.jpamodelgen.test.xmlembeddable.foo.BusinessId; + +/** + * @author Hardy Ferentschik + */ +public abstract class BusinessEntity implements Serializable { + private Long id; + + private BusinessId businessId; +} + + diff --git a/tooling/metamodel-generator/src/test/java/org/hibernate/jpamodelgen/test/xmlembeddable/EmbeddableConfiguredInXmlTest.java b/tooling/metamodel-generator/src/test/java/org/hibernate/jpamodelgen/test/xmlembeddable/EmbeddableConfiguredInXmlTest.java new file mode 100644 index 0000000000..69ebadcf90 --- /dev/null +++ b/tooling/metamodel-generator/src/test/java/org/hibernate/jpamodelgen/test/xmlembeddable/EmbeddableConfiguredInXmlTest.java @@ -0,0 +1,72 @@ +/* + * JBoss, Home of Professional Open Source + * Copyright 2010, 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.xmlembeddable; + +import java.io.File; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import org.hibernate.jpamodelgen.test.util.CompilationTest; +import org.hibernate.jpamodelgen.test.util.TestUtil; + +import static org.hibernate.jpamodelgen.test.util.TestUtil.getMetaModelSourceAsString; +import static org.testng.Assert.assertTrue; + +/** + * @author Hardy Ferentschik + */ +public class EmbeddableConfiguredInXmlTest extends CompilationTest { + @Test + public void testAttributeForEmbeddableConfiguredInXmlExists() { + // need to work with the source file. BusinessEntity_.class won't get generated, because the business id won't + // be on the classpath + String entityMetaModel = getMetaModelSourceAsString( BusinessEntity.class ); + assertTrue( entityMetaModel.contains( "SingularAttribute> businessId" ) ); + } + + @Override + @BeforeClass + // override compileAllTestEntities to compile the the business id explicitly + protected void compileAllTestEntities() throws Exception { + String fooPackageName = getPackageNameOfCurrentTest() + ".foo"; + List sourceFiles = getCompilationUnits( + CompilationTest.getSourceBaseDir(), fooPackageName + ); + compile( sourceFiles, fooPackageName ); + + sourceFiles = getCompilationUnits( getSourceBaseDir(), getPackageNameOfCurrentTest() ); + compile( sourceFiles, getPackageNameOfCurrentTest() ); + } + + @Override + protected String getPackageNameOfCurrentTest() { + return EmbeddableConfiguredInXmlTest.class.getPackage().getName(); + } + + @Override + protected Collection getOrmFiles() { + List ormFiles = new ArrayList(); + String packageName = TestUtil.fcnToPath( EmbeddableConfiguredInXmlTest.class.getPackage().getName() ); + ormFiles.add( packageName + "/orm.xml" ); + return ormFiles; + } +} \ No newline at end of file diff --git a/tooling/metamodel-generator/src/test/java/org/hibernate/jpamodelgen/test/xmlembeddable/Foo.java b/tooling/metamodel-generator/src/test/java/org/hibernate/jpamodelgen/test/xmlembeddable/Foo.java new file mode 100644 index 0000000000..7fdf005214 --- /dev/null +++ b/tooling/metamodel-generator/src/test/java/org/hibernate/jpamodelgen/test/xmlembeddable/Foo.java @@ -0,0 +1,31 @@ +/* + * JBoss, Home of Professional Open Source + * Copyright 2010, 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.xmlembeddable; + +import javax.persistence.Entity; +import javax.persistence.Id; + +/** + * @author Hardy Ferentschik + */ +@Entity +public class Foo { + @Id + long id; +} + + diff --git a/tooling/metamodel-generator/src/test/java/org/hibernate/jpamodelgen/test/xmlembeddable/foo/BusinessId.java b/tooling/metamodel-generator/src/test/java/org/hibernate/jpamodelgen/test/xmlembeddable/foo/BusinessId.java new file mode 100644 index 0000000000..e8af7f3abc --- /dev/null +++ b/tooling/metamodel-generator/src/test/java/org/hibernate/jpamodelgen/test/xmlembeddable/foo/BusinessId.java @@ -0,0 +1,28 @@ +/* + * JBoss, Home of Professional Open Source + * Copyright 2010, 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.xmlembeddable.foo; + +import java.io.Serializable; + +/** + * @author Hardy Ferentschik + */ +public class BusinessId implements Serializable { + private long businessId; +} + + diff --git a/tooling/metamodel-generator/src/test/resources/org/hibernate/jpamodelgen/test/xmlembeddable/orm.xml b/tooling/metamodel-generator/src/test/resources/org/hibernate/jpamodelgen/test/xmlembeddable/orm.xml new file mode 100644 index 0000000000..d9a06f43c0 --- /dev/null +++ b/tooling/metamodel-generator/src/test/resources/org/hibernate/jpamodelgen/test/xmlembeddable/orm.xml @@ -0,0 +1,25 @@ + + + org.hibernate.jpamodelgen.test.xmlembeddable + + + + + + + + + + + + + + + + + + \ No newline at end of file