Package com.couchace.core.api.response

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


        assertEquals(foundSpeakAction.getSaid(), speakAction.getSaid());
        assertNotNull(foundSpeakAction.getRevision(), "Revision is null");

        // Update speak action.
        foundSpeakAction.setSaid("Goodbye");
        WriteResponse putResponse = couchDatabase
            .put()
            .entity(foundSpeakAction)
            .execute();
        assertEquals(putResponse.getDocumentId(), "Action:" + foundSpeakAction.getId());
        assertEquals(putResponse.getHttpStatus(), CouchHttpStatus.CREATED);
        assertNotNull(putResponse.getDocumentRevision());

        // Get and ensure said was updated.
        foundSpeakAction = couchDatabase
            .get()
            .entity(SpeakActionEntity.class, "Action:" + foundSpeakAction.getId())
            .execute()
            .getFirstEntity();
        assertEquals(foundSpeakAction.getSaid(), "Goodbye");
        assertEquals(foundSpeakAction.getRevision(), putResponse.getDocumentRevision());

        // Should be the same if searching by ActionEntity
        ActionEntity actionEntity = couchDatabase
            .get()
            .entity(ActionEntity.class, "Action:" + foundSpeakAction.getId())
            .execute()
            .getFirstEntity();
        assertEquals(actionEntity.getClass(), SpeakActionEntity.class);
        assertEquals(actionEntity.getRevision(), putResponse.getDocumentRevision());
        assertEquals(((SpeakActionEntity)actionEntity).getSaid(), "Goodbye");


    }
View Full Code Here


    private String newId() {
        return String.valueOf(nextId++);
    }

    private WriteResponse putAction(ActionEntity actionEntity) {
        WriteResponse putResponse = couchDatabase
            .put()
            .entity(actionEntity)
            .execute();
        assertEquals(putResponse.getDocumentId(), "Action:" + actionEntity.getId());
        assertEquals(putResponse.getHttpStatus(), CouchHttpStatus.CREATED);
        assertNotNull(putResponse.getDocumentRevision());

        actions.add(actionEntity);

        return putResponse;
    }
View Full Code Here

            .getFirstContentAsLong();

        // Add a vehicle
        String firebirdId = "99";
        VehicleEntity firebird = VehicleEntity.newVehicle(firebirdId, VehicleType.CAR, "Pontiac", "Firebird", "1969", "Black");
        WriteResponse putResponse = couchDatabase
            .put()
            .entity(firebird)
            .execute();
        assertEquals(putResponse.getDocumentId(), firebirdId);
        assertEquals(putResponse.getHttpStatus(), CouchHttpStatus.CREATED);
        assertNotNull(putResponse.getDocumentRevision());

        // Check count
        long newVehicleCount = couchDatabase
            .get()
            .document(couchViewQuery)
            .execute()
            .getFirstContentAsLong();
        assertEquals(newVehicleCount, initialVehicleCount + 1);

        // Retrieve the vehicle we just added.
        VehicleEntity foundFirebird = couchDatabase
            .get()
            .entity(VehicleEntity.class, firebirdId)
            .execute()
            .getFirstEntity();

        assertEquals(foundFirebird.getId(), firebird.getId());
        assertEquals(foundFirebird.getRevision(), putResponse.getDocumentRevision());
        assertEquals(foundFirebird.getVehicleType(), firebird.getVehicleType());
        assertEquals(foundFirebird.getMake(), firebird.getMake());
        assertEquals(foundFirebird.getModel(), firebird.getModel());
        assertEquals(foundFirebird.getYear(), firebird.getYear());
        assertEquals(foundFirebird.getColor(), firebird.getColor());

        // Retrieve the raw document and ensure the id is not part of the entity body.
        GetDocumentResponse response = couchDatabase
                .get()
                .document(firebirdId)
                .execute();
        TextDocument textDocument = response.getFirstDocument();
        String content = textDocument.getContent();
        ObjectMapper objectMapper = new ObjectMapper();
        Map map = objectMapper.readValue(content, Map.class);
        Map entity = (Map) map.get("entity");
        assertFalse(entity.containsKey("id"), "The entity body stored in couch contains the id.");

        // Change color to blue and update
        foundFirebird.setColor("Green");
        putResponse = couchDatabase
            .put()
            .entity(foundFirebird)
            .execute();
        assertEquals(putResponse.getDocumentId(), firebirdId);
        assertEquals(putResponse.getHttpStatus(), CouchHttpStatus.CREATED);
        assertNotNull(putResponse.getDocumentRevision());

        // Get and ensure color was updated.
        foundFirebird = couchDatabase
            .get()
            .entity(VehicleEntity.class, firebirdId)
            .execute()
            .getFirstEntity();
        assertEquals(foundFirebird.getColor(), "Green");
        assertEquals(foundFirebird.getRevision(), putResponse.getDocumentRevision());
    }
View Full Code Here

    }

    @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

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.