1 17 package org.alfresco.webservice.test; 18 19 import java.io.InputStream ; 20 21 import org.alfresco.webservice.action.Action; 22 import org.alfresco.webservice.classification.AppliedCategory; 23 import org.alfresco.webservice.classification.CategoriesResult; 24 import org.alfresco.webservice.classification.ClassificationServiceSoapBindingStub; 25 import org.alfresco.webservice.repository.UpdateResult; 26 import org.alfresco.webservice.types.CML; 27 import org.alfresco.webservice.types.CMLCreate; 28 import org.alfresco.webservice.types.Category; 29 import org.alfresco.webservice.types.ClassDefinition; 30 import org.alfresco.webservice.types.Classification; 31 import org.alfresco.webservice.types.ContentFormat; 32 import org.alfresco.webservice.types.NamedValue; 33 import org.alfresco.webservice.types.ParentReference; 34 import org.alfresco.webservice.types.Predicate; 35 import org.alfresco.webservice.types.Reference; 36 import org.alfresco.webservice.util.Constants; 37 import org.alfresco.webservice.util.ContentUtils; 38 import org.alfresco.webservice.util.WebServiceFactory; 39 import org.apache.commons.logging.Log; 40 import org.apache.commons.logging.LogFactory; 41 42 public class ClassificationServiceSystemTest extends BaseWebServiceSystemTest 43 { 44 private static Log logger = LogFactory 45 .getLog(ClassificationServiceSystemTest.class); 46 47 private ClassificationServiceSoapBindingStub classificationService; 48 49 private static boolean categoriesLoaded = false; 50 51 @Override 52 protected void setUp() throws Exception 53 { 54 super.setUp(); 55 56 this.classificationService = WebServiceFactory.getClassificationService(); 57 58 if (ClassificationServiceSystemTest.categoriesLoaded == false) 59 { 60 InputStream viewStream = getClass().getClassLoader().getResourceAsStream("org/alfresco/webservice/test/resources/test.acp"); 62 byte[] byteArray = ContentUtils.convertToByteArray(viewStream); 63 64 ParentReference categoryParentRef = new ParentReference(BaseWebServiceSystemTest.store, BaseWebServiceSystemTest.rootReference.getUuid(), null, Constants.ASSOC_CHILDREN, "{test}testContent"); 66 NamedValue[] categoryProperties = new NamedValue[]{new NamedValue(Constants.PROP_NAME, "categories.acp")}; 67 CMLCreate createCategory = new CMLCreate("categoryImport", categoryParentRef, Constants.TYPE_CONTENT, categoryProperties); 68 CML cml2 = new CML(); 69 cml2.setCreate(new CMLCreate[]{createCategory}); 70 UpdateResult[] updateResult = this.repositoryService.update(cml2); 71 Reference categoryReference = updateResult[0].getDestination(); 72 73 this.contentService.write( 75 categoryReference, 76 Constants.PROP_CONTENT, 77 byteArray, 78 new ContentFormat("application/acp", "UTF-8")); 79 80 String rootNodeRef = store.getScheme().getValue() + "://" + store.getAddress() + "/" + rootReference.getUuid(); 82 Action importAction = new Action(); 83 importAction.setActionName("import"); 84 NamedValue[] params = new NamedValue[]{ 85 new NamedValue("encoding", "UTF-8"), 86 new NamedValue("destination", rootNodeRef) 87 }; 88 importAction.setParameters(params); 89 90 WebServiceFactory.getActionService().executeActions( 91 new Predicate(new Reference[]{categoryReference}, store, null), 92 new Action[]{importAction}); 93 94 ClassificationServiceSystemTest.categoriesLoaded = true; 95 } 96 } 97 98 103 public void testGetClassifications() throws Exception 104 { 105 Classification[] classifications = this.classificationService 106 .getClassifications(BaseWebServiceSystemTest.store); 107 108 assertNotNull(classifications); 109 assertTrue((classifications.length != 0)); 110 Classification classification = classifications[0]; 111 assertNotNull(classification.getTitle()); 112 assertNotNull(classification.getRootCategory()); 113 assertNotNull(classification.getRootCategory().getId()); 114 assertNotNull(classification.getRootCategory().getTitle()); 115 116 if (logger.isDebugEnabled() == true) 117 { 118 for (Classification item : classifications) 119 { 120 logger.debug( 121 "Classification '" + 122 item.getTitle() + 123 "' with root category '" + 124 item.getRootCategory().getTitle() + 125 "'"); 126 } 127 } 128 } 129 130 135 public void testGetChildCategories() throws Exception 136 { 137 Classification[] classifications = this.classificationService.getClassifications(BaseWebServiceSystemTest.store); 138 Reference parentCategory = classifications[0].getRootCategory().getId(); 139 140 Category[] categories = this.classificationService.getChildCategories(parentCategory); 141 assertNotNull(categories); 142 assertTrue((categories.length != 0)); 143 Category item = categories[0]; 144 assertNotNull(item.getId()); 145 assertNotNull(item.getTitle()); 146 147 if (logger.isDebugEnabled() == true) 148 { 149 for (Category category : categories) 150 { 151 logger.debug( 152 "Sub-category '" + 153 category.getTitle() + 154 "'"); 155 } 156 } 157 } 158 159 164 public void testGetAndSetCategories() throws Exception 165 { 166 Classification[] classifications = this.classificationService.getClassifications(BaseWebServiceSystemTest.store); 167 String classification = classifications[0].getClassification(); 168 Reference category = classifications[0].getRootCategory().getId(); 169 170 Reference reference = createContentAtRoot("TestContent" + System.currentTimeMillis(), "Any old content."); 171 Predicate predicate = convertToPredicate(reference); 172 173 CategoriesResult[] result1 = this.classificationService.getCategories(predicate); 175 assertNotNull(result1); 176 assertEquals(1, result1.length); 177 assertNull(result1[0].getCategories()); 178 179 AppliedCategory appliedCategory = new AppliedCategory(); 180 appliedCategory.setCategories(new Reference[]{category}); 181 appliedCategory.setClassification(classification); 182 183 AppliedCategory[] appliedCategories = new AppliedCategory[]{appliedCategory}; 184 185 CategoriesResult[] result2 = this.classificationService.setCategories(predicate, appliedCategories); 187 assertNotNull(result2); 188 assertEquals(1, result2.length); 189 190 CategoriesResult[] result3 = this.classificationService.getCategories(predicate); 192 assertNotNull(result3); 193 assertEquals(1, result3.length); 194 CategoriesResult categoryResult = result3[0]; 195 assertEquals(reference.getUuid(), categoryResult.getNode().getUuid()); 196 AppliedCategory[] appCats = categoryResult.getCategories(); 197 assertNotNull(appCats); 198 assertEquals(1, appCats.length); 199 AppliedCategory appCat = appCats[0]; 200 assertEquals(classification, appCat.getClassification()); 201 Reference[] refs = appCat.getCategories(); 202 assertNotNull(refs); 203 assertEquals(1, refs.length); 204 Reference ref = refs[0]; 205 assertEquals(category.getUuid(), ref.getUuid()); 206 207 } 211 212 213 218 public void testDescribeClassification() throws Exception 219 { 220 Classification[] classifications = this.classificationService.getClassifications(BaseWebServiceSystemTest.store); 221 String classification = classifications[0].getClassification(); 222 223 ClassDefinition classDefinition = this.classificationService.describeClassification(classification); 224 225 assertNotNull(classDefinition); 226 227 } 229 } 230 | Popular Tags |