use of com.sldeditor.tool.ysld.YSLDTool in project sldeditor by robward-scisys.
the class YSLDToolTest method testPanel.
/**
* Test get layer name.
*/
@Test
public void testPanel() {
YSLDTool tool = new YSLDTool();
assertTrue(tool.getPanel() != null);
}
use of com.sldeditor.tool.ysld.YSLDTool in project sldeditor by robward-scisys.
the class YSLDToolTest method testGetToolName.
/**
* Test get tool name.
*/
@Test
public void testGetToolName() {
YSLDTool tool = new YSLDTool();
String toolName = tool.getToolName();
assertTrue(toolName.compareTo("com.sldeditor.tool.ysld.YSLDTool") == 0);
}
use of com.sldeditor.tool.ysld.YSLDTool in project sldeditor by robward-scisys.
the class YSLDToolTest method testSupports.
/**
* Test which file types the tool supports.
*/
@Test
public void testSupports() {
YSLDTool tool = new YSLDTool();
assertFalse(tool.supports(null, null, null));
File testFile1 = null;
File testFile2 = null;
File testFile3 = null;
try {
testFile1 = File.createTempFile("invalid", ".tst");
testFile2 = File.createTempFile("valid", ".sld");
testFile3 = File.createTempFile("valid", ".ysld");
} catch (IOException e1) {
e1.printStackTrace();
}
// Try with invalid file
try {
List<NodeInterface> nodeTypeList = new ArrayList<NodeInterface>();
assertNotNull(testFile1);
nodeTypeList.add(new FileTreeNode(testFile1.getParentFile(), testFile1.getName()));
assertFalse(tool.supports(null, nodeTypeList, null));
} catch (SecurityException | FileNotFoundException e) {
e.printStackTrace();
}
// Try with valid sld file
try {
List<NodeInterface> nodeTypeList = new ArrayList<NodeInterface>();
nodeTypeList.add(new FileTreeNode(testFile2.getParentFile(), testFile2.getName()));
assertTrue(tool.supports(null, nodeTypeList, null));
} catch (SecurityException | FileNotFoundException e) {
e.printStackTrace();
}
// Try with valid ysld file
try {
List<NodeInterface> nodeTypeList = new ArrayList<NodeInterface>();
nodeTypeList.add(new FileTreeNode(testFile3.getParentFile(), testFile3.getName()));
assertTrue(tool.supports(null, nodeTypeList, null));
} catch (SecurityException | FileNotFoundException e) {
e.printStackTrace();
}
// Try with several files
try {
List<NodeInterface> nodeTypeList = new ArrayList<NodeInterface>();
nodeTypeList.add(new FileTreeNode(testFile1.getParentFile(), testFile1.getName()));
nodeTypeList.add(new FileTreeNode(testFile2.getParentFile(), testFile2.getName()));
nodeTypeList.add(new FileTreeNode(testFile3.getParentFile(), testFile3.getName()));
assertFalse(tool.supports(null, nodeTypeList, null));
} catch (SecurityException | FileNotFoundException e) {
e.printStackTrace();
}
testFile1.delete();
testFile2.delete();
testFile3.delete();
}
use of com.sldeditor.tool.ysld.YSLDTool 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