Search in sources :

Example 11 with PrefData

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);
}
Also used : SLDData(com.sldeditor.common.data.SLDData) PointSymbolizer(org.geotools.styling.PointSymbolizer) VendorOptionPresent(com.sldeditor.common.vendoroption.minversion.VendorOptionPresent) ArrayList(java.util.ArrayList) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) PrefData(com.sldeditor.common.preferences.PrefData) VersionData(com.sldeditor.common.vendoroption.VersionData) VendorOptionVersion(com.sldeditor.common.vendoroption.VendorOptionVersion) GetMinimumVersionInterface(com.sldeditor.ui.panels.GetMinimumVersionInterface) Style(org.geotools.styling.Style) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) Rule(org.geotools.styling.Rule) NamedLayer(org.geotools.styling.NamedLayer) VendorOptionInfo(com.sldeditor.common.vendoroption.info.VendorOptionInfo) File(java.io.File) Test(org.junit.Test)

Example 12 with PrefData

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());
}
Also used : PrefData(com.sldeditor.common.preferences.PrefData) SelectedFiles(com.sldeditor.common.filesystem.SelectedFiles) GeoServerConnection(com.sldeditor.common.data.GeoServerConnection) Test(org.junit.Test)

Example 13 with PrefData

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);
}
Also used : GeoServerVendorOption(com.sldeditor.common.vendoroption.GeoServerVendorOption) PrefData(com.sldeditor.common.preferences.PrefData) VersionData(com.sldeditor.common.vendoroption.VersionData) Color(java.awt.Color) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 14 with PrefData

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());
}
Also used : PrefData(com.sldeditor.common.preferences.PrefData) PrefDataLastViewedEnum(com.sldeditor.common.preferences.PrefDataLastViewedEnum) Test(org.junit.Test)

Example 15 with PrefData

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());
}
Also used : PrefData(com.sldeditor.common.preferences.PrefData) Color(java.awt.Color) Test(org.junit.Test)

Aggregations

PrefData (com.sldeditor.common.preferences.PrefData)20 Test (org.junit.Test)17 ArrayList (java.util.ArrayList)9 VersionData (com.sldeditor.common.vendoroption.VersionData)7 Color (java.awt.Color)5 GeoServerVendorOption (com.sldeditor.common.vendoroption.GeoServerVendorOption)3 PrefDataLastViewedEnum (com.sldeditor.common.preferences.PrefDataLastViewedEnum)2 GeoServerConnection (com.sldeditor.common.data.GeoServerConnection)1 SLDData (com.sldeditor.common.data.SLDData)1 SelectedFiles (com.sldeditor.common.filesystem.SelectedFiles)1 UndoEvent (com.sldeditor.common.undo.UndoEvent)1 VendorOptionVersion (com.sldeditor.common.vendoroption.VendorOptionVersion)1 VendorOptionInfo (com.sldeditor.common.vendoroption.info.VendorOptionInfo)1 MinimumVersion (com.sldeditor.common.vendoroption.minversion.MinimumVersion)1 VendorOptionPresent (com.sldeditor.common.vendoroption.minversion.VendorOptionPresent)1 FileSystemExtension (com.sldeditor.extension.filesystem.FileSystemExtension)1 GetMinimumVersionInterface (com.sldeditor.ui.panels.GetMinimumVersionInterface)1 File (java.io.File)1 FeatureTypeStyle (org.geotools.styling.FeatureTypeStyle)1 NamedLayer (org.geotools.styling.NamedLayer)1