2017-03-21 18:01:31 +01:00
|
|
|
package org.gcube.spatial.data.sdi.test;
|
|
|
|
|
2017-08-03 12:43:53 +02:00
|
|
|
import java.net.MalformedURLException;
|
|
|
|
import java.nio.file.Paths;
|
|
|
|
import java.util.List;
|
|
|
|
|
2017-03-21 18:01:31 +01:00
|
|
|
import javax.ws.rs.core.Application;
|
2017-08-03 12:43:53 +02:00
|
|
|
import javax.ws.rs.core.GenericType;
|
2017-03-21 18:01:31 +01:00
|
|
|
import javax.ws.rs.core.MediaType;
|
|
|
|
|
2017-08-03 12:43:53 +02:00
|
|
|
import org.gcube.spatial.data.sdi.LocalConfiguration;
|
2017-03-21 18:01:31 +01:00
|
|
|
import org.gcube.spatial.data.sdi.SDIService;
|
2017-04-11 18:07:58 +02:00
|
|
|
import org.gcube.spatial.data.sdi.engine.GISManager;
|
|
|
|
import org.gcube.spatial.data.sdi.engine.GeoNetworkManager;
|
2017-08-03 12:43:53 +02:00
|
|
|
import org.gcube.spatial.data.sdi.engine.GeoNetworkProvider;
|
|
|
|
import org.gcube.spatial.data.sdi.engine.MetadataTemplateManager;
|
2017-03-30 15:31:39 +02:00
|
|
|
import org.gcube.spatial.data.sdi.engine.SDIManager;
|
2017-08-03 12:43:53 +02:00
|
|
|
import org.gcube.spatial.data.sdi.engine.TemporaryPersistence;
|
2017-04-11 18:07:58 +02:00
|
|
|
import org.gcube.spatial.data.sdi.engine.ThreddsManager;
|
2017-07-05 18:42:04 +02:00
|
|
|
import org.gcube.spatial.data.sdi.model.ServiceConstants;
|
2017-08-03 12:43:53 +02:00
|
|
|
import org.gcube.spatial.data.sdi.model.metadata.TemplateDescriptor;
|
2017-03-22 17:48:16 +01:00
|
|
|
import org.gcube.spatial.data.sdi.rest.GeoNetwork;
|
2017-08-03 12:43:53 +02:00
|
|
|
import org.gcube.spatial.data.sdi.test.factories.GISManagerFactory;
|
|
|
|
import org.gcube.spatial.data.sdi.test.factories.GeoNetworkManagerFactory;
|
|
|
|
import org.gcube.spatial.data.sdi.test.factories.GeoNetworkProviderFactory;
|
|
|
|
import org.gcube.spatial.data.sdi.test.factories.MetadataTemplateManagerFactory;
|
|
|
|
import org.gcube.spatial.data.sdi.test.factories.SDIManagerFactory;
|
|
|
|
import org.gcube.spatial.data.sdi.test.factories.TemporaryPersistenceFactory;
|
|
|
|
import org.gcube.spatial.data.sdi.test.factories.ThreddsManagerFactory;
|
2017-03-21 18:01:31 +01:00
|
|
|
import org.glassfish.hk2.utilities.binding.AbstractBinder;
|
2017-08-03 12:43:53 +02:00
|
|
|
import org.glassfish.jersey.media.multipart.MultiPartFeature;
|
2017-03-21 18:01:31 +01:00
|
|
|
import org.glassfish.jersey.server.ResourceConfig;
|
|
|
|
import org.glassfish.jersey.test.JerseyTest;
|
2017-08-03 12:43:53 +02:00
|
|
|
import org.junit.BeforeClass;
|
2017-03-21 18:01:31 +01:00
|
|
|
import org.junit.Test;
|
|
|
|
|
2017-03-22 17:48:16 +01:00
|
|
|
import io.swagger.jaxrs.config.BeanConfig;
|
|
|
|
|
2017-03-21 18:01:31 +01:00
|
|
|
public class MainTest extends JerseyTest{
|
|
|
|
|
2017-08-03 12:43:53 +02:00
|
|
|
@BeforeClass
|
|
|
|
public static void init() throws MalformedURLException {
|
|
|
|
LocalConfiguration.init(Paths.get("src/main/webapp/WEB-INF/config.properties").toUri().toURL());
|
|
|
|
}
|
|
|
|
|
2017-04-11 18:07:58 +02:00
|
|
|
|
2017-03-21 18:01:31 +01:00
|
|
|
public static class MyBinder extends AbstractBinder{
|
|
|
|
|
|
|
|
public MyBinder() {
|
|
|
|
super();
|
|
|
|
// TODO Auto-generated constructor stub
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void configure() {
|
2017-08-03 12:43:53 +02:00
|
|
|
bindFactory(TemporaryPersistenceFactory.class).to(TemporaryPersistence.class);
|
|
|
|
bindFactory(GeoNetworkProviderFactory.class).to(GeoNetworkProvider.class);
|
2017-03-30 15:31:39 +02:00
|
|
|
bindFactory(SDIManagerFactory.class).to(SDIManager.class);
|
2017-04-11 18:07:58 +02:00
|
|
|
bindFactory(ThreddsManagerFactory.class).to(ThreddsManager.class);
|
|
|
|
bindFactory(GeoNetworkManagerFactory.class).to(GeoNetworkManager.class);
|
|
|
|
bindFactory(GISManagerFactory.class).to(GISManager.class);
|
2017-08-03 12:43:53 +02:00
|
|
|
bindFactory(MetadataTemplateManagerFactory.class).to(MetadataTemplateManager.class);
|
2017-03-21 18:01:31 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected Application configure() {
|
2017-07-05 18:42:04 +02:00
|
|
|
System.out.println("Configuration for "+ServiceConstants.APPLICATION);
|
2017-03-21 18:01:31 +01:00
|
|
|
|
|
|
|
ResourceConfig config= new ResourceConfig(SDIService.class);
|
|
|
|
config.register(new MyBinder());
|
2017-03-22 17:48:16 +01:00
|
|
|
config.register(io.swagger.jaxrs.listing.ApiListingResource.class);
|
|
|
|
config.register(io.swagger.jaxrs.listing.SwaggerSerializers.class);
|
2017-03-21 18:01:31 +01:00
|
|
|
|
2017-03-22 17:48:16 +01:00
|
|
|
// //SWAGGER
|
|
|
|
BeanConfig beanConfig = new BeanConfig();
|
|
|
|
beanConfig.setVersion("1.0.0");
|
|
|
|
beanConfig.setSchemes(new String[]{"http","https"});
|
|
|
|
beanConfig.setHost("localhost:9998");
|
|
|
|
beanConfig.setBasePath("gcube/service");
|
|
|
|
String packageName=GeoNetwork.class.getPackage().getName();
|
|
|
|
System.out.println("PACKAGE : "+packageName);
|
|
|
|
beanConfig.setResourcePackage(packageName);
|
|
|
|
beanConfig.setScan(true);
|
|
|
|
System.out.println(beanConfig.getSwagger());
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-03-21 18:01:31 +01:00
|
|
|
//Multipart
|
|
|
|
// config.packages("org.glassfish.jersey.media.multipart");
|
|
|
|
config.packages("org.gcube.spatial.data");
|
2017-08-03 12:43:53 +02:00
|
|
|
config.register(MultiPartFeature.class);
|
2017-03-21 18:01:31 +01:00
|
|
|
return config;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-03-30 15:31:39 +02:00
|
|
|
// @Test
|
|
|
|
// public void getConfiguration(){
|
|
|
|
// System.out.println(target(Constants.GEONETWORK_INTERFACE).
|
|
|
|
// path(Constants.GEONETWORK_CONFIGURATION_PATH).
|
|
|
|
// request(MediaType.APPLICATION_JSON_TYPE).get(String.class));
|
|
|
|
// System.out.println(target(Constants.GEONETWORK_INTERFACE).
|
|
|
|
// path(Constants.GEONETWORK_CONFIGURATION_PATH).
|
|
|
|
// getUri());
|
|
|
|
// }
|
|
|
|
|
2017-08-03 12:43:53 +02:00
|
|
|
|
|
|
|
|
|
|
|
// @Test
|
|
|
|
// public void getConfiguration(){
|
|
|
|
// System.out.println(target(ServiceConstants.INTERFACE).request(MediaType.APPLICATION_JSON_TYPE).get(String.class));
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// @Test
|
|
|
|
// public void getGeoServer(){
|
|
|
|
// System.out.println(target(ServiceConstants.GeoServer.INTERFACE).path("configuration/geoserver-dev.research-infrastructures.eu").request(MediaType.APPLICATION_JSON_TYPE).get(String.class));
|
|
|
|
// }
|
|
|
|
|
2017-03-21 18:01:31 +01:00
|
|
|
@Test
|
2017-08-03 12:43:53 +02:00
|
|
|
public void testGetTemplateList(){
|
|
|
|
List<TemplateDescriptor> result=target(ServiceConstants.Metadata.INTERFACE).
|
|
|
|
path(ServiceConstants.Metadata.LIST_METHOD).
|
|
|
|
request(MediaType.APPLICATION_JSON_TYPE).get().
|
|
|
|
readEntity(new GenericType<List<TemplateDescriptor>>() {});
|
|
|
|
System.out.println(result);
|
2017-03-22 17:48:16 +01:00
|
|
|
}
|
2017-03-30 15:31:39 +02:00
|
|
|
|
2017-07-05 18:42:04 +02:00
|
|
|
@Test
|
2017-08-03 12:43:53 +02:00
|
|
|
public void testHealthReport() {
|
|
|
|
System.out.println(target(ServiceConstants.INTERFACE).path("status").request(MediaType.APPLICATION_JSON_TYPE).get(String.class));
|
|
|
|
System.out.println(target(ServiceConstants.INTERFACE).path("status").request(MediaType.APPLICATION_XML_TYPE).get(String.class));
|
2017-07-05 18:42:04 +02:00
|
|
|
}
|
2017-03-30 15:31:39 +02:00
|
|
|
|
2017-08-03 12:43:53 +02:00
|
|
|
|
2017-03-28 15:20:10 +02:00
|
|
|
//
|
|
|
|
// @Test
|
|
|
|
// public void getSwagger(){
|
|
|
|
// String path="gcube/service/swagger.json";
|
|
|
|
// System.out.println(target(path).getUri());
|
|
|
|
// System.out.println(target(path).request(MediaType.APPLICATION_JSON_TYPE).get(String.class));
|
|
|
|
// }
|
2017-03-21 18:01:31 +01:00
|
|
|
}
|