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
@ -133,12 +133,21 @@ public class GSVersionDecoder extends XmlElement {
|
||||
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) {
|
||||
return new GSVersionDecoder(response);
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
|
||||
@ -41,6 +41,34 @@ import org.jdom.filter.Filter;
|
||||
*
|
||||
* 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 {
|
||||
|
||||
|
||||
@ -45,6 +45,8 @@ import it.geosolutions.geoserver.rest.encoder.utils.XmlElement;
|
||||
*
|
||||
* The layer encoder is enabled by default
|
||||
*
|
||||
* @since gs-2.1.x
|
||||
*
|
||||
*/
|
||||
public class GSLayerEncoder21 extends GSLayerEncoder {
|
||||
|
||||
|
||||
@ -166,9 +166,25 @@ public abstract class GSResourceEncoder extends PropertyXMLEncoder {
|
||||
}
|
||||
|
||||
public void addKeyword(String keyword) {
|
||||
final Element el = new Element("string");
|
||||
el.setText(keyword);
|
||||
keywordsListEncoder.addContent(el);
|
||||
checkKeyword(keyword);
|
||||
putKeyword(keyword);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@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
|
||||
*/
|
||||
public boolean delKeyword(final String keyword) {
|
||||
final Element el = new Element("string");
|
||||
el.setText(keyword);
|
||||
return removeKeyword(keyword, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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() {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public boolean matches(Object obj) {
|
||||
if (((Element) obj).getText().equals(keyword)) {
|
||||
if (((Element) obj).getText().equals(text)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@ -192,6 +223,31 @@ public abstract class GSResourceEncoder extends PropertyXMLEncoder {
|
||||
})).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
|
||||
*
|
||||
|
||||
@ -47,7 +47,6 @@ public class GSCoverageEncoder extends GSResourceEncoder {
|
||||
|
||||
public GSCoverageEncoder() {
|
||||
super("coverage");
|
||||
addContent(dimensionsEncoder);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -78,10 +78,10 @@ public class VersionDecoderTest extends GeoserverRESTTest {
|
||||
if (!enabled())
|
||||
return;
|
||||
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);
|
||||
} else if (GSVersionDecoder.VERSION.UNRECOGNIZED.equals(GSVersionDecoder.VERSION
|
||||
.getVersion(VERSION))) {
|
||||
.getVersion(GS_VERSION))) {
|
||||
Assert.assertEquals(geoserver.getVersion(), GSVersionDecoder.VERSION.UNRECOGNIZED);
|
||||
}
|
||||
// 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.RESTLayerGroup;
|
||||
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 java.net.MalformedURLException;
|
||||
@ -77,7 +78,7 @@ public abstract class GeoserverRESTTest {
|
||||
public static final String RESTPW;
|
||||
|
||||
// geoserver target version
|
||||
public static final String VERSION;
|
||||
public static final String GS_VERSION;
|
||||
|
||||
public static URL URL;
|
||||
|
||||
@ -95,7 +96,7 @@ public abstract class GeoserverRESTTest {
|
||||
RESTURL = getenv("gsmgr_resturl", "http://localhost:8080/geoserver");
|
||||
RESTUSER = getenv("gsmgr_restuser", "admin");
|
||||
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
|
||||
enabled = getenv("gsmgr_resttest", "false").equalsIgnoreCase("true");
|
||||
@ -138,9 +139,9 @@ public abstract class GeoserverRESTTest {
|
||||
}
|
||||
|
||||
GSVersionDecoder v=reader.getGeoserverVersion();
|
||||
if (!v.getVersion().equals(GSVersionDecoder.VERSION.getVersion(VERSION))){
|
||||
System.out.println("Failing tests : geoserver version does not match.\nAccepted versions: "+GSVersionDecoder.VERSION.print());
|
||||
fail("GeoServer version ("+v.getVersion()+") does not match the desired one (+VERSION+)");
|
||||
if (v.compareTo(VERSION.getVersion(GS_VERSION))!=0){
|
||||
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 ("+GS_VERSION+")");
|
||||
}
|
||||
} else {
|
||||
System.out.println("Skipping tests ");
|
||||
|
||||
@ -90,10 +90,10 @@ public class GSFeatureEncoderTest extends GeoserverRESTTest {
|
||||
fte.addMetadataLinkInfo(metadatalink);
|
||||
|
||||
GSLayerEncoder layerEncoder = null;
|
||||
if (!GSVersionDecoder.VERSION.getVersion(VERSION).equals(
|
||||
if (!GSVersionDecoder.VERSION.getVersion(GS_VERSION).equals(
|
||||
GSVersionDecoder.VERSION.UNRECOGNIZED)) {
|
||||
layerEncoder = new GSLayerEncoder();
|
||||
} else if (GSVersionDecoder.VERSION.getVersion(VERSION).equals(
|
||||
} else if (GSVersionDecoder.VERSION.getVersion(GS_VERSION).equals(
|
||||
GSVersionDecoder.VERSION.UNRECOGNIZED)) {
|
||||
layerEncoder = new GSLayerEncoder21();
|
||||
}
|
||||
@ -224,13 +224,17 @@ public class GSFeatureEncoderTest extends GeoserverRESTTest {
|
||||
public void testModifyFeature() {
|
||||
GSFeatureTypeEncoder encoder = new GSFeatureTypeEncoder();
|
||||
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("KEYWORD_N");
|
||||
|
||||
assertTrue(encoder.delKeyword("KEYWORD_2"));
|
||||
assertFalse(encoder.delKeyword("KEYWORD_M"));
|
||||
|
||||
encoder.addKeyword("KEYWORD_2");
|
||||
assertFalse(encoder.delKeyword("KEYWORD_2","LAN_1","VOCAB_1"));
|
||||
assertTrue(encoder.delKeyword("KEYWORD_2"));
|
||||
|
||||
// metadataLinkInfo
|
||||
encoder.addMetadataLinkInfo("text/xml", "ISO19115:2003",
|
||||
"http://www.organization.org/metadata1");
|
||||
|
||||
@ -110,7 +110,7 @@ public class GeoserverRESTImageMosaicTest extends GeoserverRESTTest {
|
||||
coverageEncoder.setUSE_JAI_IMAGEREAD(true);
|
||||
|
||||
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)
|
||||
GSCoverageDimensionEncoder gsCoverageDimensionEncoder = new GSCoverageDimensionEncoder(
|
||||
"GRAY_INDEX", "GridSampleDimension[-Infinity,Infinity]", "-inf", "inf",
|
||||
|
||||
Loading…
Reference in New Issue
Block a user