@Test
public void testExecute() throws Exception
{
JdbcMetadataSource source
= new JdbcMetadataSource(DRIVER, URL, null, null, null);
SourceElement rootElement = source.createRootElement();
assertEquals("database", rootElement.getName());
List<SourceElement> tableElements = rootElement.getChildren();
assertEquals(2, tableElements.size());
for (SourceElement tableElement : tableElements)
{
assertEquals("table", tableElement.getName());
Object tableName = tableElement.getAttribute("name");
if ("AUTHOR".equals(tableName))
{
List<SourceElement> columnElements
= tableElement.getChildren();
assertEquals(2, columnElements.size());
for (SourceElement columnElement : columnElements)
{
assertEquals("column", columnElement.getName());
Object columnName = columnElement.getAttribute("name");
if ("AUTHOR_ID".equals(columnName))
{
assertEquals(
"true",
columnElement.getAttribute("primaryKey"));
assertNull(columnElement.getAttribute("required"));
assertEquals(
"INTEGER",
columnElement.getAttribute("type"));
assertNull(columnElement.getAttribute("size"));
assertNull(columnElement.getAttribute("scale"));
// do not check default value as it is currently
// not generated correctly
// assertNull(columnElement.getAttribute("default"));
}
else if ("NAME".equals(columnName))
{
assertNull(columnElement.getAttribute("primaryKey"));
assertEquals(
"true",
columnElement.getAttribute("required"));
assertEquals(
"VARCHAR",
columnElement.getAttribute("type"));
assertEquals(
"50",
columnElement.getAttribute("size"));
assertNull(columnElement.getAttribute("scale"));
assertNull(columnElement.getAttribute("default"));
}
else
{
fail("Unknown column : " + columnName);
}
}
}
else if ("BOOK".equals(tableName))
{
assertEquals(5, tableElement.getChildren().size());
List<SourceElement> columnElements
= tableElement.getChildren("column");
assertEquals(4, columnElements.size());
for (SourceElement columnElement : columnElements)
{
assertEquals("column", columnElement.getName());
Object columnName = columnElement.getAttribute("name");
if ("BOOK_ID".equals(columnName))
{
assertEquals(
"true",
columnElement.getAttribute("primaryKey"));
assertNull(columnElement.getAttribute("required"));
assertEquals(
"INTEGER",
columnElement.getAttribute("type"));
assertNull(columnElement.getAttribute("size"));
assertNull(columnElement.getAttribute("scale"));
// do not check default value as it is currently
// not generated correctly
// assertNull(columnElement.getAttribute("default"));
}
else if ("ISBN".equals(columnName))
{
assertNull(columnElement.getAttribute("primaryKey"));
assertNull(columnElement.getAttribute("required"));
assertEquals(
"VARCHAR",
columnElement.getAttribute("type"));
assertEquals(
"15",
columnElement.getAttribute("size"));
assertNull(columnElement.getAttribute("scale"));
assertNull(columnElement.getAttribute("default"));
}
else if ("AUTHOR_ID".equals(columnName))
{
assertNull(columnElement.getAttribute("primaryKey"));
assertEquals(
"true",
columnElement.getAttribute("required"));
assertEquals(
"INTEGER",
columnElement.getAttribute("type"));
assertNull(columnElement.getAttribute("size"));
assertNull(columnElement.getAttribute("scale"));
assertNull(columnElement.getAttribute("default"));
}
else if ("TITLE".equals(columnName))
{
assertNull(columnElement.getAttribute("primaryKey"));
assertEquals(
"true",
columnElement.getAttribute("required"));
assertEquals(
"VARCHAR",
columnElement.getAttribute("type"));
assertEquals(
"255",
columnElement.getAttribute("size"));
assertNull(columnElement.getAttribute("scale"));
assertEquals(
"no title",
columnElement.getAttribute("default"));
}
else
{
fail("Unknown column : " + columnName);
}
}
List<SourceElement> foreignKeyElements
= tableElement.getChildren("foreign-key");
assertEquals(1, foreignKeyElements.size());
SourceElement foreignKeyElement = foreignKeyElements.get(0);
assertEquals(
"AUTHOR",
foreignKeyElement.getAttribute("foreignTable"));
}
else
{
fail("Unknown table : " + tableName);
}