mirror of
https://github.com/apache/struts.git
synced 2026-08-11 01:27:14 +00:00
WW-1399 Extend unit tests for iBATIS statements; move the "sample" script back (seems to work now).
git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@426954 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
@@ -17,7 +17,7 @@ public class AppData {
|
||||
private String locale_code;
|
||||
private String locale_name;
|
||||
|
||||
private String account_key;
|
||||
private String registration_key;
|
||||
private String username;
|
||||
private String password;
|
||||
private String password2;
|
||||
@@ -29,16 +29,44 @@ public class AppData {
|
||||
private String protocol_code;
|
||||
private String protocol_name;
|
||||
|
||||
private String host_key;
|
||||
private String host_name;
|
||||
private String subscription_key;
|
||||
private String subscription_host;
|
||||
private String host_user;
|
||||
private String host_pass;
|
||||
private Integer host_auto;
|
||||
|
||||
/**
|
||||
* <p>Adapt internal Integer value to external boolean value. </p>
|
||||
* @return False if host_auto==0, True otherwise
|
||||
*/
|
||||
public boolean isHost_auto_checkbox() {
|
||||
Integer _host_auto = getHost_auto();
|
||||
if (_host_auto == null) _host_auto = 0;
|
||||
return (_host_auto == 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Adapt internal Integer value to external boolean value. </p>
|
||||
*/
|
||||
public void setHost_auto_checkbox(boolean host_auto_checkbox) {
|
||||
if (host_auto_checkbox)
|
||||
setHost_auto(1);
|
||||
else setHost_auto(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Return true if a logic or state test passed,
|
||||
* such as whether a record already exists.</p>
|
||||
* @return True if a business logic test passed.
|
||||
*/
|
||||
public boolean isNominal() {
|
||||
return nominal;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Record outcome of a logic or state test,
|
||||
* such as whether a record already exists.</p>
|
||||
*/
|
||||
public void setNominal(boolean nominal) {
|
||||
this.nominal = nominal;
|
||||
}
|
||||
@@ -67,12 +95,12 @@ public class AppData {
|
||||
this.locale_name = locale_name;
|
||||
}
|
||||
|
||||
public String getAccount_key() {
|
||||
return account_key;
|
||||
public String getRegistration_key() {
|
||||
return registration_key;
|
||||
}
|
||||
|
||||
public void setAccount_key(String account_key) {
|
||||
this.account_key = account_key;
|
||||
public void setRegistration_key(String registration_key) {
|
||||
this.registration_key = registration_key;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
@@ -139,20 +167,20 @@ public class AppData {
|
||||
this.protocol_code = protocol_code;
|
||||
}
|
||||
|
||||
public String getHost_key() {
|
||||
return host_key;
|
||||
public String getSubscription_key() {
|
||||
return subscription_key;
|
||||
}
|
||||
|
||||
public void setHost_key(String host_key) {
|
||||
this.host_key = host_key;
|
||||
public void setSubscription_key(String subscription_key) {
|
||||
this.subscription_key = subscription_key;
|
||||
}
|
||||
|
||||
public String getHost_name() {
|
||||
return host_name;
|
||||
public String getSubscription_host() {
|
||||
return subscription_host;
|
||||
}
|
||||
|
||||
public void setHost_name(String host_name) {
|
||||
this.host_name = host_name;
|
||||
public void setSubscription_host(String subscription_host) {
|
||||
this.subscription_host = subscription_host;
|
||||
}
|
||||
|
||||
public String getHost_user() {
|
||||
@@ -187,16 +215,4 @@ public class AppData {
|
||||
this.host_auto = host_auto;
|
||||
}
|
||||
|
||||
public boolean isHost_auto_checkbox() {
|
||||
Integer _host_auto = getHost_auto();
|
||||
if (_host_auto == null) _host_auto = 0;
|
||||
return (_host_auto == 0);
|
||||
}
|
||||
|
||||
public void setHost_auto_checkbox(boolean host_auto_checkbox) {
|
||||
if (host_auto_checkbox)
|
||||
setHost_auto(1);
|
||||
else setHost_auto(0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,7 +23,22 @@ package mailreader2;
|
||||
*/
|
||||
public final class Constants {
|
||||
|
||||
// --- Tokens ----
|
||||
// -- Statements --
|
||||
|
||||
public static final String LOCALE_LIST = "LOCALE_LIST";
|
||||
public static final String REGISTRATION_INSERT_ASSERT = "REGISTRATION_INSERT_ASSERT";
|
||||
public static final String REGISTRATION_INSERT = "REGISTRATION_INSERT";
|
||||
public static final String REGISTRATION_PASSWORD = "REGISTRATION_PASSWORD";
|
||||
public static final String REGISTRATION_FULLNAME = "REGISTRATION_FULLNAME";
|
||||
public static final String REGISTRATION_EDIT = "REGISTRATION_EDIT";
|
||||
public static final String REGISTRATION_UPDATE = "REGISTRATION_UPDATE";
|
||||
public static final String SUBSCRIPTION_INSERT_ASSERT = "SUBSCRIPTION_INSERT_ASSERT";
|
||||
public static final String SUBSCRIPTION_INSERT = "SUBSCRIPTION_INSERT";
|
||||
public static final String SUBSCRIPTION_LIST = "SUBSCRIPTION_LIST";
|
||||
public static final String SUBSCRIPTION_EDIT = "SUBSCRIPTION_EDIT";
|
||||
public static final String SUBSCRIPTION_UPDATE = "SUBSCRIPTION_UPDATE";
|
||||
|
||||
// -- Tokens --
|
||||
|
||||
/**
|
||||
* <p> The token representing a "cancel" request. </p>
|
||||
|
||||
@@ -3,24 +3,85 @@
|
||||
|
||||
<sqlMap namespace="mailreader">
|
||||
|
||||
<typeAlias alias="data"
|
||||
type="mailreader2.AppData"/>
|
||||
<typeAlias alias="data"
|
||||
type="mailreader2.AppData"/>
|
||||
|
||||
<update id="registration_update" parameterClass="data">
|
||||
</update>
|
||||
|
||||
<select id="subscription_list" parameterClass="data">
|
||||
</select>
|
||||
|
||||
<insert id="registration_insert" parameterClass="data">
|
||||
</insert>
|
||||
|
||||
<select id="registration_fullname" parameterClass="data" resultClass="data">
|
||||
SELECT username, fullname FROM registration WHERE username=#username#;
|
||||
</select>
|
||||
|
||||
<select id="locale_list" parameterClass="data" resultClass="data">
|
||||
SELECT locale_code, locale_name FROM locale;
|
||||
<select id="LOCALE_LIST" resultClass="data">
|
||||
SELECT pk_locale AS locale_key, locale_code
|
||||
FROM locale;
|
||||
</select>
|
||||
|
||||
<select id="REGISTRATION_INSERT_ASSERT" parameterClass="data" resultClass="long">
|
||||
SELECT COUNT(*)
|
||||
FROM registration
|
||||
WHERE username=#username#;
|
||||
</select>
|
||||
|
||||
<insert id="REGISTRATION_INSERT" parameterClass="data">
|
||||
INSERT INTO registration
|
||||
(pk_registration, fk_locale, username, password, fullname, email_from, email_replyto)
|
||||
VALUES (#registration_key#, #locale_key#, #username#, #password#, #fullname#, #email_from#, #email_replyto#);
|
||||
</insert>
|
||||
|
||||
<select id="REGISTRATION_PASSWORD" parameterClass="data" resultClass="data">
|
||||
SELECT username, password
|
||||
FROM registration
|
||||
WHERE username=#username#;
|
||||
</select>
|
||||
|
||||
<select id="REGISTRATION_FULLNAME" parameterClass="data" resultClass="data">
|
||||
SELECT username, fullname
|
||||
FROM registration
|
||||
WHERE username=#username#;
|
||||
</select>
|
||||
|
||||
<select id="REGISTRATION_EDIT" parameterClass="data" resultClass="data">
|
||||
SELECT pk_registration AS registration_key, fk_locale AS locale_key,
|
||||
username, password, fullname, email_from, email_replyto
|
||||
FROM registration
|
||||
WHERE username=#username#;
|
||||
</select>
|
||||
|
||||
<update id="REGISTRATION_UPDATE" parameterClass="data">
|
||||
UPDATE registration
|
||||
SET fk_locale=#locale_key#, username=#username#, password=#password#, fullname=#fullname#,
|
||||
email_from=#email_from#, email_replyto=#email_replyto#
|
||||
WHERE pk_registration=#registration_key#;
|
||||
</update>
|
||||
|
||||
<select id="SUBSCRIPTION_INSERT_ASSERT" parameterClass="data" resultClass="data">
|
||||
SELECT COUNT(*)
|
||||
FROM subscription
|
||||
WHERE fk_registration=#registration_key#
|
||||
AND subscription_host=#subscription_host#;
|
||||
</select>
|
||||
|
||||
<insert id="SUBSCRIPTION_INSERT" parameterClass="data">
|
||||
INSERT INTO subscription
|
||||
(pk_subscription, fk_registration, fk_protocol, subscription_host, host_user, host_pass, host_auto)
|
||||
VALUES (#subscription_key#, #registration_key#, #protocol_key#, #username#,
|
||||
#subscription_host#, #host_user#, #host_pass#, #host_auto#);
|
||||
</insert>
|
||||
|
||||
<select id="SUBSCRIPTION_LIST" parameterClass="data" resultClass="data">
|
||||
SELECT pk_subscription AS subscription_key,
|
||||
subscription_host, host_user, host_pass, host_auto, protocol_name
|
||||
FROM subscription
|
||||
JOIN protocol ON fk_protocol=pk_protocol
|
||||
WHERE fk_registration=#registration_key#;
|
||||
</select>
|
||||
|
||||
<select id="SUBSCRIPTION_EDIT" parameterClass="data" resultClass="data">
|
||||
SELECT pk_subscription AS subscription_key, fk_registration AS registration_key, fk_protocol AS protocol_key,
|
||||
subscription_host, host_user, host_pass, host_auto FROM subscription, protocol
|
||||
WHERE pk_subscription=#subscription_key#;
|
||||
</select>
|
||||
|
||||
<update id="SUBSCRIPTION_UPDATE" parameterClass="data">
|
||||
UPDATE subscription
|
||||
SET fk_registration=#registration_key#, fk_protocol=#protocol_key#,
|
||||
subscription_host=#subscription_host#, host_user=#host_user#, host_pass=#host_pass#, host_auto=#host_auto#
|
||||
FROM subscription WHERE pk_subscription=#subscription_key#;
|
||||
</update>
|
||||
|
||||
</sqlMap>
|
||||
|
||||
@@ -6,17 +6,82 @@ package mailreader2;
|
||||
*/
|
||||
public class MailreaderTest extends BaseSqlMapTest {
|
||||
|
||||
// DEFAULTS FROM SAMPLE SCRIPT
|
||||
|
||||
private static String locale_key = "01-en";
|
||||
|
||||
private static String registration_key = "01-user";
|
||||
private static String username = "user";
|
||||
private static String password = "pass";
|
||||
private static String fullname = "John Q. User";
|
||||
private static String email_from = "zaphod@magrathea.com";
|
||||
private static String email_replyto = "zb42@igmail.com";
|
||||
|
||||
private static String registration_key2 = "02-zaphod";
|
||||
private static String username2 = "zaphod";
|
||||
private static String password2 = "g4rgl3Bl4st3r";
|
||||
private static String fullname2 = "Zaphod Beeblebrox";
|
||||
private static String email_from2 = "zaphod@magrathea.com";
|
||||
private static String email_replyto2 = "zb42@igmail.com";
|
||||
|
||||
// SETUP & TEARDOWN
|
||||
|
||||
public void testUser_locale() throws Exception {
|
||||
AppData output = (AppData) sqlMap.queryForObject("locale_list",null);
|
||||
private AppData input;
|
||||
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
input = new AppData();
|
||||
}
|
||||
|
||||
public void testLOCALE_LIST() throws Exception {
|
||||
AppData output = (AppData) sqlMap.queryForObject(Constants.LOCALE_LIST,null);
|
||||
assertNotNull(output);
|
||||
}
|
||||
|
||||
public void testUser_fullname() throws Exception {
|
||||
AppData input = new AppData();
|
||||
input.setUsername("user");
|
||||
AppData output = (AppData) sqlMap.queryForObject("registration_fullname", input);
|
||||
assertEquals("John Q. User", output.getFullname());
|
||||
public void testREGISTRATION_INSERT_ASSERT_fail() throws Exception {
|
||||
input.setUsername(username);
|
||||
Object output = sqlMap.queryForObject(Constants.REGISTRATION_INSERT_ASSERT,input);
|
||||
Long count = (Long) output;
|
||||
assertTrue("Expected user to already exist",count.intValue()>0);
|
||||
}
|
||||
|
||||
public void testREGISTRATION_INSERT_ASSERT() throws Exception {
|
||||
input.setUsername(username2);
|
||||
Object output = sqlMap.queryForObject(Constants.REGISTRATION_INSERT_ASSERT,input);
|
||||
Long count = (Long) output;
|
||||
assertTrue("Expected user to already exist",count.intValue()==0);
|
||||
}
|
||||
|
||||
public void testREGISTRATION_INSERT() throws Exception {
|
||||
input.setRegistration_key(registration_key2);
|
||||
input.setLocale_key(locale_key);
|
||||
input.setUsername(username2);
|
||||
input.setPassword(password2 );
|
||||
input.setFullname(fullname2);
|
||||
input.setEmail_from(email_from2);
|
||||
input.setEmail_replyto(email_replyto2);
|
||||
sqlMap.insert(Constants.REGISTRATION_INSERT,input);
|
||||
// Trust but verify
|
||||
input.setPassword(null);
|
||||
AppData output = (AppData) sqlMap.queryForObject(Constants.REGISTRATION_PASSWORD,input);
|
||||
assertEquals(password2,output.getPassword());
|
||||
}
|
||||
|
||||
public void testREGISTRATION_PASSWORD() throws Exception {
|
||||
input.setUsername(username);
|
||||
AppData output = (AppData) sqlMap.queryForObject(Constants.REGISTRATION_PASSWORD,input);
|
||||
assertEquals(password,output.getPassword());
|
||||
}
|
||||
|
||||
public void test() throws Exception {
|
||||
}
|
||||
|
||||
public void testREGISTRATION_FULLNAME() throws Exception {
|
||||
input.setUsername(username);
|
||||
AppData output = (AppData) sqlMap.queryForObject(Constants.REGISTRATION_FULLNAME, input);
|
||||
assertEquals(fullname, output.getFullname());
|
||||
assertNull("Expected other fields to be null", output.getPassword());
|
||||
assertNull("Expected other fields to be null",output.getEmail_from());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user