public void registerExtractorsForCustomTypes(String docType) { String pluralizedDoctype = DocumentTypeUtils.pluralize(docType); if (!containsKey(pluralizedDoctype)) { LOGGER.info("register new extractors for document type: {}", docType); registerEngine(pluralizedDoctype, new TypedDocumentsExtractor()); registerEngine("published_" + pluralizedDoctype, new PublishedCustomExtractor(docType)); } }
@Test public void shouldRegisterExtractorsForCustomType() { // A document type is known String newDocumentType = "project"; DocumentTypes.addDocumentType(newDocumentType); // when we register extractors for the new type ModelExtractors.getInstance().registerExtractorsForCustomTypes(newDocumentType); // then an extractor is registered by pluralized type as key assertThat(ModelExtractors.getInstance().containsKey("projects")).isTrue(); // and an extractor for published types is registered assertThat(ModelExtractors.getInstance().containsKey("published_projects")).isTrue(); }
@Test public void shouldRegisterExtractorsForCustomType() { // given: "A document type is known" String newDocumentType = "project"; DocumentTypes.addDocumentType(newDocumentType); ModelExtractorsDocumentTypeListener listener = new ModelExtractorsDocumentTypeListener(); // when: "the listener is called with that type" listener.added(newDocumentType); // then: "an extractor is registered by pluralized type as key" assertThat(ModelExtractors.getInstance().containsKey("projects")).isTrue(); // and: "an extractor for published types is registered" assertThat(ModelExtractors.getInstance().containsKey("published_projects")).isTrue(); } }
@Test public void shouldLoadExtractorsOnInstantiation() { ModelExtractors.getInstance(); String[] expectedKeys = new String[]{ "pages", "posts", "indexs", "archives", "feeds", "published_posts", "published_pages", "published_content", "published_date", "all_content", "alltags", "db", "tag_posts", "tags", "tagged_documents", }; for (String aKey : expectedKeys) { assertThat(ModelExtractors.getInstance().containsKey(aKey)).isTrue(); } }
@Test public void shouldRegisterExtractorsOnlyForCustomTypes() { String knownDocumentType = "alltag"; DocumentTypes.addDocumentType(knownDocumentType); ModelExtractors.getInstance().registerExtractorsForCustomTypes(knownDocumentType); assertThat(ModelExtractors.getInstance().containsKey("published_alltags")).isFalse(); }
public void registerExtractorsForCustomTypes(String docType) { String pluralizedDoctype = DocumentTypeUtils.pluralize(docType); if (!containsKey(pluralizedDoctype)) { LOGGER.info("register new extractors for document type: {}", docType); registerEngine(pluralizedDoctype, new TypedDocumentsExtractor()); registerEngine("published_" + pluralizedDoctype, new PublishedCustomExtractor(docType)); } }