adding wms stores integration test

This commit is contained in:
draktina 2015-09-15 11:55:18 +01:00
parent bb0498055e
commit 0220c64288
6 changed files with 434 additions and 1 deletions

View File

@ -646,7 +646,7 @@ public class GeoServerRESTPublisher {
case DATASTORES:
return "dataStore";
case WMSSTORES:
return "wmsstores";
return "wmsStore";
default:
return "coverageStore";
}

View File

@ -0,0 +1,114 @@
package it.geosolutions.geoserver.rest.encoder.wmsstore;
import it.geosolutions.geoserver.rest.GeoServerRESTPublisher;
import it.geosolutions.geoserver.rest.encoder.GSAbstractStoreEncoder;
import it.geosolutions.geoserver.rest.encoder.coverage.GSCoverageEncoder;
import it.geosolutions.geoserver.rest.encoder.datastore.GSAbstractDatastoreEncoder;
import it.geosolutions.geoserver.rest.encoder.utils.ElementUtils;
import org.jdom.Element;
import java.net.URL;
/**
* Created by drakiko on 15/09/2015.
*/
public class GSWmsStoreEncoder extends GSAbstractStoreEncoder {
static final String TYPE = "WMS";
final static String ROOT = "wmsStore";
static final String DEFAULT_MIN_CONNECTIONS = "1";
static final String DEFAULT_MAX_CONNECTIONS = "6";
static final String DEFAULT_CONNECTION_TIMEOUT = "30";
static final String DEFAULT_READ_TIMEOUT = "60";
public GSWmsStoreEncoder(String storeName, URL url) {
super(GeoServerRESTPublisher.StoreType.WMSSTORES, ROOT);
setType(TYPE);
ensureValidName(storeName);
setName(storeName);
ensureValidURL(url);
setCapabilitiesURL(url.toString());
setMaxConnections(DEFAULT_MAX_CONNECTIONS);
setConnectTimeout(DEFAULT_CONNECTION_TIMEOUT);
setReadTimeout(DEFAULT_READ_TIMEOUT);
}
public void setCapabilitiesURL(String capabilitiesURL){
set("capabilitiesURL", capabilitiesURL);
}
public String getCapabilitiesURL(){
Element e = ElementUtils.contains(getRoot(), "capabilitiesURL");
return e!=null?e.getTextTrim():null;
}
public void setUser(String user) {
set("user", user);
}
public String getUser() {
Element e = ElementUtils.contains(getRoot(), "user");
return e!=null?e.getTextTrim():null;
}
public void setPassword(String password) {
set("password", password);
}
public String getPassword() {
Element e = ElementUtils.contains(getRoot(), "password");
return e!=null?e.getTextTrim():null;
}
public void setMaxConnections(String maxConnections) {
set("maxConnections", maxConnections);
}
public String getMaxConnections() {
Element e = ElementUtils.contains(getRoot(), "maxConnections");
return e!=null?e.getTextTrim():null;
}
public void setReadTimeout(String readTimeout) {
set("readTimeout", readTimeout);
}
public String getReadTimeout() {
Element e = ElementUtils.contains(getRoot(), "readTimeout");
return e!=null?e.getTextTrim():null;
}
public void setConnectTimeout(String connectTimeout) {
set("connectTimeout", connectTimeout);
}
public String getConnectTimeout() {
Element e = ElementUtils.contains(getRoot(), "connectTimeout");
return e!=null?e.getTextTrim():null;
}
/**
* @return {@value #TYPE}
*/
protected String getValidType() {
return TYPE;
}
/**
* Check url validity.
*
* @param url the url
* @throws IllegalArgumentException if url is null or empty
*/
private static void ensureValidURL(URL url) {
if (url == null || url.toString().isEmpty()) {
throw new IllegalArgumentException(
"Wms store URL cannot be null or empty");
}
}
}

View File

@ -0,0 +1,49 @@
package it.geosolutions.geoserver.rest.encoder;
import junit.framework.Assert;
import org.junit.Before;
import org.junit.Test;
/**
* Created by drakiko on 14/09/2015.
*/
public class GSWMSLayerEncoderTest {
GSWMSLayerEncoder gswmsLayerEncoder;
@Before
public void setUp() {
gswmsLayerEncoder = new GSWMSLayerEncoder();
gswmsLayerEncoder.setName("WMS_NAME");
gswmsLayerEncoder.setNativeName("WMS_NATIVE_NAME");
gswmsLayerEncoder.setTitle("WMS_TITLE");
gswmsLayerEncoder.setNativeCRS("EPSG:4326");
gswmsLayerEncoder.setEnabled(true);
}
/**
* Test method for {@link GSWMSLayerEncoder#GSWMSLayerEncoder()}.
*/
@Test
public void testProperties() {
Assert.assertEquals(
true,
Boolean.parseBoolean(gswmsLayerEncoder.getRoot().getChild("enabled")
.getValue()));
Assert.assertEquals(
"WMS_NAME",
gswmsLayerEncoder.getRoot().getChild("name").getValue());
Assert.assertEquals(
"WMS_NATIVE_NAME",
gswmsLayerEncoder.getRoot().getChild("nativeName").getValue());
Assert.assertEquals(
"WMS_TITLE",
gswmsLayerEncoder.getRoot().getChild("title").getValue());
Assert.assertEquals(
"EPSG:4326",
gswmsLayerEncoder.getRoot().getChild("nativeCRS").getValue());
}
}

