svnno****@sourc*****
svnno****@sourc*****
2009年 4月 4日 (土) 16:45:40 JST
Revision: 3099 http://svn.sourceforge.jp/view?root=jiemamy&view=rev&rev=3099 Author: daisuke_m Date: 2009-04-04 16:45:40 +0900 (Sat, 04 Apr 2009) Log Message: ----------- TestModelBuilderを使ったテストを改善。 Modified Paths: -------------- artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/composer/exporter/SqlExporterTest.java artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/dialect/DefaultSqlEmitterTest.java artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/utils/model/AttributeUtilTest.java Added Paths: ----------- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/internal/test/TestModelBuilderProvider.java artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/internal/test/TestModelEntry.java artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/internal/test/TestModelsTestBase.java -------------- next part -------------- Added: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/internal/test/TestModelBuilderProvider.java =================================================================== --- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/internal/test/TestModelBuilderProvider.java (rev 0) +++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/internal/test/TestModelBuilderProvider.java 2009-04-04 07:45:40 UTC (rev 3099) @@ -0,0 +1,65 @@ +/* + * Copyright 2007-2009 Jiemamy Project and the Others. + * Created on 2009/04/04 + * + * This file is part of Jiemamy. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific language + * governing permissions and limitations under the License. + */ +package org.jiemamy.internal.test; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Iterator; +import java.util.List; + +import org.apache.commons.io.IOUtils; +import org.apache.commons.lang.CharEncoding; + +import org.jiemamy.Artemis; +import org.jiemamy.Jiemamy; +import org.jiemamy.utils.CollectionsUtil; + +/** + * TODO for daisuke + * + * @author daisuke + */ +public class TestModelBuilderProvider implements Iterable<TestModelEntry> { + + private List<TestModelEntry> entries = CollectionsUtil.newArrayList(); + + + /** + * インスタンスを生成する。 + * + * @throws IOException + */ + public TestModelBuilderProvider() throws IOException { + entries.add(new TestModelEntry("EMP-DEPT", new CoreTestModelBuilder(newJiemamy()), getXml("/sample.xml"))); + entries.add(new TestModelEntry("ORDER", new CoreTestModelBuilder2(newJiemamy()), getXml("/sample.xml"))); + } + + public Iterator<TestModelEntry> iterator() { + return entries.iterator(); + } + + private String getXml(String path) throws IOException { + InputStream in = TestModelBuilderProvider.class.getResourceAsStream(path); + return IOUtils.toString(in, CharEncoding.UTF_8); + } + + private Jiemamy newJiemamy() { + return Jiemamy.newInstance(new Artemis(), new ReflectionDialectProvider()); + } +} Property changes on: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/internal/test/TestModelBuilderProvider.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/internal/test/TestModelEntry.java =================================================================== --- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/internal/test/TestModelEntry.java (rev 0) +++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/internal/test/TestModelEntry.java 2009-04-04 07:45:40 UTC (rev 3099) @@ -0,0 +1,74 @@ +/* + * Copyright 2007-2009 Jiemamy Project and the Others. + * Created on 2009/04/04 + * + * This file is part of Jiemamy. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific language + * governing permissions and limitations under the License. + */ +package org.jiemamy.internal.test; + +import org.jiemamy.Jiemamy; + +/** + * TODO for daisuke + * + * @author daisuke + */ +public class TestModelEntry { + + private final String name; + + private final TestModelBuilder tmb; + + private final String xml; + + + /** + * インスタンスを生成する。 + * @param name + * + * @param tmb + * @param xml + */ + public TestModelEntry(String name, TestModelBuilder tmb, String xml) { + this.name = name; + this.tmb = tmb; + this.xml = xml; + } + + /** + * TODO for daisuke + * @return the tmb + */ + public Jiemamy getBuiltModel() { + return tmb.build(); + } + + /** + * TODO for daisuke + * @return the name + */ + public String getName() { + return name; + } + + /** + * TODO for daisuke + * @return the xml + */ + public String getXml() { + return xml; + } + +} Property changes on: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/internal/test/TestModelEntry.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/internal/test/TestModelsTestBase.java =================================================================== --- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/internal/test/TestModelsTestBase.java (rev 0) +++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/internal/test/TestModelsTestBase.java 2009-04-04 07:45:40 UTC (rev 3099) @@ -0,0 +1,79 @@ +/* + * Copyright 2007-2009 Jiemamy Project and the Others. + * Created on 2009/04/04 + * + * This file is part of Jiemamy. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific language + * governing permissions and limitations under the License. + */ +package org.jiemamy.internal.test; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * TODO for daisuke + * + * @author daisuke + */ +public abstract class TestModelsTestBase { + + private static Logger logger = LoggerFactory.getLogger(TestModelsTestBase.class); + + private TestModelBuilderProvider provider; + + + /** + * TODO for daisuke + * + * @param entry + * @throws Exception + */ + public abstract void doTest(TestModelEntry entry) throws Exception; + + /** + * テストを初期化する。 + * + * @throws Exception 例外が発生した場合 + */ + @Before + public void setUp() throws Exception { + provider = new TestModelBuilderProvider(); + } + + /** + * テストの情報を破棄する。 + * + * @throws Exception 例外が発生した場合 + */ + @After + public void tearDown() throws Exception { + provider = null; + } + + /** + * TODO for daisuke + * + * @throws Exception 例外が発生した場合 + */ + @Test + public void testAllEntries() throws Exception { + for (TestModelEntry entry : provider) { + logger.info("==== Test Model: " + entry.getName()); + doTest(entry); + } + } +} Property changes on: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/internal/test/TestModelsTestBase.java ___________________________________________________________________ Added: svn:mime-type + text/plain 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-04-04 06:50:37 UTC (rev 3098) +++ artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/composer/exporter/SqlExporterTest.java 2009-04-04 07:45:40 UTC (rev 3099) @@ -27,25 +27,21 @@ import java.io.FileReader; import org.apache.commons.io.IOUtils; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.jiemamy.Artemis; import org.jiemamy.Jiemamy; import org.jiemamy.JiemamyFactory; import org.jiemamy.composer.Exporter; -import org.jiemamy.internal.test.ReflectionDialectProvider; -import org.jiemamy.internal.test.CoreTestModelBuilder; +import org.jiemamy.internal.test.TestModelEntry; +import org.jiemamy.internal.test.TestModelsTestBase; import org.jiemamy.model.RootModel; /** * {@link SqlExporter}のテストクラス。 * @author daisuke */ -public class SqlExporterTest { +public class SqlExporterTest extends TestModelsTestBase { private static Logger logger = LoggerFactory.getLogger(SqlExporterTest.class); @@ -55,39 +51,17 @@ /** テスト対象のエクスポータ */ private Exporter<SqlExportConfig> exporter = new SqlExporter(); - private JiemamyFactory factory; - /** - * テストを初期化する。 - * - * @throws Exception 例外が発生した場合 - */ - @Before - public void setUp() throws Exception { - Jiemamy jiemamy = Jiemamy.newInstance(new Artemis(), new ReflectionDialectProvider()); - CoreTestModelBuilder mb = new CoreTestModelBuilder(jiemamy); - mb.build(); - factory = jiemamy.getFactory(); - } - - /** - * テストの情報を破棄する。 - * - * @throws Exception 例外が発生した場合 - */ - @After - public void tearDown() throws Exception { - factory = null; - } - - /** * モデルからSQLファイルがエクスポートできることを確認する。 * * @throws Exception 例外が発生した場合 */ - @Test - public void test01_モデルからSQLファイルがエクスポートできることを確認する() throws Exception { + @Override + public void doTest(TestModelEntry entry) throws Exception { + Jiemamy jiemamy = entry.getBuiltModel(); + JiemamyFactory factory = jiemamy.getFactory(); + File outputFile = new File(FILENAME); deleteFile(outputFile); assertThat(outputFile.exists(), is(false)); Modified: artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/dialect/DefaultSqlEmitterTest.java =================================================================== --- artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/dialect/DefaultSqlEmitterTest.java 2009-04-04 06:50:37 UTC (rev 3098) +++ artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/dialect/DefaultSqlEmitterTest.java 2009-04-04 07:45:40 UTC (rev 3099) @@ -20,19 +20,15 @@ import java.util.List; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.jiemamy.Artemis; import org.jiemamy.Jiemamy; import org.jiemamy.dialect.internal.SqlEmitter; import org.jiemamy.dialect.internal.impl.DefaultDataTypeResolver; import org.jiemamy.dialect.internal.impl.DefaultSqlEmitter; -import org.jiemamy.internal.test.ReflectionDialectProvider; -import org.jiemamy.internal.test.CoreTestModelBuilder; +import org.jiemamy.internal.test.TestModelEntry; +import org.jiemamy.internal.test.TestModelsTestBase; import org.jiemamy.model.sql.SqlStatement; import org.jiemamy.utils.model.RootModelUtil; @@ -41,52 +37,28 @@ * * @author daisuke */ -public class DefaultSqlEmitterTest { +public class DefaultSqlEmitterTest extends TestModelsTestBase { private static Logger logger = LoggerFactory.getLogger(DefaultSqlEmitterTest.class); - private Jiemamy jiemamy; - - private SqlEmitter sqlEmitter; - /** - * テストを初期化する。 - * - * @throws Exception 例外が発生した場合 - */ - @Before - public void setUp() throws Exception { - jiemamy = Jiemamy.newInstance(new Artemis(), new ReflectionDialectProvider()); - CoreTestModelBuilder mb = new CoreTestModelBuilder(jiemamy); - mb.build(); - Dialect dialect = RootModelUtil.getDialect(mb.rootModel); - sqlEmitter = new DefaultSqlEmitter(new DefaultDataTypeResolver(dialect.getMoldManager())); - } - - /** - * テストの情報を破棄する。 - * - * @throws Exception 例外が発生した場合 - */ - @After - public void tearDown() throws Exception { - jiemamy = null; - sqlEmitter = null; - } - - /** * 正常にSQLが出力されること。 * * @throws Exception 例外が発生した場合 */ - @Test - public void test01_正常にSQLが出力されること() throws Exception { + @Override + public void doTest(TestModelEntry entry) throws Exception { + Jiemamy jiemamy = entry.getBuiltModel(); + Dialect dialect = RootModelUtil.getDialect(jiemamy.getFactory().getRootModel()); + SqlEmitter sqlEmitter = new DefaultSqlEmitter(new DefaultDataTypeResolver(dialect.getMoldManager())); + List<SqlStatement> statements = sqlEmitter.emit(jiemamy.getFactory().getRootModel(), new MockEmitConfig()); for (SqlStatement sqlStatement : statements) { logger.info(sqlStatement.toString()); // TODO assertion } + } Modified: artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/utils/model/AttributeUtilTest.java =================================================================== --- artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/utils/model/AttributeUtilTest.java 2009-04-04 06:50:37 UTC (rev 3098) +++ artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/utils/model/AttributeUtilTest.java 2009-04-04 07:45:40 UTC (rev 3099) @@ -24,14 +24,9 @@ import java.util.List; import java.util.SortedSet; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import org.jiemamy.Artemis; import org.jiemamy.Jiemamy; -import org.jiemamy.internal.test.ReflectionDialectProvider; -import org.jiemamy.internal.test.CoreTestModelBuilder; +import org.jiemamy.internal.test.TestModelEntry; +import org.jiemamy.internal.test.TestModelsTestBase; import org.jiemamy.model.RootModel; import org.jiemamy.model.attribute.AttributeModel; import org.jiemamy.model.entity.EntityModel; @@ -42,41 +37,17 @@ * * @author daisuke */ -public class AttributeUtilTest { +public class AttributeUtilTest extends TestModelsTestBase { - private CoreTestModelBuilder mb; - - /** - * テストを初期化する。 - * - * @throws Exception 例外が発生した場合 - */ - @Before - public void setUp() throws Exception { - Jiemamy jiemamy = Jiemamy.newInstance(new Artemis(), new ReflectionDialectProvider()); - mb = new CoreTestModelBuilder(jiemamy); - mb.build(); - } - - /** - * テストの情報を破棄する。 - * - * @throws Exception 例外が発生した場合 - */ - @After - public void tearDown() throws Exception { - mb = null; - } - - /** * {@link AttributeUtil#getDefinedTable(AttributeModel)}のテスト。 * * @throws Exception 例外が発生した場合 */ - @Test - public void test01_getDefinedTable() throws Exception { - RootModel rootModel = mb.getJiemamy().getFactory().getRootModel(); + @Override + public void doTest(TestModelEntry entry) throws Exception { + Jiemamy jiemamy = entry.getBuiltModel(); + RootModel rootModel = jiemamy.getFactory().getRootModel(); SortedSet<EntityModel> entities = rootModel.getEntities(); for (EntityModel entityModel : entities) { if (entityModel instanceof TableModel) {