1 17 package org.alfresco.repo.search.impl.lucene; 18 19 import java.io.File ; 20 21 import org.alfresco.repo.search.impl.lucene.LuceneIndexerAndSearcherFactory.LuceneIndexBackupComponent; 22 import org.alfresco.repo.security.authentication.AuthenticationComponent; 23 import org.alfresco.service.cmr.repository.NodeService; 24 import org.alfresco.service.transaction.TransactionService; 25 import org.alfresco.util.ApplicationContextHelper; 26 import org.alfresco.util.TempFileProvider; 27 import org.springframework.context.ApplicationContext; 28 29 import junit.framework.TestCase; 30 31 36 public class LuceneIndexBackupComponentTest extends TestCase 37 { 38 private static ApplicationContext ctx = ApplicationContextHelper.getApplicationContext(); 39 40 private LuceneIndexBackupComponent backupComponent; 41 private File tempTargetDir; 42 43 private AuthenticationComponent authenticationComponent; 44 45 @Override 46 public void setUp() throws Exception 47 { 48 TransactionService transactionService = (TransactionService) ctx.getBean("transactionComponent"); 49 NodeService nodeService = (NodeService) ctx.getBean("NodeService"); 50 LuceneIndexerAndSearcherFactory factory = (LuceneIndexerAndSearcherFactory) ctx.getBean("luceneIndexerAndSearcherFactory"); 51 52 this.authenticationComponent = (AuthenticationComponent)ctx.getBean("authenticationComponent"); 53 this.authenticationComponent.setSystemUserAsCurrentUser(); 54 55 tempTargetDir = new File (TempFileProvider.getTempDir(), getName()); 56 tempTargetDir.mkdir(); 57 58 backupComponent = new LuceneIndexBackupComponent(); 59 backupComponent.setTransactionService(transactionService); 60 backupComponent.setFactory(factory); 61 backupComponent.setNodeService(nodeService); 62 backupComponent.setTargetLocation(tempTargetDir.toString()); 63 } 64 65 @Override 66 protected void tearDown() throws Exception 67 { 68 authenticationComponent.clearCurrentSecurityContext(); 69 super.tearDown(); 70 } 71 72 public void testBackup() 73 { 74 backupComponent.backup(); 75 76 assertTrue("Target location doesn't exist", tempTargetDir.exists()); 78 } 79 } 80 | Popular Tags |