Search in sources :

Example 6 with Messages

use of org.pentaho.platform.web.http.messages.Messages in project pentaho-platform by pentaho.

the class FileResourceTest method testSetFileAclsError.

@Test
public void testSetFileAclsError() throws Exception {
    RepositoryFileAclDto mockRepositoryFileAclDto = mock(RepositoryFileAclDto.class);
    Messages mockMessages = mock(Messages.class);
    doReturn(mockMessages).when(fileResource).getMessagesInstance();
    Response mockInternalServerErrorResponse = mock(Response.class);
    doReturn(mockInternalServerErrorResponse).when(fileResource).buildStatusResponse(Response.Status.INTERNAL_SERVER_ERROR);
    Exception mockRuntimeException = mock(RuntimeException.class);
    doThrow(mockRuntimeException).when(fileResource.fileService).setFileAcls(PATH_ID, mockRepositoryFileAclDto);
    Response testResponse = fileResource.setFileAcls(PATH_ID, mockRepositoryFileAclDto);
    assertEquals(mockInternalServerErrorResponse, testResponse);
    verify(fileResource, times(1)).getMessagesInstance();
    verify(fileResource, times(1)).buildStatusResponse(Response.Status.INTERNAL_SERVER_ERROR);
    verify(fileResource.fileService, times(1)).setFileAcls(PATH_ID, mockRepositoryFileAclDto);
}
Also used : Response(javax.ws.rs.core.Response) Messages(org.pentaho.platform.web.http.messages.Messages) RepositoryFileAclDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileAclDto) GeneralSecurityException(java.security.GeneralSecurityException) InvalidParameterException(java.security.InvalidParameterException) PentahoAccessControlException(org.pentaho.platform.api.engine.PentahoAccessControlException) UnifiedRepositoryAccessDeniedException(org.pentaho.platform.api.repository2.unified.UnifiedRepositoryAccessDeniedException) FileNotFoundException(java.io.FileNotFoundException) WebApplicationException(javax.ws.rs.WebApplicationException) IllegalSelectorException(java.nio.channels.IllegalSelectorException) IOException(java.io.IOException) NoSuchBeanDefinitionException(org.springframework.beans.factory.NoSuchBeanDefinitionException) Test(org.junit.Test)

Example 7 with Messages

use of org.pentaho.platform.web.http.messages.Messages in project pentaho-platform by pentaho.

the class FileResourceTest method testDoIsParameterizableError.

@Test
public void testDoIsParameterizableError() throws Exception {
    String path = "path";
    doReturn(path).when(fileResource.fileService).idToPath(PATH_ID);
    RepositoryFile mockRepositoryFile = mock(RepositoryFile.class);
    doReturn(mockRepositoryFile).when(fileResource.repository).getFile(path);
    Exception mockNoSuchBeanDefinitionException = mock(NoSuchBeanDefinitionException.class);
    doThrow(mockNoSuchBeanDefinitionException).when(fileResource).hasParameterUi(mockRepositoryFile);
    String exceptionMessage = "exceptionMessage";
    doReturn(exceptionMessage).when(mockNoSuchBeanDefinitionException).getMessage();
    Messages mockMessages = mock(Messages.class);
    doReturn(mockMessages).when(fileResource).getMessagesInstance();
    String message = "message";
    String key = "FileResource.PARAM_FAILURE";
    doReturn(message).when(mockMessages).getString(key, exceptionMessage);
    // Test 1
    String testResult = fileResource.doIsParameterizable(PATH_ID);
    assertEquals(Boolean.FALSE.toString(), testResult);
    // Test 2
    doReturn(true).when(fileResource).hasParameterUi(mockRepositoryFile);
    doThrow(mockNoSuchBeanDefinitionException).when(fileResource).getContentGenerator(mockRepositoryFile);
    testResult = fileResource.doIsParameterizable(PATH_ID);
    assertEquals(Boolean.FALSE.toString(), testResult);
    verify(fileResource.fileService, times(2)).idToPath(PATH_ID);
    verify(fileResource.repository, times(2)).getFile(path);
    verify(fileResource, times(2)).hasParameterUi(mockRepositoryFile);
    verify(mockNoSuchBeanDefinitionException, times(1)).getMessage();
    verify(mockMessages, times(1)).getString(key, exceptionMessage);
}
Also used : Messages(org.pentaho.platform.web.http.messages.Messages) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) GeneralSecurityException(java.security.GeneralSecurityException) InvalidParameterException(java.security.InvalidParameterException) PentahoAccessControlException(org.pentaho.platform.api.engine.PentahoAccessControlException) UnifiedRepositoryAccessDeniedException(org.pentaho.platform.api.repository2.unified.UnifiedRepositoryAccessDeniedException) FileNotFoundException(java.io.FileNotFoundException) WebApplicationException(javax.ws.rs.WebApplicationException) IllegalSelectorException(java.nio.channels.IllegalSelectorException) IOException(java.io.IOException) NoSuchBeanDefinitionException(org.springframework.beans.factory.NoSuchBeanDefinitionException) Test(org.junit.Test)

