added tests for testing with jetty and junit
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-catalogue/grsf-publisher-ws@132963 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
a2a00e0d8a
commit
45ac9feb0b
6
pom.xml
6
pom.xml
|
@ -112,6 +112,12 @@
|
|||
<artifactId>common-smartgears</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.glassfish.jersey.test-framework.providers</groupId>
|
||||
<artifactId>jersey-test-framework-provider-jetty</artifactId>
|
||||
<version>2.23.2</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
|
|
@ -1,13 +1,17 @@
|
|||
package org.gcube.data_catalogue.grsf_publish_ws.services;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.Response.Status;
|
||||
|
||||
import org.gcube.data_catalogue.grsf_publish_ws.json.input.FisheryRecord;
|
||||
import org.gcube.data_catalogue.grsf_publish_ws.json.output.ResponseCreationBean;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
|
@ -27,9 +31,10 @@ public class GrsfPublisherFisheryService {
|
|||
public Response publishFishery(FisheryRecord record){
|
||||
|
||||
logger.info("Incoming request for creating a fishery record");
|
||||
System.out.println(record);
|
||||
|
||||
// TODO
|
||||
return null;
|
||||
return Response.status(Status.CREATED).entity(new ResponseCreationBean(UUID.randomUUID().toString(), null)).build();
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -45,8 +45,9 @@ public class AssociationToGroupThread extends Thread {
|
|||
// check the user has enough privileges to associate it
|
||||
if(catalogue.checkRoleIntoGroup(username, groupTitle, RolesCkanGroupOrOrg.MEMBER)){
|
||||
|
||||
logger.warn("The user " + username + " has no enough priviliges to associate the dataset into group " + groupTitle);
|
||||
logger.warn("The user " + username + " has not enough privileges to associate the dataset into group " + groupTitle);
|
||||
continue;
|
||||
|
||||
}
|
||||
|
||||
boolean putIntoGroup = catalogue.assignDatasetToGroup(groupTitle, datasetId, catalogue.getApiKeyFromUsername(username));
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
package org.gcube.data_catalogue.grsf_publish_ws;
|
||||
|
||||
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.json.input.FisheryRecord;
|
||||
import org.gcube.data_catalogue.grsf_publish_ws.json.input.StockRecord;
|
||||
import org.gcube.data_catalogue.grsf_publish_ws.services.GrsfPublisherFisheryService;
|
||||
import org.gcube.data_catalogue.grsf_publish_ws.services.GrsfPublisherStockService;
|
||||
import org.gcube.data_catalogue.grsf_publish_ws.utils.groups.Source;
|
||||
import org.gcube.data_catalogue.grsf_publish_ws.utils.groups.Status;
|
||||
import org.gcube.data_catalogue.grsf_publish_ws.utils.groups.Type;
|
||||
import org.glassfish.jersey.server.ResourceConfig;
|
||||
import org.glassfish.jersey.test.JerseyTest;
|
||||
|
||||
public class JJerseyTest extends JerseyTest{
|
||||
|
||||
//@Override
|
||||
protected Application configure() {
|
||||
return new ResourceConfig(GrsfPublisherFisheryService.class, GrsfPublisherStockService.class);
|
||||
}
|
||||
|
||||
//@Test
|
||||
public void testFishery() {
|
||||
FisheryRecord recordFishery = new FisheryRecord();
|
||||
recordFishery.setAuthor("Costantino Perciante");
|
||||
recordFishery.setAuthorContact("costantino.perciante@isti.cnr.it");
|
||||
recordFishery.setType(Type.Fishing_Description);
|
||||
recordFishery.setDatabaseSources(Source.FIRMS);
|
||||
recordFishery.setStatus(Status.Pending);
|
||||
recordFishery.setSpatial(
|
||||
"{\"type\":\"Polygon\",\"coordinates\":[[[2.05827, 49.8625],[2.05827, 55.7447], [-6.41736, 55.7447], [-6.41736, 49.8625], [2.05827, 49.8625]]]}");
|
||||
|
||||
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(Type.Fishing_Description);
|
||||
stock.setDatabaseSources(Source.FIRMS);
|
||||
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);
|
||||
}
|
||||
}
|
|
@ -127,5 +127,4 @@ public class JTests {
|
|||
FisheryRecord converted = mapper.readValue(jsonInString, recordFishery.getClass());
|
||||
System.out.println(converted);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue