1   /**
2    * BSD-style license; for more info see http://xradar.sourceforge.net/license.html
3    */
4   package org.sourceforge.xradar;
5   
6   import org.junit.After;
7   import static org.junit.Assert.assertTrue;
8   import org.junit.Before;
9   
10  import java.io.File;
11  import java.io.IOException;
12  import java.net.MalformedURLException;
13  
14  
15  /**
16   * @author zahir NUCKCHADY
17   *
18   */
19  public abstract class AbstractTestForCommandLine {
20  
21  	protected final String targetDirectory = "target";
22  	protected String testProductsDirectory;
23  	protected String target;
24  	
25  	
26  	@Before
27  	public void createResultDirectory() {
28  		File targetDirectoryFile = new File(targetDirectory);
29  		if (   ! targetDirectoryFile.exists() ) 
30  			assertTrue(targetDirectoryFile.mkdir());
31  		File targetFile = new File(target);
32  		if (   ! targetFile.exists() ) 
33  			assertTrue(targetFile.mkdir());
34  		
35  	}
36  	
37  	@After
38  	public void deleteResultDirectory() {
39  		File targetFile = new File(targetDirectory);
40  		if ( targetFile.exists() )
41  			targetFile.delete();
42  	}
43  	/**
44  	 * <p>A handy method to run XRadar with a set of argument, plus
45  	 * an appropriate awaited message in case of failure.Otherwise 
46  	 * return true/p>
47  	 * 
48  	 * @param arg
49  	 * @param expectedMessage
50  	 * @return
51  	 * @throws MalformedURLException
52  	 * @throws IOException
53  	 * @throws XRadarException
54  	 */
55  	protected boolean runRadar(String arg[], String expectedMessage) throws MalformedURLException, IOException, XRadarException {
56  		
57  		try {
58  			XRadarExecute.main(arg);
59  		} catch (IllegalArgumentException e) {
60  			//e.printStackTrace(); 
61  			//System.out.println(e.getMessage().replace(File.separator,  "/"));
62  			return e.getMessage().replace(File.separator,  "/").equals(expectedMessage);
63  		}
64  		return true;
65  	}
66  }