use of org.apache.chemistry.opencmis.commons.definitions.TypeDefinition in project alfresco-repository by Alfresco.
the class CMISTest method testIntegerBoudaries.
/**
* Test for MNT-9089
*/
@Test
public void testIntegerBoudaries() throws Exception {
AuthenticationUtil.pushAuthentication();
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
try {
final FileInfo fileInfo = transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<FileInfo>() {
@Override
public FileInfo execute() throws Throwable {
NodeRef companyHomeNodeRef = repositoryHelper.getCompanyHome();
QName testIntTypeQName = QName.createQName("http://testCMISIntegersModel/1.0/", "testintegerstype");
String folderName = GUID.generate();
FileInfo folderInfo = fileFolderService.create(companyHomeNodeRef, folderName, ContentModel.TYPE_FOLDER);
nodeService.setProperty(folderInfo.getNodeRef(), ContentModel.PROP_NAME, folderName);
assertNotNull(folderInfo);
String docName = GUID.generate();
FileInfo fileInfo = fileFolderService.create(folderInfo.getNodeRef(), docName, testIntTypeQName);
assertNotNull(fileInfo);
nodeService.setProperty(fileInfo.getNodeRef(), ContentModel.PROP_NAME, docName);
return fileInfo;
}
});
// get repository id
withCmisService(new CmisServiceCallback<Void>() {
@Override
public Void execute(CmisService cmisService) {
List<RepositoryInfo> repositories = cmisService.getRepositoryInfos(null);
assertTrue(repositories.size() > 0);
RepositoryInfo repo = repositories.get(0);
String repositoryId = repo.getId();
String objectIdStr = fileInfo.getNodeRef().toString();
TypeDefinition typeDef = cmisService.getTypeDefinition(repositoryId, "D:tcim:testintegerstype", null);
PropertyIntegerDefinitionImpl intNoBoundsTypeDef = (PropertyIntegerDefinitionImpl) typeDef.getPropertyDefinitions().get("tcim:int");
PropertyIntegerDefinitionImpl longNoBoundsTypeDef = (PropertyIntegerDefinitionImpl) typeDef.getPropertyDefinitions().get("tcim:long");
PropertyIntegerDefinitionImpl intWithBoundsTypeDef = (PropertyIntegerDefinitionImpl) typeDef.getPropertyDefinitions().get("tcim:intwithbounds");
PropertyIntegerDefinitionImpl longWithBoundsTypeDef = (PropertyIntegerDefinitionImpl) typeDef.getPropertyDefinitions().get("tcim:longwithbounds");
BigInteger minInteger = BigInteger.valueOf(Integer.MIN_VALUE);
BigInteger maxInteger = BigInteger.valueOf(Integer.MAX_VALUE);
BigInteger minLong = BigInteger.valueOf(Long.MIN_VALUE);
BigInteger maxLong = BigInteger.valueOf(Long.MAX_VALUE);
// test for default boundaries
assertTrue(intNoBoundsTypeDef.getMinValue().equals(minInteger));
assertTrue(intNoBoundsTypeDef.getMaxValue().equals(maxInteger));
assertTrue(longNoBoundsTypeDef.getMinValue().equals(minLong));
assertTrue(longNoBoundsTypeDef.getMaxValue().equals(maxLong));
// test for pre-defined boundaries
assertTrue(intWithBoundsTypeDef.getMinValue().equals(BigInteger.valueOf(-10L)));
assertTrue(intWithBoundsTypeDef.getMaxValue().equals(BigInteger.valueOf(10L)));
assertTrue(longWithBoundsTypeDef.getMinValue().equals(BigInteger.valueOf(-10L)));
assertTrue(longWithBoundsTypeDef.getMaxValue().equals(BigInteger.valueOf(10L)));
try // try to overfloat long without boundaries
{
BigInteger aValue = BigInteger.valueOf(Long.MAX_VALUE).add(BigInteger.valueOf(1L));
setProperiesToObject(cmisService, repositoryId, objectIdStr, "tcim:long", aValue);
fail();
} catch (Exception e) {
assertTrue(e instanceof CmisConstraintException);
}
try // try to overfloat int without boundaries
{
BigInteger aValue = BigInteger.valueOf(Integer.MAX_VALUE).add(BigInteger.valueOf(1L));
setProperiesToObject(cmisService, repositoryId, objectIdStr, "tcim:int", aValue);
fail();
} catch (Exception e) {
assertTrue(e instanceof CmisConstraintException);
}
try // try to overfloat int with boundaries
{
BigInteger aValue = BigInteger.valueOf(11l);
setProperiesToObject(cmisService, repositoryId, objectIdStr, "tcim:intwithbounds", aValue);
fail();
} catch (Exception e) {
assertTrue(e instanceof CmisConstraintException);
}
try // try to overfloat long with boundaries
{
BigInteger aValue = BigInteger.valueOf(11l);
setProperiesToObject(cmisService, repositoryId, objectIdStr, "tcim:longwithbounds", aValue);
fail();
} catch (Exception e) {
assertTrue(e instanceof CmisConstraintException);
}
return null;
}
}, CmisVersion.CMIS_1_0);
} catch (Exception e) {
fail(e.getMessage());
} finally {
AuthenticationUtil.popAuthentication();
}
}
Aggregations