use of org.springframework.cloud.gcp.storage.GoogleStorageLocation in project spring-cloud-gcp by spring-cloud.
the class DocumentOcrTemplateIntegrationTests method testDocumentOcrTemplate.
@Test
public void testDocumentOcrTemplate() throws ExecutionException, InterruptedException, InvalidProtocolBufferException, TimeoutException {
GoogleStorageLocation document = GoogleStorageLocation.forFile("vision-integration-test-bucket", "test.pdf");
GoogleStorageLocation outputLocationPrefix = GoogleStorageLocation.forFile("vision-integration-test-bucket", "it_output/test-");
ListenableFuture<DocumentOcrResultSet> result = this.documentOcrTemplate.runOcrForDocument(document, outputLocationPrefix);
DocumentOcrResultSet ocrPages = result.get(5, TimeUnit.MINUTES);
String page1Text = ocrPages.getPage(1).getText();
assertThat(page1Text).contains("Hello World. Is mayonnaise an instrument?");
String page2Text = ocrPages.getPage(2).getText();
assertThat(page2Text).contains("Page 2 stuff");
ArrayList<String> pageContent = new ArrayList<>();
Iterator<TextAnnotation> pageIterator = ocrPages.getAllPages();
while (pageIterator.hasNext()) {
pageContent.add(pageIterator.next().getText());
}
assertThat(pageContent).containsExactly("Hello World. Is mayonnaise an instrument?\n", "Page 2 stuff\n", "Page 3 stuff\n", "Page 4 stuff\n");
}
Aggregations