Package com.couchace.core.api.response

Examples of com.couchace.core.api.response.WriteResponse


    }

    @Override
    public WriteResponse createDatabase() {
        CouchHttpResponse httpResponse =  httpClient.createDatabase(databaseName);
        return new WriteResponse(httpResponse);
    }
View Full Code Here


    @Override
    public WriteResponse deleteDatabase() {
        if (featureSet.isTrue(CouchFeature.ALLOW_DB_DELETE)) {
            CouchHttpResponse httpResponse = httpClient.deleteDatabase(databaseName);
            return new WriteResponse(httpResponse);
        } else {
            throw CouchException.forbidden("Deletion of database " + databaseName + " is not allowed. To allow configure with CouchFeature.ALLOW_DB_DELETE.");
        }
    }
View Full Code Here

        if (oneTestDatabase.exists()) {
            oneTestDatabase.deleteDatabase();
        }

        // Here we use "raw" database put and delete for the database create and delete
        WriteResponse writeResponse = oneTestDatabase.put().database().execute();
        assertEquals(writeResponse.getHttpStatus(), CouchHttpStatus.CREATED);

        // Get the database
        GetContentResponse getContentResponse = oneTestDatabase.get().database().execute();
        assertEquals(getContentResponse.getHttpStatus(), CouchHttpStatus.OK);
        assertEquals(getContentResponse.getContentType(), CouchMediaType.APPLICATION_JSON);

        // Delete the database
        WriteResponse deleteResponse = oneTestDatabase.delete().database().execute();
        assertEquals(deleteResponse.getHttpStatus(), CouchHttpStatus.OK);

        // Database should no longer exist.
        getContentResponse = oneTestDatabase.get().database().execute();
        assertEquals(getContentResponse.getHttpStatus(), CouchHttpStatus.NOT_FOUND);
View Full Code Here

        assertEquals(getContentResponse.getHttpStatus(), CouchHttpStatus.NOT_FOUND);

    }

    public void compactDatabaseTest() {
        WriteResponse response = database.post().database("_compact").execute();
        assertEquals(response.getHttpStatus(), CouchHttpStatus.ACCEPTED);
    }
View Full Code Here

        WriteResponse response = database.post().database("_compact").execute();
        assertEquals(response.getHttpStatus(), CouchHttpStatus.ACCEPTED);
    }

    public void viewCleanupDatabaseTest() {
        WriteResponse response = database.post().database("_view_cleanup").execute();
        assertEquals(response.getHttpStatus(), CouchHttpStatus.ACCEPTED);
    }
