/*
* Copyright 2004, 2005, 2006 Odysseus Software GmbH
*
* 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 de.odysseus.calyxo.forms.conf.impl;
import java.net.URL;
import java.util.Iterator;
import de.odysseus.calyxo.base.I18nSupport;
import de.odysseus.calyxo.base.ModuleContext;
import de.odysseus.calyxo.base.test.TestI18nSupport;
import de.odysseus.calyxo.base.test.TestModuleContext;
import de.odysseus.calyxo.forms.conf.FieldConfig;
import de.odysseus.calyxo.forms.conf.FormConfig;
import de.odysseus.calyxo.forms.conf.FormsRootConfig;
import de.odysseus.calyxo.forms.conf.MatchConfig;
import de.odysseus.calyxo.forms.conf.PropertyConfig;
import de.odysseus.calyxo.forms.conf.impl.FormsRootConfigParser;
import junit.framework.TestCase;
/**
*
* @author beck
*/
public class FormsRootConfigParserTest extends TestCase {
private String VALIDATORS =
"/de/odysseus/calyxo/forms/conf/impl/calyxo-forms-validators.xml";
FormsRootConfigParser parser;
/**
* Constructor for FormsRootConfigParserTest.
* @param name
*/
public FormsRootConfigParserTest(String name) {
super(name);
}
public static void main(String[] args) {
junit.textui.TestRunner.run(FormsRootConfigParserTest.class);
}
/*
* @see TestCase#setUp()
*/
protected void setUp() throws Exception {
super.setUp();
ModuleContext context = new TestModuleContext("test");
I18nSupport support = new TestI18nSupport();
context.setAttribute(I18nSupport.I18N_SUPPORT_KEY, support);
parser = new FormsRootConfigParser(context);
}
public void test0() throws Exception {
URL[] inputs = new URL[]{
getClass().getResource(VALIDATORS)
};
FormsRootConfig config = parser.parse(inputs);
assertNotNull(config.getValidatorsConfig().getMatcherConfig("regexp"));
assertEquals(false, config.getFormsConfigs().hasNext());
}
public void test1() throws Exception {
URL[] inputs = new URL[]{
getClass().getResource(VALIDATORS),
getClass().getResource("test1.xml")
};
FormsRootConfig config = parser.parse(inputs);
assertNotNull(config.getValidatorsConfig().getMatcherConfig("regexp"));
assertEquals(true, config.getFormsConfigs().hasNext());
}
public void test2() throws Exception {
URL[] inputs = new URL[]{
getClass().getResource(VALIDATORS),
getClass().getResource("test2.xml")
};
FormsRootConfig config = parser.parse(inputs);
FormConfig form = config.findFormConfig("LoginForm", null);
FieldConfig field = form.getFieldConfig("password");
Iterator matchers = field.getMatchConfigs();
MatchConfig notEmpty = (MatchConfig)matchers.next();
assertEquals("notEmpty", notEmpty.getMatcherConfig().getId());
MatchConfig regexp = (MatchConfig)matchers.next();
assertEquals("regexp", regexp.getMatcherConfig().getId());
PropertyConfig pattern = (PropertyConfig)regexp.getPropertyConfigs().next();
assertEquals("pattern", pattern.getName());
assertEquals("^\\w*$", pattern.getValue());
}
}