134 lines
4.3 KiB
Java
134 lines
4.3 KiB
Java
package org.gcube.spatial.data.clients.geoserver;
|
|
|
|
import static org.junit.Assert.assertTrue;
|
|
import static org.junit.Assume.assumeTrue;
|
|
|
|
import java.util.Collections;
|
|
import java.util.HashMap;
|
|
import java.util.UUID;
|
|
|
|
import javax.sound.midi.SysexMessage;
|
|
|
|
import org.gcube.sdi.test.GCubeSDITest;
|
|
import org.gcube.spatial.data.clients.SDIGenericPlugin;
|
|
import org.gcube.spatial.data.clients.model.engine.Engine;
|
|
import org.gcube.spatial.data.sdi.model.faults.RemoteException;
|
|
import org.json.simple.JSONObject;
|
|
import org.junit.Test;
|
|
|
|
public class GSTests extends GCubeSDITest{
|
|
|
|
|
|
protected GSRESTClient getClient() throws RemoteException, Exception {
|
|
SDIGenericPlugin obj=manager().getClientByEngineId(Engine.GS_ENGINE);
|
|
assertTrue(obj.getClass().isAssignableFrom(GeoServerClient.class));
|
|
return (GSRESTClient) obj.getRESTClient();
|
|
}
|
|
|
|
@Test
|
|
public void basics() throws RemoteException, Exception {
|
|
assumeTrue(isTestInfrastructureEnabled());
|
|
GSRESTClient client=getClient();
|
|
assertTrue(client.exist());
|
|
}
|
|
|
|
|
|
@Test
|
|
public void gets() throws RemoteException, Exception {
|
|
assumeTrue(isTestInfrastructureEnabled());
|
|
|
|
|
|
GSRESTClient client=getClient();
|
|
|
|
client.authenticate();
|
|
client.getWorkspaceNames().forEach((String ws)->{
|
|
try {
|
|
if(ws!=null) {
|
|
System.out.println("************************************ WS ***************************");
|
|
System.out.println(client.getWorkspace(ws));
|
|
for(String sld:client.getStylesNamesinWorkspace(ws))
|
|
if(sld!=null)try {
|
|
System.out.println(client.getSLD(sld));
|
|
}catch(RemoteException e ) {System.err.println("Unable to read SLD "+sld+" from "+ws+". Cause "+e.getResponseHTTPCode()+": "+e.getMessage());}
|
|
|
|
|
|
System.out.println(client.getDataStoresInWorkspace(ws));
|
|
|
|
for(String ds:client.getDataStoresNamesInWorkspace(ws))
|
|
if(ds!=null) {
|
|
try{ System.out.println(client.getDataStore(ws, ds));
|
|
}catch(RemoteException e ) {System.err.println("Unable to read DS "+ds+" from "+ws+". Cause "+e.getResponseHTTPCode()+": "+e.getMessage());}
|
|
}
|
|
|
|
|
|
for(String ft : client.getFeatureTypesInWorkspace(ws))
|
|
if(ft!=null)try {
|
|
System.out.println(client.getFeatureType(ws, ft));
|
|
}catch(RemoteException e ) {System.err.println("Unable to read FT "+ft+" from "+ws+". Cause "+e.getResponseHTTPCode()+": "+e.getMessage());}
|
|
|
|
|
|
for(String l : client.getLayers(ws))
|
|
if(l!=null)try {
|
|
System.out.println(client.getLayerInWorkspace(ws, l));
|
|
System.out.println(client.getLayer(l));
|
|
}catch(RemoteException e ) {System.err.println("Unable to read LA "+l+" from "+ws+". Cause "+e.getResponseHTTPCode()+": "+e.getMessage());}
|
|
|
|
}
|
|
}catch(Exception e) {
|
|
System.err.println("Unable to check "+ws+" : "+e);
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
System.out.println("Listing layers without ws");
|
|
// client.getLayers().forEach((String l)->{
|
|
// try{System.out.println(client.getLayer(l));
|
|
// }catch(RemoteException e ) {System.err.println("Unable to read LA "+l+". Cause "+e.getResponseHTTPCode()+": "+e.getMessage());}
|
|
// catch(Exception e ) {System.err.println("Unable to read LA "+l+". Cause : "+e.getMessage());}
|
|
// });
|
|
}
|
|
|
|
|
|
@Test
|
|
public void CRUDS() throws RemoteException, Exception {
|
|
assumeTrue(isTestInfrastructureEnabled());
|
|
GSRESTClient client=getClient();
|
|
|
|
client.authenticate();
|
|
String ws=UUID.randomUUID().toString().replace("-", "_");
|
|
client.createWorkspace(ws);
|
|
client.getWorkspace(ws);
|
|
|
|
|
|
String myDS=UUID.randomUUID().toString().replace("-", "_");
|
|
|
|
HashMap<String,String> parameters=new HashMap<String, String>();
|
|
|
|
// parameters.put("dbtype","gpkg");
|
|
parameters.put("url","gpkg");
|
|
|
|
client.publishDataStore(ws,
|
|
new DataStoreRegistrationRequest(myDS,parameters).getDatastore());
|
|
|
|
client.deleteWorkspace(ws,true);
|
|
}
|
|
|
|
// @Test
|
|
// public void crudGPKG() throws RemoteException, Exception {
|
|
// assumeTrue(isTestInfrastructureEnabled());
|
|
// GSRESTClient client=getClient();
|
|
//
|
|
// client.authenticate();
|
|
// String ws=UUID.randomUUID().toString().replace("-", "_");
|
|
// client.createWorkspace(ws);
|
|
//
|
|
//String myDS=UUID.randomUUID().toString().replace("-", "_");
|
|
//
|
|
// client.publishDataStore(ws, new DataStoreRegistrationRequest(myDS).getDatastore());
|
|
// }
|
|
|
|
|
|
}
|