private void runTests(String base) throws IOException {
Abdera abdera = new Abdera();
Factory factory = abdera.getFactory();
AbderaClient client = new AbderaClient(abdera);
String uri = "http://localhost:9002" + base;
// Service document test.
ClientResponse res = client.get(uri);
assertNotNull(res);
try {
assertEquals(200, res.getStatus());
assertEquals(ResponseType.SUCCESS, res.getType());
assertTrue(MimeTypeHelper.isMatch(res.getContentType().toString(), Constants.APP_MEDIA_TYPE));
Document<Service> doc = res.getDocument();
Service service = doc.getRoot();
assertEquals(1, service.getWorkspaces().size());
Workspace workspace = service.getWorkspaces().get(0);
assertEquals(1, workspace.getCollections().size());
// Keep the loop in case we add other collections to the test.
for (Collection collection : workspace.getCollections()) {
if (collection.getTitle().equals("Acme Customer Database")) {
String expected = uri + "customers";
String actual = collection.getResolvedHref().toString();
assertEquals(expected, actual);
}
}
} finally {
res.release();
}
// Testing of entry creation
IRI colUri = new IRI(uri).resolve("customers");
Entry entry = factory.newEntry();
entry.setTitle("This is ignored right now");
entry.setUpdated(new Date());
entry.addAuthor("Acme Industries");
entry.setId(factory.newUuidUri());
entry.setSummary("Customer document");
Element customerEl = factory.newElement(new QName("customer"));
customerEl.setAttributeValue(new QName("name"), "Dan Diephouse");
entry.setContent(customerEl);
RequestOptions opts = new RequestOptions();
opts.setContentType("application/atom+xml;type=entry");
res = client.post(colUri.toString() + "?test=foo", entry, opts);
assertEquals(201, res.getStatus());
//prettyPrint(abdera, res.getDocument());
IRI location = res.getLocation();
assertEquals(uri + "customers/1001-Dan_Diephouse", location.toString());
// GET the entry
res = client.get(location.toString());
assertEquals(200, res.getStatus());
res.release();
// prettyPrint(abdera, res.getDocument());
org.apache.abdera.model.Document<Entry> entry_doc = res.getDocument();
//prettyPrint(abdera, entry_doc);
entry = entry_doc.getRoot();
assertEquals(uri + "customers/1001-Dan_Diephouse", entry_doc.getRoot().getEditLinkResolvedHref().toString());
// HEAD
res = client.head(location.toString());
assertEquals(200, res.getStatus());
assertEquals(0, res.getContentLength());
res.release();
// Try invalid resources
res = client.get(colUri + "/foobar");
assertEquals(404, res.getStatus());
res.release();
res = client.head(colUri + "/foobar");
assertEquals(404, res.getStatus());
assertEquals(0, res.getContentLength());
res.release();
IRI badColUri = new IRI(uri).resolve("customersbad");
// GET the service doc
res = client.get(colUri.toString());
assertEquals(200, res.getStatus());
res.release();
res = client.get(badColUri.toString());
assertEquals(404, res.getStatus());
res.release();
}