/*
* 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.base.conf.impl;
import java.net.URL;
import java.util.List;
import java.util.Date;
import java.util.HashMap;
import de.odysseus.calyxo.base.ModuleContext;
import de.odysseus.calyxo.base.conf.ConfigException;
import de.odysseus.calyxo.base.test.TestModuleContext;
import junit.framework.TestCase;
/**
*
* @author Christoph Beck
*/
public class BaseConfigTest extends TestCase {
private void checkMap(ModuleContext context, HashMap map) {
assertNotNull(map);
assertEquals("foo", map.get("bar"));
assertEquals("bar", map.get("foo"));
assertEquals(new Integer(2), context.getAttribute("two"));
assertSame(map.get("foo"), context.getAttribute("foo"));
assertSame(map.get("bar"), context.getAttribute("bar"));
assertEquals("barfoo", map.get("foobar"));
assertTrue("missing date property", map.get("date") instanceof Date);
}
public void testBaseMap() throws ConfigException {
TestModuleContext context = new TestModuleContext("test");
BaseRootConfigParser parser = new BaseRootConfigParser(context);
URL url = getClass().getResource("calyxo-base-config-map.xml");
parser.parse(new URL[]{url});
checkMap(context, (HashMap)context.getAttribute("map"));
}
public void testFooMap() throws ConfigException {
TestModuleContext context = new TestModuleContext("test");
FooRootConfigParser parser = new FooRootConfigParser(context);
parser.parse("calyxo-foo-config-map.xml");
checkMap(context, (HashMap)context.getAttribute("map"));
}
public void testFooMapImport() throws ConfigException {
TestModuleContext context = new TestModuleContext("test");
FooRootConfigParser parser = new FooRootConfigParser(context);
parser.parse("calyxo-foo-config-map-import.xml");
checkMap(context, (HashMap)context.getAttribute("map"));
}
public void testBaseList() throws ConfigException {
TestModuleContext context = new TestModuleContext("test");
BaseRootConfigParser parser = new BaseRootConfigParser(context);
URL url = getClass().getResource("calyxo-base-config-list.xml");
parser.parse(new URL[]{url});
List list = (List)context.getAttribute("list");
assertTrue(list.size() == 2);
assertEquals("foo", list.get(0));
assertEquals("foobar", list.get(1));
}
public void testBaseFormat() throws ConfigException {
TestModuleContext context = new TestModuleContext("test");
BaseRootConfigParser parser = new BaseRootConfigParser(context);
URL url = getClass().getResource("calyxo-base-config-format.xml");
parser.parse(new URL[]{url});
assertEquals("123,46", context.getAttribute("result"));
}
}