@Test(expected = AlreadyExistsException.class) public void testScheduleHarvestAlreadyExists() throws AlreadyExistsException, DoesNotExistException, MissingArgumentsException { Mockito.when(response.getStatus()).thenReturn(409); Mockito.when(response.readEntity(Result.class)).thenReturn(new Result("Already exist!")); ha.scheduleHarvest("ds0", Calendar.getInstance(), Frequency.WEEKLY, 10, false); }
public void scheduleHarvest(String id, Calendar firstDateTime, Frequency frequency, int xmonths, boolean incremental) throws DoesNotExistException, MissingArgumentsException, AlreadyExistsException { WebTarget target = client.target( restUrl + "/" + DatasetOptionListContainer.DATASETS + "/" + id + "/" + HarvestOptionListContainer.HARVEST + "/" + HarvestOptionListContainer.SCHEDULE) .queryParam(HarvestOptionListContainer.INCREMENTAL, incremental); ScheduledTask scheduledTask = new ScheduledTask(); scheduledTask.setFirstRun(firstDateTime); scheduledTask.setFrequency(frequency); scheduledTask.setXmonths(new Integer(xmonths)); Response response = target.request(MediaType.APPLICATION_JSON).post( Entity.entity(scheduledTask, MediaType.APPLICATION_JSON), Response.class); switch (response.getStatus()) { case 404: Result errorMessage = response.readEntity(Result.class); LOGGER.warn("scheduleHarvest(..) failure! : " + errorMessage.getResult()); throw new DoesNotExistException(errorMessage.getResult()); case 406: errorMessage = response.readEntity(Result.class); LOGGER.warn("scheduleHarvest(..) failure! : " + errorMessage.getResult()); throw new MissingArgumentsException(errorMessage.getResult()); case 409: errorMessage = response.readEntity(Result.class); LOGGER.warn("scheduleHarvest(..) failure! : " + errorMessage.getResult()); throw new AlreadyExistsException(errorMessage.getResult()); case 500: errorMessage = response.readEntity(Result.class); LOGGER.warn("scheduleHarvest(..) failure! : " + errorMessage.getResult()); throw new InternalServerErrorException(errorMessage.getResult()); } LOGGER.info("scheduleHarvest(..) success!"); }
HarvestAccessor { public void scheduleHarvest(String id, Calendar firstDateTime, Frequency frequency, int xmonths, boolean incremental) throws DoesNotExistException, MissingArgumentsException, AlreadyExistsException { WebTarget target = client.target( restUrl + "/" + DatasetOptionListContainer.DATASETS + "/" + id + "/" + HarvestOptionListContainer.HARVEST + "/" + HarvestOptionListContainer.SCHEDULE) .queryParam(HarvestOptionListContainer.INCREMENTAL, incremental); ScheduledTask scheduledTask = new ScheduledTask(); scheduledTask.setFirstRun(firstDateTime); scheduledTask.setFrequency(frequency); scheduledTask.setXmonths(new Integer(xmonths)); Response response = target.request(MediaType.APPLICATION_JSON).post( Entity.entity(scheduledTask, MediaType.APPLICATION_JSON), Response.class); switch (response.getStatus()) { case 404: Result errorMessage = response.readEntity(Result.class); LOGGER.warn("scheduleHarvest(..) failure! : " + errorMessage.getResult()); throw new DoesNotExistException(errorMessage.getResult()); case 406: errorMessage = response.readEntity(Result.class); LOGGER.warn("scheduleHarvest(..) failure! : " + errorMessage.getResult()); throw new MissingArgumentsException(errorMessage.getResult()); case 409: errorMessage = response.readEntity(Result.class); LOGGER.warn("scheduleHarvest(..) failure! : " + errorMessage.getResult()); throw new AlreadyExistsException(errorMessage.getResult()); case 500: errorMessage = response.readEntity(Result.class); LOGGER.warn("scheduleHarvest(..) failure! : " + errorMessage.getResult()); throw new InternalServerErrorException(errorMessage.getResult()); } LOGGER.info("scheduleHarvest(..) success!"); } }
HarvestAccessor { public void scheduleHarvest(String id, Calendar firstDateTime, Frequency frequency, int xmonths, boolean incremental) throws DoesNotExistException, MissingArgumentsException, AlreadyExistsException { WebTarget target = client.target( restUrl + "/" + DatasetOptionListContainer.DATASETS + "/" + id + "/" + HarvestOptionListContainer.HARVEST + "/" + HarvestOptionListContainer.SCHEDULE) .queryParam(HarvestOptionListContainer.INCREMENTAL, incremental); ScheduledTask scheduledTask = new ScheduledTask(); scheduledTask.setFirstRun(firstDateTime); scheduledTask.setFrequency(frequency); scheduledTask.setXmonths(new Integer(xmonths)); Response response = target.request(MediaType.APPLICATION_JSON).post( Entity.entity(scheduledTask, MediaType.APPLICATION_JSON), Response.class); switch (response.getStatus()) { case 404: Result errorMessage = response.readEntity(Result.class); LOGGER.warn("scheduleHarvest(..) failure! : " + errorMessage.getResult()); throw new DoesNotExistException(errorMessage.getResult()); case 406: errorMessage = response.readEntity(Result.class); LOGGER.warn("scheduleHarvest(..) failure! : " + errorMessage.getResult()); throw new MissingArgumentsException(errorMessage.getResult()); case 409: errorMessage = response.readEntity(Result.class); LOGGER.warn("scheduleHarvest(..) failure! : " + errorMessage.getResult()); throw new AlreadyExistsException(errorMessage.getResult()); case 500: errorMessage = response.readEntity(Result.class); LOGGER.warn("scheduleHarvest(..) failure! : " + errorMessage.getResult()); throw new InternalServerErrorException(errorMessage.getResult()); } LOGGER.info("scheduleHarvest(..) success!"); } HarvestAccessor(URL restUrl, String username, String password);   HarvestAccessor(URL restUrl, String username, String password, Client client); }
HarvestAccessor { public void scheduleHarvest(String id, Calendar firstDateTime, Frequency frequency, int xmonths, boolean incremental) throws DoesNotExistException, MissingArgumentsException, AlreadyExistsException { WebTarget target = client.target( restUrl + "/" + DatasetOptionListContainer.DATASETS + "/" + id + "/" + HarvestOptionListContainer.HARVEST + "/" + HarvestOptionListContainer.SCHEDULE) .queryParam(HarvestOptionListContainer.INCREMENTAL, incremental); ScheduledTask scheduledTask = new ScheduledTask(); scheduledTask.setFirstRun(firstDateTime); scheduledTask.setFrequency(frequency); scheduledTask.setXmonths(new Integer(xmonths)); Response response = target.request(MediaType.APPLICATION_JSON).post( Entity.entity(scheduledTask, MediaType.APPLICATION_JSON), Response.class); switch (response.getStatus()) { case 404: Result errorMessage = response.readEntity(Result.class); LOGGER.warn("scheduleHarvest(..) failure! : " + errorMessage.getResult()); throw new DoesNotExistException(errorMessage.getResult()); case 406: errorMessage = response.readEntity(Result.class); LOGGER.warn("scheduleHarvest(..) failure! : " + errorMessage.getResult()); throw new MissingArgumentsException(errorMessage.getResult()); case 409: errorMessage = response.readEntity(Result.class); LOGGER.warn("scheduleHarvest(..) failure! : " + errorMessage.getResult()); throw new AlreadyExistsException(errorMessage.getResult()); case 500: errorMessage = response.readEntity(Result.class); LOGGER.warn("scheduleHarvest(..) failure! : " + errorMessage.getResult()); throw new InternalServerErrorException(errorMessage.getResult()); } LOGGER.info("scheduleHarvest(..) success!"); } HarvestAccessor(URL restUrl, String username, String password);   HarvestAccessor(URL restUrl, String username, String password, Client client); void startHarvest(String id, String type); void cancelHarvest(String id); void scheduleHarvest(String id, Calendar firstDateTime, Frequency frequency, int xmonths,
      boolean incremental); void deleteScheduledTask(String id, String taskId); List<ScheduledTask> getDatasetScheduledTasks(String id); String getDatasetHarvestingStatus(String id); String getDatasetLastIngestLog(String id); List<Task> getCurrentHarvestsList(); }
