Search in sources :

Example 21 with SLDData

use of com.sldeditor.common.data.SLDData 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);
}
Also used : SLDData(com.sldeditor.common.data.SLDData) StyleWrapper(com.sldeditor.common.data.StyleWrapper) VersionData(com.sldeditor.common.vendoroption.VersionData) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 22 with SLDData

use of com.sldeditor.common.data.SLDData 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());
}
Also used : DataSourceConnector(com.sldeditor.datasource.connector.instance.DataSourceConnector) SLDData(com.sldeditor.common.data.SLDData) StyleWrapper(com.sldeditor.common.data.StyleWrapper) DataSourcePropertiesInterface(com.sldeditor.common.DataSourcePropertiesInterface) DataSourceProperties(com.sldeditor.datasource.impl.DataSourceProperties) SLDEditorFile(com.sldeditor.datasource.SLDEditorFile) File(java.io.File) Test(org.junit.Test)

Example 23 with SLDData

use of com.sldeditor.common.data.SLDData 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 24 with SLDData

use of com.sldeditor.common.data.SLDData 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();
}
Also used : SLDData(com.sldeditor.common.data.SLDData) MalformedURLException(java.net.MalformedURLException) StyleWrapper(com.sldeditor.common.data.StyleWrapper) IOException(java.io.IOException) File(java.io.File) Test(org.junit.Test)

Example 25 with SLDData

use of com.sldeditor.common.data.SLDData in project sldeditor by robward-scisys.

the class ReloadManagerTest method testReloadSavedFile.

@Test
public void testReloadSavedFile() {
    SLDData sldData = new SLDData(new StyleWrapper(), "");
    ReloadManager.getInstance().sldDataUpdated(sldData, true);
    DummyCallback callback = new DummyCallback();
    ReloadManager.getInstance().addListener(callback);
    assertEquals(0, callback.reloadCallbackCalled);
    // Set loaded file - should match
    File expectedFile = new File("/tmp/testFile.sld");
    Path path = expectedFile.toPath();
    sldData.setSLDFile(expectedFile);
    ReloadManager.getInstance().sldDataUpdated(sldData, true);
    // Mark as not saved
    ReloadManager.getInstance().fileModified(path);
    try {
        Thread.sleep(1500);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    assertEquals(1, callback.reloadCallbackCalled);
    // Mark as saved
    callback.reloadCallbackCalled = 0;
    ReloadManager.getInstance().setFileSaved();
    ReloadManager.getInstance().fileModified(path);
    try {
        Thread.sleep(1500);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    assertEquals(0, callback.reloadCallbackCalled);
    // Mark as not saved
    ReloadManager.getInstance().fileModified(path);
    try {
        Thread.sleep(1500);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    assertEquals(1, callback.reloadCallbackCalled);
}
Also used : Path(java.nio.file.Path) SLDData(com.sldeditor.common.data.SLDData) StyleWrapper(com.sldeditor.common.data.StyleWrapper) File(java.io.File) Test(org.junit.Test)

Aggregations

SLDData (com.sldeditor.common.data.SLDData)68 Test (org.junit.Test)54 StyleWrapper (com.sldeditor.common.data.StyleWrapper)35 File (java.io.File)27 StyledLayerDescriptor (org.geotools.styling.StyledLayerDescriptor)24 SLDDataInterface (com.sldeditor.common.SLDDataInterface)20 IOException (java.io.IOException)20 URL (java.net.URL)16 ArrayList (java.util.ArrayList)14 FileTreeNode (com.sldeditor.datasource.extension.filesystem.node.file.FileTreeNode)8 SLDFileHandlerTest (com.sldeditor.test.unit.extension.filesystem.file.sld.SLDFileHandlerTest)8 GeoServerConnection (com.sldeditor.common.data.GeoServerConnection)7 FileNotFoundException (java.io.FileNotFoundException)7 URISyntaxException (java.net.URISyntaxException)7 MalformedURLException (java.net.MalformedURLException)6 NamedLayer (org.geotools.styling.NamedLayer)6 Style (org.geotools.styling.Style)6 SLDWriterInterface (com.sldeditor.common.output.SLDWriterInterface)5 FeatureTypeStyle (org.geotools.styling.FeatureTypeStyle)5 VersionData (com.sldeditor.common.vendoroption.VersionData)4