fix commit for #105. add integration tests

This commit is contained in:
carlo cancellieri 2013-10-18 16:08:44 +02:00
parent afb6ba3be0
commit 471c860007
4 changed files with 28 additions and 13 deletions

View File

@ -176,11 +176,11 @@ public class GeoServerRESTReader {
* Return the version of the target GeoServer
*/
public GSVersionDecoder getGeoserverVersion() {
final String url = baseurl + "/rest/about/version.xml";
final String url = "/rest/about/version.xml";
String xml = load(url);
if (xml == null) {
GSVersionDecoder v = new GSVersionDecoder();
v.getGeoServer().setVersion(GSVersionDecoder.VERSION.BEFORE);
v.getGeoServer().setVersion(GSVersionDecoder.VERSION.UNRECOGNIZED.toString());
return v;
} else {
return GSVersionDecoder.build(load(url));

View File

@ -119,7 +119,7 @@ public class GSVersionDecoder extends XmlElement {
}
public enum VERSION {
BEFORE(0), v21(21), v22(22), v23(23), v24(24), v25(25), ABOVE(9999), URECOGNIZED(-1);
v22(22), v23(23), v24(24), v25(25), ABOVE(9999), UNRECOGNIZED(-1);
final private int version;
@ -136,10 +136,8 @@ public class GSVersionDecoder extends XmlElement {
}
public static VERSION getVersion(String v) {
if (v.matches("2\\.0.*") || v.matches("1\\..*")) {
return BEFORE;
} else if (v.matches("2\\.1.*")) {
return v21;
if (v==null) {
return UNRECOGNIZED;
} else if (v.matches("2\\.2.*")) {
return v22;
} else if (v.matches("2\\.3.*")) {
@ -151,12 +149,12 @@ public class GSVersionDecoder extends XmlElement {
} else if (v.matches("2\\..+")) {
return ABOVE;
} else {
return URECOGNIZED;
return UNRECOGNIZED;
}
}
public static String print(){
return "["+BEFORE+", "+v21+", "+v22+", "+v23+", "+v24+", "+v25+", "+ABOVE+"]";
return "["+v22+", "+v23+", "+v24+", "+v25+", "+ABOVE+", "+UNRECOGNIZED+"]";
}
}

View File

@ -21,6 +21,9 @@
*/
package it.geosolutions.geoserver.decoder;
import it.geosolutions.geoserver.rest.GeoServerRESTPublisher;
import it.geosolutions.geoserver.rest.GeoServerRESTReader;
import it.geosolutions.geoserver.rest.GeoserverRESTTest;
import it.geosolutions.geoserver.rest.decoder.about.GSVersionDecoder;
import it.geosolutions.geoserver.rest.decoder.about.GSVersionDecoder.VERSION;
import junit.framework.Assert;
@ -45,7 +48,7 @@ import org.junit.Test;
* </about>
* }
*/
public class VersionDecoderTest {
public class VersionDecoderTest extends GeoserverRESTTest {
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>";
@ -54,18 +57,32 @@ public class VersionDecoderTest {
public void testVersionDecoder() {
GSVersionDecoder dec=new GSVersionDecoder(version);
Assert.assertEquals(VERSION.v22, dec.getVersion());
Assert.assertEquals(GSVersionDecoder.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(GSVersionDecoder.VERSION.v23, dec.getVersion());
Assert.assertEquals("_CustomGeoServerName_", dec.getGeoServer().getName());
//print(dec.getRoot());
}
@Test
public void testIntegrationVersionDecoder() {
if (!enabled())
return;
GSVersionDecoder geoserver = reader.getGeoserverVersion();
if (GSVersionDecoder.VERSION.v22.equals(GSVersionDecoder.VERSION.getVersion(VERSION))) {
Assert.assertEquals(geoserver.getVersion(), GSVersionDecoder.VERSION.v22);
} else if (GSVersionDecoder.VERSION.UNRECOGNIZED.equals(GSVersionDecoder.VERSION
.getVersion(VERSION))) {
Assert.assertEquals(geoserver.getVersion(), GSVersionDecoder.VERSION.UNRECOGNIZED);
}
// print(dec.getRoot());
}
public String print(Element e){
return new XMLOutputter().outputString(e);
}

View File

@ -138,7 +138,7 @@ public abstract class GeoserverRESTTest {
}
GSVersionDecoder v=reader.getGeoserverVersion();
if (v.getVersion().equals(GSVersionDecoder.VERSION.getVersion(VERSION))){
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+)");
}