1 16 package org.apache.commons.chain.impl; 17 18 import junit.framework.Test; 19 import junit.framework.TestCase; 20 import junit.framework.TestSuite; 21 import org.apache.commons.chain.Catalog; 22 import org.apache.commons.chain.CatalogFactory; 23 import org.apache.commons.chain.Command; 24 import org.apache.commons.chain.impl.CatalogBase; 25 import java.util.Iterator ; 26 27 33 34 public class CatalogFactoryBaseTestCase extends TestCase { 35 36 37 39 40 43 protected CatalogFactory factory = null; 44 45 46 48 49 54 public CatalogFactoryBaseTestCase(String name) { 55 super(name); 56 } 57 58 59 61 62 65 public void setUp() { 66 factory = CatalogFactory.getInstance(); 67 } 68 69 70 73 public static Test suite() { 74 return (new TestSuite(CatalogFactoryBaseTestCase.class)); 75 } 76 77 80 public void tearDown() { 81 factory = null; 82 } 83 84 85 87 88 91 public void testPristine() { 92 93 assertNotNull(factory); 94 assertNull(factory.getCatalog()); 95 assertNull(factory.getCatalog("foo")); 96 assertEquals(0, getCatalogCount()); 97 98 } 99 100 101 104 public void testDefaultCatalog() { 105 106 Catalog catalog = new CatalogBase(); 107 factory.setCatalog(catalog); 108 assertTrue(catalog == factory.getCatalog()); 109 assertEquals(0, getCatalogCount()); 110 111 } 112 113 114 117 public void testSpecificCatalog() { 118 119 Catalog catalog = new CatalogBase(); 120 factory.setCatalog(catalog); 121 catalog = new CatalogBase(); 122 factory.addCatalog("foo", catalog); 123 assertTrue(catalog == factory.getCatalog("foo")); 124 assertEquals(1, getCatalogCount()); 125 factory.addCatalog("foo", new CatalogBase()); 126 assertEquals(1, getCatalogCount()); 127 assertTrue(!(catalog == factory.getCatalog("foo"))); 128 CatalogFactory.clear(); 129 factory = CatalogFactory.getInstance(); 130 assertEquals(0, getCatalogCount()); 131 132 } 133 134 135 137 138 142 private int getCatalogCount() { 143 144 Iterator names = factory.getNames(); 145 assertNotNull(names); 146 int n = 0; 147 while (names.hasNext()) { 148 names.next(); 149 n++; 150 } 151 return n; 152 153 } 154 155 156 } 157 | Popular Tags |