#84 - master - support encoding of multiple styles + tests

This commit is contained in:
eblondel 2013-07-04 19:03:41 +02:00
parent 499924a527
commit 93ec8db2fb
3 changed files with 117 additions and 2 deletions

View File

@ -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,35 @@ public class GSLayerEncoder extends PropertyXMLEncoder {
throw new IllegalArgumentException("Unable to set an empty or null parameter");
set("defaultStyle", defaultStyle);
}
/**
* Add a style
* @param style to add to the list of available styles
*/
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;
}
}

View File

@ -0,0 +1,74 @@
/*
* 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());
}
}

View File

@ -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);