Search in sources :

Example 1 with PDFIndexerWrapper

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();
    }
}
Also used : IndexDocument(org.wso2.carbon.registry.indexing.solr.IndexDocument) PDFIndexerWrapper(org.wso2.carbon.apimgt.impl.indexing.indexer.util.PDFIndexerWrapper) PDFParser(org.apache.pdfbox.pdfparser.PDFParser) PDDocument(org.apache.pdfbox.pdmodel.PDDocument) COSDocument(org.apache.pdfbox.cos.COSDocument) PDFTextStripper(org.apache.pdfbox.text.PDFTextStripper) Test(org.junit.Test)

Aggregations

COSDocument (org.apache.pdfbox.cos.COSDocument)1 PDFParser (org.apache.pdfbox.pdfparser.PDFParser)1 PDDocument (org.apache.pdfbox.pdmodel.PDDocument)1 PDFTextStripper (org.apache.pdfbox.text.PDFTextStripper)1 Test (org.junit.Test)1 PDFIndexerWrapper (org.wso2.carbon.apimgt.impl.indexing.indexer.util.PDFIndexerWrapper)1 IndexDocument (org.wso2.carbon.registry.indexing.solr.IndexDocument)1