Search in sources :

Example 11 with ISystemSettings

use of org.pentaho.platform.api.engine.ISystemSettings in project data-access by pentaho.

the class AgileHelperTest method testGetCsvSampleRowSize.

@Test
public void testGetCsvSampleRowSize() {
    int defaultRowSize = 100;
    int expected = Integer.MAX_VALUE;
    PentahoSystem.setSystemSettingsService(null);
    assertEquals(defaultRowSize, AgileHelper.getCsvSampleRowSize());
    ISystemSettings systemSettings = mock(ISystemSettings.class);
    when(systemSettings.getSystemSetting(anyString(), anyString(), anyString())).thenReturn(null).thenReturn(String.valueOf(expected));
    PentahoSystem.setSystemSettingsService(systemSettings);
    assertEquals(defaultRowSize, AgileHelper.getCsvSampleRowSize());
    assertEquals(expected, AgileHelper.getCsvSampleRowSize());
}
Also used : ISystemSettings(org.pentaho.platform.api.engine.ISystemSettings) Test(org.junit.Test)

Example 12 with ISystemSettings

use of org.pentaho.platform.api.engine.ISystemSettings in project data-access by pentaho.

the class AgileHelperTest method testGetDatasourceSolutionStorage.

@Test
public void testGetDatasourceSolutionStorage() {
    PentahoSystem.setSystemSettingsService(null);
    assertEquals("admin", AgileHelper.getDatasourceSolutionStorage());
    ISystemSettings systemSettings = mock(ISystemSettings.class);
    when(systemSettings.getSystemSetting(anyString(), anyString(), anyString())).thenReturn(null);
    PentahoSystem.setSystemSettingsService(systemSettings);
    assertNull(AgileHelper.getDatasourceSolutionStorage());
}
Also used : ISystemSettings(org.pentaho.platform.api.engine.ISystemSettings) Test(org.junit.Test)

Example 13 with ISystemSettings

use of org.pentaho.platform.api.engine.ISystemSettings in project data-access by pentaho.

the class CsvDatasourceServiceImplTest method testHasPermissions.

@Test
public void testHasPermissions() throws Exception {
    hasPermissions = true;
    final ISystemSettings systemSettings = mock(ISystemSettings.class);
    when(systemSettings.getSystemSetting("data-access-override", "false")).thenReturn("false");
    PentahoSystem.setSystemSettingsService(systemSettings);
    String filename = "anotherStageFile_CsvFile.csv";
    File file = createTmpCsvFile(filename);
    file.deleteOnExit();
    try {
        ModelInfo modelInfo = service.stageFile(filename, ",", "\n", true, "utf-8");
        CsvFileInfo fileInfo = modelInfo.getFileInfo();
        assertEquals("One header row", 1, fileInfo.getHeaderRows());
        assertEquals("Header + content row", 2, fileInfo.getContents().size());
        assertEquals(filename, fileInfo.getTmpFilename());
        final FileInfo[] stagedFiles = service.getStagedFiles();
        assertNotNull(stagedFiles);
        boolean present = false;
        for (FileInfo info : stagedFiles) {
            if (filename.equals(info.getName())) {
                present = true;
                break;
            }
        }
        assertTrue(present);
        final String encoding = service.getEncoding(filename);
        assertNotNull(encoding);
        final List<String> previewRows = service.getPreviewRows(filename, true, 1, "utf-8");
        assertNotNull(previewRows);
        assertEquals(1, previewRows.size());
        assertEquals("col1,col2", previewRows.get(0));
        final DatasourceDTO datasourceDto = mock(DatasourceDTO.class);
        when(datasourceDto.getCsvModelInfo()).thenReturn(modelInfo);
        try {
            final FileTransformStats fileTransformStats = service.generateDomain(datasourceDto);
        } catch (Exception e) {
        // Testing this logic is not a purpose of this junit
        }
        // Passed permissions check
        verify(datasourceDto, times(1)).getCsvModelInfo();
    } finally {
        file.delete();
    }
}
Also used : CsvFileInfo(org.pentaho.platform.dataaccess.datasource.wizard.models.CsvFileInfo) ModelInfo(org.pentaho.platform.dataaccess.datasource.wizard.models.ModelInfo) CsvFileInfo(org.pentaho.platform.dataaccess.datasource.wizard.models.CsvFileInfo) FileInfo(org.pentaho.platform.dataaccess.datasource.wizard.models.FileInfo) ISystemSettings(org.pentaho.platform.api.engine.ISystemSettings) Matchers.anyString(org.mockito.Matchers.anyString) DatasourceDTO(org.pentaho.platform.dataaccess.datasource.wizard.models.DatasourceDTO) File(java.io.File) FileTransformStats(org.pentaho.platform.dataaccess.datasource.wizard.sources.csv.FileTransformStats) Test(org.junit.Test)