HarvestAccessor { public void scheduleHarvest(String id, Calendar firstDateTime, Frequency frequency, int xmonths, boolean incremental) throws DoesNotExistException, MissingArgumentsException, AlreadyExistsException { WebTarget target = client.target( restUrl + "/" + DatasetOptionListContainer.DATASETS + "/" + id + "/" + HarvestOptionListContainer.HARVEST + "/" + HarvestOptionListContainer.SCHEDULE) .queryParam(HarvestOptionListContainer.INCREMENTAL, incremental); ScheduledTask scheduledTask = new ScheduledTask(); scheduledTask.setFirstRun(firstDateTime); scheduledTask.setFrequency(frequency); scheduledTask.setXmonths(new Integer(xmonths)); Response response = target.request(MediaType.APPLICATION_JSON).post( Entity.entity(scheduledTask, MediaType.APPLICATION_JSON), Response.class); switch (response.getStatus()) { case 404: Result errorMessage = response.readEntity(Result.class); LOGGER.warn("scheduleHarvest(..) failure! : " + errorMessage.getResult()); throw new DoesNotExistException(errorMessage.getResult()); case 406: errorMessage = response.readEntity(Result.class); LOGGER.warn("scheduleHarvest(..) failure! : " + errorMessage.getResult()); throw new MissingArgumentsException(errorMessage.getResult()); case 409: errorMessage = response.readEntity(Result.class); LOGGER.warn("scheduleHarvest(..) failure! : " + errorMessage.getResult()); throw new AlreadyExistsException(errorMessage.getResult()); case 500: errorMessage = response.readEntity(Result.class); LOGGER.warn("scheduleHarvest(..) failure! : " + errorMessage.getResult()); throw new InternalServerErrorException(errorMessage.getResult()); } LOGGER.info("scheduleHarvest(..) success!"); } HarvestAccessor(URL restUrl, String username, String password);   HarvestAccessor(URL restUrl, String username, String password, Client client); void startHarvest(String id, String type); void cancelHarvest(String id); void scheduleHarvest(String id, Calendar firstDateTime, Frequency frequency, int xmonths,
      boolean incremental); void deleteScheduledTask(String id, String taskId); List<ScheduledTask> getDatasetScheduledTasks(String id); String getDatasetHarvestingStatus(String id); String getDatasetLastIngestLog(String id); List<Task> getCurrentHarvestsList();  }