/*
* Copyright 2002-2007 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.internna.iwebmvc.spring.mvc.validators;
import java.util.ArrayList;
import org.internna.iwebmvc.core.validation.ValidationVisitor;
import org.junit.Before;
import org.junit.Test;
import org.springframework.validation.BeanPropertyBindingResult;
import org.springframework.validation.Errors;
import stubs.Trivial;
import stubs.validation.CollectionBean;
import stubs.validation.InnerBean;
import stubs.validation.InnerBeanExtension;
import static org.junit.Assert.*;
/**
*
* @author Jose Noheda
* @since 1.0
*/
public class AnnotatedValidatorTest {
private AnnotatedValidator annotatedValidator;
private CollectionBean collectionBean;
private Errors errors;
@Before
public void setUp() throws Exception {
annotatedValidator = new AnnotatedValidator();
annotatedValidator.validator = new ValidationVisitor();
collectionBean = new CollectionBean();
collectionBean.setBeans(new ArrayList<InnerBean>());
errors = new BeanPropertyBindingResult(collectionBean, "collectionBean");
}
@Test
public void supports() {
assertFalse("Not a domain class", annotatedValidator.supports(Trivial.class));
assertTrue("A valid annotated class", annotatedValidator.supports(CollectionBean.class));
assertTrue("A valid annotated subclass", annotatedValidator.supports(InnerBeanExtension.class));
}
@Test
public void validate() {
annotatedValidator.validate(collectionBean, errors);
assertTrue("Validation correct", errors.hasErrors());
}
}