📄 hibernatemappingtests.java
字号:
/*
* Copyright (c) 2005 Chris Richardson
*
* 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 net.chrisrichardson.ormunit.hibernate;
import java.util.Collections;
import java.util.Set;
import net.chrisrichardson.ormunit.PropertyNameSet;
import org.hibernate.MappingException;
import org.hibernate.PropertyNotFoundException;
/**
* Base class for writing tests that make assertions about a Hibernate O/R
* mapping document.
*
* Note: This class been replaced by HibernateORMappingTests, which uses the term 'property' rather than field
* and by default, checks for property mappings rather than field mappings
*
* @author cer
* @see net.chrisrichardson.ormunit.HibernateORMappingTests
*
*/
public abstract class HibernateMappingTests extends AbstractORMappingTests {
protected void onSetUp() throws Exception {
super.onSetUp();
mappingChecker.setAccessStrategy(AccessStrategy.FIELD);
}
protected ComponentPropertyMapping getComponentFieldMapping(String propertyName)
throws MappingException {
return classChecker.getComponentPropertyMapping(propertyName);
}
protected void assertAllFieldsMapped() throws MappingException {
classChecker.assertAllPropertiesMappedExcept(Collections.EMPTY_SET);
}
protected void assertAllFieldsMappedExcept(Set propertyNames)
throws MappingException {
classChecker.assertAllPropertiesMappedExcept(propertyNames);
}
protected void assertCompositeListField(String propertyName)
throws MappingException {
classChecker.assertCompositeListProperty(propertyName);
}
protected ListPropertyMapping assertListField(String propertyName)
throws MappingException {
return classChecker.assertListProperty(propertyName);
}
protected CompositeListPropertyMapping getCompositeListFieldMapping(
String propertyName) throws MappingException {
return classChecker.getCompositeListPropertyMapping(propertyName);
}
protected ListPropertyMapping getListFieldMapping(String propertyName)
throws MappingException {
return classChecker.getListPropertyMapping(propertyName);
}
protected void assertComponentField(String propertyName)
throws MappingException {
classChecker.assertComponentProperty(propertyName);
}
protected void assertSetField(String propertyName) throws MappingException {
classChecker.assertSetProperty(propertyName);
}
protected ToOnePropertyMapping assertManyToOneField(String propertyName,
String foreignKeyColumnName) throws MappingException {
return classChecker.assertManyToOneProperty(propertyName,
foreignKeyColumnName);
}
protected void assertVersionField(String propertyName, String columnName) {
classChecker.assertVersionProperty(propertyName, columnName);
}
protected void assertIdField(String idProperty, String idColumn)
throws PropertyNotFoundException, MappingException {
classChecker.assertIdProperty(idProperty, idColumn);
}
protected void assertField(String propertyName, String columnName)
throws MappingException {
classChecker.assertProperty(propertyName, columnName);
}
protected void assertField(String propertyName, String columnName,
Class fieldType) {
classChecker.assertProperty(propertyName, columnName, fieldType);
}
protected void assertOneToManyListField(String propertyName,
String foreignKeyColumn, String indexColumn)
throws MappingException {
classChecker.assertOneToManyListProperty(propertyName, foreignKeyColumn,
indexColumn);
}
protected void assertAllFieldsMappedExcept(String field1, String field2,
String field3) throws MappingException {
classChecker.assertAllPropertiesMappedExcept(field1, field2, field3);
}
protected void assertAllFieldsMappedExcept(String field1, String field2)
throws MappingException {
classChecker.assertAllPropertiesMappedExcept(field1, field2);
}
protected void assertAllFieldsMappedExcept(String field1)
throws MappingException {
classChecker.assertAllPropertiesMappedExcept(field1);
}
protected CompositeSetPropertyMapping getCompositeSetFieldMapping(String propertyName) {
return classChecker.getCompositeSetPropertyMapping(propertyName);
}
protected PropertyNameSet makeFieldNameSet(Class type, String field) {
return PropertyNameSet.makePropertyNameSet(type, field);
}
protected void assertAllClassesMapped(PropertyNameSet set) {
mappingChecker.assertAllClassesMapped(set.asSet());
}
protected PropertyNameSet except(Class type, String name) {
return PropertyNameSet.except(type, name);
}
protected PropertyNameSet except(String propertyName) {
return PropertyNameSet.except(propertyName);
}
protected void assertAllFieldsMapped(PropertyNameSet set) {
classChecker.assertAllPropertiesMappedExcept(set.asSet());
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -