1
0
mirror of https://github.com/sismics/docs.git synced 2025-12-18 04:01:42 +00:00

Initial commit

This commit is contained in:
jendib
2013-07-27 18:33:20 +02:00
parent 41cb6dd9ae
commit 9b74bd8194
156 changed files with 72879 additions and 0 deletions

View File

@@ -0,0 +1,31 @@
package com.sismics.docs;
import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction;
import org.junit.After;
import org.junit.Before;
import com.sismics.util.context.ThreadLocalContext;
import com.sismics.util.jpa.EMF;
/**
* Base class of tests with a transactional context.
*
* @author jtremeaux
*/
public abstract class BaseTransactionalTest {
@Before
public void setUp() throws Exception {
// Initialize the entity manager
EntityManager em = EMF.get().createEntityManager();
ThreadLocalContext context = ThreadLocalContext.get();
context.setEntityManager(em);
EntityTransaction tx = em.getTransaction();
tx.begin();
}
@After
public void tearDown() throws Exception {
}
}

View File

@@ -0,0 +1,36 @@
package com.sismics.docs.core.dao.jpa;
import junit.framework.Assert;
import org.junit.Test;
import com.sismics.docs.BaseTransactionalTest;
import com.sismics.docs.core.dao.jpa.UserDao;
import com.sismics.docs.core.model.jpa.User;
import com.sismics.docs.core.util.TransactionUtil;
/**
* Tests the persistance layer.
*
* @author jtremeaux
*/
public class TestJpa extends BaseTransactionalTest {
@Test
public void testJpa() throws Exception {
// Create a user
UserDao userDao = new UserDao();
User user = new User();
user.setUsername("username");
user.setEmail("toto@docs.com");
user.setLocaleId("fr");
user.setRoleId("admin");
String id = userDao.create(user);
TransactionUtil.commit();
// Search a user by his ID
user = userDao.getById(id);
Assert.assertNotNull(user);
Assert.assertEquals("toto@docs.com", user.getEmail());
}
}

View File

@@ -0,0 +1,18 @@
package com.sismics.util;
import junit.framework.Assert;
import org.junit.Test;
/**
* Test of the date utilities.
*
* @author jtremeaux
*/
public class TestDateUtil {
@Test
public void guessTimezoneCodeTest() throws Exception {
Assert.assertEquals("Thu, 04 APR 2013 20:37:27 +10", DateUtil.guessTimezoneOffset("Thu, 04 APR 2013 20:37:27 AEST"));
}
}

View File

@@ -0,0 +1,30 @@
package com.sismics.util;
import java.util.List;
import junit.framework.Assert;
import org.junit.Test;
/**
* Test of the resource utils.
*
* @author jtremeaux
*/
public class TestResourceUtil {
@Test
public void listFilesTest() throws Exception {
List<String> fileList = ResourceUtil.list(Test.class, "/junit/framework");
Assert.assertTrue(fileList.contains("Test.class"));
fileList = ResourceUtil.list(Test.class, "/junit/framework/");
Assert.assertTrue(fileList.contains("Test.class"));
fileList = ResourceUtil.list(Test.class, "junit/framework/");
Assert.assertTrue(fileList.contains("Test.class"));
fileList = ResourceUtil.list(Test.class, "junit/framework/");
Assert.assertTrue(fileList.contains("Test.class"));
}
}

View File

@@ -0,0 +1,10 @@
hibernate.connection.driver_class=org.hsqldb.jdbcDriver
hibernate.connection.url=jdbc:hsqldb:mem:d<>s
hibernate.connection.username=sa
hibernate.connection.password=
hibernate.hbm2ddl.auto=none
hibernate.dialect=org.hibernate.dialect.HSQLDialect
hibernate.show_sql=true
hibernate.format_sql=false
hibernate.max_fetch_depth=5
hibernate.cache.use_second_level_cache=false

View File

@@ -0,0 +1,8 @@
log4j.rootCategory=DEBUG, CONSOLE, MEMORY
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern=%d{DATE} %p %l %m %n
log4j.appender.MEMORY=com.sismics.util.log4j.MemoryAppender
log4j.appender.MEMORY.size=1000
log4j.logger.com.sismics=DEBUG