Search in sources :

Example 1 with D2RTranslator

use of com.torodb.core.d2r.D2RTranslator in project torodb by torodb.

the class D2RTranslationBatchFunctionTest method testApply.

@Test
public void testApply() {
    D2RTranslator translator = mock(D2RTranslator.class);
    CollectionData colData = mock(CollectionData.class);
    KvDocument doc1 = mock(KvDocument.class);
    KvDocument doc2 = mock(KvDocument.class);
    given(translator.getCollectionDataAccumulator()).willReturn(colData);
    given(translatorFactory.createTranslator(metaDb, batchMetaCol)).willReturn(translator);
    List<KvDocument> docs = Lists.newArrayList(doc1, doc2);
    //when
    CollectionData result = fun.apply(docs);
    //then
    verify(batchMetaCol).newBatch();
    verify(translator).translate(doc1);
    verify(translator).translate(doc2);
    verify(translator).getCollectionDataAccumulator();
    verifyNoMoreInteractions(translator);
    verify(translatorFactory).createTranslator(metaDb, batchMetaCol);
    verifyNoMoreInteractions(translatorFactory);
    assertEquals(colData, result);
}
Also used : CollectionData(com.torodb.core.d2r.CollectionData) KvDocument(com.torodb.kvdocument.values.KvDocument) D2RTranslator(com.torodb.core.d2r.D2RTranslator) Test(org.junit.Test)

Example 2 with D2RTranslator

use of com.torodb.core.d2r.D2RTranslator in project torodb by torodb.

the class D2RTranslationBatchFunction method apply.

@Override
public CollectionData apply(List<KvDocument> docs) {
    metaDocCollection.newBatch();
    D2RTranslator translator = translatorFactory.createTranslator(metaDatabase, metaDocCollection);
    for (KvDocument doc : docs) {
        translator.translate(doc);
    }
    return translator.getCollectionDataAccumulator();
}
Also used : KvDocument(com.torodb.kvdocument.values.KvDocument) D2RTranslator(com.torodb.core.d2r.D2RTranslator)

Aggregations

D2RTranslator (com.torodb.core.d2r.D2RTranslator)2 KvDocument (com.torodb.kvdocument.values.KvDocument)2 CollectionData (com.torodb.core.d2r.CollectionData)1 Test (org.junit.Test)1