View Full Code Here

    public void createAndDeleteDocuments() {

        // Create a view
        URL designUrl = getClass().getClassLoader().getResource("design/simple-design.json");
        WriteResponse response = database
                .put()
                .design("simple", designUrl)
                .execute();
        assertEquals(response.getHttpStatus(), CouchHttpStatus.CREATED);
        GetDocumentResponse documentResponse = database
                .get()
                .document("_design/simple")
                .execute();
        assertTrue(documentResponse.isOk(), documentResponse.getErrorReason());
        assertEquals(documentResponse.getDocumentCount(), 1);

        // Create a simple document
        String docId = "707";
        response = database
                .put()
                .document(docId, "{\"direction\" : \"NORTH\",\"city\" : \"Toronto\"}")
                .execute();
        assertTrue(response.isCreated(), response.getErrorReason());
        documentResponse = database
                .get()
                .document(docId)
                .execute();
        assertTrue(documentResponse.isOk(), documentResponse.getErrorReason());
        assertEquals(documentResponse.getDocumentCount(), 1);

        // Get count using built in _all_docs
        documentResponse = database
            .get()
            .document("_all_docs")
            .execute();
        assertTrue(documentResponse.isOk(), documentResponse.getErrorReason());
        assertEquals(documentResponse.getDocumentCount(), 2);
        for (TextDocument doc : documentResponse.getDocumentList()) {
            assertNotNull(doc.getDocumentId());
            assertNotNull(doc.getDocumentRevision());
        }

        // Get count using all view
        CouchViewQuery viewQuery = CouchViewQuery.builder("simple", "all").build();
        documentResponse = database
                .get()
                .document(viewQuery)
                .execute();
        assertTrue(documentResponse.isOk(), documentResponse.getErrorReason());
        assertEquals(documentResponse.getDocumentCount(), 1);

        // Delete all non design
        response = database
                .delete()
                .allNonDesigns()
                .execute();
        assertTrue(response.isOk(), response.getErrorReason());

        // Count should be zero using all view
        documentResponse = database
                .get()
                .document(viewQuery)
                .execute();
        assertTrue(documentResponse.isOk(), documentResponse.getErrorReason());
        assertEquals(documentResponse.getDocumentCount(), 0);

        // Count using _all_docs should be one
        documentResponse = database
            .get()
            .document("_all_docs")
            .execute();
        assertTrue(documentResponse.isOk(), documentResponse.getErrorReason());
        assertEquals(documentResponse.getDocumentCount(), 1);
        for (TextDocument doc : documentResponse.getDocumentList()) {
            assertNotNull(doc.getDocumentId());
            assertNotNull(doc.getDocumentRevision());
        }

        // Create a simple document again
        docId = "909";
        response = database
            .put()
            .document(docId, "{\"direction\" : \"NORTH\",\"city\" : \"Toronto\"}")
            .execute();
        assertTrue(response.isCreated(), response.getErrorReason());
        documentResponse = database
            .get()
            .document(docId)
            .execute();
        assertTrue(documentResponse.isOk(), documentResponse.getErrorReason());
        assertEquals(documentResponse.getDocumentCount(), 1);

        // Count using _all_docs should be two
        documentResponse = database
            .get()
            .document("_all_docs")
            .execute();
        assertTrue(documentResponse.isOk(), documentResponse.getErrorReason());
        assertEquals(documentResponse.getDocumentCount(), 2);
        for (TextDocument doc : documentResponse.getDocumentList()) {
            assertNotNull(doc.getDocumentId());
            assertNotNull(doc.getDocumentRevision());
        }

        // Delete all design
        response = database
            .delete()
            .allDesigns()
            .execute();
        assertTrue(response.isOk(), response.getErrorReason());

        // Count using _all_docs should be one
        documentResponse = database
            .get()
            .document("_all_docs")
            .execute();
        assertTrue(documentResponse.isOk(), documentResponse.getErrorReason());
        assertEquals(documentResponse.getDocumentCount(), 1);
        for (TextDocument doc : documentResponse.getDocumentList()) {
            assertNotNull(doc.getDocumentId());
            assertNotNull(doc.getDocumentRevision());
        }

        // Delete all docs
        response = database
            .delete()
            .allDocuments()
            .execute();
        assertTrue(response.isOk(), response.getErrorReason());

        // Count using _all_docs should be one
        documentResponse = database
            .get()
            .document("_all_docs")
View Full Code Here

        couchDatabase.recreateDatabase();
        assertTrue(couchDatabase.exists());

        // Add the Entity design doc
        URL designUrl = getClass().getClassLoader().getResource("design/entity-design.json");
        WriteResponse response = couchDatabase.put().design("entity", designUrl).execute();
        assertTrue(response.isCreated());

        // Add the Person design doc
        designUrl = getClass().getClassLoader().getResource("design/person-design.json");
        response = couchDatabase.put().design("person", designUrl).execute();
        assertTrue(response.isCreated());

        // Add Pet design doc
        designUrl = getClass().getClassLoader().getResource("design/pet-design.json");
        response = couchDatabase.put().design("pet", designUrl).execute();
        assertTrue(response.isCreated());

        // Add City design doc
        designUrl = getClass().getClassLoader().getResource("design/city-design.json");
        response = couchDatabase.put().design("city", designUrl).execute();
        assertTrue(response.isCreated());

        // Read the image bytes
        try {
            Path path = Paths.get(getClass().getClassLoader().getResource("AceOfSpades.jpg").toURI());
            imageBytes = Files.readAllBytes(path);
View Full Code Here

    @Test
    public void postTest() {

        // Post the document
        WriteResponse response = couchDatabase.post().document(docThreeJson).execute();

        // Verify
        assertNotNull(response.getDocumentId());
        docThreeId = response.getDocumentId();
        assertEquals(response.getHttpStatus(), CouchHttpStatus.CREATED);
        assertTrue(response.isCreated());
        assertNotNull(response.getDocumentRevision());
        assertEquals(response.getMethodType(), CouchMethodType.POST);
        docThreeVersion = response.getDocumentRevision();

        // Get and verify
        GetDocumentResponse docResponse = couchDatabase.get().document(docThreeId).execute();
        assertEquals(docResponse.getHttpStatus(), CouchHttpStatus.OK);
        assertTrue(docResponse.isOk());
View Full Code Here

    @Test
    public void putTest() {

        // Put the document and verify
        WriteResponse putDocResponse = couchDatabase.put().document(attachDocId, attachDocJson).execute();
        assertEquals(putDocResponse.getHttpStatus(), CouchHttpStatus.CREATED);
        assertTrue(putDocResponse.isCreated());
        assertNotNull(putDocResponse.getDocumentRevision());
        assertEquals(putDocResponse.getMethodType(), CouchMethodType.PUT);
        latestRevision = putDocResponse.getDocumentRevision();

        // Put the html attachment and verify
        WriteResponse putAttachResponse = couchDatabase
            .put()
            .attachment(putDocResponse.getDocumentId(),
                putDocResponse.getDocumentRevision(),
                "html",
                CouchMediaType.TEXT_HTML,
                htmlContent)
            .execute();
        assertEquals(putAttachResponse.getHttpStatus(), CouchHttpStatus.CREATED);
        assertTrue(putAttachResponse.isCreated());
        assertNotNull(putAttachResponse.getDocumentRevision());
        assertEquals(putAttachResponse.getMethodType(), CouchMethodType.PUT);
        latestRevision = putAttachResponse.getDocumentRevision();

        // Put the image bytes attachment and verify
        putAttachResponse = couchDatabase
            .put()
            .attachment(putDocResponse.getDocumentId(),
                latestRevision,
                "image",
                CouchMediaType.IMAGE_JPEG,
                aceOfSpacesBytes)
            .execute();
        assertEquals(putAttachResponse.getHttpStatus(), CouchHttpStatus.CREATED);
        assertTrue(putAttachResponse.isCreated());
        assertNotNull(putAttachResponse.getDocumentRevision());
        assertEquals(putAttachResponse.getMethodType(), CouchMethodType.PUT);
        latestRevision = putAttachResponse.getDocumentRevision();

    }
View Full Code Here

    @Test(dependsOnMethods = {"getVersionTest"})
    public void deleteTest() {

        // Delete the attachment
        WriteResponse deleteResponse = couchDatabase
                .delete()
                .attachment(attachDocId, latestRevision, "html")
                .execute();
        assertEquals(deleteResponse.getHttpStatus(), CouchHttpStatus.OK);
        String previousVersion = latestRevision;
        latestRevision = deleteResponse.getDocumentRevision();

        // Get attachment should now return not found
        GetAttachmentResponse response = couchDatabase
                .get()
                .attachment(attachDocId, latestRevision, "html")
View Full Code Here

TOP

Related Classes of com.couchace.core.api.response.WriteResponse

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.