use of org.alfresco.opencmis.PublicApiAlfrescoCmisServiceFactory in project alfresco-remote-api by Alfresco.
the class TestCMIS method testSetMaxContentSize.
/**
* REPO-2041 / MNT-16236 Upload via cmis binding atom and browser files with different maxContentSize
*/
@Test
public void testSetMaxContentSize() throws Exception {
final TestNetwork network1 = getTestFixture().getRandomNetwork();
Iterator<String> personIt = network1.getPersonIds().iterator();
final String personId = personIt.next();
assertNotNull(personId);
// Create a site
final TestSite site = TenantUtil.runAsUserTenant(new TenantRunAsWork<TestSite>() {
@Override
public TestSite doWork() throws Exception {
String siteName = "site" + System.currentTimeMillis();
SiteInformation siteInfo = new SiteInformation(siteName, siteName, siteName, SiteVisibility.PRIVATE);
TestSite site = network1.createSite(siteInfo);
return site;
}
}, personId, network1.getId());
publicApiClient.setRequestContext(new RequestContext(network1.getId(), personId));
CmisSession cmisSessionAtom = publicApiClient.createPublicApiCMISSession(Binding.atom, CMIS_VERSION_11, AlfrescoObjectFactoryImpl.class.getName());
CmisSession cmisSessionBrowser = publicApiClient.createPublicApiCMISSession(Binding.browser, CMIS_VERSION_11, AlfrescoObjectFactoryImpl.class.getName());
Folder documentLibrary = (Folder) cmisSessionAtom.getObjectByPath("/Sites/" + site.getSiteId() + "/documentLibrary");
// create file for upload
String fileName = "test+" + GUID.generate();
// 6MB
long fileLength = 6291456L;
RandomAccessFile f = new RandomAccessFile(fileName, "rw");
f.setLength(fileLength);
Map<String, Serializable> properties = new HashMap<String, Serializable>();
properties.put(PropertyIds.OBJECT_TYPE_ID, TYPE_CMIS_DOCUMENT);
properties.put(PropertyIds.NAME, fileName);
// change maxContentSize so that the file will be to big
// 5MB
double maxContentSize = 5.8;
PublicApiAlfrescoCmisServiceFactory publicApiAlfrescoCmisServiceFactory = (PublicApiAlfrescoCmisServiceFactory) ctx.getBean("publicApiCMISServiceFactory");
publicApiAlfrescoCmisServiceFactory.setMaxContentSize(maxContentSize);
// for atom
FileChannel fc = f.getChannel();
InputStream is = Channels.newInputStream(fc);
ContentStreamImpl contentStream = new ContentStreamImpl(fileName, BigInteger.valueOf(fileLength), MimetypeMap.MIMETYPE_TEXT_PLAIN, is);
try {
cmisSessionAtom.createDocument(documentLibrary.getId(), fileName, properties, contentStream, VersioningState.MAJOR);
fail("The file should be to big to upload via atom binding");
} catch (CmisConstraintException e) {
}
// for browser
fc.position(0);
try {
cmisSessionBrowser.createDocument(documentLibrary.getId(), fileName, properties, contentStream, VersioningState.MAJOR);
fail("The file should be to big to upload via browser binding");
} catch (CmisConstraintException e) {
}
// increase maxContensize so that the file is not to big
// 10MB
maxContentSize = 10.6;
publicApiAlfrescoCmisServiceFactory.setMaxContentSize(maxContentSize);
// for atom
fc.position(0);
Document result = cmisSessionAtom.createDocument(documentLibrary.getId(), fileName, properties, contentStream, VersioningState.MAJOR);
assertNotNull(result);
// for browser
fc.position(0);
result = cmisSessionBrowser.createDocument(documentLibrary.getId(), fileName + "2", properties, contentStream, VersioningState.MAJOR);
assertNotNull(result);
// ignore the size check
maxContentSize = -1;
publicApiAlfrescoCmisServiceFactory.setMaxContentSize(maxContentSize);
// for atom
fc.position(0);
result = cmisSessionAtom.createDocument(documentLibrary.getId(), fileName + "3", properties, contentStream, VersioningState.MAJOR);
assertNotNull(result);
// for browser
fc.position(0);
result = cmisSessionBrowser.createDocument(documentLibrary.getId(), fileName + "4", properties, contentStream, VersioningState.MAJOR);
assertNotNull(result);
}
Aggregations