1 17 package org.alfresco.webservice.test; 18 19 import junit.framework.TestCase; 20 21 import org.alfresco.webservice.content.Content; 22 import org.alfresco.webservice.content.ContentServiceSoapBindingStub; 23 import org.alfresco.webservice.repository.RepositoryServiceSoapBindingStub; 24 import org.alfresco.webservice.repository.UpdateResult; 25 import org.alfresco.webservice.types.CML; 26 import org.alfresco.webservice.types.CMLCreate; 27 import org.alfresco.webservice.types.ContentFormat; 28 import org.alfresco.webservice.types.NamedValue; 29 import org.alfresco.webservice.types.Node; 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.Store; 34 import org.alfresco.webservice.types.StoreEnum; 35 import org.alfresco.webservice.util.AuthenticationUtils; 36 import org.alfresco.webservice.util.Constants; 37 import org.alfresco.webservice.util.WebServiceFactory; 38 import org.apache.commons.logging.Log; 39 import org.apache.commons.logging.LogFactory; 40 41 51 public abstract class BaseWebServiceSystemTest extends TestCase 52 { 53 @SuppressWarnings ("unused") 54 private static Log logger = LogFactory.getLog(BaseWebServiceSystemTest.class); 55 56 protected static final String USERNAME = "admin"; 57 protected static final String PASSWORD = "admin"; 58 59 public static final String FOLDER_NAME = "test folder"; 60 protected static final String CONTENT_NAME = "test content"; 61 62 protected static final String TEST_CONTENT = "This is some test content. This is some test content."; 63 64 protected static Store store; 65 protected static Reference rootReference; 66 protected static Reference contentReference; 67 protected static Reference folderReference; 68 69 protected RepositoryServiceSoapBindingStub repositoryService; 70 protected ContentServiceSoapBindingStub contentService; 71 72 public BaseWebServiceSystemTest() 73 { 74 this.repositoryService = WebServiceFactory.getRepositoryService(); 75 this.contentService = WebServiceFactory.getContentService(); 76 } 77 78 82 @Override 83 protected void setUp() throws Exception 84 { 85 super.setUp(); 86 87 AuthenticationUtils.startSession(USERNAME, PASSWORD); 89 90 if (BaseWebServiceSystemTest.store == null) 92 { 93 BaseWebServiceSystemTest.store = WebServiceFactory.getRepositoryService().createStore(StoreEnum.workspace, "Test" + System.currentTimeMillis()); 95 96 Predicate predicate = new Predicate(null, BaseWebServiceSystemTest.store, null); 98 Node[] nodes = WebServiceFactory.getRepositoryService().get(predicate); 99 if (nodes.length == 1) 100 { 101 BaseWebServiceSystemTest.rootReference = nodes[0].getReference(); 102 } 103 else 104 { 105 throw new Exception ("Unable to get the root not of the created sotre."); 106 } 107 108 ParentReference contentParentRef = new ParentReference(BaseWebServiceSystemTest.store, BaseWebServiceSystemTest.rootReference.getUuid(), null, Constants.ASSOC_CHILDREN, "{test}testContent"); 110 NamedValue[] contentProperties = new NamedValue[]{new NamedValue(Constants.PROP_NAME, CONTENT_NAME)}; 111 CMLCreate createContent = new CMLCreate("testContent", contentParentRef, Constants.TYPE_CONTENT, contentProperties); 112 113 ParentReference folderParentRef = new ParentReference(BaseWebServiceSystemTest.store, BaseWebServiceSystemTest.rootReference.getUuid(), null, Constants.ASSOC_CHILDREN, "{test}testFolder"); 115 NamedValue[] folderProperties = new NamedValue[]{new NamedValue(Constants.PROP_NAME, FOLDER_NAME)}; 116 CMLCreate createFolder = new CMLCreate("testFolder", folderParentRef, Constants.TYPE_FOLDER, folderProperties); 117 118 CML cml = new CML(); 119 cml.setCreate(new CMLCreate[]{createContent, createFolder}); 120 121 UpdateResult[] updateResult = this.repositoryService.update(cml); 122 BaseWebServiceSystemTest.contentReference = updateResult[0].getDestination(); 123 BaseWebServiceSystemTest.folderReference = updateResult[1].getDestination(); 124 125 this.contentService.write(BaseWebServiceSystemTest.contentReference, Constants.PROP_CONTENT, TEST_CONTENT.getBytes(), new ContentFormat(Constants.MIMETYPE_TEXT_PLAIN, "UTF-8")); 127 } 128 } 129 130 @Override 131 protected void tearDown() throws Exception 132 { 133 AuthenticationUtils.endSession(); 135 } 136 137 138 protected ParentReference getFolderParentReference(String assocName) 139 { 140 ParentReference parentReference = new ParentReference(); 141 parentReference.setStore(BaseWebServiceSystemTest.store); 142 parentReference.setUuid(BaseWebServiceSystemTest.folderReference.getUuid()); 143 parentReference.setAssociationType(Constants.ASSOC_CONTAINS); 144 parentReference.setChildName(assocName); 145 return parentReference; 146 } 147 148 protected Reference createContentAtRoot(String name, String contentValue) throws Exception 149 { 150 ParentReference parentRef = new ParentReference(); 151 parentRef.setStore(BaseWebServiceSystemTest.store); 152 parentRef.setUuid(BaseWebServiceSystemTest.rootReference.getUuid()); 153 parentRef.setAssociationType(Constants.ASSOC_CHILDREN); 154 parentRef.setChildName("{test}test" + System.currentTimeMillis()); 155 156 NamedValue[] properties = new NamedValue[]{new NamedValue(Constants.PROP_NAME, name)}; 157 CMLCreate create = new CMLCreate("1", parentRef, Constants.TYPE_CONTENT, properties); 158 CML cml = new CML(); 159 cml.setCreate(new CMLCreate[]{create}); 160 UpdateResult[] result = this.repositoryService.update(cml); 161 162 Reference newContentNode = result[0].getDestination(); 163 164 Content content = this.contentService.write(newContentNode, Constants.PROP_CONTENT, contentValue.getBytes(), new ContentFormat("text/plain", "UTF-8")); 165 166 assertNotNull(content); 167 assertNotNull(content.getFormat()); 168 assertEquals("text/plain", content.getFormat().getMimetype()); 169 170 return content.getNode(); 171 } 172 173 protected Predicate convertToPredicate(Reference reference) 174 { 175 Predicate predicate = new Predicate(); 176 predicate.setNodes(new Reference[] {reference}); 177 return predicate; 178 } 179 180 } 181 | Popular Tags |