Example 8 with Messages

use of org.pentaho.platform.web.http.messages.Messages in project pentaho-platform by pentaho.

the class FileResourceTest method testDoGetMetadataError.

@Test
public void testDoGetMetadataError() throws Exception {
    Exception mockFileNotFoundException = mock(FileNotFoundException.class);
    doThrow(mockFileNotFoundException).when(fileResource.fileService).doGetMetadata(PATH_ID);
    Messages mockMessages = mock(Messages.class);
    doReturn(mockMessages).when(fileResource).getMessagesInstance();
    List<StringKeyStringValueDto> testList = fileResource.doGetMetadata(PATH_ID);
    assertNull(testList);
    verify(fileResource.fileService, times(1)).doGetMetadata(PATH_ID);
    verify(fileResource, times(1)).getMessagesInstance();
    verify(mockMessages, times(1)).getErrorString("FileResource.FILE_UNKNOWN", PATH_ID);
}
Also used : StringKeyStringValueDto(org.pentaho.platform.repository2.unified.webservices.StringKeyStringValueDto) Messages(org.pentaho.platform.web.http.messages.Messages) GeneralSecurityException(java.security.GeneralSecurityException) InvalidParameterException(java.security.InvalidParameterException) PentahoAccessControlException(org.pentaho.platform.api.engine.PentahoAccessControlException) UnifiedRepositoryAccessDeniedException(org.pentaho.platform.api.repository2.unified.UnifiedRepositoryAccessDeniedException) FileNotFoundException(java.io.FileNotFoundException) WebApplicationException(javax.ws.rs.WebApplicationException) IllegalSelectorException(java.nio.channels.IllegalSelectorException) IOException(java.io.IOException) NoSuchBeanDefinitionException(org.springframework.beans.factory.NoSuchBeanDefinitionException) Test(org.junit.Test)

Example 9 with Messages

use of org.pentaho.platform.web.http.messages.Messages in project pentaho-platform by pentaho.

the class FileResourceTest method testDoGetFileLocalesError.

@Test
public void testDoGetFileLocalesError() throws Exception {
    Messages mockMessages = mock(Messages.class);
    doReturn(mockMessages).when(fileResource).getMessagesInstance();
    // Test 1
    Exception mockFileNotFoundException = mock(FileNotFoundException.class);
    doThrow(mockFileNotFoundException).when(fileResource.fileService).doGetFileLocales(PATH_ID);
    List<LocaleMapDto> testLocales = fileResource.doGetFileLocales(PATH_ID);
    assertEquals(0, testLocales.size());
    // Test 2
    Throwable mockThrowable = mock(RuntimeException.class);
    doThrow(mockThrowable).when(fileResource.fileService).doGetFileLocales(PATH_ID);
    testLocales = fileResource.doGetFileLocales(PATH_ID);
    assertEquals(0, testLocales.size());
    verify(fileResource, times(2)).getMessagesInstance();
    verify(mockMessages, times(1)).getErrorString("FileResource.FILE_NOT_FOUND", PATH_ID);
    verify(mockMessages, times(1)).getString("SystemResource.GENERAL_ERROR");
}
Also used : LocaleMapDto(org.pentaho.platform.repository2.unified.webservices.LocaleMapDto) Messages(org.pentaho.platform.web.http.messages.Messages) GeneralSecurityException(java.security.GeneralSecurityException) InvalidParameterException(java.security.InvalidParameterException) PentahoAccessControlException(org.pentaho.platform.api.engine.PentahoAccessControlException) UnifiedRepositoryAccessDeniedException(org.pentaho.platform.api.repository2.unified.UnifiedRepositoryAccessDeniedException) FileNotFoundException(java.io.FileNotFoundException) WebApplicationException(javax.ws.rs.WebApplicationException) IllegalSelectorException(java.nio.channels.IllegalSelectorException) IOException(java.io.IOException) NoSuchBeanDefinitionException(org.springframework.beans.factory.NoSuchBeanDefinitionException) Test(org.junit.Test)

