01: /*
02: * Copyright (C) 2007 XStream Committers.
03: * All rights reserved.
04: *
05: * The software in this package is published under the terms of the BSD
06: * style license a copy of which has been included with this distribution in
07: * the LICENSE.txt file.
08: *
09: * Created on 10. November 2007 by Joerg Schaible
10: */
11: package com.thoughtworks.acceptance.annotations;
12:
13: import com.thoughtworks.acceptance.AbstractAcceptanceTest;
14: import com.thoughtworks.xstream.XStream;
15: import com.thoughtworks.xstream.annotations.AnnotationProvider;
16: import com.thoughtworks.xstream.annotations.AnnotationReflectionConverter;
17: import com.thoughtworks.xstream.annotations.Annotations;
18:
19: /**
20: * Tests XStream 1.2.x annotation compatibility.
21: * @author Jörg Schaible
22: */
23: public class XStream12AnnotationCompatibilityTest extends
24: AbstractAcceptanceTest {
25:
26: @Override
27: protected void setUp() throws Exception {
28: super .setUp();
29: xstream = new XStream();
30: xstream.registerConverter(new AnnotationReflectionConverter(
31: xstream.getMapper(), xstream.getReflectionProvider(),
32: new AnnotationProvider()), XStream.PRIORITY_VERY_LOW);
33: xstream.alias("annotatedTask",
34: FieldConverterTest.TaskWithAnnotations.class);
35: }
36:
37: public void testDifferentConverterCanBeAnnotatedForFieldsOfSameType() {
38: final FieldConverterTest.TaskWithAnnotations task = new FieldConverterTest.TaskWithAnnotations(
39: "Tom", "Dick", "Harry");
40: final String xml = "" + "<annotatedTask>\n"
41: + " <name1 str=\"Tom\"/>\n"
42: + " <name2>_Dick_</name2>\n"
43: + " <name3>Harry</name3>\n" + "</annotatedTask>";
44: assertBothWays(task, xml);
45: }
46:
47: public void testImplicitCollection() {
48: String expected = "" + "<root>\n" + " <string>one</string>\n"
49: + " <string>two</string>\n" + "</root>";
50: Annotations.configureAliases(xstream,
51: ImplicitCollectionTest.ImplicitRootOne.class);
52: ImplicitCollectionTest.ImplicitRootOne implicitRoot = new ImplicitCollectionTest.ImplicitRootOne();
53: implicitRoot.getValues().add("one");
54: implicitRoot.getValues().add("two");
55: assertBothWays(implicitRoot, expected);
56: }
57:
58: }
|