use of com.sldeditor.common.data.StyleWrapper in project sldeditor by robward-scisys.
the class SLDDataTest method testStyle.
/**
* Test style.
*/
@Test
public void testStyle() {
StyleWrapper styleWrapper = new StyleWrapper("workspace", "style");
SLDData data = new SLDData(styleWrapper, null);
assertEquals(styleWrapper, data.getStyle());
}
use of com.sldeditor.common.data.StyleWrapper in project sldeditor by robward-scisys.
the class ExternalFilenamesTest method testGetText.
/**
* Test method for {@link com.sldeditor.common.utils.ExternalFilenames#getText(java.net.URL)}.
*/
@Test
public void testGetText() {
assertNull(ExternalFilenames.getText(null, null));
SLDData sldData = new SLDData(new StyleWrapper("workspace", "style"), "contents");
File tempSLDFile = null;
try {
tempSLDFile = File.createTempFile(getClass().getSimpleName(), ".sld");
} catch (IOException e1) {
e1.printStackTrace();
fail("Couldn't create temp test file");
}
String expectedFilename = "test.tst";
// Try it with no SLD file set
assertNull(ExternalFilenames.getFile(sldData, expectedFilename));
// Now set the SLD file
sldData.setSLDFile(tempSLDFile);
String rootFolder = tempSLDFile.getParent();
String expectedResult = File.separator + expectedFilename;
File file = new File(rootFolder + expectedResult);
try {
String actualResult = ExternalFilenames.getText(sldData, file.toURI().toURL());
assertEquals(expectedResult, actualResult);
} catch (MalformedURLException e) {
e.printStackTrace();
fail(e.getMessage());
}
String actualFilename2 = new File(expectedFilename).getAbsolutePath();
File file2 = new File(actualFilename2);
try {
assertEquals(actualFilename2, ExternalFilenames.getText(sldData, file2.toURI().toURL()));
} catch (MalformedURLException e) {
e.printStackTrace();
fail(e.getMessage());
}
tempSLDFile.delete();
}
use of com.sldeditor.common.data.StyleWrapper in project sldeditor by robward-scisys.
the class ReloadManagerTest method testReloadFile.
/**
* Test method for
* {@link com.sldeditor.common.watcher.ReloadManager#fileAdded(java.nio.file.Path)}. Test method
* for {@link com.sldeditor.common.watcher.ReloadManager#fileModified(java.nio.file.Path)}. Test
* method for
* {@link com.sldeditor.common.watcher.ReloadManager#fileDeleted(java.nio.file.Path)}. Test
* method for
* {@link com.sldeditor.common.watcher.ReloadManager#sldDataUpdated(com.sldeditor.common.SLDDataInterface, boolean)}.
* Test method for
* {@link com.sldeditor.common.watcher.ReloadManager#addListener(com.sldeditor.common.LoadSLDInterface)}.
*/
@Test
public void testReloadFile() {
ReloadManager.getInstance().fileAdded(null);
ReloadManager.getInstance().fileModified(null);
ReloadManager.getInstance().fileDeleted(null);
SLDData sldData = new SLDData(new StyleWrapper(), "");
ReloadManager.getInstance().sldDataUpdated(sldData, true);
File expectedFile = new File("/tmp/testFile.sld");
Path path = expectedFile.toPath();
// Try with no callback
ReloadManager.getInstance().fileModified(path);
DummyCallback callback = new DummyCallback();
ReloadManager.getInstance().addListener(callback);
assertEquals(0, callback.reloadCallbackCalled);
// Set loaded file - should match
sldData.setSLDFile(expectedFile);
ReloadManager.getInstance().sldDataUpdated(sldData, true);
ReloadManager.getInstance().fileModified(path);
try {
Thread.sleep(1500);
} catch (InterruptedException e) {
e.printStackTrace();
}
assertEquals(1, callback.reloadCallbackCalled);
// Set loaded file - won't match
callback.reloadCallbackCalled = 0;
File expectedFile2 = new File("/tmp/differenttestFile.sld");
path = expectedFile2.toPath();
ReloadManager.getInstance().fileModified(path);
try {
Thread.sleep(1500);
} catch (InterruptedException e) {
e.printStackTrace();
}
assertEquals(0, callback.reloadCallbackCalled);
// Now try valid multiple calls
path = expectedFile.toPath();
ReloadManager.getInstance().fileModified(path);
ReloadManager.getInstance().fileModified(path);
ReloadManager.getInstance().fileModified(path);
try {
Thread.sleep(1500);
} catch (InterruptedException e) {
e.printStackTrace();
}
assertEquals(1, callback.reloadCallbackCalled);
}
use of com.sldeditor.common.data.StyleWrapper in project sldeditor by robward-scisys.
the class GeoServerStyleNodeTest method testGeoServerLayerNode.
/**
* Test method for {@link com.sldeditor.datasource.extension.filesystem.node.geoserver.GeoServerStyleNode#GeoServerStyleNode(com.sldeditor.common.filesystem.FileSystemInterface)}.
*/
@Test
public void testGeoServerLayerNode() {
FileSystemInterface fileHandler = new DummyFileSystemInput();
GeoServerConnection connection = new GeoServerConnection();
connection.setConnectionName("test connection");
connection.setUserName("test user name");
StyleWrapper styleWrapper = new StyleWrapper("workspace", "layer");
GeoServerStyleNode node = new GeoServerStyleNode(fileHandler, connection, styleWrapper);
assertEquals(fileHandler, node.getHandler());
assertEquals(connection, node.getConnectionData());
assertEquals(styleWrapper, node.getStyle());
assertEquals(BuiltInDataFlavour.GEOSERVER_STYLE_DATAITEM_FLAVOUR, node.getDataFlavour());
assertNull(node.getDestinationText());
}
use of com.sldeditor.common.data.StyleWrapper in project sldeditor by robward-scisys.
the class NewSLDPanel method showDialog.
/**
* Show dialog.
*
* @param parent the parent
* @return the created SLD if selected
*/
public List<SLDDataInterface> showDialog(JFrame parent) {
List<SLDDataInterface> newSLDList = null;
selected = null;
if (parent != null) {
this.setLocationRelativeTo(parent);
int x = ((parent.getWidth() - getWidth()) / 2);
int y = ((parent.getHeight() - getHeight()) / 2);
this.setLocation(x, y);
}
setVisible(true);
if (selected != null) {
newSLDList = new ArrayList<SLDDataInterface>();
StyledLayerDescriptor sld = selected.create();
if (sldWriter == null) {
sldWriter = SLDWriterFactory.createWriter(null);
}
newSLDList.add(new SLDData(new StyleWrapper(selected.getName()), sldWriter.encodeSLD(null, sld)));
return newSLDList;
}
return null;
}
Aggregations