Revision: 3714
Author: [email protected]
Date: Mon Jul 12 15:14:09 2010
Log: Added a test for a forum post that a user cannot load the built in
XSLT transformation in 0.9.16. The new test checks a basic project can be
saved to HTML using the built in template.
This also fixes the regression that you have to save to export to HTML.
http://code.google.com/p/power-architect/source/detail?r=3714
Added:
/trunk/regress/ca/sqlpower/architect/transformation/XsltTransformationTest.java
Modified:
/trunk/src/main/java/ca/sqlpower/architect/transformation/XsltTransformation.java
=======================================
--- /dev/null
+++
/trunk/regress/ca/sqlpower/architect/transformation/XsltTransformationTest.java
Mon Jul 12 15:14:09 2010
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2010, SQL Power Group Inc.
+ *
+ * This file is part of SQL Power Architect.
+ *
+ * SQL Power Architect is free software; you can redistribute it and/or
modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * SQL Power Architect is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package ca.sqlpower.architect.transformation;
+
+import java.io.File;
+
+import junit.framework.TestCase;
+import ca.sqlpower.architect.swingui.ArchitectSwingSession;
+import ca.sqlpower.architect.swingui.ArchitectSwingSessionContextImpl;
+import ca.sqlpower.architect.transformation.ReportTransformer;
+import ca.sqlpower.architect.transformation.TransformerFactory;
+import ca.sqlpower.sqlobject.SQLColumn;
+import ca.sqlpower.sqlobject.SQLDatabase;
+import ca.sqlpower.sqlobject.SQLTable;
+
+public class XsltTransformationTest extends TestCase {
+
+ /**
+ * Tests the export panel can compile the built in template and can
export a
+ * simple session.
+ */
+ public void testExportSimpleSession() throws Exception {
+ ArchitectSwingSessionContextImpl context = new
ArchitectSwingSessionContextImpl("pl.regression.ini", false);
+ ArchitectSwingSession session = context.createSession(false);
+
+ //XXX Still an issue
+ session.getProjectLoader().setFile(File.createTempFile("Garbage
test file", ""));
+
+ SQLDatabase db = session.getTargetDatabase();
+ SQLTable table = new SQLTable(db, true);
+ table.setName("Test table");
+ db.addTable(table);
+ SQLColumn col = new SQLColumn();
+ col.setName("Testing col");
+ table.addColumn(col);
+
+
+ final ReportTransformer transformer;
+ transformer = TransformerFactory.getTransformer(null);
+
+ File output = File.createTempFile("TestArchitectTransformer", "");
+ transformer.transform("/xsltStylesheets/architect2html.xslt",
output, session);
+
+ assertTrue(output.exists());
+ }
+}
=======================================
---
/trunk/src/main/java/ca/sqlpower/architect/transformation/XsltTransformation.java
Fri Feb 5 14:24:47 2010
+++
/trunk/src/main/java/ca/sqlpower/architect/transformation/XsltTransformation.java
Mon Jul 12 15:14:09 2010
@@ -19,6 +19,9 @@
package ca.sqlpower.architect.transformation;
import ca.sqlpower.architect.swingui.ArchitectSwingSession;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
@@ -90,10 +93,14 @@
throws Exception {
File project = session.getProjectLoader().getFile();
- projectDir = project.getParentFile();
- InputStream xml = new FileInputStream(project);
-
- Source xmlSource = new StreamSource(xml);
+ if (project != null) {
+ projectDir = project.getParentFile();
+ }
+
+ ByteArrayOutputStream sessionAsStream = new
ByteArrayOutputStream();
+ session.getProjectLoader().save(sessionAsStream, "utf-8");
+
+ Source xmlSource = new StreamSource(new
ByteArrayInputStream(sessionAsStream.toByteArray()));
Source xsltSource = new StreamSource(xsltStylesheet);
FileOutputStream result = new FileOutputStream(output);
@@ -109,7 +116,6 @@
result.flush();
result.close();
xsltStylesheet.close();
- xml.close();
}
/**