Search in sources :

Example 1 with Country

use of cn.edu.zju.acm.onlinejudge.bean.enumeration.Country in project zoj by licheng.

the class ForumPersistenceImplTest method setUp.

/**
 * Setup.
 * @throws Exception to JUnit
 */
protected void setUp() throws Exception {
    DatabaseHelper.resetAllTables(false);
    profile.setHandle("myHandle");
    profile.setPassword("myPassword");
    profile.setEmail("myEmail");
    profile.setRegDate(new Date());
    profile.setFirstName("myFirstName");
    profile.setLastName("myLastName");
    profile.setAddressLine1("myAddressLine1");
    profile.setAddressLine2("myAddressLine2");
    profile.setCity("myCity");
    profile.setState("myState");
    profile.setCountry(new Country(1, "foo"));
    profile.setZipCode("myZipCode");
    profile.setPhoneNumber("myPhoneNumber");
    profile.setBirthDate(DateFormat.getDateInstance(DateFormat.SHORT, Locale.US).parse("1/1/1980"));
    profile.setGender('M');
    profile.setSchool("mySchool");
    profile.setMajor("myMajor");
    profile.setGraduateStudent(true);
    profile.setGraduationYear(2005);
    profile.setStudentNumber("myStudentNumber");
    profile.setConfirmed(false);
    new UserPersistenceImpl().createUserProfile(profile, 1);
    forum1 = newForum(1);
    forum2 = newForum(2);
    forum3 = newForum(3);
    persistence.createForum(forum1, 1);
    persistence.createForum(forum2, 1);
    persistence.createForum(forum3, 1);
    thread1 = newThread(1, forum1.getId(), profile.getId());
    thread2 = newThread(2, forum1.getId(), profile.getId());
    thread3 = newThread(3, forum2.getId(), profile.getId());
    persistence.createThread(thread1, 1);
    persistence.createThread(thread2, 1);
    persistence.createThread(thread3, 1);
    post1 = newPost(1, thread1.getId(), profile.getId());
    post2 = newPost(2, thread1.getId(), profile.getId());
    post3 = newPost(3, thread2.getId(), profile.getId());
    persistence.createPost(post1, 1);
    persistence.createPost(post2, 1);
    persistence.createPost(post3, 1);
    thread3Posts = new ArrayList();
    for (int i = 1; i <= 10; ++i) {
        Post post = newPost(i, thread3.getId(), profile.getId());
        thread3Posts.add(post);
        persistence.createPost(post, 1);
    }
}
Also used : Post(cn.edu.zju.acm.onlinejudge.bean.Post) ArrayList(java.util.ArrayList) Country(cn.edu.zju.acm.onlinejudge.bean.enumeration.Country) Date(java.util.Date)

Example 2 with Country

use of cn.edu.zju.acm.onlinejudge.bean.enumeration.Country in project zoj by licheng.

the class SubmissionPersistenceImplTest method newUserProfile.

/**
 * Creates a new user profile.
 * @param id the id
 * @return a new user profile instance
 */
private UserProfile newUserProfile(long id) {
    UserProfile profile = new UserProfile();
    profile.setId(id);
    profile.setHandle("myHandle" + id);
    profile.setPassword("myPassword");
    profile.setEmail("myEmail" + id);
    profile.setRegDate(new Date());
    profile.setFirstName("myFirstName");
    profile.setLastName("myLastName");
    profile.setAddressLine1("myAddressLine1");
    profile.setAddressLine2("myAddressLine2");
    profile.setCity("myCity");
    profile.setState("myState");
    profile.setCountry(new Country(1, "foo"));
    profile.setZipCode("myZipCode");
    profile.setPhoneNumber("myPhoneNumber");
    profile.setBirthDate(new Date(0));
    profile.setGender('M');
    profile.setSchool("mySchool");
    profile.setMajor("myMajor");
    profile.setGraduateStudent(true);
    profile.setGraduationYear(2005);
    profile.setStudentNumber("myStudentNumber");
    profile.setConfirmed(false);
    return profile;
}
Also used : UserProfile(cn.edu.zju.acm.onlinejudge.bean.UserProfile) Country(cn.edu.zju.acm.onlinejudge.bean.enumeration.Country) Date(java.util.Date)

Example 3 with Country

use of cn.edu.zju.acm.onlinejudge.bean.enumeration.Country in project zoj by licheng.

the class UserPersistenceImplTest method testUpdateUserProfile.

/**
 * Tests updateUserProfile method
 * @throws Exception to JUnit
 */
public void testUpdateUserProfile() throws Exception {
    persistence.createUserProfile(profile, 1);
    profile.setHandle("myNewHandle");
    profile.setPassword("myNewPassword");
    profile.setEmail("myNewEmail");
    profile.setRegDate(new Date());
    profile.setFirstName("myNewFirstName");
    profile.setLastName("myNewLastName");
    profile.setAddressLine1("myNewAddressLine1");
    profile.setAddressLine2("myNewAddressLine2");
    profile.setCity("myNewCity");
    profile.setState("myNewState");
    profile.setCountry(new Country(2, "foo"));
    profile.setZipCode("myNewZipCode");
    profile.setPhoneNumber("myNewPhoneNumber");
    profile.setBirthDate(DateFormat.getDateInstance(DateFormat.SHORT, Locale.US).parse("1/1/1980"));
    profile.setGender('F');
    profile.setSchool("myNewSchool");
    profile.setMajor("myNewMajor");
    profile.setGraduateStudent(false);
    profile.setGraduationYear(2006);
    profile.setStudentNumber("myNewStudentNumber");
    profile.setConfirmed(false);
    persistence.updateUserProfile(profile, 1);
    UserProfile profile1 = persistence.getUserProfile(profile.getId());
    checkUserProfile(profile, profile1);
}
Also used : UserProfile(cn.edu.zju.acm.onlinejudge.bean.UserProfile) Country(cn.edu.zju.acm.onlinejudge.bean.enumeration.Country) Date(java.util.Date)

