Commit 646ced9b authored by Sonia Zorba's avatar Sonia Zorba
Browse files

Handled xlink namespace and added ShortJobDescriptionTest

parent 70020b48
Loading
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -19,6 +19,10 @@
            @javax.xml.bind.annotation.XmlNs(
                    namespaceURI = "http://www.w3.org/2001/XMLSchema-instance",
                    prefix = "xsi"
            ),
            @javax.xml.bind.annotation.XmlNs(
                    namespaceURI = "http://www.w3.org/1999/xlink",
                    prefix = "xlink"
            )
        }
        // </edit>
+4 −0
Original line number Diff line number Diff line
@@ -18,6 +18,10 @@
            @javax.xml.bind.annotation.XmlNs(
                    namespaceURI = "http://www.w3.org/2001/XMLSchema-instance",
                    prefix = "xsi"
            ),
            @javax.xml.bind.annotation.XmlNs(
                    namespaceURI = "http://www.w3.org/1999/xlink",
                    prefix = "xlink"
            )
        }
        // </edit>
+68 −0
Original line number Diff line number Diff line
package net.ivoa.xml.uws.v1;

import java.io.StringReader;
import java.io.StringWriter;
import javax.xml.bind.JAXB;
import javax.xml.datatype.DatatypeConfigurationException;
import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.XMLGregorianCalendar;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.Test;

public class ShortJobDescriptionTest {

    @Test
    public void testXmlSerialization() throws Exception {

        ShortJobDescription jobDesc = getShortJobDescription();

        String xml;
        try ( StringWriter sw = new StringWriter()) {
            JAXB.marshal(jobDesc, sw);
            xml = sw.toString();
            System.out.println(xml);
        }

        assertTrue(xml.contains("xlink:type=\"type\""));

        try ( StringReader sr = new StringReader(xml)) {
            ShortJobDescription deserialized = JAXB.unmarshal(sr, ShortJobDescription.class);
            verifyJobsAreEquals(deserialized);
        }
    }

    private ShortJobDescription getShortJobDescription() {

        ShortJobDescription jobDesc = new ShortJobDescription();
        jobDesc.setCreationTime(getXmlDate("2015-05-26T11:06:45.713"));
        jobDesc.setId("job_id");
        jobDesc.setPhase(ExecutionPhase.EXECUTING);
        jobDesc.setHref("href");
        jobDesc.setOwnerId("owner_id");
        jobDesc.setRunId("run_id");
        jobDesc.setType("type");

        return jobDesc;
    }

    private XMLGregorianCalendar getXmlDate(String dateTimeString) {
        try {
            return DatatypeFactory.newInstance().newXMLGregorianCalendar(dateTimeString);
        } catch (DatatypeConfigurationException ex) {
            throw new RuntimeException(ex);
        }
    }

    private void verifyJobsAreEquals(ShortJobDescription deserialized) {

        assertEquals("href", deserialized.getHref());
        assertEquals("job_id", deserialized.getId());
        assertEquals("owner_id", deserialized.getOwnerId());
        assertEquals("run_id", deserialized.getRunId());
        assertEquals("type", deserialized.getType());
        assertEquals("href", deserialized.getHref());
        assertEquals("2015-05-26T11:06:45.713", deserialized.getCreationTime().toString());
        assertEquals(ExecutionPhase.EXECUTING, deserialized.getPhase());
    }
}
+1 −1

File changed.

Contains only whitespace changes.