[Jiemamy-notify:2405] commit [3405] [CORE-128] テスト追加。

Back to archive index

svnno****@sourc***** svnno****@sourc*****
2009年 5月 18日 (月) 21:06:33 JST


Revision: 3405
          http://svn.sourceforge.jp/view?root=jiemamy&view=rev&rev=3405
Author:   daisuke_m
Date:     2009-05-18 21:06:33 +0900 (Mon, 18 May 2009)

Log Message:
-----------
[CORE-128] テスト追加。

Modified Paths:
--------------
    artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/composer/exporter/SqlExporterTest.java


-------------- next part --------------
Modified: artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/composer/exporter/SqlExporterTest.java
===================================================================
--- artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/composer/exporter/SqlExporterTest.java	2009-05-18 11:57:19 UTC (rev 3404)
+++ artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/composer/exporter/SqlExporterTest.java	2009-05-18 12:06:33 UTC (rev 3405)
@@ -26,7 +26,12 @@
 import java.io.File;
 import java.io.FileReader;
 
+import org.apache.commons.io.FileUtils;
 import org.apache.commons.io.IOUtils;
+import org.junit.experimental.theories.DataPoints;
+import org.junit.experimental.theories.Theories;
+import org.junit.experimental.theories.Theory;
+import org.junit.runner.RunWith;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -34,20 +39,29 @@
 import org.jiemamy.JiemamyFactory;
 import org.jiemamy.composer.Exporter;
 import org.jiemamy.internal.test.TestModelBuilders;
-import org.jiemamy.internal.test.TestModelsTestBase;
 import org.jiemamy.model.RootModel;
 
 /**
  * {@link SqlExporter}のテストクラス。
  * @author daisuke
  */
-public class SqlExporterTest extends TestModelsTestBase {
+ @ RunWith(Theories.class)
+public class SqlExporterTest {
 	
 	private static Logger logger = LoggerFactory.getLogger(SqlExporterTest.class);
 	
 	/** ${WORKSPACE}/org.jiemamy.composer/target/sqlExporterTest1.sql */
-	private static final String FILENAME = "./target/sqlExporterTest1.sql";
+	private static final File OUTPUT_FILE = new File("./target/sqlExporterTest1.sql");
 	
+	/** ${WORKSPACE}/org.jiemamy.composer/target/notExists/sqlExporterTest2.sql */
+	private static final File OUTPUT_FILE_IN_NOT_EXISTS_DIR = new File("./target/notExists/sqlExporterTest2.sql");
+	
+	private static final File NOT_EXISTS_DIR = new File("./target/notExists");
+	
+	/** モデルビルダの配列 */
+	@DataPoints
+	public static final TestModelBuilders[] builders = TestModelBuilders.values();
+	
 	/** テスト対象のエクスポータ */
 	private Exporter<SqlExportConfig> exporter = new SqlExporter();
 	
@@ -55,16 +69,16 @@
 	/**
 	 * モデルからSQLファイルがエクスポートできることを確認する。
 	 * 
+	 * @param entry モデルビルダ
 	 * @throws Exception 例外が発生した場合
 	 */
-	@Override
+	@Theory
 	public void doTest(TestModelBuilders entry) throws Exception {
 		Jiemamy jiemamy = entry.getBuiltModel();
 		JiemamyFactory factory = jiemamy.getFactory();
 		
-		File outputFile = new File(FILENAME);
-		deleteFile(outputFile);
-		assertThat(outputFile.exists(), is(false));
+		deleteFile(OUTPUT_FILE);
+		assertThat(OUTPUT_FILE.exists(), is(false));
 		
 		RootModel model = factory.getRootModel();
 		model.setDialectClassName("org.jiemamy.dialect.mysql.MySqlDialect");
@@ -72,13 +86,13 @@
 		BufferedReader reader = null;
 		try {
 			DefaultSqlExportConfig config = new DefaultSqlExportConfig();
-			config.setOutputFile(outputFile);
+			config.setOutputFile(OUTPUT_FILE);
 			config.setOverwrite(true);
 			exporter.exportModel(model, config);
 			
-			assertThat(outputFile.exists(), is(true));
+			assertThat(OUTPUT_FILE.exists(), is(true));
 			
-			reader = new BufferedReader(new FileReader(outputFile));
+			reader = new BufferedReader(new FileReader(OUTPUT_FILE));
 			String line;
 			while ((line = reader.readLine()) != null) {
 				logger.info(line);
@@ -91,12 +105,51 @@
 		}
 	}
 	
-	private void deleteFile(File outputFile) {
-		if (outputFile.exists() == false) {
+	/**
+	 * モデルからSQLファイルがエクスポートできることを確認する。
+	 * 
+	 * @param entry モデルビルダ
+	 * @throws Exception 例外が発生した場合
+	 */
+	@Theory
+	public void doTest2(TestModelBuilders entry) throws Exception {
+		Jiemamy jiemamy = entry.getBuiltModel();
+		JiemamyFactory factory = jiemamy.getFactory();
+		
+		FileUtils.deleteDirectory(NOT_EXISTS_DIR);
+		assertThat(NOT_EXISTS_DIR.exists(), is(false));
+		
+		RootModel model = factory.getRootModel();
+		model.setDialectClassName("org.jiemamy.dialect.mysql.MySqlDialect");
+		
+		BufferedReader reader = null;
+		try {
+			DefaultSqlExportConfig config = new DefaultSqlExportConfig();
+			config.setOutputFile(OUTPUT_FILE_IN_NOT_EXISTS_DIR);
+			config.setOverwrite(true);
+			exporter.exportModel(model, config);
+			
+			assertThat(OUTPUT_FILE_IN_NOT_EXISTS_DIR.exists(), is(true));
+			
+			reader = new BufferedReader(new FileReader(OUTPUT_FILE_IN_NOT_EXISTS_DIR));
+			String line;
+			while ((line = reader.readLine()) != null) {
+				logger.info(line);
+			}
+			
+			// UNDONE sqlExporterTest2.sqlの内容確認
+			
+		} finally {
+			IOUtils.closeQuietly(reader);
+		}
+	}
+	
+	private void deleteFile(File file) {
+		if (file.exists() == false) {
 			return;
 		}
-		if (outputFile.delete() == false) {
-			fail("Cannot delete file: " + outputFile.getPath());
+		if (file.delete() == false) {
+			fail("Cannot delete file: " + file.getPath());
 		}
 	}
 }



Jiemamy-notify メーリングリストの案内
Back to archive index