use of com.sldeditor.common.data.SLDData 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.data.SLDData 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.data.SLDData 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());
}
use of com.sldeditor.common.data.SLDData in project sldeditor by robward-scisys.
the class YSLDFileHandlerTest method testGetSLDName.
/**
* Check SLD name
*
* <p>Test method for {@link com.sldeditor.extension.filesystem.file.sld.SLDFileHandler#getSLDContents(com.sldeditor.common.NodeInterface)}.
*/
@Test
public void testGetSLDName() {
YSLDFileHandler handler = new YSLDFileHandler();
assertTrue(handler.getSLDName(null).compareTo("") == 0);
SLDData sldData = new SLDData(new StyleWrapper("workspace", "layer.ysld"), "sldContents");
String sldName = handler.getSLDName(sldData);
assertTrue(sldName.compareTo("layer.ysld") == 0);
}
use of com.sldeditor.common.data.SLDData in project sldeditor by robward-scisys.
the class GeoServerInputTest method testUpdateConnectionDetails.
/**
* Test method for
* {@link com.sldeditor.extension.filesystem.geoserver.GeoServerInput#updateConnectionDetails(com.sldeditor.common.data.GeoServerConnection, com.sldeditor.common.data.GeoServerConnection)}.
*/
@Test
public void testUpdateConnectionDetails() {
GeoServerInput input = new GeoServerInput(null);
GeoServerInput.overrideGeoServerClientClass(DummyGeoServerClient.class);
// Add some GeoServer connections
GeoServerConnection connection1 = new GeoServerConnection();
connection1.setConnectionName("test connection 1");
input.addNewConnection(connection1);
GeoServerConnection connection2 = new GeoServerConnection();
connection2.setConnectionName("test connection 2");
input.addNewConnection(connection2);
// Try null parameters
input.updateConnectionDetails(null, null);
// Delete connection details
List<GeoServerConnection> listToDelete = new ArrayList<GeoServerConnection>();
listToDelete.add(connection1);
input.deleteConnections(listToDelete);
GeoServerConnection connection1Updated = new GeoServerConnection();
connection1Updated.setConnectionName("update test connection 1");
input.addNewConnection(connection1Updated);
// Update the connection details
input.updateConnectionDetails(connection1, connection1Updated);
StyleWrapper styleWrapper = new StyleWrapper("workspace", "layer1");
SLDData sldData = new SLDData(styleWrapper, "sld contents");
sldData.setConnectionData(connection1);
// Try and save with the old GeoServer connection details
assertFalse(input.save(sldData));
// Try and save with the new GeoServer connection details
sldData.setConnectionData(connection1Updated);
assertTrue(input.save(sldData));
}
Aggregations