* tests building a source element.
*/
@Test
public void testBuildSource() {
try {
Source source = rssDoc.buildSource(null, "somewhere cool");
assertNotNull(source);
fail("we should have thrown an exception above.");
} catch (RSSpectException r) {
assertEquals(r.getMessage(),
"source elements MUST contain a url attribute.");
}
try {
Source source = rssDoc.buildSource(rssDoc.buildAttribute("cat",
"dog"), "somewhere cool");
assertNotNull(source);
fail("we should have thrown an exception above.");
} catch (RSSpectException r) {
assertEquals(r.getMessage(),
"source elements MUST contain a url attribute.");
}
try {
Source source = rssDoc.buildSource(rssDoc.buildAttribute("url",
"http://www.earthbeats.net"), "somewhere cool");
assertNotNull(source);
assertNotNull(source.getUrl());
assertNotNull(source.getUrl().getName());
assertEquals(source.getUrl().getName(), "url");
assertNotNull(source.getUrl().getValue());
assertEquals(source.getUrl().getValue(),
"http://www.earthbeats.net");
assertNotNull(source.getSource());
assertEquals(source.getSource(), "somewhere cool");
} catch (Exception e) {
fail("should not fail here.");
}
try {
rssDoc.buildSource(rssDoc.buildAttribute("url",
"http://www.colorfulsoftware.com"), null);
fail("should not get here.");
} catch (RSSpectException r) {
assertEquals(r.getMessage(), "source SHOULD NOT be blank.");
}
try {
rssDoc.buildSource(rssDoc.buildAttribute("url",
"http://www.colorfulsoftware.com"), "");
fail("should not get here.");
} catch (RSSpectException r) {
assertEquals(r.getMessage(), "source SHOULD NOT be blank.");
}
try {
Source source = rssDoc.buildSource(rssDoc.buildAttribute("url",
"http://www.colorfulsoftware.com"), "Colorful Software");
assertNotNull(source);
assertEquals(source.getSource(), "Colorful Software");
} catch (RSSpectException r) {
fail("should not get here.");
}
}