Search in sources :

Example 1 with ElementNameAndTextQualifier

use of org.custommonkey.xmlunit.ElementNameAndTextQualifier in project opencast by opencast.

the class RoleParsingTest method testMarshalUser.

@Test
public void testMarshalUser() throws Exception {
    StringWriter writer = new StringWriter();
    JaxbRole role = new JaxbRole("ROLE_TEST", ORGANIZATION, "This is a test role");
    jaxbContext.createMarshaller().marshal(role, writer);
    String expectedOutput = IOUtils.toString(getClass().getResourceAsStream(ROLE_XML_FILE), "UTF-8");
    Diff diff = new Diff(expectedOutput, writer.toString());
    /* We don't care about ordering. */
    diff.overrideElementQualifier(new ElementNameAndTextQualifier());
    XMLAssert.assertXMLEqual(diff, true);
}
Also used : StringWriter(java.io.StringWriter) Diff(org.custommonkey.xmlunit.Diff) ElementNameAndTextQualifier(org.custommonkey.xmlunit.ElementNameAndTextQualifier) Test(org.junit.Test)

Example 2 with ElementNameAndTextQualifier

use of org.custommonkey.xmlunit.ElementNameAndTextQualifier in project opencast by opencast.

the class GroupParsingTest method testMarshalUser.

@Test
public void testMarshalUser() throws Exception {
    StringWriter writer = new StringWriter();
    StringWriter writer2 = new StringWriter();
    Set<JaxbRole> roles = new HashSet<JaxbRole>();
    roles.add(new JaxbRole("ROLE_COURSE_ADMIN", ORGANIZATION));
    roles.add(new JaxbRole("ROLE_USER", ORGANIZATION));
    Set<String> members = new HashSet<String>();
    members.add("admin1");
    members.add("admin2");
    JaxbGroup group = new JaxbGroup("admin", ORGANIZATION, "Admin", "Admin group", roles, members);
    jaxbContext.createMarshaller().marshal(group, writer);
    String expectedOutput = IOUtils.toString(getClass().getResourceAsStream(GROUP_XML_FILE), "UTF-8");
    StreamSource streamSource = new StreamSource(getClass().getResourceAsStream(GROUP_XML_FILE));
    JaxbGroup groupFromFile = jaxbContext.createUnmarshaller().unmarshal(streamSource, JaxbGroup.class).getValue();
    jaxbContext.createMarshaller().marshal(groupFromFile, writer2);
    Diff diff = new Diff(writer2.toString(), writer.toString());
    /* We don't care about ordering. */
    diff.overrideElementQualifier(new ElementNameAndTextQualifier());
    XMLAssert.assertXMLEqual(diff, true);
}
Also used : JaxbGroup(org.opencastproject.security.api.JaxbGroup) JaxbRole(org.opencastproject.security.api.JaxbRole) StringWriter(java.io.StringWriter) Diff(org.custommonkey.xmlunit.Diff) ElementNameAndTextQualifier(org.custommonkey.xmlunit.ElementNameAndTextQualifier) StreamSource(javax.xml.transform.stream.StreamSource) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

StringWriter (java.io.StringWriter)2 Diff (org.custommonkey.xmlunit.Diff)2 ElementNameAndTextQualifier (org.custommonkey.xmlunit.ElementNameAndTextQualifier)2 Test (org.junit.Test)2 HashSet (java.util.HashSet)1 StreamSource (javax.xml.transform.stream.StreamSource)1 JaxbGroup (org.opencastproject.security.api.JaxbGroup)1 JaxbRole (org.opencastproject.security.api.JaxbRole)1