use of com.yahoo.vespa.http.client.FeedClient in project vespa by vespa-engine.
the class XmlFeedReaderTest method testEncoding.
@Test
public void testEncoding() throws Exception {
InputStream stream = new ByteArrayInputStream("<?xml version=\"1.0\" encoding=\"utf8\"?><vespafeed><remove documentid=\"id:&\"/></vespafeed>".getBytes(StandardCharsets.UTF_8));
AtomicInteger numSent = new AtomicInteger(0);
FeedClient feedClient = mock(FeedClient.class);
doAnswer(new Answer<Object>() {
public Object answer(InvocationOnMock invocation) {
Object[] args = invocation.getArguments();
String docId = (String) args[0];
CharSequence value = (CharSequence) args[1];
assertThat(value.toString(), is("<remove documentid=\"id:&\"></remove>"));
assertThat(docId, is("id:&"));
return null;
}
}).when(feedClient).stream(anyString(), anyObject());
XmlFeedReader.read(stream, feedClient, numSent);
assertThat(numSent.get(), is(1));
}
use of com.yahoo.vespa.http.client.FeedClient in project vespa by vespa-engine.
the class XmlFeedReaderTest method testGarbage.
@Test(expected = SAXParseException.class)
public void testGarbage() throws Exception {
InputStream stream = new ByteArrayInputStream("eehh".getBytes(StandardCharsets.UTF_8));
AtomicInteger numSent = new AtomicInteger(0);
FeedClient feedClient = mock(FeedClient.class);
XmlFeedReader.read(stream, feedClient, numSent);
}
use of com.yahoo.vespa.http.client.FeedClient in project vespa by vespa-engine.
the class XmlFeedReaderTest method testRealData.
@Test
public void testRealData() throws Exception {
InputStream inputStream = XmlFeedReaderTest.class.getResourceAsStream(feedResource);
BufferedInputStream bis = new BufferedInputStream(inputStream);
AtomicInteger numSent = new AtomicInteger(0);
FeedClient feedClient = mock(FeedClient.class);
XmlFeedReader.read(bis, feedClient, numSent);
assertThat(numSent.get(), is(6));
}
use of com.yahoo.vespa.http.client.FeedClient in project vespa by vespa-engine.
the class XmlFeedReaderTest method testReadRemove.
@Test
public void testReadRemove() throws Exception {
InputStream stream = new ByteArrayInputStream(updateDocRemove.getBytes(StandardCharsets.UTF_8));
AtomicInteger numSent = new AtomicInteger(0);
FeedClient feedClient = mock(FeedClient.class);
XmlFeedReader.read(stream, feedClient, numSent);
assertThat(numSent.get(), is(2));
}
use of com.yahoo.vespa.http.client.FeedClient in project vespa by vespa-engine.
the class XmlFeedReaderTest method testCharacterEndcoding.
@Test
public void testCharacterEndcoding() throws Exception {
InputStream stream = new ByteArrayInputStream(characterDocs.getBytes(StandardCharsets.UTF_8));
AtomicInteger numSent = new AtomicInteger(0);
FeedClient feedClient = mock(FeedClient.class);
final AtomicBoolean success = new AtomicBoolean(false);
doAnswer(new Answer<Object>() {
public Object answer(InvocationOnMock invocation) {
Object[] args = invocation.getArguments();
String docId = (String) args[0];
CharSequence value = (CharSequence) args[1];
assertThat(value.toString(), is("<document documenttype=\"simple\" documentid=\"id:test::&http://www.e.no/matprat\">\n" + " <language><![CDATA[ja]]></language>\n" + " <title><![CDATA[test document1]]></title>\n" + " <description><![CDATA[Bjørnen' blåbær på øy nærheten.]]></description>\n" + " <date>1091356845</date>\n" + " <surl><![CDATA[http://www.eventyr.no/matprat]]></surl>\n" + " </document>"));
success.set(true);
return null;
}
}).when(feedClient).stream(anyString(), anyObject());
XmlFeedReader.read(stream, feedClient, numSent);
assertThat(numSent.get(), is(1));
assert (success.get());
}
Aggregations