1 17 package org.alfresco.webservice.test; 18 19 20 import org.alfresco.webservice.authoring.AuthoringServiceSoapBindingStub; 21 import org.alfresco.webservice.authoring.CancelCheckoutResult; 22 import org.alfresco.webservice.authoring.CheckinResult; 23 import org.alfresco.webservice.authoring.CheckoutResult; 24 import org.alfresco.webservice.authoring.LockStatus; 25 import org.alfresco.webservice.authoring.LockTypeEnum; 26 import org.alfresco.webservice.authoring.VersionResult; 27 import org.alfresco.webservice.content.Content; 28 import org.alfresco.webservice.types.ContentFormat; 29 import org.alfresco.webservice.types.NamedValue; 30 import org.alfresco.webservice.types.ParentReference; 31 import org.alfresco.webservice.types.Predicate; 32 import org.alfresco.webservice.types.Reference; 33 import org.alfresco.webservice.types.Version; 34 import org.alfresco.webservice.types.VersionHistory; 35 import org.alfresco.webservice.util.Constants; 36 import org.alfresco.webservice.util.ContentUtils; 37 import org.alfresco.webservice.util.WebServiceFactory; 38 import org.apache.commons.logging.Log; 39 import org.apache.commons.logging.LogFactory; 40 41 public class AuthoringServiceSystemTest extends BaseWebServiceSystemTest 42 { 43 @SuppressWarnings ("unused") 44 private static Log logger = LogFactory.getLog(AuthoringServiceSystemTest.class); 45 46 private static final String INITIAL_VERSION_CONTENT = "Content of the initial version"; 47 private static final String SECOND_VERSION_CONTENT = "The content for the second version is completely different"; 48 49 private static final String VALUE_DESCRIPTION = "description"; 50 51 private AuthoringServiceSoapBindingStub authoringService; 52 53 public AuthoringServiceSystemTest() 54 { 55 this.authoringService = WebServiceFactory.getAuthoringService(); 56 } 57 58 63 public void testCheckout() throws Exception 64 { 65 doCheckOut(); 66 67 } 69 70 76 private Reference doCheckOut() throws Exception 77 { 78 Reference reference = createContentAtRoot("version_test.txt", INITIAL_VERSION_CONTENT); 80 Predicate predicate = convertToPredicate(reference); 81 82 CheckoutResult result = this.authoringService.checkout(predicate, null); 84 assertNotNull(result); 85 assertEquals(1, result.getOriginals().length); 86 assertEquals(1, result.getWorkingCopies().length); 87 88 90 return result.getWorkingCopies()[0]; 91 } 92 93 99 public void testCheckoutWithDestination() throws Exception 100 { 101 Reference reference = createContentAtRoot("version_test.txt", INITIAL_VERSION_CONTENT); 102 Predicate predicate = convertToPredicate(reference); 103 ParentReference parentReference = getFolderParentReference("{test}workingCopy"); 104 105 CheckoutResult result = this.authoringService.checkout(predicate, parentReference); 107 assertNotNull(result); 108 assertEquals(1, result.getOriginals().length); 109 assertEquals(1, result.getWorkingCopies().length); 110 111 } 113 114 119 public void testCheckin() throws Exception 120 { 121 Reference workingCopy = doCheckOut(); 123 124 Predicate predicate = convertToPredicate(workingCopy); 126 NamedValue[] comments = getVersionComments(); 127 CheckinResult checkinResult = this.authoringService.checkin(predicate, comments, true); 128 129 assertNotNull(checkinResult); 131 assertEquals(1, checkinResult.getCheckedIn().length); 132 assertEquals(1, checkinResult.getWorkingCopies().length); 133 135 Predicate predicate2 = convertToPredicate(checkinResult.getWorkingCopies()[0]); 137 CheckinResult checkinResult2 = this.authoringService.checkin(predicate2, comments, false); 138 139 assertNotNull(checkinResult2); 141 assertEquals(1, checkinResult2.getCheckedIn().length); 142 assertNull(checkinResult2.getWorkingCopies()); 143 146 } 148 149 154 private NamedValue[] getVersionComments() 155 { 156 NamedValue[] comments = new NamedValue[1]; 157 comments[0] = new NamedValue("description", VALUE_DESCRIPTION); 158 return comments; 159 } 160 161 166 public void testCheckinExternal() throws Exception 167 { 168 Reference workingCopy = doCheckOut(); 170 171 NamedValue[] comments = getVersionComments(); 173 ContentFormat contentFormat = new ContentFormat(Constants.MIMETYPE_TEXT_PLAIN, "UTF-8"); 174 Reference origionalNode = this.authoringService.checkinExternal(workingCopy, comments, false, contentFormat, SECOND_VERSION_CONTENT.getBytes()); 175 176 assertNotNull(origionalNode); 178 Content[] contents = this.contentService.read(new Predicate(new Reference[]{origionalNode}, BaseWebServiceSystemTest.store, null), Constants.PROP_CONTENT.toString()); 179 Content readResult = contents[0]; 180 assertNotNull(readResult); 181 String checkedInContent = ContentUtils.getContentAsString(readResult); 182 assertNotNull(checkedInContent); 183 assertEquals(SECOND_VERSION_CONTENT, checkedInContent); 184 } 185 186 191 public void testCancelCheckout() throws Exception 192 { 193 Reference workingCopy = doCheckOut(); 195 196 Predicate predicate = convertToPredicate(workingCopy); 198 CancelCheckoutResult result = this.authoringService.cancelCheckout(predicate); 199 200 assertNotNull(result); 202 assertEquals(1, result.getOriginals().length); 203 205 } 207 208 213 public void testLockUnLockGetStatus() throws Exception 214 { 215 Reference reference = createContentAtRoot("lock_test1.txt", INITIAL_VERSION_CONTENT); 216 Predicate predicate = convertToPredicate(reference); 217 218 checkLockStatus(predicate, null, null); 220 221 Reference[] lockedRefs = this.authoringService.lock(predicate, false, LockTypeEnum.write); 223 assertNotNull(lockedRefs); 224 assertEquals(1, lockedRefs.length); 225 227 checkLockStatus(predicate, USERNAME, LockTypeEnum.write); 229 230 241 Reference[] unlocked = this.authoringService.unlock(predicate, false); 243 assertNotNull(unlocked); 244 assertEquals(1, unlocked.length); 245 246 checkLockStatus(predicate, null, null); 248 249 Reference[] lockedRefs2 = this.authoringService.lock(predicate, false, LockTypeEnum.read); 251 252 assertNotNull(lockedRefs2); 253 assertEquals(1, lockedRefs2.length); 254 256 checkLockStatus(predicate, USERNAME, LockTypeEnum.read); 258 } 259 260 private void checkLockStatus(Predicate predicate, String lockOwner, LockTypeEnum lockType) 261 throws Exception 262 { 263 LockStatus[] lockStatus1 = this.authoringService.getLockStatus(predicate); 264 assertNotNull(lockStatus1); 265 assertEquals(1, lockStatus1.length); 266 LockStatus ls1 = lockStatus1[0]; 267 assertNotNull(ls1); 268 assertEquals(lockOwner, ls1.getLockOwner()); 269 assertEquals(lockType, ls1.getLockType()); 270 } 271 272 277 public void testVersionMethods() throws Exception 278 { 279 Reference reference = createContentAtRoot("create_version_test.txt", INITIAL_VERSION_CONTENT); 280 Predicate predicate = convertToPredicate(reference); 281 282 VersionHistory emptyVersionHistory = this.authoringService.getVersionHistory(reference); 284 assertNotNull(emptyVersionHistory); 285 assertNull(emptyVersionHistory.getVersions()); 286 287 VersionResult result = this.authoringService.createVersion(predicate, getVersionComments(), false); 289 assertNotNull(result); 290 assertEquals(1, result.getNodes().length); 291 assertEquals(1, result.getVersions().length); 292 Version version = result.getVersions()[0]; 293 assertEquals("1.0", version.getLabel()); 294 297 VersionHistory versionHistory = this.authoringService.getVersionHistory(reference); 299 assertNotNull(versionHistory); 300 assertEquals(2, versionHistory.getVersions().length); 301 303 this.contentService.write(reference, Constants.PROP_CONTENT, SECOND_VERSION_CONTENT.getBytes(), null); 305 306 VersionResult versionResult2 = this.authoringService.createVersion(predicate, getVersionComments(), false); 308 assertNotNull(versionResult2); 309 assertEquals(1, versionResult2.getNodes().length); 310 assertEquals(1, versionResult2.getVersions().length); 311 Version version2 = versionResult2.getVersions()[0]; 312 assertEquals("1.3", version2.getLabel()); 313 316 VersionHistory versionHistory2 = this.authoringService.getVersionHistory(reference); 318 assertNotNull(versionHistory2); 319 assertEquals(4, versionHistory2.getVersions().length); 320 322 Content[] contents = this.contentService.read(new Predicate(new Reference[]{reference}, BaseWebServiceSystemTest.store, null), Constants.PROP_CONTENT.toString()); 324 Content readResult1 = contents[0]; 325 String content1 = ContentUtils.getContentAsString(readResult1); 326 assertEquals(SECOND_VERSION_CONTENT, content1); 327 328 this.authoringService.revertVersion(reference, "1.0"); 330 331 Content[] contents2 = this.contentService.read(new Predicate(new Reference[]{reference}, BaseWebServiceSystemTest.store, null), Constants.PROP_CONTENT.toString()); 333 Content readResult2 = contents2[0]; 334 String content2 = ContentUtils.getContentAsString(readResult2); 335 assertEquals(INITIAL_VERSION_CONTENT, content2); 336 337 VersionHistory deletedVersionHistory = this.authoringService.deleteAllVersions(reference); 339 assertNotNull(deletedVersionHistory); 340 assertNull(deletedVersionHistory.getVersions()); 341 342 VersionHistory versionHistory3 = this.authoringService.getVersionHistory(reference); 344 assertNotNull(versionHistory3); 345 assertNull(versionHistory3.getVersions()); 346 } 347 } 348 | Popular Tags |