jp.terasoluna.fw.validation.springmodules.DefaultBeanValidatorExTest.java Source code

Java tutorial

Introduction

Here is the source code for jp.terasoluna.fw.validation.springmodules.DefaultBeanValidatorExTest.java

Source

/*
 * Copyright (c) 2007 NTT DATA Corporation
 *
 * 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 jp.terasoluna.fw.validation.springmodules;

import static org.junit.Assert.assertSame;
import static org.junit.Assert.fail;

import org.apache.commons.validator.Validator;
import org.apache.commons.validator.ValidatorException;
import org.apache.commons.validator.ValidatorResources;
import org.junit.Test;
import org.springframework.test.util.ReflectionTestUtils;

/**
 * {@link jp.terasoluna.fw.validation.springmodules.DefaultBeanValidatorEx} ?
 * <p>
 * <h4>???</h4> Spring-Modules?DefaultBeanValidator
 * <p>
 * @see jp.terasoluna.fw.validation.springmodules.DefaultBeanValidatorEx
 */
public class DefaultBeanValidatorExTest {

    /**
     * testCleanupValidator01() <br>
     * <br>
     * () <br>
     * A,E <br>
     * <br>
     * () validator:CommonsValidatorEx<br>
     * (????) validator.getValidatorException():ValidatorException<br>
     * <br>
     * () :ValidatorExceptionterasoluna-spring-validator)<br>
     * ?ValidatorException(commons)<br>
     * <br>
     * validator?ValidatorException????????????? <br>
     * @throws Exception ?????
     */
    @Test
    public void testCleanupValidator01() throws Exception {
        // ??
        ValidatorResources resources = new ValidatorResources();
        CommonsValidatorEx commonsValidatorEx = new CommonsValidatorEx(resources, null);
        ValidatorException validatorException = new ValidatorException();
        ReflectionTestUtils.setField(commonsValidatorEx, "validatorException", validatorException);

        DefaultBeanValidatorEx defaultBeanValidatorEx = new DefaultBeanValidatorEx();
        try {
            // 
            defaultBeanValidatorEx.cleanupValidator(commonsValidatorEx);
            fail();
        } catch (jp.terasoluna.fw.validation.springmodules.ValidatorException e) {
            // 
            assertSame(validatorException, e.getCause());
        }
    }

    /**
     * testCleanupValidator02() <br>
     * <br>
     * () <br>
     * A,E <br>
     * <br>
     * () validator:CommonsValidatorEx<br>
     * (????) validator.getValidatorException():null<br>
     * <br>
     *  <br>
     * validator?ValidatorException???????????????? <br>
     * @throws Exception ?????
     */
    @Test
    public void testCleanupValidator02() throws Exception {
        // ??
        ValidatorResources resources = new ValidatorResources();
        CommonsValidatorEx commonsValidatorEx = new CommonsValidatorEx(resources, null);
        ReflectionTestUtils.setField(commonsValidatorEx, "validatorException", null);

        DefaultBeanValidatorEx defaultBeanValidatorEx = new DefaultBeanValidatorEx();
        try {
            // 
            defaultBeanValidatorEx.cleanupValidator(commonsValidatorEx);
        } catch (jp.terasoluna.fw.validation.springmodules.ValidatorException e) {
            // 
            fail();
        }
    }

    /**
     * testCleanupValidator03() <br>
     * <br>
     * () <br>
     * A,E <br>
     * <br>
     * () validator:CommonsValidatorEx?<br>
     * <br>
     *  <br>
     * validator?validatorCommonsValidatorEx????????????? <br>
     * @throws Exception ?????
     */
    @Test
    public void testCleanupValidator03() throws Exception {
        // ??
        ValidatorResources resources = new ValidatorResources();
        Validator validator = new Validator(resources);

        DefaultBeanValidatorEx defaultBeanValidatorEx = new DefaultBeanValidatorEx();
        try {

            defaultBeanValidatorEx.cleanupValidator(validator);
        } catch (jp.terasoluna.fw.validation.springmodules.ValidatorException e) {
            // 
            fail();
        }
    }

}