package org.gcube.informationsystem.model.impl.properties; import java.io.IOException; import java.util.Calendar; import java.util.Date; import java.util.List; import java.util.UUID; import org.gcube.com.fasterxml.jackson.core.JsonParseException; import org.gcube.com.fasterxml.jackson.databind.JsonMappingException; import org.gcube.informationsystem.model.reference.properties.Header; import org.gcube.informationsystem.model.reference.properties.Property; import org.gcube.informationsystem.utils.ElementMapper; import org.junit.Assert; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * @author Luca Frosini (ISTI - CNR) */ public class HeaderTest { private static Logger logger = LoggerFactory.getLogger(HeaderTest.class); @Test public void headerTest() throws Exception { HeaderImpl header = new HeaderImpl(UUID.randomUUID()); Date date = Calendar.getInstance().getTime(); header.creationTime = date; header.lastUpdateTime = date; header.creator = Header.UNKNOWN_USER; String json = ElementMapper.marshal(header); logger.debug(json); Property property = ElementMapper.unmarshal(Property.class, json); Assert.assertTrue(property instanceof Header); Assert.assertTrue(((Header) property).getCreationTime().compareTo(date)==0); Assert.assertTrue(((Header) property).getLastUpdateTime().compareTo(date)==0); logger.debug(ElementMapper.marshal(property)); Header h = ElementMapper.unmarshal(Header.class, json); Assert.assertTrue(property instanceof Header); Assert.assertTrue(h.getCreationTime().compareTo(date)==0); Assert.assertTrue(h.getLastUpdateTime().compareTo(date)==0); logger.debug(ElementMapper.marshal(h)); } @Test public void testContextsInHeader() throws JsonParseException, JsonMappingException, IOException { String headerJson = "{\"@class\":\"Header\",\"uuid\":\"cee84aaf-030c-4170-b554-836e7df3f611\",\"creator\":\"UNKNOWN_USER\",\"modifiedBy\":null,\"creationTime\":\"2020-11-09 10:01:25.415 +0000\",\"lastUpdateTime\":\"2020-11-09 10:01:25.415 +0000\",\"contexts\":[\"167114e0-9027-4e9e-83af-57973a8f8f08\",\"bad5f350-345c-11e9-9f49-cef9b1608c3f\"]}"; Property property = ElementMapper.unmarshal(Property.class, headerJson); logger.debug("{}", property); Header h = ElementMapper.unmarshal(Header.class, headerJson); logger.debug("{}", h); @SuppressWarnings("unchecked") List contexts = (List) h.getAdditionalProperty(Header.__CONTEXTS); logger.debug("Contexts UUIDs are {}", contexts); } }