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.

XMLWriterTest.java 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package org.apache.archiva.xml;
  2. /*
  3. * Licensed to the Apache Software Foundation (ASF) under one
  4. * or more contributor license agreements. See the NOTICE file
  5. * distributed with this work for additional information
  6. * regarding copyright ownership. The ASF licenses this file
  7. * to you under the Apache License, Version 2.0 (the
  8. * "License"); you may not use this file except in compliance
  9. * with the License. You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing,
  14. * software distributed under the License is distributed on an
  15. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  16. * KIND, either express or implied. See the License for the
  17. * specific language governing permissions and limitations
  18. * under the License.
  19. */
  20. import org.dom4j.Document;
  21. import org.dom4j.DocumentHelper;
  22. import org.dom4j.Element;
  23. import org.junit.Test;
  24. import java.io.StringWriter;
  25. /**
  26. * XMLWriterTest
  27. *
  28. *
  29. */
  30. public class XMLWriterTest
  31. extends AbstractArchivaXmlTestCase
  32. {
  33. @Test
  34. public void testWrite()
  35. throws Exception
  36. {
  37. StringBuilder expected = new StringBuilder();
  38. expected.append( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" );
  39. expected.append( "\n" );
  40. expected.append( "<basic>\n" );
  41. expected.append( " <names>\n" );
  42. expected.append( " <name>" ).append( TRYGVIS ).append( "</name>\n" );
  43. expected.append( " <name>" ).append( INFINITE_ARCHIVA ).append( "</name>\n" );
  44. expected.append( " </names>\n" );
  45. expected.append( "</basic>\n" );
  46. Element basic = DocumentHelper.createElement( "basic" );
  47. Document doc = DocumentHelper.createDocument( basic );
  48. Element names = basic.addElement( "names" );
  49. names.addElement( "name" ).setText( TRYGVIS );
  50. names.addElement( "name" ).setText( INFINITE_ARCHIVA );
  51. StringWriter actual = new StringWriter();
  52. XMLWriter.write( doc, actual );
  53. assertEquals( "Comparision of contents:", expected.toString(), actual.toString() );
  54. }
  55. }