1 31 32 package org.opencms.file; 33 34 import org.opencms.main.CmsException; 35 import org.opencms.test.OpenCmsTestCase; 36 import org.opencms.test.OpenCmsTestProperties; 37 import org.opencms.util.CmsUUID; 38 39 import java.util.List ; 40 41 import junit.extensions.TestSetup; 42 import junit.framework.Test; 43 import junit.framework.TestSuite; 44 45 52 public class TestPropertyDefinition extends OpenCmsTestCase { 53 54 59 public TestPropertyDefinition(String arg0) { 60 61 super(arg0); 62 } 63 64 69 public static Test suite() { 70 OpenCmsTestProperties.initialize(org.opencms.test.AllTests.TEST_PROPERTIES_PATH); 71 72 TestSuite suite = new TestSuite(); 73 suite.setName(TestPropertyDefinition.class.getName()); 74 75 suite.addTest(new TestPropertyDefinition("testCreatePropertyDefinition")); 76 suite.addTest(new TestPropertyDefinition("testCreateReadDeletePropertyDefinition")); 77 suite.addTest(new TestPropertyDefinition("testGetResourcesWithProperty")); 78 79 TestSetup wrapper = new TestSetup(suite) { 80 81 protected void setUp() { 82 83 setupOpenCms("simpletest", "/sites/default/"); 84 } 85 86 protected void tearDown() { 87 88 removeOpenCms(); 89 } 90 }; 91 92 return wrapper; 93 } 94 95 102 public static void createPropertyDefinition(OpenCmsTestCase tc, CmsObject cms, String propertyDefiniton1) 103 throws Throwable { 104 105 List allPropertydefintions = cms.readAllPropertyDefinitions(); 107 CmsPropertyDefinition prop = new CmsPropertyDefinition( 109 CmsUUID.getNullUUID(), 110 propertyDefiniton1); 111 112 cms.createPropertyDefinition(propertyDefiniton1); 113 114 tc.assertPropertydefinitionExist(cms, prop); 116 tc.assertPropertydefinitions(cms, allPropertydefintions, prop); 118 } 119 120 125 public void testCreatePropertyDefinition() throws Throwable { 126 127 CmsObject cms = getCmsObject(); 128 echo("Testing createPropetyDefinition and readPropertyDefiniton"); 129 createPropertyDefinition(this, cms, "NewPropertyDefinition"); 130 } 131 132 137 public void testCreateReadDeletePropertyDefinition() throws Throwable { 138 139 CmsObject cms = getCmsObject(); 140 141 echo("Testing creation of a new property definition"); 142 createReadDeletePropertyDefinition(cms); 143 } 144 145 151 public static void createReadDeletePropertyDefinition(CmsObject cms) throws Throwable { 152 153 CmsPropertyDefinition propertyDefinition = null; 154 String propertyDefinitionName = "locale-available"; 155 156 158 try { 159 propertyDefinition = cms.createPropertyDefinition(propertyDefinitionName); 161 } catch (CmsException e) { 162 fail("Error creating property definition " + propertyDefinitionName + ", " + e.toString()); 163 } 164 165 assertEquals(propertyDefinition.getName(), propertyDefinitionName); 166 167 169 try { 170 propertyDefinition = null; 172 propertyDefinition = cms.readPropertyDefinition(propertyDefinitionName); 173 } catch (CmsException e) { 174 fail("Error reading property definition " + propertyDefinitionName + ", " + e.toString()); 175 } 176 177 assertEquals(propertyDefinition.getName(), propertyDefinitionName); 178 179 181 List allPropertyDefinitions = null; 182 try { 183 allPropertyDefinitions = cms.readAllPropertyDefinitions(); 185 } catch (CmsException e) { 186 fail("Error reading all property definitions, " + e.toString()); 187 } 188 189 boolean found = false; 190 for (int i = 0, n = allPropertyDefinitions.size(); i < n; i++) { 191 if (((CmsPropertyDefinition)allPropertyDefinitions.get(i)).equals(propertyDefinition)) { 192 found = true; 193 break; 194 } 195 } 196 197 if (!found) { 198 fail("Property definition " + propertyDefinitionName + " is not in the list of all property definitions"); 199 } 200 201 203 try { 204 cms.deletePropertyDefinition(propertyDefinitionName); 206 } catch (CmsException e) { 207 fail("Error deleting property definition " + propertyDefinitionName + ", " + e.toString()); 208 } 209 210 212 try { 213 propertyDefinition = null; 215 propertyDefinition = cms.readPropertyDefinition(propertyDefinitionName); 216 } catch (CmsException e) { 217 } 219 220 assertNull(propertyDefinition); 221 222 224 allPropertyDefinitions = null; 225 try { 226 allPropertyDefinitions = cms.readAllPropertyDefinitions(); 228 } catch (CmsException e) { 229 fail("Error reading all property definitions, " + e.toString()); 230 } 231 232 found = false; 233 for (int i = 0, n = allPropertyDefinitions.size(); i < n; i++) { 234 if (((CmsPropertyDefinition)allPropertyDefinitions.get(i)).equals(propertyDefinition)) { 235 found = true; 236 break; 237 } 238 } 239 240 if (found) { 241 fail("Property definition " + propertyDefinitionName + " is still in the list of all property definitions"); 242 } 243 244 } 245 246 251 public void testGetResourcesWithProperty() throws Exception { 252 253 echo("Testing reading all resources with a specific property"); 254 CmsObject cms = getCmsObject(); 255 List result; 256 257 result = cms.readResourcesWithProperty(CmsPropertyDefinition.PROPERTY_TITLE); 258 assertEquals(63, result.size()); 259 result = cms.readResourcesWithProperty(CmsPropertyDefinition.PROPERTY_TEMPLATE); 260 assertEquals(25, result.size()); 261 } 262 263 } | Popular Tags |