Search in sources :

Example 1 with Messages

use of org.pentaho.platform.repository2.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 2 with Messages

use of org.pentaho.platform.repository2.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 3 with Messages

use of org.pentaho.platform.repository2.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 4 with Messages

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

the class ActionSequenceAction method execute.

public void execute() throws Exception {
    IOutputHandler outputHandler = null;
    if (xactionResultsOutputStream instanceof RepositoryFileOutputStream) {
        outputHandler = new RepositoryFileOutputHandler(((RepositoryFileOutputStream) xactionResultsOutputStream));
    } else {
        outputHandler = new SimpleOutputHandler(xactionResultsOutputStream, false);
    }
    IRuntimeContext rt = null;
    try {
        ISolutionEngine solutionEngine = PentahoSystem.get(ISolutionEngine.class, null);
        solutionEngine.setCreateFeedbackParameterCallback(null);
        solutionEngine.setLoggingLevel(ILogger.DEBUG);
        solutionEngine.setForcePrompt(false);
        ArrayList messages = new ArrayList();
        HashMap<String, Object> parameterProviders = new HashMap<String, Object>();
        parameterProviders.put(IParameterProvider.SCOPE_REQUEST, new SimpleParameterProvider(xActionInputParams));
        parameterProviders.put(IParameterProvider.SCOPE_SESSION, new PentahoSessionParameterProvider(PentahoSessionHolder.getSession()));
        String xactionPath = null;
        if (xactionDefInputStream instanceof RepositoryFileInputStream) {
            xactionPath = ((RepositoryFileInputStream) xactionDefInputStream).getFile().getPath();
        }
        rt = solutionEngine.execute(xactionPath, this.getClass().getName(), false, true, null, true, parameterProviders, outputHandler, null, null, messages);
        if (!outputHandler.contentDone()) {
            if ((rt != null) && (rt.getStatus() == IRuntimeContext.RUNTIME_STATUS_SUCCESS)) {
                // set content which generated by sequence for pass it to caller
                List<IContentItem> components = new ArrayList<IContentItem>(rt.getOutputContentItems());
                setActionOutputContents(components);
                boolean isFlushed = false;
                boolean isEmpty;
                if (xactionResultsOutputStream instanceof RepositoryFileOutputStream) {
                    RepositoryFileOutputStream repositoryFileOutputStream = (RepositoryFileOutputStream) xactionResultsOutputStream;
                    isFlushed = repositoryFileOutputStream.isFlushed();
                    isEmpty = repositoryFileOutputStream.size() > 0 ? false : true;
                    String extension = RepositoryFilenameUtils.getExtension(repositoryFileOutputStream.getFilePath());
                    String mimeTypeFromExtension = MimeHelper.getMimeTypeFromExtension("." + extension);
                    if (mimeTypeFromExtension == null) {
                        // unknown type, treat it not as an extension but part of the name
                        extension = "";
                    }
                    if (extension.isEmpty() && xactionResultsOutputStream.toString().isEmpty()) {
                        repositoryFileOutputStream.setFilePath(repositoryFileOutputStream.getFilePath() + ".html");
                    }
                } else {
                    isEmpty = xactionResultsOutputStream.toString().isEmpty();
                }
                if (!isFlushed) {
                    if (isEmpty) {
                        StringBuffer buffer = new StringBuffer();
                        // $NON-NLS-1$
                        MessageFormatUtils.formatSuccessMessage("text/html", rt, buffer, false);
                        xactionResultsOutputStream.write(buffer.toString().getBytes(LocaleHelper.getSystemEncoding()));
                    }
                    xactionResultsOutputStream.close();
                }
            } else {
                // we need an error message...
                StringBuffer buffer = new StringBuffer();
                // $NON-NLS-1$
                MessageFormatUtils.formatFailureMessage("text/html", rt, buffer, messages);
                xactionResultsOutputStream.write(buffer.toString().getBytes(LocaleHelper.getSystemEncoding()));
                xactionResultsOutputStream.close();
            }
        }
    } finally {
        if (rt != null) {
            rt.dispose();
        }
    }
}
Also used : ISolutionEngine(org.pentaho.platform.api.engine.ISolutionEngine) RepositoryFileOutputHandler(org.pentaho.platform.repository2.unified.fileio.RepositoryFileOutputHandler) HashMap(java.util.HashMap) PentahoSessionParameterProvider(org.pentaho.platform.engine.core.solution.PentahoSessionParameterProvider) ArrayList(java.util.ArrayList) SimpleOutputHandler(org.pentaho.platform.engine.core.output.SimpleOutputHandler) RepositoryFileInputStream(org.pentaho.platform.repository2.unified.fileio.RepositoryFileInputStream) RepositoryFileOutputStream(org.pentaho.platform.repository2.unified.fileio.RepositoryFileOutputStream) IOutputHandler(org.pentaho.platform.api.engine.IOutputHandler) IContentItem(org.pentaho.platform.api.repository.IContentItem) IRuntimeContext(org.pentaho.platform.api.engine.IRuntimeContext) SimpleParameterProvider(org.pentaho.platform.engine.core.solution.SimpleParameterProvider)

Example 5 with Messages

use of org.pentaho.platform.repository2.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)

Aggregations

Test (org.junit.Test)8 FileNotFoundException (java.io.FileNotFoundException)7 IOException (java.io.IOException)7 IllegalSelectorException (java.nio.channels.IllegalSelectorException)7 GeneralSecurityException (java.security.GeneralSecurityException)7 InvalidParameterException (java.security.InvalidParameterException)7 WebApplicationException (javax.ws.rs.WebApplicationException)7 PentahoAccessControlException (org.pentaho.platform.api.engine.PentahoAccessControlException)7 UnifiedRepositoryAccessDeniedException (org.pentaho.platform.api.repository2.unified.UnifiedRepositoryAccessDeniedException)7 Messages (org.pentaho.platform.web.http.messages.Messages)7 NoSuchBeanDefinitionException (org.springframework.beans.factory.NoSuchBeanDefinitionException)7 RepositoryFileDto (org.pentaho.platform.repository2.unified.webservices.RepositoryFileDto)4 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Response (javax.ws.rs.core.Response)2 List (java.util.List)1 Locale (java.util.Locale)1 Properties (java.util.Properties)1 Matchers.anyString (org.mockito.Matchers.anyString)1 IOutputHandler (org.pentaho.platform.api.engine.IOutputHandler)1