View File

@ -0,0 +1,68 @@
package it.geosolutions.geoserver.rest.publisher;
import it.geosolutions.geoserver.rest.GeoserverRESTTest;
import it.geosolutions.geoserver.rest.decoder.RESTDataStore;
import it.geosolutions.geoserver.rest.encoder.GSAbstractStoreEncoder;
import it.geosolutions.geoserver.rest.encoder.GSLayerEncoder;
import it.geosolutions.geoserver.rest.encoder.GSWMSLayerEncoder;
import it.geosolutions.geoserver.rest.manager.GeoServerRESTStoreManager;
import org.junit.After;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.FileNotFoundException;
import java.io.IOException;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
/**
* Testcase for publishing wms layers on geoserver.
* We need a running GeoServer to properly run the tests.
* If such geoserver instance cannot be contacted, tests will be skipped.
*
* @author draktina
*/
public class GeoserverRESTPublisherWmsTest extends GeoserverRESTTest {
private final static Logger LOGGER = LoggerFactory.getLogger(GeoserverRESTPublisherWmsTest.class);
@After
public void cleanUp(){
}
@Test
public void testPublishUnexistingWmsLayer(){
if (!enabled()) {
return;
}
String wsName = "this_ws_does_not_exist";
String storeName = "this_store_does_not_exist";
String layerName ="this_layer_does_not_exist";
GSWMSLayerEncoder gswmsLayerEncoder = new GSWMSLayerEncoder();
gswmsLayerEncoder.setName(layerName);
GSLayerEncoder layerEncoder = new GSLayerEncoder();
boolean ok = publisher.publishWMSLayer(wsName, storeName, gswmsLayerEncoder, layerEncoder);
assertFalse("added not existing layer", ok);
}
@Test
public void testUnpublishUnexistingWmsLayer() throws IOException {
if (!enabled()) {
return;
}
String wsName = "this_ws_does_not_exist";
String storeName = "this_store_does_not_exist";
String layerName ="this_layer_does_not_exist";
boolean ok = publisher.unpublishWmsLayer(wsName, storeName, layerName);
assertFalse("removed not existing layer", ok);
}
}

View File

@ -0,0 +1,36 @@
package it.geosolutions.geoserver.rest.wmsstore;
import it.geosolutions.geoserver.rest.encoder.GSAbstractStoreEncoder;
import it.geosolutions.geoserver.rest.encoder.datastore.GSOracleNGDatastoreEncoder;
import it.geosolutions.geoserver.rest.encoder.wmsstore.GSWmsStoreEncoder;
import java.net.URL;
import java.net.MalformedURLException;
/**
* Created by drakiko on 15/09/2015.
*/
public class WmsStoreEncoderTest extends WmsStoreIntegrationTest{
public WmsStoreEncoderTest() throws IllegalArgumentException, MalformedURLException {
super(System.getProperty("wmsIgnore", "true").equalsIgnoreCase("true"));
}
@Override
public GSAbstractStoreEncoder getStoreEncoderTest() {
URL url = null;
try {
url = new URL(System.getProperty("wmsStoreUrl", "test"));
} catch (MalformedURLException e) {
//
}
GSWmsStoreEncoder wmsStoreEncoder = new GSWmsStoreEncoder(System.getProperty("wmsDataStoreName", "testWmsIntegration"), url);
wmsStoreEncoder.setEnabled(true);
return wmsStoreEncoder;
}
}

View File

