Skip to content

Commit

Permalink
Add html generator tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
nakag committed Apr 30, 2019
1 parent 6a861d3 commit 70871ef
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 23 deletions.
3 changes: 2 additions & 1 deletion tests/tmdmaker.ui.test/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ Require-Bundle: org.eclipse.swtbot.eclipse.finder,
org.eclipse.swtbot.e4.finder,
tmdmaker.imagegenerator,
tmdmaker.sphinx,
tmdmaker.ddlgenerator
tmdmaker.ddlgenerator,
tmdmaker.htmlgenerator
Automatic-Module-Name: tmdmaker.ui.test
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
package jp.sourceforge.tmdmaker.ui.editor;

import java.io.File;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

import org.eclipse.core.runtime.Platform;
import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
Expand All @@ -27,8 +24,6 @@
import org.junit.runner.RunWith;

import jp.sourceforge.tmdmaker.generate.ddl.DdlUtilsDDLGenerator;
import jp.sourceforge.tmdmaker.model.AbstractEntityModel;
import jp.sourceforge.tmdmaker.model.Entity;

/**
* TMD-MakerのDdlUtilsDDLGeneratorテスト.
Expand All @@ -41,6 +36,7 @@
@RunWith(SWTBotJunit4ClassRunner.class)
public class DDLGeneratorTest extends AbstractUITest {
DdlUtilsDDLGenerator generator;
String rootDir;

@Override
public void setUp() throws Exception {
Expand All @@ -54,15 +50,13 @@ public void setUp() throws Exception {
sleep();
wait.waitFor(10);
generator = new DdlUtilsDDLGenerator();
rootDir = Platform.getInstanceLocation().getURL().getPath() + projectName();
}

@Test
public void notSelectDatabase() {
try {
Entity e = (Entity) tmdEditor.getRootModel().getChildren().get(0);
List<AbstractEntityModel> list = Arrays.asList(e);
String rootDir = Platform.getInstanceLocation().getURL().getPath() + projectName();
generator.execute(rootDir, list);
generator.execute(rootDir, tmdEditor.getRootModel().findEntityModel());
} catch (RuntimeException e) {
return;
}
Expand All @@ -81,12 +75,7 @@ public void generateTest() {
bot.button("OK").click();
sleep();

List<AbstractEntityModel> list = tmdEditor.getRootModel().getChildren().stream()
.filter(m -> m instanceof AbstractEntityModel).map(m -> (AbstractEntityModel) m)
.collect(Collectors.toList());

String rootDir = Platform.getInstanceLocation().getURL().getPath() + projectName();
generator.execute(rootDir, list);
generator.execute(rootDir, tmdEditor.getRootModel().findEntityModel());
String docPath = rootDir + File.separator + "ddl.sql";
assertEquals(true, new File(docPath).exists());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* Copyright 2009-2019 TMD-Maker Project <https://tmdmaker.osdn.jp/>
*
* 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 jp.sourceforge.tmdmaker.ui.editor;

import java.io.File;

import org.eclipse.core.runtime.Platform;
import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
import org.junit.Test;
import org.junit.runner.RunWith;

import jp.sourceforge.tmdmaker.generate.html.attributelist.AttributeListHtmlGenerator;
import jp.sourceforge.tmdmaker.generate.html.keydefinitionlist.KeyDefinitionListHtmlGenerator;
import jp.sourceforge.tmdmaker.generate.html.relationshiplist.RelationshipListHtmlGenerator;

/**
* TMD-MakerのHtmlGeneratorテスト.
*
* SWTBotがMessageDialogに対応していないので内部クラスを直接実行している.
*
* @author nakag
*
*/
@RunWith(SWTBotJunit4ClassRunner.class)
public class HtmlGeneratorTest extends AbstractUITest {
String rootDir;

@Override
public void setUp() throws Exception {
super.setUp();
createEntity(50, 50, "顧客番号", 0);
createEntity(300, 50, "商品番号", 0);
// R:R 対照表
botEditor.activateTool("Relationship");
botEditor.click(55, 55);
botEditor.click(305, 55);
sleep();
wait.waitFor(10);
rootDir = Platform.getInstanceLocation().getURL().getPath() + projectName();
}

@Test
public void attributeListTest() {
AttributeListHtmlGenerator generator = new AttributeListHtmlGenerator();
generator.execute(rootDir, tmdEditor.getRootModel().findEntityModel());
String docPath = rootDir + File.separator + "attribute_list.html";
assertEquals(true, new File(docPath).exists());
}

@Test
public void keyListTest() {
KeyDefinitionListHtmlGenerator generator = new KeyDefinitionListHtmlGenerator();
generator.execute(rootDir, tmdEditor.getRootModel().findEntityModel());
String docPath = rootDir + File.separator + "key_list.html";
assertEquals(true, new File(docPath).exists());
}

@Test
public void relationshipListTest() {
RelationshipListHtmlGenerator generator = new RelationshipListHtmlGenerator();
generator.execute(rootDir, tmdEditor.getRootModel().findEntityModel());
String docPath = rootDir + File.separator + "relationship_list.html";
assertEquals(true, new File(docPath).exists());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,12 @@
package jp.sourceforge.tmdmaker.ui.editor;

import java.io.File;
import java.util.Arrays;
import java.util.List;

import org.eclipse.core.runtime.Platform;
import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
import org.junit.Test;
import org.junit.runner.RunWith;

import jp.sourceforge.tmdmaker.model.AbstractEntityModel;
import jp.sourceforge.tmdmaker.model.Entity;
import jp.sourceforge.tmdmaker.sphinx.generate.DocGenerator;

/**
Expand All @@ -44,16 +40,20 @@ public class SphinxGeneratorTest extends AbstractUITest {
public void setUp() throws Exception {
super.setUp();
createEntity(50, 50, "顧客番号", 0);
createEntity(300, 50, "商品番号", 0);
// R:R 対照表
botEditor.activateTool("Relationship");
botEditor.click(55, 55);
botEditor.click(305, 55);
sleep();
wait.waitFor(10);
generator = new DocGenerator();
}

@Test
public void generateTest() {
Entity e = (Entity) tmdEditor.getRootModel().getChildren().get(0);
List<AbstractEntityModel> list = Arrays.asList(e);
String rootDir = Platform.getInstanceLocation().getURL().getPath() + projectName();
generator.execute(rootDir, list);
generator.execute(rootDir, tmdEditor.getRootModel().findEntityModel());
String docPath = rootDir + File.separator + "doc";
assertEquals(true, new File(docPath).exists());
}
Expand Down

0 comments on commit 70871ef

Please sign in to comment.