summaryrefslogtreecommitdiff
path: root/projects/net.wotonomy.web/src/test/java/net/wotonomy/web/xml/XMLRPCSelectorTest.java
blob: 726fcd06c50ea43f470f6e64d2598d910ff7846e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package net.wotonomy.web.xml;

import java.io.Serializable;
import java.net.URL;
import java.util.Date;

import junit.framework.TestCase;

public class XMLRPCSelectorTest extends TestCase {

	public XMLRPCSelectorTest(String name) {
		super(name);
	}

	protected void setUp() throws Exception {
		super.setUp();
	}

	protected void tearDown() throws Exception {
		super.tearDown();
	}

	public static void testFoo() {
		try {
			// create url for server
			URL url = new URL("http://localhost:8080/xmlrpctest");

			// set up selectors
			XMLRPCSelector getFullName = new XMLRPCSelector("getFullName");
			XMLRPCSelector getCreateDate = new XMLRPCSelector("getCreateDate");
			XMLRPCSelector setCreateDate = new XMLRPCSelector("setCreateDate");
			XMLRPCSelector getChildList = new XMLRPCSelector("getChildList");
			XMLRPCSelector setChildList = new XMLRPCSelector("setChildList");

			// fetch the full name
			System.out.println(getFullName.invoke(url));

			// fetch the create date
			System.out.println(getCreateDate.invoke(url));
			// set date to current time
			setCreateDate.invoke(url, new java.util.Date());
			// re-fetch the create date
			System.out.println(getCreateDate.invoke(url));

			// fetch the child list
			java.util.List childList = (java.util.List) getChildList.invoke(url);
			System.out.println(childList);
			// add a new child
			childList.add(new MockSerializableObject(new Long(5), "John", "Doe", new Date()));
			setChildList.invoke(url, childList);
			// re-fetch the child list
			System.out.println(getChildList.invoke(url));
		} catch (Exception exc) {
			// exc.printStackTrace();
		}
	}

	public static class MockSerializableObject implements Serializable {
		public String firstname;
		public String lastname;
		public Long id;
		public Date aDate;

		public MockSerializableObject(Long id, String firstname, String lastname, Date date) {
			super();
			aDate = date;
			this.firstname = firstname;
			this.id = id;
			this.lastname = lastname;
		}

	}

}