use of com.cloudant.client.api.model.DesignDocument in project java-cloudant by cloudant.
the class DesignDocumentsTest method designDocPutNoPrefix.
/**
* Validate that a design document can be retrieved without using the "_design" prefix.
*
* @throws Exception
*/
@Test
public void designDocPutNoPrefix() throws Exception {
// Write a doc without a _design prefix
// Create an example without the _design prefix
DesignDocument designDocExampleNoPrefix = fileToDesignDocument("example");
designDocExampleNoPrefix.setId("example");
Utils.assertOKResponse(designManager.put(designDocExampleNoPrefix));
// Retrieve it with a prefix
assertNotNull(designManager.get("_design/example"), "The design doc should be retrievable" + " with a _design prefix");
}
use of com.cloudant.client.api.model.DesignDocument in project java-cloudant by cloudant.
the class DesignDocumentsTest method serializeQueryDesignDoc.
/**
* Test that if a query language design document is serialized the map function is a string
* form of the JSON object.
*
* @throws Exception
* @see #serializeJavascriptView()
* @see #deserializeJavascriptView()
* @see #deserializeQueryDesignDoc()
*/
@Test
public void serializeQueryDesignDoc() throws Exception {
DesignDocument queryDDoc = fileToDesignDocument("query");
Map<String, DesignDocument.MapReduce> views = queryDDoc.getViews();
assertEquals(1, views.size(), "There should be one view");
for (DesignDocument.MapReduce mrView : views.values()) {
assertTrue(mrView.getMap().startsWith("{"), "The map function should be a javascript " + "function in a JSON form, " + "so start with {");
assertTrue(mrView.getMap().endsWith("}"), "The map function should be a javascript " + "function in a JSON form, " + "so end with }");
assertEquals("{\"fields\":{\"Person_dob\":\"asc\"}}", mrView.getMap(), "The map " + "function string should be an object form");
}
}
use of com.cloudant.client.api.model.DesignDocument in project java-cloudant by cloudant.
the class DesignDocumentsTest method designDocCompare.
@Test
public void designDocCompare() throws Exception {
DesignDocument exampleDoc = fileToDesignDocument("example");
Response response = designManager.put(exampleDoc);
// Assign the revision to our local DesignDocument object (needed for equality)
exampleDoc.setRevision(response.getRev());
DesignDocument designDoc11 = db.getDesignDocumentManager().get("_design/example");
assertEquals(exampleDoc, designDoc11, "The design document retrieved should equal ");
}
use of com.cloudant.client.api.model.DesignDocument in project java-cloudant by cloudant.
the class DesignDocumentsTest method designDocRemoveNoPrefixWithObject.
/**
* Validate that a design document can be removed without using the "_design" prefix when a
* DesignDocument object is supplied
*
* @throws Exception
*/
@Test
public void designDocRemoveNoPrefixWithObject() throws Exception {
// Write a doc with a _design prefix
Response r = designManager.put(designDocExample);
DesignDocument ddoc = new DesignDocument();
ddoc.setId("example");
ddoc.setRevision(r.getRev());
// Retrieve it without a prefix
Utils.assertOKResponse(designManager.remove(ddoc));
}
use of com.cloudant.client.api.model.DesignDocument in project java-cloudant by cloudant.
the class DesignDocumentsTest method listDesignDocuments.
/**
* Test the {@link DesignDocumentManager#list()} function. Assert that the returned list of
* design documents matches that expected.
*
* @throws Exception
*/
@Test
public void listDesignDocuments() throws Exception {
// Put all the design docs from the directory
List<DesignDocument> designDocs = DesignDocumentManager.fromDirectory(rootDesignDir);
// Sort the list lexicographically so that the order matches that returned by the list
// function, as elements need to be in the same order for list.equals().
Collections.sort(designDocs, new Comparator<DesignDocument>() {
@Override
public int compare(DesignDocument doc1, DesignDocument doc2) {
return doc1.getId().compareTo(doc2.getId());
}
});
for (DesignDocument doc : designDocs) {
// Put each design document and set the revision for equality comparison later
doc.setRevision(designManager.put(doc).getRev());
}
assertEquals(designDocs, designManager.list(), "The retrieved list of design documents " + "should match the expected list");
}
Aggregations