Search in sources :

Example 16 with StyleWrapper

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);
}
Also used : SLDData(com.sldeditor.common.data.SLDData) StyleWrapper(com.sldeditor.common.data.StyleWrapper) Test(org.junit.Test)

Example 17 with StyleWrapper

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();
    }
}
Also used : SLDData(com.sldeditor.common.data.SLDData) PointSymbolizer(org.geotools.styling.PointSymbolizer) MalformedURLException(java.net.MalformedURLException) StyledLayer(org.geotools.styling.StyledLayer) MarkImpl(org.geotools.styling.MarkImpl) URL(java.net.URL) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) StyleWrapper(com.sldeditor.common.data.StyleWrapper) Style(org.geotools.styling.Style) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) File(java.io.File) NamedLayer(org.geotools.styling.NamedLayer) Test(org.junit.Test)

Example 18 with StyleWrapper

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);
}
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 19 with StyleWrapper

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());
}
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 20 with StyleWrapper

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();
}
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)

Aggregations

StyleWrapper (com.sldeditor.common.data.StyleWrapper)59 SLDData (com.sldeditor.common.data.SLDData)35 Test (org.junit.Test)31 StyledLayerDescriptor (org.geotools.styling.StyledLayerDescriptor)15 File (java.io.File)14 SLDDataInterface (com.sldeditor.common.SLDDataInterface)12 ArrayList (java.util.ArrayList)12 GeoServerConnection (com.sldeditor.common.data.GeoServerConnection)10 SLDFileHandlerTest (com.sldeditor.test.unit.extension.filesystem.file.sld.SLDFileHandlerTest)9 List (java.util.List)9 GeoServerLayer (com.sldeditor.common.data.GeoServerLayer)8 IOException (java.io.IOException)8 GeoServerInput (com.sldeditor.extension.filesystem.geoserver.GeoServerInput)7 SLDWriterInterface (com.sldeditor.common.output.SLDWriterInterface)5 GeoServerStyleNode (com.sldeditor.datasource.extension.filesystem.node.geoserver.GeoServerStyleNode)5 GeoServerWorkspaceNode (com.sldeditor.datasource.extension.filesystem.node.geoserver.GeoServerWorkspaceNode)5 HashMap (java.util.HashMap)5 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)5 SLDEditorFile (com.sldeditor.datasource.SLDEditorFile)4 NamedLayer (org.geotools.styling.NamedLayer)4