Search in sources :

Example 1 with ContentPersistenceException

use of org.jasig.portlet.cms.mvc.exception.ContentPersistenceException in project SimpleContentPortlet by Jasig.

the class PortletPreferencesContentDaoImplTest method testValidatorError.

@Test
public void testValidatorError() throws IOException {
    try {
        doThrow(new ValidatorException("", null)).when(preferences).store();
        contentDao.saveContent(request, content, null);
        Assert.fail("Should have thrown an exception");
    } catch (ValidatorException e) {
        Assert.fail("Validator exception should have been converted to a ContentPersistenceException");
    } catch (ContentPersistenceException e) {
    }
}
Also used : ValidatorException(javax.portlet.ValidatorException) ContentPersistenceException(org.jasig.portlet.cms.mvc.exception.ContentPersistenceException) Test(org.junit.Test)

Example 2 with ContentPersistenceException

use of org.jasig.portlet.cms.mvc.exception.ContentPersistenceException in project SimpleContentPortlet by Jasig.

the class PortletPreferencesContentDaoImplTest method testReadOnlyError.

@Test
public void testReadOnlyError() {
    try {
        doThrow(new ReadOnlyException("")).when(preferences).setValue(PortletPreferencesContentDaoImpl.CONTENT_KEY, content);
        contentDao.saveContent(request, content, null);
        Assert.fail("Should have thrown an exception");
    } catch (ReadOnlyException e) {
        Assert.fail("Read-only exception should have been converted to a ContentPersistenceException");
    } catch (ContentPersistenceException e) {
    }
}
Also used : ReadOnlyException(javax.portlet.ReadOnlyException) ContentPersistenceException(org.jasig.portlet.cms.mvc.exception.ContentPersistenceException) Test(org.junit.Test)

Example 3 with ContentPersistenceException

use of org.jasig.portlet.cms.mvc.exception.ContentPersistenceException in project SimpleContentPortlet by Jasig.

the class PortletPreferencesContentDaoImpl method saveContent.

/*
     * (non-Javadoc)
     * @see org.jasig.portlet.cms.service.dao.IContentDao#saveContent(javax.portlet.ActionRequest, java.lang.String, java.lang.String)
     */
public void saveContent(ActionRequest request, String content, String localeKey) {
    try {
        PortletPreferences preferences = request.getPreferences();
        if (StringUtils.isNotBlank(localeKey)) {
            preferences.setValue(getLocaleSpecificKey(localeKey), content);
        } else {
            preferences.setValue(CONTENT_KEY, content);
        }
        preferences.store();
    } catch (ReadOnlyException e) {
        throw new ContentPersistenceException("Failed to save read-only preference", e);
    } catch (ValidatorException e) {
        throw new ContentPersistenceException("Portlet preferences validation error while attempting to persist portlet content", e);
    } catch (IOException e) {
        throw new ContentPersistenceException("IO error while attempting to persist portlet content", e);
    }
}
Also used : ValidatorException(javax.portlet.ValidatorException) PortletPreferences(javax.portlet.PortletPreferences) IOException(java.io.IOException) ReadOnlyException(javax.portlet.ReadOnlyException) ContentPersistenceException(org.jasig.portlet.cms.mvc.exception.ContentPersistenceException)

Example 4 with ContentPersistenceException

use of org.jasig.portlet.cms.mvc.exception.ContentPersistenceException in project SimpleContentPortlet by Jasig.

the class PortletPreferencesContentDaoImplTest method testIOError.

@Test
public void testIOError() throws ValidatorException {
    try {
        doThrow(new IOException("")).when(preferences).store();
        contentDao.saveContent(request, content, null);
        Assert.fail("Should have thrown an exception");
    } catch (IOException e) {
        Assert.fail("Validator exception should have been converted to a ContentPersistenceException");
    } catch (ContentPersistenceException e) {
    }
}
Also used : IOException(java.io.IOException) ContentPersistenceException(org.jasig.portlet.cms.mvc.exception.ContentPersistenceException) Test(org.junit.Test)

Aggregations

ContentPersistenceException (org.jasig.portlet.cms.mvc.exception.ContentPersistenceException)4 Test (org.junit.Test)3 IOException (java.io.IOException)2 ReadOnlyException (javax.portlet.ReadOnlyException)2 ValidatorException (javax.portlet.ValidatorException)2 PortletPreferences (javax.portlet.PortletPreferences)1