Search in sources :

Example 6 with Messages

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

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

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

Example 9 with Messages

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

the class DefaultUnifiedRepositoryContentIT method testLocalePropertiesMap.

@Test
public void testLocalePropertiesMap() throws Exception {
    loginAsSysTenantAdmin();
    ITenant tenantAcme = tenantManager.createTenant(systemTenant, TENANT_ID_ACME, tenantAdminRoleName, tenantAuthenticatedRoleName, ANONYMOUS_ROLE_NAME);
    userRoleDao.createUser(tenantAcme, USERNAME_SUZY, PASSWORD, "", new String[] { tenantAdminRoleName });
    logout();
    login(USERNAME_SUZY, tenantAcme, new String[] { tenantAdminRoleName, tenantAuthenticatedRoleName });
    // Create file
    final String fileName = "locale.sample";
    RepositoryFile file = createSampleFile(ClientRepositoryPaths.getUserHomeFolderPath(USERNAME_SUZY), fileName, "test", false, 123);
    // Test filename title matches created file name
    assertEquals(fileName, file.getTitle());
    final String DEFAULT_LOCALE = "default";
    final IPentahoLocale SPANISH = new PentahoLocale(new Locale("es"));
    final IPentahoLocale US = new PentahoLocale(Locale.US);
    final String TITLE = "title";
    final String DESCRIPTION = "description";
    final String EN_US_TITLE = "Locale Sample";
    final String EN_US_DESCRIPTION = "This is a test for retrieving localized words";
    final String SP_TITLE = "Muestra de Localizacion";
    final String SP_DESCRIPTION = "Esta es una prueba para buscar palabras localizadas";
    RepositoryFile.Builder builder = new RepositoryFile.Builder(file);
    Map<String, Properties> localeMap = new HashMap<String, Properties>();
    // Set English locale values
    final Properties enProperties = new Properties();
    enProperties.setProperty(TITLE, EN_US_TITLE);
    enProperties.setProperty(DESCRIPTION, EN_US_DESCRIPTION);
    localeMap.put(US.toString(), enProperties);
    // Set Spanish locale values
    final Properties esProperties = new Properties();
    esProperties.setProperty(TITLE, SP_TITLE);
    esProperties.setProperty(DESCRIPTION, SP_DESCRIPTION);
    localeMap.put(SPANISH.toString(), esProperties);
    builder.localePropertiesMap(localeMap);
    // Update file data
    final SampleRepositoryFileData modContent = new SampleRepositoryFileData("blah", false, 123);
    repo.updateFile(builder.build(), modContent, null);
    // Retrieve file - gets full map
    final RepositoryFile updatedFile = repo.getFile(file.getPath(), true);
    // Assert messages are the same
    Properties ep = updatedFile.getLocalePropertiesMap().get(US.toString());
    assertEquals(EN_US_TITLE, ep.getProperty(TITLE));
    assertEquals(EN_US_DESCRIPTION, ep.getProperty(DESCRIPTION));
    Properties sp = updatedFile.getLocalePropertiesMap().get(SPANISH.toString());
    assertEquals(SP_TITLE, sp.getProperty(TITLE));
    assertEquals(SP_DESCRIPTION, sp.getProperty(DESCRIPTION));
    // Assert empty rootLocale
    Properties rootLocale = updatedFile.getLocalePropertiesMap().get(DEFAULT_LOCALE);
    assertNotNull(rootLocale);
    final String NEW_TITLE = "new title";
    final String NEW_DESCRIPTION = "new description";
    // overwrite title
    enProperties.setProperty(TITLE, NEW_TITLE);
    // overwrite title
    enProperties.setProperty(DESCRIPTION, NEW_DESCRIPTION);
    txnTemplate.execute(new TransactionCallbackWithoutResult() {

        @Override
        public void doInTransactionWithoutResult(final TransactionStatus status) {
            // assert available locales
            List<Locale> locales = repositoryFileDao.getAvailableLocalesForFile(updatedFile);
            // includes rootLocale
            assertEquals(3, locales.size());
            // assert correct locale properties
            Properties properties = repositoryFileDao.getLocalePropertiesForFile(updatedFile, "es");
            assertEquals(SP_TITLE, properties.getProperty(TITLE));
            assertEquals(SP_DESCRIPTION, properties.getProperty(DESCRIPTION));
            repositoryFileDao.setLocalePropertiesForFile(updatedFile, Locale.US.getLanguage(), enProperties);
        }
    });
    // Assert updated properties
    RepositoryFile updatedRepoFile = repo.getFile(file.getPath(), true);
    Properties updated_en = updatedRepoFile.getLocalePropertiesMap().get(US.toString());
    assertEquals(NEW_TITLE, updated_en.getProperty(TITLE));
    assertEquals(NEW_DESCRIPTION, updated_en.getProperty(DESCRIPTION));
    // test successful delete locale properties
    final RepositoryFile repoFile1 = updatedRepoFile.clone();
    txnTemplate.execute(new TransactionCallbackWithoutResult() {

        @Override
        public void doInTransactionWithoutResult(final TransactionStatus status) {
            repositoryFileDao.deleteLocalePropertiesForFile(repoFile1, "es");
        }
    });
    // assert deleted locale
    updatedRepoFile = repo.getFile(file.getPath(), true);
    List<Locale> locales = repositoryFileDao.getAvailableLocalesForFile(updatedRepoFile);
    assertEquals(2, locales.size());
    // test successful delete locale properties
    final RepositoryFile repoFile2 = updatedRepoFile.clone();
    txnTemplate.execute(new TransactionCallbackWithoutResult() {

        @Override
        public void doInTransactionWithoutResult(final TransactionStatus status) {
            repositoryFileDao.deleteLocalePropertiesForFile(repoFile2, "xx");
        }
    });
    // locale properties do not exist, no change in available locales
    updatedRepoFile = repo.getFile(file.getPath(), true);
    locales = repositoryFileDao.getAvailableLocalesForFile(updatedRepoFile);
    assertEquals(2, locales.size());
    logout();
}
Also used : Locale(java.util.Locale) PentahoLocale(org.pentaho.platform.repository2.locale.PentahoLocale) IPentahoLocale(org.pentaho.platform.api.locale.IPentahoLocale) HashMap(java.util.HashMap) TransactionStatus(org.springframework.transaction.TransactionStatus) Matchers.anyString(org.mockito.Matchers.anyString) PentahoLocale(org.pentaho.platform.repository2.locale.PentahoLocale) IPentahoLocale(org.pentaho.platform.api.locale.IPentahoLocale) Properties(java.util.Properties) SampleRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.sample.SampleRepositoryFileData) ITenant(org.pentaho.platform.api.mt.ITenant) IPentahoLocale(org.pentaho.platform.api.locale.IPentahoLocale) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) List(java.util.List) ArrayList(java.util.ArrayList) TransactionCallbackWithoutResult(org.springframework.transaction.support.TransactionCallbackWithoutResult) 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