close #105. add getVersion capabilities
This commit is contained in:
parent
a610bc3de9
commit
0c6823057b
@ -41,6 +41,7 @@ import it.geosolutions.geoserver.rest.decoder.RESTNamespaceList;
|
|||||||
import it.geosolutions.geoserver.rest.decoder.RESTResource;
|
import it.geosolutions.geoserver.rest.decoder.RESTResource;
|
||||||
import it.geosolutions.geoserver.rest.decoder.RESTStyleList;
|
import it.geosolutions.geoserver.rest.decoder.RESTStyleList;
|
||||||
import it.geosolutions.geoserver.rest.decoder.RESTWorkspaceList;
|
import it.geosolutions.geoserver.rest.decoder.RESTWorkspaceList;
|
||||||
|
import it.geosolutions.geoserver.rest.decoder.about.GSVersionDecoder;
|
||||||
|
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
@ -167,6 +168,21 @@ public class GeoServerRESTReader {
|
|||||||
return HTTPUtils.httpPing(baseurl + "/rest/", username, password);
|
return HTTPUtils.httpPing(baseurl + "/rest/", username, password);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the version of the target GeoServer
|
||||||
|
*/
|
||||||
|
public GSVersionDecoder getGeoserverVersion() {
|
||||||
|
final String url = baseurl + "/rest/about/version.xml";
|
||||||
|
String xml = load(url);
|
||||||
|
if (xml == null) {
|
||||||
|
GSVersionDecoder v = new GSVersionDecoder();
|
||||||
|
v.getGeoServer().setVersion(GSVersionDecoder.VERSION.BEFORE);
|
||||||
|
return v;
|
||||||
|
} else {
|
||||||
|
return GSVersionDecoder.build(load(url));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
//=== STYLES
|
//=== STYLES
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|||||||
@ -0,0 +1,163 @@
|
|||||||
|
/*
|
||||||
|
* GeoServer-Manager - Simple Manager Library for GeoServer
|
||||||
|
*
|
||||||
|
* Copyright (C) 2007,2011 GeoSolutions S.A.S.
|
||||||
|
* http://www.geo-solutions.it
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package it.geosolutions.geoserver.rest.decoder.about;
|
||||||
|
|
||||||
|
import it.geosolutions.geoserver.rest.decoder.utils.JDOMBuilder;
|
||||||
|
import it.geosolutions.geoserver.rest.encoder.utils.ElementUtils;
|
||||||
|
import it.geosolutions.geoserver.rest.encoder.utils.XmlElement;
|
||||||
|
|
||||||
|
import org.jdom.Attribute;
|
||||||
|
import org.jdom.Element;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Encode an XML for about/version.xml
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class GSVersionDecoder extends XmlElement {
|
||||||
|
public final static String ABOUT = "about";
|
||||||
|
|
||||||
|
final private GSAboutResource geoserver;
|
||||||
|
|
||||||
|
public class GSAboutResource extends XmlElement {
|
||||||
|
public final static String RESOURCE = "resource";
|
||||||
|
|
||||||
|
public final static String NAME = "name";
|
||||||
|
|
||||||
|
public final static String VERSION = "Version";
|
||||||
|
|
||||||
|
final private Element version;
|
||||||
|
|
||||||
|
public GSAboutResource() {
|
||||||
|
super(RESOURCE);
|
||||||
|
version = new Element(VERSION);
|
||||||
|
addContent(version);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
final Attribute _name = this.getRoot().getAttribute(GSAboutResource.NAME);
|
||||||
|
if (name!=null)
|
||||||
|
_name.setValue(name);
|
||||||
|
else
|
||||||
|
this.getRoot().setAttribute(GSAboutResource.NAME, name);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
final Attribute name = this.getRoot().getAttribute(GSAboutResource.NAME);
|
||||||
|
if (name!=null)
|
||||||
|
return name.getValue();
|
||||||
|
else
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GSAboutResource(Element el) {
|
||||||
|
super(el);
|
||||||
|
version = ElementUtils.contains(el, GSAboutResource.VERSION);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setVersion(String v){
|
||||||
|
version.setText(v);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load the string representation into this encoder
|
||||||
|
*
|
||||||
|
* @param document
|
||||||
|
*/
|
||||||
|
public GSVersionDecoder(String document) {
|
||||||
|
super(JDOMBuilder.buildElement(document));
|
||||||
|
geoserver = new GSAboutResource(ElementUtils.contains(this.getRoot(),
|
||||||
|
GSAboutResource.RESOURCE));
|
||||||
|
}
|
||||||
|
|
||||||
|
public GSVersionDecoder() {
|
||||||
|
super("about");
|
||||||
|
geoserver = new GSAboutResource();
|
||||||
|
addContent(geoserver.getRoot());
|
||||||
|
}
|
||||||
|
|
||||||
|
public GSAboutResource getGeoServer(){
|
||||||
|
return geoserver;
|
||||||
|
}
|
||||||
|
|
||||||
|
public VERSION getVersion() {
|
||||||
|
Element e = ElementUtils.contains(geoserver.version, GSAboutResource.VERSION);
|
||||||
|
return VERSION.getVersion(e.getTextTrim());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static GSVersionDecoder build(String response) {
|
||||||
|
return new GSVersionDecoder(response);
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum VERSION {
|
||||||
|
BEFORE(0), v21(21), v22(22), v23(23), v24(24), v25(25), ABOVE(9999), URECOGNIZED(-1);
|
||||||
|
|
||||||
|
final private int version;
|
||||||
|
|
||||||
|
private VERSION(int val) {
|
||||||
|
version = val;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getVersion() {
|
||||||
|
return version;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString(){
|
||||||
|
return Integer.toString(version);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static VERSION getVersion(String v) {
|
||||||
|
if (v.matches("2\\.0.*") || v.matches("1\\..*")) {
|
||||||
|
return BEFORE;
|
||||||
|
} else if (v.matches("2\\.1.*")) {
|
||||||
|
return v21;
|
||||||
|
} else if (v.matches("2\\.2.*")) {
|
||||||
|
return v22;
|
||||||
|
} else if (v.matches("2\\.3.*")) {
|
||||||
|
return v23;
|
||||||
|
} else if (v.matches("2\\.4.*")) {
|
||||||
|
return v24;
|
||||||
|
} else if (v.matches("2\\.5.*")) {
|
||||||
|
return v25;
|
||||||
|
} else if (v.matches("2\\..+")) {
|
||||||
|
return ABOVE;
|
||||||
|
} else {
|
||||||
|
return URECOGNIZED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String print(){
|
||||||
|
return "["+BEFORE+", "+v21+", "+v22+", "+v23+", "+v24+", "+v25+", "+ABOVE+"]";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -49,6 +49,10 @@ public class XmlElement{
|
|||||||
root=new Element(name);
|
root=new Element(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public XmlElement(final Element e) {
|
||||||
|
root = e;
|
||||||
|
}
|
||||||
|
|
||||||
public Element getRoot(){
|
public Element getRoot(){
|
||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,73 @@
|
|||||||
|
/*
|
||||||
|
* GeoBatch - Open Source geospatial batch processing system
|
||||||
|
* https://github.com/nfms4redd/nfms-geobatch
|
||||||
|
* Copyright (C) 2007-2012 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.decoder;
|
||||||
|
|
||||||
|
import it.geosolutions.geoserver.rest.decoder.about.GSVersionDecoder;
|
||||||
|
import it.geosolutions.geoserver.rest.decoder.about.GSVersionDecoder.VERSION;
|
||||||
|
import junit.framework.Assert;
|
||||||
|
|
||||||
|
import org.jdom.Element;
|
||||||
|
import org.jdom.output.XMLOutputter;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Carlo Cancellieri {@code
|
||||||
|
* <about>
|
||||||
|
* <resource name="GeoServer">
|
||||||
|
* <Build-Timestamp>10-Oct-2013 03:08</Build-Timestamp>
|
||||||
|
* <Git-Revision>32db076555e57cc5f826b0361d1af4efe6d3f01b</Git-Revision>
|
||||||
|
* <Version>2.2-ENTERPRISE-SNAPSHOT</Version>
|
||||||
|
* </resource>
|
||||||
|
* <resource name="GeoTools">
|
||||||
|
* <Build-Timestamp>10-Oct-2013 03:01</Build-Timestamp>
|
||||||
|
* <Git-Revision>da12effd42a9545628bd6e8ec20494607fbfe3a4</Git-Revision>
|
||||||
|
* <Version>8-ENTERPRISE-SNAPSHOT</Version>
|
||||||
|
* </resource>
|
||||||
|
* </about>
|
||||||
|
* }
|
||||||
|
*/
|
||||||
|
public class VersionDecoderTest {
|
||||||
|
|
||||||
|
private final String version = "<about><resource name=\"GeoServer\"><Build-Timestamp>10-Oct-2013 03:08</Build-Timestamp>"
|
||||||
|
+ "<Git-Revision>32db076555e57cc5f826b0361d1af4efe6d3f01b</Git-Revision><Version>2.2-ENTERPRISE-SNAPSHOT</Version></resource></about>";
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testVersionDecoder() {
|
||||||
|
|
||||||
|
GSVersionDecoder dec=new GSVersionDecoder(version);
|
||||||
|
Assert.assertEquals(VERSION.v22, dec.getVersion());
|
||||||
|
Assert.assertEquals("GeoServer", dec.getGeoServer().getName());
|
||||||
|
|
||||||
|
GSVersionDecoder.GSAboutResource geoserver=dec.getGeoServer();
|
||||||
|
geoserver.setVersion("2.3-SNAPSHOT");
|
||||||
|
geoserver.setName("_CustomGeoServerName_");
|
||||||
|
Assert.assertEquals(VERSION.v23, dec.getVersion());
|
||||||
|
Assert.assertEquals("_CustomGeoServerName_", dec.getGeoServer().getName());
|
||||||
|
|
||||||
|
//print(dec.getRoot());
|
||||||
|
}
|
||||||
|
|
||||||
|
public String print(Element e){
|
||||||
|
return new XMLOutputter().outputString(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -31,6 +31,7 @@ import it.geosolutions.geoserver.rest.decoder.RESTDataStore;
|
|||||||
import it.geosolutions.geoserver.rest.decoder.RESTFeatureType;
|
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.utils.NameLinkElem;
|
import it.geosolutions.geoserver.rest.decoder.utils.NameLinkElem;
|
||||||
|
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
@ -68,6 +69,9 @@ public abstract class GeoserverRESTTest extends Assert {
|
|||||||
|
|
||||||
public static final String RESTPW;
|
public static final String RESTPW;
|
||||||
|
|
||||||
|
// geoserver target version
|
||||||
|
public static final String VERSION;
|
||||||
|
|
||||||
public static URL URL;
|
public static URL URL;
|
||||||
|
|
||||||
public static GeoServerRESTManager manager;
|
public static GeoServerRESTManager manager;
|
||||||
@ -84,6 +88,7 @@ public abstract class GeoserverRESTTest extends Assert {
|
|||||||
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");
|
||||||
|
|
||||||
// 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");
|
||||||
@ -120,12 +125,16 @@ public abstract class GeoserverRESTTest extends Assert {
|
|||||||
LOGGER.info("Using geoserver instance " + RESTUSER + ":" + RESTPW + " @ "
|
LOGGER.info("Using geoserver instance " + RESTUSER + ":" + RESTPW + " @ "
|
||||||
+ RESTURL);
|
+ RESTURL);
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
|
|
||||||
if (!existgs) {
|
|
||||||
System.out.println("Failing tests : geoserver not found");
|
System.out.println("Failing tests : geoserver not found");
|
||||||
fail("GeoServer not found");
|
fail("GeoServer not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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+)");
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
System.out.println("Skipping tests ");
|
System.out.println("Skipping tests ");
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user