-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2052 from mattkrusz/GEOS-7855-css-styles-missing
[GEOS-7855] Fix for new style editor thinking old CSS styles are SLD
- Loading branch information
Showing
13 changed files
with
351 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
160 changes: 160 additions & 0 deletions
160
src/web/wms/src/test/java/org/geoserver/wms/web/data/StyleEditCssRecoveryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
/* (c) 2017 Open Source Geospatial Foundation - all rights reserved | ||
* This code is licensed under the GPL 2.0 license, available at the root | ||
* application directory. | ||
*/ | ||
package org.geoserver.wms.web.data; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
import java.io.File; | ||
import java.nio.file.Paths; | ||
import java.util.Arrays; | ||
import java.util.Date; | ||
import java.util.List; | ||
|
||
import org.geoserver.catalog.Catalog; | ||
import org.geoserver.catalog.StyleInfo; | ||
import org.geoserver.catalog.Styles; | ||
import org.geoserver.data.test.SystemTestData; | ||
import org.geoserver.web.GeoServerWicketTestSupport; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
/** | ||
* Tests for recovering CSS styles generated by the old (pre-pluggable styles) CSS extension. That extension extension output styles based on | ||
* generated SLD files, without saving a reference to the user's CSS input, and as a result the new style editor treats them as SLD. | ||
* | ||
*/ | ||
public class StyleEditCssRecoveryTest extends GeoServerWicketTestSupport { | ||
|
||
String oldCssStyle = "OldCssStyle"; | ||
|
||
String oldCssStyleWithFormatSLD = "OldCssStyle_Format_Set_To_SLD"; | ||
|
||
String oldCssStyleWithSLDManuallyEdited = "OldCssStyle_SLD_Manually_Edited"; | ||
|
||
Catalog catalog; | ||
|
||
protected void setUpTestData(SystemTestData testData) throws Exception { | ||
super.setUpTestData(testData); | ||
System.out.println("setUpTestData()"); | ||
|
||
Date t0 = new Date(1483228800000L); // Midnight Jan 1, 2017 UTC | ||
List<String> testStyleNames = Arrays.asList(oldCssStyle, oldCssStyleWithFormatSLD, | ||
oldCssStyleWithSLDManuallyEdited); | ||
|
||
for (String styleName : testStyleNames) { | ||
for (String ext : Arrays.asList(".css", ".sld", ".xml")) { | ||
testData.copyTo(this.getClass().getResourceAsStream(styleName + ext), | ||
"styles/" + styleName + ext); | ||
File f = Paths.get(testData.getDataDirectoryRoot().getAbsolutePath(), | ||
"styles/" + styleName + ext).toFile(); | ||
f.setLastModified(t0.getTime()); | ||
} | ||
} | ||
|
||
// Make this SLD file appear as if it was edited after being generated from CSS. | ||
File manuallyEditedSld = Paths.get(testData.getDataDirectoryRoot().getAbsolutePath(), | ||
"styles/" + oldCssStyleWithSLDManuallyEdited + ".sld").toFile(); | ||
manuallyEditedSld.setLastModified(t0.getTime() + 1000000L); | ||
} | ||
|
||
@Override | ||
protected void onSetUp(SystemTestData testData) throws Exception { | ||
super.onSetUp(testData); | ||
} | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
login(); | ||
catalog = getCatalog(); | ||
} | ||
|
||
/** | ||
* Test recovery of a CSS Style generated by the old CSS Extension, when the StyleInfo has no declared <format> and its filename points to a | ||
* derived SLD. | ||
*/ | ||
@Test | ||
public void testRecoverLostCssStyle() throws Exception { | ||
StyleInfo styleInfo = catalog.getStyleByName(oldCssStyle); | ||
StyleEditPage edit = new StyleEditPage(styleInfo); | ||
|
||
tester.startPage(edit); | ||
tester.assertRenderedPage(StyleEditPage.class); | ||
tester.assertNoErrorMessage(); | ||
|
||
// Assert that the page displays the format as css | ||
tester.assertModelValue("styleForm:context:panel:format", "css"); | ||
|
||
// Assert that the editor text area contains css | ||
String editorContents = (String) tester | ||
.getComponentFromLastRenderedPage( | ||
"styleForm:styleEditor:editorContainer:editorParent:editor") | ||
.getDefaultModelObject(); | ||
Styles.handler("css").parse(editorContents, null, null, null); | ||
|
||
// Assert that the catalog's StyleInfo is now a css style | ||
StyleInfo si = catalog.getStyleByName(oldCssStyle); | ||
assertEquals("css", si.getFormat()); | ||
assertEquals(oldCssStyle + ".css", si.getFilename()); | ||
|
||
} | ||
|
||
/** | ||
* Test recovery of a CSS Style generated by the old CSS Extension, when the StyleInfo declares <format>sld</format> and its filename points to a | ||
* derived SLD. | ||
*/ | ||
@Test | ||
public void testRecoverLostCssStyleWithFormatSetToSLD() throws Exception { | ||
StyleInfo styleInfo = catalog.getStyleByName(oldCssStyleWithFormatSLD); | ||
StyleEditPage edit = new StyleEditPage(styleInfo); | ||
|
||
tester.startPage(edit); | ||
tester.assertRenderedPage(StyleEditPage.class); | ||
tester.assertNoErrorMessage(); | ||
|
||
// Assert that the page displays the format as css | ||
tester.assertModelValue("styleForm:context:panel:format", "css"); | ||
|
||
// Assert that the editor text area contains css | ||
String editorContents = (String) tester | ||
.getComponentFromLastRenderedPage( | ||
"styleForm:styleEditor:editorContainer:editorParent:editor") | ||
.getDefaultModelObject(); | ||
Styles.handler("css").parse(editorContents, null, null, null); | ||
|
||
// Assert that the catalog's StyleInfo is now a css style | ||
StyleInfo si = catalog.getStyleByName(oldCssStyleWithFormatSLD); | ||
assertEquals("css", si.getFormat()); | ||
assertEquals(oldCssStyleWithFormatSLD + ".css", si.getFilename()); | ||
} | ||
|
||
/** | ||
* Test that the recovery code does not overwrite generated SLD styles if they were subsequently edited. | ||
*/ | ||
@Test | ||
public void testIgnoreCssStyleIfSLDWasEdited() throws Exception { | ||
StyleInfo styleInfo = catalog.getStyleByName(oldCssStyleWithSLDManuallyEdited); | ||
StyleEditPage edit = new StyleEditPage(styleInfo); | ||
|
||
tester.startPage(edit); | ||
tester.assertRenderedPage(StyleEditPage.class); | ||
tester.assertNoErrorMessage(); | ||
|
||
// Assert that the page displays the format as SLD | ||
tester.assertModelValue("styleForm:context:panel:format", "sld"); | ||
|
||
// Assert that the editor text area contains SLD | ||
String editorContents = (String) tester | ||
.getComponentFromLastRenderedPage( | ||
"styleForm:styleEditor:editorContainer:editorParent:editor") | ||
.getDefaultModelObject(); | ||
Styles.handler("sld").parse(editorContents, null, null, null); | ||
|
||
// Assert that the catalog's StyleInfo is still a SLD style | ||
StyleInfo si = catalog.getStyleByName(oldCssStyleWithSLDManuallyEdited); | ||
assertEquals("sld", si.getFormat()); | ||
assertEquals(oldCssStyleWithSLDManuallyEdited + ".sld", si.getFilename()); | ||
} | ||
|
||
} |
6 changes: 6 additions & 0 deletions
6
src/web/wms/src/test/resources/org/geoserver/wms/web/data/OldCssStyle.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[VTOTAL > 100] { | ||
fill: #0000FF; | ||
fill-opacity: 0.7; | ||
stroke: #000000; | ||
stroke-width: 0.5; | ||
} |
26 changes: 26 additions & 0 deletions
26
src/web/wms/src/test/resources/org/geoserver/wms/web/data/OldCssStyle.sld
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<sld:UserStyle xmlns="http://www.opengis.net/sld" xmlns:sld="http://www.opengis.net/sld" xmlns:gml="http://www.opengis.net/gml" xmlns:ogc="http://www.opengis.net/ogc"> | ||
<sld:Name>Default Styler</sld:Name> | ||
<sld:FeatureTypeStyle> | ||
<sld:Name>name</sld:Name> | ||
<sld:Rule> | ||
<ogc:Filter> | ||
<ogc:PropertyIsGreaterThan> | ||
<ogc:PropertyName>VTOTAL</ogc:PropertyName> | ||
<ogc:Literal>100</ogc:Literal> | ||
</ogc:PropertyIsGreaterThan> | ||
</ogc:Filter> | ||
<sld:PolygonSymbolizer> | ||
<sld:Fill> | ||
<sld:CssParameter name="fill">#0000FF</sld:CssParameter> | ||
<sld:CssParameter name="fill-opacity">0.699999988079071</sld:CssParameter> | ||
</sld:Fill> | ||
</sld:PolygonSymbolizer> | ||
<sld:LineSymbolizer> | ||
<sld:Stroke> | ||
<sld:CssParameter name="stroke-width">0.5</sld:CssParameter> | ||
</sld:Stroke> | ||
</sld:LineSymbolizer> | ||
</sld:Rule> | ||
</sld:FeatureTypeStyle> | ||
</sld:UserStyle> |
8 changes: 8 additions & 0 deletions
8
src/web/wms/src/test/resources/org/geoserver/wms/web/data/OldCssStyle.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<style> | ||
<id>StyleInfoImpl--b5f628e:1598a2fe470:-8000</id> | ||
<name>OldCssStyle</name> | ||
<sldVersion> | ||
<version>1.0.0</version> | ||
</sldVersion> | ||
<filename>OldCssStyle.sld</filename> | ||
</style> |
6 changes: 6 additions & 0 deletions
6
src/web/wms/src/test/resources/org/geoserver/wms/web/data/OldCssStyle_Format_Set_To_SLD.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[VTOTAL > 100] { | ||
fill: #0000FF; | ||
fill-opacity: 0.7; | ||
stroke: #000000; | ||
stroke-width: 0.5; | ||
} |
26 changes: 26 additions & 0 deletions
26
src/web/wms/src/test/resources/org/geoserver/wms/web/data/OldCssStyle_Format_Set_To_SLD.sld
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<sld:UserStyle xmlns="http://www.opengis.net/sld" xmlns:sld="http://www.opengis.net/sld" xmlns:gml="http://www.opengis.net/gml" xmlns:ogc="http://www.opengis.net/ogc"> | ||
<sld:Name>Default Styler</sld:Name> | ||
<sld:FeatureTypeStyle> | ||
<sld:Name>name</sld:Name> | ||
<sld:Rule> | ||
<ogc:Filter> | ||
<ogc:PropertyIsGreaterThan> | ||
<ogc:PropertyName>VTOTAL</ogc:PropertyName> | ||
<ogc:Literal>100</ogc:Literal> | ||
</ogc:PropertyIsGreaterThan> | ||
</ogc:Filter> | ||
<sld:PolygonSymbolizer> | ||
<sld:Fill> | ||
<sld:CssParameter name="fill">#0000FF</sld:CssParameter> | ||
<sld:CssParameter name="fill-opacity">0.699999988079071</sld:CssParameter> | ||
</sld:Fill> | ||
</sld:PolygonSymbolizer> | ||
<sld:LineSymbolizer> | ||
<sld:Stroke> | ||
<sld:CssParameter name="stroke-width">0.5</sld:CssParameter> | ||
</sld:Stroke> | ||
</sld:LineSymbolizer> | ||
</sld:Rule> | ||
</sld:FeatureTypeStyle> | ||
</sld:UserStyle> |
9 changes: 9 additions & 0 deletions
9
src/web/wms/src/test/resources/org/geoserver/wms/web/data/OldCssStyle_Format_Set_To_SLD.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<style> | ||
<id>StyleInfoImpl--b5f628e:1598a2fe470:-7ffc</id> | ||
<name>OldCssStyle_Format_Set_To_SLD</name> | ||
<sldVersion> | ||
<version>1.0.0</version> | ||
</sldVersion> | ||
<filename>OldCssStyle_Format_Set_To_SLD.sld</filename> | ||
<format>sld</format> | ||
</style> |
6 changes: 6 additions & 0 deletions
6
...web/wms/src/test/resources/org/geoserver/wms/web/data/OldCssStyle_SLD_Manually_Edited.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[VTOTAL > 100] { | ||
fill: #0000FF; | ||
fill-opacity: 0.7; | ||
stroke: #000000; | ||
stroke-width: 0.5; | ||
} |
26 changes: 26 additions & 0 deletions
26
...web/wms/src/test/resources/org/geoserver/wms/web/data/OldCssStyle_SLD_Manually_Edited.sld
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<sld:UserStyle xmlns="http://www.opengis.net/sld" xmlns:sld="http://www.opengis.net/sld" xmlns:gml="http://www.opengis.net/gml" xmlns:ogc="http://www.opengis.net/ogc"> | ||
<sld:Name>Default Styler</sld:Name> | ||
<sld:FeatureTypeStyle> | ||
<sld:Name>name</sld:Name> | ||
<sld:Rule> | ||
<ogc:Filter> | ||
<ogc:PropertyIsGreaterThan> | ||
<ogc:PropertyName>VTOTAL</ogc:PropertyName> | ||
<ogc:Literal>100</ogc:Literal> | ||
</ogc:PropertyIsGreaterThan> | ||
</ogc:Filter> | ||
<sld:PolygonSymbolizer> | ||
<sld:Fill> | ||
<sld:CssParameter name="fill">#00FF00</sld:CssParameter> | ||
<sld:CssParameter name="fill-opacity">0.699999988079071</sld:CssParameter> | ||
</sld:Fill> | ||
</sld:PolygonSymbolizer> | ||
<sld:LineSymbolizer> | ||
<sld:Stroke> | ||
<sld:CssParameter name="stroke-width">0.5</sld:CssParameter> | ||
</sld:Stroke> | ||
</sld:LineSymbolizer> | ||
</sld:Rule> | ||
</sld:FeatureTypeStyle> | ||
</sld:UserStyle> |
Oops, something went wrong.