public void assertBuild(Build expected, Object actualObject) { if (expected == null) { Assert.assertNull("/model/builder", actualObject); } else { Assert.assertNotNull("/model/builder", actualObject); Assert.assertEquals("/model/builder", Build.class, actualObject.getClass()); Build actual = (Build) actualObject; Assert.assertEquals( "/model/builder/sourceDirectory", expected.getSourceDirectory(), actual.getSourceDirectory()); Assert.assertEquals( "/model/builder/unitTestSourceDirectory", expected.getUnitTestSourceDirectory(), actual.getUnitTestSourceDirectory()); } }
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")); }