METAGEN-66 Adding testcase

This commit is contained in:
Hardy Ferentschik 2011-07-07 17:34:51 +02:00 committed by Strong Liu
parent 66b04e8f66
commit 86ced8bbf4
5 changed files with 188 additions and 0 deletions

View File

@ -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<T extends Serializable> implements Serializable {
private Long id;
private BusinessId<T> businessId;
}

View File

@ -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<BusinessEntity, BusinessId<T>> businessId" ) );
}
@Override
@BeforeClass
// override compileAllTestEntities to compile the the business id explicitly
protected void compileAllTestEntities() throws Exception {
String fooPackageName = getPackageNameOfCurrentTest() + ".foo";
List<File> 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<String> getOrmFiles() {
List<String> ormFiles = new ArrayList<String>();
String packageName = TestUtil.fcnToPath( EmbeddableConfiguredInXmlTest.class.getPackage().getName() );
ormFiles.add( packageName + "/orm.xml" );
return ormFiles;
}
}

View File

@ -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;
}

View File

@ -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<T> implements Serializable {
private long businessId;
}

View File

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm
http://java.sun.com/xml/ns/persistence/orm_2_0.xsd"
version="2.0">
<package>org.hibernate.jpamodelgen.test.xmlembeddable</package>
<mapped-superclass class="BusinessEntity" access="FIELD">
<attributes>
<id name="id">
<column nullable="false"/>
<generated-value strategy="AUTO"/>
</id>
<embedded name="businessId"/>
</attributes>
</mapped-superclass>
<embeddable class="org.hibernate.jpamodelgen.test.xmlembeddable.foo.BusinessId" access="FIELD">
<attributes>
<basic name="businessId">
<column nullable="false" unique="true"/>
</basic>
</attributes>
</embeddable>
</entity-mappings>