use of com.sldeditor.common.SLDDataInterface in project sldeditor by robward-scisys.
the class FileSystemInputTest method testCopyNodes.
/**
* Test method for
* {@link com.sldeditor.extension.filesystem.file.FileSystemInput#copyNodes(com.sldeditor.common.NodeInterface, java.util.Map)}.
*/
@Test
public void testCopyNodes() {
FileSystemInput input = new FileSystemInput(null);
URL url = SLDFileHandlerTest.class.getResource("/point/sld/point_attribute.sld");
List<SLDDataInterface> sldDataList = input.open(url);
assertEquals(1, sldDataList.size());
try {
Path tempFolder = Files.createTempDirectory(getClass().getSimpleName());
File tempFolderFile = tempFolder.toFile();
FileTreeNode destinationTreeNode = new FileTreeNode(tempFolderFile.getParentFile(), tempFolderFile.getName());
Map<NodeInterface, List<SLDDataInterface>> copyDataMap = new HashMap<NodeInterface, List<SLDDataInterface>>();
copyDataMap.put(destinationTreeNode, sldDataList);
assertTrue(input.copyNodes(destinationTreeNode, copyDataMap));
SLDData sldData = (SLDData) sldDataList.get(0);
sldData.setSLDFile(new File(tempFolderFile, "point_attribute.sld"));
input.deleteNodes(destinationTreeNode, sldDataList);
tempFolderFile.deleteOnExit();
} catch (IOException e) {
e.printStackTrace();
fail(e.getMessage());
}
}
use of com.sldeditor.common.SLDDataInterface in project sldeditor by robward-scisys.
the class RasterFileHandlerTest method testGetSLDContentsFile.
/**
* Single file
*
* <p>Test method for {@link com.sldeditor.extension.filesystem.file.raster.RasterFileHandler#getSLDContents(com.sldeditor.common.NodeInterface)}.
*/
@Test
public void testGetSLDContentsFile() {
assertNull(new RasterFileHandler().getSLDContents(null));
URL url = RasterFileHandlerTest.class.getResource("/point/sld");
File parent = null;
try {
parent = new File(url.toURI());
} catch (URISyntaxException e) {
e.printStackTrace();
fail(e.getMessage());
}
try {
FileTreeNode fileTreeNode = new FileTreeNode(parent, "point_attribute.sld");
RasterFileHandler handler = new RasterFileHandler();
List<SLDDataInterface> sldDataList = handler.getSLDContents(fileTreeNode);
assertNull(sldDataList);
// Try with valid vector file
FileTreeNode fileTreeNode2 = new FileTreeNode(parent, "point_attribute.tif");
sldDataList = handler.getSLDContents(fileTreeNode2);
assertTrue(sldDataList.isEmpty());
// Changes where the file is to be saved to
File saveFile = File.createTempFile(getClass().getSimpleName(), ".sld");
SLDData sldData = new SLDData(null, "");
sldData.setSLDFile(saveFile);
assertFalse(handler.save(null));
assertFalse(handler.save(sldData));
saveFile.delete();
} catch (SecurityException e) {
e.printStackTrace();
fail(e.getMessage());
} catch (FileNotFoundException e) {
e.printStackTrace();
fail(e.getMessage());
} catch (IOException e) {
e.printStackTrace();
fail(e.getMessage());
}
}
use of com.sldeditor.common.SLDDataInterface in project sldeditor by robward-scisys.
the class SLDFileHandlerTest method testGetSLDContentsFile.
/**
* Single file
*
* <p>Test method for {@link com.sldeditor.extension.filesystem.file.sld.SLDFileHandler#getSLDContents(com.sldeditor.common.NodeInterface)}.
*/
@Test
public void testGetSLDContentsFile() {
assertNull(new SLDFileHandler().getSLDContents(null));
URL url = SLDFileHandlerTest.class.getResource("/point/sld");
File parent = null;
try {
parent = new File(url.toURI());
} catch (URISyntaxException e) {
e.printStackTrace();
fail(e.getMessage());
}
try {
FileTreeNode fileTreeNode = new FileTreeNode(parent, "point_attribute.sld");
SLDFileHandler handler = new SLDFileHandler();
List<SLDDataInterface> sldDataList = handler.getSLDContents(fileTreeNode);
assertEquals(1, sldDataList.size());
// Changes where the file is to be saved to
File saveFile = File.createTempFile(getClass().getSimpleName(), ".sld");
SLDData sldData = (SLDData) sldDataList.get(0);
sldData.setSLDFile(saveFile);
assertFalse(handler.save(null));
assertTrue(handler.save(sldData));
saveFile.delete();
} catch (SecurityException e) {
e.printStackTrace();
fail(e.getMessage());
} catch (FileNotFoundException e) {
e.printStackTrace();
fail(e.getMessage());
} catch (IOException e) {
e.printStackTrace();
fail(e.getMessage());
}
}
use of com.sldeditor.common.SLDDataInterface in project sldeditor by robward-scisys.
the class VectorFileHandlerTest method testGetSLDContentsFile.
/**
* Single file
*
* <p>Test method for {@link com.sldeditor.extension.filesystem.file.vector.VectorFileHandler#getSLDContents(com.sldeditor.common.NodeInterface)}.
*/
@Test
public void testGetSLDContentsFile() {
assertNull(new VectorFileHandler().getSLDContents(null));
URL url = VectorFileHandlerTest.class.getResource("/point/sld");
File parent = null;
try {
parent = new File(url.toURI());
} catch (URISyntaxException e) {
e.printStackTrace();
fail(e.getMessage());
}
try {
FileTreeNode fileTreeNode = new FileTreeNode(parent, "point_attribute.sld");
VectorFileHandler handler = new VectorFileHandler();
List<SLDDataInterface> sldDataList = handler.getSLDContents(fileTreeNode);
assertNull(sldDataList);
// Try with valid vector file
FileTreeNode fileTreeNode2 = new FileTreeNode(parent, "point_attribute.shp");
sldDataList = handler.getSLDContents(fileTreeNode2);
assertTrue(sldDataList.isEmpty());
// Changes where the file is to be saved to
File saveFile = File.createTempFile(getClass().getSimpleName(), ".sld");
SLDData sldData = new SLDData(null, "");
sldData.setSLDFile(saveFile);
assertFalse(handler.save(null));
assertFalse(handler.save(sldData));
saveFile.delete();
} catch (SecurityException e) {
e.printStackTrace();
fail(e.getMessage());
} catch (FileNotFoundException e) {
e.printStackTrace();
fail(e.getMessage());
} catch (IOException e) {
e.printStackTrace();
fail(e.getMessage());
}
}
use of com.sldeditor.common.SLDDataInterface in project sldeditor by robward-scisys.
the class YSLDToolTest method testSetSelectedItems.
/**
* Test sld file.
*/
@Test
public void testSetSelectedItems() {
YSLDTool tool = new YSLDTool();
JPanel panel = tool.getPanel();
ToolButton toSLD = null;
ToolButton toYSLD = null;
for (Component c : panel.getComponents()) {
if (c instanceof ToolButton) {
ToolButton button = (ToolButton) c;
String toolTipText = button.getToolTipText();
if (toolTipText.compareTo(Localisation.getString(YSLDTool.class, "YSLDTool.exportToSLD")) == 0) {
toSLD = button;
} else if (toolTipText.compareTo(Localisation.getString(YSLDTool.class, "YSLDTool.exportToYSLD")) == 0) {
toYSLD = button;
}
}
}
File testFile1 = null;
File testFile3 = null;
try {
testFile1 = File.createTempFile("invalid", ".tst");
testFile3 = File.createTempFile("valid", ".ysld");
} catch (IOException e1) {
e1.printStackTrace();
}
// Should both be disabled
assertFalse(toSLD.isEnabled());
assertFalse(toYSLD.isEnabled());
tool.setSelectedItems(null, null);
// Invalid file
List<SLDDataInterface> sldDataList = new ArrayList<SLDDataInterface>();
SLDData sldData1 = new SLDData(null, null);
sldData1.setSLDFile(testFile1);
sldDataList.add(sldData1);
tool.setSelectedItems(null, sldDataList);
// Should both be disabled
assertFalse(toSLD.isEnabled());
assertFalse(toYSLD.isEnabled());
// Try with valid sld file
sldDataList = new ArrayList<SLDDataInterface>();
SLDData sldData2 = getSLDDataFile("/point/sld/point_simplepoint.sld");
sldDataList.add(sldData2);
tool.setSelectedItems(null, sldDataList);
// YSLD should be enabled
assertTrue(toYSLD.isEnabled());
assertFalse(toSLD.isEnabled());
toYSLD.doClick();
// Try with valid ysld file
sldDataList = new ArrayList<SLDDataInterface>();
SLDData sldData3 = getSLDDataFile("/point/ysld/point_simplepoint.ysld");
sldDataList.add(sldData3);
tool.setSelectedItems(null, sldDataList);
// SLD should be enabled
assertTrue(toSLD.isEnabled());
assertFalse(toYSLD.isEnabled());
toSLD.doClick();
// Try with valid sld and ysld files
sldDataList = new ArrayList<SLDDataInterface>();
sldDataList.add(sldData2);
sldDataList.add(sldData3);
tool.setSelectedItems(null, sldDataList);
// SLD and YSLD should be enabled
assertTrue(toSLD.isEnabled());
assertTrue(toYSLD.isEnabled());
testFile1.delete();
testFile3.delete();
tidyUpTempFiles(sldData2.getSLDFile());
tidyUpTempFiles(sldData3.getSLDFile());
}
Aggregations