use of com.sldeditor.common.data.StyleWrapper in project sldeditor by robward-scisys.
the class SLDDataTest method testGetLayerName.
/**
* Test get layer name.
*/
@Test
public void testGetLayerName() {
String styleName = "style";
String styleFilename = styleName + ".sld";
StyleWrapper styleWrapper = new StyleWrapper("workspace", styleFilename);
SLDData data = new SLDData(styleWrapper, null);
String actualLayerName = data.getLayerName();
assertEquals(styleFilename, actualLayerName);
String actualLayerNameWithOutSuffix = data.getLayerNameWithOutSuffix();
assertEquals(styleName, actualLayerNameWithOutSuffix);
}
use of com.sldeditor.common.data.StyleWrapper in project sldeditor by robward-scisys.
the class SLDUtilsTest method testCreateSLDFromStringFile.
@Test
public void testCreateSLDFromStringFile() {
StyleWrapper wrapper = new StyleWrapper();
SLDData sldData = new SLDData(wrapper, expectedSld);
String filename = "D:/tmp/test.sld";
File file = new File(filename);
sldData.setSLDFile(file);
StyledLayerDescriptor sld = SLDUtils.createSLDFromString(null);
assertNull(sld);
sld = SLDUtils.createSLDFromString(sldData);
StyledLayer[] styledLayers = sld.getStyledLayers();
NamedLayer namedLayer = (NamedLayer) styledLayers[0];
Style[] actualStyles = namedLayer.getStyles();
PointSymbolizer pointSymbolizer = (PointSymbolizer) actualStyles[0].featureTypeStyles().get(0).rules().get(0).symbolizers().get(0);
MarkImpl mark = (MarkImpl) pointSymbolizer.getGraphic().graphicalSymbols().get(0);
assertEquals("circle", mark.getWellKnownName().toString());
// Check resource locator
try {
URL url = file.getParentFile().toURI().toURL();
String actualResourceLocator = sldData.getResourceLocator().toExternalForm();
String expectedResourcelocator = url.toExternalForm();
assertTrue(expectedResourcelocator.compareTo(actualResourceLocator) == 0);
} catch (MalformedURLException e) {
e.printStackTrace();
fail();
}
}
use of com.sldeditor.common.data.StyleWrapper in project sldeditor by robward-scisys.
the class SLDEditorFileTest method testVendorOptionsUpdated.
/**
* Test method for {@link com.sldeditor.datasource.SLDEditorFile#vendorOptionsUpdated()}.
*/
@Test
public void testVendorOptionsUpdated() {
SLDEditorFile.destroyInstance();
DummyDataUpdate dataUpdateListener = new DummyDataUpdate();
SLDEditorFile.getInstance().addSLDEditorFileUpdateListener(dataUpdateListener);
assertFalse(dataUpdateListener.dataEditedFlag);
SLDEditorFile.getInstance().vendorOptionsUpdated(null);
assertFalse(dataUpdateListener.dataEditedFlag);
List<VersionData> vendorOptionVersionsList = new ArrayList<VersionData>();
SLDEditorFile.getInstance().vendorOptionsUpdated(vendorOptionVersionsList);
assertFalse(dataUpdateListener.dataEditedFlag);
StyleWrapper styleWrapper = new StyleWrapper("workspace", "style");
SLDData sldData = new SLDData(styleWrapper, "contents");
SLDEditorFile.getInstance().setSLDData(sldData);
SLDEditorFile.getInstance().vendorOptionsUpdated(vendorOptionVersionsList);
assertTrue(dataUpdateListener.dataEditedFlag);
}
use of com.sldeditor.common.data.StyleWrapper in project sldeditor by robward-scisys.
the class SLDEditorFileTest method testSLDData.
/**
* Test method for {@link com.sldeditor.datasource.SLDEditorFile#getSLDData()}. Test method for
* {@link com.sldeditor.datasource.SLDEditorFile#fileOpenedSaved()}. Test method for
* {@link com.sldeditor.datasource.SLDEditorFile#getSldEditorFile()}. Test method for
* {@link com.sldeditor.datasource.SLDEditorFile#addSLDEditorFileUpdateListener(com.sldeditor.datasource.SLDEditorDataUpdateInterface)}.
* Test method for {@link com.sldeditor.datasource.SLDEditorFile#renderSymbol()}. Test method
* for
* {@link com.sldeditor.datasource.SLDEditorFile#setSLDData(com.sldeditor.common.SLDDataInterface)}.
* Test method for {@link com.sldeditor.datasource.SLDEditorFile#setSldFile(java.io.File)}. Test
* method for {@link com.sldeditor.datasource.SLDEditorFile#getDataSource()}. Test method for
* {@link com.sldeditor.datasource.SLDEditorFile#setDataSource(com.sldeditor.DataSourcePropertiesInterface)}.
* Test method for
* {@link com.sldeditor.datasource.SLDEditorFile#setSldEditorFile(java.io.File)}.
*/
@Test
public void testSLDData() {
// Start with a blank canvas
SLDEditorFile.destroyInstance();
SelectedSymbol.destroyInstance();
assertNull(SLDEditorFile.getInstance().getSLD());
assertNull(SLDEditorFile.getInstance().getSLDData());
assertNull(SLDEditorFile.getInstance().getSldEditorFile());
assertNull(SLDEditorFile.getInstance().getDataSource());
SLDEditorFile.getInstance().setDataSource(null);
assertNull(SLDEditorFile.getInstance().getDataSource());
SLDEditorFile.getInstance().setSldEditorFile(null);
assertNull(SLDEditorFile.getInstance().getSldEditorFile());
SLDEditorFile.getInstance().setSldFile(null);
assertNull(SLDEditorFile.getInstance().getSLDData());
SLDEditorFile.getInstance().setSLDData(null);
assertNull(SLDEditorFile.getInstance().getSLDData());
DummyDataUpdate dataUpdateListener = new DummyDataUpdate();
SLDEditorFile.getInstance().addSLDEditorFileUpdateListener(dataUpdateListener);
// Set SLDData
StyleWrapper styleWrapper = new StyleWrapper("workspace", "style");
SLDData sldData = new SLDData(styleWrapper, "contents");
SLDEditorFile.getInstance().setSLDData(sldData);
SLDEditorFile.getInstance().fileOpenedSaved();
assertEquals(sldData, SLDEditorFile.getInstance().getSLDData());
assertFalse(dataUpdateListener.dataEditedFlag);
// Sld file
File sldFile = new File("test.txt");
SLDEditorFile.getInstance().setSldFile(sldFile);
assertEquals(sldFile.getAbsolutePath(), SLDEditorFile.getInstance().getSLDData().getSLDFile().getAbsolutePath());
assertFalse(dataUpdateListener.dataEditedFlag);
// Sld editor file
File sldEditorFile = new File("editor.file");
SLDEditorFile.getInstance().setSldEditorFile(sldEditorFile);
assertEquals(sldEditorFile.getAbsolutePath(), SLDEditorFile.getInstance().getSldEditorFile().getAbsolutePath());
assertFalse(dataUpdateListener.dataEditedFlag);
// Data source properties
SLDEditorFile.getInstance().setDataSource(null);
assertFalse(dataUpdateListener.dataEditedFlag);
DataSourcePropertiesInterface noDataSource = DataSourceConnectorFactory.getNoDataSource();
assertEquals(noDataSource.getDebugConnectionString(), SLDEditorFile.getInstance().getDataSource().getDebugConnectionString());
assertFalse(dataUpdateListener.dataEditedFlag);
DataSourcePropertiesInterface fileDSProperties = new DataSourceProperties(new DataSourceConnector());
assertEquals(fileDSProperties.getDebugConnectionString(), SLDEditorFile.getInstance().getDataSource().getDebugConnectionString());
assertFalse(dataUpdateListener.dataEditedFlag);
// Render symbol
SLDEditorFile.getInstance().renderSymbol();
assertTrue(dataUpdateListener.dataEditedFlag);
// File saved
SLDEditorFile.getInstance().fileOpenedSaved();
assertFalse(dataUpdateListener.dataEditedFlag);
assertNull(SLDEditorFile.getInstance().getRuleRenderOptions());
}
use of com.sldeditor.common.data.StyleWrapper in project sldeditor by robward-scisys.
the class ExternalFilenamesTest method testGetFile.
/**
* Test method for
* {@link com.sldeditor.common.utils.ExternalFilenames#getFile(java.lang.String)}.
*/
@Test
public void testGetFile() {
assertNull(ExternalFilenames.getFile(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 expectedGraphicsFile = "test.png";
// Try it with no SLD file set
assertNull(ExternalFilenames.getFile(sldData, expectedGraphicsFile));
// Now set the SLD file
sldData.setSLDFile(tempSLDFile);
// The graphics file is relative to the sld file so add the parent folder
// of the sld file
String absolutePath = ExternalFilenames.getFile(sldData, expectedGraphicsFile).getAbsolutePath();
assertEquals(tempSLDFile.getParent() + File.separator + expectedGraphicsFile, absolutePath);
// Now a graphics file with an absolute file path
File absolutePathGraphicsFile = null;
try {
absolutePathGraphicsFile = File.createTempFile(getClass().getSimpleName(), ".png");
} catch (IOException e) {
e.printStackTrace();
fail("Couldn't create temp test file");
}
String actualResult = ExternalFilenames.getFile(sldData, absolutePathGraphicsFile.getAbsolutePath()).getAbsolutePath();
String expectedResult = absolutePathGraphicsFile.getAbsolutePath();
assertEquals(expectedResult, actualResult);
// Now try a URL
try {
String absolutePathGraphicsFileURL = absolutePathGraphicsFile.toURI().toURL().toString();
actualResult = ExternalFilenames.getFile(sldData, absolutePathGraphicsFileURL).getAbsolutePath();
String s = OSValidator.isWindows() ? "file:/" : "file:";
expectedResult = new File(absolutePathGraphicsFileURL.substring(s.length())).getAbsolutePath();
} catch (MalformedURLException e) {
e.printStackTrace();
fail(e.getMessage());
}
assertEquals(expectedResult, actualResult);
tempSLDFile.delete();
absolutePathGraphicsFile.delete();
}
Aggregations