You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.6 KiB
40 lines
1.6 KiB
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()); |
|
} |
|
} |
|
|
|
|