use of com.sldeditor.common.preferences.PrefData in project sldeditor by robward-scisys.
the class VendorOptionManagerTest method testLoadSLDFile.
/**
* Test method for {@link com.sldeditor.common.vendoroption.VendorOptionManager#getVendorOptionVersion()}.
*/
@Test
public void testLoadSLDFile() {
VendorOptionManager.destroyInstance();
PrefData prefData = PrefManager.getInstance().getPrefData();
List<VersionData> vendorOptionList = new ArrayList<VersionData>();
VersionData actualPrefVO = VersionData.decode(GeoServerVendorOption.class, "2.4.2");
vendorOptionList.add(actualPrefVO);
prefData.setVendorOptionVersionList(vendorOptionList);
PrefManager.getInstance().setPrefData(prefData);
SLDData sldData = new SLDData(null, null);
StyledLayerDescriptor sld = null;
VendorOptionManager.getInstance().addVendorOptionListener(obj);
obj.vendorOptionVersionsList.clear();
// No SLD Editor file, SLD is empty so it should you PrefManager default set above
VendorOptionManager.getInstance().loadSLDFile(null, sld, sldData);
assertEquals(1, obj.vendorOptionVersionsList.size());
assertEquals(actualPrefVO, obj.vendorOptionVersionsList.get(0));
// No SLD Editor file, SLD contains PointSymboliser with vendor
// option so it should use the SLD vendor option
obj.vendorOptionVersionsList.clear();
sld = DefaultSymbols.createNewSLD();
SelectedSymbol.getInstance().createNewSLD(sld);
NamedLayer namedLayer = DefaultSymbols.createNewNamedLayer();
String expectedNameLayerValue = "named layer test value";
namedLayer.setName(expectedNameLayerValue);
Style style = DefaultSymbols.createNewStyle();
String expectedNameStyleValue = "style test value";
style.setName(expectedNameStyleValue);
namedLayer.addStyle(style);
FeatureTypeStyle fts = DefaultSymbols.createNewFeatureTypeStyle();
String expectedNameFTSValue = "feature type style test value";
fts.setName(expectedNameFTSValue);
style.featureTypeStyles().add(fts);
Rule rule = DefaultSymbols.createNewRule();
String expectedNameValue = "rule test value";
rule.setName(expectedNameValue);
PointSymbolizer symbolizer = DefaultSymbols.createDefaultPointSymbolizer();
rule.symbolizers().add(symbolizer);
fts.rules().add(rule);
sld.layers().add(namedLayer);
VersionData testVersionData = VersionData.decode(GeoServerVendorOption.class, "2.8.0");
VendorOptionManager.getInstance().loadSLDFile(new GetMinimumVersionInterface() {
@Override
public void getMinimumVersion(Object parentObj, Object sldObj, List<VendorOptionPresent> vendorOptionsPresentList) {
VendorOptionInfo vendorOptionInfo = new VendorOptionInfo("qgis://", new VendorOptionVersion(testVersionData.getVendorOptionType(), testVersionData), "");
VendorOptionPresent voPresent = new VendorOptionPresent(sldObj, vendorOptionInfo);
vendorOptionsPresentList.add(voPresent);
}
}, sld, sldData);
assertEquals(1, obj.vendorOptionVersionsList.size());
assertEquals(testVersionData, obj.vendorOptionVersionsList.get(0));
// Now set the SLD Editor file vendor option
obj.vendorOptionVersionsList.clear();
List<VersionData> sldEditorVendorOptionList = new ArrayList<VersionData>();
VersionData testVersionData2 = VersionData.decode(GeoServerVendorOption.class, "2.10.0");
sldEditorVendorOptionList.add(testVersionData2);
sldEditorVendorOptionList.add(VendorOptionManager.getInstance().getDefaultVendorOptionVersionData());
sldData.setVendorOptionList(sldEditorVendorOptionList);
sldData.setSldEditorFile(new File("."));
VendorOptionManager.getInstance().loadSLDFile(new GetMinimumVersionInterface() {
@Override
public void getMinimumVersion(Object parentObj, Object sldObj, List<VendorOptionPresent> vendorOptionsPresentList) {
VendorOptionInfo vendorOptionInfo = new VendorOptionInfo("qgis://", new VendorOptionVersion(testVersionData.getVendorOptionType(), testVersionData), "");
VendorOptionPresent voPresent = new VendorOptionPresent(sldObj, vendorOptionInfo);
vendorOptionsPresentList.add(voPresent);
}
}, sld, sldData);
Collections.sort(obj.vendorOptionVersionsList);
assertEquals(2, obj.vendorOptionVersionsList.size());
assertEquals(testVersionData2, obj.vendorOptionVersionsList.get(obj.vendorOptionVersionsList.size() - 1));
// Increase code coverage
VendorOptionManager.getInstance().loadSLDFile(null, null, null);
}
use of com.sldeditor.common.preferences.PrefData in project sldeditor by robward-scisys.
the class PrefManagerTest method testSetLastFolderViewed.
/**
* Test method for {@link com.sldeditor.common.preferences.PrefManager#setLastFolderViewed()}.
*/
@Test
public void testSetLastFolderViewed() {
PrefManager.initialise(null);
DummyPropertyManager propertyManager = new DummyPropertyManager();
PrefManager.initialise(propertyManager);
// Try with a null argument
PrefManager.getInstance().setLastFolderViewed(null);
PrefData actualPrefData = PrefManager.getInstance().getPrefData();
assertFalse(actualPrefData.isSaveLastFolderView());
assertEquals(PrefDataLastViewedEnum.FOLDER, actualPrefData.getLastViewedKey());
assertNull(actualPrefData.getLastFolderViewed());
// Try with an empty selected files object
SelectedFiles selectedFiles = new SelectedFiles();
PrefManager.getInstance().setLastFolderViewed(selectedFiles);
actualPrefData = PrefManager.getInstance().getPrefData();
assertFalse(actualPrefData.isSaveLastFolderView());
assertEquals(PrefDataLastViewedEnum.FOLDER, actualPrefData.getLastViewedKey());
assertNull(actualPrefData.getLastFolderViewed());
// Set folder
String expectedFolderName = "/tmp/test/abc";
selectedFiles.setFolderName(expectedFolderName);
PrefManager.getInstance().setLastFolderViewed(selectedFiles);
actualPrefData = PrefManager.getInstance().getPrefData();
assertFalse(actualPrefData.isSaveLastFolderView());
assertEquals(PrefDataLastViewedEnum.FOLDER, actualPrefData.getLastViewedKey());
assertEquals(expectedFolderName, actualPrefData.getLastFolderViewed());
expectedFolderName = "c:/tmp/test/abc";
selectedFiles.setFolderName(expectedFolderName);
PrefManager.getInstance().setLastFolderViewed(selectedFiles);
actualPrefData = PrefManager.getInstance().getPrefData();
assertFalse(actualPrefData.isSaveLastFolderView());
assertEquals(PrefDataLastViewedEnum.FOLDER, actualPrefData.getLastViewedKey());
assertEquals(expectedFolderName, actualPrefData.getLastFolderViewed());
actualPrefData.setSaveLastFolderView(true);
PrefManager.getInstance().setPrefData(actualPrefData);
actualPrefData = PrefManager.getInstance().getPrefData();
assertTrue(actualPrefData.isSaveLastFolderView());
// Set geoserver
String expectedGeoServerName = "GeoServer test";
GeoServerConnection connectionData = new GeoServerConnection();
connectionData.setConnectionName(expectedGeoServerName);
selectedFiles = new SelectedFiles();
selectedFiles.setConnectionData(connectionData);
PrefManager.getInstance().setLastFolderViewed(selectedFiles);
actualPrefData = PrefManager.getInstance().getPrefData();
assertTrue(actualPrefData.isSaveLastFolderView());
assertEquals(PrefDataLastViewedEnum.GEOSERVER, actualPrefData.getLastViewedKey());
assertEquals(expectedGeoServerName, actualPrefData.getLastFolderViewed());
}
use of com.sldeditor.common.preferences.PrefData in project sldeditor by robward-scisys.
the class PrefManagerTest method testInitialise.
/**
* Test method for {@link com.sldeditor.common.preferences.PrefManager#initialise(com.sldeditor.common.property.PropertyManagerInterface)}.
*/
@Test
public void testInitialise() {
PrefManager.initialise(null);
DummyPropertyManager propertyManager = new DummyPropertyManager();
PrefManager.initialise(propertyManager);
PrefData prefData = new PrefData();
prefData.setUseAntiAlias(true);
Color backgroundColour = Color.GRAY;
prefData.setBackgroundColour(backgroundColour);
List<VersionData> vendorOptionList = new ArrayList<VersionData>();
vendorOptionList.add(VendorOptionManager.getInstance().getDefaultVendorOptionVersionData());
prefData.setVendorOptionVersionList(vendorOptionList);
String uiLayoutClass = "perfect curve";
prefData.setUiLayoutClass(uiLayoutClass);
PrefManager.getInstance().setPrefData(prefData);
Color newBackgroundColour = Color.RED;
prefData.setBackgroundColour(newBackgroundColour);
PrefManager.getInstance().setPrefData(prefData);
assertEquals(newBackgroundColour, propertyManager.getColourValue("SldEditor.backgroundColour", null));
boolean newAntiAlias = false;
prefData.setUseAntiAlias(newAntiAlias);
PrefManager.getInstance().setPrefData(prefData);
assertEquals(newAntiAlias, propertyManager.getBooleanValue("SldEditor.useAntiAlias", true));
String newLayoutClass = "bendy line";
prefData.setUiLayoutClass(newLayoutClass);
PrefManager.getInstance().setPrefData(prefData);
assertEquals(newLayoutClass, propertyManager.getStringValue("SldEditor.uilayout", null));
List<VersionData> newVendorOptionList = new ArrayList<VersionData>();
newVendorOptionList.add(VendorOptionManager.getInstance().getDefaultVendorOptionVersionData());
prefData.setVendorOptionVersionList(newVendorOptionList);
PrefManager.getInstance().setPrefData(prefData);
newVendorOptionList.add(VersionData.getLatestVersion(GeoServerVendorOption.class));
prefData.setVendorOptionVersionList(newVendorOptionList);
PrefManager.getInstance().setPrefData(prefData);
List<String> encodelist = new ArrayList<String>();
for (VersionData versionData : newVendorOptionList) {
encodelist.add(versionData.getEncodedString());
}
assertTrue(PrefManager.cmpList(encodelist, propertyManager.getStringListValue("SldEditor.vendorOptions")));
PrefManager.initialise(null);
}
use of com.sldeditor.common.preferences.PrefData in project sldeditor by robward-scisys.
the class PrefDataTest method testLastViewedKey.
/**
* Test method for {@link com.sldeditor.common.preferences.PrefData#getLastViewedKey()}.
* Test method for {@link com.sldeditor.common.preferences.PrefData#setLastViewedKey(PrefDataLastViewedEnum)}.
*/
@Test
public void testLastViewedKey() {
PrefData prefData = new PrefData();
PrefDataLastViewedEnum expectedValue = PrefDataLastViewedEnum.FOLDER;
prefData.setLastViewedKey(expectedValue);
assertEquals(expectedValue, prefData.getLastViewedKey());
expectedValue = PrefDataLastViewedEnum.GEOSERVER;
prefData.setLastViewedKey(expectedValue);
assertEquals(expectedValue, prefData.getLastViewedKey());
}
use of com.sldeditor.common.preferences.PrefData in project sldeditor by robward-scisys.
the class PrefDataTest method testBackgroundColour.
/**
* Test method for {@link com.sldeditor.common.preferences.PrefData#getBackgroundColour()}.
* Test method for {@link com.sldeditor.common.preferences.PrefData#setBackgroundColour(java.awt.Color)}.
*/
@Test
public void testBackgroundColour() {
PrefData prefData = new PrefData();
Color testColour = Color.blue;
prefData.setBackgroundColour(testColour);
assertEquals(testColour, prefData.getBackgroundColour());
}
Aggregations