Пример #1
0
        public void TestAcl()
        {
            IDocument doc = null;

            try
            {
                doc = CreateTextDocument(Session.GetRootFolder(), "acl.txt", "Hello Joe!");

                Ace joeAce = new Ace()
                {
                    Principal = new Principal()
                    {
                        Id = "joe"
                    },
                    Permissions = new List <string> {
                        "cmis:write"
                    }
                };

                // apply ACL and test result
                IAcl newAcl = doc.ApplyAcl(new List <IAce> {
                    joeAce
                }, null, AclPropagation.RepositoryDetermined);
                Assert.IsNotNull(newAcl);
                Assert.IsNotNull(newAcl.Aces);
                Assert.IsTrue(newAcl.Aces.Count > 0);

                // retrieve ACL and test
                IAcl acl2 = Session.GetAcl(doc, true);
                Assert.IsNotNull(acl2);
                Assert.IsNotNull(acl2.Aces);
                Assert.IsTrue(acl2.Aces.Count > 0);

                // fetch document and test
                IDocument doc2 = (IDocument)Session.GetObject(doc, OperationContextUtils.CreateMaximumOperationContext());
                Assert.IsNotNull(doc2.Acl);
                Assert.IsNotNull(doc2.Acl.Aces);
                Assert.IsTrue(doc2.Acl.Aces.Count > 0);
            }
            finally
            {
                if (doc != null)
                {
                    doc.Delete();
                    Assert.IsFalse(Session.Exists(doc));
                }
            }
        }
Пример #2
0
        public void TestQuery()
        {
            if (Session.RepositoryInfo.Capabilities.QueryCapability == CapabilityQuery.None)
            {
                return;
            }

            foreach (IQueryResult qr in Session.Query("SELECT * FROM cmis:document", false))
            {
                Assert.IsNotNull(qr);
                Assert.IsNotNull(qr.GetPropertyValueByQueryName(PropertyIds.ObjectId));
                Assert.IsNotNull(qr.GetPropertyValueByQueryName(PropertyIds.Name));
            }

            int count = 0;

            foreach (IQueryResult qr in Session.Query("SELECT * FROM cmis:folder", false))
            {
                Assert.IsNotNull(qr);
                Assert.IsNotNull(qr.GetPropertyValueByQueryName(PropertyIds.ObjectId));
                Assert.IsNotNull(qr.GetPropertyValueByQueryName(PropertyIds.Name));
                count++;
            }

            Assert.IsTrue(count > 0);

            IOperationContext oc = OperationContextUtils.CreateMinimumOperationContext(PropertyIds.ObjectTypeId, PropertyIds.Name);

            IFolder rootFolder = Session.GetRootFolder(oc);
            bool    found      = false;

            foreach (ICmisObject obj in Session.QueryObjects("cmis:folder", null, false, oc))
            {
                Assert.IsNotNull(obj.Id);
                Assert.IsNotNull(obj.Name);

                if (obj.Id == rootFolder.Id)
                {
                    found = true;
                }
            }

            Assert.IsTrue(found);
        }
