Search in sources :

Example 6 with InvalidTypeException

use of org.alfresco.service.cmr.dictionary.InvalidTypeException in project alfresco-repository by Alfresco.

the class NodeServiceTest method testChangeContentPropertyParameters.

/**
 * See MNT-20850
 */
@Test
public void testChangeContentPropertyParameters() {
    NodeRef workspaceRootNodeRef = nodeService.getRootNode(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE);
    String userName1 = GUID.generate();
    HashMap<QName, Serializable> properties = new HashMap<>();
    properties.put(ContentModel.PROP_USERNAME, userName1);
    personService.createPerson(properties);
    Map<QName, Serializable> props = new HashMap<>(3);
    props.put(ContentModel.PROP_NAME, GUID.generate());
    NodeRef folder1 = nodeService.createNode(workspaceRootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName(NAMESPACE, GUID.generate()), ContentModel.TYPE_FOLDER, props).getChildRef();
    permissionService.setPermission(folder1, userName1, PermissionService.ALL_PERMISSIONS, true);
    permissionService.setInheritParentPermissions(folder1, false);
    AuthenticationUtil.runAs(() -> {
        NodeRef nodeRef = createContentNode(folder1);
        ContentData oldContentData = (ContentData) nodeService.getProperty(nodeRef, ContentModel.PROP_CONTENT);
        ContentData newContentData = new ContentData(oldContentData.getContentUrl(), MimetypeMap.MIMETYPE_PDF, oldContentData.getSize(), oldContentData.getEncoding(), oldContentData.getLocale());
        nodeService.setProperty(nodeRef, ContentModel.PROP_CONTENT, newContentData);
        assertEquals("The content property was not correct.", newContentData, nodeService.getProperty(nodeRef, ContentModel.PROP_CONTENT));
        nodeRef = createContentNode(folder1);
        oldContentData = (ContentData) nodeService.getProperty(nodeRef, ContentModel.PROP_CONTENT);
        newContentData = new ContentData(oldContentData.getContentUrl(), oldContentData.getMimetype(), oldContentData.getSize() + 1, oldContentData.getEncoding(), oldContentData.getLocale());
        nodeService.setProperty(nodeRef, ContentModel.PROP_CONTENT, newContentData);
        assertEquals("The content property was not correct.", newContentData, nodeService.getProperty(nodeRef, ContentModel.PROP_CONTENT));
        nodeRef = createContentNode(folder1);
        oldContentData = (ContentData) nodeService.getProperty(nodeRef, ContentModel.PROP_CONTENT);
        newContentData = new ContentData(oldContentData.getContentUrl(), oldContentData.getMimetype(), oldContentData.getSize(), "UTF-16", oldContentData.getLocale());
        nodeService.setProperty(nodeRef, ContentModel.PROP_CONTENT, newContentData);
        assertEquals("The content property was not correct.", newContentData, nodeService.getProperty(nodeRef, ContentModel.PROP_CONTENT));
        nodeRef = createContentNode(folder1);
        oldContentData = (ContentData) nodeService.getProperty(nodeRef, ContentModel.PROP_CONTENT);
        newContentData = new ContentData(oldContentData.getContentUrl(), oldContentData.getMimetype(), oldContentData.getSize(), oldContentData.getEncoding(), Locale.GERMAN);
        nodeService.setProperty(nodeRef, ContentModel.PROP_CONTENT, newContentData);
        assertEquals("The content property was not correct.", newContentData, nodeService.getProperty(nodeRef, ContentModel.PROP_CONTENT));
        try {
            nodeRef = createContentNode(folder1);
            oldContentData = (ContentData) nodeService.getProperty(nodeRef, ContentModel.PROP_CONTENT);
            newContentData = new ContentData("fake://url/123", oldContentData.getMimetype(), oldContentData.getSize(), oldContentData.getEncoding(), oldContentData.getLocale());
            nodeService.setProperty(nodeRef, ContentModel.PROP_CONTENT, newContentData);
            fail("Should not be possible to change content URL");
        } catch (InvalidTypeException ite) {
        // expected
        }
        return null;
    }, userName1);
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Serializable(java.io.Serializable) ContentData(org.alfresco.service.cmr.repository.ContentData) HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName) InvalidTypeException(org.alfresco.service.cmr.dictionary.InvalidTypeException) CannedQueryDAOTest(org.alfresco.repo.domain.query.CannedQueryDAOTest) Test(org.junit.Test)

Aggregations

InvalidTypeException (org.alfresco.service.cmr.dictionary.InvalidTypeException)6 Serializable (java.io.Serializable)5 NodeRef (org.alfresco.service.cmr.repository.NodeRef)5 QName (org.alfresco.service.namespace.QName)5 ContentData (org.alfresco.service.cmr.repository.ContentData)3 HashMap (java.util.HashMap)2 CannedQueryDAOTest (org.alfresco.repo.domain.query.CannedQueryDAOTest)2 TypeDefinition (org.alfresco.service.cmr.dictionary.TypeDefinition)2 Extend (org.alfresco.traitextender.Extend)2 Test (org.junit.Test)2 Collection (java.util.Collection)1 Locale (java.util.Locale)1 Map (java.util.Map)1 ChildAssocEntity (org.alfresco.repo.domain.node.ChildAssocEntity)1 AccessDeniedException (org.alfresco.repo.security.permissions.AccessDeniedException)1 PropertyDefinition (org.alfresco.service.cmr.dictionary.PropertyDefinition)1 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)1 ContentReader (org.alfresco.service.cmr.repository.ContentReader)1 DuplicateChildNodeNameException (org.alfresco.service.cmr.repository.DuplicateChildNodeNameException)1 InvalidNodeRefException (org.alfresco.service.cmr.repository.InvalidNodeRefException)1