Beispiel #1
0
  public static void removeReplicatorTestDoc(CloudantClient account, String replicatorDocId)
      throws Exception {

    // Grab replicator doc revision using HTTP HEAD command
    String replicatorDb = "_replicator";
    URI uri = URI.create(account.getBaseUri() + replicatorDb + "/" + replicatorDocId);
    HttpConnection head = Http.HEAD(uri);

    // add a response interceptor to allow us to retrieve the ETag revision header
    final AtomicReference<String> revisionRef = new AtomicReference<String>();
    head.responseInterceptors.add(
        new HttpConnectionResponseInterceptor() {

          @Override
          public HttpConnectionInterceptorContext interceptResponse(
              HttpConnectionInterceptorContext context) {
            revisionRef.set(context.connection.getConnection().getHeaderField("ETag"));
            return context;
          }
        });

    account.executeRequest(head);
    String revision = revisionRef.get();
    assertNotNull("The revision should not be null", revision);
    Database replicator = account.database(replicatorDb, false);
    Response removeResponse = replicator.remove(replicatorDocId, revision.replaceAll("\"", ""));

    assertThat(removeResponse.getError(), is(nullValue()));
  }
 @Before
 public void setUp() {
   account = CloudantClientHelper.getClient();
   // replciate the animals db for search tests
   com.cloudant.client.api.Replication r = account.replication();
   r.source("https://examples.cloudant.com/animaldb");
   r.createTarget(true);
   r.target(CloudantClientHelper.SERVER_URI.toString() + "/animaldb");
   r.trigger();
   db = account.database("animaldb", false);
 }
 public Database getDatabase() {
   if (cloudantClient == null) {
     try {
       cloudantClient = new CloudantClient(dbHost, dbUser, dbPassword);
     } catch (Exception e) {
       // TODO: handle exception
     }
   }
   if (db == null) {
     try {
       db = cloudantClient.database(dbName, true);
     } catch (Exception e) {
       // TODO: handle exception
     }
   }
   return db;
 }
  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);
  }