001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.portal.service.persistence;
022:
023: import com.liferay.portal.NoSuchAccountException;
024: import com.liferay.portal.kernel.bean.BeanLocatorUtil;
025: import com.liferay.portal.model.Account;
026: import com.liferay.portal.service.persistence.BasePersistenceTestCase;
027:
028: /**
029: * <a href="AccountPersistenceTest.java.html"><b><i>View Source</i></b></a>
030: *
031: * @author Brian Wing Shun Chan
032: *
033: */
034: public class AccountPersistenceTest extends BasePersistenceTestCase {
035: protected void setUp() throws Exception {
036: super .setUp();
037:
038: _persistence = (AccountPersistence) BeanLocatorUtil
039: .locate(_TX_IMPL);
040: }
041:
042: public void testCreate() throws Exception {
043: long pk = nextLong();
044:
045: Account account = _persistence.create(pk);
046:
047: assertNotNull(account);
048:
049: assertEquals(account.getPrimaryKey(), pk);
050: }
051:
052: public void testRemove() throws Exception {
053: Account newAccount = addAccount();
054:
055: _persistence.remove(newAccount);
056:
057: Account existingAccount = _persistence
058: .fetchByPrimaryKey(newAccount.getPrimaryKey());
059:
060: assertNull(existingAccount);
061: }
062:
063: public void testUpdateNew() throws Exception {
064: addAccount();
065: }
066:
067: public void testUpdateExisting() throws Exception {
068: long pk = nextLong();
069:
070: Account newAccount = _persistence.create(pk);
071:
072: newAccount.setCompanyId(nextLong());
073: newAccount.setUserId(nextLong());
074: newAccount.setUserName(randomString());
075: newAccount.setCreateDate(nextDate());
076: newAccount.setModifiedDate(nextDate());
077: newAccount.setParentAccountId(nextLong());
078: newAccount.setName(randomString());
079: newAccount.setLegalName(randomString());
080: newAccount.setLegalId(randomString());
081: newAccount.setLegalType(randomString());
082: newAccount.setSicCode(randomString());
083: newAccount.setTickerSymbol(randomString());
084: newAccount.setIndustry(randomString());
085: newAccount.setType(randomString());
086: newAccount.setSize(randomString());
087:
088: _persistence.update(newAccount);
089:
090: Account existingAccount = _persistence
091: .findByPrimaryKey(newAccount.getPrimaryKey());
092:
093: assertEquals(existingAccount.getAccountId(), newAccount
094: .getAccountId());
095: assertEquals(existingAccount.getCompanyId(), newAccount
096: .getCompanyId());
097: assertEquals(existingAccount.getUserId(), newAccount
098: .getUserId());
099: assertEquals(existingAccount.getUserName(), newAccount
100: .getUserName());
101: assertEquals(existingAccount.getCreateDate(), newAccount
102: .getCreateDate());
103: assertEquals(existingAccount.getModifiedDate(), newAccount
104: .getModifiedDate());
105: assertEquals(existingAccount.getParentAccountId(), newAccount
106: .getParentAccountId());
107: assertEquals(existingAccount.getName(), newAccount.getName());
108: assertEquals(existingAccount.getLegalName(), newAccount
109: .getLegalName());
110: assertEquals(existingAccount.getLegalId(), newAccount
111: .getLegalId());
112: assertEquals(existingAccount.getLegalType(), newAccount
113: .getLegalType());
114: assertEquals(existingAccount.getSicCode(), newAccount
115: .getSicCode());
116: assertEquals(existingAccount.getTickerSymbol(), newAccount
117: .getTickerSymbol());
118: assertEquals(existingAccount.getIndustry(), newAccount
119: .getIndustry());
120: assertEquals(existingAccount.getType(), newAccount.getType());
121: assertEquals(existingAccount.getSize(), newAccount.getSize());
122: }
123:
124: public void testFindByPrimaryKeyExisting() throws Exception {
125: Account newAccount = addAccount();
126:
127: Account existingAccount = _persistence
128: .findByPrimaryKey(newAccount.getPrimaryKey());
129:
130: assertEquals(existingAccount, newAccount);
131: }
132:
133: public void testFindByPrimaryKeyMissing() throws Exception {
134: long pk = nextLong();
135:
136: try {
137: _persistence.findByPrimaryKey(pk);
138:
139: fail("Missing entity did not throw NoSuchAccountException");
140: } catch (NoSuchAccountException nsee) {
141: }
142: }
143:
144: public void testFetchByPrimaryKeyExisting() throws Exception {
145: Account newAccount = addAccount();
146:
147: Account existingAccount = _persistence
148: .fetchByPrimaryKey(newAccount.getPrimaryKey());
149:
150: assertEquals(existingAccount, newAccount);
151: }
152:
153: public void testFetchByPrimaryKeyMissing() throws Exception {
154: long pk = nextLong();
155:
156: Account missingAccount = _persistence.fetchByPrimaryKey(pk);
157:
158: assertNull(missingAccount);
159: }
160:
161: protected Account addAccount() throws Exception {
162: long pk = nextLong();
163:
164: Account account = _persistence.create(pk);
165:
166: account.setCompanyId(nextLong());
167: account.setUserId(nextLong());
168: account.setUserName(randomString());
169: account.setCreateDate(nextDate());
170: account.setModifiedDate(nextDate());
171: account.setParentAccountId(nextLong());
172: account.setName(randomString());
173: account.setLegalName(randomString());
174: account.setLegalId(randomString());
175: account.setLegalType(randomString());
176: account.setSicCode(randomString());
177: account.setTickerSymbol(randomString());
178: account.setIndustry(randomString());
179: account.setType(randomString());
180: account.setSize(randomString());
181:
182: _persistence.update(account);
183:
184: return account;
185: }
186:
187: private static final String _TX_IMPL = AccountPersistence.class
188: .getName()
189: + ".transaction";
190: private AccountPersistence _persistence;
191: }
|