Example 4 with Country

use of cn.edu.zju.acm.onlinejudge.bean.enumeration.Country in project zoj by licheng.

the class UserPersistenceImplTest method testGetAllCountries.

/**
 * Tests getAllCountries method
 * @throws Exception to JUnit
 */
public void testGetAllCountries() throws Exception {
    List countries = persistence.getAllCountries();
    assertTrue("wrong size", countries.size() > 0);
    for (Iterator it = countries.iterator(); it.hasNext(); ) {
        Country country = (Country) it.next();
        assertNotNull("wrong name", country.getName());
    }
}
Also used : Iterator(java.util.Iterator) Country(cn.edu.zju.acm.onlinejudge.bean.enumeration.Country) List(java.util.List)

Example 5 with Country

use of cn.edu.zju.acm.onlinejudge.bean.enumeration.Country in project zoj by licheng.

the class UserPersistenceImpl method populateUserProfile.

/**
 * Populates a UserProfile instance with the given ResultSet.
 *
 * @param rs
 *            the ResultSet
 * @return the UserProfile instance
 * @throws SQLException
 *             if any error occurs
 */
private UserProfile populateUserProfile(ResultSet rs) throws SQLException {
    UserProfile profile = new UserProfile();
    profile.setId(rs.getLong(DatabaseConstants.USER_PROFILE_USER_PROFILE_ID));
    profile.setHandle(rs.getString(DatabaseConstants.USER_PROFILE_HANDLE));
    profile.setPassword(rs.getString(DatabaseConstants.USER_PROFILE_PASSWORD));
    profile.setEmail(rs.getString(DatabaseConstants.USER_PROFILE_EMAIL_ADDRESS));
    profile.setRegDate(rs.getTimestamp(DatabaseConstants.USER_PROFILE_REG_DATE));
    profile.setFirstName(rs.getString(DatabaseConstants.USER_PROFILE_FIRST_NAME));
    profile.setLastName(rs.getString(DatabaseConstants.USER_PROFILE_LAST_NAME));
    profile.setAddressLine1(rs.getString(DatabaseConstants.USER_PROFILE_ADDRESS_LINE1));
    profile.setAddressLine2(rs.getString(DatabaseConstants.USER_PROFILE_ADDRESS_LINE2));
    profile.setCity(rs.getString(DatabaseConstants.USER_PROFILE_CITY));
    profile.setState(rs.getString(DatabaseConstants.USER_PROFILE_STATE));
    profile.setCountry(new Country(rs.getLong(DatabaseConstants.USER_PROFILE_COUNTRY_ID), "foo"));
    profile.setZipCode(rs.getString(DatabaseConstants.USER_PROFILE_ZIP_CODE));
    profile.setPhoneNumber(rs.getString(DatabaseConstants.USER_PROFILE_PHONE_NUMBER));
    profile.setBirthDate(rs.getDate(DatabaseConstants.USER_PROFILE_BIRTH_DATE));
    String gender = rs.getString(DatabaseConstants.USER_PROFILE_GENDER);
    profile.setGender(gender == null || gender.length() == 0 ? ' ' : gender.charAt(0));
    profile.setSchool(rs.getString(DatabaseConstants.USER_PROFILE_SCHOOL));
    profile.setMajor(rs.getString(DatabaseConstants.USER_PROFILE_MAJOR));
    profile.setGraduateStudent(rs.getBoolean(DatabaseConstants.USER_PROFILE_GRADUATE_STUDENT));
    profile.setGraduationYear(rs.getInt(DatabaseConstants.USER_PROFILE_GRADUATION_YEAR));
    profile.setStudentNumber(rs.getString(DatabaseConstants.USER_PROFILE_STUDENT_NUMBER));
    profile.setConfirmed(rs.getBoolean(DatabaseConstants.USER_PROFILE_CONFIRMED));
    profile.setActive(rs.getBoolean(DatabaseConstants.USER_PROFILE_ACTIVE));
    profile.setNickName(rs.getString("nickname"));
    profile.setOldEmail(rs.getString("old_email"));
    return profile;
}
Also used : UserProfile(cn.edu.zju.acm.onlinejudge.bean.UserProfile) Country(cn.edu.zju.acm.onlinejudge.bean.enumeration.Country)

Aggregations

Country (cn.edu.zju.acm.onlinejudge.bean.enumeration.Country)8 Date (java.util.Date)5 UserProfile (cn.edu.zju.acm.onlinejudge.bean.UserProfile)3 ArrayList (java.util.ArrayList)3 Post (cn.edu.zju.acm.onlinejudge.bean.Post)2 PersistenceCreationException (cn.edu.zju.acm.onlinejudge.persistence.PersistenceCreationException)1 PersistenceException (cn.edu.zju.acm.onlinejudge.persistence.PersistenceException)1 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 Iterator (java.util.Iterator)1 List (java.util.List)1