Search in sources :

Example 1 with ComponentNotFoundException

use of org.lastaflute.di.core.exception.ComponentNotFoundException in project fess by codelibs.

the class FessXpathTransformerTest method test_canonicalXpath.

public void test_canonicalXpath() throws Exception {
    final FessXpathTransformer transformer = new FessXpathTransformer();
    transformer.init();
    final Map<String, Object> dataMap = new HashMap<String, Object>();
    final ResponseData responseData = new ResponseData();
    responseData.setUrl("http://example.com/");
    String data = "<html><body>aaa</body></html>";
    Document document = getDocument(data);
    try {
        transformer.putAdditionalData(dataMap, responseData, document);
        fail();
    } catch (final ComponentNotFoundException e) {
    // ignore
    }
    data = "<html><head><link rel=\"canonical\" href=\"http://example.com/\"></head><body>aaa</body></html>";
    document = getDocument(data);
    try {
        transformer.putAdditionalData(dataMap, responseData, document);
        fail();
    } catch (final ComponentNotFoundException e) {
    // ignore
    }
    data = "<html><head><link rel=\"canonical\" href=\"http://example.com/foo\"></head><body>aaa</body></html>";
    document = getDocument(data);
    try {
        transformer.putAdditionalData(dataMap, responseData, document);
        fail();
    } catch (final ChildUrlsException e) {
        final Set<RequestData> childUrlList = e.getChildUrlList();
        assertEquals(1, childUrlList.size());
        assertEquals("http://example.com/foo", childUrlList.iterator().next().getUrl());
    }
    data = "<html><link rel=\"canonical\" href=\"http://example.com/foo\"><body>aaa</body></html>";
    document = getDocument(data);
    try {
        transformer.putAdditionalData(dataMap, responseData, document);
        fail();
    } catch (final ChildUrlsException e) {
        final Set<RequestData> childUrlList = e.getChildUrlList();
        assertEquals(1, childUrlList.size());
        assertEquals("http://example.com/foo", childUrlList.iterator().next().getUrl());
    }
}
Also used : ChildUrlsException(org.codelibs.fess.crawler.exception.ChildUrlsException) Set(java.util.Set) ComponentNotFoundException(org.lastaflute.di.core.exception.ComponentNotFoundException) HashMap(java.util.HashMap) ResponseData(org.codelibs.fess.crawler.entity.ResponseData) Document(org.w3c.dom.Document)

Aggregations

HashMap (java.util.HashMap)1 Set (java.util.Set)1 ResponseData (org.codelibs.fess.crawler.entity.ResponseData)1 ChildUrlsException (org.codelibs.fess.crawler.exception.ChildUrlsException)1 ComponentNotFoundException (org.lastaflute.di.core.exception.ComponentNotFoundException)1 Document (org.w3c.dom.Document)1