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