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.NoSuchCompanyException;
024: import com.liferay.portal.kernel.bean.BeanLocatorUtil;
025: import com.liferay.portal.model.Company;
026: import com.liferay.portal.service.persistence.BasePersistenceTestCase;
027:
028: /**
029: * <a href="CompanyPersistenceTest.java.html"><b><i>View Source</i></b></a>
030: *
031: * @author Brian Wing Shun Chan
032: *
033: */
034: public class CompanyPersistenceTest extends BasePersistenceTestCase {
035: protected void setUp() throws Exception {
036: super .setUp();
037:
038: _persistence = (CompanyPersistence) BeanLocatorUtil
039: .locate(_TX_IMPL);
040: }
041:
042: public void testCreate() throws Exception {
043: long pk = nextLong();
044:
045: Company company = _persistence.create(pk);
046:
047: assertNotNull(company);
048:
049: assertEquals(company.getPrimaryKey(), pk);
050: }
051:
052: public void testRemove() throws Exception {
053: Company newCompany = addCompany();
054:
055: _persistence.remove(newCompany);
056:
057: Company existingCompany = _persistence
058: .fetchByPrimaryKey(newCompany.getPrimaryKey());
059:
060: assertNull(existingCompany);
061: }
062:
063: public void testUpdateNew() throws Exception {
064: addCompany();
065: }
066:
067: public void testUpdateExisting() throws Exception {
068: long pk = nextLong();
069:
070: Company newCompany = _persistence.create(pk);
071:
072: newCompany.setAccountId(nextLong());
073: newCompany.setWebId(randomString());
074: newCompany.setKey(randomString());
075: newCompany.setVirtualHost(randomString());
076: newCompany.setMx(randomString());
077: newCompany.setLogoId(nextLong());
078:
079: _persistence.update(newCompany);
080:
081: Company existingCompany = _persistence
082: .findByPrimaryKey(newCompany.getPrimaryKey());
083:
084: assertEquals(existingCompany.getCompanyId(), newCompany
085: .getCompanyId());
086: assertEquals(existingCompany.getAccountId(), newCompany
087: .getAccountId());
088: assertEquals(existingCompany.getWebId(), newCompany.getWebId());
089: assertEquals(existingCompany.getKey(), newCompany.getKey());
090: assertEquals(existingCompany.getVirtualHost(), newCompany
091: .getVirtualHost());
092: assertEquals(existingCompany.getMx(), newCompany.getMx());
093: assertEquals(existingCompany.getLogoId(), newCompany
094: .getLogoId());
095: }
096:
097: public void testFindByPrimaryKeyExisting() throws Exception {
098: Company newCompany = addCompany();
099:
100: Company existingCompany = _persistence
101: .findByPrimaryKey(newCompany.getPrimaryKey());
102:
103: assertEquals(existingCompany, newCompany);
104: }
105:
106: public void testFindByPrimaryKeyMissing() throws Exception {
107: long pk = nextLong();
108:
109: try {
110: _persistence.findByPrimaryKey(pk);
111:
112: fail("Missing entity did not throw NoSuchCompanyException");
113: } catch (NoSuchCompanyException nsee) {
114: }
115: }
116:
117: public void testFetchByPrimaryKeyExisting() throws Exception {
118: Company newCompany = addCompany();
119:
120: Company existingCompany = _persistence
121: .fetchByPrimaryKey(newCompany.getPrimaryKey());
122:
123: assertEquals(existingCompany, newCompany);
124: }
125:
126: public void testFetchByPrimaryKeyMissing() throws Exception {
127: long pk = nextLong();
128:
129: Company missingCompany = _persistence.fetchByPrimaryKey(pk);
130:
131: assertNull(missingCompany);
132: }
133:
134: protected Company addCompany() throws Exception {
135: long pk = nextLong();
136:
137: Company company = _persistence.create(pk);
138:
139: company.setAccountId(nextLong());
140: company.setWebId(randomString());
141: company.setKey(randomString());
142: company.setVirtualHost(randomString());
143: company.setMx(randomString());
144: company.setLogoId(nextLong());
145:
146: _persistence.update(company);
147:
148: return company;
149: }
150:
151: private static final String _TX_IMPL = CompanyPersistence.class
152: .getName()
153: + ".transaction";
154: private CompanyPersistence _persistence;
155: }
|