New test case added
This commit is contained in:
parent
310817e425
commit
e5a10134bd
|
@ -1,5 +1,8 @@
|
|||
package org.gcube.application;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.time.LocalDate;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
|
@ -26,6 +29,13 @@ import org.gcube.common.scope.api.ScopeProvider;
|
|||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||
import com.fasterxml.jackson.databind.JsonSerializer;
|
||||
import com.fasterxml.jackson.databind.SerializerProvider;
|
||||
|
||||
public class Project_Tests {
|
||||
|
||||
private ProjectsCaller client = null;
|
||||
|
@ -35,7 +45,7 @@ public class Project_Tests {
|
|||
private static String CONTEXT = "/gcube/devsec/devVRE";
|
||||
private static String TOKEN = ""; // devVRE
|
||||
private static String PROFILE_ID = "profiledConcessioni";
|
||||
private static String PROJECT_ID = "6226220daf515916fdb54e08";
|
||||
private static String PROJECT_ID = "62962b2502ad3d25dc21deac";
|
||||
|
||||
@Before
|
||||
public void getClient() {
|
||||
|
@ -55,7 +65,7 @@ public class Project_Tests {
|
|||
}
|
||||
}
|
||||
|
||||
// @Test
|
||||
//@Test
|
||||
public void getByID() throws Exception {
|
||||
Project project = client.getProjectByID(PROFILE_ID, PROJECT_ID);
|
||||
ProjectDVBuilder projectBuilder = ProjectDVBuilder.newBuilder().fullDocumentMap(true);
|
||||
|
@ -75,7 +85,7 @@ public class Project_Tests {
|
|||
|
||||
}
|
||||
|
||||
@Test
|
||||
// @Test
|
||||
public void getListProjectsDVFiltered() throws Exception {
|
||||
// List<Project> listOfProjects = client.getListForProfileID(PROFILE_ID);
|
||||
|
||||
|
@ -106,7 +116,9 @@ public class Project_Tests {
|
|||
|
||||
projection.put("_theDocument.introduzione", 1);
|
||||
projection.put("_theDocument.authors", 1);
|
||||
filter.setProjection(projection, ResultDocumentDV.class);
|
||||
projection.put("_theDocument.dataInizioProgetto", 1);
|
||||
|
||||
filter.setProjection(projection);
|
||||
|
||||
Integer totalDocs = client.getTotalDocument(PROFILE_ID);
|
||||
|
||||
|
@ -118,15 +130,15 @@ public class Project_Tests {
|
|||
System.out.println(++i + ") " + projectDV);
|
||||
}
|
||||
|
||||
//TEST TO PROJECT DV
|
||||
// TEST TO PROJECT DV
|
||||
/*
|
||||
ProjectDVBuilder projectBuilder = ProjectDVBuilder.newBuilder().fullDocumentMap(true);
|
||||
|
||||
List<ProjectDV> listProjects = ConvertToDataValueObjectModel.toListProject(projects, projectBuilder);
|
||||
i = 0;
|
||||
for (ProjectDV projectDV : listProjects) {
|
||||
System.out.println(++i + ") " + projectDV);
|
||||
}
|
||||
* ProjectDVBuilder projectBuilder =
|
||||
* ProjectDVBuilder.newBuilder().fullDocumentMap(true);
|
||||
*
|
||||
* List<ProjectDV> listProjects =
|
||||
* ConvertToDataValueObjectModel.toListProject(projects, projectBuilder); i = 0;
|
||||
* for (ProjectDV projectDV : listProjects) { System.out.println(++i + ") " +
|
||||
* projectDV); }
|
||||
*/
|
||||
}
|
||||
|
||||
|
@ -163,4 +175,51 @@ public class Project_Tests {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deserializeISOJSONObjectAsDate() throws Exception {
|
||||
|
||||
String jsonDate = "{hour=0, minute=0, " + "dayOfYear=259, " + "dayOfWeek=MONDAY, " + "dayOfMonth=16, "
|
||||
+ "monthValue=9, " + "year=2019, " + "month=SEPTEMBER, " + "second=0, " + "nano=0, "
|
||||
+ "chronology={calendarType=iso8601, id=ISO}" + "}";
|
||||
|
||||
try {
|
||||
|
||||
/*ObjectMapper objectMapper = new ObjectMapper();
|
||||
JavaTimeModule javaTimeModule = new JavaTimeModule();
|
||||
javaTimeModule.addDeserializer(LocalDate.class, new MyLocalDateDeserializer());
|
||||
javaTimeModule.addSerializer(LocalDate.class, new MyLocalDateSerializer());
|
||||
objectMapper.registerModule(javaTimeModule);
|
||||
|
||||
objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
|
||||
objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
|
||||
objectMapper.configure(SerializationFeature.WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS, false);
|
||||
LocalDate date = objectMapper.readerFor(LocalDate.class).readValue(jsonDate);
|
||||
System.out.println(date);*/
|
||||
|
||||
//checking if the jsonDate is a LocalDate
|
||||
//LocalDateTime date = org.gcube.application.geoportal.client.utils.Serialization.read(jsonDate, LocalDateTime.class);
|
||||
LocalDate date = org.gcube.application.geoportal.client.utils.Serialization.read(jsonDate, LocalDate.class);
|
||||
System.out.println(date);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static final DateTimeFormatter FULL_FORMATTER = DateTimeFormatter.ofPattern("uuuuMMdd_HH-mm-ss");
|
||||
|
||||
public static class MyLocalDateSerializer extends JsonSerializer<LocalDate> {
|
||||
@Override
|
||||
public void serialize(LocalDate value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
|
||||
gen.writeString(value.format(FULL_FORMATTER));
|
||||
}
|
||||
}
|
||||
|
||||
public static class MyLocalDateDeserializer extends JsonDeserializer<LocalDate> {
|
||||
|
||||
@Override
|
||||
public LocalDate deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
|
||||
return LocalDate.parse(p.getValueAsString(), FULL_FORMATTER);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue