grsf-publisher-ws/src/test/java/org/gcube/data_catalogue/grsf_publish_ws/JJerseyTest.java

69 lines
2.7 KiB
Java

package org.gcube.data_catalogue.grsf_publish_ws;
import java.util.ArrayList;
import java.util.Arrays;
import javax.ws.rs.client.Entity;
import javax.ws.rs.core.Application;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.gcube.data_catalogue.grsf_publish_ws.AAA_PORTED.FisheryRecord;
import org.gcube.data_catalogue.grsf_publish_ws.AAA_PORTED.Resource;
import org.gcube.data_catalogue.grsf_publish_ws.AAA_PORTED.StockRecord;
import org.gcube.data_catalogue.grsf_publish_ws.services.GrsfPublisherFisheryService;
import org.gcube.data_catalogue.grsf_publish_ws.services.GrsfPublisherStockService;
import org.gcube.datacatalogue.common.AAA_PORTED.Fishery_Type;
import org.gcube.datacatalogue.common.AAA_PORTED.Sources;
import org.gcube.datacatalogue.common.AAA_PORTED.Status;
import org.gcube.datacatalogue.common.AAA_PORTED.Stock_Type;
import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.test.JerseyTest;
import org.glassfish.jersey.test.TestProperties;
public class JJerseyTest extends JerseyTest{
//@Override
protected Application configure() {
forceSet(TestProperties.CONTAINER_PORT, "0");
return new ResourceConfig(GrsfPublisherFisheryService.class, GrsfPublisherStockService.class).property("jersey.config.beanValidation.enableOutputValidationErrorEntity.server", true);
}
//@Test
public void testFishery() {
FisheryRecord recordFishery = new FisheryRecord();
recordFishery.setAuthor("Costantino Perciante");
recordFishery.setAuthorContact("costantino.perciante@isti.cnr.it");
recordFishery.setLicense("a caso una lincense");
recordFishery.setDataOwner(Arrays.asList("data owner"));
recordFishery.setType(Fishery_Type.Other_Fishery);
recordFishery.setDatabaseSources(new ArrayList<Resource<Sources>>(1));
recordFishery.setSourceOfInformation(new ArrayList<Resource<String>>(1));
recordFishery.setStatus(Status.Pending);
Response res = target("fishery").path("/publish-product").request().post(Entity.entity(recordFishery, MediaType.APPLICATION_JSON));
System.out.println("Result is " + res.readEntity(String.class));
}
//@Test
public void testStock() {
StockRecord stock = new StockRecord();
stock.setAuthor("Costantino Perciante");
stock.setAuthorContact("costantino.perciante@isti.cnr.it");
stock.setType(Stock_Type.Assessment_Unit);
stock.setDatabaseSources(null);
stock.setStatus(Status.Pending);
Response res = target("stock").path("/publish-product").request().post(Entity.entity(stock, MediaType.APPLICATION_JSON));
System.out.println("Result is " + res);
}
//@Test
public void getLicenses(){
Response res = target("fishery").path("/get-licenses").request().get();
System.out.println("Result is " + res);
}
}