Skip to content

Commit

Permalink
LPS-26306 AUTOGENERATED
Browse files Browse the repository at this point in the history
  • Loading branch information
Igor Beslic authored and rotty3000 committed Apr 5, 2012
1 parent 0a612f5 commit 1cae86a
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 92 deletions.
Expand Up @@ -23,127 +23,105 @@
import com.liferay.portal.kernel.util.Validator;
import com.liferay.portal.model.ResourceCode;
import com.liferay.portal.model.impl.ResourceCodeModelImpl;
import com.liferay.portal.service.ServiceTestUtil;
import com.liferay.portal.service.persistence.PersistenceExecutionTestListener;
import com.liferay.portal.test.ExecutionTestListeners;
import com.liferay.portal.test.LiferayIntegrationJUnitTestRunner;
import com.liferay.portal.service.persistence.BasePersistenceTestCase;
import com.liferay.portal.util.PropsValues;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

import org.junit.runner.RunWith;

import java.util.List;

/**
* @author Brian Wing Shun Chan
*/
@ExecutionTestListeners(listeners = {
PersistenceExecutionTestListener.class})
@RunWith(LiferayIntegrationJUnitTestRunner.class)
public class ResourceCodePersistenceTest {
@Before
public class ResourceCodePersistenceTest extends BasePersistenceTestCase {
@Override
public void setUp() throws Exception {
super.setUp();

_persistence = (ResourceCodePersistence)PortalBeanLocatorUtil.locate(ResourceCodePersistence.class.getName());
}

@Test
public void testCreate() throws Exception {
long pk = ServiceTestUtil.nextLong();
long pk = nextLong();

ResourceCode resourceCode = _persistence.create(pk);

Assert.assertNotNull(resourceCode);
assertNotNull(resourceCode);

Assert.assertEquals(resourceCode.getPrimaryKey(), pk);
assertEquals(resourceCode.getPrimaryKey(), pk);
}

@Test
public void testRemove() throws Exception {
ResourceCode newResourceCode = addResourceCode();

_persistence.remove(newResourceCode);

ResourceCode existingResourceCode = _persistence.fetchByPrimaryKey(newResourceCode.getPrimaryKey());

Assert.assertNull(existingResourceCode);
assertNull(existingResourceCode);
}

@Test
public void testUpdateNew() throws Exception {
addResourceCode();
}

@Test
public void testUpdateExisting() throws Exception {
long pk = ServiceTestUtil.nextLong();
long pk = nextLong();

ResourceCode newResourceCode = _persistence.create(pk);

newResourceCode.setCompanyId(ServiceTestUtil.nextLong());
newResourceCode.setCompanyId(nextLong());

newResourceCode.setName(ServiceTestUtil.randomString());
newResourceCode.setName(randomString());

newResourceCode.setScope(ServiceTestUtil.nextInt());
newResourceCode.setScope(nextInt());

_persistence.update(newResourceCode, false);

ResourceCode existingResourceCode = _persistence.findByPrimaryKey(newResourceCode.getPrimaryKey());

Assert.assertEquals(existingResourceCode.getCodeId(),
assertEquals(existingResourceCode.getCodeId(),
newResourceCode.getCodeId());
Assert.assertEquals(existingResourceCode.getCompanyId(),
assertEquals(existingResourceCode.getCompanyId(),
newResourceCode.getCompanyId());
Assert.assertEquals(existingResourceCode.getName(),
newResourceCode.getName());
Assert.assertEquals(existingResourceCode.getScope(),
newResourceCode.getScope());
assertEquals(existingResourceCode.getName(), newResourceCode.getName());
assertEquals(existingResourceCode.getScope(), newResourceCode.getScope());
}

@Test
public void testFindByPrimaryKeyExisting() throws Exception {
ResourceCode newResourceCode = addResourceCode();

ResourceCode existingResourceCode = _persistence.findByPrimaryKey(newResourceCode.getPrimaryKey());

Assert.assertEquals(existingResourceCode, newResourceCode);
assertEquals(existingResourceCode, newResourceCode);
}

@Test
public void testFindByPrimaryKeyMissing() throws Exception {
long pk = ServiceTestUtil.nextLong();
long pk = nextLong();

try {
_persistence.findByPrimaryKey(pk);

Assert.fail(
"Missing entity did not throw NoSuchResourceCodeException");
fail("Missing entity did not throw NoSuchResourceCodeException");
}
catch (NoSuchResourceCodeException nsee) {
}
}

@Test
public void testFetchByPrimaryKeyExisting() throws Exception {
ResourceCode newResourceCode = addResourceCode();

ResourceCode existingResourceCode = _persistence.fetchByPrimaryKey(newResourceCode.getPrimaryKey());

Assert.assertEquals(existingResourceCode, newResourceCode);
assertEquals(existingResourceCode, newResourceCode);
}

@Test
public void testFetchByPrimaryKeyMissing() throws Exception {
long pk = ServiceTestUtil.nextLong();
long pk = nextLong();

ResourceCode missingResourceCode = _persistence.fetchByPrimaryKey(pk);

Assert.assertNull(missingResourceCode);
assertNull(missingResourceCode);
}

@Test
public void testDynamicQueryByPrimaryKeyExisting()
throws Exception {
ResourceCode newResourceCode = addResourceCode();
Expand All @@ -156,27 +134,24 @@ public void testDynamicQueryByPrimaryKeyExisting()

List<ResourceCode> result = _persistence.findWithDynamicQuery(dynamicQuery);

Assert.assertEquals(1, result.size());
assertEquals(1, result.size());

ResourceCode existingResourceCode = result.get(0);

Assert.assertEquals(existingResourceCode, newResourceCode);
assertEquals(existingResourceCode, newResourceCode);
}

@Test
public void testDynamicQueryByPrimaryKeyMissing() throws Exception {
DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(ResourceCode.class,
ResourceCode.class.getClassLoader());

dynamicQuery.add(RestrictionsFactoryUtil.eq("codeId",
ServiceTestUtil.nextLong()));
dynamicQuery.add(RestrictionsFactoryUtil.eq("codeId", nextLong()));

List<ResourceCode> result = _persistence.findWithDynamicQuery(dynamicQuery);

Assert.assertEquals(0, result.size());
assertEquals(0, result.size());
}

@Test
public void testDynamicQueryByProjectionExisting()
throws Exception {
ResourceCode newResourceCode = addResourceCode();
Expand All @@ -193,29 +168,27 @@ public void testDynamicQueryByProjectionExisting()

List<Object> result = _persistence.findWithDynamicQuery(dynamicQuery);

Assert.assertEquals(1, result.size());
assertEquals(1, result.size());

Object existingCodeId = result.get(0);

Assert.assertEquals(existingCodeId, newCodeId);
assertEquals(existingCodeId, newCodeId);
}

@Test
public void testDynamicQueryByProjectionMissing() throws Exception {
DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(ResourceCode.class,
ResourceCode.class.getClassLoader());

dynamicQuery.setProjection(ProjectionFactoryUtil.property("codeId"));

dynamicQuery.add(RestrictionsFactoryUtil.in("codeId",
new Object[] { ServiceTestUtil.nextLong() }));
new Object[] { nextLong() }));

List<Object> result = _persistence.findWithDynamicQuery(dynamicQuery);

Assert.assertEquals(0, result.size());
assertEquals(0, result.size());
}

@Test
public void testResetOriginalValues() throws Exception {
if (!PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
return;
Expand All @@ -227,25 +200,24 @@ public void testResetOriginalValues() throws Exception {

ResourceCodeModelImpl existingResourceCodeModelImpl = (ResourceCodeModelImpl)_persistence.findByPrimaryKey(newResourceCode.getPrimaryKey());

Assert.assertEquals(existingResourceCodeModelImpl.getCompanyId(),
assertEquals(existingResourceCodeModelImpl.getCompanyId(),
existingResourceCodeModelImpl.getOriginalCompanyId());
Assert.assertTrue(Validator.equals(
existingResourceCodeModelImpl.getName(),
assertTrue(Validator.equals(existingResourceCodeModelImpl.getName(),
existingResourceCodeModelImpl.getOriginalName()));
Assert.assertEquals(existingResourceCodeModelImpl.getScope(),
assertEquals(existingResourceCodeModelImpl.getScope(),
existingResourceCodeModelImpl.getOriginalScope());
}

protected ResourceCode addResourceCode() throws Exception {
long pk = ServiceTestUtil.nextLong();
long pk = nextLong();

ResourceCode resourceCode = _persistence.create(pk);

resourceCode.setCompanyId(ServiceTestUtil.nextLong());
resourceCode.setCompanyId(nextLong());

resourceCode.setName(ServiceTestUtil.randomString());
resourceCode.setName(randomString());

resourceCode.setScope(ServiceTestUtil.nextInt());
resourceCode.setScope(nextInt());

_persistence.update(resourceCode, false);

Expand Down
Expand Up @@ -237,12 +237,6 @@ public com.liferay.portal.model.ResourceCode addResourceCode(
long companyId, java.lang.String name, int scope)
throws com.liferay.portal.kernel.exception.SystemException;

public void checkResourceCodes()
throws com.liferay.portal.kernel.exception.SystemException;

public void checkResourceCodes(long companyId, java.lang.String name)
throws com.liferay.portal.kernel.exception.SystemException;

@Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
public com.liferay.portal.model.ResourceCode getResourceCode(
long companyId, java.lang.String name, int scope)
Expand Down
Expand Up @@ -268,16 +268,6 @@ public static com.liferay.portal.model.ResourceCode addResourceCode(
return getService().addResourceCode(companyId, name, scope);
}

public static void checkResourceCodes()
throws com.liferay.portal.kernel.exception.SystemException {
getService().checkResourceCodes();
}

public static void checkResourceCodes(long companyId, java.lang.String name)
throws com.liferay.portal.kernel.exception.SystemException {
getService().checkResourceCodes(companyId, name);
}

public static com.liferay.portal.model.ResourceCode getResourceCode(
long companyId, java.lang.String name, int scope)
throws com.liferay.portal.kernel.exception.SystemException {
Expand Down
Expand Up @@ -257,16 +257,6 @@ public com.liferay.portal.model.ResourceCode addResourceCode(
return _resourceCodeLocalService.addResourceCode(companyId, name, scope);
}

public void checkResourceCodes()
throws com.liferay.portal.kernel.exception.SystemException {
_resourceCodeLocalService.checkResourceCodes();
}

public void checkResourceCodes(long companyId, java.lang.String name)
throws com.liferay.portal.kernel.exception.SystemException {
_resourceCodeLocalService.checkResourceCodes(companyId, name);
}

public com.liferay.portal.model.ResourceCode getResourceCode(
long companyId, java.lang.String name, int scope)
throws com.liferay.portal.kernel.exception.SystemException {
Expand Down

0 comments on commit 1cae86a

Please sign in to comment.