1   /********************************************************************************
2    *InternetCafe is a software solution that helps the management of Cybercafes 
3    * according with the ITALIAN DECREE LAW ON ANTI-TERROR MEASURES, 27 JULY 2005.
4    * Copyright (C) 2006  Guido Angelo Ingenito
5   
6    * This program is free software; you can redistribute it and/or
7    * modify it under the terms of the GNU General Public License
8    * as published by the Free Software Foundation; either version 2
9    * of the License, or (at your option) any later version.
10  
11   * This program is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   * GNU General Public License for more details.
15   * 
16   * You should have received a copy of the GNU General Public License
17   * along with this program; if not, write to the Free Software
18   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19   *******************************************************************************/
20  
21  package test.base.jdbs;
22  
23  import java.io.File;
24  import java.io.IOException;
25  
26  import javax.xml.parsers.ParserConfigurationException;
27  import javax.xml.transform.TransformerException;
28  import javax.xml.transform.TransformerFactoryConfigurationError;
29  
30  import junit.framework.TestCase;
31  
32  import org.apache.log4j.Logger;
33  
34  import base.util.FileUtil;
35  
36  public class BackupArtifactDisassemblerTest extends TestCase {
37  
38  	private static final transient Logger logger = Logger.getLogger(BackupArtifactDisassemblerTest.class.getName());
39  		
40  	/*
41  	 * Test method for 'base.jdbs.BackupArtifactDisassembler.disassemblyBackupArtifact(SymmetricKey, KeyPair, BackupDescriptor, File)'
42  	 */
43  	public void testDisassemblyBackupArtifact() throws IOException, ParserConfigurationException, TransformerFactoryConfigurationError, TransformerException {
44  	
45  		//Lets delete all backup in the repository folder.
46  		synchronized(AllTests.getRepository()){
47  			FileUtil.deleteDirectory(AllTests.getRepository().getLocation());
48  			assertFalse(AllTests.getRepository().getLocation().exists());
49  			//Creating again the Repository Dir.
50  			AllTests.getRepository().getLocation().mkdirs();
51  			assertTrue(AllTests.getRepository().getLocation().exists());
52  			assertTrue(AllTests.getRepository().getLocation().isDirectory());
53  		}
54  		
55  		//creating a sample backup
56  		new BackupArtifactAssemblerTest().testBuildNewBackupArtifact();
57  		
58  		//lets index the repository to retrieve the backup created so far
59  		AllTests.getRepository().indexRepository();
60  		if( AllTests.getRepository().getBackupDescriptor().length > 0){
61  			base.jdbs.BackupArtifactDisassembler.disassemblyBackupArtifact(AllTests.getSymmetricKey(), AllTests.getAsymmetricKeyRing().getKeyPair(1), AllTests.getRepository().getBackupDescriptor()[0],new File(AllTests.BACKUP_DISASSEMBLY_OUTPUT_DIRECTORY_PATH));
62  		}else logger.warn("The repository doesn't contains backup artifacts. Skipping BackupArtifactDisassemblerTest!");
63  
64  	}
65  
66  }