if (!enabled())
return;
deleteAll();
GeoServerRESTPublisher publisher = new GeoServerRESTPublisher(RESTURL, RESTUSER, RESTPW);
String storeName = "resttestshp";
String layerName = "cities";
// build the store
publisher.createWorkspace(DEFAULT_WS);
// test insert
File zipFile = new ClassPathResource("testdata/resttestshp.zip").getFile();
boolean published = publisher.publishShp(DEFAULT_WS, storeName, layerName, zipFile);
assertTrue("publish() failed", published);
publisher.publishStyle(new File(new ClassPathResource("testdata").getFile(),
"default_point.sld"));
String nativeName = layerName;
layerName=layerName+"_NEW";
GSFeatureTypeEncoder fte = new GSFeatureTypeEncoder();
fte.setName(layerName);
fte.setNativeName(nativeName);
fte.setTitle("title");
fte.addKeyword("keyword1");
fte.addKeyword("keyword2");
fte.setNativeCRS("EPSG:4326");
fte.setDescription("desc");
fte.setEnabled(true);
// virtual table
// -------------
// Set-up the vtGeom
final VTGeometryEncoder vtGeom = new VTGeometryEncoder("the_geom", "Point", "4326");
// Set-up 2 virtual table parameters
final VTParameterEncoder vtParam1 = new VTParameterEncoder("high", "100000000", "^[\\d]+$");
final VTParameterEncoder vtParam2 = new VTParameterEncoder("low", "0", "^[\\d]+$");
// sql
String sql = "select gid, state_name, the_geom from pgstates where persons between %low% and %high% and state_abbr = '%state%'";
// set-up the virtual table
final GSVirtualTableEncoder vte = new GSVirtualTableEncoder();
vte.setName(nativeName);
vte.setSql(sql);
vte.addVirtualTableGeometry(vtGeom);
vte.addVirtualTableParameter(vtParam1);
vte.addVirtualTableParameter(vtParam2);
// modif the vte
vte.delVirtualTableGeometry("the_geom");
vte.addVirtualTableGeometry("the_geom", "MultiPolygon", "4326");
final VTParameterEncoder vtParam3 = new VTParameterEncoder("state", "FL", "^[\\w\\d\\s]+$");
vte.addVirtualTableParameter(vtParam3);
vte.addKeyColumn("gid");
fte.setMetadataVirtualTable(vte); // Set the virtual table
// Layer encoder
// -------------
GSLayerEncoder layerEncoder = new GSLayerEncoder();
layerEncoder.setEnabled(true);
layerEncoder.setQueryable(true);
layerEncoder.setDefaultStyle("polygon");
// test insert
// ------------
publisher.createWorkspace(DEFAULT_WS);
published = publisher.publishDBLayer(DEFAULT_WS, storeName, fte, layerEncoder);
assertTrue("Publication unsuccessful", published);
assertTrue("Layer does not exist", existsLayer(layerName));
}