X-Git-Url: http://wamblee.org/gitweb/?a=blobdiff_plain;f=impl%2Fsrc%2Ftest%2Fjava%2Forg%2Fwamblee%2Fxmlrouter%2Fimpl%2FCompositeConfigTest.java;fp=impl%2Fsrc%2Ftest%2Fjava%2Forg%2Fwamblee%2Fxmlrouter%2Fimpl%2FCompositeConfigTest.java;h=0000000000000000000000000000000000000000;hb=8e41cb29f75362a792292d21b481bd06a9506296;hp=ad7c1c06d0e5c70e0c7fc2140b6a1667e88f17a0;hpb=9dbc2844950b55ae552fe74840954ea71b754c7a;p=xmlrouter diff --git a/impl/src/test/java/org/wamblee/xmlrouter/impl/CompositeConfigTest.java b/impl/src/test/java/org/wamblee/xmlrouter/impl/CompositeConfigTest.java deleted file mode 100644 index ad7c1c0..0000000 --- a/impl/src/test/java/org/wamblee/xmlrouter/impl/CompositeConfigTest.java +++ /dev/null @@ -1,199 +0,0 @@ -/* - * Copyright 2005-2011 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.wamblee.xmlrouter.impl; - -import static junit.framework.Assert.*; - -import java.util.ArrayList; -import java.util.List; - -import org.junit.Test; -import org.wamblee.xmlrouter.common.Id; -import org.wamblee.xmlrouter.config.Identifiable; - -public class CompositeConfigTest { - - public static interface StringClassInterface extends - Identifiable { - - } - - public static class StringClass implements StringClassInterface { - - private String value; - - public StringClass(String aValue) { - value = aValue; - } - - public StringClass(int aValue) { - this(aValue + ""); - } - - @Override - public Id getId() { - return new Id(value + ""); - } - - @Override - public int hashCode() { - return value.hashCode(); - } - - @Override - public boolean equals(Object aObj) { - if (aObj == null) { - return false; - } - if (!(aObj instanceof StringClass)) { - return false; - } - StringClass obj = (StringClass) aObj; - return value.equals(obj.value); - } - } - - @Test - public void testEmptyConfig() { - Config composite = composite(); - assertTrue(composite.values().isEmpty()); - } - - @Test(expected = RuntimeException.class) - public void testAddNotAllowed() { - composite().add(new StringClass(10)); - } - - @Test(expected = RuntimeException.class) - public void testRemoveNotAllowed() { - composite().remove(new Id("xxx")); - } - - @Test - public void testAddConfig() { - CompositeConfig composite = composite(); - Config c1 = new ConfigImpl( - StringClassInterface.class, "c1") { - @Override - public Identifiable wrap(Identifiable aT) { - return aT; - } - }; - Config c2 = new ConfigImpl( - StringClassInterface.class, "c2") { - @Override - public Identifiable wrap(Identifiable aT) { - return aT; - } - }; - - StringClass i1 = new StringClass(10); - StringClass i2 = new StringClass(20); - StringClass i3 = new StringClass(30); - StringClass i4 = new StringClass(40); - - c1.add(i1); - c1.add(i2); - c2.add(i3); - c2.add(i4); - - composite.addConfig(c1); - List values = composite.values(); - List ids = new ArrayList(); - for (StringClassInterface intf : values) { - ids.add(intf.getId().getId()); - } - assertTrue(ids.contains("c1.10")); - assertTrue(ids.contains("c1.20")); - - composite.addConfig(c2); - values = composite.values(); - assertEquals(4, values.size()); - - ids = new ArrayList(); - for (StringClassInterface intf : values) { - ids.add(intf.getId().getId()); - } - assertTrue(ids.contains("c1.10")); - assertTrue(ids.contains("c1.20")); - assertTrue(ids.contains("c2.30")); - assertTrue(ids.contains("c2.40")); - } - - @Test(expected = ConfigException.class) - public void testDuplicatesNotAllowed() { - CompositeConfig composite = composite(); - Config c1 = new ConfigImpl( - StringClassInterface.class, "c1") { - @Override - public Identifiable wrap(Identifiable aT) { - return aT; - } - }; - Config c2 = new ConfigImpl( - StringClassInterface.class, "c1") { - @Override - public Identifiable wrap(Identifiable aT) { - return aT; - } - }; - composite.addConfig(c1); - composite.addConfig(c2); - } - - @Test - public void testDuplicateItem() { - CompositeConfig composite = composite(); - Config c1 = new ConfigImpl( - StringClassInterface.class, "c.x") { - @Override - public Identifiable wrap(Identifiable aT) { - return aT; - } - }; - Config c2 = new ConfigImpl( - StringClassInterface.class, "c") { - @Override - public Identifiable wrap(Identifiable aT) { - return aT; - } - }; - - StringClass i1 = new StringClass("y"); - StringClass i2 = new StringClass("x.y"); - c1.add(i1); - c2.add(i2); - composite.addConfig(c1); - try { - composite.addConfig(c2); - fail(); - } catch (ConfigException e) { - // ok. - } - assertEquals(1, composite.values().size()); - assertEquals("c.x.y", composite.values().iterator().next().getId() - .getId()); - } - - private CompositeConfig composite() { - return new CompositeConfig( - StringClassInterface.class); - } - - private Id id(String aId) { - return new Id(aId); - } -}