@Test
  public void shouldStoreAndRetrieveJob() throws JobPersistenceException {
    final String jobId = id("fooid");
    JobDetail job =
        newJob(DummyJobListener.class)
            .withIdentity(jobId, "bargroup")
            .usingJobData("foo", "bar")
            .usingJobData("fuu", "baz")
            .build();
    couchdbStore.storeJob(job, false);

    assertNull(couchdbStore.retrieveJob(JobKey.jobKey("something", "something")));
    assertEquals(
        "bar",
        couchdbStore.retrieveJob(JobKey.jobKey(jobId, "bargroup")).getJobDataMap().get("foo"));
  }
  @Test
  public void shouldDeleteExistingJobs() throws JobPersistenceException {
    final String job1Id = id("fooid1");
    JobDetail job1 = newJob(DummyJobListener.class).withIdentity(job1Id, "bargroup1").build();
    final String job2Id = id("fooid2");
    JobDetail job2 = newJob(DummyJobListener.class).withIdentity(job2Id, "bargroup2").build();
    final String job3Id = id("fooid3");
    JobDetail job3 = newJob(DummyJobListener.class).withIdentity(job3Id, "bargroup2").build();

    couchdbStore.storeJob(job1, false);
    couchdbStore.storeJob(job2, false);
    couchdbStore.storeJob(job3, false);

    couchdbStore.removeJobs(
        asList(JobKey.jobKey(job1Id, "bargroup1"), JobKey.jobKey(job2Id, "bargroup2")));

    assertNull(couchdbStore.retrieveJob(JobKey.jobKey(job1Id, "bargroup1")));
    assertNull(couchdbStore.retrieveJob(JobKey.jobKey(job2Id, "bargroup2")));
    assertNotNull(couchdbStore.retrieveJob(JobKey.jobKey(job3Id, "bargroup2")));
  }
  @Test
  public void shouldDeleteExistingJob() throws JobPersistenceException {
    final String jobId = id("fooid");
    JobDetail job =
        newJob(DummyJobListener.class)
            .withIdentity(jobId, "bargroup")
            .usingJobData("foo", "bar")
            .build();
    couchdbStore.storeJob(job, false);

    couchdbStore.removeJob(JobKey.jobKey(jobId, "bargroup"));
    assertNull(couchdbStore.retrieveJob(JobKey.jobKey(jobId, "bargroup")));
  }
  @Test(expected = ObjectAlreadyExistsException.class)
  public void shouldNotUpdateExistingJob() throws JobPersistenceException {
    JobDetail job =
        newJob(DummyJobListener.class)
            .withIdentity("fooid", "bargroup")
            .usingJobData("foo", "bar")
            .build();
    couchdbStore.storeJob(job, false);

    JobDetail newJob =
        newJob(DummyJobListener.class)
            .withIdentity("fooid", "bargroup")
            .usingJobData("fii", "bur")
            .build();
    couchdbStore.storeJob(newJob, false);

    assertNull(
        couchdbStore.retrieveJob(JobKey.jobKey("fooid", "bargroup")).getJobDataMap().get("fii"));
  }
  @Test
  public void shouldUpdateExistingJob() throws JobPersistenceException {
    final String jobId = id("fooid");
    JobDetail job =
        newJob(DummyJobListener.class)
            .withIdentity(jobId, "bargroup")
            .usingJobData("foo", "bar")
            .build();
    couchdbStore.storeJob(job, false);

    JobDetail newJob =
        newJob(DummyJobListener.class)
            .withIdentity(jobId, "bargroup")
            .usingJobData("fii", "bur")
            .build();
    couchdbStore.storeJob(newJob, true);

    assertEquals(
        "bur",
        couchdbStore.retrieveJob(JobKey.jobKey(jobId, "bargroup")).getJobDataMap().get("fii"));
  }