Adding png export test

This commit is contained in:
Pablo Luna 2011-03-25 16:43:53 +00:00
parent c70603d61d
commit 2f3143327c
4 changed files with 188 additions and 0 deletions

View File

View File

@ -0,0 +1,83 @@
<svg focusable="true" id="workspace" width="1600" height="307"
viewBox="-560 -107.44999999999999 1120 214.89999999999998" preserveAspectRatio="none">
<polyline fill="none" stroke-width="1px" stroke="#495879" stroke-opacity="1"
points="-227,-50 -237,-50 -237,-31.5 -242,-26.5 -314.5,-26.5" visibility="visible"/>
<polyline fill="none" stroke-width="1px" stroke="#495879" stroke-opacity="1" points="-227,-50 -300.5,-50.5"
visibility="visible"/>
<polyline fill="none" stroke-width="1px" stroke="#495879" stroke-opacity="1"
points="-227,-50 -237,-50 -237,-69.5 -242,-74.5 -300.5,-74.5" visibility="visible"/>
<line stroke-width="1px" stroke="#495879" x2="-152" y2="-50" x1="0" y1="0" visibility="visible"/>
<rect width="50" height="10" x="5" y="5" stroke-width="1px" stroke="#FF9933" fill="#CC0033" stroke-opacity="0.4"
fill-opacity="0.4" visibility="hidden"/>
<polyline fill="none" stroke-width="1px" stroke="#CC0033" stroke-opacity="0.4" fill-opacity="0.4"
visibility="hidden"/>
<line stroke-width="1px" stroke="#CC0033" stroke-opacity="0.4" fill-opacity="0.4" visibility="hidden"/>
<rect width="50" height="10" x="5" y="5" stroke-width="1px" stroke="#FF9933" fill="#CC0033" stroke-opacity="0.4"
fill-opacity="0.4" visibility="hidden"/>
<g preserveAspectRatio="none" focusable="true" width="100" height="100" transform="translate(-301, -91) scale(1)"
visibility="visible">
<rect width="59" height="23" rx="3.4499999999999997" ry="3.4499999999999997" x="-2" y="-3" stroke-width="1px"
stroke="#77555a" fill="#dbe2e6" stroke-opacity="0" fill-opacity="0"/>
<ellipse width="6" height="6" rx="3" ry="3" cx="3" cy="3" stroke-width="1px" fill="#E0E5EF"
style="cursor: default;" visibility="hidden" stroke="#023BB9"/>
<line stroke-width="1px" stroke="#495879" style="cursor: move;" visibility="hidden" x1="-1" y1="17" x2="56"
y2="17"/>
<text focusable="true" font-family="verdana" font-size="8.0625" font-style="normal" font-weight="normal"
fill="#525c61" style="cursor: move;" y="9" x="6" visibility="visible">Sub Topic
</text>
</g>
<g preserveAspectRatio="none" focusable="true" width="100" height="100" transform="translate(-301, -67) scale(1)"
visibility="visible">
<rect width="59" height="23" rx="3.4499999999999997" ry="3.4499999999999997" x="-2" y="-3" stroke-width="1px"
stroke="#77555a" fill="#dbe2e6" stroke-opacity="0" fill-opacity="0"/>
<ellipse width="6" height="6" rx="3" ry="3" cx="3" cy="3" stroke-width="1px" fill="#E0E5EF"
style="cursor: default;" visibility="hidden" stroke="#023BB9"/>
<line stroke-width="1px" stroke="#495879" style="cursor: move;" visibility="hidden" x1="-1" y1="17" x2="56"
y2="17"/>
<text focusable="true" font-family="verdana" font-size="8.0625" font-style="normal" font-weight="normal"
fill="#525c61" style="cursor: move;" y="9" x="6" visibility="visible">Sub Topic
</text>
</g>
<g preserveAspectRatio="none" focusable="true" width="100" height="100" transform="translate(-315, -43) scale(1)"
visibility="visible">
<rect width="73" height="23" rx="3.4499999999999997" ry="3.4499999999999997" x="-2" y="-3" stroke-width="1px"
stroke="#77555a" fill="#dbe2e6" stroke-opacity="0" fill-opacity="0"/>
<ellipse width="6" height="6" rx="3" ry="3" cx="3" cy="3" stroke-width="1px" fill="#E0E5EF"
style="cursor: default;" visibility="hidden" stroke="#023BB9"/>
<line stroke-width="1px" stroke="#495879" style="cursor: move;" visibility="hidden" x1="-1" y1="17" x2="70"
y2="17"/>
<text focusable="true" font-family="verdana" font-size="8.0625" font-style="normal" font-weight="normal"
fill="#525c61" style="cursor: move;" y="9" x="20" visibility="visible">Sub Topic
</text>
<g preserveAspectRatio="none" focusable="true" width="14" height="12" transform="translate(3, 3) scale(1)">
<image href="../images/world_link.png" width="12" height="12" y="0" x="2"/>
</g>
</g>
<g preserveAspectRatio="none" focusable="true" width="100" height="100" transform="translate(-226, -61) scale(1)"
visibility="visible">
<rect width="80" height="28" rx="4.2" ry="4.2" x="-2" y="-3" stroke-width="1px" stroke="#77555a" fill="#dbe2e6"
stroke-opacity="0" fill-opacity="0"/>
<rect width="76" height="22" rx="3.3" ry="3.3" x="0" y="0" stroke-width="0.5px" stroke="#023BB9" fill="#E0E5EF"
style="cursor: move;"/>
<text focusable="true" font-family="verdana" font-size="10.75" font-style="normal" font-weight="normal"
fill="#525c61" style="cursor: move;" y="12" x="8" visibility="visible">Main Topic
</text>
<ellipse width="6" height="6" rx="3" ry="3" cx="-3" cy="11" stroke-width="1px" fill="#E0E5EF"
style="cursor: default;" visibility="visible" stroke="#023BB9"/>
</g>
<g preserveAspectRatio="none" focusable="true" width="100" height="100" transform="translate(-79, -17) scale(1)"
visibility="visible">
<rect width="163" height="41" rx="6.1499999999999995" ry="6.1499999999999995" x="-2" y="-3" stroke-width="1px"
stroke="#77555a" fill="#c7d8ff" stroke-opacity="1" fill-opacity="1" style="cursor: default;"/>
<rect width="159" height="35" rx="5.25" ry="5.25" x="0" y="0" stroke-width="0.5px" fill="#f7f7f7"
stroke="#023BB9" style="cursor: default;"/>
<text focusable="true" font-family="verdana" font-size="13.4375" font-style="normal" font-weight="bold"
fill="#023BB9" style="cursor: default;" y="19" x="56" visibility="visible">exporttes't
</text>
<g preserveAspectRatio="none" focusable="true" width="38" height="12" transform="translate(9, 9) scale(1)">
<image href="../images/disconnect.png" width="12" height="12" y="0" x="2"/>
<image href="../images/world_link.png" width="12" height="12" y="0" x="14"/>
<image href="../images/note.png" width="12" height="12" y="0" x="26"/>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 6.2 KiB

