PageRenderTime 11ms CodeModel.GetById 2ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/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
25package org.hudsonci.utils.marshal.xref;
26
27import com.thoughtworks.xstream.XStream;
28import com.thoughtworks.xstream.annotations.XStreamAlias;
29import org.junit.After;
30import org.junit.Before;
31import org.junit.Test;
32
33import java.util.Date;
34
35/**
36 * Tests for {@link XReference}.
37 */
38public class XReferenceTest
39{
40    private XStream xs;
41
42    @Before
43    public void setUp() throws Exception {
44        xs = new XStream();
45        xs.autodetectAnnotations(true);
46    }
47
48    @After
49    public void tearDown() throws Exception {
50        xs = null;
51    }
52
53    @Test
54    public void testMarshal() throws Exception {
55        Date value1 = new Date();
56        TestRef ref1 = new TestRef(value1, "a");
57
58        String xml = xs.toXML(ref1);
59        System.out.println("XML:\n" + xml);
60    }
61
62    @XStreamAlias("test-ref")
63    private static class TestRef
64        extends XReference
65    {
66        private String path;
67
68        private TestRef(Object value, String path) {
69            super(value);
70            this.path = path;
71        }
72
73        @Override
74        public String getPath() {
75            return path;
76        }
77    }
78}