コード例 #1
0
  // Test case for issue #31
  @Test
  public void customGsonDeserializerTest() {
    Map<String, Object> h = new HashMap<String, Object>();
    h.put("_id", "serializertest");
    h.put("date", "2015-01-23T18:25:43.511Z");
    db.save(h);

    GsonBuilder builder = new GsonBuilder();
    builder.setDateFormat("yyyy-MM-dd'T'HH:mm:ss");
    account.setGsonBuilder(builder);

    db.find(Foo.class, "serializertest"); // should not throw a JsonSyntaxException
  }
コード例 #2
0
  public static void main(String[] args) {
    CloudantClient client =
        new CloudantClient("http://username.cloudant.com", "username", "password");
    Database db = client.database("java-searchindex", false);

    Map<String, Object> animals = new HashMap<>();
    animals.put("index", "function(doc){ index(\"default\", doc._id); }");

    Map<String, Object> indexes = new HashMap<>();
    indexes.put("animals", animals);

    Map<String, Object> ddoc = new HashMap<>();
    ddoc.put("_id", "_design/searchindex");
    ddoc.put("indexes", indexes);

    db.save(ddoc);
  }
コード例 #3
0
  @Test
  @Category(RequiresCloudant.class)
  public void QuorumTests() {

    db.save(new Animal("human"), 2);
    Animal h =
        db.find(Animal.class, "human", new com.cloudant.client.api.model.Params().readQuorum(2));
    assertNotNull(h);
    assertEquals("human", h.getId());

    db.update(h.setClass("inhuman"), 2);
    h = db.find(Animal.class, "human", new com.cloudant.client.api.model.Params().readQuorum(2));
    assertEquals("inhuman", h.getclass());

    db.post(new Animal("test"), 2);
    h = db.find(Animal.class, "test", new com.cloudant.client.api.model.Params().readQuorum(3));
    assertEquals("test", h.getId());
  }