Пример #3
0
        public void TestVersioning()
        {
            IOperationContext noCacheOC = OperationContextUtils.CreateMaximumOperationContext();

            noCacheOC.CacheEnabled = false;

            IFolder   rootFolder = Session.GetRootFolder();
            IDocument doc        = null;

            try
            {
                // create document
                string         name1          = "versioned1.txt";
                IContentStream contentStream1 = ContentStreamUtils.CreateTextContentStream(name1, "v1");

                IDictionary <string, object> props = new Dictionary <string, object>();
                props[PropertyIds.Name]         = name1;
                props[PropertyIds.ObjectTypeId] = "VersionableType";

                doc = rootFolder.CreateDocument(props, contentStream1, VersioningState.Major);

                // create next version
                string         name2          = "versioned2.txt";
                IContentStream contentStream2 = ContentStreamUtils.CreateTextContentStream(name2, "v2");

                IObjectId pwcId = doc.CheckOut();
                IDocument pwc   = (IDocument)Session.GetObject(pwcId, noCacheOC);
                Assert.AreEqual(true, pwc.IsPrivateWorkingCopy);

                pwc.Rename(name2);

                IObjectId newVersId = pwc.CheckIn(true, null, contentStream2, "version 2");
                IDocument newVers   = (IDocument)Session.GetObject(newVersId, noCacheOC);

                Assert.AreEqual(name2, newVers.Name);
                Assert.AreEqual("v2", ConvertStreamToString(newVers.GetContentStream().Stream));
                Assert.AreEqual(true, newVers.IsLatestVersion);
                Assert.AreEqual(true, newVers.IsMajorVersion);

                IDocument latestVersion = Session.GetLatestDocumentVersion(doc);
                Assert.AreEqual(newVers.Id, latestVersion.Id);

                // create next version
                string         name3          = "versioned3.txt";
                IContentStream contentStream3 = ContentStreamUtils.CreateTextContentStream(name3, "v3");

                pwcId = newVers.CheckOut();
                pwc   = (IDocument)Session.GetObject(pwcId, noCacheOC);

                pwc.Rename(name3);

                newVersId = pwc.CheckIn(true, null, contentStream3, "version 3");
                newVers   = (IDocument)Session.GetObject(newVersId);

                Assert.AreEqual(name3, newVers.Name);
                Assert.AreEqual("v3", ConvertStreamToString(newVers.GetContentStream().Stream));
                Assert.AreEqual(true, newVers.IsLatestVersion);
                Assert.AreEqual(true, newVers.IsMajorVersion);

                latestVersion = Session.GetLatestDocumentVersion(doc);
                Assert.AreEqual(newVers.Id, latestVersion.Id);

                // create next (minor) version
                string         name4          = "versioned4.txt";
                IContentStream contentStream4 = ContentStreamUtils.CreateTextContentStream(name4, "v3.1");

                pwcId = newVers.CheckOut();
                pwc   = (IDocument)Session.GetObject(pwcId, noCacheOC);

                pwc.Rename(name4);

                newVersId = pwc.CheckIn(false, null, contentStream4, "version 3.1");
                newVers   = (IDocument)Session.GetObject(newVersId);

                Assert.AreEqual(name4, newVers.Name);
                Assert.AreEqual("v3.1", ConvertStreamToString(newVers.GetContentStream().Stream));
                Assert.AreEqual(true, newVers.IsLatestVersion);
                Assert.AreEqual(false, newVers.IsMajorVersion);

                latestVersion = Session.GetLatestDocumentVersion(doc);
                Assert.AreEqual(newVers.Id, latestVersion.Id);

                // check version history
                IList <IDocument> versions = doc.GetAllVersions();
                Assert.AreEqual(4, versions.Count);

                Assert.AreEqual(latestVersion.Id, versions[0].Id);
                Assert.AreEqual(doc.Id, versions[3].Id);
            }
            finally
            {
                if (doc != null)
                {
                    doc.Delete();
                    Assert.IsFalse(Session.Exists(doc));
                }
            }
        }
Пример #4
0
        public void TestCreate()
        {
            string testFolderName = "porttest";

            if (Session.ExistsPath("/", testFolderName))
            {
                ICmisObject obj = Session.GetObjectByPath("/", testFolderName, OperationContextUtils.CreateMinimumOperationContext());
                if (obj is IFolder)
                {
                    ((IFolder)obj).DeleteTree(true, UnfileObject.Delete, true);
                }
                else
                {
                    obj.Delete();
                }
            }

            // create folder
            IFolder root      = Session.GetRootFolder();
            IFolder newFolder = CreateFolder(root, testFolderName);

            Assert.IsNotNull(newFolder);

            // create document
            string    contentString = "Hello World";
            IDocument newDoc        = CreateTextDocument(newFolder, "test.txt", contentString);

            Assert.IsNotNull(newDoc);

            // get content
            IContentStream newContent = newDoc.GetContentStream();

            Assert.IsNotNull(newContent);
            Assert.IsNotNull(newContent.Stream);

            Assert.AreEqual(contentString, ConvertStreamToString(newContent.Stream));

            // fetch it again to get the updated content stream length property
            IOperationContext ctxt   = OperationContextUtils.CreateMaximumOperationContext();
            ICmisObject       newObj = Session.GetObject(newDoc, ctxt);

            Assert.IsTrue(newObj is IDocument);
            IDocument newDoc2 = (IDocument)newObj;

            Assert.AreEqual(newDoc.Name, newDoc2.Name);
            Assert.AreEqual(Encoding.UTF8.GetBytes(contentString).Length, newDoc2.ContentStreamLength);

            // fetch it again
            newObj = Session.GetLatestDocumentVersion(newDoc, ctxt);
            Assert.IsTrue(newObj is IDocument);
            IDocument newDoc3 = (IDocument)newObj;

            Assert.AreEqual(newDoc.Id, newDoc3.Id);
            Assert.AreEqual(newDoc.Name, newDoc3.Name);

            // delete document
            newDoc.Delete();

            try
            {
                Session.GetObject(newDoc);
                Assert.Fail("Document still exists.");
            }
            catch (CmisObjectNotFoundException)
            {
                // expected
            }

            Assert.IsFalse(Session.Exists(newDoc.Id));


            // try an item
            IList <IObjectType> types = Session.GetTypeChildren(null, false).ToList();

            Assert.IsNotNull(types);
            Assert.IsTrue(types.Count >= 2);
            if (types.Any(type => type.Id == "cmis:item"))
            {
                IItem newItem = CreateItem(newFolder, "testItem");

                newItem.Delete();

                Assert.IsFalse(Session.Exists(newItem.Id));
            }


            // delete folder

            Assert.IsTrue(Session.ExistsPath(newFolder.Path));

            newFolder.Delete();

            Assert.IsFalse(Session.Exists(newFolder));
        }