use of org.alfresco.repo.usage.ContentUsageImpl in project alfresco-repository by Alfresco.
the class FTPServerTest method testFtpQuotaAndFtp.
/**
* Test a quota failue exception over FTP.
* A file should not exist after a create and quota exception.
*/
public void testFtpQuotaAndFtp() throws Exception {
// Enable usages
ContentUsageImpl contentUsage = (ContentUsageImpl) applicationContext.getBean("contentUsageImpl");
contentUsage.setEnabled(true);
contentUsage.init();
UserUsageTrackingComponent userUsageTrackingComponent = (UserUsageTrackingComponent) applicationContext.getBean("userUsageTrackingComponent");
userUsageTrackingComponent.setEnabled(true);
userUsageTrackingComponent.bootstrapInternal();
final String TEST_DIR = "/Alfresco/User Homes/" + USER_THREE;
FTPClient ftpOne = connectClient();
try {
int reply = ftpOne.getReplyCode();
if (!FTPReply.isPositiveCompletion(reply)) {
fail("FTP server refused connection.");
}
boolean login = ftpOne.login(USER_THREE, PASSWORD_THREE);
assertTrue("user three login not successful", login);
boolean success = ftpOne.changeWorkingDirectory("Alfresco");
assertTrue("user three unable to cd to Alfreco", success);
success = ftpOne.changeWorkingDirectory("User*Homes");
assertTrue("user one unable to cd to User*Homes", success);
success = ftpOne.changeWorkingDirectory(USER_THREE);
assertTrue("user one unable to cd to " + USER_THREE, success);
/**
* Create a file as user three which is bigger than the quota
*/
String FILE3_CONTENT_3 = "test file 3 content that needs to be greater than 100 bytes to result in a quota exception being thrown";
String FILE1_NAME = "test.docx";
// Should not be success
success = ftpOne.appendFile(FILE1_NAME, new ByteArrayInputStream(FILE3_CONTENT_3.getBytes("UTF-8")));
assertFalse("user one can ignore quota", success);
boolean deleted = ftpOne.deleteFile(FILE1_NAME);
assertFalse("quota exception expected", deleted);
logger.debug("test done");
} finally {
// Disable usages
contentUsage.setEnabled(false);
contentUsage.init();
userUsageTrackingComponent.setEnabled(false);
userUsageTrackingComponent.bootstrapInternal();
ftpOne.dele(TEST_DIR);
if (ftpOne != null) {
ftpOne.disconnect();
}
}
}
Aggregations