Search in sources :

Example 1 with FeedClient

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:&amp;\"/></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:&amp;\"></remove>"));
            assertThat(docId, is("id:&"));
            return null;
        }
    }).when(feedClient).stream(anyString(), anyObject());
    XmlFeedReader.read(stream, feedClient, numSent);
    assertThat(numSent.get(), is(1));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BufferedInputStream(java.io.BufferedInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Matchers.anyObject(org.mockito.Matchers.anyObject) FeedClient(com.yahoo.vespa.http.client.FeedClient) Matchers.anyString(org.mockito.Matchers.anyString) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Example 2 with FeedClient

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);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BufferedInputStream(java.io.BufferedInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) FeedClient(com.yahoo.vespa.http.client.FeedClient) Test(org.junit.Test)

Example 3 with FeedClient

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));
}
Also used : BufferedInputStream(java.io.BufferedInputStream) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BufferedInputStream(java.io.BufferedInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) FeedClient(com.yahoo.vespa.http.client.FeedClient) Test(org.junit.Test)

Example 4 with FeedClient

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));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BufferedInputStream(java.io.BufferedInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) FeedClient(com.yahoo.vespa.http.client.FeedClient) Test(org.junit.Test)

Example 5 with FeedClient

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::&amp;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());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ByteArrayInputStream(java.io.ByteArrayInputStream) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BufferedInputStream(java.io.BufferedInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Matchers.anyObject(org.mockito.Matchers.anyObject) FeedClient(com.yahoo.vespa.http.client.FeedClient) Matchers.anyString(org.mockito.Matchers.anyString) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Aggregations

FeedClient (com.yahoo.vespa.http.client.FeedClient)10 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)10 BufferedInputStream (java.io.BufferedInputStream)8 ByteArrayInputStream (java.io.ByteArrayInputStream)8 InputStream (java.io.InputStream)8 Test (org.junit.Test)8 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)2 Matchers.anyObject (org.mockito.Matchers.anyObject)2 Matchers.anyString (org.mockito.Matchers.anyString)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 Result (com.yahoo.vespa.http.client.Result)1 SimpleLoggerResultCallback (com.yahoo.vespa.http.client.SimpleLoggerResultCallback)1 Cluster (com.yahoo.vespa.http.client.config.Cluster)1 Endpoint (com.yahoo.vespa.http.client.config.Endpoint)1 SessionParams (com.yahoo.vespa.http.client.config.SessionParams)1 File (java.io.File)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1