use of org.pentaho.platform.api.mt.ITenant in project pentaho-platform by pentaho.
the class DefaultUnifiedRepositoryContentIT method testCreateFolder.
@Test
public void testCreateFolder() throws Exception {
loginAsSysTenantAdmin();
ITenant tenantAcme = tenantManager.createTenant(systemTenant, TENANT_ID_ACME, tenantAdminRoleName, tenantAuthenticatedRoleName, ANONYMOUS_ROLE_NAME);
userRoleDao.createUser(tenantAcme, USERNAME_ADMIN, PASSWORD, "", new String[] { tenantAdminRoleName });
login(USERNAME_ADMIN, tenantAcme, new String[] { tenantAdminRoleName, tenantAuthenticatedRoleName });
userRoleDao.createUser(tenantAcme, USERNAME_SUZY, PASSWORD, "", null);
login(USERNAME_SUZY, tenantAcme, new String[] { tenantAuthenticatedRoleName });
RepositoryFile parentFolder = repo.getFile(ClientRepositoryPaths.getUserHomeFolderPath(USERNAME_SUZY));
RepositoryFile newFolder = new RepositoryFile.Builder("test").folder(true).title("title").hidden(true).build();
Date beginTime = Calendar.getInstance().getTime();
// Sleep for 1 second for time comparison
Thread.sleep(1000);
newFolder = repo.createFolder(parentFolder.getId(), newFolder, null);
Thread.sleep(1000);
LocaleHelper.setLocale(new Locale("de"));
// new request after change Locale
newFolder = repo.getFileById(newFolder.getId());
Date endTime = Calendar.getInstance().getTime();
assertTrue(beginTime.before(newFolder.getCreatedDate()));
assertTrue(endTime.after(newFolder.getCreatedDate()));
assertNotNull(newFolder);
assertNotNull(newFolder.getId());
assertTrue(newFolder.isHidden());
assertFalse(newFolder.isAclNode());
assertEquals("title", newFolder.getTitle());
assertNotNull(SimpleJcrTestUtils.getItem(testJcrTemplate, ServerRepositoryPaths.getUserHomeFolderPath(tenantAcme, USERNAME_SUZY) + "/test"));
}
use of org.pentaho.platform.api.mt.ITenant in project pentaho-platform by pentaho.
the class DefaultUnifiedRepositoryContentIT method testCreateSimpleFile.
@Test
public void testCreateSimpleFile() throws Exception {
loginAsSysTenantAdmin();
ITenant tenantAcme = tenantManager.createTenant(systemTenant, TENANT_ID_ACME, tenantAdminRoleName, tenantAuthenticatedRoleName, ANONYMOUS_ROLE_NAME);
userRoleDao.createUser(tenantAcme, USERNAME_ADMIN, PASSWORD, "", new String[] { tenantAdminRoleName });
login(USERNAME_ADMIN, tenantAcme, new String[] { tenantAdminRoleName, tenantAuthenticatedRoleName });
userRoleDao.createUser(tenantAcme, USERNAME_SUZY, PASSWORD, "", null);
login(USERNAME_SUZY, tenantAcme, new String[] { tenantAuthenticatedRoleName });
RepositoryFile parentFolder = repo.getFile(ClientRepositoryPaths.getUserHomeFolderPath(USERNAME_SUZY));
final String expectedDataString = "Hello World!";
final String expectedEncoding = "UTF-8";
byte[] data = expectedDataString.getBytes(expectedEncoding);
ByteArrayInputStream dataStream = new ByteArrayInputStream(data);
final String expectedMimeType = "text/plain";
final String expectedName = "helloworld.xaction";
final String expectedAbsolutePath = ClientRepositoryPaths.getUserHomeFolderPath(USERNAME_SUZY) + "/helloworld.xaction";
final SimpleRepositoryFileData content = new SimpleRepositoryFileData(dataStream, expectedEncoding, expectedMimeType);
Date beginTime = Calendar.getInstance().getTime();
// when the test runs too fast, begin and lastModifiedDate are the same; manual pause
Thread.sleep(1000);
Calendar cal = Calendar.getInstance(Locale.US);
SimpleDateFormat df = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z", Locale.US);
cal.setTime(df.parse("Wed, 4 Jul 2000 12:08:56 -0700"));
RepositoryFile newFile = repo.createFile(parentFolder.getId(), new RepositoryFile.Builder(expectedName).hidden(true).versioned(true).createdDate(cal.getTime()).build(), content, null);
assertEquals(cal.getTime(), repo.getVersionSummaries(newFile.getId()).get(0).getDate());
Date endTime = Calendar.getInstance().getTime();
assertTrue(beginTime.before(newFile.getLastModifiedDate()));
assertTrue(endTime.after(newFile.getLastModifiedDate()));
assertNotNull(newFile.getId());
RepositoryFile foundFile = repo.getFile(expectedAbsolutePath);
assertNotNull(foundFile);
assertEquals(expectedName, foundFile.getName());
assertEquals(expectedAbsolutePath, foundFile.getPath());
assertNotNull(foundFile.getCreatedDate());
assertNotNull(foundFile.getLastModifiedDate());
assertTrue(foundFile.isHidden());
assertTrue(foundFile.getFileSize() > 0);
SimpleRepositoryFileData contentFromRepo = repo.getDataForRead(foundFile.getId(), SimpleRepositoryFileData.class);
assertEquals(expectedEncoding, contentFromRepo.getEncoding());
assertEquals(expectedMimeType, contentFromRepo.getMimeType());
assertEquals(expectedDataString, IOUtils.toString(contentFromRepo.getStream(), expectedEncoding));
}
use of org.pentaho.platform.api.mt.ITenant in project pentaho-platform by pentaho.
the class DefaultUnifiedRepositoryContentIT method testCreateFileAtRootIllegal.
@Test(expected = UnifiedRepositoryException.class)
public void testCreateFileAtRootIllegal() throws Exception {
loginAsSysTenantAdmin();
ITenant tenantAcme = tenantManager.createTenant(systemTenant, TENANT_ID_ACME, tenantAdminRoleName, tenantAuthenticatedRoleName, ANONYMOUS_ROLE_NAME);
userRoleDao.createUser(tenantAcme, USERNAME_ADMIN, PASSWORD, "", new String[] { tenantAdminRoleName });
login(USERNAME_ADMIN, tenantAcme, new String[] { tenantAdminRoleName, tenantAuthenticatedRoleName });
userRoleDao.createUser(tenantAcme, USERNAME_SUZY, PASSWORD, "", null);
login(USERNAME_SUZY, tenantAcme, new String[] { tenantAuthenticatedRoleName });
final String dataString = "Hello World!";
final String encoding = "UTF-8";
byte[] data = dataString.getBytes(encoding);
ByteArrayInputStream dataStream = new ByteArrayInputStream(data);
final String fileName = "helloworld.xaction";
final SimpleRepositoryFileData content = new SimpleRepositoryFileData(dataStream, encoding, "text/plain");
repo.createFile(null, new RepositoryFile.Builder(fileName).build(), content, null);
}
use of org.pentaho.platform.api.mt.ITenant in project pentaho-platform by pentaho.
the class DefaultUnifiedRepositoryContentIT method testCreateSampleFile.
@Test
public void testCreateSampleFile() throws Exception {
loginAsSysTenantAdmin();
ITenant tenantAcme = tenantManager.createTenant(systemTenant, TENANT_ID_ACME, tenantAdminRoleName, tenantAuthenticatedRoleName, ANONYMOUS_ROLE_NAME);
userRoleDao.createUser(tenantAcme, USERNAME_ADMIN, PASSWORD, "", new String[] { tenantAdminRoleName });
login(USERNAME_ADMIN, tenantAcme, new String[] { tenantAdminRoleName, tenantAuthenticatedRoleName });
userRoleDao.createUser(tenantAcme, USERNAME_SUZY, PASSWORD, "", null);
login(USERNAME_SUZY, tenantAcme, new String[] { tenantAuthenticatedRoleName });
final String expectedName = "helloworld.sample";
final String sampleString = "Ciao World!";
final boolean sampleBoolean = true;
final int sampleInteger = 99;
final String parentFolderPath = ClientRepositoryPaths.getUserHomeFolderPath(USERNAME_SUZY);
final String expectedAbsolutePath = parentFolderPath + RepositoryFile.SEPARATOR + expectedName;
RepositoryFile newFile = createSampleFile(parentFolderPath, expectedName, sampleString, sampleBoolean, sampleInteger);
assertNotNull(newFile.getId());
RepositoryFile foundFile = repo.getFile(expectedAbsolutePath);
assertNotNull(foundFile);
assertEquals(expectedName, foundFile.getName());
assertEquals(expectedAbsolutePath, foundFile.getPath());
assertNotNull(foundFile.getCreatedDate());
assertNotNull(foundFile.getLastModifiedDate());
SampleRepositoryFileData data = repo.getDataForRead(foundFile.getId(), SampleRepositoryFileData.class);
assertEquals(sampleString, data.getSampleString());
assertEquals(sampleBoolean, data.getSampleBoolean());
assertEquals(sampleInteger, data.getSampleInteger());
}
use of org.pentaho.platform.api.mt.ITenant in project pentaho-platform by pentaho.
the class DefaultUnifiedRepositoryContentIT method testGetTreeWithFileTypeFilter.
@Test
public void testGetTreeWithFileTypeFilter() throws Exception {
RepositoryFileTree root = null;
loginAsSysTenantAdmin();
ITenant tenantAcme = tenantManager.createTenant(systemTenant, TENANT_ID_ACME, tenantAdminRoleName, tenantAuthenticatedRoleName, ANONYMOUS_ROLE_NAME);
userRoleDao.createUser(tenantAcme, USERNAME_ADMIN, PASSWORD, "", new String[] { tenantAdminRoleName });
login(USERNAME_ADMIN, tenantAcme, new String[] { tenantAdminRoleName, tenantAuthenticatedRoleName });
userRoleDao.createUser(tenantAcme, USERNAME_SUZY, PASSWORD, "", null);
login(USERNAME_SUZY, tenantAcme, new String[] { tenantAuthenticatedRoleName });
RepositoryFile publicFolder = repo.getFile(ClientRepositoryPaths.getUserHomeFolderPath(PentahoSessionHolder.getSession().getName()));
final String dataString = "Hello World!";
final String encoding = "UTF-8";
byte[] data = dataString.getBytes(encoding);
ByteArrayInputStream dataStream = new ByteArrayInputStream(data);
final String mimeType = "text/plain";
final SimpleRepositoryFileData content = new SimpleRepositoryFileData(dataStream, encoding, mimeType);
RepositoryFile newFile1 = repo.createFile(publicFolder.getId(), new RepositoryFile.Builder("helloworld.xaction").versioned(true).hidden(false).build(), content, null);
RepositoryFile newFile2 = repo.createFolder(publicFolder.getId(), new RepositoryFile.Builder("testFolder").versioned(false).hidden(false).folder(true).build(), null, null);
root = repo.getTree(new RepositoryRequest(publicFolder.getPath(), true, 1, "*|FILES"));
assertFalse(root.getChildren().isEmpty());
assertEquals(1, root.getChildren().size());
assertEquals("helloworld.xaction", root.getChildren().get(0).getFile().getName());
root = repo.getTree(new RepositoryRequest(publicFolder.getPath(), true, 1, "*"));
assertFalse(root.getChildren().isEmpty());
assertEquals(2, root.getChildren().size());
root = repo.getTree(new RepositoryRequest(publicFolder.getPath(), true, 1, "*|FILES_FOLDERS"));
assertFalse(root.getChildren().isEmpty());
assertEquals(2, root.getChildren().size());
root = repo.getTree(new RepositoryRequest(publicFolder.getPath(), true, 1, "*|FOLDERS"));
assertFalse(root.getChildren().isEmpty());
assertEquals(1, root.getChildren().size());
assertEquals("testFolder", root.getChildren().get(0).getFile().getName());
}
Aggregations