Testing
This commit is contained in:
parent
2cdfcd2870
commit
0099e09b1f
|
@ -6,6 +6,7 @@ import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.*;
|
import com.fasterxml.jackson.databind.*;
|
||||||
import com.fasterxml.jackson.databind.module.SimpleModule;
|
import com.fasterxml.jackson.databind.module.SimpleModule;
|
||||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||||
|
import com.vdurmont.semver4j.Semver;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.bson.Document;
|
import org.bson.Document;
|
||||||
import org.bson.types.ObjectId;
|
import org.bson.types.ObjectId;
|
||||||
|
@ -33,8 +34,14 @@ public class Serialization {
|
||||||
SimpleModule s=new SimpleModule();
|
SimpleModule s=new SimpleModule();
|
||||||
s.addDeserializer(ObjectId.class,new ObjectIdDeserializer());
|
s.addDeserializer(ObjectId.class,new ObjectIdDeserializer());
|
||||||
s.addSerializer(ObjectId.class,new ObjectIdSerializer());
|
s.addSerializer(ObjectId.class,new ObjectIdSerializer());
|
||||||
s.addDeserializer(ComparableVersion.class,new ComparableVersionDeserializer());
|
|
||||||
s.addSerializer(ComparableVersion.class,new ComparableVersionSerializer());
|
// s.addDeserializer(ComparableVersion.class,new ComparableVersionDeserializer());
|
||||||
|
// s.addSerializer(ComparableVersion.class,new ComparableVersionSerializer());
|
||||||
|
|
||||||
|
s.addDeserializer(Semver.class,new SemverDeserializer());
|
||||||
|
s.addSerializer(Semver.class,new SemverSerializer());
|
||||||
|
|
||||||
|
|
||||||
mapper.registerModule(s);
|
mapper.registerModule(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -135,4 +142,32 @@ public class Serialization {
|
||||||
return ComparableVersion.class;
|
return ComparableVersion.class;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Sem Version
|
||||||
|
private static class SemverSerializer extends JsonSerializer<Semver> {
|
||||||
|
@Override
|
||||||
|
public void serialize(Semver semver, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException, JsonProcessingException {
|
||||||
|
if (semver == null) jsonGenerator.writeNull();
|
||||||
|
else jsonGenerator.writeString(semver.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Class<Semver> handledType() {
|
||||||
|
return Semver.class;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private static class SemverDeserializer extends JsonDeserializer<Semver> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Semver deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
|
||||||
|
String value=jsonParser.getValueAsString();
|
||||||
|
if(value==null || value.isEmpty() || value.equals("null"))
|
||||||
|
return null;
|
||||||
|
else return new Semver(value);
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public Class<Semver> handledType() {
|
||||||
|
return Semver.class;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@ import org.gcube.application.geoportal.common.model.document.Access;
|
||||||
import org.gcube.application.geoportal.common.model.document.AccessPolicy;
|
import org.gcube.application.geoportal.common.model.document.AccessPolicy;
|
||||||
import org.gcube.application.geoportal.common.model.document.ProfiledDocument;
|
import org.gcube.application.geoportal.common.model.document.ProfiledDocument;
|
||||||
import org.gcube.application.geoportal.common.model.document.RegisteredFileSet;
|
import org.gcube.application.geoportal.common.model.document.RegisteredFileSet;
|
||||||
|
import org.gcube.application.geoportal.common.model.legacy.RelazioneScavo;
|
||||||
import org.gcube.application.geoportal.common.model.legacy.report.ConstraintCheck;
|
import org.gcube.application.geoportal.common.model.legacy.report.ConstraintCheck;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -80,14 +81,14 @@ public class ProfiledConcessione extends ProfiledDocument {
|
||||||
//RELAZIONE
|
//RELAZIONE
|
||||||
// TODO NB provare se object gia' presente sia usando Document che sub Object
|
// TODO NB provare se object gia' presente sia usando Document che sub Object
|
||||||
doc.putIfAbsent(RELAZIONE_SCAVO,new Document());
|
doc.putIfAbsent(RELAZIONE_SCAVO,new Document());
|
||||||
Document rel=doc.get(RELAZIONE_SCAVO,Document.class);
|
RelazioneScavo rel=doc.get(RELAZIONE_SCAVO,RelazioneScavo.class);
|
||||||
rel.putIfAbsent(Sections.TITOLO,doc.getString(NOME)+" relazione di scavo");
|
// rel.putIfAbsent(Sections.TITOLO,doc.getString(NOME)+" relazione di scavo");
|
||||||
rel.putIfAbsent(SOGGETTO,doc.get(SOGGETTO));
|
// rel.putIfAbsent(SOGGETTO,doc.get(SOGGETTO));
|
||||||
rel.putIfAbsent(RegisteredFileSet.CREATION_INFO,this.getInfo().getCreationInfo());
|
// rel.putIfAbsent(RegisteredFileSet.CREATION_INFO,this.getInfo().getCreationInfo());
|
||||||
rel.putIfAbsent(RegisteredFileSet.ACCESS,this.getInfo().getAccess());
|
// rel.putIfAbsent(RegisteredFileSet.ACCESS,this.getInfo().getAccess());
|
||||||
Access relAccess=rel.get(RegisteredFileSet.ACCESS,Access.class);
|
// Access relAccess=rel.get(RegisteredFileSet.ACCESS,Access.class);
|
||||||
relAccess.setLicense(ConstraintCheck.defaultFor(relAccess.getLicense(),"CC-BY-4.0").evaluate());
|
// relAccess.setLicense(ConstraintCheck.defaultFor(relAccess.getLicense(),"CC-BY-4.0").evaluate());
|
||||||
relAccess.setPolicy(ConstraintCheck.defaultFor(relAccess.getPolicy(), AccessPolicy.OPEN).evaluate());
|
// relAccess.setPolicy(ConstraintCheck.defaultFor(relAccess.getPolicy(), AccessPolicy.OPEN).evaluate());
|
||||||
|
|
||||||
//ABSTRACT Relazione
|
//ABSTRACT Relazione
|
||||||
doc.putIfAbsent(ABSTRACT_RELAZIONE,new Document());
|
doc.putIfAbsent(ABSTRACT_RELAZIONE,new Document());
|
||||||
|
@ -95,7 +96,7 @@ public class ProfiledConcessione extends ProfiledDocument {
|
||||||
abs.putIfAbsent(Sections.TITOLO,doc.getString(NOME)+" abstract relazione di scavo");
|
abs.putIfAbsent(Sections.TITOLO,doc.getString(NOME)+" abstract relazione di scavo");
|
||||||
abs.putIfAbsent(RegisteredFileSet.CREATION_INFO,this.getInfo().getCreationInfo());
|
abs.putIfAbsent(RegisteredFileSet.CREATION_INFO,this.getInfo().getCreationInfo());
|
||||||
abs.putIfAbsent(RegisteredFileSet.ACCESS,this.getInfo().getAccess());
|
abs.putIfAbsent(RegisteredFileSet.ACCESS,this.getInfo().getAccess());
|
||||||
Access absAccess=rel.get(RegisteredFileSet.ACCESS,Access.class);
|
Access absAccess=abs.get(RegisteredFileSet.ACCESS,Access.class);
|
||||||
absAccess.setLicense(ConstraintCheck.defaultFor(absAccess.getLicense(),"CC-BY-4.0").evaluate());
|
absAccess.setLicense(ConstraintCheck.defaultFor(absAccess.getLicense(),"CC-BY-4.0").evaluate());
|
||||||
absAccess.setPolicy(ConstraintCheck.defaultFor(absAccess.getPolicy(), AccessPolicy.OPEN).evaluate());
|
absAccess.setPolicy(ConstraintCheck.defaultFor(absAccess.getPolicy(), AccessPolicy.OPEN).evaluate());
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,12 @@
|
||||||
package org.gcube.application.geoportal.service;
|
package org.gcube.application.geoportal.service;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import org.bson.Document;
|
import org.bson.Document;
|
||||||
import org.gcube.application.cms.Serialization;
|
import org.gcube.application.cms.Serialization;
|
||||||
import org.gcube.application.cms.tests.TokenSetter;
|
import org.gcube.application.cms.tests.TokenSetter;
|
||||||
import org.gcube.application.geoportal.common.model.document.ProfiledDocument;
|
import org.gcube.application.geoportal.common.model.document.ProfiledDocument;
|
||||||
|
import org.gcube.application.geoportal.common.model.rest.Configuration;
|
||||||
|
import org.gcube.application.geoportal.common.model.rest.QueryRequest;
|
||||||
import org.gcube.application.geoportal.common.rest.InterfaceConstants;
|
import org.gcube.application.geoportal.common.rest.InterfaceConstants;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
@ -27,9 +30,14 @@ public class ProfiledDocumentsTests extends BasicServiceTestUnit{
|
||||||
TokenSetter.set(scope);
|
TokenSetter.set(scope);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected WebTarget baseTarget(){
|
||||||
|
return target(InterfaceConstants.Methods.PROJECTS).path(testProfileId);
|
||||||
|
}
|
||||||
|
// GET
|
||||||
@Test
|
@Test
|
||||||
public void testMissingProfile(){
|
public void testMissingProfile(){
|
||||||
Response resp = target(InterfaceConstants.Methods.PROJECTS)
|
Response resp = baseTarget()
|
||||||
.path("non-existent-profile").request().get();
|
.path("non-existent-profile").request().get();
|
||||||
assertEquals(resp.getStatus(),404);
|
assertEquals(resp.getStatus(),404);
|
||||||
}
|
}
|
||||||
|
@ -37,15 +45,15 @@ public class ProfiledDocumentsTests extends BasicServiceTestUnit{
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getAll() {
|
public void getAll() {
|
||||||
System.out.println(target(InterfaceConstants.Methods.PROJECTS).path(testProfileId).request(MediaType.APPLICATION_JSON).get(List.class));
|
System.out.println(baseTarget().request(MediaType.APPLICATION_JSON).get(List.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getByID(){
|
public void getByID(){
|
||||||
target(InterfaceConstants.Methods.PROJECTS).path(testProfileId).request(MediaType.APPLICATION_JSON).get(List.class).forEach(d ->{
|
baseTarget().request(MediaType.APPLICATION_JSON).get(List.class).forEach(d ->{
|
||||||
|
|
||||||
try {
|
try {
|
||||||
check(target(InterfaceConstants.Methods.PROJECTS).path(testProfileId).path((Serialization.convert(d,ProfiledDocument.class)).get_id())
|
check(baseTarget().path((Serialization.convert(d,ProfiledDocument.class)).get_id())
|
||||||
.request(MediaType.APPLICATION_JSON).get(),ProfiledDocument.class);
|
.request(MediaType.APPLICATION_JSON).get(),ProfiledDocument.class);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace(System.err);
|
e.printStackTrace(System.err);
|
||||||
|
@ -54,74 +62,52 @@ public class ProfiledDocumentsTests extends BasicServiceTestUnit{
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getConfiguration() {
|
||||||
|
System.out.println(baseTarget().request(MediaType.APPLICATION_JSON).get(Configuration.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Queries
|
||||||
|
@Test
|
||||||
|
public void query() throws JsonProcessingException {
|
||||||
|
System.out.println(baseTarget().path(InterfaceConstants.Methods.QUERY_PATH).
|
||||||
|
request(MediaType.APPLICATION_JSON).
|
||||||
|
post(Entity.entity(Serialization.write(new QueryRequest()),MediaType.APPLICATION_JSON)));
|
||||||
|
}
|
||||||
|
|
||||||
|
// CREATE / edit / delete
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void registerNew() throws Exception {
|
public void registerNew() throws Exception {
|
||||||
WebTarget target=target(InterfaceConstants.Methods.PROJECTS);
|
createNew();
|
||||||
|
|
||||||
Document document =new Document(Collections.singletonMap("dumbKey","dumbValue"));
|
|
||||||
check(target.path(testProfileId).request(MediaType.APPLICATION_JSON).
|
|
||||||
post(Entity.entity(document, MediaType.APPLICATION_JSON)),ProfiledDocument.class);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private ProfiledDocument createNew() throws Exception {
|
private ProfiledDocument createNew() throws Exception {
|
||||||
WebTarget target=target(InterfaceConstants.Methods.PROJECTS);
|
|
||||||
|
|
||||||
Document document =new Document(Collections.singletonMap("dumbKey","dumbValue"));
|
Document document =new Document(Collections.singletonMap("dumbKey","dumbValue"));
|
||||||
return check(target.path(testProfileId).request(MediaType.APPLICATION_JSON).
|
return check(baseTarget().request(MediaType.APPLICATION_JSON).
|
||||||
post(Entity.entity(document, MediaType.APPLICATION_JSON)),ProfiledDocument.class);
|
post(Entity.entity(document, MediaType.APPLICATION_JSON)),ProfiledDocument.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void edit() throws Exception {
|
||||||
|
ProfiledDocument doc=createNew();
|
||||||
|
String beforeJson=doc.getTheDocument().toJson();
|
||||||
|
doc.getTheDocument().put("someStrangeField","someOtherRandomValue");
|
||||||
|
String edited=doc.getTheDocument().toJson();
|
||||||
|
Assert.assertNotEquals(beforeJson,doc.getTheDocument().toJson());
|
||||||
|
doc=check(baseTarget().path(doc.get_id()).request(MediaType.APPLICATION_JSON).
|
||||||
|
put(Entity.entity(doc.getTheDocument(), MediaType.APPLICATION_JSON)),ProfiledDocument.class);
|
||||||
|
Assert.assertEquals(edited,doc.getTheDocument().toJson());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void addFileSet() throws Exception {
|
public void addFileSet() throws Exception {
|
||||||
// TODO Test register fileset
|
|
||||||
|
ProfiledDocument doc = createNew();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// @Test
|
|
||||||
// public void getFilteredAll() {
|
|
||||||
// WebTarget target=target(InterfaceConstants.Methods.PROJECTS);
|
|
||||||
// Document document =new Document(Collections.singletonMap("key", "value"));
|
|
||||||
//
|
|
||||||
// System.out.println(target.path("search").request(MediaType.APPLICATION_JSON).
|
|
||||||
// post(Entity.entity(document, MediaType.APPLICATION_JSON)));
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Test
|
|
||||||
// public void getAllByProfile() {
|
|
||||||
// WebTarget target=target(InterfaceConstants.Methods.PROJECTS);
|
|
||||||
// System.out.println(target.path(testProfileId).request(MediaType.APPLICATION_JSON).get(List.class));
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Test
|
|
||||||
// public void getFilteredByProfile() {
|
|
||||||
// WebTarget target=target(InterfaceConstants.Methods.PROJECTS);
|
|
||||||
// Document document =new Document(Collections.singletonMap("key", "value"));
|
|
||||||
//
|
|
||||||
// System.out.println(target.path("search").path(testProfileId).request(MediaType.APPLICATION_JSON).
|
|
||||||
// post(Entity.entity(document, MediaType.APPLICATION_JSON)));
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// @Test
|
|
||||||
// public void getById() {
|
|
||||||
// WebTarget target=target(InterfaceConstants.Methods.PROJECTS);
|
|
||||||
// System.out.println(target.path(testProfileId).path(projectId).request(MediaType.APPLICATION_JSON).get().readEntity(String.class));
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// @Test
|
|
||||||
// public void updateDocument() {
|
|
||||||
// WebTarget target=target(InterfaceConstants.Methods.PROJECTS);
|
|
||||||
// Document document =new Document(Collections.singletonMap("key", "value"));
|
|
||||||
//
|
|
||||||
// System.out.println(target.path(testProfileId).path(projectId).request(MediaType.APPLICATION_JSON).
|
|
||||||
// put(Entity.entity(document, MediaType.APPLICATION_JSON)));
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue