/hudson-utils/src/test/java/org/hudsonci/utils/marshal/xref/XReferenceTest.java

http://github.com/hudson/hudson · Java · 78 lines · 41 code · 11 blank · 26 comment · 0 complexity · d6c942e6c1641389667880daac2fd988 MD5 · raw file

  1. /**
  2. * The MIT License
  3. *
  4. * Copyright (c) 2010-2011 Sonatype, Inc. All rights reserved.
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a copy
  7. * of this software and associated documentation files (the "Software"), to deal
  8. * in the Software without restriction, including without limitation the rights
  9. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. * copies of the Software, and to permit persons to whom the Software is
  11. * furnished to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included in
  14. * all copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  19. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  22. * THE SOFTWARE.
  23. */
  24. package org.hudsonci.utils.marshal.xref;
  25. import com.thoughtworks.xstream.XStream;
  26. import com.thoughtworks.xstream.annotations.XStreamAlias;
  27. import org.junit.After;
  28. import org.junit.Before;
  29. import org.junit.Test;
  30. import java.util.Date;
  31. /**
  32. * Tests for {@link XReference}.
  33. */
  34. public class XReferenceTest
  35. {
  36. private XStream xs;
  37. @Before
  38. public void setUp() throws Exception {
  39. xs = new XStream();
  40. xs.autodetectAnnotations(true);
  41. }
  42. @After
  43. public void tearDown() throws Exception {
  44. xs = null;
  45. }
  46. @Test
  47. public void testMarshal() throws Exception {
  48. Date value1 = new Date();
  49. TestRef ref1 = new TestRef(value1, "a");
  50. String xml = xs.toXML(ref1);
  51. System.out.println("XML:\n" + xml);
  52. }
  53. @XStreamAlias("test-ref")
  54. private static class TestRef
  55. extends XReference
  56. {
  57. private String path;
  58. private TestRef(Object value, String path) {
  59. super(value);
  60. this.path = path;
  61. }
  62. @Override
  63. public String getPath() {
  64. return path;
  65. }
  66. }
  67. }