Skip to content

Commit

Permalink
Merge pull request #61 from profeg/OLogTransformerTest
Browse files Browse the repository at this point in the history
O log transformer test
  • Loading branch information
lvca committed Apr 22, 2015
2 parents 0a7963e + d2084d5 commit c628550
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public Object executeTransform(final Object input) {
if (postfix != null && !postfix.isEmpty())
buffer.append(resolve(postfix));

out.println(buffer.toString()); //TODO log(OETLProcessor.LOG_LEVELS.INFO, buffer.toString());
log(OETLProcessor.LOG_LEVELS.INFO, buffer.toString());

return input;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.orientechnologies.orient.etl.transformer;

import com.orientechnologies.orient.core.record.impl.ODocument;
import com.orientechnologies.orient.etl.ETLBaseTest;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.util.List;

import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;

public class OLogTransformerTest extends ETLBaseTest {

private final PrintStream OUT = System.out;

@Test
public void testPrefix() throws Exception {
ByteArrayOutputStream output = getByteArrayOutputStream();
String cfgJson = "{source: { content: { value: 'id,text\n1,Hello\n2,Bye'} }, extractor : { row : {} }, transformers : [{ csv : {} },{ log : {prefix:'-> '}}], loader : { test: {} } }";
process(cfgJson);
List<ODocument> res = getResult();
ODocument doc = res.get(0);
String[] stringList = output.toString().split("\n");
assertEquals("[1:log] INFO -> {id:1,text:Hello}", stringList[1]);
assertEquals("[2:log] INFO -> {id:2,text:Bye}", stringList[2]);
}
@Test
public void testPostfix() throws Exception {
ByteArrayOutputStream output = getByteArrayOutputStream();
String cfgJson = "{source: { content: { value: 'id,text\n1,Hello\n2,Bye'} }, extractor : { row : {} }, transformers : [{ csv : {} },{ log : {postfix:'-> '}}], loader : { test: {} } }";
process(cfgJson);
List<ODocument> res = getResult();
ODocument doc = res.get(0);
String[] stringList = output.toString().split("\n");
assertEquals("[1:log] INFO {id:1,text:Hello}-> ", stringList[1]);
assertEquals("[2:log] INFO {id:2,text:Bye}-> ", stringList[2]);
}

private ByteArrayOutputStream getByteArrayOutputStream() {
ByteArrayOutputStream output = new ByteArrayOutputStream();
System.setOut(new PrintStream(output, true));
return output;
}

}

0 comments on commit c628550

Please sign in to comment.