@Test(expectedExceptions = ExportImportException.class) public void testCreatePartialImportError() throws Exception { when(restTemplate.postForObject(eq(PartialMdExportToken.URI), any(PartialMdExportToken.class), eq(UriResponse.class), eq(PROJECT_ID))) .thenThrow(new GoodDataRestException(400, "request", "Failed", "import", "error")); service.partialImport(project, new PartialMdExportToken("TOKEN123")); }
public FutureResult<Void> partialImport(Project project, PartialMdExportToken mdExportToken) { notNull(project, "project"); notNull(project.getId(), "project.id"); notNull(mdExportToken, "mdExportToken"); final UriResponse importResponse; try { importResponse = restTemplate.postForObject(PartialMdExportToken.URI, mdExportToken, UriResponse.class, project.getId()); } catch (GoodDataRestException | RestClientException e) { throw new ExportImportException("Unable to import partial metadata to project '" + project.getId() + "' with token '" + mdExportToken.getToken() + "'.", e); } return new PollResult<>(this, new AbstractPollHandler<TaskStatus, Void>(notNullState(importResponse, "partial import response").getUri(), TaskStatus.class, Void.class) { @Override public void handlePollResult(TaskStatus pollResult) { if (!pollResult.isSuccess()) { throw new ExportImportException("Partial metadata import failed with errors: " + pollResult.getMessages()); } setResult(null); } @Override public void handlePollException(GoodDataRestException e) { throw new ExportImportException("Unable to import partial metadata.", e); } }); }
ExportImportService extends AbstractService { public FutureResult<Void> partialImport(Project project, PartialMdExportToken mdExportToken) { notNull(project, "project"); notNull(project.getId(), "project.id"); notNull(mdExportToken, "mdExportToken"); final UriResponse importResponse; try { importResponse = restTemplate.postForObject(PartialMdExportToken.URI, mdExportToken, UriResponse.class, project.getId()); } catch (GoodDataRestException | RestClientException e) { throw new ExportImportException("Unable to import partial metadata to project '" + project.getId() + "' with token '" + mdExportToken.getToken() + "'.", e); } return new PollResult<>(this, new AbstractPollHandler<TaskStatus, Void>(notNullState(importResponse, "partial import response").getUri(), TaskStatus.class, Void.class) { @Override public void handlePollResult(TaskStatus pollResult) { if (!pollResult.isSuccess()) { throw new ExportImportException("Partial metadata import failed with errors: " + pollResult.getMessages()); } setResult(null); } @Override public void handlePollException(GoodDataRestException e) { throw new ExportImportException("Unable to import partial metadata.", e); } }); } }
ExportImportService extends AbstractService { public FutureResult<Void> partialImport(Project project, PartialMdExportToken mdExportToken) { notNull(project, "project"); notNull(project.getId(), "project.id"); notNull(mdExportToken, "mdExportToken"); final UriResponse importResponse; try { importResponse = restTemplate.postForObject(PartialMdExportToken.URI, mdExportToken, UriResponse.class, project.getId()); } catch (GoodDataRestException | RestClientException e) { throw new ExportImportException("Unable to import partial metadata to project '" + project.getId() + "' with token '" + mdExportToken.getToken() + "'.", e); } return new PollResult<>(this, new AbstractPollHandler<TaskStatus, Void>(notNullState(importResponse, "partial import response").getUri(), TaskStatus.class, Void.class) { @Override public void handlePollResult(TaskStatus pollResult) { if (!pollResult.isSuccess()) { throw new ExportImportException("Partial metadata import failed with errors: " + pollResult.getMessages()); } setResult(null); } @Override public void handlePollException(GoodDataRestException e) { throw new ExportImportException("Unable to import partial metadata.", e); } }); } ExportImportService(final RestTemplate restTemplate, final GoodDataSettings settings); }
ExportImportService extends AbstractService { public FutureResult<Void> partialImport(Project project, PartialMdExportToken mdExportToken) { notNull(project, "project"); notNull(project.getId(), "project.id"); notNull(mdExportToken, "mdExportToken"); final UriResponse importResponse; try { importResponse = restTemplate.postForObject(PartialMdExportToken.URI, mdExportToken, UriResponse.class, project.getId()); } catch (GoodDataRestException | RestClientException e) { throw new ExportImportException("Unable to import partial metadata to project '" + project.getId() + "' with token '" + mdExportToken.getToken() + "'.", e); } return new PollResult<>(this, new AbstractPollHandler<TaskStatus, Void>(notNullState(importResponse, "partial import response").getUri(), TaskStatus.class, Void.class) { @Override public void handlePollResult(TaskStatus pollResult) { if (!pollResult.isSuccess()) { throw new ExportImportException("Partial metadata import failed with errors: " + pollResult.getMessages()); } setResult(null); } @Override public void handlePollException(GoodDataRestException e) { throw new ExportImportException("Unable to import partial metadata.", e); } }); } ExportImportService(final RestTemplate restTemplate, final GoodDataSettings settings); FutureResult<PartialMdExportToken> partialExport(Project project, final PartialMdExport export); FutureResult<Void> partialImport(Project project, PartialMdExportToken mdExportToken); }
ExportImportService extends AbstractService { public FutureResult<Void> partialImport(Project project, PartialMdExportToken mdExportToken) { notNull(project, "project"); notNull(project.getId(), "project.id"); notNull(mdExportToken, "mdExportToken"); final UriResponse importResponse; try { importResponse = restTemplate.postForObject(PartialMdExportToken.URI, mdExportToken, UriResponse.class, project.getId()); } catch (GoodDataRestException | RestClientException e) { throw new ExportImportException("Unable to import partial metadata to project '" + project.getId() + "' with token '" + mdExportToken.getToken() + "'.", e); } return new PollResult<>(this, new AbstractPollHandler<TaskStatus, Void>(notNullState(importResponse, "partial import response").getUri(), TaskStatus.class, Void.class) { @Override public void handlePollResult(TaskStatus pollResult) { if (!pollResult.isSuccess()) { throw new ExportImportException("Partial metadata import failed with errors: " + pollResult.getMessages()); } setResult(null); } @Override public void handlePollException(GoodDataRestException e) { throw new ExportImportException("Unable to import partial metadata.", e); } }); } ExportImportService(final RestTemplate restTemplate, final GoodDataSettings settings); FutureResult<PartialMdExportToken> partialExport(Project project, final PartialMdExport export); FutureResult<Void> partialImport(Project project, PartialMdExportToken mdExportToken);  }