1 31 32 package org.opencms.notification; 33 34 import org.opencms.file.CmsObject; 35 import org.opencms.file.CmsProperty; 36 import org.opencms.file.CmsPropertyDefinition; 37 import org.opencms.file.CmsResource; 38 import org.opencms.file.CmsUser; 39 import org.opencms.file.types.CmsResourceTypeXmlPage; 40 import org.opencms.i18n.CmsLocaleManager; 41 import org.opencms.security.I_CmsPrincipal; 42 import org.opencms.test.OpenCmsTestCase; 43 import org.opencms.test.OpenCmsTestProperties; 44 import org.opencms.util.CmsStringUtil; 45 46 import java.util.Calendar ; 47 import java.util.Collection ; 48 import java.util.Date ; 49 import java.util.GregorianCalendar ; 50 import java.util.HashMap ; 51 import java.util.Iterator ; 52 import java.util.TimeZone ; 53 54 import junit.extensions.TestSetup; 55 import junit.framework.Test; 56 import junit.framework.TestSuite; 57 58 64 public class TestContentNotification extends OpenCmsTestCase { 65 66 71 public TestContentNotification(String arg0) { 72 super(arg0); 73 } 74 75 80 public static Test suite() { 81 OpenCmsTestProperties.initialize(org.opencms.test.AllTests.TEST_PROPERTIES_PATH); 82 83 TestSuite suite = new TestSuite(); 84 suite.setName(TestContentNotification.class.getName()); 85 86 suite.addTest(new TestContentNotification("testContentNotification")); 87 88 TestSetup wrapper = new TestSetup(suite) { 89 90 protected void setUp() { 91 setupOpenCms("simpletest", "/sites/default/"); 92 } 93 94 protected void tearDown() { 95 removeOpenCms(); 96 } 97 }; 98 99 return wrapper; 100 } 101 102 103 108 public void testContentNotification() throws Throwable { 109 110 echo("Testing OpenCms content notification"); 111 CmsObject cms = getCmsObject(); 112 114 GregorianCalendar today = new GregorianCalendar (TimeZone.getDefault(), CmsLocaleManager.getDefaultLocale()); 115 today.setTimeInMillis(cms.getRequestContext().getRequestTime()); 116 GregorianCalendar inFiveDays = (GregorianCalendar )today.clone(); 117 inFiveDays.add(Calendar.DAY_OF_YEAR, 5); 118 GregorianCalendar inEightDays = (GregorianCalendar )today.clone(); 119 inEightDays.add(Calendar.DAY_OF_YEAR, 8); 120 GregorianCalendar oneDayBefore = (GregorianCalendar )today.clone(); 121 oneDayBefore.add(Calendar.DAY_OF_YEAR, -1); 122 123 124 echo("yesterday: " + oneDayBefore.getTimeInMillis()); 125 echo("today: " + today.getTimeInMillis()); 126 echo("in five days: " + inFiveDays.getTimeInMillis()); 127 echo("inEightDays: " + inEightDays.getTimeInMillis()); 128 129 CmsUser fry = cms.createUser("fry", "password", "First test user", new HashMap ()); 131 132 String folder = "folder1/"; 134 String expired01 = "folder1/expired01.html"; 135 CmsResource expired = cms.createResource(expired01, CmsResourceTypeXmlPage.getStaticTypeId()); 136 cms.chacc(expired01, I_CmsPrincipal.PRINCIPAL_USER, fry.getName(), "+s"); 137 cms.setDateExpired(expired01, inFiveDays.getTimeInMillis(), false); 138 139 String expired02 = "folder1/expired02.html"; 140 cms.createResource(expired02, CmsResourceTypeXmlPage.getStaticTypeId()); 141 cms.chacc(expired02, I_CmsPrincipal.PRINCIPAL_USER, fry.getName(), "+s"); 142 cms.setDateExpired(expired02, inEightDays.getTimeInMillis(), false); 143 144 String expired03 = "folder1/expired03.html"; 145 cms.createResource(expired03, CmsResourceTypeXmlPage.getStaticTypeId()); 146 cms.chacc(expired03, I_CmsPrincipal.PRINCIPAL_USER, fry.getName(), "+s"); 147 cms.setDateExpired(expired03, oneDayBefore.getTimeInMillis(), false); 148 149 String released01 = "folder1/released01.html"; 150 CmsResource released = cms.createResource(released01, CmsResourceTypeXmlPage.getStaticTypeId()); 151 cms.chacc(released01, I_CmsPrincipal.PRINCIPAL_USER, fry.getName(), "+s"); 152 cms.setDateReleased(released01, inFiveDays.getTimeInMillis(), false); 153 154 String released02Name = "folder1/released02.html"; 155 cms.createResource(released02Name, CmsResourceTypeXmlPage.getStaticTypeId()); 156 cms.chacc(released02Name, I_CmsPrincipal.PRINCIPAL_USER, fry.getName(), "+s"); 157 cms.setDateReleased(released02Name, inEightDays.getTimeInMillis(), false); 158 159 String released03 = "folder1/released03.html"; 160 cms.createResource(released03, CmsResourceTypeXmlPage.getStaticTypeId()); 161 cms.chacc(released03, I_CmsPrincipal.PRINCIPAL_USER, fry.getName(), "+s"); 162 cms.setDateReleased(released03, oneDayBefore.getTimeInMillis(), false); 163 164 cms.lockResource(folder); 165 cms.writePropertyObject(folder, new CmsProperty( 166 CmsPropertyDefinition.PROPERTY_ENABLE_NOTIFICATION, CmsStringUtil.TRUE, CmsStringUtil.TRUE)); 167 cms.unlockResource(folder); 168 cms.publishProject(); 169 Iterator notifications = new CmsNotificationCandidates(cms).getContentNotifications().iterator(); 170 while (notifications.hasNext()) { 172 CmsContentNotification notification = (CmsContentNotification)notifications.next(); 173 assertTrue(notification.getResponsible().equals(fry)); Collection notificationCauses = notification.getNotificationCauses(); 175 assertTrue(notificationCauses.contains(new CmsExtendedNotificationCause(expired, 176 CmsExtendedNotificationCause.RESOURCE_EXPIRES, new Date (expired.getDateExpired())))); 177 assertTrue(notificationCauses.contains(new CmsExtendedNotificationCause(released, 178 CmsExtendedNotificationCause.RESOURCE_RELEASE, new Date (released.getDateReleased())))); 179 assertEquals(notificationCauses.size(), 2); 181 } 182 } 183 } | Popular Tags |