Commit 26b7ada825e1d461b0d3159c159baa002883d3a7
1 parent
f98f8be1
WSA-53
"Break up nunit test files into more moduler self contained tests" Implemented. Committed By: Conrad Vermeulen Reviewed By: Kevin Fourie git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@7646 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
19 changed files
with
1744 additions
and
172 deletions
ktwebservice/nunit/README
| @@ -11,6 +11,9 @@ The unit tests were written for NUnit. NUnit 2.2.0 was used during development. | @@ -11,6 +11,9 @@ The unit tests were written for NUnit. NUnit 2.2.0 was used during development. | ||
| 11 | 11 | ||
| 12 | This framework was developed in Linux using Mono. | 12 | This framework was developed in Linux using Mono. |
| 13 | 13 | ||
| 14 | +The document type 'NewType' must be added to the database for the document_type.cs unit test to run. | ||
| 15 | + | ||
| 16 | + | ||
| 14 | RUNNING THE TESTS | 17 | RUNNING THE TESTS |
| 15 | ----------------- | 18 | ----------------- |
| 16 | 19 | ||
| @@ -20,8 +23,6 @@ A makefile is provided which can be used as follows: | @@ -20,8 +23,6 @@ A makefile is provided which can be used as follows: | ||
| 20 | 23 | ||
| 21 | - make // will build and run the tests | 24 | - make // will build and run the tests |
| 22 | 25 | ||
| 23 | -- make results // will attempt to only build results | ||
| 24 | - | ||
| 25 | - make clean // will remove all temporary and binary files | 26 | - make clean // will remove all temporary and binary files |
| 26 | 27 | ||
| 27 | STATE | 28 | STATE |
ktwebservice/nunit/authentication.cs
| @@ -3,42 +3,42 @@ using System; | @@ -3,42 +3,42 @@ using System; | ||
| 3 | using System.IO; | 3 | using System.IO; |
| 4 | 4 | ||
| 5 | namespace MonoTests.KnowledgeTree | 5 | namespace MonoTests.KnowledgeTree |
| 6 | -{ | 6 | +{ |
| 7 | [TestFixture] | 7 | [TestFixture] |
| 8 | public class AuthenticationTest | 8 | public class AuthenticationTest |
| 9 | { | 9 | { |
| 10 | - | 10 | + |
| 11 | private String _session; | 11 | private String _session; |
| 12 | private KnowledgeTreeService _kt; | 12 | private KnowledgeTreeService _kt; |
| 13 | - | 13 | + |
| 14 | [SetUp] | 14 | [SetUp] |
| 15 | - public void SetUp() | 15 | + public void SetUp() |
| 16 | { | 16 | { |
| 17 | - this._kt = new KnowledgeTreeService(); | 17 | + this._kt = new KnowledgeTreeService(); |
| 18 | } | 18 | } |
| 19 | 19 | ||
| 20 | [TearDown] | 20 | [TearDown] |
| 21 | - public void TearDown() | 21 | + public void TearDown() |
| 22 | { | 22 | { |
| 23 | } | 23 | } |
| 24 | - | 24 | + |
| 25 | [Test] | 25 | [Test] |
| 26 | - public void Login() | 26 | + public void Login() |
| 27 | { | 27 | { |
| 28 | - kt_response response = this._kt.login("admin","admin","127.0.0.1"); | ||
| 29 | - | 28 | + kt_response response = this._kt.login("admin","admin","127.0.0.1"); |
| 29 | + | ||
| 30 | Assert.AreEqual(0,response.status_code); | 30 | Assert.AreEqual(0,response.status_code); |
| 31 | Assert.IsFalse(response.message == null); | 31 | Assert.IsFalse(response.message == null); |
| 32 | Assert.IsFalse(response.message == ""); | 32 | Assert.IsFalse(response.message == ""); |
| 33 | - | ||
| 34 | - this._session = response.message; | 33 | + |
| 34 | + this._session = response.message; | ||
| 35 | } | 35 | } |
| 36 | - | 36 | + |
| 37 | [Test] | 37 | [Test] |
| 38 | - public void Logout() | 38 | + public void Logout() |
| 39 | { | 39 | { |
| 40 | kt_response response = this._kt.logout(this._session); | 40 | kt_response response = this._kt.logout(this._session); |
| 41 | Assert.AreEqual(0,response.status_code); | 41 | Assert.AreEqual(0,response.status_code); |
| 42 | - } | 42 | + } |
| 43 | } | 43 | } |
| 44 | } | 44 | } |
ktwebservice/nunit/document_add.cs
| @@ -3,70 +3,78 @@ using System; | @@ -3,70 +3,78 @@ using System; | ||
| 3 | using System.IO; | 3 | using System.IO; |
| 4 | 4 | ||
| 5 | namespace MonoTests.KnowledgeTree | 5 | namespace MonoTests.KnowledgeTree |
| 6 | -{ | 6 | +{ |
| 7 | [TestFixture] | 7 | [TestFixture] |
| 8 | - public class AddDocumentTest | 8 | + public class AddDocumentTest |
| 9 | { | 9 | { |
| 10 | - | 10 | + |
| 11 | private String _session; | 11 | private String _session; |
| 12 | - private KnowledgeTreeService _kt; | 12 | + private KnowledgeTreeService _kt; |
| 13 | private int _docId; | 13 | private int _docId; |
| 14 | - private int _folderId; | 14 | + private int _folderId; |
| 15 | private String _filename; | 15 | private String _filename; |
| 16 | private String _content; | 16 | private String _content; |
| 17 | private bool _verbose; | 17 | private bool _verbose; |
| 18 | - | ||
| 19 | - | 18 | + |
| 19 | + public AddDocumentTest() | ||
| 20 | + { | ||
| 21 | + | ||
| 22 | + this._verbose = true; | ||
| 23 | + | ||
| 24 | + this._folderId = 1; | ||
| 25 | + } | ||
| 26 | + | ||
| 27 | + | ||
| 20 | [SetUp] | 28 | [SetUp] |
| 21 | - public void SetUp() | 29 | + public void SetUp() |
| 22 | { | 30 | { |
| 23 | - this._kt = new KnowledgeTreeService(); | 31 | + this._kt = new KnowledgeTreeService(); |
| 24 | //this._kt.Url = "http://ktdms.trunk/ktwebservice/webservice.php"; | 32 | //this._kt.Url = "http://ktdms.trunk/ktwebservice/webservice.php"; |
| 25 | kt_response response = this._kt.login("admin","admin","127.0.0.1"); | 33 | kt_response response = this._kt.login("admin","admin","127.0.0.1"); |
| 26 | - this._session = response.message; | ||
| 27 | - | ||
| 28 | - this._filename = Helper.isUnix()?"/tmp/kt_unit_test1.txt":"c:\\kt_unit_test1.txt"; | 34 | + this._session = response.message; |
| 35 | + | ||
| 36 | + this._filename = Helper.isUnix()?"/tmp/kt_unit_test1.txt":"c:\\kt_unit_test1.txt"; | ||
| 29 | this._content = "hello world!"; | 37 | this._content = "hello world!"; |
| 30 | 38 | ||
| 31 | Helper.writeFile(this._filename, this._content); | 39 | Helper.writeFile(this._filename, this._content); |
| 32 | - | ||
| 33 | - this._verbose = false; | ||
| 34 | - | ||
| 35 | - this._folderId = 1; | 40 | + |
| 41 | + | ||
| 36 | } | 42 | } |
| 37 | 43 | ||
| 38 | [TearDown] | 44 | [TearDown] |
| 39 | - public void TearDown() | 45 | + public void TearDown() |
| 40 | { | 46 | { |
| 41 | - this._kt.logout(this._session); | ||
| 42 | - | ||
| 43 | - Helper.deleteFile(this._filename); | 47 | + |
| 48 | + Helper.deleteFile(this._filename); | ||
| 49 | + | ||
| 50 | + | ||
| 51 | + this._kt.logout(this._session); | ||
| 44 | } | 52 | } |
| 45 | - | ||
| 46 | - | ||
| 47 | - | ||
| 48 | - | 53 | + |
| 54 | + | ||
| 55 | + | ||
| 56 | + | ||
| 49 | [Test] | 57 | [Test] |
| 50 | - public void FindDocumentBeforeAdd() | 58 | + public void FindDocumentBeforeAdd() |
| 51 | { | 59 | { |
| 52 | String filename = "Root Folder/kt test folder/kt unit test1"; | 60 | String filename = "Root Folder/kt test folder/kt unit test1"; |
| 53 | if (this._verbose) System.Console.WriteLine("Finding document before add: " + filename); | 61 | if (this._verbose) System.Console.WriteLine("Finding document before add: " + filename); |
| 54 | - kt_document_detail documentDetail = this._kt.get_document_detail_by_name(this._session, filename, "T"); | 62 | + kt_document_detail documentDetail = this._kt.get_document_detail_by_title(this._session, 1, filename, ""); |
| 55 | if (0 == documentDetail.status_code) | 63 | if (0 == documentDetail.status_code) |
| 56 | { | 64 | { |
| 57 | if (this._verbose) System.Console.WriteLine("Found document - deleting"); | 65 | if (this._verbose) System.Console.WriteLine("Found document - deleting"); |
| 58 | kt_response response = this._kt.delete_document(this._session, documentDetail.document_id, "Delete - cleaning up before add"); | 66 | kt_response response = this._kt.delete_document(this._session, documentDetail.document_id, "Delete - cleaning up before add"); |
| 59 | Assert.AreEqual(0, response.status_code); | 67 | Assert.AreEqual(0, response.status_code); |
| 60 | } | 68 | } |
| 61 | - else if (this._verbose) | 69 | + else if (this._verbose) |
| 62 | { | 70 | { |
| 63 | System.Console.WriteLine("document not found. that is ok!"); | 71 | System.Console.WriteLine("document not found. that is ok!"); |
| 64 | } | 72 | } |
| 65 | - } | ||
| 66 | - | ||
| 67 | - | 73 | + } |
| 74 | + | ||
| 75 | + | ||
| 68 | [Test] | 76 | [Test] |
| 69 | - public void FindFolderBeforeAdd() | 77 | + public void FindFolderBeforeAdd() |
| 70 | { | 78 | { |
| 71 | String folder = "Root Folder/kt test folder"; | 79 | String folder = "Root Folder/kt test folder"; |
| 72 | if (this._verbose) System.Console.WriteLine("Finding folder before add: " + folder); | 80 | if (this._verbose) System.Console.WriteLine("Finding folder before add: " + folder); |
| @@ -81,87 +89,150 @@ namespace MonoTests.KnowledgeTree | @@ -81,87 +89,150 @@ namespace MonoTests.KnowledgeTree | ||
| 81 | { | 89 | { |
| 82 | if (this._verbose) System.Console.WriteLine("folder not found. that is ok!"); | 90 | if (this._verbose) System.Console.WriteLine("folder not found. that is ok!"); |
| 83 | } | 91 | } |
| 84 | - } | ||
| 85 | - | ||
| 86 | - | 92 | + } |
| 93 | + | ||
| 94 | + | ||
| 87 | [Test] | 95 | [Test] |
| 88 | - public void AddDocument() | ||
| 89 | - { | 96 | + public void AddDocument() |
| 97 | + { | ||
| 90 | String folder = "kt test folder"; | 98 | String folder = "kt test folder"; |
| 91 | - | 99 | + |
| 92 | if (this._verbose) System.Console.WriteLine("Creating folder : " + folder); | 100 | if (this._verbose) System.Console.WriteLine("Creating folder : " + folder); |
| 93 | kt_folder_detail folderDetail = this._kt.create_folder(this._session, 1, folder); | 101 | kt_folder_detail folderDetail = this._kt.create_folder(this._session, 1, folder); |
| 94 | this._folderId = folderDetail.id; | 102 | this._folderId = folderDetail.id; |
| 95 | if (this._verbose) System.Console.WriteLine("Got folder id : " + this._folderId); | 103 | if (this._verbose) System.Console.WriteLine("Got folder id : " + this._folderId); |
| 96 | - | 104 | + |
| 97 | String filename = "kt unit test1"; | 105 | String filename = "kt unit test1"; |
| 98 | - | 106 | + |
| 99 | if (this._verbose) System.Console.WriteLine("Adding document : " + filename); | 107 | if (this._verbose) System.Console.WriteLine("Adding document : " + filename); |
| 100 | - | ||
| 101 | - | 108 | + |
| 109 | + | ||
| 102 | kt_document_detail response1 = this._kt.add_base64_document(this._session, this._folderId, filename, this._filename, "Default", Helper.ConvertFileToBase64Encoding(this._filename)); | 110 | kt_document_detail response1 = this._kt.add_base64_document(this._session, this._folderId, filename, this._filename, "Default", Helper.ConvertFileToBase64Encoding(this._filename)); |
| 103 | - | 111 | + |
| 104 | Assert.AreEqual(0, response1.status_code); | 112 | Assert.AreEqual(0, response1.status_code); |
| 105 | Assert.AreEqual("kt unit test1", response1.title); | 113 | Assert.AreEqual("kt unit test1", response1.title); |
| 106 | Assert.AreEqual("Default", response1.document_type); | 114 | Assert.AreEqual("Default", response1.document_type); |
| 107 | Assert.AreEqual("0.1", response1.version); | 115 | Assert.AreEqual("0.1", response1.version); |
| 108 | Assert.AreEqual("kt_unit_test1.txt", response1.filename); | 116 | Assert.AreEqual("kt_unit_test1.txt", response1.filename); |
| 109 | - | 117 | + |
| 110 | Assert.IsFalse(response1.created_date == null); | 118 | Assert.IsFalse(response1.created_date == null); |
| 111 | Assert.IsFalse(response1.created_date == ""); | 119 | Assert.IsFalse(response1.created_date == ""); |
| 112 | - | 120 | + |
| 113 | Assert.AreEqual("Administrator", response1.created_by); | 121 | Assert.AreEqual("Administrator", response1.created_by); |
| 114 | - | 122 | + |
| 115 | //Assert.IsTrue(response1.updated_date == null); | 123 | //Assert.IsTrue(response1.updated_date == null); |
| 116 | - Assert.IsTrue("" != response1.updated_date); | 124 | + Assert.IsTrue("" != response1.updated_date); |
| 125 | + | ||
| 126 | + Assert.AreEqual("Administrator", response1.updated_by); | ||
| 117 | 127 | ||
| 118 | - Assert.AreEqual("Administrator", response1.updated_by); | 128 | + Assert.IsTrue(response1.document_id > 0); |
| 119 | 129 | ||
| 120 | - Assert.IsTrue(response1.document_id > 0); | ||
| 121 | - | ||
| 122 | Assert.AreEqual(this._folderId, response1.folder_id); | 130 | Assert.AreEqual(this._folderId, response1.folder_id); |
| 123 | - | ||
| 124 | - | ||
| 125 | - Assert.AreEqual("n/a",response1.workflow); | ||
| 126 | - | ||
| 127 | - | ||
| 128 | - Assert.AreEqual("n/a",response1.workflow_state); | ||
| 129 | - | ||
| 130 | - Assert.AreEqual("Root Folder/" + folder + "/kt unit test1", response1.full_path); | ||
| 131 | - | 131 | + |
| 132 | + | ||
| 133 | + Assert.AreEqual("n/a",response1.workflow); | ||
| 134 | + | ||
| 135 | + | ||
| 136 | + Assert.AreEqual("n/a",response1.workflow_state); | ||
| 137 | + | ||
| 138 | + Assert.AreEqual("Root Folder/" + folder + "/kt unit test1", response1.full_path); | ||
| 139 | + | ||
| 132 | this._docId = response1.document_id; | 140 | this._docId = response1.document_id; |
| 133 | } | 141 | } |
| 134 | - | 142 | + |
| 135 | [Test] | 143 | [Test] |
| 136 | - public void FindDocumentBeforeDelete() | 144 | + public void FindDocumentBeforeDelete() |
| 137 | { | 145 | { |
| 146 | + | ||
| 138 | if (this._verbose) System.Console.WriteLine("Find document before delete"); | 147 | if (this._verbose) System.Console.WriteLine("Find document before delete"); |
| 139 | - kt_document_detail documentDetail = this._kt.get_document_detail_by_name(this._session, "Root Folder/kt test folder/kt unit test1", "T"); | 148 | + kt_document_detail documentDetail = this._kt.get_document_detail_by_name(this._session, 1, "Root Folder/kt test folder/kt unit test1", "T",""); |
| 140 | Assert.AreEqual(0, documentDetail.status_code); | 149 | Assert.AreEqual(0, documentDetail.status_code); |
| 141 | Assert.AreEqual(this._docId, documentDetail.document_id); | 150 | Assert.AreEqual(this._docId, documentDetail.document_id); |
| 142 | - | 151 | + |
| 152 | + | ||
| 153 | + | ||
| 143 | if (this._verbose) System.Console.WriteLine("Find document before delete without the Root Folder's explicit naming"); | 154 | if (this._verbose) System.Console.WriteLine("Find document before delete without the Root Folder's explicit naming"); |
| 144 | - documentDetail = this._kt.get_document_detail_by_name(this._session, "/kt test folder/kt unit test1", "T"); | 155 | + documentDetail = this._kt.get_document_detail_by_title(this._session, 1, "/kt test folder/kt unit test1", ""); |
| 145 | Assert.AreEqual(0, documentDetail.status_code); | 156 | Assert.AreEqual(0, documentDetail.status_code); |
| 146 | Assert.AreEqual(this._docId, documentDetail.document_id); | 157 | Assert.AreEqual(this._docId, documentDetail.document_id); |
| 147 | } | 158 | } |
| 148 | - | 159 | + |
| 149 | [Test] | 160 | [Test] |
| 150 | - public void DeleteDocument() | 161 | + public void DeleteDocument() |
| 151 | { | 162 | { |
| 152 | if (this._verbose) System.Console.WriteLine("Deleting document"); | 163 | if (this._verbose) System.Console.WriteLine("Deleting document"); |
| 153 | - kt_response response = this._kt.delete_document(this._session, this._docId, "Delete - cleaning up after add"); | 164 | + kt_response response = this._kt.delete_document(this._session, this._docId, "Delete - cleaning up after add"); |
| 154 | Assert.AreEqual(0, response.status_code); | 165 | Assert.AreEqual(0, response.status_code); |
| 155 | } | 166 | } |
| 156 | - | 167 | + |
| 157 | [Test] | 168 | [Test] |
| 158 | - public void FindDocumentAfterDelete() | 169 | + public void FindDocumentAfterDelete() |
| 159 | { | 170 | { |
| 160 | if (this._verbose) System.Console.WriteLine("Checking that document is gone!"); | 171 | if (this._verbose) System.Console.WriteLine("Checking that document is gone!"); |
| 161 | - | ||
| 162 | - kt_document_detail documentDetail = this._kt.get_document_detail_by_name(this._session, "Root Folder/kt test folder/kt unit test1", "T"); | 172 | + |
| 173 | + kt_document_detail documentDetail = this._kt.get_document_detail_by_title(this._session, 1, "Root Folder/kt test folder/kt unit test1", ""); | ||
| 163 | Assert.IsTrue(0 != documentDetail.status_code); | 174 | Assert.IsTrue(0 != documentDetail.status_code); |
| 164 | - } | ||
| 165 | - | 175 | + } |
| 176 | + | ||
| 177 | + | ||
| 178 | + | ||
| 179 | + | ||
| 180 | + [Test] | ||
| 181 | + public void Add2PhaseDocument() | ||
| 182 | + { | ||
| 183 | + | ||
| 184 | + | ||
| 185 | + String filename = "kt unit test31"; | ||
| 186 | + | ||
| 187 | + if (this._verbose) System.Console.WriteLine("Adding document : " + filename); | ||
| 188 | + FileUploader uploader = new FileUploader("http://ktdms.trunk/ktwebservice/upload.php"); | ||
| 189 | + | ||
| 190 | + uploader.upload(this._session, this._filename); | ||
| 191 | + String tempname = uploader.getFilename(); | ||
| 192 | + | ||
| 193 | + kt_document_detail response1 = this._kt.add_document(this._session, this._folderId, filename, this._filename, "Default", tempname); | ||
| 194 | + | ||
| 195 | + Assert.AreEqual(0, response1.status_code); | ||
| 196 | + Assert.AreEqual(filename, response1.title); | ||
| 197 | + Assert.AreEqual("Default", response1.document_type); | ||
| 198 | + Assert.AreEqual("0.1", response1.version); | ||
| 199 | + Assert.AreEqual("kt_unit_test1.txt", response1.filename); | ||
| 200 | + | ||
| 201 | + Assert.IsFalse(response1.created_date == null); | ||
| 202 | + Assert.IsFalse(response1.created_date == ""); | ||
| 203 | + | ||
| 204 | + Assert.AreEqual("Administrator", response1.created_by); | ||
| 205 | + | ||
| 206 | + //Assert.IsTrue(response1.updated_date == null); | ||
| 207 | + Assert.IsTrue("" != response1.updated_date); | ||
| 208 | + | ||
| 209 | + Assert.AreEqual("Administrator", response1.updated_by); | ||
| 210 | + | ||
| 211 | + Assert.IsTrue(response1.document_id > 0); | ||
| 212 | + | ||
| 213 | + Assert.AreEqual(this._folderId, response1.folder_id); | ||
| 214 | + | ||
| 215 | + | ||
| 216 | + Assert.AreEqual("n/a",response1.workflow); | ||
| 217 | + | ||
| 218 | + | ||
| 219 | + Assert.AreEqual("n/a",response1.workflow_state); | ||
| 220 | + | ||
| 221 | + | ||
| 222 | + this._docId = response1.document_id; | ||
| 223 | + | ||
| 224 | + kt_response response = this._kt.delete_document(this._session, this._docId, "Delete - cleaning up after add"); | ||
| 225 | + Assert.AreEqual(0, response.status_code); | ||
| 226 | + } | ||
| 227 | + | ||
| 228 | + [Test] | ||
| 229 | + public void DropFolder() | ||
| 230 | + { | ||
| 231 | + if (this._verbose) System.Console.WriteLine("Drop Folder!"); | ||
| 232 | + | ||
| 233 | + kt_response documentDetail = this._kt.delete_folder(this._session, this._folderId, "delete - cleaning up"); | ||
| 234 | + Assert.AreEqual(0, documentDetail.status_code); | ||
| 235 | + } | ||
| 236 | + | ||
| 166 | } | 237 | } |
| 167 | } | 238 | } |
ktwebservice/nunit/document_checkout.cs
0 โ 100644
| 1 | +using NUnit.Framework; | ||
| 2 | +using System; | ||
| 3 | +using System.IO; | ||
| 4 | + | ||
| 5 | +namespace MonoTests.KnowledgeTree | ||
| 6 | +{ | ||
| 7 | + [TestFixture] | ||
| 8 | + public class CheckoutDocumentTest | ||
| 9 | + { | ||
| 10 | + private String _session; | ||
| 11 | + private KnowledgeTreeService _kt; | ||
| 12 | + private int _docId; | ||
| 13 | + private int _folderId; | ||
| 14 | + private String _filename; | ||
| 15 | + private String _content; | ||
| 16 | + private bool _verbose; | ||
| 17 | + | ||
| 18 | + | ||
| 19 | + [SetUp] | ||
| 20 | + public void SetUp() | ||
| 21 | + { | ||
| 22 | + this._kt = new KnowledgeTreeService(); | ||
| 23 | + kt_response response = this._kt.login("admin","admin","127.0.0.1"); | ||
| 24 | + this._session = response.message; | ||
| 25 | + | ||
| 26 | + this._filename = Helper.isUnix()?"/tmp/kt_unit_test1.txt":"c:\\kt_unit_test1.txt"; | ||
| 27 | + | ||
| 28 | + String filename = "kt unit test1"; | ||
| 29 | + | ||
| 30 | + this._content = "hello world!"; | ||
| 31 | + | ||
| 32 | + Helper.writeFile(this._filename, this._content); | ||
| 33 | + | ||
| 34 | + this._verbose = false; | ||
| 35 | + | ||
| 36 | + this._folderId = 1; | ||
| 37 | + | ||
| 38 | + kt_document_detail response1 = this._kt.add_base64_document(this._session, this._folderId, filename, this._filename, "Default", Helper.ConvertFileToBase64Encoding(this._filename)); | ||
| 39 | + | ||
| 40 | + if (this._verbose && response1.status_code != 0) | ||
| 41 | + { | ||
| 42 | + System.Console.WriteLine("Could not create file: " + this._filename); | ||
| 43 | + } | ||
| 44 | + this._docId = response1.document_id; | ||
| 45 | + | ||
| 46 | + | ||
| 47 | + } | ||
| 48 | + | ||
| 49 | + [TearDown] | ||
| 50 | + public void TearDown() | ||
| 51 | + { | ||
| 52 | + | ||
| 53 | + Helper.deleteFile(this._filename); | ||
| 54 | + | ||
| 55 | + kt_response response = this._kt.delete_document(this._session, this._docId, "Delete - cleaning up"); | ||
| 56 | + if (this._verbose && response.status_code != 0) | ||
| 57 | + { | ||
| 58 | + System.Console.WriteLine("Could not delete file: " + this._filename); | ||
| 59 | + } | ||
| 60 | + | ||
| 61 | + this._kt.logout(this._session); | ||
| 62 | + | ||
| 63 | + } | ||
| 64 | + | ||
| 65 | + [Test] | ||
| 66 | + public void CheckoutDocument() | ||
| 67 | + { | ||
| 68 | + String filename = "kt unit test1"; | ||
| 69 | + | ||
| 70 | + if (this._verbose) System.Console.WriteLine("Checking out document : " + filename); | ||
| 71 | + | ||
| 72 | + kt_response response = this._kt.checkout_base64_document(this._session, this._docId, "unit test - going to checkout and then undo", false); | ||
| 73 | + Assert.AreEqual(0, response.status_code); | ||
| 74 | + | ||
| 75 | + | ||
| 76 | + response = this._kt.undo_document_checkout(this._session, this._docId, "unit test - doing undo"); | ||
| 77 | + Assert.AreEqual(0, response.status_code); | ||
| 78 | + } | ||
| 79 | + | ||
| 80 | + [Test] | ||
| 81 | + public void CheckinDocument() | ||
| 82 | + { | ||
| 83 | + String filename = "kt unit test1"; | ||
| 84 | + | ||
| 85 | + if (this._verbose) System.Console.WriteLine("Checking out document : " + filename); | ||
| 86 | + | ||
| 87 | + kt_response response = this._kt.checkout_base64_document(this._session, this._docId, "unit test - going to checkout and then checkin", false); | ||
| 88 | + Assert.AreEqual(0, response.status_code); | ||
| 89 | + | ||
| 90 | + | ||
| 91 | + kt_document_detail checkin = this._kt.checkin_base64_document(this._session, this._docId, filename, "unit test - doing checkin", Helper.ConvertFileToBase64Encoding(this._filename), false); | ||
| 92 | + Assert.AreEqual(0, checkin.status_code); | ||
| 93 | + | ||
| 94 | + //assert - check data checkout | ||
| 95 | + } | ||
| 96 | + | ||
| 97 | + [Test] | ||
| 98 | + public void Checkin2PhaseDocument() | ||
| 99 | + { | ||
| 100 | + String filename = "kt unit test1"; | ||
| 101 | + | ||
| 102 | + if (this._verbose) System.Console.WriteLine("Checking out document : " + filename); | ||
| 103 | + | ||
| 104 | + kt_response response = this._kt.checkout_document(this._session, this._docId, "unit test - going to checkout and then checkin", false); | ||
| 105 | + Assert.AreEqual(0, response.status_code); | ||
| 106 | + | ||
| 107 | + | ||
| 108 | + FileUploader uploader = new FileUploader("http://ktdms.trunk/ktwebservice/upload.php"); | ||
| 109 | + | ||
| 110 | + uploader.upload(this._session, this._filename); | ||
| 111 | + String tempname = uploader.getFilename(); | ||
| 112 | + | ||
| 113 | + kt_document_detail checkin = this._kt.checkin_document(this._session, this._docId, filename, "unit test - doing checkin", tempname, false); | ||
| 114 | + Assert.AreEqual(0, checkin.status_code); | ||
| 115 | + } | ||
| 116 | + | ||
| 117 | + | ||
| 118 | + | ||
| 119 | + } | ||
| 120 | +} |
ktwebservice/nunit/document_detail.cs
0 โ 100644
| 1 | +using NUnit.Framework; | ||
| 2 | +using System; | ||
| 3 | +using System.IO; | ||
| 4 | + | ||
| 5 | +namespace MonoTests.KnowledgeTree | ||
| 6 | +{ | ||
| 7 | + [TestFixture] | ||
| 8 | + public class DocumentDetailTest | ||
| 9 | + { | ||
| 10 | + private String _session; | ||
| 11 | + private KnowledgeTreeService _kt; | ||
| 12 | + private int _docId; | ||
| 13 | + private int _folderId; | ||
| 14 | + private String _filename; | ||
| 15 | + private String _content; | ||
| 16 | + private bool _verbose; | ||
| 17 | + | ||
| 18 | + | ||
| 19 | + [SetUp] | ||
| 20 | + public void SetUp() | ||
| 21 | + { | ||
| 22 | + this._kt = new KnowledgeTreeService(); | ||
| 23 | + kt_response response = this._kt.login("admin","admin","127.0.0.1"); | ||
| 24 | + this._session = response.message; | ||
| 25 | + | ||
| 26 | + this._filename = Helper.isUnix()?"/tmp/kt_unit_test1.txt":"c:\\kt_unit_test1.txt"; | ||
| 27 | + | ||
| 28 | + String filename = "kt unit test1"; | ||
| 29 | + | ||
| 30 | + this._content = "hello world!"; | ||
| 31 | + | ||
| 32 | + Helper.writeFile(this._filename, this._content); | ||
| 33 | + | ||
| 34 | + this._verbose = false; | ||
| 35 | + | ||
| 36 | + this._folderId = 1; | ||
| 37 | + | ||
| 38 | + kt_document_detail response1 = this._kt.add_base64_document(this._session, this._folderId, filename, this._filename, "Default", Helper.ConvertFileToBase64Encoding(this._filename)); | ||
| 39 | + | ||
| 40 | + if (this._verbose && response1.status_code != 0) | ||
| 41 | + { | ||
| 42 | + System.Console.WriteLine("Could not create file: " + this._filename); | ||
| 43 | + } | ||
| 44 | + this._docId = response1.document_id; | ||
| 45 | + | ||
| 46 | + | ||
| 47 | + } | ||
| 48 | + | ||
| 49 | + [TearDown] | ||
| 50 | + public void TearDown() | ||
| 51 | + { | ||
| 52 | + | ||
| 53 | + Helper.deleteFile(this._filename); | ||
| 54 | + | ||
| 55 | + kt_response response = this._kt.delete_document(this._session, this._docId, "Delete - cleaning up"); | ||
| 56 | + if (this._verbose && response.status_code != 0) | ||
| 57 | + { | ||
| 58 | + System.Console.WriteLine("Could not delete file: " + this._filename); | ||
| 59 | + } | ||
| 60 | + | ||
| 61 | + this._kt.logout(this._session); | ||
| 62 | + | ||
| 63 | + } | ||
| 64 | + | ||
| 65 | + [Test] | ||
| 66 | + public void NonExistantDocumentTest() | ||
| 67 | + { | ||
| 68 | + kt_document_detail response = this._kt.get_document_detail(this._session, -1,""); | ||
| 69 | + Assert.IsFalse(response.status_code == 0); | ||
| 70 | + } | ||
| 71 | + | ||
| 72 | + [Test] | ||
| 73 | + public void DocumentExistanceTest() | ||
| 74 | + { | ||
| 75 | + kt_document_detail response = this._kt.get_document_detail(this._session, this._docId,""); | ||
| 76 | + Assert.AreEqual(0, response.status_code); | ||
| 77 | + Assert.AreEqual(this._docId, response.document_id); | ||
| 78 | + } | ||
| 79 | + | ||
| 80 | + [Test] | ||
| 81 | + public void GetDetailByTitleTest() | ||
| 82 | + { | ||
| 83 | + kt_document_detail response = this._kt.get_document_detail_by_name(this._session, 1, "Root Folder/kt unit test1", "T",""); | ||
| 84 | + | ||
| 85 | + Assert.AreEqual(0, response.status_code); | ||
| 86 | + Assert.AreEqual(this._docId, response.document_id); | ||
| 87 | + } | ||
| 88 | + | ||
| 89 | + | ||
| 90 | + [Test] | ||
| 91 | + public void GetDetailByTitle2Test() | ||
| 92 | + { | ||
| 93 | + kt_document_detail response = this._kt.get_document_detail_by_title(this._session, 1, "Root Folder/kt unit test1", ""); | ||
| 94 | + | ||
| 95 | + Assert.AreEqual(0, response.status_code); | ||
| 96 | + Assert.AreEqual(this._docId, response.document_id); | ||
| 97 | + } | ||
| 98 | + | ||
| 99 | + [Test] | ||
| 100 | + public void GetDetailByFileTest() | ||
| 101 | + { | ||
| 102 | + kt_document_detail response = this._kt.get_document_detail_by_name(this._session, 1, "Root Folder/kt_unit_test1.txt", "F",""); | ||
| 103 | + | ||
| 104 | + Assert.AreEqual(0, response.status_code); | ||
| 105 | + Assert.AreEqual(this._docId, response.document_id); | ||
| 106 | + } | ||
| 107 | + [Test] | ||
| 108 | + public void GetDetailByFile2Test() | ||
| 109 | + { | ||
| 110 | + kt_document_detail response = this._kt.get_document_detail_by_filename(this._session, 1, "Root Folder/kt_unit_test1.txt", ""); | ||
| 111 | + | ||
| 112 | + Assert.AreEqual(0, response.status_code); | ||
| 113 | + Assert.AreEqual(this._docId, response.document_id); | ||
| 114 | + } | ||
| 115 | + | ||
| 116 | + [Test] | ||
| 117 | + public void GetDetailByUnknownNameTest() | ||
| 118 | + { | ||
| 119 | + kt_document_detail response = this._kt.get_document_detail_by_name(this._session, 1, "Root Folder/kt_unit_test1.ssssdasdasd", "F",""); | ||
| 120 | + Assert.IsFalse(response.status_code == 0); | ||
| 121 | + } | ||
| 122 | + } | ||
| 123 | +} |
ktwebservice/nunit/document_download.cs
0 โ 100644
| 1 | +using NUnit.Framework; | ||
| 2 | +using System; | ||
| 3 | +using System.IO; | ||
| 4 | +using System.Net; | ||
| 5 | + | ||
| 6 | +namespace MonoTests.KnowledgeTree | ||
| 7 | +{ | ||
| 8 | + | ||
| 9 | + | ||
| 10 | + [TestFixture] | ||
| 11 | + public class DocumentSystemMetadataTest | ||
| 12 | + { | ||
| 13 | + private String _session; | ||
| 14 | + private KnowledgeTreeService _kt; | ||
| 15 | + private int _folderId; | ||
| 16 | + private bool _verbose; | ||
| 17 | + private Document _doc1; | ||
| 18 | + | ||
| 19 | + | ||
| 20 | + [SetUp] | ||
| 21 | + public void SetUp() | ||
| 22 | + { | ||
| 23 | + this._kt = new KnowledgeTreeService(); | ||
| 24 | + kt_response response = this._kt.login("admin","admin","127.0.0.1"); | ||
| 25 | + this._session = response.message; | ||
| 26 | + | ||
| 27 | + this._folderId = 1; | ||
| 28 | + | ||
| 29 | + | ||
| 30 | + this._doc1 = new Document(1, this._session, this._kt, this._verbose,false); | ||
| 31 | + this._doc1.createFile(this._folderId); | ||
| 32 | + | ||
| 33 | + | ||
| 34 | + this._verbose = true; | ||
| 35 | + | ||
| 36 | + } | ||
| 37 | + | ||
| 38 | + [TearDown] | ||
| 39 | + public void TearDown() | ||
| 40 | + { | ||
| 41 | + this._doc1.deleteFile(); | ||
| 42 | + | ||
| 43 | + this._kt.logout(this._session); | ||
| 44 | + | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | + [Test] | ||
| 48 | + public void DownloadTest() | ||
| 49 | + { | ||
| 50 | + kt_response update_resp = this._kt.download_document(this._session, this._doc1.docId ); | ||
| 51 | + Assert.AreEqual(0, update_resp.status_code); | ||
| 52 | + | ||
| 53 | + System.Console.WriteLine("Download...." + update_resp.message); | ||
| 54 | + | ||
| 55 | + String uri = update_resp.message; | ||
| 56 | + | ||
| 57 | + HttpWebRequest webrequest = (HttpWebRequest)WebRequest.Create(uri); | ||
| 58 | + | ||
| 59 | + WebResponse response = webrequest.GetResponse(); | ||
| 60 | + StreamReader sr = new StreamReader(response.GetResponseStream()); | ||
| 61 | + String content = sr.ReadToEnd(); | ||
| 62 | + | ||
| 63 | + System.Console.WriteLine(content); | ||
| 64 | + | ||
| 65 | + | ||
| 66 | + } | ||
| 67 | + | ||
| 68 | + [Test] | ||
| 69 | + public void SmallDownloadTest() | ||
| 70 | + { | ||
| 71 | + kt_response update_resp = this._kt.download_small_document(this._session, this._doc1.docId ); | ||
| 72 | + Assert.AreEqual(0, update_resp.status_code); | ||
| 73 | + | ||
| 74 | + String filename = Helper.isUnix()?("/tmp/kt_unit_test_tmp.txt"):("c:\\kt_unit_test_tmp.txt"); | ||
| 75 | + | ||
| 76 | + | ||
| 77 | + | ||
| 78 | + long length = Helper.ConvertBase64EncodingToFile(update_resp.message, filename); | ||
| 79 | + //System.Console.WriteLine(Helper.readFile(filename)); | ||
| 80 | + | ||
| 81 | + // TODO - why??? | ||
| 82 | + //Assert.AreEqual(length, this._doc1.filesize); | ||
| 83 | + } | ||
| 84 | + } | ||
| 85 | +} |
ktwebservice/nunit/document_history.cs
0 โ 100644
| 1 | +using NUnit.Framework; | ||
| 2 | +using System; | ||
| 3 | +using System.IO; | ||
| 4 | + | ||
| 5 | +namespace MonoTests.KnowledgeTree | ||
| 6 | +{ | ||
| 7 | + [TestFixture] | ||
| 8 | + public class DocumentHistoryTest | ||
| 9 | + { | ||
| 10 | + private String _session; | ||
| 11 | + private KnowledgeTreeService _kt; | ||
| 12 | + private int _folderId; | ||
| 13 | + private bool _verbose; | ||
| 14 | + private Document _doc1; | ||
| 15 | + | ||
| 16 | + [SetUp] | ||
| 17 | + public void SetUp() | ||
| 18 | + { | ||
| 19 | + this._kt = new KnowledgeTreeService(); | ||
| 20 | + kt_response response = this._kt.login("admin","admin","127.0.0.1"); | ||
| 21 | + this._session = response.message; | ||
| 22 | + | ||
| 23 | + this._folderId = 1; | ||
| 24 | + | ||
| 25 | + this._doc1 = new Document(1, this._session, this._kt, this._verbose,false); | ||
| 26 | + this._doc1.createFile(this._folderId); | ||
| 27 | + | ||
| 28 | + this._verbose = true; | ||
| 29 | + | ||
| 30 | + } | ||
| 31 | + | ||
| 32 | + [TearDown] | ||
| 33 | + public void TearDown() | ||
| 34 | + { | ||
| 35 | + this._doc1.deleteFile(); | ||
| 36 | + | ||
| 37 | + this._kt.logout(this._session); | ||
| 38 | + } | ||
| 39 | + | ||
| 40 | + [Test] | ||
| 41 | + public void ChangeTypeTest() | ||
| 42 | + { | ||
| 43 | + kt_document_version_history_response version_resp = this._kt.get_document_version_history(this._session, this._doc1.docId); | ||
| 44 | + Assert.AreEqual(0, version_resp.status_code); | ||
| 45 | + | ||
| 46 | + kt_document_transaction_history_response history_resp = this._kt.get_document_transaction_history(this._session, this._doc1.docId); | ||
| 47 | + Assert.AreEqual(0, history_resp.status_code); | ||
| 48 | + } | ||
| 49 | + } | ||
| 50 | +} |
ktwebservice/nunit/document_links.cs
0 โ 100644
| 1 | +using NUnit.Framework; | ||
| 2 | +using System; | ||
| 3 | +using System.IO; | ||
| 4 | + | ||
| 5 | +namespace MonoTests.KnowledgeTree | ||
| 6 | +{ | ||
| 7 | + | ||
| 8 | + | ||
| 9 | + [TestFixture] | ||
| 10 | + public class DocumentLinkTest | ||
| 11 | + { | ||
| 12 | + private String _session; | ||
| 13 | + private KnowledgeTreeService _kt; | ||
| 14 | + private int _folderId; | ||
| 15 | + private bool _verbose; | ||
| 16 | + private Document _doc1; | ||
| 17 | + private Document _doc2; | ||
| 18 | + | ||
| 19 | + | ||
| 20 | + [SetUp] | ||
| 21 | + public void SetUp() | ||
| 22 | + { | ||
| 23 | + this._kt = new KnowledgeTreeService(); | ||
| 24 | + kt_response response = this._kt.login("admin","admin","127.0.0.1"); | ||
| 25 | + this._session = response.message; | ||
| 26 | + | ||
| 27 | + this._folderId = 1; | ||
| 28 | + | ||
| 29 | + | ||
| 30 | + this._doc1 = new Document(1, this._session, this._kt, this._verbose, false); | ||
| 31 | + this._doc1.createFile(this._folderId); | ||
| 32 | + this._doc2 = new Document(2, this._session, this._kt, this._verbose, false); | ||
| 33 | + this._doc2.createFile(this._folderId); | ||
| 34 | + | ||
| 35 | + | ||
| 36 | + this._verbose = true; | ||
| 37 | + | ||
| 38 | + } | ||
| 39 | + | ||
| 40 | + [TearDown] | ||
| 41 | + public void TearDown() | ||
| 42 | + { | ||
| 43 | + this._doc1.deleteFile(); | ||
| 44 | + this._doc2.deleteFile(); | ||
| 45 | + | ||
| 46 | + this._kt.logout(this._session); | ||
| 47 | + | ||
| 48 | + } | ||
| 49 | + | ||
| 50 | + [Test] | ||
| 51 | + public void LinkingTest() | ||
| 52 | + { | ||
| 53 | + kt_linked_document_response linkresp = this._kt.get_document_links(this._session, this._doc1.docId); | ||
| 54 | + Assert.AreEqual(0, linkresp.status_code); | ||
| 55 | + Assert.AreEqual(null, linkresp.links); | ||
| 56 | + | ||
| 57 | + kt_response response = this._kt.link_documents(this._session, this._doc1.docId, this._doc2.docId, "Reference"); | ||
| 58 | + Assert.AreEqual(0, response.status_code); | ||
| 59 | + | ||
| 60 | + linkresp = this._kt.get_document_links(this._session, this._doc1.docId); | ||
| 61 | + Assert.AreEqual(0, linkresp.status_code); | ||
| 62 | + Assert.AreEqual(this._doc1.docId, linkresp.parent_document_id); | ||
| 63 | + Assert.AreEqual(1, linkresp.links.Length); | ||
| 64 | + Assert.AreEqual(this._doc2.docId, linkresp.links[0].document_id); | ||
| 65 | + | ||
| 66 | + response = this._kt.unlink_documents(this._session, this._doc1.docId, this._doc2.docId); | ||
| 67 | + Assert.AreEqual(0, response.status_code); | ||
| 68 | + | ||
| 69 | + linkresp = this._kt.get_document_links(this._session, this._doc1.docId); | ||
| 70 | + Assert.AreEqual(0, linkresp.status_code); | ||
| 71 | + Assert.AreEqual(null, linkresp.links); | ||
| 72 | + | ||
| 73 | + } | ||
| 74 | + | ||
| 75 | + | ||
| 76 | + } | ||
| 77 | +} |
ktwebservice/nunit/document_metadata.cs
0 โ 100644
| 1 | +using NUnit.Framework; | ||
| 2 | +using System; | ||
| 3 | +using System.IO; | ||
| 4 | + | ||
| 5 | +namespace MonoTests.KnowledgeTree | ||
| 6 | +{ | ||
| 7 | + [TestFixture] | ||
| 8 | + public class DocumentMetadataTest | ||
| 9 | + { | ||
| 10 | + private String _session; | ||
| 11 | + private KnowledgeTreeService _kt; | ||
| 12 | + private int _docId; | ||
| 13 | + private int _folderId; | ||
| 14 | + private String _filename; | ||
| 15 | + private String _content; | ||
| 16 | + private bool _verbose; | ||
| 17 | + | ||
| 18 | + | ||
| 19 | + [SetUp] | ||
| 20 | + public void SetUp() | ||
| 21 | + { | ||
| 22 | + this._kt = new KnowledgeTreeService(); | ||
| 23 | + | ||
| 24 | + kt_response response = this._kt.login("admin","admin","127.0.0.1"); | ||
| 25 | + this._session = response.message; | ||
| 26 | + | ||
| 27 | + this._filename = Helper.isUnix()?"/tmp/kt_unit_test1.txt":"c:\\kt_unit_test1.txt"; | ||
| 28 | + | ||
| 29 | + String filename = "kt unit test1"; | ||
| 30 | + | ||
| 31 | + this._content = "hello world!"; | ||
| 32 | + | ||
| 33 | + Helper.writeFile(this._filename, this._content); | ||
| 34 | + | ||
| 35 | + this._verbose = false; | ||
| 36 | + | ||
| 37 | + this._folderId = 1; | ||
| 38 | + | ||
| 39 | + kt_document_detail response1 = this._kt.add_base64_document(this._session, this._folderId, filename, this._filename, "Default", Helper.ConvertFileToBase64Encoding(this._filename)); | ||
| 40 | + | ||
| 41 | + if (this._verbose && response1.status_code != 0) | ||
| 42 | + { | ||
| 43 | + System.Console.WriteLine("Could not create file: " + this._filename); | ||
| 44 | + } | ||
| 45 | + this._docId = response1.document_id; | ||
| 46 | + | ||
| 47 | + | ||
| 48 | + } | ||
| 49 | + | ||
| 50 | + [TearDown] | ||
| 51 | + public void TearDown() | ||
| 52 | + { | ||
| 53 | + | ||
| 54 | + Helper.deleteFile(this._filename); | ||
| 55 | + | ||
| 56 | + kt_response response = this._kt.delete_document(this._session, this._docId, "Delete - cleaning up"); | ||
| 57 | + if (this._verbose && response.status_code != 0) | ||
| 58 | + { | ||
| 59 | + System.Console.WriteLine("Could not delete file: " + this._filename); | ||
| 60 | + } | ||
| 61 | + | ||
| 62 | + this._kt.logout(this._session); | ||
| 63 | + | ||
| 64 | + } | ||
| 65 | + | ||
| 66 | + [Test] | ||
| 67 | + public void GetDocumentTypesTest() | ||
| 68 | + { | ||
| 69 | + kt_document_types_response doc_types = this._kt.get_document_types(this._session); | ||
| 70 | + Assert.AreEqual(0, doc_types.status_code); | ||
| 71 | + } | ||
| 72 | + | ||
| 73 | + [Test] | ||
| 74 | + public void GetDocumentTypeMetadataTest() | ||
| 75 | + { | ||
| 76 | + | ||
| 77 | + kt_metadata_response metadata = this._kt.get_document_type_metadata(this._session, "Default"); | ||
| 78 | + Assert.AreEqual(0, metadata.status_code); | ||
| 79 | + } | ||
| 80 | + | ||
| 81 | + [Test] | ||
| 82 | + public void GetDocumentMetadataTest() | ||
| 83 | + { | ||
| 84 | + | ||
| 85 | + kt_metadata_response metadata = this._kt.get_document_metadata(this._session, this._docId); | ||
| 86 | + Assert.AreEqual(0, metadata.status_code); | ||
| 87 | + } | ||
| 88 | + | ||
| 89 | + [Test] | ||
| 90 | + public void UpdateDocumentMetadataTest() | ||
| 91 | + { | ||
| 92 | + kt_metadata_fieldset[] fs = new kt_metadata_fieldset[1]; | ||
| 93 | + fs[0] = new kt_metadata_fieldset(); | ||
| 94 | + fs[0].fieldset = "General information"; | ||
| 95 | + fs[0].fields = new kt_metadata_field[3]; | ||
| 96 | + fs[0].fields[0] = new kt_metadata_field(); | ||
| 97 | + fs[0].fields[0].name = "Document Author"; | ||
| 98 | + fs[0].fields[0].value = "Joe Soap"; | ||
| 99 | + fs[0].fields[1] = new kt_metadata_field(); | ||
| 100 | + fs[0].fields[1].name = "Category"; | ||
| 101 | + fs[0].fields[1].value = "Technical"; | ||
| 102 | + fs[0].fields[2] = new kt_metadata_field(); | ||
| 103 | + fs[0].fields[2].name = "Media Type"; | ||
| 104 | + fs[0].fields[2].value = "Text"; | ||
| 105 | + | ||
| 106 | + kt_sysdata_item[] sysdata = new kt_sysdata_item[0]; | ||
| 107 | + | ||
| 108 | + kt_document_detail update_resp = this._kt.update_document_metadata(this._session, this._docId, fs, sysdata); | ||
| 109 | + Assert.AreEqual(0, update_resp.status_code); | ||
| 110 | + Assert.AreEqual("General information", update_resp.metadata[1].fieldset); | ||
| 111 | + | ||
| 112 | + Assert.AreEqual("Document Author", update_resp.metadata[1].fields[0].name); | ||
| 113 | + Assert.AreEqual("Joe Soap", update_resp.metadata[1].fields[0].value); | ||
| 114 | + | ||
| 115 | + Assert.AreEqual("Category", update_resp.metadata[1].fields[1].name); | ||
| 116 | + Assert.AreEqual("Technical", update_resp.metadata[1].fields[1].value); | ||
| 117 | + | ||
| 118 | + Assert.AreEqual("Media Type", update_resp.metadata[1].fields[2].name); | ||
| 119 | + Assert.AreEqual("Text", update_resp.metadata[1].fields[2].value); | ||
| 120 | + | ||
| 121 | + | ||
| 122 | + } | ||
| 123 | + | ||
| 124 | + } | ||
| 125 | +} |
ktwebservice/nunit/document_owner.cs
0 โ 100644
| 1 | +using NUnit.Framework; | ||
| 2 | +using System; | ||
| 3 | +using System.IO; | ||
| 4 | + | ||
| 5 | +namespace MonoTests.KnowledgeTree | ||
| 6 | +{ | ||
| 7 | + [TestFixture] | ||
| 8 | + public class DocumentOwnerTest | ||
| 9 | + { | ||
| 10 | + private String _session; | ||
| 11 | + private KnowledgeTreeService _kt; | ||
| 12 | + private int _folderId; | ||
| 13 | + private bool _verbose; | ||
| 14 | + private Document _doc1; | ||
| 15 | + | ||
| 16 | + [SetUp] | ||
| 17 | + public void SetUp() | ||
| 18 | + { | ||
| 19 | + this._kt = new KnowledgeTreeService(); | ||
| 20 | + kt_response response = this._kt.login("admin","admin","127.0.0.1"); | ||
| 21 | + this._session = response.message; | ||
| 22 | + | ||
| 23 | + this._folderId = 1; | ||
| 24 | + | ||
| 25 | + | ||
| 26 | + this._doc1 = new Document(1, this._session, this._kt, this._verbose, false); | ||
| 27 | + this._doc1.createFile(this._folderId); | ||
| 28 | + | ||
| 29 | + this._verbose = true; | ||
| 30 | + | ||
| 31 | + } | ||
| 32 | + | ||
| 33 | + [TearDown] | ||
| 34 | + public void TearDown() | ||
| 35 | + { | ||
| 36 | + this._doc1.deleteFile(); | ||
| 37 | + | ||
| 38 | + this._kt.logout(this._session); | ||
| 39 | + | ||
| 40 | + } | ||
| 41 | + | ||
| 42 | + [Test] | ||
| 43 | + public void ChangeOwnerTest() | ||
| 44 | + { | ||
| 45 | + kt_document_detail response = this._kt.change_document_owner(this._session, this._doc1.docId, "anonymous", "just trying to change owner"); | ||
| 46 | + Assert.AreEqual(0, response.status_code); | ||
| 47 | + | ||
| 48 | + // test to non existant user | ||
| 49 | + response = this._kt.change_document_owner(this._session, this._doc1.docId, "blah", "just trying to change owner"); | ||
| 50 | + Assert.IsFalse(0 == response.status_code); | ||
| 51 | + } | ||
| 52 | + } | ||
| 53 | +} |
ktwebservice/nunit/document_rename.cs
0 โ 100644
| 1 | +using NUnit.Framework; | ||
| 2 | +using System; | ||
| 3 | +using System.IO; | ||
| 4 | + | ||
| 5 | +namespace MonoTests.KnowledgeTree | ||
| 6 | +{ | ||
| 7 | + [TestFixture] | ||
| 8 | + public class DocumentRenameTest | ||
| 9 | + { | ||
| 10 | + private String _session; | ||
| 11 | + private KnowledgeTreeService _kt; | ||
| 12 | + private int _folderId; | ||
| 13 | + private bool _verbose; | ||
| 14 | + private Document _doc1; | ||
| 15 | + | ||
| 16 | + [SetUp] | ||
| 17 | + public void SetUp() | ||
| 18 | + { | ||
| 19 | + this._kt = new KnowledgeTreeService(); | ||
| 20 | + kt_response response = this._kt.login("admin","admin","127.0.0.1"); | ||
| 21 | + this._session = response.message; | ||
| 22 | + | ||
| 23 | + this._folderId = 1; | ||
| 24 | + | ||
| 25 | + this._doc1 = new Document(1, this._session, this._kt, this._verbose,false); | ||
| 26 | + this._doc1.createFile(this._folderId); | ||
| 27 | + | ||
| 28 | + this._verbose = true; | ||
| 29 | + | ||
| 30 | + } | ||
| 31 | + | ||
| 32 | + [TearDown] | ||
| 33 | + public void TearDown() | ||
| 34 | + { | ||
| 35 | + this._doc1.deleteFile(); | ||
| 36 | + | ||
| 37 | + this._kt.logout(this._session); | ||
| 38 | + } | ||
| 39 | + | ||
| 40 | + [Test] | ||
| 41 | + public void RenameTest() | ||
| 42 | + { | ||
| 43 | + kt_document_detail response = this._kt.rename_document_filename(this._session, this._doc1.docId, "test fname"); | ||
| 44 | + Assert.AreEqual(0, response.status_code); | ||
| 45 | + Assert.AreEqual("test fname", response.filename); | ||
| 46 | + | ||
| 47 | + response = this._kt.rename_document_title(this._session, this._doc1.docId, "test title"); | ||
| 48 | + Assert.AreEqual(0, response.status_code); | ||
| 49 | + Assert.AreEqual("test title", response.title); | ||
| 50 | + } | ||
| 51 | + } | ||
| 52 | +} |
ktwebservice/nunit/document_system_metadata.cs
0 โ 100644
| 1 | +using NUnit.Framework; | ||
| 2 | +using System; | ||
| 3 | +using System.IO; | ||
| 4 | + | ||
| 5 | +namespace MonoTests.KnowledgeTree | ||
| 6 | +{ | ||
| 7 | + | ||
| 8 | + | ||
| 9 | + [TestFixture] | ||
| 10 | + public class DocumentSystemMetadataTest | ||
| 11 | + { | ||
| 12 | + private String _session; | ||
| 13 | + private KnowledgeTreeService _kt; | ||
| 14 | + private int _folderId; | ||
| 15 | + private bool _verbose; | ||
| 16 | + private Document _doc1; | ||
| 17 | + private Document _doc2; | ||
| 18 | + | ||
| 19 | + | ||
| 20 | + [SetUp] | ||
| 21 | + public void SetUp() | ||
| 22 | + { | ||
| 23 | + this._kt = new KnowledgeTreeService(); | ||
| 24 | + kt_response response = this._kt.login("admin","admin","127.0.0.1"); | ||
| 25 | + this._session = response.message; | ||
| 26 | + | ||
| 27 | + this._folderId = 1; | ||
| 28 | + | ||
| 29 | + | ||
| 30 | + this._doc1 = new Document(1, this._session, this._kt, this._verbose,false); | ||
| 31 | + this._doc1.createFile(this._folderId); | ||
| 32 | + this._doc2 = new Document(2, this._session, this._kt, this._verbose,true); | ||
| 33 | + | ||
| 34 | + | ||
| 35 | + this._verbose = true; | ||
| 36 | + | ||
| 37 | + } | ||
| 38 | + | ||
| 39 | + [TearDown] | ||
| 40 | + public void TearDown() | ||
| 41 | + { | ||
| 42 | + this._doc1.deleteFile(); | ||
| 43 | + this._doc2.deleteFile(); | ||
| 44 | + | ||
| 45 | + this._kt.logout(this._session); | ||
| 46 | + | ||
| 47 | + } | ||
| 48 | + | ||
| 49 | + [Test] | ||
| 50 | + public void UpdateDocumentMetadataTest() | ||
| 51 | + { | ||
| 52 | + | ||
| 53 | + kt_metadata_fieldset[] fs = new kt_metadata_fieldset[1]; | ||
| 54 | + fs[0] = new kt_metadata_fieldset(); | ||
| 55 | + fs[0].fieldset = "General information"; | ||
| 56 | + fs[0].fields = new kt_metadata_field[3]; | ||
| 57 | + fs[0].fields[0] = new kt_metadata_field(); | ||
| 58 | + fs[0].fields[0].name = "Document Author"; | ||
| 59 | + fs[0].fields[0].value = "Joe Soap"; | ||
| 60 | + fs[0].fields[1] = new kt_metadata_field(); | ||
| 61 | + fs[0].fields[1].name = "Category"; | ||
| 62 | + fs[0].fields[1].value = "Technical"; | ||
| 63 | + fs[0].fields[2] = new kt_metadata_field(); | ||
| 64 | + fs[0].fields[2].name = "Media Type"; | ||
| 65 | + fs[0].fields[2].value = "Text"; | ||
| 66 | + | ||
| 67 | + kt_sysdata_item[] sysdata = new kt_sysdata_item[2]; | ||
| 68 | + sysdata[0] = new kt_sysdata_item(); | ||
| 69 | + sysdata[0].name = "created_by"; | ||
| 70 | + sysdata[0].value = "Anonymous"; | ||
| 71 | + sysdata[1] = new kt_sysdata_item(); | ||
| 72 | + sysdata[1].name = "created_date"; | ||
| 73 | + sysdata[1].value = "2007-01-17"; | ||
| 74 | + | ||
| 75 | + | ||
| 76 | + kt_document_detail update_resp = this._kt.update_document_metadata(this._session, this._doc1.docId, fs, sysdata); | ||
| 77 | + Assert.AreEqual(0, update_resp.status_code); | ||
| 78 | + Assert.AreEqual("General information", update_resp.metadata[1].fieldset); | ||
| 79 | + | ||
| 80 | + Assert.AreEqual("Document Author", update_resp.metadata[1].fields[0].name); | ||
| 81 | + Assert.AreEqual("Joe Soap", update_resp.metadata[1].fields[0].value); | ||
| 82 | + | ||
| 83 | + Assert.AreEqual("Category", update_resp.metadata[1].fields[1].name); | ||
| 84 | + Assert.AreEqual("Technical", update_resp.metadata[1].fields[1].value); | ||
| 85 | + | ||
| 86 | + Assert.AreEqual("Media Type", update_resp.metadata[1].fields[2].name); | ||
| 87 | + Assert.AreEqual("Text", update_resp.metadata[1].fields[2].value); | ||
| 88 | + | ||
| 89 | + Assert.AreEqual("Anonymous", update_resp.created_by); | ||
| 90 | + Assert.AreEqual("2007-01-17 00:00:00", update_resp.created_date); | ||
| 91 | + } | ||
| 92 | + | ||
| 93 | + [Test] | ||
| 94 | + public void AddSmallDocumentWithMetadataTest() | ||
| 95 | + { | ||
| 96 | + kt_metadata_fieldset[] fs = new kt_metadata_fieldset[1]; | ||
| 97 | + fs[0] = new kt_metadata_fieldset(); | ||
| 98 | + fs[0].fieldset = "General information"; | ||
| 99 | + fs[0].fields = new kt_metadata_field[3]; | ||
| 100 | + fs[0].fields[0] = new kt_metadata_field(); | ||
| 101 | + fs[0].fields[0].name = "Document Author"; | ||
| 102 | + fs[0].fields[0].value = "Joe Soap"; | ||
| 103 | + fs[0].fields[1] = new kt_metadata_field(); | ||
| 104 | + fs[0].fields[1].name = "Category"; | ||
| 105 | + fs[0].fields[1].value = "Technical"; | ||
| 106 | + fs[0].fields[2] = new kt_metadata_field(); | ||
| 107 | + fs[0].fields[2].name = "Media Type"; | ||
| 108 | + fs[0].fields[2].value = "Text"; | ||
| 109 | + | ||
| 110 | + kt_sysdata_item[] sysdata = new kt_sysdata_item[2]; | ||
| 111 | + sysdata[0] = new kt_sysdata_item(); | ||
| 112 | + sysdata[0].name = "created_by"; | ||
| 113 | + sysdata[0].value = "Anonymous"; | ||
| 114 | + sysdata[1] = new kt_sysdata_item(); | ||
| 115 | + sysdata[1].name = "created_date"; | ||
| 116 | + sysdata[1].value = "2007-01-17"; | ||
| 117 | + | ||
| 118 | + this._doc2.local=false; | ||
| 119 | + kt_document_detail update_resp = this._doc2.createFileWithMetadata(this._folderId, fs, sysdata); | ||
| 120 | + | ||
| 121 | + Assert.AreEqual(0, update_resp.status_code); | ||
| 122 | + Assert.AreEqual("General information", update_resp.metadata[1].fieldset); | ||
| 123 | + | ||
| 124 | + Assert.AreEqual("Document Author", update_resp.metadata[1].fields[0].name); | ||
| 125 | + Assert.AreEqual("Joe Soap", update_resp.metadata[1].fields[0].value); | ||
| 126 | + | ||
| 127 | + Assert.AreEqual("Category", update_resp.metadata[1].fields[1].name); | ||
| 128 | + Assert.AreEqual("Technical", update_resp.metadata[1].fields[1].value); | ||
| 129 | + | ||
| 130 | + Assert.AreEqual("Media Type", update_resp.metadata[1].fields[2].name); | ||
| 131 | + Assert.AreEqual("Text", update_resp.metadata[1].fields[2].value); | ||
| 132 | + | ||
| 133 | + Assert.AreEqual("Anonymous", update_resp.created_by); | ||
| 134 | + Assert.AreEqual("2007-01-17 00:00:00", update_resp.created_date); | ||
| 135 | + } | ||
| 136 | + | ||
| 137 | + [Test] | ||
| 138 | + public void CheckinSmallDocumentWithMetadataTest() | ||
| 139 | + { | ||
| 140 | + kt_metadata_fieldset[] fs = new kt_metadata_fieldset[1]; | ||
| 141 | + fs[0] = new kt_metadata_fieldset(); | ||
| 142 | + fs[0].fieldset = "General information"; | ||
| 143 | + fs[0].fields = new kt_metadata_field[3]; | ||
| 144 | + fs[0].fields[0] = new kt_metadata_field(); | ||
| 145 | + fs[0].fields[0].name = "Document Author"; | ||
| 146 | + fs[0].fields[0].value = "Joe Soap"; | ||
| 147 | + fs[0].fields[1] = new kt_metadata_field(); | ||
| 148 | + fs[0].fields[1].name = "Category"; | ||
| 149 | + fs[0].fields[1].value = "Technical"; | ||
| 150 | + fs[0].fields[2] = new kt_metadata_field(); | ||
| 151 | + fs[0].fields[2].name = "Media Type"; | ||
| 152 | + fs[0].fields[2].value = "Text"; | ||
| 153 | + | ||
| 154 | + kt_sysdata_item[] sysdata = new kt_sysdata_item[2]; | ||
| 155 | + sysdata[0] = new kt_sysdata_item(); | ||
| 156 | + sysdata[0].name = "created_by"; | ||
| 157 | + sysdata[0].value = "Anonymous"; | ||
| 158 | + sysdata[1] = new kt_sysdata_item(); | ||
| 159 | + sysdata[1].name = "created_date"; | ||
| 160 | + sysdata[1].value = "2007-01-17"; | ||
| 161 | + | ||
| 162 | + kt_response resp = this._kt.checkout_base64_document(this._session, this._doc1.docId, "test checkin", false); | ||
| 163 | + Assert.AreEqual(0, resp.status_code); | ||
| 164 | + | ||
| 165 | + | ||
| 166 | + | ||
| 167 | + kt_document_detail update_resp = this._doc1.checkinFileWithMetadata(this._folderId, fs, sysdata); | ||
| 168 | + | ||
| 169 | + Assert.AreEqual(0, update_resp.status_code); | ||
| 170 | + Assert.AreEqual("General information", update_resp.metadata[1].fieldset); | ||
| 171 | + | ||
| 172 | + Assert.AreEqual("Document Author", update_resp.metadata[1].fields[0].name); | ||
| 173 | + Assert.AreEqual("Joe Soap", update_resp.metadata[1].fields[0].value); | ||
| 174 | + | ||
| 175 | + Assert.AreEqual("Category", update_resp.metadata[1].fields[1].name); | ||
| 176 | + Assert.AreEqual("Technical", update_resp.metadata[1].fields[1].value); | ||
| 177 | + | ||
| 178 | + Assert.AreEqual("Media Type", update_resp.metadata[1].fields[2].name); | ||
| 179 | + Assert.AreEqual("Text", update_resp.metadata[1].fields[2].value); | ||
| 180 | + | ||
| 181 | + Assert.AreEqual("Anonymous", update_resp.created_by); | ||
| 182 | + Assert.AreEqual("2007-01-17 00:00:00", update_resp.created_date); | ||
| 183 | + } | ||
| 184 | + | ||
| 185 | + | ||
| 186 | + } | ||
| 187 | +} |
ktwebservice/nunit/document_type.cs
0 โ 100644
| 1 | +using NUnit.Framework; | ||
| 2 | +using System; | ||
| 3 | +using System.IO; | ||
| 4 | + | ||
| 5 | +namespace MonoTests.KnowledgeTree | ||
| 6 | +{ | ||
| 7 | + [TestFixture] | ||
| 8 | + public class DocumentOwnerTest | ||
| 9 | + { | ||
| 10 | + private String _session; | ||
| 11 | + private KnowledgeTreeService _kt; | ||
| 12 | + private int _folderId; | ||
| 13 | + private bool _verbose; | ||
| 14 | + private Document _doc1; | ||
| 15 | + | ||
| 16 | + [SetUp] | ||
| 17 | + public void SetUp() | ||
| 18 | + { | ||
| 19 | + this._kt = new KnowledgeTreeService(); | ||
| 20 | + kt_response response = this._kt.login("admin","admin","127.0.0.1"); | ||
| 21 | + this._session = response.message; | ||
| 22 | + | ||
| 23 | + this._folderId = 1; | ||
| 24 | + | ||
| 25 | + | ||
| 26 | + this._doc1 = new Document(1, this._session, this._kt, this._verbose,false); | ||
| 27 | + this._doc1.createFile(this._folderId); | ||
| 28 | + | ||
| 29 | + this._verbose = true; | ||
| 30 | + | ||
| 31 | + } | ||
| 32 | + | ||
| 33 | + [TearDown] | ||
| 34 | + public void TearDown() | ||
| 35 | + { | ||
| 36 | + this._doc1.deleteFile(); | ||
| 37 | + | ||
| 38 | + this._kt.logout(this._session); | ||
| 39 | + | ||
| 40 | + } | ||
| 41 | + | ||
| 42 | + [Test] | ||
| 43 | + public void ChangeTypeTest() | ||
| 44 | + { | ||
| 45 | + // NOTE: Create the following type 'NewType' via the admin pages | ||
| 46 | + | ||
| 47 | + kt_document_detail response = this._kt.change_document_type(this._session, this._doc1.docId, "NewType"); | ||
| 48 | + Assert.AreEqual(0, response.status_code); | ||
| 49 | + if (0 != response.status_code) | ||
| 50 | + { | ||
| 51 | + System.Console.WriteLine("Please check that the document type 'NewType' exists in the database! This test should pass if it exists!"); | ||
| 52 | + System.Console.WriteLine("SQL: insert into document_types_lookup(name) values('NewType');"); | ||
| 53 | + } | ||
| 54 | + | ||
| 55 | + // NOTE: we need to test with an unknown type as well | ||
| 56 | + | ||
| 57 | + response = this._kt.change_document_type(this._session, this._doc1.docId, "UnknownType"); | ||
| 58 | + Assert.IsTrue(0 != response.status_code); | ||
| 59 | + | ||
| 60 | + } | ||
| 61 | + } | ||
| 62 | +} |
ktwebservice/nunit/document_workflow.cs
0 โ 100644
| 1 | +using NUnit.Framework; | ||
| 2 | +using System; | ||
| 3 | +using System.IO; | ||
| 4 | + | ||
| 5 | +namespace MonoTests.KnowledgeTree | ||
| 6 | +{ | ||
| 7 | + [TestFixture] | ||
| 8 | + public class WorkflowTest | ||
| 9 | + { | ||
| 10 | + private String _session; | ||
| 11 | + private KnowledgeTreeService _kt; | ||
| 12 | + private int _folderId; | ||
| 13 | + private bool _verbose; | ||
| 14 | + private Document _doc1; | ||
| 15 | + | ||
| 16 | + [SetUp] | ||
| 17 | + public void SetUp() | ||
| 18 | + { | ||
| 19 | + this._kt = new KnowledgeTreeService(); | ||
| 20 | + kt_response response = this._kt.login("admin","admin","127.0.0.1"); | ||
| 21 | + this._session = response.message; | ||
| 22 | + | ||
| 23 | + this._folderId = 1; | ||
| 24 | + | ||
| 25 | + | ||
| 26 | + this._doc1 = new Document(1, this._session, this._kt, this._verbose, false); | ||
| 27 | + this._doc1.createFile(this._folderId); | ||
| 28 | + | ||
| 29 | + this._verbose = true; | ||
| 30 | + } | ||
| 31 | + | ||
| 32 | + [TearDown] | ||
| 33 | + public void TearDown() | ||
| 34 | + { | ||
| 35 | + this._doc1.deleteFile(); | ||
| 36 | + this._kt.logout(this._session); | ||
| 37 | + } | ||
| 38 | + | ||
| 39 | + [Test] | ||
| 40 | + public void NonExistantWorkflowTest() | ||
| 41 | + { | ||
| 42 | + kt_document_detail response = this._kt.start_document_workflow(this._session, this._doc1.docId, "Non Existant Workflow"); | ||
| 43 | + Assert.IsTrue(0 != response.status_code); | ||
| 44 | + } | ||
| 45 | + | ||
| 46 | + [Test] | ||
| 47 | + public void StartWorkflowTest() | ||
| 48 | + { | ||
| 49 | + kt_document_detail response = this._kt.start_document_workflow(this._session, this._doc1.docId, "Review Process"); | ||
| 50 | + Assert.AreEqual(0, response.status_code); | ||
| 51 | + Assert.AreEqual("Review Process", response.workflow); | ||
| 52 | + } | ||
| 53 | + | ||
| 54 | + [Test] | ||
| 55 | + public void StopWorkflowTest() | ||
| 56 | + { | ||
| 57 | + kt_document_detail response = this._kt.start_document_workflow(this._session, this._doc1.docId, "Review Process"); | ||
| 58 | + Assert.AreEqual(0, response.status_code); | ||
| 59 | + Assert.AreEqual("Review Process", response.workflow); | ||
| 60 | + | ||
| 61 | + response = this._kt.delete_document_workflow(this._session, this._doc1.docId); | ||
| 62 | + Assert.AreEqual(0, response.status_code); | ||
| 63 | + Assert.AreEqual("n/a", response.workflow); | ||
| 64 | + } | ||
| 65 | + | ||
| 66 | + [Test] | ||
| 67 | + public void GetTransitionsTest() | ||
| 68 | + { | ||
| 69 | + kt_document_detail response = this._kt.start_document_workflow(this._session, this._doc1.docId, "Review Process"); | ||
| 70 | + Assert.AreEqual(0, response.status_code); | ||
| 71 | + Assert.AreEqual("Review Process", response.workflow); | ||
| 72 | + | ||
| 73 | + kt_workflow_transitions_response trans_resp = this._kt.get_document_workflow_transitions(this._session, this._doc1.docId); | ||
| 74 | + Assert.AreEqual(0, trans_resp.status_code); | ||
| 75 | + Assert.AreEqual(1, trans_resp.transitions.Length); | ||
| 76 | + Assert.AreEqual("Request Approval", trans_resp.transitions[0]); | ||
| 77 | + } | ||
| 78 | + | ||
| 79 | + [Test] | ||
| 80 | + public void WorkflowTransitionTest() | ||
| 81 | + { | ||
| 82 | + kt_document_detail response = this._kt.start_document_workflow(this._session, this._doc1.docId, "Review Process"); | ||
| 83 | + Assert.AreEqual(0, response.status_code); | ||
| 84 | + Assert.AreEqual("Review Process", response.workflow); | ||
| 85 | + Assert.AreEqual("Draft", response.workflow_state); | ||
| 86 | + | ||
| 87 | + response = this._kt.perform_document_workflow_transition(this._session, this._doc1.docId, "Request Approval", "Please approve me"); | ||
| 88 | + Assert.AreEqual(0, response.status_code); | ||
| 89 | + Assert.AreEqual("Review Process", response.workflow); | ||
| 90 | + Assert.AreEqual("Approval", response.workflow_state); | ||
| 91 | + | ||
| 92 | + response = this._kt.perform_document_workflow_transition(this._session, this._doc1.docId, "Approve", "Ok!"); | ||
| 93 | + Assert.AreEqual(0, response.status_code); | ||
| 94 | + Assert.AreEqual("Review Process", response.workflow); | ||
| 95 | + Assert.AreEqual("Published", response.workflow_state); | ||
| 96 | + } | ||
| 97 | + } | ||
| 98 | +} |
ktwebservice/nunit/folder.cs
| @@ -3,39 +3,36 @@ using System; | @@ -3,39 +3,36 @@ using System; | ||
| 3 | using System.IO; | 3 | using System.IO; |
| 4 | 4 | ||
| 5 | namespace MonoTests.KnowledgeTree | 5 | namespace MonoTests.KnowledgeTree |
| 6 | -{ | 6 | +{ |
| 7 | [TestFixture] | 7 | [TestFixture] |
| 8 | - public class FolderTest | 8 | + public class FolderTest |
| 9 | { | 9 | { |
| 10 | - | 10 | + |
| 11 | private String _session; | 11 | private String _session; |
| 12 | private KnowledgeTreeService _kt; | 12 | private KnowledgeTreeService _kt; |
| 13 | private int _folder_id; | 13 | private int _folder_id; |
| 14 | private int _subfolder_id; | 14 | private int _subfolder_id; |
| 15 | - private bool _skip; | ||
| 16 | - | 15 | + |
| 17 | [SetUp] | 16 | [SetUp] |
| 18 | - public void SetUp() | 17 | + public void SetUp() |
| 19 | { | 18 | { |
| 20 | - this._skip = true; | ||
| 21 | - if (this._skip) return; | ||
| 22 | - this._kt = new KnowledgeTreeService(); | 19 | + this._kt = new KnowledgeTreeService(); |
| 23 | kt_response response = this._kt.login("admin","admin","127.0.0.1"); | 20 | kt_response response = this._kt.login("admin","admin","127.0.0.1"); |
| 24 | - this._session = response.message; | ||
| 25 | - | 21 | + this._session = response.message; |
| 22 | + | ||
| 26 | } | 23 | } |
| 27 | 24 | ||
| 28 | [TearDown] | 25 | [TearDown] |
| 29 | - public void TearDown() | 26 | + public void TearDown() |
| 30 | { | 27 | { |
| 31 | - if (this._skip) return; | 28 | + |
| 32 | this._kt.logout(this._session); | 29 | this._kt.logout(this._session); |
| 33 | } | 30 | } |
| 34 | - | 31 | + |
| 35 | [Test] | 32 | [Test] |
| 36 | - public void GetFolderDetail() | 33 | + public void GetFolderDetail() |
| 37 | { | 34 | { |
| 38 | - if (this._skip) return; | 35 | + |
| 39 | kt_folder_detail response = this._kt.get_folder_detail(this._session, 1); | 36 | kt_folder_detail response = this._kt.get_folder_detail(this._session, 1); |
| 40 | Assert.AreEqual(0, response.status_code); | 37 | Assert.AreEqual(0, response.status_code); |
| 41 | Assert.AreEqual(1, response.id); | 38 | Assert.AreEqual(1, response.id); |
| @@ -43,49 +40,49 @@ namespace MonoTests.KnowledgeTree | @@ -43,49 +40,49 @@ namespace MonoTests.KnowledgeTree | ||
| 43 | Assert.AreEqual(0, response.parent_id); | 40 | Assert.AreEqual(0, response.parent_id); |
| 44 | Assert.AreEqual("/Root Folder", response.full_path); // ??? DOESNT SEEM CONSISTENT - should be 'Root Filder' | 41 | Assert.AreEqual("/Root Folder", response.full_path); // ??? DOESNT SEEM CONSISTENT - should be 'Root Filder' |
| 45 | } | 42 | } |
| 46 | - | 43 | + |
| 47 | [Test] | 44 | [Test] |
| 48 | - public void AddFolder() | 45 | + public void AddFolder() |
| 49 | { | 46 | { |
| 50 | - if (this._skip) return; | 47 | + |
| 51 | kt_folder_detail response = this._kt.create_folder(this._session, 1, "kt_unit_test"); | 48 | kt_folder_detail response = this._kt.create_folder(this._session, 1, "kt_unit_test"); |
| 52 | Assert.AreEqual(0,response.status_code); | 49 | Assert.AreEqual(0,response.status_code); |
| 53 | - | 50 | + |
| 54 | this._folder_id = response.id; | 51 | this._folder_id = response.id; |
| 55 | - | 52 | + |
| 56 | response = this._kt.create_folder(this._session, this._folder_id, "subfolder"); | 53 | response = this._kt.create_folder(this._session, this._folder_id, "subfolder"); |
| 57 | Assert.AreEqual(0,response.status_code); | 54 | Assert.AreEqual(0,response.status_code); |
| 58 | - | 55 | + |
| 59 | this._subfolder_id = response.id; | 56 | this._subfolder_id = response.id; |
| 60 | - | ||
| 61 | - } | 57 | + |
| 58 | + } | ||
| 62 | 59 | ||
| 63 | [Test] | 60 | [Test] |
| 64 | - public void GetFolderByName() | 61 | + public void GetFolderByName() |
| 65 | { | 62 | { |
| 66 | - if (this._skip) return; | 63 | + |
| 67 | kt_folder_detail response = this._kt.get_folder_detail_by_name(this._session, "/kt_unit_test"); | 64 | kt_folder_detail response = this._kt.get_folder_detail_by_name(this._session, "/kt_unit_test"); |
| 68 | Assert.AreEqual(0,response.status_code); | 65 | Assert.AreEqual(0,response.status_code); |
| 69 | - Assert.AreEqual(this._folder_id, response.id); | 66 | + Assert.AreEqual(this._folder_id, response.id); |
| 70 | 67 | ||
| 71 | response = this._kt.get_folder_detail_by_name(this._session, "kt_unit_test"); | 68 | response = this._kt.get_folder_detail_by_name(this._session, "kt_unit_test"); |
| 72 | Assert.AreEqual(0,response.status_code); | 69 | Assert.AreEqual(0,response.status_code); |
| 73 | - Assert.AreEqual(this._folder_id, response.id); | 70 | + Assert.AreEqual(this._folder_id, response.id); |
| 74 | 71 | ||
| 75 | response = this._kt.get_folder_detail_by_name(this._session, "kt_unit_test/subfolder"); | 72 | response = this._kt.get_folder_detail_by_name(this._session, "kt_unit_test/subfolder"); |
| 76 | Assert.AreEqual(0,response.status_code); | 73 | Assert.AreEqual(0,response.status_code); |
| 77 | - Assert.AreEqual(this._subfolder_id,response.id); | 74 | + Assert.AreEqual(this._subfolder_id,response.id); |
| 78 | 75 | ||
| 79 | response = this._kt.get_folder_detail_by_name(this._session, "kt_unit_test/subfolder2"); | 76 | response = this._kt.get_folder_detail_by_name(this._session, "kt_unit_test/subfolder2"); |
| 80 | Assert.IsFalse(response.status_code == 0); | 77 | Assert.IsFalse(response.status_code == 0); |
| 81 | - | 78 | + |
| 82 | 79 | ||
| 83 | } | 80 | } |
| 84 | - | 81 | + |
| 85 | [Test] | 82 | [Test] |
| 86 | - public void GetFolderContents() | 83 | + public void GetFolderContents() |
| 87 | { | 84 | { |
| 88 | - if (this._skip) return; | 85 | + |
| 89 | kt_folder_contents response = this._kt.get_folder_contents(this._session, this._folder_id, 1, "DF"); | 86 | kt_folder_contents response = this._kt.get_folder_contents(this._session, this._folder_id, 1, "DF"); |
| 90 | Assert.AreEqual(0,response.status_code); | 87 | Assert.AreEqual(0,response.status_code); |
| 91 | Assert.AreEqual(this._folder_id,response.folder_id); | 88 | Assert.AreEqual(this._folder_id,response.folder_id); |
| @@ -98,45 +95,29 @@ namespace MonoTests.KnowledgeTree | @@ -98,45 +95,29 @@ namespace MonoTests.KnowledgeTree | ||
| 98 | Assert.AreEqual("subfolder", response2.folder_name); | 95 | Assert.AreEqual("subfolder", response2.folder_name); |
| 99 | Assert.AreEqual("Root Folder/kt_unit_test/subfolder", response2.full_path); | 96 | Assert.AreEqual("Root Folder/kt_unit_test/subfolder", response2.full_path); |
| 100 | } | 97 | } |
| 101 | - | 98 | + |
| 102 | [Test] | 99 | [Test] |
| 103 | - public void RenameFolder() | 100 | + public void RenameFolder() |
| 104 | { | 101 | { |
| 105 | - if (this._skip) return; | 102 | + |
| 106 | kt_response response = this._kt.rename_folder(this._session, this._subfolder_id, "subfolder2"); | 103 | kt_response response = this._kt.rename_folder(this._session, this._subfolder_id, "subfolder2"); |
| 107 | Assert.AreEqual(0, response.status_code); | 104 | Assert.AreEqual(0, response.status_code); |
| 108 | - | 105 | + |
| 109 | kt_folder_detail response2 = this._kt.get_folder_detail(this._session, this._subfolder_id); | 106 | kt_folder_detail response2 = this._kt.get_folder_detail(this._session, this._subfolder_id); |
| 110 | Assert.AreEqual(0, response2.status_code); | 107 | Assert.AreEqual(0, response2.status_code); |
| 111 | Assert.AreEqual(this._subfolder_id, response2.id); | 108 | Assert.AreEqual(this._subfolder_id, response2.id); |
| 112 | Assert.AreEqual("subfolder2", response2.folder_name); | 109 | Assert.AreEqual("subfolder2", response2.folder_name); |
| 113 | Assert.AreEqual(this._folder_id, response2.parent_id); | 110 | Assert.AreEqual(this._folder_id, response2.parent_id); |
| 114 | - Assert.AreEqual("Root Folder/kt_unit_test/subfolder2", response2.full_path); | ||
| 115 | - } | 111 | + Assert.AreEqual("Root Folder/kt_unit_test/subfolder2", response2.full_path); |
| 112 | + } | ||
| 116 | 113 | ||
| 117 | [Test] | 114 | [Test] |
| 118 | - public void CopyFolder() | ||
| 119 | - { | ||
| 120 | - if (this._skip) return; | ||
| 121 | - // TODO copy | ||
| 122 | - // | ||
| 123 | - } | ||
| 124 | - | ||
| 125 | - [Test] | ||
| 126 | - public void MoveFolder() | 115 | + public void RemoveFolder() |
| 127 | { | 116 | { |
| 128 | - if (this._skip) return; | ||
| 129 | - // TODO move | ||
| 130 | - // | ||
| 131 | - } | ||
| 132 | 117 | ||
| 133 | - [Test] | ||
| 134 | - public void RemoveFolder() | ||
| 135 | - { | ||
| 136 | - if (this._skip) return; | ||
| 137 | kt_response response = this._kt.delete_folder(this._session, this._folder_id, "unit testing remove"); | 118 | kt_response response = this._kt.delete_folder(this._session, this._folder_id, "unit testing remove"); |
| 138 | Assert.AreEqual(0, response.status_code); | 119 | Assert.AreEqual(0, response.status_code); |
| 139 | - } | 120 | + } |
| 140 | 121 | ||
| 141 | } | 122 | } |
| 142 | } | 123 | } |
ktwebservice/nunit/helper.cs
0 โ 100755
| 1 | +using System; | ||
| 2 | +using System.Text; | ||
| 3 | +using System.Net; | ||
| 4 | +using System.IO; | ||
| 5 | + | ||
| 6 | +namespace MonoTests.KnowledgeTree | ||
| 7 | +{ | ||
| 8 | + public class FileUploader | ||
| 9 | + { | ||
| 10 | + private String boundary; | ||
| 11 | + private String uri; | ||
| 12 | + private String filename; | ||
| 13 | + | ||
| 14 | + | ||
| 15 | + public FileUploader(String uri) | ||
| 16 | + { | ||
| 17 | + this.uri = uri; | ||
| 18 | + this.boundary = "----" + DateTime.Now.Ticks.ToString("x"); | ||
| 19 | + } | ||
| 20 | + | ||
| 21 | + public String getFilename() | ||
| 22 | + { | ||
| 23 | + return this.filename; | ||
| 24 | + } | ||
| 25 | + | ||
| 26 | + | ||
| 27 | + public void upload(String sessionid, String filename) | ||
| 28 | + { | ||
| 29 | + String displayname = Path.GetFileName(filename); | ||
| 30 | + StringBuilder header = new StringBuilder(); | ||
| 31 | + | ||
| 32 | + header.Append("--" + boundary + "\r\n" + "Content-Disposition: form-data; name=\"session_id\"\r\n\r\n" + sessionid + "\r\n"); | ||
| 33 | + header.Append("--" + boundary + "\r\n" + "Content-Disposition: form-data; name=\"action\"\r\n\r\nA\r\n"); | ||
| 34 | + header.Append("--" + boundary + "\r\n" + "Content-Disposition: form-data; name=\"output\"\r\n\r\nxml\r\n"); | ||
| 35 | + | ||
| 36 | + header.Append("--" + boundary + "\r\n"); | ||
| 37 | + header.Append("Content-Disposition: form-data; name=\"name\";"); | ||
| 38 | + header.Append("filename=\"" + displayname + "\"\r\nContent-Type: application/octet-stream\r\n\r\n"); | ||
| 39 | + | ||
| 40 | + | ||
| 41 | + HttpWebRequest webrequest = (HttpWebRequest)WebRequest.Create(this.uri); | ||
| 42 | + webrequest.ContentType = "multipart/form-data; boundary=" + boundary; | ||
| 43 | + webrequest.Method = "POST"; | ||
| 44 | + | ||
| 45 | + | ||
| 46 | + byte[] headerArray = Encoding.UTF8.GetBytes(header.ToString()); | ||
| 47 | + byte[] boundaryArray = Encoding.ASCII.GetBytes("\r\n--" + boundary + "\r\n"); | ||
| 48 | + | ||
| 49 | + FileStream file = new FileStream(filename, System.IO.FileMode.Open, System.IO.FileAccess.Read); | ||
| 50 | + | ||
| 51 | + long filesize = file.Length; | ||
| 52 | + webrequest.ContentLength = headerArray.Length + filesize + boundaryArray.Length; | ||
| 53 | + | ||
| 54 | + Stream requestStream = webrequest.GetRequestStream(); | ||
| 55 | + requestStream.Write(headerArray, 0, headerArray.Length); | ||
| 56 | + | ||
| 57 | + byte[] buffer = new byte[10240]; | ||
| 58 | + | ||
| 59 | + int read = 0; | ||
| 60 | + | ||
| 61 | + while ((read = file.Read(buffer, 0, buffer.Length)) > 0) | ||
| 62 | + { | ||
| 63 | + | ||
| 64 | + requestStream.Write(buffer, 0, read); | ||
| 65 | + } | ||
| 66 | + | ||
| 67 | + requestStream.Write(boundaryArray, 0, boundaryArray.Length); | ||
| 68 | + | ||
| 69 | + | ||
| 70 | + WebResponse response = webrequest.GetResponse(); | ||
| 71 | + StreamReader sr = new StreamReader(response.GetResponseStream()); | ||
| 72 | + String xml = sr.ReadToEnd(); | ||
| 73 | + //System.Console.WriteLine("xml: " + xml); | ||
| 74 | + | ||
| 75 | + | ||
| 76 | + | ||
| 77 | + if (xml.IndexOf("<status_code>0</status_code>") != -1) | ||
| 78 | + { | ||
| 79 | + long tmp = this.tokenInt("filesize",xml); | ||
| 80 | + if (tmp != filesize) | ||
| 81 | + { | ||
| 82 | + throw new Exception("Filesize should be " + filesize + " but appears to be "+ tmp); | ||
| 83 | + } | ||
| 84 | + | ||
| 85 | + tmp = this.tokenInt("error",xml); | ||
| 86 | + if (tmp > 0) | ||
| 87 | + { | ||
| 88 | + throw new Exception("The server reported error code " + tmp + " for the file upload"); | ||
| 89 | + } | ||
| 90 | + this.filename = this.tokenString("filename",xml); | ||
| 91 | + // yay, all is good! | ||
| 92 | + return; | ||
| 93 | + } | ||
| 94 | + | ||
| 95 | + String msg = this.tokenString("msg", xml); | ||
| 96 | + long error = this.tokenInt("error", xml); | ||
| 97 | + if (error > 0) | ||
| 98 | + { | ||
| 99 | + throw new Exception("The server reported error code " + error + " for the file upload"); | ||
| 100 | + } | ||
| 101 | + | ||
| 102 | + throw new Exception("Upload error: " + msg); | ||
| 103 | + | ||
| 104 | + } | ||
| 105 | + | ||
| 106 | + private String tokenString(String token, String xml) | ||
| 107 | + { | ||
| 108 | + int tokStart = xml.IndexOf("<"+token+">") + token.Length+2; | ||
| 109 | + int tokEnd = xml.IndexOf("</"+token+">"); | ||
| 110 | + if (tokEnd == -1) return ""; | ||
| 111 | + | ||
| 112 | + String value = xml.Substring(tokStart, tokEnd-tokStart); | ||
| 113 | + //System.Console.WriteLine(token + ": " + value); | ||
| 114 | + return value; | ||
| 115 | + } | ||
| 116 | + | ||
| 117 | + private long tokenInt(String token, String xml) | ||
| 118 | + { | ||
| 119 | + String value = this.tokenString(token, xml); | ||
| 120 | + if (value.Equals("")) | ||
| 121 | + { | ||
| 122 | + return -1; | ||
| 123 | + } | ||
| 124 | + return long.Parse(value); | ||
| 125 | + } | ||
| 126 | + | ||
| 127 | + } | ||
| 128 | + | ||
| 129 | + public class Document | ||
| 130 | + { | ||
| 131 | + public String title; | ||
| 132 | + public String filename; | ||
| 133 | + public String content; | ||
| 134 | + public int docId; | ||
| 135 | + public String session; | ||
| 136 | + public KnowledgeTreeService kt; | ||
| 137 | + public long filesize; | ||
| 138 | + public bool verbose; | ||
| 139 | + public bool local; | ||
| 140 | + | ||
| 141 | + public Document(int offset, String session, KnowledgeTreeService kt, bool verbose, bool local) | ||
| 142 | + { | ||
| 143 | + this.title = "kt unit test" + offset; | ||
| 144 | + this.filename = Helper.isUnix()?("/tmp/kt_unit_test" + offset + ".txt"):("c:\\kt_unit_test"+offset+".txt"); | ||
| 145 | + this.content = "hello world!"; | ||
| 146 | + this.docId = 0; | ||
| 147 | + this.session = session; | ||
| 148 | + this.kt = kt; | ||
| 149 | + this.verbose =verbose; | ||
| 150 | + this.local = local; | ||
| 151 | + } | ||
| 152 | + | ||
| 153 | + public kt_document_detail createFile(int folderId) | ||
| 154 | + { | ||
| 155 | + Helper.writeFile(this.filename, this.content); | ||
| 156 | + this.filesize = this.content.Length; | ||
| 157 | + | ||
| 158 | + if (this.local) | ||
| 159 | + { | ||
| 160 | + return null; | ||
| 161 | + } | ||
| 162 | + kt_document_detail d1 = this.kt.get_document_detail_by_title(this.session, folderId, this.title, ""); | ||
| 163 | + if (d1.status_code == 1) | ||
| 164 | + { | ||
| 165 | + this.docId = d1.document_id; | ||
| 166 | + this.deleteFile(); | ||
| 167 | + } | ||
| 168 | + | ||
| 169 | + kt_document_detail response1 = this.kt.add_base64_document(this.session, folderId, this.title, this.filename, "Default", Helper.ConvertFileToBase64Encoding(this.filename)); | ||
| 170 | + | ||
| 171 | + if (response1.status_code == 0) | ||
| 172 | + { | ||
| 173 | + this.docId = response1.document_id; | ||
| 174 | + } | ||
| 175 | + | ||
| 176 | + if (this.verbose) | ||
| 177 | + { | ||
| 178 | + if (response1.status_code == 0) | ||
| 179 | + { | ||
| 180 | + System.Console.WriteLine("docid: " + this.docId + " filename: " + this.filename); | ||
| 181 | + } | ||
| 182 | + else | ||
| 183 | + { | ||
| 184 | + System.Console.WriteLine("Could not create file: " + this.filename); | ||
| 185 | + } | ||
| 186 | + } | ||
| 187 | + | ||
| 188 | + return response1; | ||
| 189 | + | ||
| 190 | + } | ||
| 191 | + | ||
| 192 | + public kt_document_detail createFileWithMetadata(int folderId, kt_metadata_fieldset[] metadata, kt_sysdata_item[] sysdata) | ||
| 193 | + { | ||
| 194 | + Helper.writeFile(this.filename, this.content); | ||
| 195 | + | ||
| 196 | + this.filesize = this.content.Length; | ||
| 197 | + | ||
| 198 | + if (this.local) | ||
| 199 | + { | ||
| 200 | + return null; | ||
| 201 | + } | ||
| 202 | + | ||
| 203 | + kt_document_detail d1 = this.kt.get_document_detail_by_title(this.session, folderId, this.title, ""); | ||
| 204 | + if (d1.status_code == 1) | ||
| 205 | + { | ||
| 206 | + this.docId = d1.document_id; | ||
| 207 | + this.deleteFile(); | ||
| 208 | + } | ||
| 209 | + | ||
| 210 | + kt_document_detail response1 = this.kt.add_base64_document_with_metadata(this.session, folderId, this.title, this.filename, "Default", Helper.ConvertFileToBase64Encoding(this.filename), metadata, sysdata); | ||
| 211 | + | ||
| 212 | + if (response1.status_code == 0) | ||
| 213 | + { | ||
| 214 | + this.docId = response1.document_id; | ||
| 215 | + } | ||
| 216 | + | ||
| 217 | + if (this.verbose) | ||
| 218 | + { | ||
| 219 | + if (response1.status_code == 0) | ||
| 220 | + { | ||
| 221 | + System.Console.WriteLine("docid: " + this.docId + " filename: " + this.filename); | ||
| 222 | + } | ||
| 223 | + else | ||
| 224 | + { | ||
| 225 | + System.Console.WriteLine("Could not create file: " + this.filename); | ||
| 226 | + } | ||
| 227 | + } | ||
| 228 | + | ||
| 229 | + return response1; | ||
| 230 | + } | ||
| 231 | + | ||
| 232 | + public kt_document_detail checkinFileWithMetadata(int folderId, kt_metadata_fieldset[] metadata, kt_sysdata_item[] sysdata) | ||
| 233 | + { | ||
| 234 | + Helper.writeFile(this.filename, this.content); | ||
| 235 | + this.filesize = this.content.Length; | ||
| 236 | + | ||
| 237 | + if (this.local) | ||
| 238 | + { | ||
| 239 | + return null; | ||
| 240 | + } | ||
| 241 | + | ||
| 242 | + kt_document_detail d1 = this.kt.get_document_detail_by_title(this.session, folderId, this.title, ""); | ||
| 243 | + if (d1.status_code == 1) | ||
| 244 | + { | ||
| 245 | + this.docId = d1.document_id; | ||
| 246 | + this.deleteFile(); | ||
| 247 | + } | ||
| 248 | + | ||
| 249 | + kt_document_detail response1 = this.kt.checkin_base64_document_with_metadata(this.session, this.docId, this.filename, "checkin reason", Helper.ConvertFileToBase64Encoding(this.filename), false, metadata, sysdata); | ||
| 250 | + | ||
| 251 | + if (response1.status_code == 0) | ||
| 252 | + { | ||
| 253 | + this.docId = response1.document_id; | ||
| 254 | + } | ||
| 255 | + | ||
| 256 | + if (this.verbose) | ||
| 257 | + { | ||
| 258 | + if (response1.status_code == 0) | ||
| 259 | + { | ||
| 260 | + System.Console.WriteLine("docid: " + this.docId + " filename: " + this.filename); | ||
| 261 | + } | ||
| 262 | + else | ||
| 263 | + { | ||
| 264 | + System.Console.WriteLine("Could not create file: " + this.filename); | ||
| 265 | + } | ||
| 266 | + } | ||
| 267 | + | ||
| 268 | + return response1; | ||
| 269 | + } | ||
| 270 | + | ||
| 271 | + | ||
| 272 | + | ||
| 273 | + public void deleteFile() | ||
| 274 | + { | ||
| 275 | + Helper.deleteFile(this.filename); | ||
| 276 | + | ||
| 277 | + if (this.local) | ||
| 278 | + { | ||
| 279 | + return; | ||
| 280 | + } | ||
| 281 | + | ||
| 282 | + if (this.docId > 0) | ||
| 283 | + { | ||
| 284 | + | ||
| 285 | + kt_response response = this.kt.delete_document(this.session, this.docId, "Delete - cleaning up"); | ||
| 286 | + if (this.verbose && response.status_code != 0) | ||
| 287 | + { | ||
| 288 | + System.Console.WriteLine("Could not delete file: " + this.filename); | ||
| 289 | + } | ||
| 290 | + } | ||
| 291 | + } | ||
| 292 | + } | ||
| 293 | + | ||
| 294 | + | ||
| 295 | + public class Helper | ||
| 296 | + { | ||
| 297 | + public static bool isUnix() | ||
| 298 | + { | ||
| 299 | + // found reference on: http://www.mono-project.com/FAQ:_Technical | ||
| 300 | + int platform = (int) Environment.OSVersion.Platform; | ||
| 301 | + return (platform == 4) || (platform == 128); | ||
| 302 | + } | ||
| 303 | + | ||
| 304 | + public static void writeFile(String filename, String text) | ||
| 305 | + { | ||
| 306 | + try | ||
| 307 | + { | ||
| 308 | + TextWriter tw = new StreamWriter(filename); | ||
| 309 | + tw.WriteLine(text ); | ||
| 310 | + tw.Close(); | ||
| 311 | + } | ||
| 312 | + catch (System.Exception exp) | ||
| 313 | + { | ||
| 314 | + System.Console.WriteLine("{0}", exp.Message); | ||
| 315 | + throw; | ||
| 316 | + } | ||
| 317 | + } | ||
| 318 | + | ||
| 319 | + public static String readFile(String filename) | ||
| 320 | + { | ||
| 321 | + String text = null; | ||
| 322 | + try | ||
| 323 | + { | ||
| 324 | + FileStream inFile = new FileStream(filename, System.IO.FileMode.Open, System.IO.FileAccess.Read); | ||
| 325 | + StreamReader sr = new StreamReader(inFile); | ||
| 326 | + text = sr.ReadToEnd(); | ||
| 327 | + inFile.Close(); | ||
| 328 | + } | ||
| 329 | + catch (System.Exception exp) | ||
| 330 | + { | ||
| 331 | + System.Console.WriteLine("{0}", exp.Message); | ||
| 332 | + throw; | ||
| 333 | + } | ||
| 334 | + | ||
| 335 | + return text; | ||
| 336 | + } | ||
| 337 | + | ||
| 338 | + public static void deleteFile(string filename) | ||
| 339 | + { | ||
| 340 | + try | ||
| 341 | + { | ||
| 342 | + File.Delete(filename); | ||
| 343 | + } | ||
| 344 | + catch(System.Exception) | ||
| 345 | + { | ||
| 346 | + // we are using this to cleanup, so don't handle | ||
| 347 | + } | ||
| 348 | + } | ||
| 349 | + | ||
| 350 | + public static string ConvertFileToBase64Encoding(string filename) | ||
| 351 | + { | ||
| 352 | + System.IO.FileStream inFile; | ||
| 353 | + | ||
| 354 | + byte[] binaryData; | ||
| 355 | + string base64String = ""; | ||
| 356 | + | ||
| 357 | + try | ||
| 358 | + { | ||
| 359 | + inFile = new System.IO.FileStream(filename, System.IO.FileMode.Open, System.IO.FileAccess.Read); | ||
| 360 | + binaryData = new Byte[inFile.Length]; | ||
| 361 | + inFile.Read(binaryData, 0, (int)inFile.Length); | ||
| 362 | + inFile.Close(); | ||
| 363 | + | ||
| 364 | + base64String = System.Convert.ToBase64String(binaryData, 0, binaryData.Length); | ||
| 365 | + } | ||
| 366 | + catch (System.Exception exp) | ||
| 367 | + { | ||
| 368 | + System.Console.WriteLine("{0}", exp.Message); | ||
| 369 | + throw; | ||
| 370 | + } | ||
| 371 | + | ||
| 372 | + return base64String; | ||
| 373 | + } | ||
| 374 | + | ||
| 375 | + public static long ConvertBase64EncodingToFile(String encoding, string filename) | ||
| 376 | + { | ||
| 377 | + System.IO.FileStream inFile; | ||
| 378 | + | ||
| 379 | + byte[] binaryData; | ||
| 380 | + string base64String = ""; | ||
| 381 | + | ||
| 382 | + try | ||
| 383 | + { | ||
| 384 | + binaryData = Convert.FromBase64String (encoding); | ||
| 385 | + | ||
| 386 | + inFile = new System.IO.FileStream(filename, System.IO.FileMode.Create); | ||
| 387 | + | ||
| 388 | + inFile.Write(binaryData, 0, (int)binaryData.Length); | ||
| 389 | + inFile.Close(); | ||
| 390 | + } | ||
| 391 | + catch (System.Exception exp) | ||
| 392 | + { | ||
| 393 | + System.Console.WriteLine("{0}", exp.Message); | ||
| 394 | + throw; | ||
| 395 | + } | ||
| 396 | + return binaryData.Length; | ||
| 397 | + } | ||
| 398 | + | ||
| 399 | + } | ||
| 400 | +} |
ktwebservice/nunit/inventory.txt
0 โ 100644
| 1 | +authentication.cs | ||
| 2 | +================= | ||
| 3 | +*login | ||
| 4 | +*logout | ||
| 5 | + | ||
| 6 | +document_add.cs | ||
| 7 | +=============== | ||
| 8 | + | ||
| 9 | +*add_base64_document | ||
| 10 | +*delete_document | ||
| 11 | +*delete_folder | ||
| 12 | +*get_document_detail_by_name | ||
| 13 | +*get_folder_detail_by_name | ||
| 14 | + | ||
| 15 | +document_checkout.cs | ||
| 16 | +==================== | ||
| 17 | + | ||
| 18 | +*checkin_base64_document | ||
| 19 | +*checkout_base64_document | ||
| 20 | +*undo_document_checkout | ||
| 21 | + | ||
| 22 | +document_detail.cs | ||
| 23 | +================== | ||
| 24 | + | ||
| 25 | +*get_document_detail | ||
| 26 | +*get_document_detail_by_name | ||
| 27 | + | ||
| 28 | +document_links.cs | ||
| 29 | +================= | ||
| 30 | + | ||
| 31 | +*get_document_links | ||
| 32 | +*link_documents | ||
| 33 | +*unlink_documents | ||
| 34 | + | ||
| 35 | +document_owner.cs | ||
| 36 | +================= | ||
| 37 | + | ||
| 38 | +*change_document_owner | ||
| 39 | + | ||
| 40 | + | ||
| 41 | +document_type.cs | ||
| 42 | +================ | ||
| 43 | + | ||
| 44 | +*change_document_type | ||
| 45 | + | ||
| 46 | +document_history.cs | ||
| 47 | +=================== | ||
| 48 | + | ||
| 49 | +*get_document_version_history | ||
| 50 | +*get_document_transaction_history | ||
| 51 | + | ||
| 52 | +document_rename.cs | ||
| 53 | +================== | ||
| 54 | + | ||
| 55 | +*rename_document_filename | ||
| 56 | +*rename_document_title | ||
| 57 | + | ||
| 58 | +document_workflow.cs | ||
| 59 | +==================== | ||
| 60 | + | ||
| 61 | +*start_document_workflow | ||
| 62 | +*stop_document_workflow | ||
| 63 | +*perform_document_workflow_transition | ||
| 64 | +*get_document_workflow_transitions | ||
| 65 | + | ||
| 66 | +document_metadata.cs | ||
| 67 | +==================== | ||
| 68 | + | ||
| 69 | +*get_document_types | ||
| 70 | +*get_document_type_metadata | ||
| 71 | +*get_document_metadata | ||
| 72 | +*update_document_metadata | ||
| 73 | + | ||
| 74 | +folder.cs | ||
| 75 | +========= | ||
| 76 | + | ||
| 77 | +*get_folder_detail | ||
| 78 | +*create_folder | ||
| 79 | +*get_folder_detail_by_name | ||
| 80 | +*get_folder_contents | ||
| 81 | +*delete_folder | ||
| 82 | + | ||
| 83 | +document_system_metadata.cs | ||
| 84 | +=========================== | ||
| 85 | + | ||
| 86 | +*update_document_metadata |
ktwebservice/nunit/makefile
| 1 | -RESULTS=authentication.result folder.result document.result query.result | 1 | +RESULTS=authentication.result document_detail.result document_links.result document_owner.result document_type.result document_history.result document_rename.result document_workflow.result document_metadata.result folder.result document_add.result document_system_metadata.result document_checkout.result |
| 2 | +#document_download.result | ||
| 2 | PROXY=KTproxy.cs | 3 | PROXY=KTproxy.cs |
| 3 | WSDL=ktdms.wsdl | 4 | WSDL=ktdms.wsdl |
| 4 | WSDL_URL=http://ktdms.trunk/ktwebservice/index.php?wsdl | 5 | WSDL_URL=http://ktdms.trunk/ktwebservice/index.php?wsdl |
| 5 | 6 | ||
| 6 | all: ${RESULTS} | 7 | all: ${RESULTS} |
| 7 | - | 8 | + |
| 8 | results: clean-results ${RESULTS} | 9 | results: clean-results ${RESULTS} |
| 9 | - | ||
| 10 | -KTproxy.dll: KTproxy.cs | ||
| 11 | - mcs -r:System.Web.Services /target:library KTproxy.cs | 10 | + |
| 11 | +KTproxy.dll: KTproxy.cs helper.cs | ||
| 12 | + mcs -r:System.Web.Services /target:library KTproxy.cs helper.cs | ||
| 12 | 13 | ||
| 13 | KTproxy.cs: ktdms.wsdl | 14 | KTproxy.cs: ktdms.wsdl |
| 14 | wsdl -out:${PROXY} ${WSDL} | 15 | wsdl -out:${PROXY} ${WSDL} |
| @@ -23,7 +24,7 @@ clean-results: | @@ -23,7 +24,7 @@ clean-results: | ||
| 23 | rm -f ${RESULTS} | 24 | rm -f ${RESULTS} |
| 24 | 25 | ||
| 25 | %.dll: %.cs KTproxy.dll | 26 | %.dll: %.cs KTproxy.dll |
| 26 | - mcs -r:System.Web.Services -r:nunit.framework /r:KTproxy.dll -debug /target:library -out:$@ $< | 27 | + mcs -r:System.Web.Services -r:nunit.framework /r:KTproxy.dll -debug /target:library -out:$@ $< |
| 27 | 28 | ||
| 28 | %.result: %.dll | 29 | %.result: %.dll |
| 29 | nunit-console $< | 30 | nunit-console $< |
ktwebservice/nunit/query.cs
| @@ -3,45 +3,45 @@ using System; | @@ -3,45 +3,45 @@ using System; | ||
| 3 | using System.IO; | 3 | using System.IO; |
| 4 | 4 | ||
| 5 | namespace MonoTests.KnowledgeTree | 5 | namespace MonoTests.KnowledgeTree |
| 6 | -{ | 6 | +{ |
| 7 | [TestFixture] | 7 | [TestFixture] |
| 8 | public class QueryTest | 8 | public class QueryTest |
| 9 | { | 9 | { |
| 10 | - | 10 | + |
| 11 | private String _session; | 11 | private String _session; |
| 12 | private KnowledgeTreeService _kt; | 12 | private KnowledgeTreeService _kt; |
| 13 | - | 13 | + |
| 14 | [SetUp] | 14 | [SetUp] |
| 15 | - public void SetUp() | 15 | + public void SetUp() |
| 16 | { | 16 | { |
| 17 | - this._kt = new KnowledgeTreeService(); | ||
| 18 | - kt_response response = this._kt.login("admin","admin","127.0.0.1"); | ||
| 19 | - this._session = response.message; | ||
| 20 | - | 17 | + this._kt = new KnowledgeTreeService(); |
| 18 | + kt_response response = this._kt.login("admin","admin","127.0.0.1"); | ||
| 19 | + this._session = response.message; | ||
| 20 | + | ||
| 21 | } | 21 | } |
| 22 | 22 | ||
| 23 | [TearDown] | 23 | [TearDown] |
| 24 | - public void TearDown() | 24 | + public void TearDown() |
| 25 | { | 25 | { |
| 26 | this._kt.logout(this._session); | 26 | this._kt.logout(this._session); |
| 27 | } | 27 | } |
| 28 | - | 28 | + |
| 29 | [Test] | 29 | [Test] |
| 30 | - public void Query() | 30 | + public void Query() |
| 31 | { | 31 | { |
| 32 | - kt_search_response response = this._kt.search(this._session, "Filesize >= \"0\"", ""); | ||
| 33 | - | ||
| 34 | - Assert.AreEqual(0,response.status_code); | ||
| 35 | - | ||
| 36 | - | 32 | + kt_search_response response = this._kt.search(this._session, "Filesize >= \"0\"", ""); |
| 33 | + | ||
| 34 | + Assert.AreEqual(0,response.status_code); | ||
| 35 | + | ||
| 36 | + | ||
| 37 | if (response.status_code == 0) | 37 | if (response.status_code == 0) |
| 38 | { | 38 | { |
| 39 | - | 39 | + |
| 40 | for(int i=0;i<response.hits.Length;i++) | 40 | for(int i=0;i<response.hits.Length;i++) |
| 41 | { | 41 | { |
| 42 | - | 42 | + |
| 43 | } | 43 | } |
| 44 | - } | ||
| 45 | - } | 44 | + } |
| 45 | + } | ||
| 46 | } | 46 | } |
| 47 | } | 47 | } |