Menu

Commit [r2599]  Maximize  Restore  History

Added test class for HeadlessJavaGenerator

hotzst 2009-10-03

added /trunk/ch.sahits.codegen.test/src/ch/sahits/codegen/java/wizards/HeadlessJavaGeneratorTest.java
/trunk/ch.sahits.codegen.test/src/ch/sahits/codegen/java/wizards/HeadlessJavaGeneratorTest.java Diff Switch to side-by-side view
--- a
+++ b/trunk/ch.sahits.codegen.test/src/ch/sahits/codegen/java/wizards/HeadlessJavaGeneratorTest.java
@@ -0,0 +1,112 @@
+package ch.sahits.codegen.java.wizards;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Properties;
+
+import junit.framework.Assert;
+
+import org.eclipse.core.runtime.CoreException;
+import org.jdom.JDOMException;
+import org.junit.Before;
+import org.junit.Test;
+
+import ch.sahits.codegen.test.PropertyFileLoader;
+import ch.sahits.codegen.util.ERunAsType;
+import ch.sahits.codegen.util.RunAs;
+import ch.sahits.test.ComparetorResult;
+import ch.sahits.test.FileComparator;
+@RunAs(ERunAsType.PLUGIN)
+public class HeadlessJavaGeneratorTest  extends PropertyFileLoader{
+	private static String tempdir;
+	private String oracleInputFile;
+	private static String outDir;
+
+	private String[] help;
+	private String[] jetemplate;
+	private String[] serialize;
+	private String[] deserialize;
+	
+	public HeadlessJavaGeneratorTest() {
+		Properties prop = loadFile("fragments/headlessgeneral.properties");
+		tempdir=prop.getProperty("tempdir2");
+		outDir=tempdir+File.separator+"src";
+		oracleInputFile=prop.getProperty("inputfile");
+	}
+	@Override
+	protected Properties loadFile(String fileName) {
+		Properties prop = new Properties();
+		try {
+			URL url = new File(fileName).toURI().toURL();
+			final InputStream input = url.openStream();
+			prop.load(input);
+		} catch (MalformedURLException e) {
+			e.printStackTrace();
+		} catch (IOException e) {
+			e.printStackTrace();
+		}
+		return prop;
+	}
+
+	@Before
+	public void setUp() throws Exception {
+		help = new String[]{"help"};
+		jetemplate = new String[]{"-src",tempdir,"-pk","ch.sahits","-cl","Foo","-mod","PUB","-m","JT","-i","WDB","-f",oracleInputFile,"-j","ch.sahits.codegen.java@jet_templates/dbbean.javajet","-p","ORACLE"};
+		//deserialize = new String[]{"-l",serializedSQLs};
+	}
+	/**
+	 * Test the print out on the console. Visual verification
+	 */
+	public void testPrintUsage(){
+		try {
+			new HeadlessJavaGenerator().run(help);
+		} catch (FileNotFoundException e) {
+			Assert.fail(e.getMessage());
+		} catch (IOException e) {
+			Assert.fail(e.getMessage());
+		} catch (ClassNotFoundException e) {
+			Assert.fail(e.getMessage());
+		} catch (CoreException e) {
+			Assert.fail(e.getMessage());
+		} catch (JDOMException e) {
+			Assert.fail("No serialisation should take place");
+		}
+	}
+
+	/**
+	 * Test the generation of the sql scipt
+	 */
+	@Test
+	public void testGenerationJETemplate(){
+		try {
+			new HeadlessJavaGenerator().run(jetemplate);
+		} catch (FileNotFoundException e1) {
+			Assert.fail(e1.getMessage());
+		} catch (IOException e1) {
+			Assert.fail(e1.getMessage());
+		} catch (ClassNotFoundException e1) {
+			Assert.fail(e1.getMessage());
+		} catch (CoreException e1) {
+			Assert.fail(e1.getMessage());
+		} catch (JDOMException e) {
+			Assert.fail("No serialisation should take place");
+		}
+		String outputFile = outDir+File.separator+"ch"+File.separator+"sahits"+File.separator+"Foo.java";
+		ComparetorResult expected = ComparetorResult.TRUE;
+		try {
+			FileComparator comp = new FileComparator(outputFile);
+			ComparetorResult actual = comp.equals("fragments/headless_test/Foo1.java");
+			Assert.assertEquals(expected, actual);
+		} catch (FileNotFoundException e) {
+			e.printStackTrace();
+			Assert.fail(e.getMessage());
+		} catch (IOException e) {
+			Assert.fail(e.getMessage());
+		}
+	}
+
+}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.