View File

@ -0,0 +1,104 @@
package com.wisemapping.test.export;
import com.wisemapping.exporter.ExportException;
import com.wisemapping.exporter.ExportFormat;
import com.wisemapping.exporter.ExportProperties;
import com.wisemapping.exporter.freemind.FreemindExporter;
import com.wisemapping.importer.ImportFormat;
import com.wisemapping.importer.Importer;
import com.wisemapping.importer.ImporterException;
import com.wisemapping.importer.ImporterFactory;
import com.wisemapping.model.MindMap;
import com.wisemapping.model.MindMapNative;
import org.apache.batik.transcoder.TranscoderException;
import org.jetbrains.annotations.NotNull;
import org.testng.Assert;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import org.xml.sax.SAXException;
import javax.xml.bind.JAXBException;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.stream.XMLStreamException;
import javax.xml.transform.TransformerException;
import java.io.*;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
@Test
public class ExportTest {
private static final String DATA_DIR_PATH = "src/test/data/svg/";
@Test(dataProvider = "Data-Provider-Function")
public void exportSvgTest(@NotNull final File svgFile, @NotNull final File pngFile) throws ImporterException, IOException, ExportException {
BufferedReader reader = null;
StringBuffer buffer = new StringBuffer();
reader = new BufferedReader(new FileReader(svgFile));
String text;
while((text=reader.readLine()) != null){
buffer.append(text).append(System.getProperty("line.separator"));
}
String svgXml = buffer.toString();
final ExportFormat format = ExportFormat.PNG;
final ExportProperties properties = ExportProperties.create(format);
final ExportProperties.ImageProperties imageProperties = (ExportProperties.ImageProperties) properties;
imageProperties.setSize(ExportProperties.ImageProperties.Size.LARGE);
// Write content ...
MindMap mindMap = new MindMap();
MindMapNative nativeBrowser = new MindMapNative();
nativeBrowser.setSvgXml(svgXml);
mindMap.setNativeBrowser(nativeBrowser);
//Export to PNG
OutputStream outputStream = new FileOutputStream(pngFile, false);
try {
mindMap.export(properties, outputStream);
outputStream.close();
System.out.println("finished");
} catch (JAXBException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
} catch (TranscoderException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
} catch (TransformerException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
} catch (ParserConfigurationException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
} catch (SAXException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
} catch (XMLStreamException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
}
//This function will provide the parameter data
@DataProvider(name = "Data-Provider-Function")
public Object[][] parameterIntTestProvider() {
final File dataDir = new File(DATA_DIR_PATH);
final File[] freeMindFiles = dataDir.listFiles(new FilenameFilter() {
public boolean accept(File dir, String name) {
return name.endsWith(".svg");
}
});
final Object[][] result = new Object[freeMindFiles.length][2];
for (int i = 0; i < freeMindFiles.length; i++) {
File freeMindFile = freeMindFiles[i];
final String name = freeMindFile.getName();
result[i] = new Object[]{freeMindFile, new File(DATA_DIR_PATH, name.substring(0, name.lastIndexOf(".")) + ".png")};
}
return result;
}
}

View File

@ -4,6 +4,7 @@
<test name="FreeMind Import Export Tests"> <test name="FreeMind Import Export Tests">
<packages> <packages>
<package name="com.wisemapping.test.freemind"/> <package name="com.wisemapping.test.freemind"/>
<package name="com.wisemapping.test.export"/>
</packages> </packages>
</test> </test>
<test name="Model Tests"> <test name="Model Tests">