Search in sources :

Example 1 with Messages

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

the class FileResourceTest method testDoGetFileAsInlineError.

@Test
public void testDoGetFileAsInlineError() throws Exception {
    Response mockForbiddenResponse = mock(Response.class);
    doReturn(mockForbiddenResponse).when(fileResource).buildStatusResponse(Response.Status.FORBIDDEN);
    Response mockNotFoundResponse = mock(Response.class);
    doReturn(mockNotFoundResponse).when(fileResource).buildStatusResponse(Response.Status.NOT_FOUND);
    Response mockInternalServereErrorResponse = mock(Response.class);
    doReturn(mockInternalServereErrorResponse).when(fileResource).buildStatusResponse(Response.Status.INTERNAL_SERVER_ERROR);
    Messages mockMessages = mock(Messages.class);
    doReturn(mockMessages).when(fileResource).getMessagesInstance();
    // Test 1
    Exception mockIllegalArgumentException = mock(IllegalArgumentException.class);
    doThrow(mockIllegalArgumentException).when(fileResource.fileService).doGetFileAsInline(PATH_ID);
    Response testResponse = fileResource.doGetFileAsInline(PATH_ID);
    assertEquals(mockForbiddenResponse, testResponse);
    // Test 2
    Exception mockFileNotFoundException = mock(FileNotFoundException.class);
    doThrow(mockFileNotFoundException).when(fileResource.fileService).doGetFileAsInline(PATH_ID);
    testResponse = fileResource.doGetFileAsInline(PATH_ID);
    assertEquals(mockNotFoundResponse, testResponse);
    // Test 3
    Error mockInternalError = mock(InternalError.class);
    doThrow(mockInternalError).when(fileResource.fileService).doGetFileAsInline(PATH_ID);
    testResponse = fileResource.doGetFileAsInline(PATH_ID);
    assertEquals(mockInternalServereErrorResponse, testResponse);
    verify(mockMessages, times(3)).getString("SystemResource.GENERAL_ERROR");
}
Also used : Response(javax.ws.rs.core.Response) 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 2 with Messages

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

the class FileResourceTest method testDoGetGeneratedContentForUserError.

@Test
public void testDoGetGeneratedContentForUserError() throws Exception {
    String user = "user";
    Exception mockFileNotFoundException = mock(FileNotFoundException.class);
    doThrow(mockFileNotFoundException).when(fileResource.fileService).doGetGeneratedContent(PATH_ID, user);
    Messages mockMessages = mock(Messages.class);
    doReturn(mockMessages).when(fileResource).getMessagesInstance();
    // Test 1
    List<RepositoryFileDto> testList = fileResource.doGetGeneratedContentForUser(PATH_ID, user);
    assertEquals(0, testList.size());
    // Test 2
    Throwable mockThrowable = mock(RuntimeException.class);
    doThrow(mockThrowable).when(fileResource.fileService).doGetGeneratedContent(PATH_ID, user);
    testList = fileResource.doGetGeneratedContentForUser(PATH_ID, user);
    assertEquals(0, testList.size());
    verify(fileResource.fileService, times(2)).doGetGeneratedContent(PATH_ID, user);
    verify(fileResource, times(1)).getMessagesInstance();
    verify(mockMessages, times(1)).getString("FileResource.GENERATED_CONTENT_FOR_USER_FAILED", PATH_ID, user);
}
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)

Example 3 with Messages

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

the class FileResourceTest method testSetContentCreatorError.

@Test
public void testSetContentCreatorError() throws Exception {
    RepositoryFileDto mockRepositoryFileDto = mock(RepositoryFileDto.class);
    Response mockNotFoundResponse = mock(Response.class);
    doReturn(mockNotFoundResponse).when(fileResource).buildStatusResponse(Response.Status.NOT_FOUND);
    Response mockInternalServerErrorResponse = mock(Response.class);
    doReturn(mockInternalServerErrorResponse).when(fileResource).buildStatusResponse(Response.Status.INTERNAL_SERVER_ERROR);
    Messages mockMessages = mock(Messages.class);
    doReturn(mockMessages).when(fileResource).getMessagesInstance();
    // Test 1
    Exception mockFileNotFoundException = mock(FileNotFoundException.class);
    doThrow(mockFileNotFoundException).when(fileResource.fileService).doSetContentCreator(PATH_ID, mockRepositoryFileDto);
    Response testResponse = fileResource.doSetContentCreator(PATH_ID, mockRepositoryFileDto);
    assertEquals(mockNotFoundResponse, testResponse);
    // Test 2
    Throwable mockThrowable = mock(RuntimeException.class);
    doThrow(mockThrowable).when(fileResource.fileService).doSetContentCreator(PATH_ID, mockRepositoryFileDto);
    testResponse = fileResource.doSetContentCreator(PATH_ID, mockRepositoryFileDto);
    assertEquals(mockInternalServerErrorResponse, testResponse);
    verify(fileResource, times(1)).buildStatusResponse(Response.Status.NOT_FOUND);
    verify(fileResource, times(1)).buildStatusResponse(Response.Status.INTERNAL_SERVER_ERROR);
    verify(fileResource.fileService, times(2)).doSetContentCreator(PATH_ID, mockRepositoryFileDto);
    verify(mockMessages, times(1)).getErrorString("FileResource.FILE_NOT_FOUND", PATH_ID);
    verify(mockMessages, times(1)).getString("SystemResource.GENERAL_ERROR");
}
Also used : RepositoryFileDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileDto) Response(javax.ws.rs.core.Response) 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 4 with Messages

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

