79 lines
2.7 KiB
Java
79 lines
2.7 KiB
Java
package org.gcube.informationsystem.model.impl.properties;
|
|
|
|
import java.io.IOException;
|
|
import java.util.Calendar;
|
|
import java.util.Date;
|
|
import java.util.Map;
|
|
|
|
import org.gcube.com.fasterxml.jackson.core.JsonParseException;
|
|
import org.gcube.com.fasterxml.jackson.databind.JsonMappingException;
|
|
import org.gcube.informationsystem.base.reference.Element;
|
|
import org.gcube.informationsystem.model.reference.properties.Metadata;
|
|
import org.gcube.informationsystem.model.reference.properties.Property;
|
|
import org.gcube.informationsystem.serialization.ElementMapper;
|
|
import org.junit.Assert;
|
|
import org.junit.Test;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
/**
|
|
* @author Luca Frosini (ISTI - CNR)
|
|
*/
|
|
public class MetadataTest {
|
|
|
|
private static Logger logger = LoggerFactory.getLogger(MetadataTest.class);
|
|
|
|
@Test
|
|
public void metadataTest() throws Exception {
|
|
MetadataImpl metadata = new MetadataImpl();
|
|
Date date = Calendar.getInstance().getTime();
|
|
metadata.creationTime = date;
|
|
metadata.lastUpdateTime = date;
|
|
metadata.createdBy = Metadata.UNKNOWN_USER;
|
|
metadata.lastUpdateBy = Metadata.UNKNOWN_USER;
|
|
|
|
String json = ElementMapper.marshal(metadata);
|
|
logger.debug(json);
|
|
|
|
|
|
Property property = ElementMapper.unmarshal(Property.class, json);
|
|
Assert.assertTrue(property instanceof Metadata);
|
|
Assert.assertTrue(((Metadata) property).getCreationTime().compareTo(date)==0);
|
|
Assert.assertTrue(((Metadata) property).getLastUpdateTime().compareTo(date)==0);
|
|
logger.debug(ElementMapper.marshal(property));
|
|
|
|
Metadata h = ElementMapper.unmarshal(Metadata.class, json);
|
|
Assert.assertTrue(property instanceof Metadata);
|
|
Assert.assertTrue(h.getCreationTime().compareTo(date)==0);
|
|
Assert.assertTrue(h.getLastUpdateTime().compareTo(date)==0);
|
|
logger.debug(ElementMapper.marshal(h));
|
|
}
|
|
|
|
@Test
|
|
public void testContextsInMetadata() throws JsonParseException, JsonMappingException, IOException {
|
|
|
|
String metadataJson =
|
|
"{"
|
|
+ "\"" + Element.TYPE_PROPERTY + "\":\"Metadata\","
|
|
+ "\"createdBy\":\"UNKNOWN_USER\","
|
|
+ "\"lastUpdateBy\":\"UNKNOWN_USER\","
|
|
+ "\"creationTime\":\"2020-11-09 10:01:25.415 +0000\","
|
|
+ "\"lastUpdateTime\":\"2020-11-09 10:01:25.415 +0000\","
|
|
+ "\"contexts\": {"
|
|
+ "\"bad5f350-345c-11e9-9f49-cef9b1608c3f\": \"/gcube/devNext/NextNext\""
|
|
+ "}"
|
|
+ "}";
|
|
|
|
Property property = ElementMapper.unmarshal(Property.class, metadataJson);
|
|
logger.debug("{}", property);
|
|
|
|
Metadata h = ElementMapper.unmarshal(Metadata.class, metadataJson);
|
|
logger.debug("{}", h);
|
|
|
|
@SuppressWarnings("unchecked")
|
|
Map<String,String> contexts = (Map<String, String>) h.getAdditionalProperty(Metadata.__CONTEXTS);
|
|
logger.debug("Contexts IDs are {}", contexts);
|
|
}
|
|
|
|
}
|