protected PortletPreferences getPortletPreferences(
      long companyId, long ownerId, int ownerType, long plid, String serviceName)
      throws PortalException {

    PortletPreferences portletPreferences = null;

    try {
      if ((ownerType == PortletKeys.PREFS_OWNER_TYPE_ARCHIVED)
          || (ownerType == PortletKeys.PREFS_OWNER_TYPE_COMPANY)
          || (ownerType == PortletKeys.PREFS_OWNER_TYPE_GROUP)) {

        portletPreferences =
            PortletPreferencesLocalServiceUtil.getPortletPreferences(
                ownerId, ownerType, LayoutConstants.DEFAULT_PLID, serviceName);
      } else {
        portletPreferences =
            PortletPreferencesLocalServiceUtil.getPortletPreferences(
                ownerId, ownerType, plid, serviceName);
      }
    } catch (NoSuchPortletPreferencesException nsppe) {
      portletPreferences =
          PortletPreferencesLocalServiceUtil.addPortletPreferences(
              companyId, ownerId, ownerType, plid, serviceName, null, null);
    }

    return portletPreferences;
  }
  @Test
  public void testCleanUpLayoutRevisionPortletPreferences() throws Exception {
    LayoutRevision layoutRevision = getLayoutRevision();

    PortletPreferences portletPreferences =
        PortletPreferencesLocalServiceUtil.addPortletPreferences(
            TestPropsValues.getCompanyId(),
            TestPropsValues.getUserId(),
            0,
            layoutRevision.getLayoutRevisionId(),
            RandomTestUtil.randomString(),
            new PortletImpl(),
            StringPool.BLANK);

    Assert.assertNotNull(portletPreferences);

    doVerify();

    portletPreferences =
        PortletPreferencesLocalServiceUtil.fetchPortletPreferences(
            portletPreferences.getPortletPreferencesId());

    Assert.assertNull(portletPreferences);
  }