r1950 - in trunk/topia-persistence/src: main/java/org/nuiton/topia/framework test/java/org/nuiton/topia/framework
Author: fdesbois Date: 2010-05-10 16:33:00 +0200 (Mon, 10 May 2010) New Revision: 1950 Url: http://nuiton.org/repositories/revision/topia/1950 Log: Start test for TopiaContextImpl Added: trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TestService.java trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaContextImplTest.java Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImpl.java Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImpl.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImpl.java 2010-05-10 13:21:44 UTC (rev 1949) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImpl.java 2010-05-10 14:33:00 UTC (rev 1950) @@ -202,6 +202,13 @@ postInitServices(services); } + /** + * Default constructor, useful for tests. + */ + protected TopiaContextImpl() { + + } + protected Map<String, TopiaService> loadServices(Properties config) { Map<String, TopiaService> result = new HashMap<String, TopiaService>(); // recherche des services present dans la config @@ -222,12 +229,13 @@ key, service.getServiceName())); } } catch (Throwable eee) { - if (log.isErrorEnabled()) { - log.error(I18n._("topia.persistence.error.service.unknown", - key, classService)); - } + String message = + I18n._("topia.persistence.error.service.unknown", + key, classService); if (log.isDebugEnabled()) { - log.debug(eee); + log.debug(message, eee); + } else if (log.isErrorEnabled()) { + log.error(message); } } } Added: trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TestService.java =================================================================== --- trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TestService.java (rev 0) +++ trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TestService.java 2010-05-10 14:33:00 UTC (rev 1950) @@ -0,0 +1,36 @@ +package org.nuiton.topia.framework; + +import org.junit.Ignore; + +/** + * TestService which implements {@link TopiaService} to test loading from + * {@link TopiaContextImplTest#testLoadServices()}. + * + * Created: 10 mai 2010 + * + * @author fdesbois <fdesbois@codelutin.com> + * @version $Id$ + */ +@Ignore +public class TestService implements TopiaService { + + @Override + public String getServiceName() { + return "test"; + } + + @Override + public Class<?>[] getPersistenceClasses() { + return new Class<?>[0]; + } + + @Override + public boolean preInit(TopiaContextImplementor context) { + return true; + } + + @Override + public boolean postInit(TopiaContextImplementor context) { + return true; + } +} Property changes on: trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TestService.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaContextImplTest.java =================================================================== --- trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaContextImplTest.java (rev 0) +++ trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaContextImplTest.java 2010-05-10 14:33:00 UTC (rev 1950) @@ -0,0 +1,230 @@ +package org.nuiton.topia.framework; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.nuiton.i18n.I18n; + +import java.util.Locale; +import java.util.Map; +import java.util.Properties; + +/** + * Created: 10 mai 2010 + * + * @author fdesbois <fdesbois@codelutin.com> + * @version $Id$ + */ +public class TopiaContextImplTest { + + private static final Log log = + LogFactory.getLog(TopiaContextImplTest.class); + + protected Properties properties = new Properties(); + + @BeforeClass + public static void setUpClass() throws Exception { + I18n.init(Locale.FRENCH); + } + + @Before + public void setUp() throws Exception { + properties.clear(); + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testLoadServices() throws Exception { + log.info("## testLoadServices"); + + /** PREPARE DATA **/ + properties.setProperty("topia.service.test", + TestService.class.getName()); + + TopiaContextImpl context = new TopiaContextImpl(); + + /** EXEC METHOD **/ + log.info("test 1 : load a simple TestService from properties"); + Map<String, TopiaService> results = context.loadServices(properties); + Assert.assertEquals(1, results.size()); + Assert.assertTrue(results.containsKey("test")); + TopiaService service = results.get("test"); + Assert.assertEquals(TestService.class, service.getClass()); + + log.info("test 2 : load with wrong key : will display a WARN"); + properties.clear(); + + properties.setProperty("topia.service.fake", + TestService.class.getName()); + + results = context.loadServices(properties); + Assert.assertEquals(0, results.size()); + Assert.assertFalse(results.containsKey("fake")); + + log.info("test 3 : load with fake service name : will display an ERROR"); + properties.clear(); + + properties.setProperty("topia.service.test", "FAKE"); + + results = context.loadServices(properties); + Assert.assertEquals(0, results.size()); + Assert.assertFalse(results.containsKey("test")); + + // TODO-fdesbois-20100510 : need integration tests for all existing topia services + } + +// @Test +// public void testGetServices() throws Exception { +// } +// +// @Test +// public void testServiceEnabled() throws Exception { +// } +// +// @Test +// public void testGetService() throws Exception { +// } +// +// @Test +// public void testGetAllServices() throws Exception { +// } +// +// @Test +// public void testGetChildContext() throws Exception { +// } +// +// @Test +// public void testRemoveChildContext() throws Exception { +// } +// +// @Test +// public void testGetParentContext() throws Exception { +// } +// +// @Test +// public void testGetRootContext() throws Exception { +// } +// +// @Test +// public void testGetConfig() throws Exception { +// } +// +// @Test +// public void testCreateSchema() throws Exception { +// } +// +// @Test +// public void testShowCreateSchema() throws Exception { +// } +// +// @Test +// public void testUpdateSchema() throws Exception { +// } +// +// @Test +// public void testGetHibernate() throws Exception { +// } +// +// @Test +// public void testGetHibernateFactory() throws Exception { +// } +// +// @Test +// public void testGetHibernateConfiguration() throws Exception { +// } +// +// @Test +// public void testGetDAO() throws Exception { +// } +// +// @Test +// public void testBeginTransaction() throws Exception { +// } +// +// @Test +// public void testCommitTransaction() throws Exception { +// } +// +// @Test +// public void testRollbackTransaction() throws Exception { +// } +// +// @Test +// public void testCloseContext() throws Exception { +// } +// +// @Test +// public void testIsClosed() throws Exception { +// } +// +// @Test +// public void testFindByTopiaId() throws Exception { +// } +// +// @Test +// public void testFind() throws Exception { +// } +// +// @Test +// public void testFind2() throws Exception { +// } +// +// @Test +// public void testExecute() throws Exception { +// } +// +// @Test +// public void testAdd() throws Exception { +// } +// +// @Test +// public void testImportXML() throws Exception { +// } +// +// @Test +// public void testExportXML() throws Exception { +// } +// +// @Test +// public void testReplicate() throws Exception { +// } +// +// @Test +// public void testReplicateEntity() throws Exception { +// } +// +// @Test +// public void testReplicateEntities() throws Exception { +// } +// +// @Test +// public void testGetFiresSupport() throws Exception { +// } +// +// @Test +// public void testBackup() throws Exception { +// } +// +// @Test +// public void testRestore() throws Exception { +// } +// +// @Test +// public void testClear() throws Exception { +// } +// +// @Test +// public void testGetPersistenceClasses() throws Exception { +// } +// +// @Test +// public void testIsSchemaExist() throws Exception { +// } +} Property changes on: trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaContextImplTest.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL
participants (1)
-
fdesbois@users.nuiton.org