Merge pull request #85 from eblondel/master-84-GSLayerEncoder-multiple-styles
#84 - master - support encoding of multiple styles + tests
This commit is contained in:
commit
205cd75285
@ -26,7 +26,7 @@
|
||||
package it.geosolutions.geoserver.rest.encoder;
|
||||
|
||||
import org.jdom.Element;
|
||||
|
||||
import org.jdom.filter.Filter;
|
||||
import it.geosolutions.geoserver.rest.encoder.utils.PropertyXMLEncoder;
|
||||
|
||||
/**
|
||||
@ -38,10 +38,14 @@ import it.geosolutions.geoserver.rest.encoder.utils.PropertyXMLEncoder;
|
||||
*
|
||||
*/
|
||||
public class GSLayerEncoder extends PropertyXMLEncoder {
|
||||
|
||||
|
||||
public final static String STYLES = "styles";
|
||||
final private Element stylesEncoder = new Element(STYLES);
|
||||
|
||||
public GSLayerEncoder() {
|
||||
super("layer");
|
||||
addEnabled();
|
||||
addContent(stylesEncoder);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -130,4 +134,36 @@ public class GSLayerEncoder extends PropertyXMLEncoder {
|
||||
throw new IllegalArgumentException("Unable to set an empty or null parameter");
|
||||
set("defaultStyle", defaultStyle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a style
|
||||
*
|
||||
* @param style
|
||||
*/
|
||||
public void addStyle(String style) {
|
||||
final Element el = new Element("style");
|
||||
el.setText(style);
|
||||
stylesEncoder.addContent(el);
|
||||
}
|
||||
|
||||
/**
|
||||
* delete a style from the list of available styles
|
||||
*
|
||||
* @param style
|
||||
* @return true if something is removed, false otherwise
|
||||
*/
|
||||
public boolean delStyle(final String style) {
|
||||
final Element el = new Element("style");
|
||||
el.setText(style);
|
||||
return (stylesEncoder.removeContent(new Filter() {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public boolean matches(Object obj) {
|
||||
if (((Element) obj).getText().equals(style)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
})).size() == 0 ? false : true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,85 @@
|
||||
/*
|
||||
* Copyright (C) 2007 - 2011 GeoSolutions S.A.S.
|
||||
* http://www.geo-solutions.it
|
||||
*
|
||||
* GPLv3 + Classpath exception
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package it.geosolutions.geoserver.rest.encoder;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.jdom.Element;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* GSLayerEncoderTest
|
||||
*
|
||||
* @author Emmanuel Blondel - emmanuel.blondel1@gmail.com |
|
||||
* emmanuel.blondel@fao.org
|
||||
*/
|
||||
public class GSLayerEncoderTest {
|
||||
|
||||
GSLayerEncoder layerEncoder;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
layerEncoder = new GSLayerEncoder();
|
||||
layerEncoder.setEnabled(true);
|
||||
layerEncoder.setQueryable(true);
|
||||
layerEncoder.setDefaultStyle("point");
|
||||
layerEncoder.addStyle("additional_style1");
|
||||
layerEncoder.addStyle("additional_style2");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProperties() {
|
||||
Assert.assertEquals(
|
||||
true,
|
||||
Boolean.parseBoolean(layerEncoder.getRoot().getChild("enabled")
|
||||
.getValue()));
|
||||
Assert.assertEquals(
|
||||
true,
|
||||
Boolean.parseBoolean(layerEncoder.getRoot()
|
||||
.getChild("queryable").getValue()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultStyle() {
|
||||
Assert.assertEquals("point",
|
||||
layerEncoder.getRoot().getChild("defaultStyle").getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultipleStyles() {
|
||||
Assert.assertEquals(2, layerEncoder.getRoot().getChild("styles")
|
||||
.getChildren().size());
|
||||
Assert.assertEquals("additional_style1", ((Element) layerEncoder
|
||||
.getRoot().getChild("styles").getChildren().get(0)).getText());
|
||||
Assert.assertEquals("additional_style2", ((Element) layerEncoder
|
||||
.getRoot().getChild("styles").getChildren().get(1)).getText());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveStyle() {
|
||||
Assert.assertTrue(layerEncoder.delStyle("additional_style1"));
|
||||
Assert.assertEquals(1, layerEncoder.getRoot().getChild("styles")
|
||||
.getChildren().size());
|
||||
Assert.assertEquals("additional_style2", ((Element) layerEncoder
|
||||
.getRoot().getChild("styles").getChildren().get(0)).getText());
|
||||
}
|
||||
|
||||
}
|
||||
@ -48,6 +48,10 @@ import org.slf4j.LoggerFactory;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
|
||||
/**
|
||||
*
|
||||
* Note on adding multiple available styles to the GSLayerEncoder: - to run the
|
||||
* testIntegration(), 2 clones of the "point" style, named "point2" and "point3"
|
||||
* have to be created.
|
||||
*
|
||||
* @author ETj (etj at geo-solutions.it)
|
||||
* @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it
|
||||
@ -88,6 +92,8 @@ public class GSFeatureEncoderTest extends GeoserverRESTPublisherTest {
|
||||
layerEncoder.setQueryable(true);
|
||||
|
||||
layerEncoder.setDefaultStyle("point");
|
||||
layerEncoder.addStyle("point2");
|
||||
layerEncoder.addStyle("point3");
|
||||
|
||||
publisher.createWorkspace(DEFAULT_WS);
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user