Skip to content

Commit

Permalink
Fix #795 (#798)
Browse files Browse the repository at this point in the history
* bump version

nodegraphcore was using an outdated version, breaking connections.

* added unit test

* Throw assert if no file extension
  • Loading branch information
i-make-robots authored Feb 21, 2025
1 parent 9231160 commit bcb83a4
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,18 @@ public static List<FileNameExtensionFilter> getSaveExtensions() {
public static void save(Turtle turtle,String filename, PlotterSettings settings) throws Exception {
if(filename == null || filename.trim().isEmpty()) throw new InvalidParameterException("filename cannot be empty");

String extension = filename.substring(filename.lastIndexOf("."));
if(extension.isEmpty()) throw new InvalidParameterException("filename must have an extension");

for (TurtleSaver saver : savers) {
if(isValidExtension(filename,saver.getFileNameFilter())) {
try (FileOutputStream out = new FileOutputStream(filename)) {
saver.save(out, turtle,settings);
return;
}
return;
}
}
String extension = filename.substring(filename.lastIndexOf("."));

throw new Exception("TurtleFactory could not save '"+filename+"' : invalid file format '" + extension + "'");
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
package com.marginallyclever.makelangelo.donatelloimpl;

import com.marginallyclever.makelangelo.donatelloimpl.nodes.turtle.LoadTurtle;
import com.marginallyclever.makelangelo.donatelloimpl.nodes.turtle.SaveTurtle;
import com.marginallyclever.makelangelo.donatelloimpl.nodes.turtle.TurtleDAO4JSON;
import com.marginallyclever.makelangelo.turtle.Turtle;
import com.marginallyclever.nodegraphcore.Connection;
import com.marginallyclever.nodegraphcore.DAO4JSONFactory;
import com.marginallyclever.nodegraphcore.port.*;
import com.marginallyclever.nodegraphcore.Graph;
import com.marginallyclever.nodegraphcore.NodeFactory;
import com.marginallyclever.nodegraphcore.port.Input;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.IOException;

import static org.junit.jupiter.api.Assertions.*;

/**
Expand All @@ -22,7 +28,7 @@
public class TestNodeGraphMakelangelo {
private static final Logger logger = LoggerFactory.getLogger(TestNodeGraphMakelangelo.class);

private static Graph model = new Graph();
private static final Graph model = new Graph();

@BeforeAll
public static void beforeAll() throws Exception {
Expand Down Expand Up @@ -81,4 +87,38 @@ public void testTurtleDAO() {
Turtle r2=dao.fromJSON(dao.toJSON(r1));
assertEquals(r1,r2);
}

/**
* Create a donatello panel;
* connect a LoadTurtle node and a SaveTurtle node;
* load a test file;
* save the test file;
* confirm the test file was saved.
*/
@Test
public void testLoadAndSaveTurtle() throws IOException {
Graph graph = new Graph();

// Create and connect LoadTurtle and SaveTurtle nodes
LoadTurtle loadNode = new LoadTurtle();
SaveTurtle saveNode = new SaveTurtle();
graph.add(loadNode);
graph.add(saveNode);
graph.add(new Connection(loadNode,1, saveNode,1));

// get a filename for a non-existent temporary file
File tempFile = File.createTempFile("testTurtle", ".dxf");
tempFile.deleteOnExit();
String tempFilename = tempFile.getAbsolutePath();

// Load a test file
loadNode.getPort("filename").setValue("src/test/resources/dxf/circle.dxf");
saveNode.getPort("filename").setValue(tempFilename);
loadNode.update();
saveNode.update();

// confirm the file saved.
assertTrue(tempFile.exists());
assert(tempFile.length()>0);
}
}

0 comments on commit bcb83a4

Please sign in to comment.