mirror of
https://github.com/crawler-commons/crawler-commons
synced 2024-05-22 19:06:03 +02:00
Inline unit test for locale-specific number formats in video:price tags (#220)
- simply unit tests to contain only tested or required video attributes - fix order of attributes/elements to follow XSD schema spec
This commit is contained in:
parent
4de43a7534
commit
f361597447
|
@ -25,6 +25,7 @@ import java.net.MalformedURLException;
|
|||
import java.net.URL;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
@ -54,7 +55,10 @@ public class SiteMapParserExtensionTest {
|
|||
assertEquals(false, asm.isIndex());
|
||||
assertEquals(true, asm instanceof SiteMap);
|
||||
SiteMap sm = (SiteMap) asm;
|
||||
assertEquals(1, sm.getSiteMapUrls().size());
|
||||
assertEquals(2, sm.getSiteMapUrls().size());
|
||||
Iterator<SiteMapURL> siter = sm.getSiteMapUrls().iterator();
|
||||
|
||||
// first <loc> element: nearly all video attributes
|
||||
VideoAttributes expectedVideoAttributes = new VideoAttributes(new URL("http://www.example.com/thumbs/123.jpg"), "Grilling steaks for summer",
|
||||
"Alkis shows you how to get perfectly done steaks every time", new URL("http://www.example.com/video123.flv"), new URL("http://www.example.com/videoplayer.swf?video=123"));
|
||||
expectedVideoAttributes.setDuration(600);
|
||||
|
@ -74,12 +78,17 @@ public class SiteMapParserExtensionTest {
|
|||
expectedVideoAttributes.setUploader("GrillyMcGrillerson");
|
||||
expectedVideoAttributes.setUploaderInfo(new URL("http://www.example.com/users/grillymcgrillerson"));
|
||||
expectedVideoAttributes.setLive(false);
|
||||
VideoAttributes attr = (VideoAttributes) siter.next().getAttributesForExtension(Extension.VIDEO)[0];
|
||||
assertNotNull(attr);
|
||||
assertEquals(expectedVideoAttributes, attr);
|
||||
|
||||
for (SiteMapURL su : sm.getSiteMapUrls()) {
|
||||
assertNotNull(su.getAttributesForExtension(Extension.VIDEO));
|
||||
VideoAttributes attr = (VideoAttributes) su.getAttributesForExtension(Extension.VIDEO)[0];
|
||||
assertEquals(expectedVideoAttributes, attr);
|
||||
}
|
||||
// locale-specific number format in <video:price>, test #220
|
||||
expectedVideoAttributes = new VideoAttributes(new URL("http://www.example.com/thumbs/123-2.jpg"), "Grilling steaks for summer, episode 2",
|
||||
"Alkis shows you how to get perfectly done steaks every time", new URL("http://www.example.com/video123-2.flv"), null);
|
||||
expectedVideoAttributes.setPrices(new VideoAttributes.VideoPrice[] { new VideoAttributes.VideoPrice("EUR", null, VideoAttributes.VideoPriceType.own) });
|
||||
attr = (VideoAttributes) siter.next().getAttributesForExtension(Extension.VIDEO)[0];
|
||||
assertNotNull(attr);
|
||||
assertEquals(expectedVideoAttributes, attr);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -257,46 +266,4 @@ public class SiteMapParserExtensionTest {
|
|||
assertEquals(74, sm.getSiteMapUrls().size());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testVideosSitemapWithError() throws UnknownFormatException, IOException {
|
||||
SiteMapParser parser = new SiteMapParser();
|
||||
parser.enableExtension(Extension.VIDEO);
|
||||
|
||||
String contentType = "text/xml";
|
||||
byte[] content = SiteMapParserTest.getResourceAsBytes("src/test/resources/sitemaps/extension/sitemap-videos-error.xml");
|
||||
|
||||
URL url = new URL("http://www.example.com/sitemap-video.xml");
|
||||
AbstractSiteMap asm = parser.parseSiteMap(contentType, content, url);
|
||||
assertEquals(false, asm.isIndex());
|
||||
assertEquals(true, asm instanceof SiteMap);
|
||||
SiteMap sm = (SiteMap) asm;
|
||||
assertEquals(1, sm.getSiteMapUrls().size());
|
||||
VideoAttributes expectedVideoAttributes = new VideoAttributes(new URL("http://www.example.com/thumbs/123.jpg"), "Grilling steaks for summer",
|
||||
"Alkis shows you how to get perfectly done steaks every time", new URL("http://www.example.com/video123.flv"), new URL("http://www.example.com/videoplayer.swf?video=123"));
|
||||
expectedVideoAttributes.setDuration(600);
|
||||
ZonedDateTime dt = ZonedDateTime.parse("2009-11-05T19:20:30+08:00");
|
||||
expectedVideoAttributes.setExpirationDate(dt);
|
||||
dt = ZonedDateTime.parse("2007-11-05T19:20:30+08:00");
|
||||
expectedVideoAttributes.setPublicationDate(dt);
|
||||
expectedVideoAttributes.setRating(4.2f);
|
||||
expectedVideoAttributes.setViewCount(12345);
|
||||
expectedVideoAttributes.setFamilyFriendly(true);
|
||||
expectedVideoAttributes.setTags(new String[] { "sample_tag1", "sample_tag2" });
|
||||
expectedVideoAttributes.setAllowedCountries(new String[] { "IE", "GB", "US", "CA" });
|
||||
expectedVideoAttributes.setGalleryLoc(new URL("http://cooking.example.com"));
|
||||
expectedVideoAttributes.setGalleryTitle("Cooking Videos");
|
||||
expectedVideoAttributes.setPrices(new VideoAttributes.VideoPrice[] { new VideoAttributes.VideoPrice("EUR", null, VideoAttributes.VideoPriceType.own) });
|
||||
expectedVideoAttributes.setRequiresSubscription(true);
|
||||
expectedVideoAttributes.setUploader("GrillyMcGrillerson");
|
||||
expectedVideoAttributes.setUploaderInfo(new URL("http://www.example.com/users/grillymcgrillerson"));
|
||||
expectedVideoAttributes.setLive(false);
|
||||
|
||||
for (SiteMapURL su : sm.getSiteMapUrls()) {
|
||||
assertNotNull(su.getAttributesForExtension(Extension.VIDEO));
|
||||
VideoAttributes attr = (VideoAttributes) su.getAttributesForExtension(Extension.VIDEO)[0];
|
||||
assertEquals(expectedVideoAttributes, attr);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,33 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
|
||||
xmlns:video="http://www.google.com/schemas/sitemap-video/1.1" >
|
||||
<!-- example from https://support.google.com/webmasters/answer/80471 -->
|
||||
<url>
|
||||
<loc>http://www.example.com/videos/some_video_landing_page.html</loc>
|
||||
<video:video>
|
||||
<video:thumbnail_loc>http://www.example.com/thumbs/123.jpg</video:thumbnail_loc>
|
||||
<video:title>Grilling steaks for summer</video:title>
|
||||
<video:description>Alkis shows you how to get perfectly done steaks every
|
||||
time</video:description>
|
||||
<video:content_loc>http://www.example.com/video123.flv</video:content_loc>
|
||||
<video:player_loc allow_embed="yes" autoplay="ap=1">
|
||||
http://www.example.com/videoplayer.swf?video=123</video:player_loc>
|
||||
<video:duration>600</video:duration>
|
||||
<video:expiration_date>2009-11-05T19:20:30+08:00</video:expiration_date>
|
||||
<video:rating>4.2</video:rating>
|
||||
<video:view_count>12345</video:view_count>
|
||||
<video:publication_date>2007-11-05T19:20:30+08:00</video:publication_date>
|
||||
<video:family_friendly>yes</video:family_friendly>
|
||||
<video:tag>sample_tag1</video:tag>
|
||||
<video:tag>sample_tag2</video:tag>
|
||||
<video:restriction relationship="allow">IE GB US CA</video:restriction>
|
||||
<video:gallery_loc title="Cooking Videos">http://cooking.example.com</video:gallery_loc>
|
||||
<video:price currency="EUR">1,99</video:price>
|
||||
<video:requires_subscription>yes</video:requires_subscription>
|
||||
<video:uploader
|
||||
info="http://www.example.com/users/grillymcgrillerson">GrillyMcGrillerson
|
||||
</video:uploader>
|
||||
<video:live>no</video:live>
|
||||
</video:video>
|
||||
</url>
|
||||
</urlset>
|
|
@ -17,9 +17,9 @@
|
|||
<video:rating>4.2</video:rating>
|
||||
<video:view_count>12345</video:view_count>
|
||||
<video:publication_date>2007-11-05T19:20:30+08:00</video:publication_date>
|
||||
<video:family_friendly>yes</video:family_friendly>
|
||||
<video:tag>sample_tag1</video:tag>
|
||||
<video:tag>sample_tag2</video:tag>
|
||||
<video:family_friendly>yes</video:family_friendly>
|
||||
<video:restriction relationship="allow">IE GB US CA</video:restriction>
|
||||
<video:gallery_loc title="Cooking Videos">http://cooking.example.com</video:gallery_loc>
|
||||
<video:price currency="EUR">1.99</video:price>
|
||||
|
@ -30,4 +30,16 @@
|
|||
<video:live>no</video:live>
|
||||
</video:video>
|
||||
</url>
|
||||
<url>
|
||||
<loc>http://www.example.com/videos/some_video_landing_page-2.html</loc>
|
||||
<video:video>
|
||||
<video:thumbnail_loc>http://www.example.com/thumbs/123-2.jpg</video:thumbnail_loc>
|
||||
<video:title>Grilling steaks for summer, episode 2</video:title>
|
||||
<video:description>Alkis shows you how to get perfectly done steaks every
|
||||
time</video:description>
|
||||
<video:content_loc>http://www.example.com/video123-2.flv</video:content_loc>
|
||||
<!-- locale-specific number format, test #220 -->
|
||||
<video:price currency="EUR">1,99</video:price>
|
||||
</video:video>
|
||||
</url>
|
||||
</urlset>
|
||||
|
|
Loading…
Reference in New Issue