Search in sources :

Example 6 with DesignDocument

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");
}
Also used : DesignDocument(com.cloudant.client.api.model.DesignDocument) Test(org.junit.jupiter.api.Test)

Example 7 with DesignDocument

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");
    }
}
Also used : DesignDocument(com.cloudant.client.api.model.DesignDocument) Test(org.junit.jupiter.api.Test)

Example 8 with DesignDocument

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 ");
}
Also used : Response(com.cloudant.client.api.model.Response) MockResponse(okhttp3.mockwebserver.MockResponse) DesignDocument(com.cloudant.client.api.model.DesignDocument) Test(org.junit.jupiter.api.Test)

Example 9 with DesignDocument

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));
}
Also used : Response(com.cloudant.client.api.model.Response) MockResponse(okhttp3.mockwebserver.MockResponse) DesignDocument(com.cloudant.client.api.model.DesignDocument) Test(org.junit.jupiter.api.Test)

Example 10 with DesignDocument

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");
}
Also used : DesignDocument(com.cloudant.client.api.model.DesignDocument) Test(org.junit.jupiter.api.Test)

Aggregations

DesignDocument (com.cloudant.client.api.model.DesignDocument)15 Test (org.junit.jupiter.api.Test)10 Response (com.cloudant.client.api.model.Response)4 MockResponse (okhttp3.mockwebserver.MockResponse)4 JsonObject (com.google.gson.JsonObject)2 File (java.io.File)2 HashMap (java.util.HashMap)2 DesignDocumentManager (com.cloudant.client.api.DesignDocumentManager)1 NoDocumentException (com.cloudant.client.org.lightcouch.NoDocumentException)1 Gson (com.google.gson.Gson)1 JsonArray (com.google.gson.JsonArray)1 FileInputStream (java.io.FileInputStream)1 InputStreamReader (java.io.InputStreamReader)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 BeforeAll (org.junit.jupiter.api.BeforeAll)1