Exemplo n.º 1
0
  @Test
  public void testNoIdsInSourceXml() {
    IResource xml = resourceLocator.getFirst("/xml/carrot2-no-ids.xml");

    processingAttributes.put(AttributeUtils.getKey(XmlDocumentSource.class, "xml"), xml);
    final int documentCount = runQuery();
    assertEquals(2, documentCount);
    assertEquals(Lists.newArrayList(0, 1), Lists.transform(getDocuments(), DOCUMENT_TO_INT_ID));
  }
Exemplo n.º 2
0
 private void assertTransformedDocumentsEqual(final int documentCount) {
   assertEquals(2, documentCount);
   assertEquals("xslt test", resultAttributes.get(AttributeNames.QUERY));
   assertEquals(
       Lists.newArrayList(498967, 831478), Lists.transform(getDocuments(), DOCUMENT_TO_INT_ID));
   assertEquals(
       Lists.newArrayList("IBM's MARS Block Cipher.", "IBM WebSphere Studio Device Developer"),
       Lists.transform(getDocuments(), DOCUMENT_TO_TITLE));
   assertEquals(
       Lists.newArrayList(
           "The company's AES proposal using 128 bit blocks.",
           "An integrated development environment."),
       Lists.transform(getDocuments(), DOCUMENT_TO_SUMMARY));
   assertEquals(
       Lists.newArrayList(
           "http://www.research.ibm.com/security/mars.html",
           "http://www-3.ibm.com/software/wireless/wsdd/"),
       Lists.transform(getDocuments(), DOCUMENT_TO_CONTENT_URL));
 }
Exemplo n.º 3
0
  @Test
  public void testOverridingInitializationTimeXslt() {
    IResource initXslt = resourceLocator.getFirst("/xsl/carrot2-identity.xsl");
    initAttributes.put(AttributeUtils.getKey(XmlDocumentSource.class, "xslt"), initXslt);

    @SuppressWarnings("unchecked")
    Controller controller = getCachingController(initAttributes);

    // Run with identity XSLT
    {
      IResource xml = resourceLocator.getFirst("/xml/carrot2-test.xml");
      processingAttributes.put(AttributeUtils.getKey(XmlDocumentSource.class, "xml"), xml);

      final int documentCount = runQuery(controller);
      assertEquals(2, documentCount);
      assertEquals(
          Lists.newArrayList("Title 0", "Title 1"),
          Lists.transform(getDocuments(), DOCUMENT_TO_TITLE));
      assertEquals(
          Lists.newArrayList("Snippet 0", "Snippet 1"),
          Lists.transform(getDocuments(), DOCUMENT_TO_SUMMARY));
    }

    // Run with swapping XSLT
    {
      IResource xml = resourceLocator.getFirst("/xml/carrot2-test.xml");
      IResource xslt = resourceLocator.getFirst("/xsl/carrot2-title-snippet-switch.xsl");
      processingAttributes.put(AttributeUtils.getKey(XmlDocumentSource.class, "xml"), xml);
      processingAttributes.put(AttributeUtils.getKey(XmlDocumentSource.class, "xslt"), xslt);

      final int documentCount = runQuery(controller);
      assertEquals(2, documentCount);
      assertEquals(
          Lists.newArrayList("Snippet 0", "Snippet 1"),
          Lists.transform(getDocuments(), DOCUMENT_TO_TITLE));
      assertEquals(
          Lists.newArrayList("Title 0", "Title 1"),
          Lists.transform(getDocuments(), DOCUMENT_TO_SUMMARY));
    }
  }