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());
}
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());
}
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();
}
}
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();
}
}
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);
}
Aggregations