Testing serialization
This commit is contained in:
parent
a98d362ccf
commit
49094b73ee
|
@ -50,7 +50,7 @@ public class ConcessioniLifeCycleManager extends Default3PhaseManager implements
|
||||||
// STATIC ROUTINES
|
// STATIC ROUTINES
|
||||||
|
|
||||||
static final Project setDefaults(Project document) throws IOException {
|
static final Project setDefaults(Project document) throws IOException {
|
||||||
log.info("Concessione {}, setting defaults..",document.getId());
|
log.info("Concessione ID {}, setting defaults..",document.getId());
|
||||||
log.debug("Full concessione is {}",document);
|
log.debug("Full concessione is {}",document);
|
||||||
ProfiledConcessione c=Serialization.convert(document,ProfiledConcessione.class);
|
ProfiledConcessione c=Serialization.convert(document,ProfiledConcessione.class);
|
||||||
Document doc=c.getTheDocument();
|
Document doc=c.getTheDocument();
|
||||||
|
|
|
@ -12,6 +12,7 @@ import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static junit.framework.TestCase.*;
|
import static junit.framework.TestCase.*;
|
||||||
|
@ -28,6 +29,9 @@ public class ConcessioniPluginTests extends BasicPluginTest {
|
||||||
public void testDefaults() throws IOException {
|
public void testDefaults() throws IOException {
|
||||||
Project c= TestDocuments.documentMap.get("dummy.json");
|
Project c= TestDocuments.documentMap.get("dummy.json");
|
||||||
|
|
||||||
|
LocalDateTime start = LocalDateTime.now();
|
||||||
|
c.getTheDocument().put(ProfiledConcessione.DATA_INZIO_PROGETTO,start);
|
||||||
|
c.getTheDocument().put(ProfiledConcessione.DATA_FINE_PROGETTO,start);
|
||||||
|
|
||||||
c.getTheDocument().put(ProfiledConcessione.POSIZIONAMENTO_SCAVO,new Document());
|
c.getTheDocument().put(ProfiledConcessione.POSIZIONAMENTO_SCAVO,new Document());
|
||||||
c.getTheDocument().put(ProfiledConcessione.IMMAGINI_RAPPRESENTATIVE,new Document[]{new Document()});
|
c.getTheDocument().put(ProfiledConcessione.IMMAGINI_RAPPRESENTATIVE,new Document[]{new Document()});
|
||||||
|
@ -39,6 +43,12 @@ public class ConcessioniPluginTests extends BasicPluginTest {
|
||||||
|
|
||||||
assertNotNull(c.getTheDocument().get(ProfiledConcessione.SOGGETTO));
|
assertNotNull(c.getTheDocument().get(ProfiledConcessione.SOGGETTO));
|
||||||
assertNotNull(c.getTheDocument().getString(ProfiledConcessione.DESCRIZIONE_CONTENUTO));
|
assertNotNull(c.getTheDocument().getString(ProfiledConcessione.DESCRIZIONE_CONTENUTO));
|
||||||
|
|
||||||
|
assertNotNull(c.getTheDocument().get(ProfiledConcessione.DATA_INZIO_PROGETTO));
|
||||||
|
assertEquals(Serialization.convert(c.getTheDocument().get(ProfiledConcessione.DATA_INZIO_PROGETTO),LocalDateTime.class),start);
|
||||||
|
assertNotNull(c.getTheDocument().get(ProfiledConcessione.DATA_FINE_PROGETTO));
|
||||||
|
assertEquals(Serialization.convert(c.getTheDocument().get(ProfiledConcessione.DATA_FINE_PROGETTO),LocalDateTime.class),start);
|
||||||
|
|
||||||
assertNotNull(c.getTheDocument().get(ProfiledConcessione.RELAZIONE_SCAVO));
|
assertNotNull(c.getTheDocument().get(ProfiledConcessione.RELAZIONE_SCAVO));
|
||||||
Document rel = Serialization.convert(c.getTheDocument().get(ProfiledConcessione.RELAZIONE_SCAVO), Document.class);
|
Document rel = Serialization.convert(c.getTheDocument().get(ProfiledConcessione.RELAZIONE_SCAVO), Document.class);
|
||||||
assertNotNull(rel.get(ProfiledConcessione.Sections.TITOLO));
|
assertNotNull(rel.get(ProfiledConcessione.Sections.TITOLO));
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
package org.gcube.application.geoportal.clients;
|
package org.gcube.application.geoportal.clients;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.bson.Document;
|
||||||
import org.gcube.application.geoportal.client.DefaultDocumentsClient;
|
import org.gcube.application.geoportal.client.DefaultDocumentsClient;
|
||||||
|
import org.gcube.application.geoportal.client.utils.Serialization;
|
||||||
import org.gcube.application.geoportal.common.model.document.Project;
|
import org.gcube.application.geoportal.common.model.document.Project;
|
||||||
import org.gcube.application.geoportal.common.model.configuration.Configuration;
|
import org.gcube.application.geoportal.common.model.configuration.Configuration;
|
||||||
import org.gcube.application.geoportal.common.model.rest.QueryRequest;
|
import org.gcube.application.geoportal.common.model.rest.QueryRequest;
|
||||||
|
@ -10,12 +14,15 @@ import org.junit.Test;
|
||||||
import sun.net.www.content.text.Generic;
|
import sun.net.www.content.text.Generic;
|
||||||
|
|
||||||
import java.rmi.RemoteException;
|
import java.rmi.RemoteException;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
import java.util.concurrent.atomic.AtomicLong;
|
import java.util.concurrent.atomic.AtomicLong;
|
||||||
|
|
||||||
import static junit.framework.TestCase.assertTrue;
|
import static junit.framework.TestCase.assertTrue;
|
||||||
import static org.gcube.application.geoportal.client.plugins.GeoportalAbstractPlugin.*;
|
import static org.gcube.application.geoportal.client.plugins.GeoportalAbstractPlugin.*;
|
||||||
|
import static org.gcube.application.geoportal.client.utils.Serialization.write;
|
||||||
import static org.junit.Assume.assumeTrue;
|
import static org.junit.Assume.assumeTrue;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
public class ProfiledDocumentsTest<M extends Project,C extends Projects<M>> extends GenericUseCases {
|
public class ProfiledDocumentsTest<M extends Project,C extends Projects<M>> extends GenericUseCases {
|
||||||
|
|
||||||
// protected String getProfileID(){return "basic";}
|
// protected String getProfileID(){return "basic";}
|
||||||
|
@ -25,6 +32,22 @@ public class ProfiledDocumentsTest<M extends Project,C extends Projects<M>> exte
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void registerNew() throws RemoteException, JsonProcessingException {
|
||||||
|
assumeTrue(GCubeTest.isTestInfrastructureEnabled());
|
||||||
|
Projects<M> client = (Projects<M>) getClient();
|
||||||
|
|
||||||
|
Document theDoc= Document.parse("{\n" +
|
||||||
|
"\"posizionamentoScavo\" :{\n" +
|
||||||
|
"\t\"titolo\" : \"mio titolo\"}}");
|
||||||
|
|
||||||
|
theDoc.put("startTime", LocalDateTime.now());
|
||||||
|
|
||||||
|
Project p =client.createNew(theDoc);
|
||||||
|
|
||||||
|
log.debug("Registered project (AS JSON) : {}", write(p));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getConfiguration() throws Exception {
|
public void getConfiguration() throws Exception {
|
||||||
assumeTrue(GCubeTest.isTestInfrastructureEnabled());
|
assumeTrue(GCubeTest.isTestInfrastructureEnabled());
|
||||||
|
|
|
@ -0,0 +1,33 @@
|
||||||
|
package org.gcube.application.geoportal.clients.serialization;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.gcube.application.geoportal.client.utils.Serialization;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
public class SerializationTests {
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDates() throws IOException {
|
||||||
|
LocalDateTime obj = LocalDateTime.now();
|
||||||
|
|
||||||
|
roundTrip(obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean roundTrip(Object obj) throws IOException {
|
||||||
|
log.info("Round trip for {}",obj);
|
||||||
|
Class clazz =Object.class;
|
||||||
|
if(obj!=null) clazz=obj.getClass();
|
||||||
|
log.debug("Class is {}",obj.getClass());
|
||||||
|
String json= Serialization.write(obj);
|
||||||
|
log.debug("JSON String is : {}",json);
|
||||||
|
Object unmarshalled = Serialization.read(json,clazz);
|
||||||
|
log.debug("Unmarshalled as {}",unmarshalled);
|
||||||
|
return obj.equals(unmarshalled);
|
||||||
|
}
|
||||||
|
}
|
|
@ -37,6 +37,12 @@ public class GeoPortalService extends ResourceConfig{
|
||||||
super();
|
super();
|
||||||
//Register interrfaces
|
//Register interrfaces
|
||||||
|
|
||||||
|
log.info("Initializing serialization");
|
||||||
|
JacksonJaxbJsonProvider provider = new JacksonJaxbJsonProvider();
|
||||||
|
provider.setMapper(Serialization.mapper);
|
||||||
|
register(provider);
|
||||||
|
|
||||||
|
|
||||||
registerClasses(ConcessioniOverMongo.class);
|
registerClasses(ConcessioniOverMongo.class);
|
||||||
registerClasses(ProfiledDocuments.class);
|
registerClasses(ProfiledDocuments.class);
|
||||||
registerClasses(UseCaseDescriptors.class);
|
registerClasses(UseCaseDescriptors.class);
|
||||||
|
@ -65,10 +71,6 @@ public class GeoPortalService extends ResourceConfig{
|
||||||
|
|
||||||
ImplementationProvider.get().initEngines();
|
ImplementationProvider.get().initEngines();
|
||||||
|
|
||||||
log.info("Initializing serialization");
|
|
||||||
JacksonJaxbJsonProvider provider = new JacksonJaxbJsonProvider();
|
|
||||||
provider.setMapper(Serialization.mapper);
|
|
||||||
register(provider);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package org.gcube.application.geoportal.service.profiledDocuments;
|
package org.gcube.application.geoportal.service.profiledDocuments;
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
import com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider;
|
||||||
import org.bson.Document;
|
import org.bson.Document;
|
||||||
import org.gcube.application.cms.serialization.Serialization;
|
import org.gcube.application.cms.serialization.Serialization;
|
||||||
import org.gcube.application.cms.tests.TokenSetter;
|
import org.gcube.application.cms.tests.TokenSetter;
|
||||||
|
@ -42,7 +43,13 @@ public abstract class AbstractProfiledDocumentsTests extends BasicServiceTestUni
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected abstract WebTarget baseTarget();
|
|
||||||
|
protected WebTarget baseTarget(){
|
||||||
|
JacksonJaxbJsonProvider provider = new JacksonJaxbJsonProvider();
|
||||||
|
provider.setMapper(Serialization.mapper);
|
||||||
|
WebTarget toReturn = target(InterfaceConstants.Methods.PROJECTS).register(provider);
|
||||||
|
return toReturn;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -90,6 +97,8 @@ public abstract class AbstractProfiledDocumentsTests extends BasicServiceTestUni
|
||||||
// @@@@@@@@@@@@@@@ Routines
|
// @@@@@@@@@@@@@@@ Routines
|
||||||
|
|
||||||
protected Project createNew(Document content) throws Exception {
|
protected Project createNew(Document content) throws Exception {
|
||||||
|
|
||||||
|
|
||||||
Project doc =check(baseTarget().request(MediaType.APPLICATION_JSON).
|
Project doc =check(baseTarget().request(MediaType.APPLICATION_JSON).
|
||||||
post(Entity.entity(content, MediaType.APPLICATION_JSON)), Project.class);
|
post(Entity.entity(content, MediaType.APPLICATION_JSON)), Project.class);
|
||||||
BasicTests.validate(doc);
|
BasicTests.validate(doc);
|
||||||
|
|
|
@ -20,6 +20,8 @@ import javax.ws.rs.client.Entity;
|
||||||
import javax.ws.rs.client.WebTarget;
|
import javax.ws.rs.client.WebTarget;
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.Assert.assertNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.junit.Assume.assumeTrue;
|
import static org.junit.Assume.assumeTrue;
|
||||||
|
@ -38,7 +40,7 @@ public class DummyProjectTest extends AbstractProfiledDocumentsTests{
|
||||||
@Override
|
@Override
|
||||||
protected WebTarget baseTarget() {
|
protected WebTarget baseTarget() {
|
||||||
String testProfileId="basic";
|
String testProfileId="basic";
|
||||||
return target(InterfaceConstants.Methods.PROJECTS).path(testProfileId);
|
return super.baseTarget().path(testProfileId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -48,10 +50,13 @@ public class DummyProjectTest extends AbstractProfiledDocumentsTests{
|
||||||
@Test
|
@Test
|
||||||
public void registerNew() throws Exception {
|
public void registerNew() throws Exception {
|
||||||
assumeTrue(GCubeTest.isTestInfrastructureEnabled());
|
assumeTrue(GCubeTest.isTestInfrastructureEnabled());
|
||||||
Project doc = createNew(new Document("field","value"));
|
Document doc = new Document("field","value");
|
||||||
|
doc.put("startTime", LocalDateTime.now());
|
||||||
assertTrue(doc.getTheDocument().containsKey("field"));
|
System.out.println(Serialization.write(doc));
|
||||||
assertTrue(doc.getTheDocument().getString("field").equals("value"));
|
Project project = createNew(doc);
|
||||||
|
System.out.println(Serialization.write(project));
|
||||||
|
assertTrue(project.getTheDocument().containsKey("field"));
|
||||||
|
assertTrue(project.getTheDocument().getString("field").equals("value"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -99,12 +104,26 @@ public class DummyProjectTest extends AbstractProfiledDocumentsTests{
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDelete() throws Exception {
|
public void testSimpleDelete() throws Exception {
|
||||||
|
assumeTrue(GCubeTest.isTestInfrastructureEnabled());
|
||||||
|
Document baseDoc=new Document();
|
||||||
|
baseDoc.put("section",new Document("title","My Title"));
|
||||||
|
Project doc = createNew(baseDoc);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testFullDelete() throws Exception {
|
||||||
assumeTrue(GCubeTest.isTestInfrastructureEnabled());
|
assumeTrue(GCubeTest.isTestInfrastructureEnabled());
|
||||||
delete(createWithFileSet().getId(),true);
|
delete(createWithFileSet().getId(),true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private Project createWithFileSet() throws Exception {
|
private Project createWithFileSet() throws Exception {
|
||||||
Document baseDoc=new Document();
|
Document baseDoc=new Document();
|
||||||
baseDoc.put("section",new Document("title","My Title"));
|
baseDoc.put("section",new Document("title","My Title"));
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package org.gcube.application.geoportal.service.profiledDocuments;
|
package org.gcube.application.geoportal.service.profiledDocuments;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.bson.Document;
|
import org.bson.Document;
|
||||||
import org.gcube.application.cms.serialization.Serialization;
|
import org.gcube.application.cms.serialization.Serialization;
|
||||||
import org.gcube.application.geoportal.common.model.document.Project;
|
import org.gcube.application.geoportal.common.model.document.Project;
|
||||||
|
@ -15,9 +16,12 @@ import org.junit.Test;
|
||||||
|
|
||||||
import javax.ws.rs.client.WebTarget;
|
import javax.ws.rs.client.WebTarget;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
public class ProfiledConcessioniTests extends AbstractProfiledDocumentsTests{
|
public class ProfiledConcessioniTests extends AbstractProfiledDocumentsTests{
|
||||||
|
|
||||||
|
|
||||||
|
@ -25,19 +29,27 @@ public class ProfiledConcessioniTests extends AbstractProfiledDocumentsTests{
|
||||||
@Override
|
@Override
|
||||||
protected WebTarget baseTarget() {
|
protected WebTarget baseTarget() {
|
||||||
String testProfileId="profiledConcessioni";
|
String testProfileId="profiledConcessioni";
|
||||||
return target(InterfaceConstants.Methods.PROJECTS).path(testProfileId);
|
return super.baseTarget().path(testProfileId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSDI() throws Exception {
|
public void testSDI() throws Exception {
|
||||||
UserUtils.DEFAULT_ROLES.add("Data-Manager");
|
UserUtils.DEFAULT_ROLES.add("Data-Manager");
|
||||||
// Create new
|
// Create new
|
||||||
|
|
||||||
Document theDoc=Document.parse("{\n" +
|
Document theDoc=Document.parse("{\n" +
|
||||||
"\"posizionamentoScavo\" :{\n" +
|
"\"posizionamentoScavo\" :{\n" +
|
||||||
"\t\"titolo\" : \"mio titolo\"}}");
|
"\t\"titolo\" : \"mio titolo\"}}");
|
||||||
|
|
||||||
|
theDoc.put("startTime", LocalDateTime.now());
|
||||||
|
|
||||||
|
log.debug("Sending {}",theDoc);
|
||||||
|
log.debug("AS JSON : {}",Serialization.write(theDoc));
|
||||||
|
|
||||||
Project doc = createNew(theDoc);
|
Project doc = createNew(theDoc);
|
||||||
|
|
||||||
|
log.debug("Received : {}",doc);
|
||||||
|
log.debug("AS JSON : {}",Serialization.write(doc));
|
||||||
|
|
||||||
|
|
||||||
// register filesets
|
// register filesets
|
||||||
|
@ -71,4 +83,20 @@ public class ProfiledConcessioniTests extends AbstractProfiledDocumentsTests{
|
||||||
assertTrue(doc.getIdentificationReferenceByType(SpatialReference.SPATIAL_REFERENCE_TYPE).size()==1);
|
assertTrue(doc.getIdentificationReferenceByType(SpatialReference.SPATIAL_REFERENCE_TYPE).size()==1);
|
||||||
System.out.println("Project "+doc.getId()+" published with spatial reference "+doc.getIdentificationReferenceByType(SpatialReference.SPATIAL_REFERENCE_TYPE).get(0));
|
System.out.println("Project "+doc.getId()+" published with spatial reference "+doc.getIdentificationReferenceByType(SpatialReference.SPATIAL_REFERENCE_TYPE).get(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void delete() throws Exception {
|
||||||
|
Document theDoc=Document.parse("{\n" +
|
||||||
|
"\"posizionamentoScavo\" :{\n" +
|
||||||
|
"\t\"titolo\" : \"mio titolo\"}}");
|
||||||
|
|
||||||
|
theDoc.put("startTime", LocalDateTime.now());
|
||||||
|
|
||||||
|
log.debug("sendi");
|
||||||
|
|
||||||
|
Project doc = createNew(theDoc);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue