/*
* Copyright 2005-2006 the original author or authors.
*
* 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.strecks.form.controller;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMessage;
import org.strecks.form.impl.ObjectValidatorForm;
import org.strecks.validator.internal.ValidationAnnotationReader;
import org.testng.annotations.Configuration;
import org.testng.annotations.Test;
/**
* @author Phil Zoio
*/
public class TestObjectValidator
{
private ObjectValidatorForm form;
private DelegatingForm delegator;
@Configuration(beforeTestMethod = true)
public void setUp()
{
form = new ObjectValidatorForm();
delegator = FormTestUtils.getDelegatingForm(form);
}
@Test
public void testNullIntegerValidation()
{
ActionErrors errors = delegator.validate(null, null);
ActionMessage element = (ActionMessage) errors.get("requiredInteger").next();
assert element != null;
}
@Test
public void testFormValidation()
{
form.setRequiredInteger(1);
assert null == delegator.validate(null, null);
}
//@Test(expectedExceptions=ApplicationConfigurationException.class)
public void testBadlyTypedValidator()
{
ValidationAnnotationReader reader = new ValidationAnnotationReader();
reader.readValidationHandlers(new BadlyTypedValidatorForm(), null);
}
}