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