1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
|
/*
* BioJava development code
*
* This code may be freely distributed and modified under the
* terms of the GNU Lesser General Public Licence. This should
* be distributed with the code. If you do not have a copy,
* see:
*
* http://www.gnu.org/copyleft/lesser.html
*
* Copyright for this code is held jointly by the individual
* authors. These should be listed in @author doc comments.
*
* For more information on the BioJava project and its aims,
* or to join the biojava-l mailing list, visit the home page
* at:
*
* http://www.biojava.org/
*
*/
package org.biojava.directory;
import java.util.HashMap;
import java.util.Map;
import junit.framework.TestCase;
/**
* <code>RegistryConfigurationTest</code> tests basic behaviour of
* <code>RegistryConfiguration</code>s. Note that the OBDA
* implementation maps a database identifier string to a
* <code>List</code> of <code>Map</code>s which acts as a sequence of
* fallback mappings. The test maps the database identifier string
* directly to config <code>Map</code>s for simplicity.
*
* @author Keith James
*/
public class RegistryConfigurationTest extends TestCase
{
protected Map confParams0;
protected Map confParams1;
protected Map confParams2;
protected String locator0;
protected String locator1;
protected String locator2;
public RegistryConfigurationTest(String name)
{
super(name);
}
protected void setUp()
{
confParams0 = new HashMap();
confParams0.put("protocol", "<protocol-type 0>");
confParams0.put("location", "<location-string 0>");
confParams0.put("parameter-x", "<value 0>");
confParams1 = new HashMap();
confParams1.put("protocol", "<protocol-type 1>");
confParams1.put("location", "<location-string 1>");
confParams1.put("parameter-y", "<value 1>");
confParams2 = new HashMap();
confParams2.put("protocol", "<protocol-type 2>");
confParams2.put("location", "<location-string 2>");
confParams2.put("parameter-x", "<value 2>");
locator0 = "<locator0>";
locator1 = "<locator1>";
locator2 = "<locator2>";
}
public void testSimpleRegistry() throws Exception
{
Map conf0 = new HashMap();
conf0.put("databank_0", confParams0);
RegistryConfiguration simple =
new RegistryConfiguration.Impl(locator0, conf0);
assertEquals(locator0, simple.getConfigLocator());
assertEquals(conf0, simple.getConfiguration());
}
public void testCompositeRegistry() throws Exception
{
RegistryConfiguration.Composite composite =
new RegistryConfiguration.Composite();
Map conf0 = new HashMap();
conf0.put("databank_0", confParams0);
RegistryConfiguration simple0 =
new RegistryConfiguration.Impl(locator0, conf0);
Map conf1 = new HashMap();
conf1.put("databank_0", confParams1);
RegistryConfiguration simple1 =
new RegistryConfiguration.Impl(locator1, conf1);
Map conf2 = new HashMap();
conf2.put("databank_0", confParams2);
RegistryConfiguration simple2 =
new RegistryConfiguration.Impl(locator2, conf2);
// Initial config
composite.addTopConfig(simple0);
assertEquals(locator0, composite.getConfigLocator());
assertEquals("<protocol-type 0>",
((Map) composite.getConfiguration().get("databank_0")).get("protocol"));
assertEquals("<location-string 0>",
((Map) composite.getConfiguration().get("databank_0")).get("location"));
// This should be obscured by the initial config
composite.addBottomConfig(simple1);
assertEquals(locator0 + "::" + locator1,
composite.getConfigLocator());
assertEquals("<protocol-type 0>",
((Map) composite.getConfiguration().get("databank_0")).get("protocol"));
assertEquals("<location-string 0>",
((Map) composite.getConfiguration().get("databank_0")).get("location"));
// This should obscure previous configs
composite.addTopConfig(simple2);
assertEquals(locator2 + "::" + locator0 + "::" + locator1,
composite.getConfigLocator());
assertEquals("<protocol-type 2>",
((Map) composite.getConfiguration().get("databank_0")).get("protocol"));
assertEquals("<location-string 2>",
((Map) composite.getConfiguration().get("databank_0")).get("location"));
// Parameter present in top and middle; should get top value
assertEquals("<value 2>",
((Map) composite.getConfiguration().get("databank_0")).get("parameter-x"));
// Parameter present in bottom only; should get null
assertNull(((Map) composite.getConfiguration().get("databank_0")).get("parameter-y"));
}
}
|