package de.superx.spring.batch; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import org.junit.Test; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; import de.superx.job.ActionNode; import de.superx.job.ContainerNode; import de.superx.spring.service.JsonJobDescriptionAdapter; public class ObjectMappingTest { private final static String JSON = "{\"type\":\"CONTAINER\",\"name\":\"test\",\"id\":\"testId\",\"tid\":null,\"systemInfoId\":42," + "\"active\":true,\"custom\":0,\"actions\":[],\"jobType\":\"unknown\",\"parameters\":{},\"ignoreErrors\":false," + "\"description\":\"test\",\"jobSource\":\"FILE\"}"; @Test public void testContainerSerialization() throws JsonProcessingException { ContainerNode root = new ContainerNode("test", "testId", Integer.valueOf(42)); ObjectMapper mapper = new ObjectMapper(); String json = mapper.writeValueAsString(root); assertEquals("Serialize to JSON", JSON, json); } @Test public void testContainerDeserialization() throws JsonMappingException, JsonProcessingException { JsonJobDescriptionAdapter jjda = new JsonJobDescriptionAdapter(); ActionNode node = jjda.convert(JSON); assertNotNull("JSON String converts to ActionNode", node); assertEquals("JSON String converts to ContainerNode", ContainerNode.class, node.getClass()); } }