Search in sources :

Example 16 with TypeDefinition

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();
    }
}
Also used : PropertyIntegerDefinitionImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyIntegerDefinitionImpl) RepositoryInfo(org.apache.chemistry.opencmis.commons.data.RepositoryInfo) QName(org.alfresco.service.namespace.QName) CmisConstraintException(org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException) CmisUpdateConflictException(org.apache.chemistry.opencmis.commons.exceptions.CmisUpdateConflictException) CmisConstraintException(org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException) CmisRuntimeException(org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException) IOException(java.io.IOException) CmisInvalidArgumentException(org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) TypeDefinition(org.apache.chemistry.opencmis.commons.definitions.TypeDefinition) NodeRef(org.alfresco.service.cmr.repository.NodeRef) FileInfo(org.alfresco.service.cmr.model.FileInfo) CmisService(org.apache.chemistry.opencmis.commons.server.CmisService) BigInteger(java.math.BigInteger) ObjectInFolderList(org.apache.chemistry.opencmis.commons.data.ObjectInFolderList) ArrayList(java.util.ArrayList) ObjectList(org.apache.chemistry.opencmis.commons.data.ObjectList) List(java.util.List) VersionableAspectTest(org.alfresco.repo.version.VersionableAspectTest) Test(org.junit.Test)

Aggregations

TypeDefinition (org.apache.chemistry.opencmis.commons.definitions.TypeDefinition)16 MutableTypeDefinition (org.apache.chemistry.opencmis.commons.definitions.MutableTypeDefinition)5 ArrayList (java.util.ArrayList)4 LinkedList (java.util.LinkedList)4 MutableDocumentTypeDefinition (org.apache.chemistry.opencmis.commons.definitions.MutableDocumentTypeDefinition)4 MutableFolderTypeDefinition (org.apache.chemistry.opencmis.commons.definitions.MutableFolderTypeDefinition)4 MutableItemTypeDefinition (org.apache.chemistry.opencmis.commons.definitions.MutableItemTypeDefinition)4 MutablePolicyTypeDefinition (org.apache.chemistry.opencmis.commons.definitions.MutablePolicyTypeDefinition)4 MutableRelationshipTypeDefinition (org.apache.chemistry.opencmis.commons.definitions.MutableRelationshipTypeDefinition)4 MutableSecondaryTypeDefinition (org.apache.chemistry.opencmis.commons.definitions.MutableSecondaryTypeDefinition)4 CmisInvalidArgumentException (org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException)4 CmisTestResult (org.apache.chemistry.opencmis.tck.CmisTestResult)4 HashMap (java.util.HashMap)3 VersionableAspectTest (org.alfresco.repo.version.VersionableAspectTest)3 RepositoryInfo (org.apache.chemistry.opencmis.commons.data.RepositoryInfo)3 DocumentTypeDefinition (org.apache.chemistry.opencmis.commons.definitions.DocumentTypeDefinition)3 TypeDefinitionContainer (org.apache.chemistry.opencmis.commons.definitions.TypeDefinitionContainer)3 DateTimeFormat (org.apache.chemistry.opencmis.commons.enums.DateTimeFormat)3 CmisObjectNotFoundException (org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException)3 CmisRuntimeException (org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException)3