improve versions checking and junit related tests. improve keywords and add lang and vocabulary support. improve junit tests.
This commit is contained in:
parent
0f833b2664
commit
5accaa01ed
@ -132,13 +132,22 @@ public class GSVersionDecoder extends XmlElement {
|
|||||||
Element e = ElementUtils.contains(geoserver.version, GSAboutResource.VERSION);
|
Element e = ElementUtils.contains(geoserver.version, GSAboutResource.VERSION);
|
||||||
return VERSION.getVersion(e.getTextTrim());
|
return VERSION.getVersion(e.getTextTrim());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see {@link Enum#compareTo(Enum)}
|
||||||
|
* @param v
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public int compareTo(VERSION v) {
|
||||||
|
return getVersion().compareTo(v);
|
||||||
|
}
|
||||||
|
|
||||||
public static GSVersionDecoder build(String response) {
|
public static GSVersionDecoder build(String response) {
|
||||||
return new GSVersionDecoder(response);
|
return new GSVersionDecoder(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum VERSION {
|
public enum VERSION {
|
||||||
v22(22), v23(23), v24(24), v25(25), ABOVE(9999), UNRECOGNIZED(-1);
|
UNRECOGNIZED(-1), v22(22), v23(23), v24(24), v25(25), ABOVE(9999);
|
||||||
|
|
||||||
final private int version;
|
final private int version;
|
||||||
|
|
||||||
|
|||||||
@ -41,6 +41,34 @@ import org.jdom.filter.Filter;
|
|||||||
*
|
*
|
||||||
* The layer encoder is enabled by default
|
* The layer encoder is enabled by default
|
||||||
*
|
*
|
||||||
|
* {@code
|
||||||
|
* <layer>
|
||||||
|
* <name>{LAYERNAME}</name>
|
||||||
|
* <type>RASTER</type>
|
||||||
|
* <defaultStyle>
|
||||||
|
* <name>{STYLE_NAME}</name>
|
||||||
|
* <atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="alternate" href="http://{GSURL}/rest/styles/{STYLE}xml" type="application/xml"/>
|
||||||
|
* </defaultStyle>
|
||||||
|
* <resource class="coverage">
|
||||||
|
* <name>{RESOURCE_NAME}</name>
|
||||||
|
* <atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="alternate"
|
||||||
|
* href="http://{GSURL}/rest/workspaces/{WS}/coveragestores/{STORE}/coverages/{LAYER}.xml" type="application/xml"/>
|
||||||
|
* </resource>
|
||||||
|
* <attribution>
|
||||||
|
* <title>test</title>
|
||||||
|
* <href>http://www.fao.org/fileadmin/templates/faoweb/images/FAO-logo.png</href>
|
||||||
|
* <logoURL>http://www.fao.org/fileadmin/templates/faoweb/images/FAO-logo.png</logoURL>
|
||||||
|
* <logoWidth>412</logoWidth>
|
||||||
|
* <logoHeight>77</logoHeight>
|
||||||
|
* <logoType>image/png</logoType>
|
||||||
|
* </attribution>
|
||||||
|
* ...
|
||||||
|
*
|
||||||
|
* </layer>
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @since gs-2.2.x
|
||||||
*/
|
*/
|
||||||
public class GSLayerEncoder extends PropertyXMLEncoder {
|
public class GSLayerEncoder extends PropertyXMLEncoder {
|
||||||
|
|
||||||
@ -50,7 +78,7 @@ public class GSLayerEncoder extends PropertyXMLEncoder {
|
|||||||
|
|
||||||
final private Element stylesEncoder = new Element(STYLES);
|
final private Element stylesEncoder = new Element(STYLES);
|
||||||
final private Element authorityURLListEncoder = new Element(AUTHORITY_URLS);
|
final private Element authorityURLListEncoder = new Element(AUTHORITY_URLS);
|
||||||
final private Element identifierListEncoder = new Element(IDENTIFIERS);
|
final private Element identifierListEncoder = new Element(IDENTIFIERS);
|
||||||
|
|
||||||
public GSLayerEncoder() {
|
public GSLayerEncoder() {
|
||||||
super("layer");
|
super("layer");
|
||||||
|
|||||||
@ -45,6 +45,8 @@ import it.geosolutions.geoserver.rest.encoder.utils.XmlElement;
|
|||||||
*
|
*
|
||||||
* The layer encoder is enabled by default
|
* The layer encoder is enabled by default
|
||||||
*
|
*
|
||||||
|
* @since gs-2.1.x
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
public class GSLayerEncoder21 extends GSLayerEncoder {
|
public class GSLayerEncoder21 extends GSLayerEncoder {
|
||||||
|
|
||||||
|
|||||||
@ -166,9 +166,25 @@ public abstract class GSResourceEncoder extends PropertyXMLEncoder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void addKeyword(String keyword) {
|
public void addKeyword(String keyword) {
|
||||||
final Element el = new Element("string");
|
checkKeyword(keyword);
|
||||||
el.setText(keyword);
|
putKeyword(keyword);
|
||||||
keywordsListEncoder.addContent(el);
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@code
|
||||||
|
* <keywords>
|
||||||
|
* <string>WCS</string>
|
||||||
|
* <string>ImageMosaic</string>
|
||||||
|
* <string>srtm30</string> <string> KEYWORD}\@language={LANGUAGE}\;\@vocabulary={VOCABULARY}\;</string>
|
||||||
|
* <string>{KEYWORD_2}\@vocabulary={VOCABULARY_2}\;</string> <string>{KEYWORD_3}\@language={LANGUAGE_3}\;</string> </keywords> }
|
||||||
|
*
|
||||||
|
* @param keyword mandatory keyword ('\' characters are not permitted)
|
||||||
|
* @param language optional parameter
|
||||||
|
* @param vocabulary optional parameter
|
||||||
|
*/
|
||||||
|
public void addKeyword(final String keyword, final String language, final String vocabulary) {
|
||||||
|
checkKeyword(keyword);
|
||||||
|
putKeyword(buildKeyword(keyword, language, vocabulary));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -178,13 +194,28 @@ public abstract class GSResourceEncoder extends PropertyXMLEncoder {
|
|||||||
* @return true if something is removed, false otherwise
|
* @return true if something is removed, false otherwise
|
||||||
*/
|
*/
|
||||||
public boolean delKeyword(final String keyword) {
|
public boolean delKeyword(final String keyword) {
|
||||||
final Element el = new Element("string");
|
return removeKeyword(keyword, null, null);
|
||||||
el.setText(keyword);
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* delete a keyword from the list
|
||||||
|
*
|
||||||
|
* @param keyword
|
||||||
|
* @return true if something is removed, false otherwise
|
||||||
|
*/
|
||||||
|
public boolean delKeyword(final String keyword, final String language, final String vocabulary) {
|
||||||
|
return removeKeyword(keyword, language, vocabulary);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean removeKeyword(final String keyword, final String language,
|
||||||
|
final String vocabulary) {
|
||||||
|
checkKeyword(keyword);
|
||||||
|
final String text = buildKeyword(keyword, language, vocabulary);
|
||||||
return (keywordsListEncoder.removeContent(new Filter() {
|
return (keywordsListEncoder.removeContent(new Filter() {
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
public boolean matches(Object obj) {
|
public boolean matches(Object obj) {
|
||||||
if (((Element) obj).getText().equals(keyword)) {
|
if (((Element) obj).getText().equals(text)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@ -192,6 +223,31 @@ public abstract class GSResourceEncoder extends PropertyXMLEncoder {
|
|||||||
})).size() == 0 ? false : true;
|
})).size() == 0 ? false : true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void putKeyword(String keyword) {
|
||||||
|
final Element el = new Element("string");
|
||||||
|
el.setText(keyword);
|
||||||
|
keywordsListEncoder.addContent(el);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkKeyword(String keyword) {
|
||||||
|
if (keyword == null || keyword.isEmpty() || keyword.contains("\\")) {
|
||||||
|
throw new IllegalArgumentException("keyword may not be null, empty or contains '\'");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String buildKeyword(final String keyword, final String language, final String vocabulary) {
|
||||||
|
StringBuilder sb = new StringBuilder(keyword);
|
||||||
|
// \@language={LANGUAGE_3}\;
|
||||||
|
if (language != null && !language.isEmpty()) {
|
||||||
|
sb.append("\\@language=").append(language).append("\\;");
|
||||||
|
}
|
||||||
|
// \@vocabulary={VOCABULARY}\;
|
||||||
|
if (vocabulary != null && !vocabulary.isEmpty()) {
|
||||||
|
sb.append("\\@vocabulary=").append(vocabulary).append("\\;");
|
||||||
|
}
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a MetadataLinkInfo to the GeoServer Resource
|
* Adds a MetadataLinkInfo to the GeoServer Resource
|
||||||
*
|
*
|
||||||
|
|||||||
@ -47,7 +47,6 @@ public class GSCoverageEncoder extends GSResourceEncoder {
|
|||||||
|
|
||||||
public GSCoverageEncoder() {
|
public GSCoverageEncoder() {
|
||||||
super("coverage");
|
super("coverage");
|
||||||
addContent(dimensionsEncoder);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -78,10 +78,10 @@ public class VersionDecoderTest extends GeoserverRESTTest {
|
|||||||
if (!enabled())
|
if (!enabled())
|
||||||
return;
|
return;
|
||||||
GSVersionDecoder geoserver = reader.getGeoserverVersion();
|
GSVersionDecoder geoserver = reader.getGeoserverVersion();
|
||||||
if (GSVersionDecoder.VERSION.v22.equals(GSVersionDecoder.VERSION.getVersion(VERSION))) {
|
if (GSVersionDecoder.VERSION.v22.equals(GSVersionDecoder.VERSION.getVersion(GS_VERSION))) {
|
||||||
Assert.assertEquals(geoserver.getVersion(), GSVersionDecoder.VERSION.v22);
|
Assert.assertEquals(geoserver.getVersion(), GSVersionDecoder.VERSION.v22);
|
||||||
} else if (GSVersionDecoder.VERSION.UNRECOGNIZED.equals(GSVersionDecoder.VERSION
|
} else if (GSVersionDecoder.VERSION.UNRECOGNIZED.equals(GSVersionDecoder.VERSION
|
||||||
.getVersion(VERSION))) {
|
.getVersion(GS_VERSION))) {
|
||||||
Assert.assertEquals(geoserver.getVersion(), GSVersionDecoder.VERSION.UNRECOGNIZED);
|
Assert.assertEquals(geoserver.getVersion(), GSVersionDecoder.VERSION.UNRECOGNIZED);
|
||||||
}
|
}
|
||||||
// print(dec.getRoot());
|
// print(dec.getRoot());
|
||||||
|
|||||||
@ -32,6 +32,7 @@ import it.geosolutions.geoserver.rest.decoder.RESTFeatureType;
|
|||||||
import it.geosolutions.geoserver.rest.decoder.RESTLayer;
|
import it.geosolutions.geoserver.rest.decoder.RESTLayer;
|
||||||
import it.geosolutions.geoserver.rest.decoder.RESTLayerGroup;
|
import it.geosolutions.geoserver.rest.decoder.RESTLayerGroup;
|
||||||
import it.geosolutions.geoserver.rest.decoder.about.GSVersionDecoder;
|
import it.geosolutions.geoserver.rest.decoder.about.GSVersionDecoder;
|
||||||
|
import it.geosolutions.geoserver.rest.decoder.about.GSVersionDecoder.VERSION;
|
||||||
import it.geosolutions.geoserver.rest.decoder.utils.NameLinkElem;
|
import it.geosolutions.geoserver.rest.decoder.utils.NameLinkElem;
|
||||||
|
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
@ -77,7 +78,7 @@ public abstract class GeoserverRESTTest {
|
|||||||
public static final String RESTPW;
|
public static final String RESTPW;
|
||||||
|
|
||||||
// geoserver target version
|
// geoserver target version
|
||||||
public static final String VERSION;
|
public static final String GS_VERSION;
|
||||||
|
|
||||||
public static URL URL;
|
public static URL URL;
|
||||||
|
|
||||||
@ -95,7 +96,7 @@ public abstract class GeoserverRESTTest {
|
|||||||
RESTURL = getenv("gsmgr_resturl", "http://localhost:8080/geoserver");
|
RESTURL = getenv("gsmgr_resturl", "http://localhost:8080/geoserver");
|
||||||
RESTUSER = getenv("gsmgr_restuser", "admin");
|
RESTUSER = getenv("gsmgr_restuser", "admin");
|
||||||
RESTPW = getenv("gsmgr_restpw", "geoserver");
|
RESTPW = getenv("gsmgr_restpw", "geoserver");
|
||||||
VERSION = getenv("gsmgr_version", "2.4");
|
GS_VERSION = getenv("gsmgr_version", "2.4");
|
||||||
|
|
||||||
// These tests will destroy data, so let's make sure we do want to run them
|
// These tests will destroy data, so let's make sure we do want to run them
|
||||||
enabled = getenv("gsmgr_resttest", "false").equalsIgnoreCase("true");
|
enabled = getenv("gsmgr_resttest", "false").equalsIgnoreCase("true");
|
||||||
@ -138,9 +139,9 @@ public abstract class GeoserverRESTTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
GSVersionDecoder v=reader.getGeoserverVersion();
|
GSVersionDecoder v=reader.getGeoserverVersion();
|
||||||
if (!v.getVersion().equals(GSVersionDecoder.VERSION.getVersion(VERSION))){
|
if (v.compareTo(VERSION.getVersion(GS_VERSION))!=0){
|
||||||
System.out.println("Failing tests : geoserver version does not match.\nAccepted versions: "+GSVersionDecoder.VERSION.print());
|
System.out.println("Failing tests : geoserver version does not match.\nAccepted versions: "+VERSION.print());
|
||||||
fail("GeoServer version ("+v.getVersion()+") does not match the desired one (+VERSION+)");
|
fail("GeoServer version ("+v.getVersion()+") does not match the desired one ("+GS_VERSION+")");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
System.out.println("Skipping tests ");
|
System.out.println("Skipping tests ");
|
||||||
|
|||||||
@ -90,10 +90,10 @@ public class GSFeatureEncoderTest extends GeoserverRESTTest {
|
|||||||
fte.addMetadataLinkInfo(metadatalink);
|
fte.addMetadataLinkInfo(metadatalink);
|
||||||
|
|
||||||
GSLayerEncoder layerEncoder = null;
|
GSLayerEncoder layerEncoder = null;
|
||||||
if (!GSVersionDecoder.VERSION.getVersion(VERSION).equals(
|
if (!GSVersionDecoder.VERSION.getVersion(GS_VERSION).equals(
|
||||||
GSVersionDecoder.VERSION.UNRECOGNIZED)) {
|
GSVersionDecoder.VERSION.UNRECOGNIZED)) {
|
||||||
layerEncoder = new GSLayerEncoder();
|
layerEncoder = new GSLayerEncoder();
|
||||||
} else if (GSVersionDecoder.VERSION.getVersion(VERSION).equals(
|
} else if (GSVersionDecoder.VERSION.getVersion(GS_VERSION).equals(
|
||||||
GSVersionDecoder.VERSION.UNRECOGNIZED)) {
|
GSVersionDecoder.VERSION.UNRECOGNIZED)) {
|
||||||
layerEncoder = new GSLayerEncoder21();
|
layerEncoder = new GSLayerEncoder21();
|
||||||
}
|
}
|
||||||
@ -224,12 +224,16 @@ public class GSFeatureEncoderTest extends GeoserverRESTTest {
|
|||||||
public void testModifyFeature() {
|
public void testModifyFeature() {
|
||||||
GSFeatureTypeEncoder encoder = new GSFeatureTypeEncoder();
|
GSFeatureTypeEncoder encoder = new GSFeatureTypeEncoder();
|
||||||
encoder.addKeyword("KEYWORD_1");
|
encoder.addKeyword("KEYWORD_1");
|
||||||
encoder.addKeyword("KEYWORD_2");
|
encoder.addKeyword("KEYWORD_1","LAN_1","VOCAB_1");
|
||||||
|
assertTrue(encoder.delKeyword("KEYWORD_1","LAN_1","VOCAB_1"));
|
||||||
|
|
||||||
encoder.addKeyword("...");
|
encoder.addKeyword("...");
|
||||||
encoder.addKeyword("KEYWORD_N");
|
encoder.addKeyword("KEYWORD_N");
|
||||||
|
|
||||||
assertTrue(encoder.delKeyword("KEYWORD_2"));
|
|
||||||
assertFalse(encoder.delKeyword("KEYWORD_M"));
|
assertFalse(encoder.delKeyword("KEYWORD_M"));
|
||||||
|
|
||||||
|
encoder.addKeyword("KEYWORD_2");
|
||||||
|
assertFalse(encoder.delKeyword("KEYWORD_2","LAN_1","VOCAB_1"));
|
||||||
|
assertTrue(encoder.delKeyword("KEYWORD_2"));
|
||||||
|
|
||||||
// metadataLinkInfo
|
// metadataLinkInfo
|
||||||
encoder.addMetadataLinkInfo("text/xml", "ISO19115:2003",
|
encoder.addMetadataLinkInfo("text/xml", "ISO19115:2003",
|
||||||
|
|||||||
@ -110,7 +110,7 @@ public class GeoserverRESTImageMosaicTest extends GeoserverRESTTest {
|
|||||||
coverageEncoder.setUSE_JAI_IMAGEREAD(true);
|
coverageEncoder.setUSE_JAI_IMAGEREAD(true);
|
||||||
|
|
||||||
GSVersionDecoder v=reader.getGeoserverVersion();
|
GSVersionDecoder v=reader.getGeoserverVersion();
|
||||||
if (v.getVersion().equals(GSVersionDecoder.VERSION.getVersion(GSVersionDecoder.VERSION.v24.toString()))){
|
if (v.compareTo(GSVersionDecoder.VERSION.v24)>=0){
|
||||||
// New style dimensions (since gs-2.4.x)
|
// New style dimensions (since gs-2.4.x)
|
||||||
GSCoverageDimensionEncoder gsCoverageDimensionEncoder = new GSCoverageDimensionEncoder(
|
GSCoverageDimensionEncoder gsCoverageDimensionEncoder = new GSCoverageDimensionEncoder(
|
||||||
"GRAY_INDEX", "GridSampleDimension[-Infinity,Infinity]", "-inf", "inf",
|
"GRAY_INDEX", "GridSampleDimension[-Infinity,Infinity]", "-inf", "inf",
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user