use of org.wso2.carbon.apimgt.impl.indexing.indexer.util.PDFIndexerWrapper in project carbon-apimgt by wso2.
the class PDFIndexerTest method testShouldReturnIndexedDocumentWhenParameterCorrect.
@Test
public void testShouldReturnIndexedDocumentWhenParameterCorrect() throws IOException {
String mediaType = "application/pdf+test";
final String MEDIA_TYPE = "mediaType";
PDFParser parser = Mockito.mock(PDFParser.class);
COSDocument cosDoc = Mockito.mock(COSDocument.class);
PDFTextStripper pdfTextStripper = Mockito.mock(PDFTextStripper.class);
Mockito.doThrow(IOException.class).when(cosDoc).close();
Mockito.when(parser.getDocument()).thenReturn(new COSDocument()).thenReturn(cosDoc);
Mockito.when(pdfTextStripper.getText(new PDDocument())).thenReturn("");
PDFIndexer pdfIndexer = new PDFIndexerWrapper(parser, pdfTextStripper);
// should return the default media type when media type is not defined in file2Index
IndexDocument pdf = pdfIndexer.getIndexedDocument(file2Index);
if (!"application/pdf".equals(pdf.getFields().get(MEDIA_TYPE).get(0))) {
Assert.fail();
}
// should return the media type we have set in the file2Index even if error occurs in finally block
file2Index.mediaType = mediaType;
pdf = pdfIndexer.getIndexedDocument(file2Index);
if (!mediaType.equals(pdf.getFields().get(MEDIA_TYPE).get(0))) {
Assert.fail();
}
}
Aggregations