001: /*
002: * ChainBuilder ESB
003: * Visual Enterprise Integration
004: *
005: * Copyright (C) 2006 Bostech Corporation
006: *
007: * This program is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU General Public License as published by the
009: * Free Software Foundation; either version 2 of the License, or (at your option)
010: * any later version.
011: *
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
014: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
015: * for more details.
016: *
017: * You should have received a copy of the GNU General Public License along with
018: * this program; if not, write to the Free Software Foundation, Inc.,
019: * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020: *
021: *
022: * $Id$
023: */
024: package com.bostechcorp.cbesb.common.util.emailsettings;
025:
026: import java.sql.Timestamp;
027: import java.util.Date;
028: import java.util.List;
029:
030: import com.bostechcorp.cbesb.common.util.emailsettings.DaoConfig;
031: import com.bostechcorp.cbesb.common.util.emailsettings.vo.EmailSettingsVO;
032: import com.ibatis.sqlmap.client.SqlMapClient;
033:
034: import junit.framework.TestCase;
035:
036: public class TestEmailSettings extends TestCase {
037:
038: private DaoConfig daoConfig;
039: private SqlMapClient sqlMap;
040: private EmailSettingsVO vo;
041:
042: @Override
043: protected void setUp() throws Exception {
044: super .setUp();
045: daoConfig = new DaoConfig();
046: sqlMap = daoConfig.getSqlMapInstance();
047: }
048:
049: public void testInsert() throws Exception {
050: vo = new EmailSettingsVO();
051: vo.setName("testSettingName");
052: vo.setHost("smtp.263xmail.com");
053: vo.setPort("25");
054: vo.setUserName("cbesb@inprosystem.com");
055: vo.setPassword("cbesb");
056: vo.setFromAddress("cbesb@inprosystem.com");
057: vo.setToAddress("j.zhang@inprosystem.com");
058: vo.setCc("rui.hou@inprosystem.com");
059: vo.setLastUpdated(new Timestamp(System.currentTimeMillis()));
060: sqlMap.insert("insertEmailSettings", vo);
061: }
062:
063: public void testQuery() throws Exception {
064: vo = new EmailSettingsVO();
065: vo.setName("testSettingName");
066: Object result = sqlMap.queryForObject(
067: "queryEmailSettingsByName", vo);
068: EmailSettingsVO resultVO = (EmailSettingsVO) result;
069: assertVO(resultVO, false);
070: }
071:
072: public void testUpdate() throws Exception {
073: vo = new EmailSettingsVO();
074: vo.setName("testSettingName");
075: vo.setHost("smtp.263xmail.com2");
076: vo.setPort("252");
077: vo.setUserName("cbesb@inprosystem.com2");
078: vo.setPassword("cbesb2");
079: vo.setFromAddress("cbesb@inprosystem.com2");
080: vo.setToAddress("j.zhang@inprosystem.com2");
081: vo.setCc("rui.hou@inprosystem.com2");
082: vo.setLastUpdated(new Timestamp(System.currentTimeMillis()));
083: sqlMap.update("updateEmailSetting", vo);
084: Object result = sqlMap.queryForObject(
085: "queryEmailSettingsByName", vo);
086: EmailSettingsVO resultVO = (EmailSettingsVO) result;
087: assertVO(resultVO, true);
088: }
089:
090: public void testQueryNames() throws Exception {
091: Object result = sqlMap.queryForList(
092: "queryAllNamesOfEmailSettings", null);
093: if (result instanceof List) {
094: List list = (List) result;
095: System.out.println(list.size());
096: for (int i = 0; i < list.size(); i++) {
097: String s = (String) list.get(i);
098: System.out.println(s);
099: }
100: }
101: }
102:
103: public void testDelete() throws Exception {
104: vo = new EmailSettingsVO();
105: vo.setName("testSettingName");
106: sqlMap.delete("deleteEmailSettings", vo);
107: }
108:
109: private void assertVO(EmailSettingsVO resultVO, boolean isUpdated) {
110: System.out.println(resultVO.getId());
111: System.out.println(resultVO.getName());
112: System.out.println(resultVO.getHost());
113: System.out.println(resultVO.getPort());
114: System.out.println(resultVO.getUserName());
115: System.out.println(resultVO.getPassword());
116: System.out.println(resultVO.getFromAddress());
117: System.out.println(resultVO.getToAddress());
118: System.out.println(resultVO.getCc());
119: System.out.println(resultVO.getLastUpdated());
120: if (isUpdated) {
121: assertEquals(resultVO.getHost(), "smtp.263xmail.com2");
122: assertEquals(resultVO.getPort(), "252");
123: assertEquals(resultVO.getUserName(),
124: "cbesb@inprosystem.com2");
125: assertEquals(resultVO.getPassword(), "cbesb2");
126: assertEquals(resultVO.getFromAddress(),
127: "cbesb@inprosystem.com2");
128: assertEquals(resultVO.getToAddress(),
129: "j.zhang@inprosystem.com2");
130: assertEquals(resultVO.getCc(), "rui.hou@inprosystem.com2");
131: } else {
132: assertEquals(resultVO.getHost(), "smtp.263xmail.com");
133: assertEquals(resultVO.getPort(), "25");
134: assertEquals(resultVO.getUserName(),
135: "cbesb@inprosystem.com");
136: assertEquals(resultVO.getPassword(), "cbesb");
137: assertEquals(resultVO.getFromAddress(),
138: "cbesb@inprosystem.com");
139: assertEquals(resultVO.getToAddress(),
140: "j.zhang@inprosystem.com");
141: assertEquals(resultVO.getCc(), "rui.hou@inprosystem.com");
142: }
143: }
144: }
|