|
| 1 | +package org.dataone.cn.indexer.object; |
| 2 | + |
| 3 | +import org.dataone.cn.indexer.object.hashstore.HashStoreObjManager; |
| 4 | +import org.junit.Rule; |
| 5 | +import org.junit.Test; |
| 6 | +import uk.org.webcompere.systemstubs.rules.EnvironmentVariablesRule; |
| 7 | + |
| 8 | +import static org.junit.Assert.assertTrue; |
| 9 | +import static org.junit.Assert.fail; |
| 10 | + |
| 11 | +/** |
| 12 | + * A Junit test class for ObjectManagerFactory |
| 13 | + * @author Tao |
| 14 | + */ |
| 15 | +public class ObjectManagerFactoryTest { |
| 16 | + |
| 17 | + private static final String envName = "DATAONE_INDEXER_OBJECT_MANAGER_CLASSNAME"; |
| 18 | + @Rule |
| 19 | + public EnvironmentVariablesRule environmentVariablesClassName = |
| 20 | + new EnvironmentVariablesRule(envName, null); |
| 21 | + /** |
| 22 | + * Test to create a HashStoreObjManager |
| 23 | + * @throws Exception |
| 24 | + */ |
| 25 | + @Test |
| 26 | + public void testHashStoreObjManager() throws Exception { |
| 27 | + environmentVariablesClassName.set(envName, null); |
| 28 | + ObjectManagerFactory.resetManagerNull(); |
| 29 | + ObjectManager manager = ObjectManagerFactory.getObjectManager(); |
| 30 | + assertTrue(manager instanceof HashStoreObjManager); |
| 31 | + } |
| 32 | + |
| 33 | + /** |
| 34 | + * Test the failure with a wrong class name |
| 35 | + * @throws Exception |
| 36 | + */ |
| 37 | + @Test |
| 38 | + public void testWrongClassName() throws Exception { |
| 39 | + environmentVariablesClassName.set(envName, "foo.foo1.className"); |
| 40 | + ObjectManagerFactory.resetManagerNull(); |
| 41 | + try { |
| 42 | + ObjectManager manager = ObjectManagerFactory.getObjectManager(); |
| 43 | + fail("Test shouldn't get here since the class doesn't exist with the given name."); |
| 44 | + } catch (Exception e) { |
| 45 | + assertTrue( e instanceof ClassNotFoundException); |
| 46 | + } |
| 47 | + } |
| 48 | +} |
0 commit comments