HHH-6113 test and license header

This commit is contained in:
Strong Liu 2011-05-15 16:37:31 +08:00
parent b30024ee9d
commit cb63f03437
4 changed files with 111 additions and 29 deletions

View File

@ -1,3 +1,26 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2011, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc..
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.metamodel.source.annotations.xml; package org.hibernate.metamodel.source.annotations.xml;
import org.jboss.jandex.DotName; import org.jboss.jandex.DotName;

View File

@ -1,3 +1,26 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2011, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc..
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.metamodel.source.annotations.xml; package org.hibernate.metamodel.source.annotations.xml;
import java.util.ArrayList; import java.util.ArrayList;
@ -9,10 +32,8 @@ import org.hibernate.metamodel.source.annotation.xml.XMLEntityMappings;
import org.hibernate.metamodel.source.annotations.xml.mocker.EntityMappingsMocker; import org.hibernate.metamodel.source.annotations.xml.mocker.EntityMappingsMocker;
import org.hibernate.metamodel.source.internal.JaxbRoot; import org.hibernate.metamodel.source.internal.JaxbRoot;
import org.hibernate.metamodel.source.internal.MetadataImpl; import org.hibernate.metamodel.source.internal.MetadataImpl;
/** /**
* @author Hardy Ferentschik * @author Hardy Ferentschik
* @todo Need some create some XMLContext as well which can be populated w/ information which can not be expressed via annotations
*/ */
public class OrmXmlParser { public class OrmXmlParser {
private final MetadataImpl meta; private final MetadataImpl meta;

View File

@ -107,7 +107,8 @@ public abstract class AbstractMockerTest {
return index; return index;
} }
protected Index getMockedIndex(String ormFileName){
protected Index getMockedIndex(String ormFileName) {
EntityMappingsMocker mocker = getEntityMappingsMocker( ormFileName ); EntityMappingsMocker mocker = getEntityMappingsMocker( ormFileName );
return mocker.mockNewIndex(); return mocker.mockNewIndex();
} }
@ -138,36 +139,23 @@ public abstract class AbstractMockerTest {
return serviceRegistry; return serviceRegistry;
} }
protected void assertHasAnnotation(Index index, DotName className, DotName annName) {
assertHasAnnotation( index, className, annName, 1 );
}
protected void assertHasNoAnnotation(Index index, DotName className, DotName annName) { protected void assertHasNoAnnotation(Index index, DotName className, DotName annName) {
ClassInfo classInfo = index.getClassByName( className ); List<AnnotationInstance> annotationInstanceList = getAnnotationInstances( index, className, annName );
if ( classInfo == null ) { if ( annotationInstanceList != null ) {
fail( "Can't find " + className + " from Index" ); if ( !annotationInstanceList.isEmpty() ) {
} fail( className + " has Annotation " + annName );
if ( classInfo.annotations() != null ) {
List<AnnotationInstance> annotationInstanceList = classInfo.annotations().get( annName );
if ( annotationInstanceList != null ) {
if(!annotationInstanceList.isEmpty()){
fail( className+" has Annotation "+annName );
}
} }
} }
} }
protected void assertHasAnnotation(Index index, DotName className, DotName annName) {
assertHasAnnotation( index, className, annName, 1 );
}
protected void assertHasAnnotation(Index index, DotName className, DotName annName, int size) { protected void assertHasAnnotation(Index index, DotName className, DotName annName, int size) {
ClassInfo classInfo = index.getClassByName( className ); List<AnnotationInstance> annotationInstanceList = getAnnotationInstances( index, className, annName );
if ( classInfo == null ) {
fail( "Can't find " + className + " from Index" );
}
if ( classInfo.annotations() == null ) {
fail( classInfo + " doesn't have any annotations defined" );
}
List<AnnotationInstance> annotationInstanceList = classInfo.annotations().get( annName );
if ( annotationInstanceList == null || annotationInstanceList.isEmpty() ) { if ( annotationInstanceList == null || annotationInstanceList.isEmpty() ) {
fail( classInfo + " doesn't have annotation " + annName ); fail( "Expected annotation " + annName + " size is " + size + ", but no one can be found in Index" );
} }
assertEquals( assertEquals(
"Expected annotation " + annName + " size is " + size + ", but it actually is " + annotationInstanceList "Expected annotation " + annName + " size is " + size + ", but it actually is " + annotationInstanceList
@ -188,13 +176,28 @@ public abstract class AbstractMockerTest {
protected void assertAnnotationValue(Index index, DotName className, DotName annName, int size, AnnotationValueChecker checker) { protected void assertAnnotationValue(Index index, DotName className, DotName annName, int size, AnnotationValueChecker checker) {
assertHasAnnotation( index, className, annName, size ); assertHasAnnotation( index, className, annName, size );
ClassInfo classInfo = index.getClassByName( className ); List<AnnotationInstance> annotationInstanceList = getAnnotationInstances( index,className,annName );
List<AnnotationInstance> annotationInstanceList = classInfo.annotations().get( annName );
for ( AnnotationInstance annotationInstance : annotationInstanceList ) { for ( AnnotationInstance annotationInstance : annotationInstanceList ) {
checker.check( annotationInstance ); checker.check( annotationInstance );
} }
} }
private List<AnnotationInstance> getAnnotationInstances(Index index, DotName className, DotName annName) {
if ( className != null ) {
ClassInfo classInfo = index.getClassByName( className );
if ( classInfo == null ) {
fail( "Can't find " + className + " from Index" );
}
if ( classInfo.annotations() == null ) {
fail( classInfo + " doesn't have any annotations defined" );
}
return classInfo.annotations().get( annName );
}
else {
return index.getAnnotations( annName );
}
}
static interface AnnotationValueChecker { static interface AnnotationValueChecker {
void check(AnnotationInstance annotationInstance); void check(AnnotationInstance annotationInstance);
} }

View File

@ -1,7 +1,36 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2011, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc..
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.metamodel.source.annotations.xml.mocker; package org.hibernate.metamodel.source.annotations.xml.mocker;
import javax.persistence.AccessType;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.Index; import org.jboss.jandex.Index;
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.*;
import org.hibernate.metamodel.source.annotations.xml.MockedNames;
/** /**
* @author Strong Liu * @author Strong Liu
@ -10,6 +39,12 @@ public class PersistenceMetadataMockerTest extends AbstractMockerTest {
@Test @Test
public void testPersistenceMetadata() { public void testPersistenceMetadata() {
Index index = getMockedIndex( "persistence-metadata.xml" ); Index index = getMockedIndex( "persistence-metadata.xml" );
index.printAnnotations(); assertHasAnnotation( index, null, MockedNames.DEFAULT_ACCESS, 1 );
assertAnnotationValue(index,null,MockedNames.DEFAULT_ACCESS,new AnnotationValueChecker(){
@Override
public void check(AnnotationInstance annotationInstance) {
assertEquals( AccessType.FIELD.toString(), annotationInstance.value().asEnum());
}
});
} }
} }