From f71499efd8a43810e4e8c748b665442f0b101313 Mon Sep 17 00:00:00 2001 From: Ted Nathan Husted Date: Sun, 30 Jul 2006 22:01:59 +0000 Subject: [PATCH] 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 --- .../src/main/java/mailreader2/AppData.java | 70 ++++++++------ .../src/main/java/mailreader2/Constants.java | 17 +++- .../src/main/resources/sql/sql-map.xml | 95 +++++++++++++++---- .../test/java/mailreader2/MailreaderTest.java | 79 +++++++++++++-- .../resources/sql/mailreader-sample.sql | 0 5 files changed, 209 insertions(+), 52 deletions(-) rename apps/mailreader/src/{main => test}/resources/sql/mailreader-sample.sql (100%) diff --git a/apps/mailreader/src/main/java/mailreader2/AppData.java b/apps/mailreader/src/main/java/mailreader2/AppData.java index 9a93abbd7..8b3f6cfa1 100644 --- a/apps/mailreader/src/main/java/mailreader2/AppData.java +++ b/apps/mailreader/src/main/java/mailreader2/AppData.java @@ -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; + /** + *

Adapt internal Integer value to external boolean value.

+ * @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); + } + + /** + *

Adapt internal Integer value to external boolean value.

+ */ + public void setHost_auto_checkbox(boolean host_auto_checkbox) { + if (host_auto_checkbox) + setHost_auto(1); + else setHost_auto(0); + } + + /** + *

Return true if a logic or state test passed, + * such as whether a record already exists.

+ * @return True if a business logic test passed. + */ public boolean isNominal() { return nominal; } + /** + *

Record outcome of a logic or state test, + * such as whether a record already exists.

+ */ 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); - } - } diff --git a/apps/mailreader/src/main/java/mailreader2/Constants.java b/apps/mailreader/src/main/java/mailreader2/Constants.java index 89d96075a..28400cbfa 100644 --- a/apps/mailreader/src/main/java/mailreader2/Constants.java +++ b/apps/mailreader/src/main/java/mailreader2/Constants.java @@ -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 -- /** *

The token representing a "cancel" request.

diff --git a/apps/mailreader/src/main/resources/sql/sql-map.xml b/apps/mailreader/src/main/resources/sql/sql-map.xml index 7139fea90..31f6007d7 100644 --- a/apps/mailreader/src/main/resources/sql/sql-map.xml +++ b/apps/mailreader/src/main/resources/sql/sql-map.xml @@ -3,24 +3,85 @@ - + - - - - - - - - - - - + SELECT pk_locale AS locale_key, locale_code + FROM locale; + + + + 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#); + + + + + + + + + + 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#; + + + + + + 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#); + + + + + + + + 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#; + + diff --git a/apps/mailreader/src/test/java/mailreader2/MailreaderTest.java b/apps/mailreader/src/test/java/mailreader2/MailreaderTest.java index e9beb9643..3c9714a93 100644 --- a/apps/mailreader/src/test/java/mailreader2/MailreaderTest.java +++ b/apps/mailreader/src/test/java/mailreader2/MailreaderTest.java @@ -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()); + } + } diff --git a/apps/mailreader/src/main/resources/sql/mailreader-sample.sql b/apps/mailreader/src/test/resources/sql/mailreader-sample.sql similarity index 100% rename from apps/mailreader/src/main/resources/sql/mailreader-sample.sql rename to apps/mailreader/src/test/resources/sql/mailreader-sample.sql