01: /*
02: * Copyright (C) 2004, 2006 Joe Walnes.
03: * Copyright (C) 2006, 2007, 2008 XStream Committers.
04: * All rights reserved.
05: *
06: * The software in this package is published under the terms of the BSD
07: * style license a copy of which has been included with this distribution in
08: * the LICENSE.txt file.
09: *
10: * Created on 25. March 2004 by Joe Walnes
11: */
12: package com.thoughtworks.acceptance;
13:
14: import com.thoughtworks.acceptance.objects.SampleDynamicProxy;
15:
16: public class DynamicProxyTest extends AbstractAcceptanceTest {
17: public static class ClassWithProxyMember {
18: SampleDynamicProxy.InterfaceOne one;
19: SampleDynamicProxy.InterfaceTwo two;
20: };
21:
22: public void testCanBeMarshaled() {
23: assertBothWays(
24: SampleDynamicProxy.newInstance(),
25: ""
26: + "<dynamic-proxy>\n"
27: + " <interface>com.thoughtworks.acceptance.objects.SampleDynamicProxy$InterfaceOne</interface>\n"
28: + " <interface>com.thoughtworks.acceptance.objects.SampleDynamicProxy$InterfaceTwo</interface>\n"
29: + " <handler class=\"com.thoughtworks.acceptance.objects.SampleDynamicProxy\">\n"
30: + " <aField>hello</aField>\n"
31: + " </handler>\n" + "</dynamic-proxy>");
32: }
33:
34: public void testAsFieldMember() {
35: ClassWithProxyMember expected = new ClassWithProxyMember();
36: expected.one = (SampleDynamicProxy.InterfaceOne) SampleDynamicProxy
37: .newInstance();
38: expected.two = (SampleDynamicProxy.InterfaceTwo) expected.one;
39: xstream.alias("with-proxy", ClassWithProxyMember.class);
40: assertBothWays(
41: expected,
42: ""
43: + "<with-proxy>\n"
44: + " <one class=\"dynamic-proxy\">\n"
45: + " <interface>com.thoughtworks.acceptance.objects.SampleDynamicProxy$InterfaceOne</interface>\n"
46: + " <interface>com.thoughtworks.acceptance.objects.SampleDynamicProxy$InterfaceTwo</interface>\n"
47: + " <handler class=\"com.thoughtworks.acceptance.objects.SampleDynamicProxy\">\n"
48: + " <aField>hello</aField>\n"
49: + " </handler>\n"
50: + " </one>\n"
51: + " <two class=\"dynamic-proxy\" reference=\"../one\"/>\n"
52: + "</with-proxy>");
53: }
54:
55: public void testTypeCanBeAliased() {
56: xstream.aliasType("one", SampleDynamicProxy.InterfaceOne.class);
57: xstream.alias("two", SampleDynamicProxy.InterfaceTwo.class);
58: xstream.alias("handler", SampleDynamicProxy.class);
59: String expected = "" + "<one>\n"
60: + " <interface>one</interface>\n"
61: + " <interface>two</interface>\n"
62: + " <handler class=\"handler\">\n"
63: + " <aField>hello</aField>\n" + " </handler>\n"
64: + "</one>";
65: assertEquals(expected, xstream.toXML(SampleDynamicProxy
66: .newInstance()));
67: }
68: }
|