Example 10 with Messages

use of org.pentaho.platform.web.http.messages.Messages in project pentaho-platform by pentaho.

the class FileResourceTest method testDoGetGeneratedContentError.

@Test
public void testDoGetGeneratedContentError() throws Exception {
    Exception mockFileNotFoundException = mock(FileNotFoundException.class);
    doThrow(mockFileNotFoundException).when(fileResource.fileService).doGetGeneratedContent(PATH_ID);
    Messages mockMessages = mock(Messages.class);
    doReturn(mockMessages).when(fileResource).getMessagesInstance();
    // Test 1
    List<RepositoryFileDto> testList = fileResource.doGetGeneratedContent(PATH_ID);
    assertEquals(0, testList.size());
    // Test 2
    Throwable mockThrowable = mock(RuntimeException.class);
    doThrow(mockThrowable).when(fileResource.fileService).doGetGeneratedContent(PATH_ID);
    testList = fileResource.doGetGeneratedContent(PATH_ID);
    assertEquals(0, testList.size());
    verify(fileResource.fileService, times(2)).doGetGeneratedContent(PATH_ID);
    verify(fileResource, times(1)).getMessagesInstance();
    verify(mockMessages, times(1)).getString("FileResource.GENERATED_CONTENT_FAILED", PATH_ID);
}
Also used : RepositoryFileDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileDto) Messages(org.pentaho.platform.web.http.messages.Messages) GeneralSecurityException(java.security.GeneralSecurityException) InvalidParameterException(java.security.InvalidParameterException) PentahoAccessControlException(org.pentaho.platform.api.engine.PentahoAccessControlException) UnifiedRepositoryAccessDeniedException(org.pentaho.platform.api.repository2.unified.UnifiedRepositoryAccessDeniedException) FileNotFoundException(java.io.FileNotFoundException) WebApplicationException(javax.ws.rs.WebApplicationException) IllegalSelectorException(java.nio.channels.IllegalSelectorException) IOException(java.io.IOException) NoSuchBeanDefinitionException(org.springframework.beans.factory.NoSuchBeanDefinitionException) Test(org.junit.Test)

Aggregations

FileNotFoundException (java.io.FileNotFoundException)10 IOException (java.io.IOException)10 IllegalSelectorException (java.nio.channels.IllegalSelectorException)10 GeneralSecurityException (java.security.GeneralSecurityException)10 InvalidParameterException (java.security.InvalidParameterException)10 WebApplicationException (javax.ws.rs.WebApplicationException)10 Test (org.junit.Test)10 PentahoAccessControlException (org.pentaho.platform.api.engine.PentahoAccessControlException)10 UnifiedRepositoryAccessDeniedException (org.pentaho.platform.api.repository2.unified.UnifiedRepositoryAccessDeniedException)10 Messages (org.pentaho.platform.web.http.messages.Messages)10 NoSuchBeanDefinitionException (org.springframework.beans.factory.NoSuchBeanDefinitionException)10 Response (javax.ws.rs.core.Response)4 RepositoryFileDto (org.pentaho.platform.repository2.unified.webservices.RepositoryFileDto)4 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)1 LocaleMapDto (org.pentaho.platform.repository2.unified.webservices.LocaleMapDto)1 RepositoryFileAclDto (org.pentaho.platform.repository2.unified.webservices.RepositoryFileAclDto)1 StringKeyStringValueDto (org.pentaho.platform.repository2.unified.webservices.StringKeyStringValueDto)1