Skip to content
This repository has been archived by the owner on Jan 17, 2022. It is now read-only.

Commit

Permalink
Updated regex and tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mihai Moisa committed Jul 6, 2017
1 parent 4849012 commit 0f9083f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class RecommendedXMLEventHandler extends BaseXMLEventHandler {
private static final String URL_ATTRIBUTE = "url";
private static final String TYPE_VALUE = "http://www.ft.com/ontology/content/Article";
private static final String BASE_URL = "http://api.ft.com/content/";
private static final String REGEX = "(^\\/[A-Za-z0-9/.?]*=)([a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12})$";
private static final String REGEX = "^(\\/[^=]*=)([a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12})$";

private Pattern pattern;
private RecommendedXMLParser recommendedXMLParser;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1173,100 +1173,100 @@ public void shouldStripAllNotesFromContent() throws Exception {

@Test
public void shouldKeepAnchorTagsFromRecommended() {
String contentWithNotes = "<body><recommended><recommended-title/><ul><li><a href=\"link\">Title</a></li></ul></recommended></body>";
String originalRecommendedContent = "<body><recommended><recommended-title/><ul><li><a href=\"link\">Title</a></li></ul></recommended></body>";
String transformedContent = "<body><recommended><recommended-title/><ul><li><a href=\"link\">Title</a></li></ul></recommended></body>";
checkTransformation(contentWithNotes, transformedContent);
checkTransformation(originalRecommendedContent, transformedContent);
}

@Test
public void shouldRemoveDummyTextFromAnchorTagsFromRecommended() {
String contentWithNotes = "<body><recommended><recommended-title/><ul><li><a href=\"link\"><?EM-dummyText [Headline]?></a></li></ul></recommended></body>";
String originalRecommendedContent = "<body><recommended><recommended-title/><ul><li><a href=\"link\"><?EM-dummyText [Headline]?></a></li></ul></recommended></body>";
String transformedContent = "<body><recommended><recommended-title/><ul><li><a href=\"link\"/></li></ul></recommended></body>";
checkTransformation(contentWithNotes, transformedContent);
checkTransformation(originalRecommendedContent, transformedContent);
}

@Test
public void shouldRemoveEmptyIntroFromRecommended() {
String contentWithNotes = "<body><recommended><p></p><ul><li><a href=\"link\">Title</a></li></ul></recommended></body>";
String originalRecommendedContent = "<body><recommended><p></p><ul><li><a href=\"link\">Title</a></li></ul></recommended></body>";
String transformedContent = "<body><recommended><recommended-title/><ul><li><a href=\"link\">Title</a></li></ul></recommended></body>";
checkTransformation(contentWithNotes, transformedContent);
checkTransformation(originalRecommendedContent, transformedContent);
}

@Test
public void shouldRemoveDummyTextIntroFromRecommended() {
String contentWithNotes = "<body><recommended><p><?EM-dummyText [Title]?></p><ul><li><a href=\"link\">Title</a></li></ul></recommended></body>";
String originalRecommendedContent = "<body><recommended><p><?EM-dummyText [Title]?></p><ul><li><a href=\"link\">Title</a></li></ul></recommended></body>";
String transformedContent = "<body><recommended><recommended-title/><ul><li><a href=\"link\">Title</a></li></ul></recommended></body>";
checkTransformation(contentWithNotes, transformedContent);
checkTransformation(originalRecommendedContent, transformedContent);
}

@Test
public void shouldKeepIntroIfNotEmptyFromRecommended() {
String contentWithNotes = "<body><recommended><p>Intro</p><ul><li><a href=\"link\">Title</a></li></ul></recommended></body>";
String originalRecommendedContent = "<body><recommended><p>Intro</p><ul><li><a href=\"link\">Title</a></li></ul></recommended></body>";
String transformedContent = "<body><recommended><recommended-title/><p>Intro</p><ul><li><a href=\"link\">Title</a></li></ul></recommended></body>";
checkTransformation(contentWithNotes, transformedContent);
checkTransformation(originalRecommendedContent, transformedContent);
}

@Test
public void shouldAddMissingRecommendedTitleFromRecommended() {
String contentWithNotes = "<body><recommended><p></p><ul><li><a href=\"link\">Title</a></li></ul></recommended></body>";
String originalRecommendedContent = "<body><recommended><p></p><ul><li><a href=\"link\">Title</a></li></ul></recommended></body>";
String transformedContent = "<body><recommended><recommended-title/><ul><li><a href=\"link\">Title</a></li></ul></recommended></body>";
checkTransformation(contentWithNotes, transformedContent);
checkTransformation(originalRecommendedContent, transformedContent);
}

@Test
public void shouldNotAddRecommendedIfAnchorsAreMissingFromRecommended() {
String contentWithNotes = "<body><recommended></recommended></body>";
String originalRecommendedContent = "<body><recommended></recommended></body>";
String transformedContent = "<body></body>";
checkTransformation(contentWithNotes, transformedContent);
checkTransformation(originalRecommendedContent, transformedContent);
}

@Test
public void shouldTransformMethodeLinkFromRecommended() {
String contentWithNotes = "<body><recommended><ul><li><a href=\"/Content/2007/Path/To/Methode/Article.xml?uuid=e30ce78c-59fe-11e7-b553-e2df1b0c3220\">Internal articles’s title added by methode automatically</a></li></ul></recommended></body>";
String originalRecommendedContent = "<body><recommended><ul><li><a href=\"/FT/Content/Companies/Stories/Live/GB/New%20UUID%20Generation%20for%20image-sets/rj/Article01%20without%20imageset.xml?uuid=e30ce78c-59fe-11e7-b553-e2df1b0c3220\">Internal articles’s title added by methode automatically</a></li></ul></recommended></body>";
String transformedContent = "<body><recommended><recommended-title/><ul><li><a type=\"http://www.ft.com/ontology/content/Article\" url=\"http://api.ft.com/content/e30ce78c-59fe-11e7-b553-e2df1b0c3220\">Internal articles’s title added by methode automatically</a></li></ul></recommended></body>";
checkTransformation(contentWithNotes, transformedContent);
checkTransformation(originalRecommendedContent, transformedContent);
}

@Test
public void shouldKeepManualLinkFromRecommended() {
String contentWithNotes = "<body><recommended><ul><li><a href=\"http://ft.com/content/71ece778-5a53-11e7-9bc8-8055f264aa8b\">Manually added FT article’s manual title</a></li></ul></recommended></body>";
String originalRecommendedContent = "<body><recommended><ul><li><a href=\"http://ft.com/content/71ece778-5a53-11e7-9bc8-8055f264aa8b\">Manually added FT article’s manual title</a></li></ul></recommended></body>";
String transformedContent = "<body><recommended><recommended-title/><ul><li><a href=\"http://ft.com/content/71ece778-5a53-11e7-9bc8-8055f264aa8b\">Manually added FT article’s manual title</a></li></ul></recommended></body>";
checkTransformation(contentWithNotes, transformedContent);
checkTransformation(originalRecommendedContent, transformedContent);
}

@Test
public void shouldKeepExternalLinkFromRecommended() {
String contentWithNotes = "<body><recommended><ul><li><a href=\"http://example.com/manually/added/document1.pdf\">External link’s manually added title</a></li></ul></recommended></body>";
String originalRecommendedContent = "<body><recommended><ul><li><a href=\"http://example.com/manually/added/document1.pdf\">External link’s manually added title</a></li></ul></recommended></body>";
String transformedContent = "<body><recommended><recommended-title/><ul><li><a href=\"http://example.com/manually/added/document1.pdf\">External link’s manually added title</a></li></ul></recommended></body>";
checkTransformation(contentWithNotes, transformedContent);
checkTransformation(originalRecommendedContent, transformedContent);
}

@Test
public void shouldRemoveListItemIfAnchorIsEmptyFromRecommended() {
String contentWithNotes = "<body><recommended><ul><li><a href=\"http://example.com/manually/added/document1.pdf\">External link’s manually added title</a></li><li><a/></li></ul></recommended></body>";
String originalRecommendedContent = "<body><recommended><ul><li><a href=\"http://example.com/manually/added/document1.pdf\">External link’s manually added title</a></li><li><a/></li></ul></recommended></body>";
String transformedContent = "<body><recommended><recommended-title/><ul><li><a href=\"http://example.com/manually/added/document1.pdf\">External link’s manually added title</a></li></ul></recommended></body>";
checkTransformation(contentWithNotes, transformedContent);
checkTransformation(originalRecommendedContent, transformedContent);
}

@Test
public void shouldRemoveListItemIfAnchorIsMissingHrefFromRecommended() {
String contentWithNotes = "<body><recommended><ul><li><a href=\"http://example.com/manually/added/document1.pdf\">External link’s manually added title</a></li><li><a>Some text</a></li></ul></recommended></body>";
String originalRecommendedContent = "<body><recommended><ul><li><a href=\"http://example.com/manually/added/document1.pdf\">External link’s manually added title</a></li><li><a>Some text</a></li></ul></recommended></body>";
String transformedContent = "<body><recommended><recommended-title/><ul><li><a href=\"http://example.com/manually/added/document1.pdf\">External link’s manually added title</a></li></ul></recommended></body>";
checkTransformation(contentWithNotes, transformedContent);
checkTransformation(originalRecommendedContent, transformedContent);
}

@Test
public void shouldRemoveListItemIfHrefIsEmptyFromRecommended() {
String contentWithNotes = "<body><recommended><ul><li><a href=\"link\">Valid</a></li><li><a href=\" \">Invalid</a></li></ul></recommended></body>";
String originalRecommendedContent = "<body><recommended><ul><li><a href=\"link\">Valid</a></li><li><a href=\" \">Invalid</a></li></ul></recommended></body>";
String transformedContent = "<body><recommended><recommended-title/><ul><li><a href=\"link\">Valid</a></li></ul></recommended></body>";
checkTransformation(contentWithNotes, transformedContent);
checkTransformation(originalRecommendedContent, transformedContent);
}

@Test
public void shouldKeepAnchorTagsWithDummyTextThatHaveHrefFromRecommended() {
String contentWithNotes = "<body><recommended><ul><li><a href=\"link\"><?EM-dummyText [Article Title]?></a></li></ul></recommended></body>";
String originalRecommendedContent = "<body><recommended><ul><li><a href=\"link\"><?EM-dummyText [Article Title]?></a></li></ul></recommended></body>";
String transformedContent = "<body><recommended><recommended-title/><ul><li><a href=\"link\"></a></li></ul></recommended></body>";
checkTransformation(contentWithNotes, transformedContent);
checkTransformation(originalRecommendedContent, transformedContent);
}

private void checkTransformation(String originalBody, String expectedTransformedBody) {
Expand Down

0 comments on commit 0f9083f

Please sign in to comment.