Example 14 with ISystemSettings

use of org.pentaho.platform.api.engine.ISystemSettings in project data-access by pentaho.

the class CsvDatasourceServiceImplTest method testNoPermissions.

@Test
public void testNoPermissions() throws Exception {
    final ISystemSettings systemSettings = mock(ISystemSettings.class);
    when(systemSettings.getSystemSetting("data-access-override", "false")).thenReturn("false");
    PentahoSystem.setSystemSettingsService(systemSettings);
    String filename = "stageFile_CsvFile.csv";
    File file = createTmpCsvFile(filename);
    file.deleteOnExit();
    try {
        boolean thrown = false;
        try {
            service.stageFile(filename, ",", "\n", true, "utf-8");
        } catch (SecurityException e) {
            thrown = true;
        }
        assertTrue(thrown);
        thrown = false;
        try {
            service.getStagedFiles();
        } catch (SecurityException e) {
            thrown = true;
        }
        assertTrue(thrown);
        thrown = false;
        try {
            service.getPreviewRows(filename, true, 1, "utf-8");
        } catch (SecurityException e) {
            thrown = true;
        }
        assertTrue(thrown);
        thrown = false;
        try {
            service.getEncoding(filename);
        } catch (SecurityException e) {
            thrown = true;
        }
        assertTrue(thrown);
        thrown = false;
        try {
            service.generateDomain(mock(DatasourceDTO.class));
        } catch (SecurityException e) {
            thrown = true;
        }
        assertTrue(thrown);
    } finally {
        file.delete();
    }
}
Also used : ISystemSettings(org.pentaho.platform.api.engine.ISystemSettings) Matchers.anyString(org.mockito.Matchers.anyString) DatasourceDTO(org.pentaho.platform.dataaccess.datasource.wizard.models.DatasourceDTO) File(java.io.File) Test(org.junit.Test)

Example 15 with ISystemSettings

use of org.pentaho.platform.api.engine.ISystemSettings in project data-access by pentaho.

the class CsvDatasourceServiceImplTest method setUp.

@Before
public void setUp() throws Exception {
    assertNotNull("Temp directory was not found", TMP_DIR);
    existingContext = PentahoSystem.getApplicationContext();
    mockContext = mock(IApplicationContext.class);
    when(mockContext.getSolutionPath(anyString())).thenReturn(TMP_DIR + '/');
    PentahoSystem.setApplicationContext(mockContext);
    service = new CsvDatasourceServiceImpl();
    // Skip permission check by default
    final ISystemSettings systemSettings = mock(ISystemSettings.class);
    when(systemSettings.getSystemSetting("data-access-override", "false")).thenReturn("true");
    PentahoSystem.setSystemSettingsService(systemSettings);
    PentahoSessionHolder.setSession(mock(IPentahoSession.class));
    PentahoSystem.registerObject(policy);
}
Also used : IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) IApplicationContext(org.pentaho.platform.api.engine.IApplicationContext) ISystemSettings(org.pentaho.platform.api.engine.ISystemSettings) Before(org.junit.Before)

Aggregations

ISystemSettings (org.pentaho.platform.api.engine.ISystemSettings)21 Test (org.junit.Test)13 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)4 Before (org.junit.Before)3 File (java.io.File)2 Matchers.anyString (org.mockito.Matchers.anyString)2 IPentahoObjectFactory (org.pentaho.platform.api.engine.IPentahoObjectFactory)2 ISolutionEngine (org.pentaho.platform.api.engine.ISolutionEngine)2 ObjectFactoryException (org.pentaho.platform.api.engine.ObjectFactoryException)2 DatasourceDTO (org.pentaho.platform.dataaccess.datasource.wizard.models.DatasourceDTO)2 SimpleGrantedAuthority (org.springframework.security.core.authority.SimpleGrantedAuthority)2 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 LinkedList (java.util.LinkedList)1 Map (java.util.Map)1 Properties (java.util.Properties)1 Node (org.dom4j.Node)1 Expectations (org.jmock.Expectations)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 IActionCompleteListener (org.pentaho.platform.api.engine.IActionCompleteListener)1