@ -0,0 +1,166 @@
package it.geosolutions.geoserver.rest.wmsstore;
import it.geosolutions.geoserver.rest.GeoserverRESTTest;
import it.geosolutions.geoserver.rest.decoder.RESTWmsStore;
import it.geosolutions.geoserver.rest.encoder.GSAbstractStoreEncoder;
import it.geosolutions.geoserver.rest.encoder.GSLayerEncoder;
import it.geosolutions.geoserver.rest.encoder.GSWMSLayerEncoder;
import it.geosolutions.geoserver.rest.encoder.wmsstore.GSWmsStoreEncoder;
import it.geosolutions.geoserver.rest.manager.GeoServerRESTStoreManager;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.net.MalformedURLException;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
/**
* <P>
* Since these tests require a running Store instance, this is more like integration tests.<br/>
*
* For testing that a wmsstore is properly configured, a layer publication has to be attempted
*
* @see GeoserverRESTTest
*/
public abstract class WmsStoreIntegrationTest extends GeoserverRESTTest {
protected final GeoServerRESTStoreManager storeManager;
/**
* ignore integration tests
*/
protected final boolean ignore;
private final static Logger LOGGER = LoggerFactory.getLogger(WmsStoreIntegrationTest.class);
public boolean isIgnore() {
return ignore;
}
/**
*
* @param ignore true if this test should be disabled
* @throws IllegalArgumentException
* @throws MalformedURLException
*/
public WmsStoreIntegrationTest(boolean ignore) throws IllegalArgumentException,
MalformedURLException {
super();
this.storeManager = new GeoServerRESTStoreManager(URL, RESTUSER, RESTPW);
this.ignore = ignore;
}
public abstract GSAbstractStoreEncoder getStoreEncoderTest();
@Test
public void testCreateWmsStore() throws IllegalArgumentException, MalformedURLException {
if (!enabled() || ignore) {
return;
}
// deleteAll();
assertTrue(publisher.createWorkspace(DEFAULT_WS));
// creation test
GSAbstractStoreEncoder storeEncoder = getStoreEncoderTest();
String storeName = storeEncoder.getName();
// String description = storeEncoder.getDescription();
boolean created = storeManager.create(DEFAULT_WS, storeEncoder);
assertTrue("*** store " + storeName + " has not been created.", created);
RESTWmsStore wmsStore = reader.getWmsStore(DEFAULT_WS, storeName);
assertNotNull(wmsStore);
// check if the wmsstore is properly configured in GS for publishing layers
String layername = "wmsStoreLayer";
if (storeEncoder instanceof GSWmsStoreEncoder)
layername = layername.toUpperCase();
GSWMSLayerEncoder fte = new GSWMSLayerEncoder();
fte.setName(layername);
fte.setNativeName(layername);
fte.setTitle(layername);
fte.setNativeCRS("EPSG:4326");
fte.setEnabled(true);
GSLayerEncoder layerEncoder = new GSLayerEncoder();
layerEncoder.setEnabled(true);
layerEncoder.setQueryable(true);
layerEncoder.setDefaultStyle("polygon");
boolean published = publisher.publishWMSLayer(DEFAULT_WS, storeName, fte, layerEncoder);
assertTrue("*** Test layer " + layername
+ " has not been published. Problem in wms store configuration", published);
// removing test
boolean removed = storeManager.remove(DEFAULT_WS, storeEncoder, true);
assertTrue("*** Wmsstore " + storeName + " has not been removed.", removed);
assertTrue(publisher.removeWorkspace(DEFAULT_WS, false));
}
@Test
public void testUnpublishWmsStore() throws IllegalArgumentException, MalformedURLException {
if (!enabled() || ignore) {
return;
}
// deleteAll();
assertTrue(publisher.createWorkspace(DEFAULT_WS));
// creation test
GSAbstractStoreEncoder storeEncoder = getStoreEncoderTest();
String storeName = storeEncoder.getName();
// String description = storeEncoder.getDescription();
boolean created = storeManager.create(DEFAULT_WS, storeEncoder);
assertTrue("*** store " + storeName + " has not been created.", created);
RESTWmsStore wmsStore = reader.getWmsStore(DEFAULT_WS, storeName);
assertNotNull(wmsStore);
// check if the wmsstore is properly configured in GS for publishing layers
String layername = "wmsStoreLayer";
if (storeEncoder instanceof GSWmsStoreEncoder)
layername = layername.toUpperCase();
GSWMSLayerEncoder fte = new GSWMSLayerEncoder();
fte.setName(layername);
fte.setNativeName(layername);
fte.setTitle(layername);
fte.setNativeCRS("EPSG:4326");
fte.setEnabled(true);
GSLayerEncoder layerEncoder = new GSLayerEncoder();
layerEncoder.setEnabled(true);
layerEncoder.setQueryable(true);
layerEncoder.setDefaultStyle("polygon");
boolean published = publisher.publishWMSLayer(DEFAULT_WS, storeName, fte, layerEncoder);
assertTrue("*** Test layer " + layername
+ " has not been published. Problem in wms store configuration", published);
boolean unpublished = publisher.unpublishWmsLayer(DEFAULT_WS, storeName, layername);
assertTrue("*** Test layer " + layername
+ " has not been unpublished. Problem in wms store configuration", unpublished);
// removing test
boolean removed = storeManager.remove(DEFAULT_WS, storeEncoder, true);
assertTrue("*** Wmsstore " + storeName + " has not been removed.", removed);
assertTrue(publisher.removeWorkspace(DEFAULT_WS, false));
}
}