1
2
3
4
5
6
7
8
9
10 package org.mule.module.atom;
11
12 import org.mule.tck.FunctionalTestCase;
13
14 import java.io.IOException;
15 import java.util.Date;
16
17 import javax.xml.namespace.QName;
18
19 import org.apache.abdera.Abdera;
20 import org.apache.abdera.factory.Factory;
21 import org.apache.abdera.i18n.iri.IRI;
22 import org.apache.abdera.model.Base;
23 import org.apache.abdera.model.Element;
24 import org.apache.abdera.model.Entry;
25 import org.apache.abdera.protocol.client.AbderaClient;
26 import org.apache.abdera.protocol.client.ClientResponse;
27 import org.apache.abdera.protocol.client.RequestOptions;
28 import org.apache.abdera.writer.Writer;
29
30 public abstract class AbstractCustomerTest extends FunctionalTestCase
31 {
32
33 public void testCustomerProvider(String basePath) throws Exception
34 {
35 Abdera abdera = new Abdera();
36 Factory factory = abdera.getFactory();
37
38 AbderaClient client = new AbderaClient(abdera);
39 String base = "http://localhost:9002" + basePath + "/";
40
41
42 IRI colUri = new IRI(base).resolve("customers");
43 Entry entry = factory.newEntry();
44 entry.setTitle("Hmmm this is ignored right now");
45 entry.setUpdated(new Date());
46 entry.addAuthor("Acme Industries");
47 entry.setId(factory.newUuidUri());
48 entry.setSummary("Customer document");
49
50 Element customerEl = factory.newElement(new QName("customer"));
51 customerEl.setAttributeValue(new QName("name"), "Dan Diephouse");
52 entry.setContent(customerEl);
53
54 RequestOptions opts = new RequestOptions();
55 opts.setContentType("application/atom+xml;type=entry");
56 ClientResponse res = client.post(colUri.toString(), entry, opts);
57 assertEquals(201, res.getStatus());
58
59 IRI location = res.getLocation();
60 assertEquals(basePath + "/customers/1001-Dan_Diephouse", location.toString());
61
62
63 res = client.get(colUri.resolve(location.toString()).toString());
64 assertEquals(200, res.getStatus());
65
66 org.apache.abdera.model.Document<Entry> entry_doc = res.getDocument();
67 entry = entry_doc.getRoot();
68 }
69
70 protected void prettyPrint(Abdera abdera, Base doc) throws IOException
71 {
72 Writer writer = abdera.getWriterFactory().getWriter("prettyxml");
73 writer.writeTo(doc, System.out);
74 System.out.println();
75 }
76 }