mirror of
https://bitbucket.org/wisemapping/wisemapping-open-source.git
synced 2024-11-21 21:57:56 +01:00
- Add @NotNull support
- Add FreeMindTest suite
This commit is contained in:
parent
55f9352c59
commit
4ae0258411
@ -48,6 +48,12 @@
|
||||
<classifier>jdk15</classifier>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.intellij</groupId>
|
||||
<artifactId>annotations</artifactId>
|
||||
<version>7.0.3</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-webmvc</artifactId>
|
||||
<version>2.5.6</version>
|
||||
|
@ -26,6 +26,7 @@ import com.wisemapping.xml.freemind.*;
|
||||
import com.wisemapping.xml.mindmap.RelationshipType;
|
||||
import com.wisemapping.xml.mindmap.TopicType;
|
||||
import com.wisemapping.xml.mindmap.Icon;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.xml.bind.JAXBException;
|
||||
import java.io.IOException;
|
||||
@ -110,7 +111,7 @@ public class FreemindExporter
|
||||
}
|
||||
}
|
||||
|
||||
private void addNodeFromTopic(TopicType mainTopic, Node destNode) {
|
||||
private void addNodeFromTopic(@NotNull final TopicType mainTopic, @NotNull final Node destNode) {
|
||||
final List<TopicType> currentTopic = mainTopic.getTopic();
|
||||
|
||||
for (TopicType topicType : currentTopic) {
|
||||
@ -120,10 +121,10 @@ public class FreemindExporter
|
||||
destNode.getArrowlinkOrCloudOrEdge().add(newNode);
|
||||
addNodeFromTopic(topicType, newNode);
|
||||
String position = topicType.getPosition();
|
||||
if(position!=null){
|
||||
if (position != null) {
|
||||
String xPos = position.split(",")[0];
|
||||
int x = Integer.valueOf(xPos);
|
||||
newNode.setPOSITION((x<0?POSITION_LEFT:POSITION_RIGHT));
|
||||
newNode.setPOSITION((x < 0 ? POSITION_LEFT : POSITION_RIGHT));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
1
wise-webapp/src/test/data/freemind/basic.mmr
Normal file
1
wise-webapp/src/test/data/freemind/basic.mmr
Normal file
@ -0,0 +1 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><map version="0.9.0"><node TEXT="This is the root node" STYLE="elipse" ID="ID_0"><node TEXT="Child Level 1 Right 1" POSITION="right" ID="ID_1"/><node TEXT="Child Level 1 Left 1" POSITION="left" ID="ID_2"><node TEXT="Child Level 2 Left 11" POSITION="left" ID="ID_3"/><node TEXT="Child Level 2 Left 12" POSITION="left" ID="ID_4"/></node><node TEXT="Child Level 1 Right 2" POSITION="right" ID="ID_5"/><node TEXT="Child Level 1 Left 2" POSITION="left" ID="ID_6"><node TEXT="Child Level 2 Left 21 " POSITION="left" ID="ID_7"/><node TEXT="Child Level 2 Left 22" POSITION="left" ID="ID_8"/></node></node></map>
|
@ -1 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><map version="0.9.0"><node TEXT="This is the root node" STYLE="elipse" ID="ID_0"><node TEXT="Child Level 1 Right 1" ID="ID_1"/><node TEXT="Child Level 1 Left 1" ID="ID_2"><node TEXT="Child Level 2 Left 11" ID="ID_3"/><node TEXT="Child Level 2 Left 12" ID="ID_4"/></node><node TEXT="Child Level 1 Right 2" ID="ID_5"/><node TEXT="Child Level 1 Left 2" ID="ID_6"><node TEXT="Child Level 2 Left 21 " ID="ID_7"/><node TEXT="Child Level 2 Left 22" ID="ID_8"/></node></node></map>
|
@ -1,9 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<map version="pela" name="basic">
|
||||
<topic id="0" central="true" position="210,0" shape="elipse" text="This is the root node">
|
||||
<topic id="1" position="210,0" order="1" shape="line" text="Child Level 1 Right 1"/>
|
||||
<topic id="2" position="-180,200" order="1" shape="line" text="Child Level 1 Left 1">
|
||||
<topic id="5" position="230,400" order="2" shape="line" text="Child Level 1 Right 2"/>
|
||||
<topic id="6" position="-160,600" order="2" shape="line" text="Child Level 1 Left 2">
|
||||
</topic>
|
||||
</map>
|
@ -8,30 +8,83 @@ import com.wisemapping.importer.ImporterException;
|
||||
import com.wisemapping.importer.ImporterFactory;
|
||||
|
||||
import com.wisemapping.model.MindMap;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.FileChannel;
|
||||
|
||||
@Test
|
||||
public class FreeMindExportTest {
|
||||
private static final String DATA_DIR_PATH = "src/test/data/freemind/";
|
||||
|
||||
@Test
|
||||
public void exportImportExportTest() throws ImporterException, IOException, ExportException {
|
||||
@Test(dataProvider = "Data-Provider-Function")
|
||||
public void exportImportExportTest(@NotNull final File freeMindFile, @NotNull final File recFile) throws ImporterException, IOException, ExportException {
|
||||
|
||||
ImporterFactory instance = ImporterFactory.getInstance();
|
||||
Importer importer = instance.getImporter(ImportFormat.FREEMIND);
|
||||
|
||||
FileInputStream fileInputStream = new FileInputStream(new File(DATA_DIR_PATH, "basic.mm").getAbsolutePath());
|
||||
FileInputStream fileInputStream = new FileInputStream(freeMindFile.getAbsolutePath());
|
||||
final MindMap mindMap = importer.importMap("basic", "basic", fileInputStream);
|
||||
|
||||
|
||||
|
||||
final FreemindExporter freemindExporter = new FreemindExporter();
|
||||
FileOutputStream fos = new FileOutputStream(new File(DATA_DIR_PATH,"basice.mm"));
|
||||
freemindExporter.export(mindMap,fos);
|
||||
fos.close();
|
||||
|
||||
if (recFile.exists()) {
|
||||
// Compare rec and file ...
|
||||
|
||||
// Load rec file co
|
||||
final FileInputStream fis = new FileInputStream(recFile);
|
||||
final InputStreamReader isr = new InputStreamReader(fis);
|
||||
final BufferedReader br = new BufferedReader(isr);
|
||||
|
||||
final StringBuilder recContent = new StringBuilder();
|
||||
String line = br.readLine();
|
||||
while (line != null) {
|
||||
recContent.append(line);
|
||||
line = br.readLine();
|
||||
|
||||
}
|
||||
|
||||
fis.close();
|
||||
|
||||
// Export mile content ...
|
||||
final ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
freemindExporter.export(mindMap, bos);
|
||||
final String exportContent = new String(bos.toByteArray());
|
||||
|
||||
Assert.assertEquals(recContent.toString(), exportContent);
|
||||
|
||||
} else {
|
||||
final FileOutputStream fos = new FileOutputStream(recFile);
|
||||
freemindExporter.export(mindMap, fos);
|
||||
fos.close();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
//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(".mm");
|
||||
}
|
||||
});
|
||||
|
||||
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(".")) + ".mmr")};
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user