Exemple #1
0
  public void verifyEncodedRead() throws IOException, DocumentException {
    String path = "src/test/verifiers/dom4j/expected-encoding.xml";

    Reader reader = ReaderFactory.newXmlReader(new File(path));
    MavenDom4jReader modelReader = new MavenDom4jReader();

    Model model = modelReader.read(reader);

    Assert.assertEquals("Maven\u00A9", model.getName());
  }
Exemple #2
0
  public void verifyReaderAliases() throws IOException, DocumentException {
    MavenDom4jReader reader = new MavenDom4jReader();

    String xml =
        "<mavenModel>\n"
            + "  <website>http://maven.apache.org/website</website>\n"
            + "  <organisation><name>my-org</name></organisation>\n"
            + "</mavenModel>";

    Model expected = new Model();

    expected.setUrl("http://maven.apache.org/website");

    Organization org = new Organization();

    org.setName("my-org");

    expected.setOrganization(org);

    Model actual = reader.read(new StringReader(xml));

    assertModel(expected, actual);
  }
Exemple #3
0
  public void verifyReader() throws IOException, DocumentException {
    MavenDom4jReader reader = new MavenDom4jReader();

    // ----------------------------------------------------------------------
    // Test that the entities is properly resolved
    // ----------------------------------------------------------------------

    String xml =
        "<!DOCTYPE mavenModel [\n"
            + "  <!ENTITY oslash \"&#248;\">\n"
            + "]>\n<mavenModel>\n"
            + "  <groupId>Laugst&oslash;l</groupId>\n"
            + "</mavenModel>";

    Model expected = new Model();

    String groupId = "Laugst\u00f8l";

    expected.setGroupId(groupId);

    Model actual = reader.read(new StringReader(xml));

    assertModel(expected, actual);
  }
Exemple #4
0
  public void verifyWriter() throws IOException, DocumentException {
    String expectedXml = FileUtils.fileRead(getTestFile("src/test/verifiers/dom4j/expected.xml"));
    expectedXml = expectedXml.replaceAll("(\r\n)|(\r)", "\n");

    // ----------------------------------------------------------------------
    // Build the model thats going to be written.
    // ----------------------------------------------------------------------

    Model expected = new Model();

    expected.setExtend("/foo/bar");

    expected.setName("Maven");

    expected.setModelVersion("4.0.0");

    MailingList mailingList = new MailingList();

    mailingList.setName("Mailing list");

    mailingList.setSubscribe("Super Subscribe");

    mailingList.setUnsubscribe("Duper Unsubscribe");

    mailingList.setArchive("?ber Archive");

    expected.addMailingList(mailingList);

    Scm scm = new Scm();

    String connection = "connection";

    String developerConnection = "developerConnection";

    String url = "url";

    scm.setConnection(connection);

    scm.setDeveloperConnection(developerConnection);

    scm.setUrl(url);

    expected.setScm(scm);

    Build build = new Build();

    build.setSourceDirectory("src/main/java");

    build.setUnitTestSourceDirectory("src/test/java");

    SourceModification sourceModification = new SourceModification();

    sourceModification.setClassName("excludeEclipsePlugin");

    sourceModification.setDirectory("foo");

    sourceModification.addExclude("de/abstrakt/tools/codegeneration/eclipse/*.java");

    build.addSourceModification(sourceModification);

    expected.setBuild(build);

    Component component = new Component();

    component.setName("component1");

    expected.addComponent(component);

    component = new Component();

    component.setName("component2");

    component.setComment("comment2");

    expected.addComponent(component);

    Component c2 = new Component();

    c2.setName("sub");

    c2.setComment("subcomment");

    component.getComponents().add(c2);

    component = new Component();

    component.setName("component3");

    Xpp3Dom xpp3Dom = new Xpp3Dom("custom");
    Xpp3Dom child = new Xpp3Dom("foo");
    child.setValue("bar");
    xpp3Dom.addChild(child);
    child = new Xpp3Dom("bar");
    child.setAttribute("att1", "value");
    child.setValue("baz");
    xpp3Dom.addChild(child);
    child = new Xpp3Dom("el1");
    xpp3Dom.addChild(child);
    Xpp3Dom el1 = child;
    child = new Xpp3Dom("el2");
    child.setValue("text");
    el1.addChild(child);

    component.setCustom(xpp3Dom);

    expected.addComponent(component);

    component = new Component();
    component.setName("component4");
    expected.addComponent(component);

    Properties properties = new Properties();
    properties.setProperty("name", "value");
    component.setFlatProperties(properties);

    properties = new Properties();
    properties.setProperty("key", "theValue");
    component.setProperties(properties);

    Repository repository = new Repository();
    repository.setId("foo");
    expected.addRepository(repository);

    // ----------------------------------------------------------------------
    // Write out the model
    // ----------------------------------------------------------------------

    MavenDom4jWriter writer = new MavenDom4jWriter();

    StringWriter buffer = new StringWriter();

    writer.write(buffer, expected);

    String actualXml = buffer.toString();
    actualXml = actualXml.replaceAll("(\r\n)|(\r)", "\n");

    //        System.out.println( expectedXml );
    //
    //        System.err.println( actualXml );

    Assert.assertEquals(expectedXml.trim(), actualXml.trim());

    MavenDom4jReader reader = new MavenDom4jReader();

    Model actual = reader.read(new StringReader(actualXml));

    Assert.assertNotNull("Actual", actual);

    assertModel(expected, actual);

    buffer = new StringWriter();

    writer.write(buffer, actual);

    Assert.assertEquals(
        expectedXml.trim(), buffer.toString().trim().replaceAll("(\r\n)|(\r)", "\n"));
  }