1 17 package org.alfresco.repo.admin.patch; 18 19 import java.util.Date ; 20 import java.util.List ; 21 22 import junit.framework.TestCase; 23 24 import org.alfresco.error.AlfrescoRuntimeException; 25 import org.alfresco.repo.domain.AppliedPatch; 26 import org.alfresco.service.cmr.admin.PatchException; 27 import org.alfresco.service.transaction.TransactionService; 28 import org.alfresco.util.ApplicationContextHelper; 29 import org.springframework.context.ApplicationContext; 30 31 38 public class PatchTest extends TestCase 39 { 40 private static final ApplicationContext ctx = ApplicationContextHelper.getApplicationContext(); 41 42 private TransactionService transactionService; 43 private PatchService patchService; 44 private PatchDaoService patchDaoComponent; 45 46 public PatchTest(String name) 47 { 48 super(name); 49 } 50 51 public void setUp() throws Exception 52 { 53 transactionService = (TransactionService) ctx.getBean("transactionComponent"); 54 patchService = (PatchService) ctx.getBean("PatchService"); 55 patchDaoComponent = (PatchDaoService) ctx.getBean("patchDaoComponent"); 56 57 patchService.registerPatch((Patch)ctx.getBean("patch.sample.02")); 59 patchService.registerPatch((Patch)ctx.getBean("patch.sample.01")); 60 } 61 62 public void testSetup() throws Exception 63 { 64 assertNotNull(transactionService); 65 assertNotNull(patchService); 66 assertNotNull(patchDaoComponent); 67 } 68 69 public void testSimplePatchSuccess() throws Exception 70 { 71 Patch patch = new SamplePatch(false, transactionService); 72 String report = patch.apply(); 73 assertEquals("Patch report incorrect", SamplePatch.MSG_SUCCESS, report); 75 } 76 77 public void testPatchReapplication() 78 { 79 Patch patch = new SamplePatch(false, transactionService); 81 patch.apply(); 82 try 84 { 85 patch.apply(); 86 fail("AbstractPatch failed to prevent reapplication"); 87 } 88 catch (AlfrescoRuntimeException e) 89 { 90 } 92 93 patch = new SamplePatch(true, transactionService); 95 try 96 { 97 patch.apply(); 98 fail("Failed patch didn't throw PatchException"); 99 } 100 catch (PatchException e) 101 { 102 } 104 try 106 { 107 patch.apply(); 108 fail("Reapplication of failed patch didn't throw PatchException"); 109 } 110 catch (PatchException e) 111 { 112 } 114 } 115 116 public void testApplyOutstandingPatches() throws Exception 117 { 118 boolean success = patchService.applyOutstandingPatches(); 120 assertTrue(success); 121 List <AppliedPatch> appliedPatches = patchDaoComponent.getAppliedPatches(); 123 boolean found01 = false; 125 boolean found02 = false; 126 for (AppliedPatch appliedPatch : appliedPatches) 127 { 128 if (appliedPatch.getId().equals("Sample01")) 129 { 130 found01 = true; 131 assertTrue("Patch info didn't indicate success: " + appliedPatch, appliedPatch.getSucceeded()); 132 } 133 else if (appliedPatch.getId().equals("Sample02")) 134 { 135 found02 = true; 136 assertTrue("Patch info didn't indicate success: " + appliedPatch, appliedPatch.getSucceeded()); 137 } 138 } 139 assertTrue("Sample 01 not in list of applied patches", found01); 140 assertTrue("Sample 02 not in list of applied patches", found02); 141 } 142 143 public void testGetPatchesByDate() throws Exception 144 { 145 testApplyOutstandingPatches(); 147 List <AppliedPatch> appliedPatches = patchDaoComponent.getAppliedPatches(); 149 assertTrue("Expected at least 2 applied patches", appliedPatches.size() >= 2); 150 151 List <PatchInfo> appliedPatchesAllDates = patchService.getPatches(null, null); 153 assertEquals("Applied patches by all dates doesn't match all applied patches", 154 appliedPatches.size(), appliedPatchesAllDates.size()); 155 156 PatchInfo disconnectedObject = appliedPatchesAllDates.get(0); 158 AppliedPatch persistedObject = patchDaoComponent.getAppliedPatch(disconnectedObject.getId()); 159 assertNotSame("Instances should not be shared between evicted and cached objects", 160 disconnectedObject, persistedObject); 161 162 List <PatchInfo> appliedPatchesFutureDates = patchService.getPatches(new Date (), new Date ()); 164 assertEquals("Query returned results for dates when no patches should exist", 0, appliedPatchesFutureDates.size()); 165 } 166 } 167 | Popular Tags |