Package org.internna.iwebmvc.spring.services.dwr.impl

Source Code of org.internna.iwebmvc.spring.services.dwr.impl.AJAXValidatorImplTest

/*
* 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.services.dwr.impl;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.internna.iwebmvc.core.context.ContextHolder;
import org.internna.iwebmvc.core.crypto.impl.DES3CiphererDecipherer;
import org.internna.iwebmvc.core.validation.ValidationVisitor;
import org.internna.iwebmvc.model.core.I18nText;
import org.internna.iwebmvc.model.core.Locale;
import org.internna.iwebmvc.spring.mvc.validators.AnnotatedValidator;
import org.junit.Before;
import org.junit.Test;
import org.springframework.validation.FieldError;
import static org.junit.Assert.*;

/**
*
* @author Jose Noheda
* @since 1.0
*/
public class AJAXValidatorImplTest {

    private AJAXValidatorImpl validator;
    private DES3CiphererDecipherer des;
    private ContextHolder holder;

    @Before
    public void setUp() throws Exception {
        validator = new AJAXValidatorImpl();
        des = new DES3CiphererDecipherer();
        des.init();
        validator.decipherer = des;
        validator.validator = new AnnotatedValidator();
        Field f = AnnotatedValidator.class.getDeclaredField("validator");
        f.setAccessible(true);
        f.set(validator.validator, new ValidationVisitor());
        holder = new ContextHolder() {
            @Override
            public List<Locale> getAvailableLocales() {
                Locale l = new Locale();
                l.setDescription("English");
                l.setLocale("en");
                List<Locale> list = new ArrayList<Locale>(1);
                list.add(l);
                return list;
            }
        };
        validator.contextHolder = holder;
    }

    @Test
    public void validate() throws Exception {
        I18nText i = new I18nText();
        i.initialize(holder);
        Collection<FieldError> error = (Collection<FieldError>) validator.validate(stubs.validation.FakeDomainEntity.class, "name", i);
        assertNotNull("Validation error", error);
        assertTrue("Two field errors", error.size() == 2);
    }

}
TOP

Related Classes of org.internna.iwebmvc.spring.services.dwr.impl.AJAXValidatorImplTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.