本文整理汇总了Java中com.openpojo.validation.PojoValidator.addRule方法的典型用法代码示例。如果您正苦于以下问题:Java PojoValidator.addRule方法的具体用法?Java PojoValidator.addRule怎么用?Java PojoValidator.addRule使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.openpojo.validation.PojoValidator
的用法示例。
在下文中一共展示了PojoValidator.addRule方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testPojoStructureAndBehavior
import com.openpojo.validation.PojoValidator; //导入方法依赖的package包/类
/**
* Unit Test the POJO classes.
*
* @throws ClassNotFoundException
* the class not found exception
* @throws InstantiationException
* the instantiation exception
* @throws IllegalAccessException
* the illegal access exception
*/
@Test
public void testPojoStructureAndBehavior() throws ClassNotFoundException,
InstantiationException, IllegalAccessException {
final PojoValidator pojoValidator = new PojoValidator();
for (final Class<? extends Rule> ruleClass : getValidationRules()) {
final Rule rule = ruleClass.newInstance();
pojoValidator.addRule(rule);
}
// Load tester classes
for (Class<? extends Tester> testerClass : getTesters()) {
final Tester testerInstance = testerClass.newInstance();
pojoValidator.addTester(testerInstance);
}
for (final Class<?> c : getPOJOClasses()) {
final PojoClass pojoClass = PojoClassFactory.getPojoClass(c);
pojoValidator.runValidation(pojoClass);
}
}
示例2: testPojoStructureAndBehavior
import com.openpojo.validation.PojoValidator; //导入方法依赖的package包/类
@Test
@Category(UnitTest.class)
@SuppressWarnings("unchecked")
public void testPojoStructureAndBehavior() {
if (this.getClass() == PojoTest.class) {
return;
}
Class<T> typeParameterClass = (Class<T>) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0];
PojoValidator pojoValidator = new PojoValidator();
// Create Rules to validate structure for POJO_PACKAGE
pojoValidator.addRule(new NoPublicFieldsRule());
pojoValidator.addRule(new NoPrimitivesRule());
pojoValidator.addRule(new NoStaticExceptFinalRule());
pojoValidator.addRule(new GetterMustExistRule());
pojoValidator.addRule(new SetterMustExistRule());
pojoValidator.addRule(new NoNestedClassRule());
// Create Testers to validate behaviour for POJO_PACKAGE
pojoValidator.addTester(new SetterTester());
pojoValidator.addTester(new GetterTester());
PojoClass pojoClass = PojoClassFactory.getPojoClass(typeParameterClass);
pojoValidator.runValidation(pojoClass);
}
示例3: testPojo
import com.openpojo.validation.PojoValidator; //导入方法依赖的package包/类
@Test
public void testPojo() {
PojoValidator pojoValidator = new PojoValidator();
// Create Rules to validate structure for POJO_PACKAGE
pojoValidator.addRule(new NoPublicFieldsRule());
pojoValidator.addRule(new NoPrimitivesRule());
pojoValidator.addRule(new NoStaticExceptFinalRule());
pojoValidator.addRule(new GetterMustExistRule());
pojoValidator.addRule(new SetterMustExistRule());
pojoValidator.addRule(new NoNestedClassRule());
pojoValidator.addRule(new NoPublicFieldsExceptStaticFinalRule());
pojoValidator.addRule(new NoStaticExceptFinalRule());
pojoValidator.addRule(new SerializableMustHaveSerialVersionUIDRule());
// Create Testers to validate behaviour for POJO_PACKAGE
pojoValidator.addTester(new SetterTester());
pojoValidator.addTester(new GetterTester());
PojoClass pojoClass = PojoClassFactory.getPojoClass(getPojoClass());
pojoValidator.runValidation(pojoClass);
}
示例4: init
import com.openpojo.validation.PojoValidator; //导入方法依赖的package包/类
@Before
public void init() {
pojoValidator = new PojoValidator();
pojoValidator.addRule(new NoPublicFieldsRule());
pojoValidator.addRule(new NoStaticExceptFinalRule());
pojoValidator.addRule(new NoFieldShadowingRule());
pojoValidator.addRule(new GetterMustExistRule());
pojoValidator.addRule(new SetterMustExistRule());
pojoValidator.addTester(new SetterTester());
pojoValidator.addTester(new GetterTester());
pojoValidator.addTester(new Tester() {
@Override
public void run(PojoClass pojoClass) {
List<PojoMethod> list = pojoClass.getPojoConstructors();
for (PojoMethod method : list) {
Class<?>[] types = method.getParameterTypes();
int count = types.length;
Object[] values = new Object[count];
for (int i = 0; i < count; i++) {
values[i] = RandomFactory.getRandomValue(types[i]);
}
method.invoke(null, values);
}
}
});
}
示例5: testPojoStructureAndBehavior
import com.openpojo.validation.PojoValidator; //导入方法依赖的package包/类
@Test
public final void testPojoStructureAndBehavior() {
final PojoClass pc = PojoClassFactory
.getPojoClass(GeneratedArtifact.class);
final PojoValidator pv = createPojoValidator();
pv.addRule(new SetterMustExistRule());
pv.runValidation(pc);
}
示例6: testStructureAndBehaviour
import com.openpojo.validation.PojoValidator; //导入方法依赖的package包/类
@Test
public void testStructureAndBehaviour() {
final PojoClass pc = PojoClassFactory.getPojoClass(JaxbHelper.class);
final PojoValidator pv = createPojoValidator();
pv.addRule(new SetterMustExistRule());
pv.runValidation(pc);
}
示例7: testPojoStructureAndBehavior
import com.openpojo.validation.PojoValidator; //导入方法依赖的package包/类
@Test
public final void testPojoStructureAndBehavior() {
final PojoClass pc = PojoClassFactory.getPojoClass(Config.class);
final PojoValidator pv = createPojoValidator();
pv.addRule(new SetterMustExistRule());
pv.runValidation(pc);
}
示例8: testPojo
import com.openpojo.validation.PojoValidator; //导入方法依赖的package包/类
@Test
public void testPojo() {
final PojoValidator pv = new PojoValidator();
pv.addRule(new NoPublicFieldsRule());
pv.addRule(new NoFieldShadowingRule());
pv.addRule(new GetterMustExistRule());
}
示例9: testPojoStructureAndBehavior
import com.openpojo.validation.PojoValidator; //导入方法依赖的package包/类
@Test
public final void testPojoStructureAndBehavior() {
final PojoClass pc = PojoClassFactory.getPojoClass(Target.class);
final PojoValidator pv = new PojoValidator();
pv.addRule(new NoPublicFieldsRule());
pv.addRule(new NoFieldShadowingRule());
pv.addTester(new DefaultValuesNullTester());
pv.addTester(new SetterTester());
pv.addTester(new GetterTester());
pv.runValidation(pc);
}
示例10: createPojoValidator
import com.openpojo.validation.PojoValidator; //导入方法依赖的package包/类
/**
* Creates a configured POJO validator.
*
* @return New instance.
*/
protected final PojoValidator createPojoValidator() {
final PojoValidator pv = new PojoValidator();
pv.addRule(new NoPublicFieldsRule());
pv.addRule(new NoFieldShadowingRule());
pv.addTester(new DefaultValuesNullTester());
pv.addTester(new GetterTester());
return pv;
}