Kawai Wiki

Compare Revisions

Ignore whitespace Rev 191 → Rev 192

/trunk/src/test/java/org/kawai/dao/jdbc/JdbcPageDAOTest.java
New file
0,0 → 1,82
package org.kawai.dao.jdbc;
 
import java.sql.Connection;
import java.sql.DriverManager;
 
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.kawai.model.Language;
import org.kawai.model.Page;
import org.mentabean.BeanConfig;
import org.mentabean.BeanManager;
import org.mentabean.BeanSession;
import org.mentabean.DBTypes;
import org.mentabean.jdbc.MySQLBeanSession;
 
/**
* Test class JdbcPageDAOTest.
* @author helio frota
*
*/
public class JdbcPageDAOTest {
 
/**
* Attribute beanSession of JdbcPageDAOTest.
*/
private BeanSession beanSession;
/**
* Attribute jdbcPageDAO of JdbcPageDAOTest.
*/
private JdbcPageDAO jdbcPageDAO;
 
/**
* Default setUp method.
* @throws Exception
*/
@Before
public void setUp() throws Exception {
 
BeanManager beanManager = new BeanManager();
BeanConfig beanConfig = new BeanConfig(Page.class, "Pages");
beanConfig.pk("id", "id", DBTypes.AUTOINCREMENT);
beanConfig.field("name", DBTypes.STRING);
beanConfig.field("title", DBTypes.STRING);
beanConfig.field("body", DBTypes.STRING);
beanConfig.field("languageId", "language_id", DBTypes.STRING);
beanConfig.field("systemPage", "system_page", DBTypes.BOOLEANSTRING);
beanConfig.field("frontPage", "front_page", DBTypes.BOOLEANSTRING);
beanConfig.field("modifiedById", "modified_by", DBTypes.INTEGER);
beanConfig.field("modifiedOn", "modified_on", DBTypes.NOW_ON_UPDATE_TIMESTAMP);
beanConfig.field("createdById", "created_by", DBTypes.INTEGER);
beanConfig.field("createdOn", "created_on", DBTypes.NOW_ON_INSERT_TIMESTAMP);
beanConfig.field("deleted", DBTypes.BOOLEANSTRING);
beanManager.addBeanConfig(beanConfig);
 
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/Kawai?autoReconnect=true", "kawai", "1kawai23");
beanSession = new MySQLBeanSession(beanManager, conn);
 
jdbcPageDAO = new JdbcPageDAO(beanSession);
}
 
/**
* Test method loadTest.
*/
@Ignore
@Test
public void loadTest() {
Page page = jdbcPageDAO.load(1);
}
 
/**
* Test method loadByNameTest.
*/
@Ignore
@Test
public void loadByNameTest() {
Language language = new Language(1, "en", "en_US");
Page page = jdbcPageDAO.loadByName("test", language);
}
 
}
/trunk/src/test/java/org/kawai/dao/jdbc/JdbcUserDAOTest.java
New file
0,0 → 1,74
package org.kawai.dao.jdbc;
 
import java.sql.Connection;
import java.sql.DriverManager;
 
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.kawai.model.User;
import org.mentabean.BeanConfig;
import org.mentabean.BeanManager;
import org.mentabean.BeanSession;
import org.mentabean.DBTypes;
import org.mentabean.jdbc.MySQLBeanSession;
 
/**
* Test class JdbcUserDAOTest.
* @author helio frota
*
*/
public class JdbcUserDAOTest {
 
/**
* Attribute beanSession of JdbcUserDAOTest.
*/
private BeanSession beanSession;
/**
* Attribute jdbcUserDAO of JdbcUserDAOTest.
*/
private JdbcUserDAO jdbcUserDAO;
 
/**
* Default setUp method.
* @throws Exception
*/
@Before
public void setUp() throws Exception {
 
BeanManager beanManager = new BeanManager();
BeanConfig beanConfig = new BeanConfig(User.class, "Users");
beanConfig.pk("id", DBTypes.AUTOINCREMENT);
beanConfig.field("username", DBTypes.STRING);
beanConfig.field("password", DBTypes.STRING);
beanConfig.field("groupId", "group_id", DBTypes.INTEGER);
beanManager.addBeanConfig(beanConfig);
 
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/Kawai?autoReconnect=true", "kawai", "1kawai23");
beanSession = new MySQLBeanSession(beanManager, conn);
 
jdbcUserDAO = new JdbcUserDAO(beanSession);
}
 
/**
* Test method loadTest.
*/
@Test
public void loadTest() {
User user = jdbcUserDAO.load(1);
Assert.assertNotNull(user);
Assert.assertEquals("admin", user.getUsername());
}
 
/**
* Test method findByUsernameTest.
*/
@Test
public void findByUsernameTest() {
User user = jdbcUserDAO.findByUsername("admin");
Assert.assertNotNull(user);
Assert.assertEquals("admin", user.getUsername());
}
 
}
/trunk/src/test/java/AllTests.java
3,6 → 3,8
import org.junit.runners.Suite.SuiteClasses;
import org.kawai.action.LoginActionTest;
import org.kawai.action.PageActionTest;
import org.kawai.dao.jdbc.JdbcPageDAOTest;
import org.kawai.dao.jdbc.JdbcUserDAOTest;
import org.kawai.model.ModelTest;
 
/**
14,7 → 16,9
@SuiteClasses(value = {
ModelTest.class,
LoginActionTest.class,
PageActionTest.class
PageActionTest.class,
JdbcUserDAOTest.class,
JdbcPageDAOTest.class
})
public class AllTests {