the class FileResourceTest method testDoGetPropertiesError.

@Test
public void testDoGetPropertiesError() throws Exception {
    Exception mockFileNotFoundException = mock(FileNotFoundException.class);
    doThrow(mockFileNotFoundException).when(fileResource.fileService).doGetProperties(PATH_ID);
    Messages mockMessages = mock(Messages.class);
    doReturn(mockMessages).when(fileResource).getMessagesInstance();
    RepositoryFileDto testDto = fileResource.doGetProperties(PATH_ID);
    assertNull(testDto);
    verify(fileResource.fileService, times(1)).doGetProperties(PATH_ID);
    verify(fileResource, times(1)).getMessagesInstance();
    verify(mockMessages, times(1)).getString("SystemResource.GENERAL_ERROR");
}
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)

Example 5 with Messages

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

the class FileResourceTest method testDoGetFileOrDirAsDownloadError.

@Test
public void testDoGetFileOrDirAsDownloadError() throws Throwable {
    String userAgent = "userAgent";
    String strWithManifest = "strWithManifest";
    Messages mockMessages = mock(Messages.class);
    doReturn(mockMessages).when(fileResource).getMessagesInstance();
    Response mockBadRequestResponse = mock(Response.class);
    doReturn(mockBadRequestResponse).when(fileResource).buildStatusResponse(Response.Status.BAD_REQUEST);
    Response mockForbiddenResponse = mock(Response.class);
    doReturn(mockForbiddenResponse).when(fileResource).buildStatusResponse(Response.Status.FORBIDDEN);
    Response mockNotFoundResponse = mock(Response.class);
    doReturn(mockNotFoundResponse).when(fileResource).buildStatusResponse(Response.Status.NOT_FOUND);
    Response mockInternalServerErrorResponse = mock(Response.class);
    doReturn(mockInternalServerErrorResponse).when(fileResource).buildStatusResponse(Response.Status.INTERNAL_SERVER_ERROR);
    String exceptionMessage = "exception";
    // Test 1
    Exception mockInvalidParameterException = mock(InvalidParameterException.class);
    doThrow(mockInvalidParameterException).when(fileResource.fileService).doGetFileOrDirAsDownload(userAgent, PATH_ID, strWithManifest);
    doReturn(exceptionMessage).when(mockInvalidParameterException).getMessage();
    Response testResponse = fileResource.doGetFileOrDirAsDownload(userAgent, PATH_ID, strWithManifest);
    assertEquals(mockBadRequestResponse, testResponse);
    // Test 2
    Exception mockIllegalSelectorException = mock(IllegalSelectorException.class);
    doThrow(mockIllegalSelectorException).when(fileResource.fileService).doGetFileOrDirAsDownload(userAgent, PATH_ID, strWithManifest);
    doReturn(exceptionMessage).when(mockIllegalSelectorException).getMessage();
    testResponse = fileResource.doGetFileOrDirAsDownload(userAgent, PATH_ID, strWithManifest);
    assertEquals(mockForbiddenResponse, testResponse);
    // Test 3
    Exception mockPentahoAccessControlException = mock(PentahoAccessControlException.class);
    doThrow(mockPentahoAccessControlException).when(fileResource.fileService).doGetFileOrDirAsDownload(userAgent, PATH_ID, strWithManifest);
    doReturn(exceptionMessage).when(mockPentahoAccessControlException).getMessage();
    testResponse = fileResource.doGetFileOrDirAsDownload(userAgent, PATH_ID, strWithManifest);
    assertEquals(mockForbiddenResponse, testResponse);
    // Test 4
    Exception mockFileNotFoundException = mock(FileNotFoundException.class);
    doThrow(mockFileNotFoundException).when(fileResource.fileService).doGetFileOrDirAsDownload(userAgent, PATH_ID, strWithManifest);
    doReturn(exceptionMessage).when(mockFileNotFoundException).getMessage();
    testResponse = fileResource.doGetFileOrDirAsDownload(userAgent, PATH_ID, strWithManifest);
    assertEquals(mockNotFoundResponse, testResponse);
    // Test 5
    Throwable mockThrowable = mock(Throwable.class);
    doThrow(mockThrowable).when(fileResource.fileService).doGetFileOrDirAsDownload(userAgent, PATH_ID, strWithManifest);
    doReturn(exceptionMessage).when(mockThrowable).getMessage();
    testResponse = fileResource.doGetFileOrDirAsDownload(userAgent, PATH_ID, strWithManifest);
    assertEquals(mockInternalServerErrorResponse, testResponse);
    verify(mockMessages, times(4)).getString("FileResource.EXPORT_FAILED", exceptionMessage);
    verify(mockMessages, times(1)).getString("FileResource.EXPORT_FAILED", PATH_ID + " " + exceptionMessage);
}
Also used : Response(javax.ws.rs.core.Response) 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